From efd59e378c2ba8cae98fa664ae98521027e96b81 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Thu, 4 Jun 2020 20:34:58 +0200 Subject: [PATCH] ntdll: Move the event functions to the Unix library. Signed-off-by: Alexandre Julliard --- dlls/ntdll/sync.c | 105 +++----------------------- dlls/ntdll/unix/loader.c | 7 ++ dlls/ntdll/unix/sync.c | 154 +++++++++++++++++++++++++++++++++++++++ dlls/ntdll/unixlib.h | 12 ++- 4 files changed, 181 insertions(+), 97 deletions(-) diff --git a/dlls/ntdll/sync.c b/dlls/ntdll/sync.c index 21206762b1e..6ce0fe20856 100644 --- a/dlls/ntdll/sync.c +++ b/dlls/ntdll/sync.c @@ -285,28 +285,10 @@ NTSTATUS WINAPI NtReleaseSemaphore( HANDLE handle, ULONG count, PULONG previous * NtCreateEvent (NTDLL.@) * ZwCreateEvent (NTDLL.@) */ -NTSTATUS WINAPI NtCreateEvent( PHANDLE EventHandle, ACCESS_MASK DesiredAccess, - const OBJECT_ATTRIBUTES *attr, EVENT_TYPE type, BOOLEAN InitialState) +NTSTATUS WINAPI NtCreateEvent( HANDLE *handle, ACCESS_MASK access, const OBJECT_ATTRIBUTES *attr, + EVENT_TYPE type, BOOLEAN state ) { - NTSTATUS ret; - data_size_t len; - struct object_attributes *objattr; - - if ((ret = alloc_object_attributes( attr, &objattr, &len ))) return ret; - - SERVER_START_REQ( create_event ) - { - req->access = DesiredAccess; - req->manual_reset = (type == NotificationEvent); - req->initial_state = InitialState; - wine_server_add_data( req, objattr, len ); - ret = wine_server_call( req ); - *EventHandle = wine_server_ptr_handle( reply->handle ); - } - SERVER_END_REQ; - - RtlFreeHeap( GetProcessHeap(), 0, objattr ); - return ret; + return unix_funcs->NtCreateEvent( handle, access, attr, type, state ); } /****************************************************************************** @@ -315,22 +297,7 @@ NTSTATUS WINAPI NtCreateEvent( PHANDLE EventHandle, ACCESS_MASK DesiredAccess, */ NTSTATUS WINAPI NtOpenEvent( HANDLE *handle, ACCESS_MASK access, const OBJECT_ATTRIBUTES *attr ) { - NTSTATUS ret; - - if ((ret = validate_open_object_attributes( attr ))) return ret; - - SERVER_START_REQ( open_event ) - { - req->access = access; - req->attributes = attr->Attributes; - req->rootdir = wine_server_obj_handle( attr->RootDirectory ); - if (attr->ObjectName) - wine_server_add_data( req, attr->ObjectName->Buffer, attr->ObjectName->Length ); - ret = wine_server_call( req ); - *handle = wine_server_ptr_handle( reply->handle ); - } - SERVER_END_REQ; - return ret; + return unix_funcs->NtOpenEvent( handle, access, attr ); } @@ -340,16 +307,7 @@ NTSTATUS WINAPI NtOpenEvent( HANDLE *handle, ACCESS_MASK access, const OBJECT_AT */ NTSTATUS WINAPI NtSetEvent( HANDLE handle, LONG *prev_state ) { - NTSTATUS ret; - SERVER_START_REQ( event_op ) - { - req->handle = wine_server_obj_handle( handle ); - req->op = SET_EVENT; - ret = wine_server_call( req ); - if (!ret && prev_state) *prev_state = reply->state; - } - SERVER_END_REQ; - return ret; + return unix_funcs->NtSetEvent( handle, prev_state ); } /****************************************************************************** @@ -357,16 +315,7 @@ NTSTATUS WINAPI NtSetEvent( HANDLE handle, LONG *prev_state ) */ NTSTATUS WINAPI NtResetEvent( HANDLE handle, LONG *prev_state ) { - NTSTATUS ret; - SERVER_START_REQ( event_op ) - { - req->handle = wine_server_obj_handle( handle ); - req->op = RESET_EVENT; - ret = wine_server_call( req ); - if (!ret && prev_state) *prev_state = reply->state; - } - SERVER_END_REQ; - return ret; + return unix_funcs->NtResetEvent( handle, prev_state ); } /****************************************************************************** @@ -377,7 +326,7 @@ NTSTATUS WINAPI NtResetEvent( HANDLE handle, LONG *prev_state ) */ NTSTATUS WINAPI NtClearEvent ( HANDLE handle ) { - return NtResetEvent( handle, NULL ); + return unix_funcs->NtClearEvent( handle ); } /****************************************************************************** @@ -388,17 +337,7 @@ NTSTATUS WINAPI NtClearEvent ( HANDLE handle ) */ NTSTATUS WINAPI NtPulseEvent( HANDLE handle, LONG *prev_state ) { - NTSTATUS ret; - - SERVER_START_REQ( event_op ) - { - req->handle = wine_server_obj_handle( handle ); - req->op = PULSE_EVENT; - ret = wine_server_call( req ); - if (!ret && prev_state) *prev_state = reply->state; - } - SERVER_END_REQ; - return ret; + return unix_funcs->NtPulseEvent( handle, prev_state ); } /****************************************************************************** @@ -407,33 +346,7 @@ NTSTATUS WINAPI NtPulseEvent( HANDLE handle, LONG *prev_state ) NTSTATUS WINAPI NtQueryEvent( HANDLE handle, EVENT_INFORMATION_CLASS class, void *info, ULONG len, ULONG *ret_len ) { - NTSTATUS ret; - EVENT_BASIC_INFORMATION *out = info; - - TRACE("(%p, %u, %p, %u, %p)\n", handle, class, info, len, ret_len); - - if (class != EventBasicInformation) - { - FIXME("(%p, %d, %d) Unknown class\n", - handle, class, len); - return STATUS_INVALID_INFO_CLASS; - } - - if (len != sizeof(EVENT_BASIC_INFORMATION)) return STATUS_INFO_LENGTH_MISMATCH; - - SERVER_START_REQ( query_event ) - { - req->handle = wine_server_obj_handle( handle ); - if (!(ret = wine_server_call( req ))) - { - out->EventType = reply->manual_reset ? NotificationEvent : SynchronizationEvent; - out->EventState = reply->state; - if (ret_len) *ret_len = sizeof(EVENT_BASIC_INFORMATION); - } - } - SERVER_END_REQ; - - return ret; + return unix_funcs->NtQueryEvent( handle, class, info, len, ret_len ); } /* diff --git a/dlls/ntdll/unix/loader.c b/dlls/ntdll/unix/loader.c index 51012be2bd5..83b44c24e98 100644 --- a/dlls/ntdll/unix/loader.c +++ b/dlls/ntdll/unix/loader.c @@ -985,7 +985,9 @@ static struct unix_funcs unix_funcs = { NtAllocateVirtualMemory, NtAreMappedFilesTheSame, + NtClearEvent, NtClose, + NtCreateEvent, NtCreateSemaphore, NtCurrentTeb, NtDelayExecution, @@ -996,15 +998,20 @@ static struct unix_funcs unix_funcs = NtGetWriteWatch, NtLockVirtualMemory, NtMapViewOfSection, + NtOpenEvent, NtOpenSemaphore, NtProtectVirtualMemory, + NtPulseEvent, + NtQueryEvent, NtQuerySection, NtQuerySemaphore, NtQueryVirtualMemory, NtReadVirtualMemory, NtReleaseSemaphore, + NtResetEvent, NtResetWriteWatch, NtSetContextThread, + NtSetEvent, NtSetLdtEntries, NtSignalAndWaitForSingleObject, NtUnlockVirtualMemory, diff --git a/dlls/ntdll/unix/sync.c b/dlls/ntdll/unix/sync.c index 5c5bb8730ce..427310f6c83 100644 --- a/dlls/ntdll/unix/sync.c +++ b/dlls/ntdll/unix/sync.c @@ -274,6 +274,160 @@ NTSTATUS WINAPI NtReleaseSemaphore( HANDLE handle, ULONG count, ULONG *previous } +/************************************************************************** + * NtCreateEvent (NTDLL.@) + */ +NTSTATUS WINAPI NtCreateEvent( HANDLE *handle, ACCESS_MASK access, const OBJECT_ATTRIBUTES *attr, + EVENT_TYPE type, BOOLEAN state ) +{ + NTSTATUS ret; + data_size_t len; + struct object_attributes *objattr; + + if ((ret = alloc_object_attributes( attr, &objattr, &len ))) return ret; + + SERVER_START_REQ( create_event ) + { + req->access = access; + req->manual_reset = (type == NotificationEvent); + req->initial_state = state; + wine_server_add_data( req, objattr, len ); + ret = wine_server_call( req ); + *handle = wine_server_ptr_handle( reply->handle ); + } + SERVER_END_REQ; + + RtlFreeHeap( GetProcessHeap(), 0, objattr ); + return ret; +} + + +/****************************************************************************** + * NtOpenEvent (NTDLL.@) + */ +NTSTATUS WINAPI NtOpenEvent( HANDLE *handle, ACCESS_MASK access, const OBJECT_ATTRIBUTES *attr ) +{ + NTSTATUS ret; + + if ((ret = validate_open_object_attributes( attr ))) return ret; + + SERVER_START_REQ( open_event ) + { + req->access = access; + req->attributes = attr->Attributes; + req->rootdir = wine_server_obj_handle( attr->RootDirectory ); + if (attr->ObjectName) + wine_server_add_data( req, attr->ObjectName->Buffer, attr->ObjectName->Length ); + ret = wine_server_call( req ); + *handle = wine_server_ptr_handle( reply->handle ); + } + SERVER_END_REQ; + return ret; +} + + +/****************************************************************************** + * NtSetEvent (NTDLL.@) + */ +NTSTATUS WINAPI NtSetEvent( HANDLE handle, LONG *prev_state ) +{ + NTSTATUS ret; + + SERVER_START_REQ( event_op ) + { + req->handle = wine_server_obj_handle( handle ); + req->op = SET_EVENT; + ret = wine_server_call( req ); + if (!ret && prev_state) *prev_state = reply->state; + } + SERVER_END_REQ; + return ret; +} + + +/****************************************************************************** + * NtResetEvent (NTDLL.@) + */ +NTSTATUS WINAPI NtResetEvent( HANDLE handle, LONG *prev_state ) +{ + NTSTATUS ret; + + SERVER_START_REQ( event_op ) + { + req->handle = wine_server_obj_handle( handle ); + req->op = RESET_EVENT; + ret = wine_server_call( req ); + if (!ret && prev_state) *prev_state = reply->state; + } + SERVER_END_REQ; + return ret; +} + + +/****************************************************************************** + * NtClearEvent (NTDLL.@) + */ +NTSTATUS WINAPI NtClearEvent( HANDLE handle ) +{ + /* FIXME: same as NtResetEvent ??? */ + return NtResetEvent( handle, NULL ); +} + + +/****************************************************************************** + * NtPulseEvent (NTDLL.@) + */ +NTSTATUS WINAPI NtPulseEvent( HANDLE handle, LONG *prev_state ) +{ + NTSTATUS ret; + + SERVER_START_REQ( event_op ) + { + req->handle = wine_server_obj_handle( handle ); + req->op = PULSE_EVENT; + ret = wine_server_call( req ); + if (!ret && prev_state) *prev_state = reply->state; + } + SERVER_END_REQ; + return ret; +} + + +/****************************************************************************** + * NtQueryEvent (NTDLL.@) + */ +NTSTATUS WINAPI NtQueryEvent( HANDLE handle, EVENT_INFORMATION_CLASS class, + void *info, ULONG len, ULONG *ret_len ) +{ + NTSTATUS ret; + EVENT_BASIC_INFORMATION *out = info; + + TRACE("(%p, %u, %p, %u, %p)\n", handle, class, info, len, ret_len); + + if (class != EventBasicInformation) + { + FIXME("(%p, %d, %d) Unknown class\n", + handle, class, len); + return STATUS_INVALID_INFO_CLASS; + } + + if (len != sizeof(EVENT_BASIC_INFORMATION)) return STATUS_INFO_LENGTH_MISMATCH; + + SERVER_START_REQ( query_event ) + { + req->handle = wine_server_obj_handle( handle ); + if (!(ret = wine_server_call( req ))) + { + out->EventType = reply->manual_reset ? NotificationEvent : SynchronizationEvent; + out->EventState = reply->state; + if (ret_len) *ret_len = sizeof(EVENT_BASIC_INFORMATION); + } + } + SERVER_END_REQ; + return ret; +} + + /****************************************************************** * NtWaitForMultipleObjects (NTDLL.@) */ diff --git a/dlls/ntdll/unixlib.h b/dlls/ntdll/unixlib.h index 9c1c184554f..8aa11065ae9 100644 --- a/dlls/ntdll/unixlib.h +++ b/dlls/ntdll/unixlib.h @@ -28,7 +28,7 @@ struct ldt_copy; struct msghdr; /* increment this when you change the function table */ -#define NTDLL_UNIXLIB_VERSION 22 +#define NTDLL_UNIXLIB_VERSION 23 struct unix_funcs { @@ -36,7 +36,10 @@ struct unix_funcs NTSTATUS (WINAPI *NtAllocateVirtualMemory)( HANDLE process, PVOID *ret, ULONG_PTR zero_bits, SIZE_T *size_ptr, ULONG type, ULONG protect ); NTSTATUS (WINAPI *NtAreMappedFilesTheSame)(PVOID addr1, PVOID addr2); + NTSTATUS (WINAPI *NtClearEvent)( HANDLE handle ); NTSTATUS (WINAPI *NtClose)( HANDLE handle ); + NTSTATUS (WINAPI *NtCreateEvent)( HANDLE *handle, ACCESS_MASK access, + const OBJECT_ATTRIBUTES *attr, EVENT_TYPE type, BOOLEAN state ); NTSTATUS (WINAPI *NtCreateSemaphore)( HANDLE *handle, ACCESS_MASK access, const OBJECT_ATTRIBUTES *attr, LONG initial, LONG max ); TEB * (WINAPI *NtCurrentTeb)(void); @@ -56,10 +59,15 @@ struct unix_funcs ULONG_PTR zero_bits, SIZE_T commit_size, const LARGE_INTEGER *offset_ptr, SIZE_T *size_ptr, SECTION_INHERIT inherit, ULONG alloc_type, ULONG protect ); + NTSTATUS (WINAPI *NtOpenEvent)( HANDLE *handle, ACCESS_MASK access, + const OBJECT_ATTRIBUTES *attr ); NTSTATUS (WINAPI *NtOpenSemaphore)( HANDLE *handle, ACCESS_MASK access, const OBJECT_ATTRIBUTES *attr ); NTSTATUS (WINAPI *NtProtectVirtualMemory)( HANDLE process, PVOID *addr_ptr, SIZE_T *size_ptr, ULONG new_prot, ULONG *old_prot ); + NTSTATUS (WINAPI *NtPulseEvent)( HANDLE handle, LONG *prev_state ); + NTSTATUS (WINAPI *NtQueryEvent)( HANDLE handle, EVENT_INFORMATION_CLASS class, + void *info, ULONG len, ULONG *ret_len ); NTSTATUS (WINAPI *NtQuerySection)( HANDLE handle, SECTION_INFORMATION_CLASS class, void *ptr, SIZE_T size, SIZE_T *ret_size ); NTSTATUS (WINAPI *NtQuerySemaphore)( HANDLE handle, SEMAPHORE_INFORMATION_CLASS class, @@ -70,8 +78,10 @@ struct unix_funcs NTSTATUS (WINAPI *NtReadVirtualMemory)( HANDLE process, const void *addr, void *buffer, SIZE_T size, SIZE_T *bytes_read ); NTSTATUS (WINAPI *NtReleaseSemaphore)( HANDLE handle, ULONG count, ULONG *previous ); + NTSTATUS (WINAPI *NtResetEvent)( HANDLE handle, LONG *prev_state ); NTSTATUS (WINAPI *NtResetWriteWatch)( HANDLE process, PVOID base, SIZE_T size ); NTSTATUS (WINAPI *NtSetContextThread)( HANDLE handle, const CONTEXT *context ); + NTSTATUS (WINAPI *NtSetEvent)( HANDLE handle, LONG *prev_state ); NTSTATUS (WINAPI *NtSetLdtEntries)( ULONG sel1, LDT_ENTRY entry1, ULONG sel2, LDT_ENTRY entry2 ); NTSTATUS (WINAPI *NtSignalAndWaitForSingleObject)( HANDLE signal, HANDLE wait, BOOLEAN alertable, const LARGE_INTEGER *timeout );