diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2008-04-21 16:46:58 +0400 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2008-04-21 16:46:58 +0400 |
commit | abbde487046d0f1a775a85057d51ec4ee074e33d (patch) | |
tree | 6c5a34114129748846159e3b131b0f6514a05b0c /winsup/cygwin/fhandler_socket.cc | |
parent | 70fab4ec71b3a206b042b6c027c14ad575876b8c (diff) |
* Makefile.in (DLL_OFILES): Add kernel32.o.
* autoload.cc (WSACloseEvent): Remove.
(WSACreateEvent): Remove.
* cygheap.cc (cygheap_init): Drop initializing shared_prefix.
* cygheap.h (struct init_cygheap): Drop shared_prefix and
shared_prefix_buf members.
* fhandler_socket.cc (sock_shared_name): New static function.
(search_wsa_event_slot): Convert name buffers to WCHAR. Call
NtCreateMutant/NtOpenMutant to create mutexes in session local
namespace.
(fhandler_socket::init_events): Ditto. Fix debug output.
(fhandler_socket::release_events): Close mutexes using NtClose.
(fhandler_socket::dup): Ditto.
* kernel32.cc: New file, implementing Win32 calls in a Cygwin-specific
way.
* mmap.cc (MapView): Make static.
* ntdll.h: Fix status code sorting.
(STATUS_OBJECT_NAME_EXISTS): Define.
(SEMAPHORE_QUERY_STATE): Define.
(CYG_SHARED_DIR_ACCESS): Define.
(CYG_MUTANT_ACCESS): Define.
(CYG_EVENT_ACCESS): Define.
(CYG_SEMAPHORE_ACCESS): Define.
(enum _PROCESSINFOCLASS): Define ProcessSessionInformation.
(struct _PROCESS_SESSION_INFORMATION): Define.
(NtCreateSemaphore): Declare.
(NtOpenSemaphore): Declare.
* flock.cc: Use CYG_xxx_ACCESS access masks where appropriate.
* posix_ipc.cc (ipc_mutex_init): Use native functions to create mutex.
Create in cygwin-shared subdir.
(ipc_cond_init): Ditto for event.
(ipc_mutex_close): Use NtClose.
(ipc_cond_close): Ditto.
(mq_open): Drop "cyg" prefix from mqh_uname.
* shared.cc (CYG_SHARED_DIR_ACCESS): Drop definition here.
(_cygwin_testing): Declare extern on file level.
(get_shared_parent_dir): Change name of shared directory. Add name
to api_fatal output.
(get_session_parent_dir): New function.
(shared_name): Simplify.
(shared_info::initialize): Call get_session_parent_dir.
* shared_info.h (get_session_parent_dir): Declare.
* smallprint.cc (__small_vswprintf): Fix bug in multibyte string
conversion.
* thread.cc (semaphore::semaphore): Align semaphore name to object
names in posix IPC functions.
* include/cygwin/version.h (CYGWIN_VERSION_SHARED_DATA): Bump.
Diffstat (limited to 'winsup/cygwin/fhandler_socket.cc')
-rw-r--r-- | winsup/cygwin/fhandler_socket.cc | 78 |
1 files changed, 50 insertions, 28 deletions
diff --git a/winsup/cygwin/fhandler_socket.cc b/winsup/cygwin/fhandler_socket.cc index e718db097..c0df1fb66 100644 --- a/winsup/cygwin/fhandler_socket.cc +++ b/winsup/cygwin/fhandler_socket.cc @@ -414,17 +414,31 @@ static LONG socket_serial_number __attribute__((section (".cygwin_dll_common"), static HANDLE wsa_slot_mtx; +static PWCHAR +sock_shared_name (PWCHAR buf, LONG num) +{ + __small_swprintf (buf, L"socket.%d", num); + return buf; +} + static wsa_event * search_wsa_event_slot (LONG new_serial_number) { - char name[MAX_PATH], searchname[MAX_PATH]; + WCHAR name[32], searchname[32]; + UNICODE_STRING uname; + OBJECT_ATTRIBUTES attr; + NTSTATUS status; if (!wsa_slot_mtx) { - wsa_slot_mtx = CreateMutex (&sec_all, FALSE, - shared_name (name, "sock", 0)); - if (!wsa_slot_mtx) - api_fatal ("Couldn't create/open shared socket mutex, %E"); + RtlInitUnicodeString (&uname, sock_shared_name (name, 0)); + InitializeObjectAttributes (&attr, &uname, OBJ_INHERIT | OBJ_OPENIF, + get_session_parent_dir (), + everyone_sd (CYG_MUTANT_ACCESS)); + status = NtCreateMutant (&wsa_slot_mtx, CYG_MUTANT_ACCESS, &attr, FALSE); + if (!NT_SUCCESS (status)) + api_fatal ("Couldn't create/open shared socket mutex %S, %p", + &uname, status); } switch (WaitForSingleObject (wsa_slot_mtx, INFINITE)) { @@ -438,12 +452,16 @@ search_wsa_event_slot (LONG new_serial_number) unsigned int slot = new_serial_number % NUM_SOCKS; while (wsa_events[slot].serial_number) { - HANDLE searchmtx = OpenMutex (STANDARD_RIGHTS_READ, FALSE, - shared_name (searchname, "sock", wsa_events[slot].serial_number)); - if (!searchmtx) + HANDLE searchmtx; + RtlInitUnicodeString (&uname, sock_shared_name (searchname, + wsa_events[slot].serial_number)); + InitializeObjectAttributes (&attr, &uname, 0, get_session_parent_dir (), + NULL); + status = NtOpenMutant (&searchmtx, READ_CONTROL, &attr); + if (!NT_SUCCESS (status)) break; /* Mutex still exists, attached socket is active, try next slot. */ - CloseHandle (searchmtx); + NtClose (searchmtx); slot = (slot + 1) % NUM_SOCKS; if (slot == (new_serial_number % NUM_SOCKS)) { @@ -463,8 +481,10 @@ bool fhandler_socket::init_events () { LONG new_serial_number; - char name[MAX_PATH]; - DWORD err = 0; + WCHAR name[32]; + UNICODE_STRING uname; + OBJECT_ATTRIBUTES attr; + NTSTATUS status; do { @@ -472,33 +492,35 @@ fhandler_socket::init_events () InterlockedIncrement (&socket_serial_number); if (!new_serial_number) /* 0 is reserved for global mutex */ InterlockedIncrement (&socket_serial_number); - wsock_mtx = CreateMutex (&sec_all, FALSE, - shared_name (name, "sock", new_serial_number)); - if (!wsock_mtx) + RtlInitUnicodeString (&uname, sock_shared_name (name, new_serial_number)); + InitializeObjectAttributes (&attr, &uname, OBJ_INHERIT | OBJ_OPENIF, + get_session_parent_dir (), + everyone_sd (CYG_MUTANT_ACCESS)); + status = NtCreateMutant (&wsock_mtx, CYG_MUTANT_ACCESS, &attr, FALSE); + if (!NT_SUCCESS (status)) { - debug_printf ("CreateMutex, %E"); + debug_printf ("NtCreateMutant(%S), %p", &uname, status); set_errno (ENOBUFS); return false; } - err = GetLastError (); - if (err == ERROR_ALREADY_EXISTS) - CloseHandle (wsock_mtx); + if (status == STATUS_OBJECT_NAME_EXISTS) + NtClose (wsock_mtx); } - while (err == ERROR_ALREADY_EXISTS); + while (status == STATUS_OBJECT_NAME_EXISTS); if ((wsock_evt = CreateEvent (&sec_all, TRUE, FALSE, NULL)) == WSA_INVALID_EVENT) { - debug_printf ("WSACreateEvent, %E"); + debug_printf ("CreateEvent, %E"); set_errno (ENOBUFS); - CloseHandle (wsock_mtx); + NtClose (wsock_mtx); return false; } if (WSAEventSelect (get_socket (), wsock_evt, EVENT_MASK) == SOCKET_ERROR) { debug_printf ("WSAEventSelect, %E"); set_winsock_errno (); - CloseHandle (wsock_evt); - CloseHandle (wsock_mtx); + NtClose (wsock_evt); + NtClose (wsock_mtx); return false; } wsock_events = search_wsa_event_slot (new_serial_number); @@ -601,8 +623,8 @@ fhandler_socket::wait_for_events (const long event_mask) void fhandler_socket::release_events () { - CloseHandle (wsock_evt); - CloseHandle (wsock_mtx); + NtClose (wsock_evt); + NtClose (wsock_mtx); } void @@ -629,7 +651,7 @@ fhandler_socket::dup (fhandler_base *child) TRUE, DUPLICATE_SAME_ACCESS)) { __seterrno (); - CloseHandle (fhs->wsock_mtx); + NtClose (fhs->wsock_mtx); return -1; } fhs->wsock_events = wsock_events; @@ -653,8 +675,8 @@ fhandler_socket::dup (fhandler_base *child) int ret = fhandler_base::dup (child); if (ret) { - CloseHandle (fhs->wsock_evt); - CloseHandle (fhs->wsock_mtx); + NtClose (fhs->wsock_evt); + NtClose (fhs->wsock_mtx); } return ret; } |