diff --git a/dlls/kernel/toolhelp.c b/dlls/kernel/toolhelp.c index e4872f77292aae23df1366cdd6831ba51e515313..077308cc314b61c768fd6753b891af0778070ef3 100644 --- a/dlls/kernel/toolhelp.c +++ b/dlls/kernel/toolhelp.c @@ -184,7 +184,7 @@ FARPROC16 tmp; */ HANDLE WINAPI CreateToolhelp32Snapshot( DWORD flags, DWORD process ) { - struct create_snapshot_request *req = get_req_buffer(); + HANDLE ret; TRACE("%lx,%lx\n", flags, process ); if (!(flags & (TH32CS_SNAPPROCESS|TH32CS_SNAPTHREAD|TH32CS_SNAPMODULE))) @@ -193,13 +193,19 @@ HANDLE WINAPI CreateToolhelp32Snapshot( DWORD flags, DWORD process ) SetLastError( ERROR_CALL_NOT_IMPLEMENTED ); return INVALID_HANDLE_VALUE; } - + /* Now do the snapshot */ - req->flags = flags & ~TH32CS_INHERIT; - req->inherit = (flags & TH32CS_INHERIT) != 0; - req->pid = (void *)process; - server_call( REQ_CREATE_SNAPSHOT ); - return req->handle; + SERVER_START_REQ + { + struct create_snapshot_request *req = server_alloc_req( sizeof(*req), 0 ); + req->flags = flags & ~TH32CS_INHERIT; + req->inherit = (flags & TH32CS_INHERIT) != 0; + req->pid = (void *)process; + server_call( REQ_CREATE_SNAPSHOT ); + ret = req->handle; + } + SERVER_END_REQ; + return ret; } @@ -210,7 +216,7 @@ HANDLE WINAPI CreateToolhelp32Snapshot( DWORD flags, DWORD process ) */ static BOOL TOOLHELP_Thread32Next( HANDLE handle, LPTHREADENTRY32 lpte, BOOL first ) { - struct next_thread_request *req = get_req_buffer(); + BOOL ret; if (lpte->dwSize < sizeof(THREADENTRY32)) { @@ -218,16 +224,23 @@ static BOOL TOOLHELP_Thread32Next( HANDLE handle, LPTHREADENTRY32 lpte, BOOL fir ERR("Result buffer too small (req: %d, was: %ld)\n", sizeof(THREADENTRY32), lpte->dwSize); return FALSE; } - req->handle = handle; - req->reset = first; - if (server_call( REQ_NEXT_THREAD )) return FALSE; - lpte->cntUsage = req->count; - lpte->th32ThreadID = (DWORD)req->tid; - lpte->th32OwnerProcessID = (DWORD)req->pid; - lpte->tbBasePri = req->base_pri; - lpte->tbDeltaPri = req->delta_pri; - lpte->dwFlags = 0; /* SDK: "reserved; do not use" */ - return TRUE; + SERVER_START_REQ + { + struct next_thread_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = handle; + req->reset = first; + if ((ret = !server_call( REQ_NEXT_THREAD ))) + { + lpte->cntUsage = req->count; + lpte->th32ThreadID = (DWORD)req->tid; + lpte->th32OwnerProcessID = (DWORD)req->pid; + lpte->tbBasePri = req->base_pri; + lpte->tbDeltaPri = req->delta_pri; + lpte->dwFlags = 0; /* SDK: "reserved; do not use" */ + } + } + SERVER_END_REQ; + return ret; } /*********************************************************************** @@ -257,7 +270,7 @@ BOOL WINAPI Thread32Next(HANDLE hSnapshot, LPTHREADENTRY32 lpte) */ static BOOL TOOLHELP_Process32Next( HANDLE handle, LPPROCESSENTRY32 lppe, BOOL first ) { - struct next_process_request *req = get_req_buffer(); + BOOL ret; if (lppe->dwSize < sizeof(PROCESSENTRY32)) { @@ -265,19 +278,26 @@ static BOOL TOOLHELP_Process32Next( HANDLE handle, LPPROCESSENTRY32 lppe, BOOL f ERR("Result buffer too small (req: %d, was: %ld)\n", sizeof(PROCESSENTRY32), lppe->dwSize); return FALSE; } - req->handle = handle; - req->reset = first; - if (server_call( REQ_NEXT_PROCESS )) return FALSE; - lppe->cntUsage = req->count; - lppe->th32ProcessID = (DWORD)req->pid; - lppe->th32DefaultHeapID = 0; /* FIXME */ - lppe->th32ModuleID = 0; /* FIXME */ - lppe->cntThreads = req->threads; - lppe->th32ParentProcessID = 0; /* FIXME */ - lppe->pcPriClassBase = req->priority; - lppe->dwFlags = -1; /* FIXME */ - lppe->szExeFile[0] = 0; /* FIXME */ - return TRUE; + SERVER_START_REQ + { + struct next_process_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = handle; + req->reset = first; + if ((ret = !server_call( REQ_NEXT_PROCESS ))) + { + lppe->cntUsage = req->count; + lppe->th32ProcessID = (DWORD)req->pid; + lppe->th32DefaultHeapID = 0; /* FIXME */ + lppe->th32ModuleID = 0; /* FIXME */ + lppe->cntThreads = req->threads; + lppe->th32ParentProcessID = 0; /* FIXME */ + lppe->pcPriClassBase = req->priority; + lppe->dwFlags = -1; /* FIXME */ + lppe->szExeFile[0] = 0; /* FIXME */ + } + } + SERVER_END_REQ; + return ret; } @@ -309,27 +329,34 @@ BOOL WINAPI Process32Next(HANDLE hSnapshot, LPPROCESSENTRY32 lppe) */ static BOOL TOOLHELP_Module32Next( HANDLE handle, LPMODULEENTRY32 lpme, BOOL first ) { - struct next_module_request *req = get_req_buffer(); - + BOOL ret; + if (lpme->dwSize < sizeof (MODULEENTRY32)) { SetLastError( ERROR_INSUFFICIENT_BUFFER ); ERR("Result buffer too small (req: %d, was: %ld)\n", sizeof(MODULEENTRY32), lpme->dwSize); return FALSE; } - req->handle = handle; - req->reset = first; - if (server_call( REQ_NEXT_MODULE )) return FALSE; - lpme->th32ModuleID = 0; /* toolhelp internal id, never used */ - lpme->th32ProcessID = (DWORD)req->pid; - lpme->GlblcntUsage = 0; /* FIXME */ - lpme->ProccntUsage = 0; /* FIXME */ - lpme->modBaseAddr = req->base; - lpme->modBaseSize = 0; /* FIXME */ - lpme->hModule = (DWORD)req->base; - lpme->szModule[0] = 0; /* FIXME */ - lpme->szExePath[0] = 0; /* FIXME */ - return TRUE; + SERVER_START_REQ + { + struct next_module_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = handle; + req->reset = first; + if ((ret = !server_call( REQ_NEXT_MODULE ))) + { + lpme->th32ModuleID = 0; /* toolhelp internal id, never used */ + lpme->th32ProcessID = (DWORD)req->pid; + lpme->GlblcntUsage = 0; /* FIXME */ + lpme->ProccntUsage = 0; /* FIXME */ + lpme->modBaseAddr = req->base; + lpme->modBaseSize = 0; /* FIXME */ + lpme->hModule = (DWORD)req->base; + lpme->szModule[0] = 0; /* FIXME */ + lpme->szExePath[0] = 0; /* FIXME */ + } + } + SERVER_END_REQ; + return ret; } /*********************************************************************** diff --git a/dlls/ntdll/exception.c b/dlls/ntdll/exception.c index ed3878ec93d8676d8632b4eaaf445f22bd0f223b..6ec746a2b9c495ebdad3e26a01fb8c72a614620d 100644 --- a/dlls/ntdll/exception.c +++ b/dlls/ntdll/exception.c @@ -86,18 +86,24 @@ static DWORD EXC_CallHandler( EXCEPTION_RECORD *record, EXCEPTION_FRAME *frame, /********************************************************************** - * EXC_SendEvent + * send_debug_event * * Send an EXCEPTION_DEBUG_EVENT event to the debugger. */ static inline int send_debug_event( EXCEPTION_RECORD *rec, int first_chance, CONTEXT *context ) { - struct exception_event_request *req = get_req_buffer(); - req->record = *rec; - req->first = first_chance; - req->context = *context; - if (!server_call_noerr( REQ_EXCEPTION_EVENT )) *context = req->context; - return req->status; + int ret; + SERVER_START_REQ + { + struct exception_event_request *req = server_alloc_req( sizeof(*req), 0 ); + req->record = *rec; + req->first = first_chance; + req->context = *context; + if (!server_call_noerr( REQ_EXCEPTION_EVENT )) *context = req->context; + ret = req->status; + } + SERVER_END_REQ; + return ret; } diff --git a/dlls/ntdll/nt.c b/dlls/ntdll/nt.c index e9b90ef286f08d0353712789842464875cf6c929..092a4e3689ea079dfce073c5aef69e4311dda553 100644 --- a/dlls/ntdll/nt.c +++ b/dlls/ntdll/nt.c @@ -75,10 +75,17 @@ NTSTATUS WINAPI NtQueryTimerResolution(DWORD x1,DWORD x2,DWORD x3) NTSTATUS WINAPI NtTerminateProcess( HANDLE handle, LONG exit_code ) { NTSTATUS ret; - struct terminate_process_request *req = get_req_buffer(); - req->handle = handle; - req->exit_code = exit_code; - if (!(ret = server_call_noerr( REQ_TERMINATE_PROCESS )) && req->self) exit( exit_code ); + BOOL self; + SERVER_START_REQ + { + struct terminate_process_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = handle; + req->exit_code = exit_code; + ret = server_call_noerr( REQ_TERMINATE_PROCESS ); + self = !ret && req->self; + } + SERVER_END_REQ; + if (self) exit( exit_code ); return ret; } @@ -134,24 +141,35 @@ NTSTATUS WINAPI NtResumeThread( return 0; } + /****************************************************************************** * NtTerminateThread [NTDLL] */ -NTSTATUS WINAPI NtTerminateThread( IN HANDLE handle, - IN NTSTATUS exit_code ) +NTSTATUS WINAPI NtTerminateThread( HANDLE handle, LONG exit_code ) { NTSTATUS ret; - struct terminate_thread_request *req = get_req_buffer(); - req->handle = handle; - req->exit_code = exit_code; - if (!(ret = server_call_noerr( REQ_TERMINATE_THREAD )) && req->self) + BOOL self, last; + + SERVER_START_REQ { - if (req->last) exit( exit_code ); + struct terminate_thread_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = handle; + req->exit_code = exit_code; + ret = server_call_noerr( REQ_TERMINATE_THREAD ); + self = !ret && req->self; + last = req->last; + } + SERVER_END_REQ; + + if (self) + { + if (last) exit( exit_code ); else SYSDEPS_ExitThread( exit_code ); } return ret; } + /****************************************************************************** * NtQueryInformationThread [NTDLL.] * diff --git a/dlls/ntdll/om.c b/dlls/ntdll/om.c index 8a3da0620fede23d973f2128c3101501b4d0e7a6..3e31fc8c3aa1ed56a915ae0eba38aeeb6018c08c 100644 --- a/dlls/ntdll/om.c +++ b/dlls/ntdll/om.c @@ -215,9 +215,15 @@ NTSTATUS WINAPI NtDuplicateObject( */ NTSTATUS WINAPI NtClose( HANDLE Handle ) { - struct close_handle_request *req = get_req_buffer(); - req->handle = Handle; - return server_call_noerr( REQ_CLOSE_HANDLE ); + NTSTATUS ret; + SERVER_START_REQ + { + struct close_handle_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = Handle; + ret = server_call_noerr( REQ_CLOSE_HANDLE ); + } + SERVER_END_REQ; + return ret; } /****************************************************************************** diff --git a/dlls/ntdll/sync.c b/dlls/ntdll/sync.c index e701d307aa141798c9514d8fba6a1c637fdf13b7..7409b4a667eb7c46cbcb1315859cb5becefcc6f0 100644 --- a/dlls/ntdll/sync.c +++ b/dlls/ntdll/sync.c @@ -16,17 +16,6 @@ DEFAULT_DEBUG_CHANNEL(ntdll); -/* copy a key name into the request buffer */ -static inline NTSTATUS copy_nameU( LPWSTR Dest, const OBJECT_ATTRIBUTES *attr ) -{ - if (attr && attr->ObjectName && attr->ObjectName->Buffer) - { - if ((attr->ObjectName->Length) > MAX_PATH) return STATUS_BUFFER_OVERFLOW; - strcpyW( Dest, attr->ObjectName->Buffer ); - } - else Dest[0] = 0; - return STATUS_SUCCESS; -} /* * Semaphores @@ -35,44 +24,56 @@ static inline NTSTATUS copy_nameU( LPWSTR Dest, const OBJECT_ATTRIBUTES *attr ) /****************************************************************************** * NtCreateSemaphore */ -NTSTATUS WINAPI NtCreateSemaphore( - OUT PHANDLE SemaphoreHandle, - IN ACCESS_MASK DesiredAccess, - IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, - IN ULONG InitialCount, - IN ULONG MaximumCount) +NTSTATUS WINAPI NtCreateSemaphore( OUT PHANDLE SemaphoreHandle, + IN ACCESS_MASK access, + IN const OBJECT_ATTRIBUTES *attr OPTIONAL, + IN ULONG InitialCount, + IN ULONG MaximumCount ) { - struct create_semaphore_request *req = get_req_buffer(); + DWORD len = attr && attr->ObjectName ? attr->ObjectName->Length : 0; NTSTATUS ret; if ((MaximumCount <= 0) || (InitialCount < 0) || (InitialCount > MaximumCount)) return STATUS_INVALID_PARAMETER; *SemaphoreHandle = 0; - req->initial = InitialCount; - req->max = MaximumCount; - req->inherit = ObjectAttributes && (ObjectAttributes->Attributes & OBJ_INHERIT); - if (!(ret = copy_nameU( req->name, ObjectAttributes )) && - !(ret = server_call_noerr( REQ_CREATE_SEMAPHORE ))) *SemaphoreHandle = req->handle; + + SERVER_START_REQ + { + struct create_semaphore_request *req = server_alloc_req( sizeof(*req), len ); + req->initial = InitialCount; + req->max = MaximumCount; + req->inherit = attr && (attr->Attributes & OBJ_INHERIT); + if (len) memcpy( server_data_ptr(req), attr->ObjectName->Buffer, len ); + if (!(ret = server_call_noerr( REQ_CREATE_SEMAPHORE ))) + *SemaphoreHandle = req->handle; + } + SERVER_END_REQ; return ret; } /****************************************************************************** * NtOpenSemaphore */ -NTSTATUS WINAPI NtOpenSemaphore( - OUT PHANDLE SemaphoreHandle, - IN ACCESS_MASK DesiredAcces, - IN POBJECT_ATTRIBUTES ObjectAttributes) +NTSTATUS WINAPI NtOpenSemaphore( OUT PHANDLE SemaphoreHandle, + IN ACCESS_MASK access, + IN const OBJECT_ATTRIBUTES *attr ) { - struct open_semaphore_request *req = get_req_buffer(); + DWORD len = attr && attr->ObjectName ? attr->ObjectName->Length : 0; NTSTATUS ret; *SemaphoreHandle = 0; - req->access = DesiredAcces; - req->inherit = ObjectAttributes && (ObjectAttributes->Attributes & OBJ_INHERIT); - if (!(ret = copy_nameU( req->name, ObjectAttributes )) && - !(ret = server_call_noerr( REQ_OPEN_SEMAPHORE ))) *SemaphoreHandle = req->handle; + + SERVER_START_REQ + { + struct open_semaphore_request *req = server_alloc_req( sizeof(*req), len ); + req->access = access; + req->inherit = attr && (attr->Attributes & OBJ_INHERIT); + if (len) memcpy( server_data_ptr(req), attr->ObjectName->Buffer, len ); + if (!(ret = server_call_noerr( REQ_OPEN_SEMAPHORE ))) + *SemaphoreHandle = req->handle; + } + SERVER_END_REQ; return ret; } @@ -90,25 +91,24 @@ NTSTATUS WINAPI NtQuerySemaphore( SemaphoreHandle, SemaphoreInformationClass, SemaphoreInformation, Length, ReturnLength); return STATUS_SUCCESS; } + /****************************************************************************** * NtReleaseSemaphore */ -NTSTATUS WINAPI NtReleaseSemaphore( - IN HANDLE SemaphoreHandle, - IN ULONG ReleaseCount, - IN PULONG PreviousCount) +NTSTATUS WINAPI NtReleaseSemaphore( HANDLE handle, ULONG count, PULONG previous ) { - struct release_semaphore_request *req = get_req_buffer(); NTSTATUS ret; - - if (ReleaseCount < 0) return STATUS_INVALID_PARAMETER; - - req->handle = SemaphoreHandle; - req->count = ReleaseCount; - if (!(ret = server_call_noerr( REQ_RELEASE_SEMAPHORE ))) + SERVER_START_REQ { - if (PreviousCount) *PreviousCount = req->prev_count; + struct release_semaphore_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = handle; + req->count = count; + if (!(ret = server_call_noerr( REQ_RELEASE_SEMAPHORE ))) + { + if (previous) *previous = req->prev_count; + } } + SERVER_END_REQ; return ret; } @@ -122,19 +122,25 @@ NTSTATUS WINAPI NtReleaseSemaphore( NTSTATUS WINAPI NtCreateEvent( OUT PHANDLE EventHandle, IN ACCESS_MASK DesiredAccess, - IN POBJECT_ATTRIBUTES ObjectAttributes, + IN const OBJECT_ATTRIBUTES *attr, IN BOOLEAN ManualReset, IN BOOLEAN InitialState) { - struct create_event_request *req = get_req_buffer(); + DWORD len = attr && attr->ObjectName ? attr->ObjectName->Length : 0; NTSTATUS ret; *EventHandle = 0; - req->manual_reset = ManualReset; - req->initial_state = InitialState; - req->inherit = ObjectAttributes && (ObjectAttributes->Attributes & OBJ_INHERIT); - if (!(ret = copy_nameU( req->name, ObjectAttributes )) && - !(ret = server_call_noerr( REQ_CREATE_EVENT ))) *EventHandle = req->handle; + + SERVER_START_REQ + { + struct create_event_request *req = server_alloc_req( sizeof(*req), len ); + req->manual_reset = ManualReset; + req->initial_state = InitialState; + req->inherit = attr && (attr->Attributes & OBJ_INHERIT); + if (len) memcpy( server_data_ptr(req), attr->ObjectName->Buffer, len ); + if (!(ret = server_call_noerr( REQ_CREATE_EVENT ))) *EventHandle = req->handle; + } + SERVER_END_REQ; return ret; } @@ -144,16 +150,23 @@ NTSTATUS WINAPI NtCreateEvent( NTSTATUS WINAPI NtOpenEvent( OUT PHANDLE EventHandle, IN ACCESS_MASK DesiredAccess, - IN POBJECT_ATTRIBUTES ObjectAttributes) + IN const OBJECT_ATTRIBUTES *attr ) { - struct open_event_request *req = get_req_buffer(); + DWORD len = attr && attr->ObjectName ? attr->ObjectName->Length : 0; NTSTATUS ret; *EventHandle = 0; - req->access = DesiredAccess; - req->inherit = ObjectAttributes && (ObjectAttributes->Attributes & OBJ_INHERIT); - if (!(ret = copy_nameU( req->name, ObjectAttributes )) && - !(ret = server_call_noerr( REQ_OPEN_EVENT ))) *EventHandle = req->handle; + + SERVER_START_REQ + { + struct open_event_request *req = server_alloc_req( sizeof(*req), len ); + + req->access = DesiredAccess; + req->inherit = attr && (attr->Attributes & OBJ_INHERIT); + if (len) memcpy( server_data_ptr(req), attr->ObjectName->Buffer, len ); + if (!(ret = server_call_noerr( REQ_OPEN_EVENT ))) *EventHandle = req->handle; + } + SERVER_END_REQ; return ret; } @@ -161,29 +174,40 @@ NTSTATUS WINAPI NtOpenEvent( /****************************************************************************** * NtSetEvent */ -NTSTATUS WINAPI NtSetEvent( - IN HANDLE EventHandle, - PULONG NumberOfThreadsReleased) +NTSTATUS WINAPI NtSetEvent( HANDLE handle, PULONG NumberOfThreadsReleased ) { - struct event_op_request *req = get_req_buffer(); - FIXME("(0x%08x,%p)\n", EventHandle, NumberOfThreadsReleased); - req->handle = EventHandle; - req->op = SET_EVENT; - return server_call_noerr( REQ_EVENT_OP ); + NTSTATUS ret; + FIXME("(0x%08x,%p)\n", handle, NumberOfThreadsReleased); + SERVER_START_REQ + { + struct event_op_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = handle; + req->op = SET_EVENT; + ret = server_call_noerr( REQ_EVENT_OP ); + } + SERVER_END_REQ; + return ret; } /****************************************************************************** * NtResetEvent */ -NTSTATUS WINAPI NtResetEvent( - IN HANDLE EventHandle, - PULONG NumberOfThreadsReleased) +NTSTATUS WINAPI NtResetEvent( HANDLE handle, PULONG NumberOfThreadsReleased ) { - struct event_op_request *req = get_req_buffer(); - FIXME("(0x%08x,%p)\n", EventHandle, NumberOfThreadsReleased); - req->handle = EventHandle; - req->op = RESET_EVENT; - return server_call_noerr( REQ_EVENT_OP ); + NTSTATUS ret; + + /* resetting an event can't release any thread... */ + if (NumberOfThreadsReleased) *NumberOfThreadsReleased = 0; + + SERVER_START_REQ + { + struct event_op_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = handle; + req->op = RESET_EVENT; + ret = server_call_noerr( REQ_EVENT_OP ); + } + SERVER_END_REQ; + return ret; } /****************************************************************************** @@ -192,10 +216,9 @@ NTSTATUS WINAPI NtResetEvent( * FIXME * same as NtResetEvent ??? */ -NTSTATUS WINAPI NtClearEvent ( - IN HANDLE EventHandle) +NTSTATUS WINAPI NtClearEvent ( HANDLE handle ) { - return NtResetEvent( EventHandle, NULL ); + return NtResetEvent( handle, NULL ); } /****************************************************************************** @@ -204,15 +227,19 @@ NTSTATUS WINAPI NtClearEvent ( * FIXME * PulseCount */ -NTSTATUS WINAPI NtPulseEvent( - IN HANDLE EventHandle, - IN PULONG PulseCount) +NTSTATUS WINAPI NtPulseEvent( HANDLE handle, PULONG PulseCount ) { - struct event_op_request *req = get_req_buffer(); - FIXME("(0x%08x,%p)\n", EventHandle, PulseCount); - req->handle = EventHandle; - req->op = PULSE_EVENT; - return server_call_noerr( REQ_EVENT_OP ); + NTSTATUS ret; + FIXME("(0x%08x,%p)\n", handle, PulseCount); + SERVER_START_REQ + { + struct event_op_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = handle; + req->op = PULSE_EVENT; + ret = server_call_noerr( REQ_EVENT_OP ); + } + SERVER_END_REQ; + return ret; } /****************************************************************************** diff --git a/files/change.c b/files/change.c index 80ea17e14eb67ea027532303b83bd94e279d7108..ab0741879986ca5d8716c8a4550de4a2198ee482 100644 --- a/files/change.c +++ b/files/change.c @@ -28,13 +28,19 @@ DEFAULT_DEBUG_CHANNEL(file); HANDLE WINAPI FindFirstChangeNotificationA( LPCSTR lpPathName, BOOL bWatchSubtree, DWORD dwNotifyFilter ) { - struct create_change_notification_request *req = get_req_buffer(); + HANDLE ret = -1; FIXME("this is not supported yet (non-trivial).\n"); - req->subtree = bWatchSubtree; - req->filter = dwNotifyFilter; - server_call( REQ_CREATE_CHANGE_NOTIFICATION ); - return req->handle; + + SERVER_START_REQ + { + struct create_change_notification_request *req = server_alloc_req( sizeof(*req), 0 ); + req->subtree = bWatchSubtree; + req->filter = dwNotifyFilter; + if (!server_call( REQ_CREATE_CHANGE_NOTIFICATION )) ret = req->handle; + } + SERVER_END_REQ; + return ret; } /**************************************************************************** diff --git a/files/file.c b/files/file.c index 1252f0b198c6bce975f4dd924cbe090ef7ab753b..c6197246d41eeb340a08a06dfd3502a5704e6062 100644 --- a/files/file.c +++ b/files/file.c @@ -368,14 +368,20 @@ HANDLE FILE_CreateFile( LPCSTR filename, DWORD access, DWORD sharing, */ HFILE FILE_CreateDevice( int client_id, DWORD access, LPSECURITY_ATTRIBUTES sa ) { - struct create_device_request *req = get_req_buffer(); - - req->access = access; - req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); - req->id = client_id; - SetLastError(0); - server_call( REQ_CREATE_DEVICE ); - return req->handle; + HFILE ret; + SERVER_START_REQ + { + struct create_device_request *req = server_alloc_req( sizeof(*req), 0 ); + + req->access = access; + req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); + req->id = client_id; + SetLastError(0); + server_call( REQ_CREATE_DEVICE ); + ret = req->handle; + } + SERVER_END_REQ; + return ret; } @@ -566,22 +572,29 @@ BOOL FILE_Stat( LPCSTR unixName, BY_HANDLE_FILE_INFORMATION *info ) DWORD WINAPI GetFileInformationByHandle( HANDLE hFile, BY_HANDLE_FILE_INFORMATION *info ) { - struct get_file_info_request *req = get_req_buffer(); - + DWORD ret; if (!info) return 0; - req->handle = hFile; - if (server_call( REQ_GET_FILE_INFO )) return 0; - RtlSecondsSince1970ToTime( req->write_time, &info->ftCreationTime ); - RtlSecondsSince1970ToTime( req->write_time, &info->ftLastWriteTime ); - RtlSecondsSince1970ToTime( req->access_time, &info->ftLastAccessTime ); - info->dwFileAttributes = req->attr; - info->dwVolumeSerialNumber = req->serial; - info->nFileSizeHigh = req->size_high; - info->nFileSizeLow = req->size_low; - info->nNumberOfLinks = req->links; - info->nFileIndexHigh = req->index_high; - info->nFileIndexLow = req->index_low; - return 1; + + SERVER_START_REQ + { + struct get_file_info_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = hFile; + if ((ret = !server_call( REQ_GET_FILE_INFO ))) + { + RtlSecondsSince1970ToTime( req->write_time, &info->ftCreationTime ); + RtlSecondsSince1970ToTime( req->write_time, &info->ftLastWriteTime ); + RtlSecondsSince1970ToTime( req->access_time, &info->ftLastAccessTime ); + info->dwFileAttributes = req->attr; + info->dwVolumeSerialNumber = req->serial; + info->nFileSizeHigh = req->size_high; + info->nFileSizeLow = req->size_low; + info->nNumberOfLinks = req->links; + info->nFileIndexHigh = req->index_high; + info->nFileIndexLow = req->index_low; + } + } + SERVER_END_REQ; + return ret; } @@ -1271,7 +1284,7 @@ HFILE WINAPI _lcreat( LPCSTR path, INT attr ) DWORD WINAPI SetFilePointer( HANDLE hFile, LONG distance, LONG *highword, DWORD method ) { - struct set_file_pointer_request *req = get_req_buffer(); + DWORD ret = 0xffffffff; if (highword && ((distance >= 0 && *highword != 0) || (distance < 0 && *highword != -1))) @@ -1280,20 +1293,28 @@ DWORD WINAPI SetFilePointer( HANDLE hFile, LONG distance, LONG *highword, "SetFilePointer(%08x,%08lx,%08lx,%08lx)\n", hFile,distance,*highword,method); SetLastError( ERROR_INVALID_PARAMETER ); - return 0xffffffff; + return ret; } TRACE("handle %d offset %ld origin %ld\n", hFile, distance, method ); - req->handle = hFile; - req->low = distance; - req->high = highword ? *highword : (distance >= 0) ? 0 : -1; - /* FIXME: assumes 1:1 mapping between Windows and Unix seek constants */ - req->whence = method; - SetLastError( 0 ); - if (server_call( REQ_SET_FILE_POINTER )) return 0xffffffff; - if (highword) *highword = req->new_high; - return req->new_low; + SERVER_START_REQ + { + struct set_file_pointer_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = hFile; + req->low = distance; + req->high = highword ? *highword : (distance >= 0) ? 0 : -1; + /* FIXME: assumes 1:1 mapping between Windows and Unix seek constants */ + req->whence = method; + SetLastError( 0 ); + if (!server_call( REQ_SET_FILE_POINTER )) + { + ret = req->new_low; + if (highword) *highword = req->new_high; + } + } + SERVER_END_REQ; + return ret; } @@ -1480,9 +1501,15 @@ UINT WINAPI SetHandleCount( UINT count ) */ BOOL WINAPI FlushFileBuffers( HANDLE hFile ) { - struct flush_file_request *req = get_req_buffer(); - req->handle = hFile; - return !server_call( REQ_FLUSH_FILE ); + BOOL ret; + SERVER_START_REQ + { + struct flush_file_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = hFile; + ret = !server_call( REQ_FLUSH_FILE ); + } + SERVER_END_REQ; + return ret; } @@ -1491,9 +1518,15 @@ BOOL WINAPI FlushFileBuffers( HANDLE hFile ) */ BOOL WINAPI SetEndOfFile( HANDLE hFile ) { - struct truncate_file_request *req = get_req_buffer(); - req->handle = hFile; - return !server_call( REQ_TRUNCATE_FILE ); + BOOL ret; + SERVER_START_REQ + { + struct truncate_file_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = hFile; + ret = !server_call( REQ_TRUNCATE_FILE ); + } + SERVER_END_REQ; + return ret; } @@ -1645,10 +1678,15 @@ int FILE_munmap( LPVOID start, DWORD size_high, DWORD size_low ) */ DWORD WINAPI GetFileType( HANDLE hFile ) { - struct get_file_info_request *req = get_req_buffer(); - req->handle = hFile; - if (server_call( REQ_GET_FILE_INFO )) return FILE_TYPE_UNKNOWN; - return req->type; + DWORD ret = FILE_TYPE_UNKNOWN; + SERVER_START_REQ + { + struct get_file_info_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = hFile; + if (!server_call( REQ_GET_FILE_INFO )) ret = req->type; + } + SERVER_END_REQ; + return ret; } @@ -1931,18 +1969,23 @@ BOOL WINAPI SetFileTime( HANDLE hFile, const FILETIME *lpLastAccessTime, const FILETIME *lpLastWriteTime ) { - struct set_file_time_request *req = get_req_buffer(); - - req->handle = hFile; - if (lpLastAccessTime) - req->access_time = DOSFS_FileTimeToUnixTime(lpLastAccessTime, NULL); - else - req->access_time = 0; /* FIXME */ - if (lpLastWriteTime) - req->write_time = DOSFS_FileTimeToUnixTime(lpLastWriteTime, NULL); - else - req->write_time = 0; /* FIXME */ - return !server_call( REQ_SET_FILE_TIME ); + BOOL ret; + SERVER_START_REQ + { + struct set_file_time_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = hFile; + if (lpLastAccessTime) + req->access_time = DOSFS_FileTimeToUnixTime(lpLastAccessTime, NULL); + else + req->access_time = 0; /* FIXME */ + if (lpLastWriteTime) + req->write_time = DOSFS_FileTimeToUnixTime(lpLastWriteTime, NULL); + else + req->write_time = 0; /* FIXME */ + ret = !server_call( REQ_SET_FILE_TIME ); + } + SERVER_END_REQ; + return ret; } @@ -1952,14 +1995,20 @@ BOOL WINAPI SetFileTime( HANDLE hFile, BOOL WINAPI LockFile( HANDLE hFile, DWORD dwFileOffsetLow, DWORD dwFileOffsetHigh, DWORD nNumberOfBytesToLockLow, DWORD nNumberOfBytesToLockHigh ) { - struct lock_file_request *req = get_req_buffer(); - - req->handle = hFile; - req->offset_low = dwFileOffsetLow; - req->offset_high = dwFileOffsetHigh; - req->count_low = nNumberOfBytesToLockLow; - req->count_high = nNumberOfBytesToLockHigh; - return !server_call( REQ_LOCK_FILE ); + BOOL ret; + SERVER_START_REQ + { + struct lock_file_request *req = server_alloc_req( sizeof(*req), 0 ); + + req->handle = hFile; + req->offset_low = dwFileOffsetLow; + req->offset_high = dwFileOffsetHigh; + req->count_low = nNumberOfBytesToLockLow; + req->count_high = nNumberOfBytesToLockHigh; + ret = !server_call( REQ_LOCK_FILE ); + } + SERVER_END_REQ; + return ret; } /************************************************************************** @@ -1999,14 +2048,20 @@ BOOL WINAPI LockFileEx( HANDLE hFile, DWORD flags, DWORD reserved, BOOL WINAPI UnlockFile( HANDLE hFile, DWORD dwFileOffsetLow, DWORD dwFileOffsetHigh, DWORD nNumberOfBytesToUnlockLow, DWORD nNumberOfBytesToUnlockHigh ) { - struct unlock_file_request *req = get_req_buffer(); - - req->handle = hFile; - req->offset_low = dwFileOffsetLow; - req->offset_high = dwFileOffsetHigh; - req->count_low = nNumberOfBytesToUnlockLow; - req->count_high = nNumberOfBytesToUnlockHigh; - return !server_call( REQ_UNLOCK_FILE ); + BOOL ret; + SERVER_START_REQ + { + struct unlock_file_request *req = server_alloc_req( sizeof(*req), 0 ); + + req->handle = hFile; + req->offset_low = dwFileOffsetLow; + req->offset_high = dwFileOffsetHigh; + req->count_low = nNumberOfBytesToUnlockLow; + req->count_high = nNumberOfBytesToUnlockHigh; + ret = !server_call( REQ_UNLOCK_FILE ); + } + SERVER_END_REQ; + return ret; } diff --git a/include/ntddk.h b/include/ntddk.h index 959bba21f2cd4b78942b26c9b043089a5d2538ea..73fadfce1871c52eb21ba99c8a63c4239d540c67 100644 --- a/include/ntddk.h +++ b/include/ntddk.h @@ -910,12 +910,10 @@ NTSTATUS WINAPI NtClose( HANDLE Handle); NTSTATUS WINAPI NtTerminateProcess( HANDLE handle, LONG exit_code ); +NTSTATUS WINAPI NtTerminateThread( HANDLE handle, LONG exit_code ); -NTSTATUS WINAPI NtCreateSemaphore( OUT PHANDLE SemaphoreHandle, - IN ACCESS_MASK DesiredAccess, - IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, - IN ULONG InitialCount, - IN ULONG MaximumCount); +NTSTATUS WINAPI NtCreateEvent(PHANDLE,ACCESS_MASK,const OBJECT_ATTRIBUTES *,BOOLEAN,BOOLEAN); +NTSTATUS WINAPI NtCreateSemaphore(PHANDLE,ACCESS_MASK,const OBJECT_ATTRIBUTES*,ULONG,ULONG); NTSTATUS WINAPI NtReleaseSemaphore( IN HANDLE SemaphoreHandle, IN ULONG ReleaseCount, IN PULONG PreviousCount); diff --git a/include/server.h b/include/server.h index 2c8b06d7c75fc68ec3ae5f4aae946b9cd5663d5f..777f396fedcd94751d1266e11a0acfb86a71da02 100644 --- a/include/server.h +++ b/include/server.h @@ -350,8 +350,7 @@ struct get_apc_request REQUEST_HEADER; /* request header */ OUT void* func; /* function to call */ OUT int type; /* function type */ - OUT int nb_args; /* number of arguments */ - OUT void* args[1]; /* function arguments */ + OUT VARARG(args,ptrs); /* function arguments */ }; enum apc_type { APC_NONE, APC_USER, APC_TIMER }; @@ -415,11 +414,10 @@ struct open_process_request struct select_request { REQUEST_HEADER; /* request header */ - IN int count; /* handles count */ IN int flags; /* wait flags (see below) */ IN int timeout; /* timeout in ms */ OUT int signaled; /* signaled handle */ - IN int handles[1]; /* handles to select on */ + IN VARARG(handles,ints); /* handles to select on */ }; #define SELECT_ALL 1 #define SELECT_ALERTABLE 2 @@ -434,7 +432,7 @@ struct create_event_request IN int initial_state; /* initial state of the event */ IN int inherit; /* inherit flag */ OUT int handle; /* handle to the event */ - IN WCHAR name[1]; /* event name */ + IN VARARG(name,unicode_str); /* object name */ }; /* Event operation */ @@ -454,7 +452,7 @@ struct open_event_request IN unsigned int access; /* wanted access rights */ IN int inherit; /* inherit flag */ OUT int handle; /* handle to the event */ - IN WCHAR name[1]; /* object name */ + IN VARARG(name,unicode_str); /* object name */ }; @@ -465,7 +463,7 @@ struct create_mutex_request IN int owned; /* initially owned? */ IN int inherit; /* inherit flag */ OUT int handle; /* handle to the mutex */ - IN WCHAR name[1]; /* mutex name */ + IN VARARG(name,unicode_str); /* object name */ }; @@ -484,7 +482,7 @@ struct open_mutex_request IN unsigned int access; /* wanted access rights */ IN int inherit; /* inherit flag */ OUT int handle; /* handle to the mutex */ - IN WCHAR name[1]; /* object name */ + IN VARARG(name,unicode_str); /* object name */ }; @@ -496,7 +494,7 @@ struct create_semaphore_request IN unsigned int max; /* maximum count */ IN int inherit; /* inherit flag */ OUT int handle; /* handle to the semaphore */ - IN WCHAR name[1]; /* semaphore name */ + IN VARARG(name,unicode_str); /* object name */ }; @@ -517,7 +515,7 @@ struct open_semaphore_request IN unsigned int access; /* wanted access rights */ IN int inherit; /* inherit flag */ OUT int handle; /* handle to the semaphore */ - IN WCHAR name[1]; /* object name */ + IN VARARG(name,unicode_str); /* object name */ }; @@ -835,7 +833,7 @@ struct create_mapping_request IN int inherit; /* inherit flag */ IN int file_handle; /* file handle */ OUT int handle; /* handle to the mapping */ - IN WCHAR name[1]; /* object name */ + IN VARARG(name,unicode_str); /* object name */ }; /* protection flags */ #define VPROT_READ 0x01 @@ -855,7 +853,7 @@ struct open_mapping_request IN unsigned int access; /* wanted access rights */ IN int inherit; /* inherit flag */ OUT int handle; /* handle to the mapping */ - IN WCHAR name[1]; /* object name */ + IN VARARG(name,unicode_str); /* object name */ }; @@ -941,7 +939,7 @@ struct wait_debug_event_request IN int timeout; /* timeout in ms */ OUT void* pid; /* process id */ OUT void* tid; /* thread id */ - OUT debug_event_t event; /* debug event data */ + OUT VARARG(event,debug_event); /* debug event data */ }; @@ -1175,7 +1173,7 @@ struct create_timer_request IN int inherit; /* inherit flag */ IN int manual; /* manual reset */ OUT int handle; /* handle to the timer */ - IN WCHAR name[1]; /* timer name */ + IN VARARG(name,unicode_str); /* object name */ }; @@ -1186,7 +1184,7 @@ struct open_timer_request IN unsigned int access; /* wanted access rights */ IN int inherit; /* inherit flag */ OUT int handle; /* handle to the timer */ - IN WCHAR name[1]; /* timer name */ + IN VARARG(name,unicode_str); /* object name */ }; /* Set a waitable timer */ @@ -1247,7 +1245,7 @@ struct add_atom_request REQUEST_HEADER; /* request header */ IN int local; /* is atom in local process table? */ OUT int atom; /* resulting atom */ - IN WCHAR name[1]; /* atom name */ + IN VARARG(name,unicode_str); /* atom name */ }; @@ -1266,7 +1264,7 @@ struct find_atom_request REQUEST_HEADER; /* request header */ IN int local; /* is atom in local process table? */ OUT int atom; /* atom handle */ - IN WCHAR name[1]; /* atom name */ + IN VARARG(name,unicode_str); /* atom name */ }; @@ -1277,7 +1275,7 @@ struct get_atom_name_request IN int atom; /* atom handle */ IN int local; /* is atom in local process table? */ OUT int count; /* atom lock count */ - OUT WCHAR name[1]; /* atom name */ + OUT VARARG(name,unicode_str); /* atom name */ }; @@ -1542,7 +1540,7 @@ union generic_request struct wait_input_idle_request wait_input_idle; }; -#define SERVER_PROTOCOL_VERSION 18 +#define SERVER_PROTOCOL_VERSION 19 /* ### make_requests end ### */ /* Everything above this line is generated automatically by tools/make_requests */ @@ -1621,6 +1619,12 @@ inline static void *server_data_ptr( void *req ) return (union generic_request *)req + 1; } +/* get the size of the variable part of the request */ +inline static size_t server_data_size( void *req ) +{ + return ((struct request_header *)req)->var_size; +} + /* exception support for server calls */ diff --git a/loader/module.c b/loader/module.c index e1198b9b60bbe40ef81bbd563862381d1f1deebb..6fe61788ab5f7c1951f8bf1c553aa1e73786e2ce 100644 --- a/loader/module.c +++ b/loader/module.c @@ -1526,12 +1526,14 @@ BOOL MODULE_FreeLibrary( WINE_MODREF *wm ) /* Call process detach notifications */ if ( PROCESS_Current()->free_lib_count <= 1 ) { - struct unload_dll_request *req = get_req_buffer(); - MODULE_DllProcessDetach( FALSE, NULL ); - req->base = (void *)wm->module; - server_call_noerr( REQ_UNLOAD_DLL ); - + SERVER_START_REQ + { + struct unload_dll_request *req = server_alloc_req( sizeof(*req), 0 ); + req->base = (void *)wm->module; + server_call_noerr( REQ_UNLOAD_DLL ); + } + SERVER_END_REQ; MODULE_FlushModrefs(); } diff --git a/loader/ne/module.c b/loader/ne/module.c index 15a3dc1b2f9e03863e4fdc8f80b4110879e54e5b..aff2b48fc7d5f9a8bb4a5c86faaed12ca5e3f8f8 100644 --- a/loader/ne/module.c +++ b/loader/ne/module.c @@ -992,7 +992,6 @@ static HINSTANCE16 MODULE_LoadModule16( LPCSTR libname, BOOL implicit, BOOL lib_ */ HINSTANCE16 WINAPI LoadModule16( LPCSTR name, LPVOID paramBlock ) { - struct new_thread_request *req = get_req_buffer(); TEB *teb = NULL; BOOL lib_only = !paramBlock || (paramBlock == (LPVOID)-1); LOADPARAMS16 *params; @@ -1003,7 +1002,7 @@ HINSTANCE16 WINAPI LoadModule16( LPCSTR name, LPVOID paramBlock ) TDB *pTask; LPSTR cmdline; WORD cmdShow; - HANDLE hThread; + HANDLE hThread = -1; int socket; /* Load module */ @@ -1046,10 +1045,15 @@ HINSTANCE16 WINAPI LoadModule16( LPCSTR name, LPVOID paramBlock ) /* Create the main thread */ - req->suspend = 0; - req->inherit = 0; - if (server_call_fd( REQ_NEW_THREAD, -1, &socket )) return 0; - hThread = req->handle; + SERVER_START_REQ + { + struct new_thread_request *req = server_alloc_req( sizeof(*req), 0 ); + req->suspend = 0; + req->inherit = 0; + if (!server_call_fd( REQ_NEW_THREAD, -1, &socket )) hThread = req->handle; + } + SERVER_END_REQ; + if (hThread == -1) return 0; if (!(teb = THREAD_Create( socket, 0, FALSE ))) goto error; teb->startup = NE_InitProcess; diff --git a/loader/pe_image.c b/loader/pe_image.c index 9380f986f1fe151500dc54536a5d448afabcc5ed..4267c5cdd54af4317c9dffd9906515f2e8486905 100644 --- a/loader/pe_image.c +++ b/loader/pe_image.c @@ -23,6 +23,7 @@ * NE_MODULE.module32. */ +#include <sys/types.h> #ifdef HAVE_SYS_MMAN_H #include <sys/mman.h> #endif @@ -682,13 +683,17 @@ WINE_MODREF *PE_CreateModule( HMODULE hModule, LPCSTR filename, DWORD flags, if (nt->FileHeader.Characteristics & IMAGE_FILE_DLL) { - struct load_dll_request *req = get_req_buffer(); - req->handle = hFile; - req->base = (void *)hModule; - req->dbg_offset = nt->FileHeader.PointerToSymbolTable; - req->dbg_size = nt->FileHeader.NumberOfSymbols; - req->name = &wm->filename; - server_call_noerr( REQ_LOAD_DLL ); + SERVER_START_REQ + { + struct load_dll_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = hFile; + req->base = (void *)hModule; + req->dbg_offset = nt->FileHeader.PointerToSymbolTable; + req->dbg_size = nt->FileHeader.NumberOfSymbols; + req->name = &wm->filename; + server_call_noerr( REQ_LOAD_DLL ); + } + SERVER_END_REQ; } return wm; diff --git a/memory/atom.c b/memory/atom.c index 5f32e086fddaf87081b060e5a4090a06362491b3..38ae92a5a7b146d3062fb55cdffc67333954754d 100644 --- a/memory/atom.c +++ b/memory/atom.c @@ -401,9 +401,15 @@ UINT16 WINAPI GetAtomName16( ATOM atom, LPSTR buffer, INT16 count ) */ BOOL WINAPI InitAtomTable( DWORD entries ) { - struct init_atom_table_request *req = get_req_buffer(); - req->entries = entries; - return !server_call( REQ_INIT_ATOM_TABLE ); + BOOL ret; + SERVER_START_REQ + { + struct init_atom_table_request *req = server_alloc_req( sizeof(*req), 0 ); + req->entries = entries; + ret = !server_call( REQ_INIT_ATOM_TABLE ); + } + SERVER_END_REQ; + return ret; } @@ -412,10 +418,20 @@ static ATOM ATOM_AddAtomA( LPCSTR str, BOOL local ) ATOM atom = 0; if (!ATOM_IsIntAtomA( str, &atom )) { - struct add_atom_request *req = get_req_buffer(); - server_strcpyAtoW( req->name, str ); - req->local = local; - if (!server_call( REQ_ADD_ATOM )) atom = req->atom + MIN_STR_ATOM; + DWORD len = MultiByteToWideChar( CP_ACP, 0, str, strlen(str), NULL, 0 ); + if (len > MAX_ATOM_LEN) + { + SetLastError( ERROR_INVALID_PARAMETER ); + return 0; + } + SERVER_START_REQ + { + struct add_atom_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) ); + MultiByteToWideChar( CP_ACP, 0, str, strlen(str), server_data_ptr(req), len ); + req->local = local; + if (!server_call( REQ_ADD_ATOM )) atom = req->atom + MIN_STR_ATOM; + } + SERVER_END_REQ; } TRACE( "(%s) %s -> %x\n", local ? "local" : "global", debugres_a(str), atom ); return atom; @@ -458,10 +474,20 @@ static ATOM ATOM_AddAtomW( LPCWSTR str, BOOL local ) ATOM atom = 0; if (!ATOM_IsIntAtomW( str, &atom )) { - struct add_atom_request *req = get_req_buffer(); - server_strcpyW( req->name, str ); - req->local = local; - if (!server_call( REQ_ADD_ATOM )) atom = req->atom + MIN_STR_ATOM; + DWORD len = strlenW(str); + if (len > MAX_ATOM_LEN) + { + SetLastError( ERROR_INVALID_PARAMETER ); + return 0; + } + SERVER_START_REQ + { + struct add_atom_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) ); + memcpy( server_data_ptr(req), str, len * sizeof(WCHAR) ); + req->local = local; + if (!server_call( REQ_ADD_ATOM )) atom = req->atom + MIN_STR_ATOM; + } + SERVER_END_REQ; } TRACE( "(%s) %s -> %x\n", local ? "local" : "global", debugres_w(str), atom ); return atom; @@ -492,10 +518,14 @@ static ATOM ATOM_DeleteAtom( ATOM atom, BOOL local) if (atom < MIN_STR_ATOM) atom = 0; else { - struct delete_atom_request *req = get_req_buffer(); - req->atom = atom - MIN_STR_ATOM; - req->local = local; - if (!server_call( REQ_DELETE_ATOM )) atom = 0; + SERVER_START_REQ + { + struct delete_atom_request *req = server_alloc_req( sizeof(*req), 0 ); + req->atom = atom - MIN_STR_ATOM; + req->local = local; + if (!server_call( REQ_DELETE_ATOM )) atom = 0; + } + SERVER_END_REQ; } return atom; } @@ -536,10 +566,20 @@ static ATOM ATOM_FindAtomA( LPCSTR str, BOOL local ) ATOM atom = 0; if (!ATOM_IsIntAtomA( str, &atom )) { - struct find_atom_request *req = get_req_buffer(); - server_strcpyAtoW( req->name, str ); - req->local = local; - if (!server_call( REQ_FIND_ATOM )) atom = req->atom + MIN_STR_ATOM; + DWORD len = MultiByteToWideChar( CP_ACP, 0, str, strlen(str), NULL, 0 ); + if (len > MAX_ATOM_LEN) + { + SetLastError( ERROR_INVALID_PARAMETER ); + return 0; + } + SERVER_START_REQ + { + struct find_atom_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) ); + MultiByteToWideChar( CP_ACP, 0, str, strlen(str), server_data_ptr(req), len ); + req->local = local; + if (!server_call( REQ_ADD_ATOM )) atom = req->atom + MIN_STR_ATOM; + } + SERVER_END_REQ; } TRACE( "(%s) %s -> %x\n", local ? "local" : "global", debugres_a(str), atom ); return atom; @@ -581,10 +621,20 @@ static ATOM ATOM_FindAtomW( LPCWSTR str, BOOL local ) ATOM atom = 0; if (!ATOM_IsIntAtomW( str, &atom )) { - struct find_atom_request *req = get_req_buffer(); - server_strcpyW( req->name, str ); - req->local = local; - if (!server_call( REQ_FIND_ATOM )) atom = req->atom + MIN_STR_ATOM; + DWORD len = strlenW(str); + if (len > MAX_ATOM_LEN) + { + SetLastError( ERROR_INVALID_PARAMETER ); + return 0; + } + SERVER_START_REQ + { + struct find_atom_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) ); + memcpy( server_data_ptr(req), str, len * sizeof(WCHAR) ); + req->local = local; + if (!server_call( REQ_FIND_ATOM )) atom = req->atom + MIN_STR_ATOM; + } + SERVER_END_REQ; } TRACE( "(%s) %s -> %x\n", local ? "local" : "global", debugres_w(str), atom ); return atom; @@ -612,6 +662,12 @@ ATOM WINAPI FindAtomW( LPCWSTR str ) static UINT ATOM_GetAtomNameA( ATOM atom, LPSTR buffer, INT count, BOOL local ) { INT len; + + if (count <= 0) + { + SetLastError( ERROR_MORE_DATA ); + return 0; + } if (atom < MIN_STR_ATOM) { char name[8]; @@ -625,16 +681,28 @@ static UINT ATOM_GetAtomNameA( ATOM atom, LPSTR buffer, INT count, BOOL local ) } else { - struct get_atom_name_request *req = get_req_buffer(); - req->atom = atom - MIN_STR_ATOM; - req->local = local; - if (server_call( REQ_GET_ATOM_NAME )) return 0; - lstrcpynWtoA( buffer, req->name, count ); - len = strlenW( req->name ); + len = 0; + SERVER_START_REQ + { + struct get_atom_name_request *req = server_alloc_req( sizeof(*req), + MAX_ATOM_LEN * sizeof(WCHAR) ); + req->atom = atom - MIN_STR_ATOM; + req->local = local; + if (!server_call( REQ_GET_ATOM_NAME )) + { + len = WideCharToMultiByte( CP_ACP, 0, server_data_ptr(req), server_data_size(req), + buffer, count - 1, NULL, NULL ); + if (!len) len = count; /* overflow */ + else buffer[len] = 0; + } + } + SERVER_END_REQ; } - if (count <= len) + + if (len && count <= len) { SetLastError( ERROR_MORE_DATA ); + buffer[count-1] = 0; return 0; } TRACE( "(%s) %x -> %s\n", local ? "local" : "global", atom, debugstr_a(buffer) ); @@ -680,6 +748,12 @@ UINT WINAPI GetAtomNameA( static UINT ATOM_GetAtomNameW( ATOM atom, LPWSTR buffer, INT count, BOOL local ) { INT len; + + if (count <= 0) + { + SetLastError( ERROR_MORE_DATA ); + return 0; + } if (atom < MIN_STR_ATOM) { char name[8]; @@ -688,17 +762,29 @@ static UINT ATOM_GetAtomNameW( ATOM atom, LPWSTR buffer, INT count, BOOL local ) SetLastError( ERROR_INVALID_PARAMETER ); return 0; } - len = sprintf( name, "#%d", atom ); - lstrcpynAtoW( buffer, name, count ); + sprintf( name, "#%d", atom ); + len = MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, count ); + if (!len) buffer[count-1] = 0; /* overflow */ } else { - struct get_atom_name_request *req = get_req_buffer(); - req->atom = atom - MIN_STR_ATOM; - req->local = local; - if (server_call( REQ_GET_ATOM_NAME )) return 0; - lstrcpynW( buffer, req->name, count ); - len = strlenW( req->name ); + len = 0; + SERVER_START_REQ + { + struct get_atom_name_request *req = server_alloc_req( sizeof(*req), + MAX_ATOM_LEN * sizeof(WCHAR) ); + req->atom = atom - MIN_STR_ATOM; + req->local = local; + if (!server_call( REQ_GET_ATOM_NAME )) + { + len = server_data_size(req) / sizeof(WCHAR); + if (count > len) count = len + 1; + memcpy( buffer, server_data_ptr(req), (count-1) * sizeof(WCHAR) ); + buffer[count-1] = 0; + } + } + SERVER_END_REQ; + if (!len) return 0; } if (count <= len) { diff --git a/memory/selector.c b/memory/selector.c index c12b6205eeddf9c99b161a362da7bbd05a08ff55..392de3e5b1eed9f9057229887777afb1c27122cf 100644 --- a/memory/selector.c +++ b/memory/selector.c @@ -606,7 +606,7 @@ void WINAPI UnMapLS( SEGPTR sptr ) BOOL WINAPI GetThreadSelectorEntry( HANDLE hthread, DWORD sel, LPLDT_ENTRY ldtent) { #ifdef __i386__ - struct get_selector_entry_request *req = get_req_buffer(); + BOOL ret; if (!(sel & 4)) /* GDT selector */ { @@ -639,29 +639,39 @@ BOOL WINAPI GetThreadSelectorEntry( HANDLE hthread, DWORD sel, LPLDT_ENTRY ldten return FALSE; } - req->handle = hthread; - req->entry = sel >> __AHSHIFT; - if (server_call( REQ_GET_SELECTOR_ENTRY )) return FALSE; - - if (!(req->flags & LDT_FLAGS_ALLOCATED)) + SERVER_START_REQ { - SetLastError( ERROR_MR_MID_NOT_FOUND ); /* sic */ - return FALSE; + struct get_selector_entry_request *req = server_alloc_req( sizeof(*req), 0 ); + + req->handle = hthread; + req->entry = sel >> __AHSHIFT; + if ((ret = !server_call( REQ_GET_SELECTOR_ENTRY ))) + { + if (!(req->flags & LDT_FLAGS_ALLOCATED)) + { + SetLastError( ERROR_MR_MID_NOT_FOUND ); /* sic */ + ret = FALSE; + } + else + { + if (req->flags & LDT_FLAGS_BIG) req->limit >>= 12; + ldtent->BaseLow = req->base & 0x0000ffff; + ldtent->HighWord.Bits.BaseMid = (req->base & 0x00ff0000) >> 16; + ldtent->HighWord.Bits.BaseHi = (req->base & 0xff000000) >> 24; + ldtent->LimitLow = req->limit & 0x0000ffff; + ldtent->HighWord.Bits.LimitHi = (req->limit & 0x000f0000) >> 16; + ldtent->HighWord.Bits.Dpl = 3; + ldtent->HighWord.Bits.Sys = 0; + ldtent->HighWord.Bits.Pres = 1; + ldtent->HighWord.Bits.Granularity = (req->flags & LDT_FLAGS_BIG) !=0; + ldtent->HighWord.Bits.Default_Big = (req->flags & LDT_FLAGS_32BIT) != 0; + ldtent->HighWord.Bits.Type = ((req->flags & LDT_FLAGS_TYPE) << 2) | 0x10; + if (!(req->flags & LDT_FLAGS_READONLY)) ldtent->HighWord.Bits.Type |= 0x2; + } + } } - if (req->flags & LDT_FLAGS_BIG) req->limit >>= 12; - ldtent->BaseLow = req->base & 0x0000ffff; - ldtent->HighWord.Bits.BaseMid = (req->base & 0x00ff0000) >> 16; - ldtent->HighWord.Bits.BaseHi = (req->base & 0xff000000) >> 24; - ldtent->LimitLow = req->limit & 0x0000ffff; - ldtent->HighWord.Bits.LimitHi = (req->limit & 0x000f0000) >> 16; - ldtent->HighWord.Bits.Dpl = 3; - ldtent->HighWord.Bits.Sys = 0; - ldtent->HighWord.Bits.Pres = 1; - ldtent->HighWord.Bits.Granularity = (req->flags & LDT_FLAGS_BIG) !=0; - ldtent->HighWord.Bits.Default_Big = (req->flags & LDT_FLAGS_32BIT) != 0; - ldtent->HighWord.Bits.Type = ((req->flags & LDT_FLAGS_TYPE) << 2) | 0x10; - if (!(req->flags & LDT_FLAGS_READONLY)) ldtent->HighWord.Bits.Type |= 0x2; - return TRUE; + SERVER_END_REQ; + return ret; #else SetLastError( ERROR_CALL_NOT_IMPLEMENTED ); return FALSE; diff --git a/memory/virtual.c b/memory/virtual.c index 846820c037057e15e97742b69452aca9287f0c19..8eda710665d382cdc40471d0e0d3af4523ed3824 100644 --- a/memory/virtual.c +++ b/memory/virtual.c @@ -22,6 +22,7 @@ #endif #include "winbase.h" #include "wine/exception.h" +#include "wine/unicode.h" #include "winerror.h" #include "file.h" #include "process.h" @@ -1195,14 +1196,20 @@ HANDLE WINAPI CreateFileMappingA( DWORD size_low, /* [in] Low-order 32 bits of object size */ LPCSTR name /* [in] Name of file-mapping object */ ) { - struct create_mapping_request *req = get_req_buffer(); + HANDLE ret; BYTE vprot; + DWORD len = name ? MultiByteToWideChar( CP_ACP, 0, name, strlen(name), NULL, 0 ) : 0; /* Check parameters */ TRACE("(%x,%p,%08lx,%08lx%08lx,%s)\n", hFile, sa, protect, size_high, size_low, debugstr_a(name) ); + if (len > MAX_PATH) + { + SetLastError( ERROR_FILENAME_EXCED_RANGE ); + return 0; + } vprot = VIRTUAL_GetProt( protect ); if (protect & SEC_RESERVE) { @@ -1218,16 +1225,23 @@ HANDLE WINAPI CreateFileMappingA( /* Create the server object */ - req->file_handle = hFile; - req->size_high = size_high; - req->size_low = size_low; - req->protect = vprot; - req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); - server_strcpyAtoW( req->name, name ); - SetLastError(0); - server_call( REQ_CREATE_MAPPING ); - if (req->handle == -1) return 0; - return req->handle; + SERVER_START_REQ + { + struct create_mapping_request *req = server_alloc_req( sizeof(*req), + len * sizeof(WCHAR) ); + req->file_handle = hFile; + req->size_high = size_high; + req->size_low = size_low; + req->protect = vprot; + req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); + if (len) MultiByteToWideChar( CP_ACP, 0, name, strlen(name), server_data_ptr(req), len ); + SetLastError(0); + server_call( REQ_CREATE_MAPPING ); + ret = req->handle; + } + SERVER_END_REQ; + if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ + return ret; } @@ -1239,14 +1253,21 @@ HANDLE WINAPI CreateFileMappingW( HFILE hFile, LPSECURITY_ATTRIBUTES sa, DWORD protect, DWORD size_high, DWORD size_low, LPCWSTR name ) { - struct create_mapping_request *req = get_req_buffer(); + HANDLE ret; BYTE vprot; + DWORD len = name ? strlenW(name) : 0; /* Check parameters */ TRACE("(%x,%p,%08lx,%08lx%08lx,%s)\n", hFile, sa, protect, size_high, size_low, debugstr_w(name) ); + if (len > MAX_PATH) + { + SetLastError( ERROR_FILENAME_EXCED_RANGE ); + return 0; + } + vprot = VIRTUAL_GetProt( protect ); if (protect & SEC_RESERVE) { @@ -1262,16 +1283,23 @@ HANDLE WINAPI CreateFileMappingW( HFILE hFile, LPSECURITY_ATTRIBUTES sa, /* Create the server object */ - req->file_handle = hFile; - req->size_high = size_high; - req->size_low = size_low; - req->protect = vprot; - req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); - server_strcpyW( req->name, name ); - SetLastError(0); - server_call( REQ_CREATE_MAPPING ); - if (req->handle == -1) return 0; - return req->handle; + SERVER_START_REQ + { + struct create_mapping_request *req = server_alloc_req( sizeof(*req), + len * sizeof(WCHAR) ); + req->file_handle = hFile; + req->size_high = size_high; + req->size_low = size_low; + req->protect = vprot; + req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); + memcpy( server_data_ptr(req), name, len * sizeof(WCHAR) ); + SetLastError(0); + server_call( REQ_CREATE_MAPPING ); + ret = req->handle; + } + SERVER_END_REQ; + if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ + return ret; } @@ -1288,14 +1316,26 @@ HANDLE WINAPI OpenFileMappingA( BOOL inherit, /* [in] Inherit flag */ LPCSTR name ) /* [in] Name of file-mapping object */ { - struct open_mapping_request *req = get_req_buffer(); - - req->access = access; - req->inherit = inherit; - server_strcpyAtoW( req->name, name ); - server_call( REQ_OPEN_MAPPING ); - if (req->handle == -1) return 0; /* must return 0 on failure, not -1 */ - return req->handle; + HANDLE ret; + DWORD len = name ? MultiByteToWideChar( CP_ACP, 0, name, strlen(name), NULL, 0 ) : 0; + if (len > MAX_PATH) + { + SetLastError( ERROR_FILENAME_EXCED_RANGE ); + return 0; + } + SERVER_START_REQ + { + struct open_mapping_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) ); + + req->access = access; + req->inherit = inherit; + if (len) MultiByteToWideChar( CP_ACP, 0, name, strlen(name), server_data_ptr(req), len ); + server_call( REQ_OPEN_MAPPING ); + ret = req->handle; + } + SERVER_END_REQ; + if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ + return ret; } @@ -1305,14 +1345,26 @@ HANDLE WINAPI OpenFileMappingA( */ HANDLE WINAPI OpenFileMappingW( DWORD access, BOOL inherit, LPCWSTR name) { - struct open_mapping_request *req = get_req_buffer(); - - req->access = access; - req->inherit = inherit; - server_strcpyW( req->name, name ); - server_call( REQ_OPEN_MAPPING ); - if (req->handle == -1) return 0; /* must return 0 on failure, not -1 */ - return req->handle; + HANDLE ret; + DWORD len = name ? strlenW(name) : 0; + if (len > MAX_PATH) + { + SetLastError( ERROR_FILENAME_EXCED_RANGE ); + return 0; + } + SERVER_START_REQ + { + struct open_mapping_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) ); + + req->access = access; + req->inherit = inherit; + memcpy( server_data_ptr(req), name, len * sizeof(WCHAR) ); + server_call( REQ_OPEN_MAPPING ); + ret = req->handle; + } + SERVER_END_REQ; + if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ + return ret; } diff --git a/misc/registry.c b/misc/registry.c index 4462ef8b3c3eddffa108ed4bd3852dd4d2007051..ddf2fc1487b65ed69c20cdd4190fb6f6b12849ff 100644 --- a/misc/registry.c +++ b/misc/registry.c @@ -1323,16 +1323,19 @@ void _w31_loadreg(void) { /* configure save files and start the periodic saving timer */ static void SHELL_InitRegistrySaving( HKEY hkey_users_default ) { - struct set_registry_levels_request *req = get_req_buffer(); - int all = PROFILE_GetWineIniBool( "registry", "SaveOnlyUpdatedKeys", 1 ); int period = PROFILE_GetWineIniInt( "registry", "PeriodicSave", 0 ); /* set saving level (0 for saving everything, 1 for saving only modified keys) */ - req->current = 1; - req->saving = !all; - req->period = period * 1000; - server_call( REQ_SET_REGISTRY_LEVELS ); + SERVER_START_REQ + { + struct set_registry_levels_request *req = server_alloc_req( sizeof(*req), 0 ); + req->current = 1; + req->saving = !all; + req->period = period * 1000; + server_call( REQ_SET_REGISTRY_LEVELS ); + } + SERVER_END_REQ; if (PROFILE_GetWineIniBool("registry","WritetoHomeRegistries",1)) { @@ -1377,12 +1380,16 @@ static void SHELL_InitRegistrySaving( HKEY hkey_users_default ) */ static void SetLoadLevel(int level) { - struct set_registry_levels_request *req = get_req_buffer(); + SERVER_START_REQ + { + struct set_registry_levels_request *req = server_alloc_req( sizeof(*req), 0 ); req->current = level; req->saving = 0; req->period = 0; server_call( REQ_SET_REGISTRY_LEVELS ); + } + SERVER_END_REQ; } /********************************************************************************** diff --git a/scheduler/debugger.c b/scheduler/debugger.c index 9231a89b1b89e5cc87457917bef7c941f89c2884..f3d5df68539f9c7524afa49cba59b54f43f5dbe7 100644 --- a/scheduler/debugger.c +++ b/scheduler/debugger.c @@ -26,72 +26,83 @@ DEFAULT_DEBUG_CHANNEL(debugstr); */ BOOL WINAPI WaitForDebugEvent( LPDEBUG_EVENT event, DWORD timeout ) { - struct wait_debug_event_request *req = get_req_buffer(); - - req->timeout = timeout; - if (server_call( REQ_WAIT_DEBUG_EVENT )) return FALSE; - if ((req->event.code < 0) || (req->event.code > RIP_EVENT)) - server_protocol_error( "WaitForDebugEvent: bad code %d\n", req->event.code ); - - event->dwDebugEventCode = req->event.code; - event->dwProcessId = (DWORD)req->pid; - event->dwThreadId = (DWORD)req->tid; - switch(req->event.code) + BOOL ret; + SERVER_START_REQ { - case 0: /* timeout */ - SetLastError( ERROR_SEM_TIMEOUT ); - return FALSE; - case EXCEPTION_DEBUG_EVENT: - event->u.Exception.ExceptionRecord = req->event.info.exception.record; - event->u.Exception.dwFirstChance = req->event.info.exception.first; - break; - case CREATE_THREAD_DEBUG_EVENT: - event->u.CreateThread.hThread = req->event.info.create_thread.handle; - event->u.CreateThread.lpThreadLocalBase = req->event.info.create_thread.teb; - event->u.CreateThread.lpStartAddress = req->event.info.create_thread.start; - break; - case CREATE_PROCESS_DEBUG_EVENT: - event->u.CreateProcessInfo.hFile = req->event.info.create_process.file; - event->u.CreateProcessInfo.hProcess = req->event.info.create_process.process; - event->u.CreateProcessInfo.hThread = req->event.info.create_process.thread; - event->u.CreateProcessInfo.lpBaseOfImage = req->event.info.create_process.base; - event->u.CreateProcessInfo.dwDebugInfoFileOffset = req->event.info.create_process.dbg_offset; - event->u.CreateProcessInfo.nDebugInfoSize = req->event.info.create_process.dbg_size; - event->u.CreateProcessInfo.lpThreadLocalBase = req->event.info.create_process.teb; - event->u.CreateProcessInfo.lpStartAddress = req->event.info.create_process.start; - event->u.CreateProcessInfo.lpImageName = req->event.info.create_process.name; - event->u.CreateProcessInfo.fUnicode = req->event.info.create_process.unicode; - if (req->event.info.create_process.file == -1) event->u.CreateProcessInfo.hFile = 0; - break; - case EXIT_THREAD_DEBUG_EVENT: - event->u.ExitThread.dwExitCode = req->event.info.exit.exit_code; - break; - case EXIT_PROCESS_DEBUG_EVENT: - event->u.ExitProcess.dwExitCode = req->event.info.exit.exit_code; - break; - case LOAD_DLL_DEBUG_EVENT: - event->u.LoadDll.hFile = req->event.info.load_dll.handle; - event->u.LoadDll.lpBaseOfDll = req->event.info.load_dll.base; - event->u.LoadDll.dwDebugInfoFileOffset = req->event.info.load_dll.dbg_offset; - event->u.LoadDll.nDebugInfoSize = req->event.info.load_dll.dbg_size; - event->u.LoadDll.lpImageName = req->event.info.load_dll.name; - event->u.LoadDll.fUnicode = req->event.info.load_dll.unicode; - if (req->event.info.load_dll.handle == -1) event->u.LoadDll.hFile = 0; - break; - case UNLOAD_DLL_DEBUG_EVENT: - event->u.UnloadDll.lpBaseOfDll = req->event.info.unload_dll.base; - break; - case OUTPUT_DEBUG_STRING_EVENT: - event->u.DebugString.lpDebugStringData = req->event.info.output_string.string; - event->u.DebugString.fUnicode = req->event.info.output_string.unicode; - event->u.DebugString.nDebugStringLength = req->event.info.output_string.length; - break; - case RIP_EVENT: - event->u.RipInfo.dwError = req->event.info.rip_info.error; - event->u.RipInfo.dwType = req->event.info.rip_info.type; - break; + debug_event_t *data; + struct wait_debug_event_request *req = server_alloc_req( sizeof(*req), sizeof(*data) ); + + req->timeout = timeout; + if (!(ret = !server_call( REQ_WAIT_DEBUG_EVENT ))) goto done; + + if (!server_data_size(req)) /* timeout */ + { + SetLastError( ERROR_SEM_TIMEOUT ); + ret = FALSE; + goto done; + } + data = server_data_ptr(req); + event->dwDebugEventCode = data->code; + event->dwProcessId = (DWORD)req->pid; + event->dwThreadId = (DWORD)req->tid; + switch(data->code) + { + case EXCEPTION_DEBUG_EVENT: + event->u.Exception.ExceptionRecord = data->info.exception.record; + event->u.Exception.dwFirstChance = data->info.exception.first; + break; + case CREATE_THREAD_DEBUG_EVENT: + event->u.CreateThread.hThread = data->info.create_thread.handle; + event->u.CreateThread.lpThreadLocalBase = data->info.create_thread.teb; + event->u.CreateThread.lpStartAddress = data->info.create_thread.start; + break; + case CREATE_PROCESS_DEBUG_EVENT: + event->u.CreateProcessInfo.hFile = data->info.create_process.file; + event->u.CreateProcessInfo.hProcess = data->info.create_process.process; + event->u.CreateProcessInfo.hThread = data->info.create_process.thread; + event->u.CreateProcessInfo.lpBaseOfImage = data->info.create_process.base; + event->u.CreateProcessInfo.dwDebugInfoFileOffset = data->info.create_process.dbg_offset; + event->u.CreateProcessInfo.nDebugInfoSize = data->info.create_process.dbg_size; + event->u.CreateProcessInfo.lpThreadLocalBase = data->info.create_process.teb; + event->u.CreateProcessInfo.lpStartAddress = data->info.create_process.start; + event->u.CreateProcessInfo.lpImageName = data->info.create_process.name; + event->u.CreateProcessInfo.fUnicode = data->info.create_process.unicode; + if (data->info.create_process.file == -1) event->u.CreateProcessInfo.hFile = 0; + break; + case EXIT_THREAD_DEBUG_EVENT: + event->u.ExitThread.dwExitCode = data->info.exit.exit_code; + break; + case EXIT_PROCESS_DEBUG_EVENT: + event->u.ExitProcess.dwExitCode = data->info.exit.exit_code; + break; + case LOAD_DLL_DEBUG_EVENT: + event->u.LoadDll.hFile = data->info.load_dll.handle; + event->u.LoadDll.lpBaseOfDll = data->info.load_dll.base; + event->u.LoadDll.dwDebugInfoFileOffset = data->info.load_dll.dbg_offset; + event->u.LoadDll.nDebugInfoSize = data->info.load_dll.dbg_size; + event->u.LoadDll.lpImageName = data->info.load_dll.name; + event->u.LoadDll.fUnicode = data->info.load_dll.unicode; + if (data->info.load_dll.handle == -1) event->u.LoadDll.hFile = 0; + break; + case UNLOAD_DLL_DEBUG_EVENT: + event->u.UnloadDll.lpBaseOfDll = data->info.unload_dll.base; + break; + case OUTPUT_DEBUG_STRING_EVENT: + event->u.DebugString.lpDebugStringData = data->info.output_string.string; + event->u.DebugString.fUnicode = data->info.output_string.unicode; + event->u.DebugString.nDebugStringLength = data->info.output_string.length; + break; + case RIP_EVENT: + event->u.RipInfo.dwError = data->info.rip_info.error; + event->u.RipInfo.dwType = data->info.rip_info.type; + break; + default: + server_protocol_error( "WaitForDebugEvent: bad code %d\n", data->code ); + } + done: } - return TRUE; + SERVER_END_REQ; + return ret; } @@ -100,11 +111,17 @@ BOOL WINAPI WaitForDebugEvent( LPDEBUG_EVENT event, DWORD timeout ) */ BOOL WINAPI ContinueDebugEvent( DWORD pid, DWORD tid, DWORD status ) { - struct continue_debug_event_request *req = get_req_buffer(); - req->pid = (void *)pid; - req->tid = (void *)tid; - req->status = status; - return !server_call( REQ_CONTINUE_DEBUG_EVENT ); + BOOL ret; + SERVER_START_REQ + { + struct continue_debug_event_request *req = server_alloc_req( sizeof(*req), 0 ); + req->pid = (void *)pid; + req->tid = (void *)tid; + req->status = status; + ret = !server_call( REQ_CONTINUE_DEBUG_EVENT ); + } + SERVER_END_REQ; + return ret; } @@ -113,9 +130,15 @@ BOOL WINAPI ContinueDebugEvent( DWORD pid, DWORD tid, DWORD status ) */ BOOL WINAPI DebugActiveProcess( DWORD pid ) { - struct debug_process_request *req = get_req_buffer(); - req->pid = (void *)pid; - return !server_call( REQ_DEBUG_PROCESS ); + BOOL ret; + SERVER_START_REQ + { + struct debug_process_request *req = server_alloc_req( sizeof(*req), 0 ); + req->pid = (void *)pid; + ret = !server_call( REQ_DEBUG_PROCESS ); + } + SERVER_END_REQ; + return ret; } @@ -124,11 +147,15 @@ BOOL WINAPI DebugActiveProcess( DWORD pid ) */ void WINAPI OutputDebugStringA( LPCSTR str ) { - struct output_debug_string_request *req = get_req_buffer(); - req->string = (void *)str; - req->unicode = 0; - req->length = strlen(str) + 1; - server_call_noerr( REQ_OUTPUT_DEBUG_STRING ); + SERVER_START_REQ + { + struct output_debug_string_request *req = server_alloc_req( sizeof(*req), 0 ); + req->string = (void *)str; + req->unicode = 0; + req->length = strlen(str) + 1; + server_call_noerr( REQ_OUTPUT_DEBUG_STRING ); + } + SERVER_END_REQ; WARN("%s\n", str); } @@ -138,11 +165,15 @@ void WINAPI OutputDebugStringA( LPCSTR str ) */ void WINAPI OutputDebugStringW( LPCWSTR str ) { - struct output_debug_string_request *req = get_req_buffer(); - req->string = (void *)str; - req->unicode = 1; - req->length = (lstrlenW(str) + 1) * sizeof(WCHAR); - server_call_noerr( REQ_OUTPUT_DEBUG_STRING ); + SERVER_START_REQ + { + struct output_debug_string_request *req = server_alloc_req( sizeof(*req), 0 ); + req->string = (void *)str; + req->unicode = 1; + req->length = (lstrlenW(str) + 1) * sizeof(WCHAR); + server_call_noerr( REQ_OUTPUT_DEBUG_STRING ); + } + SERVER_END_REQ; WARN("%s\n", debugstr_w(str)); } @@ -189,8 +220,12 @@ void WINAPI DebugBreak16( CONTEXT86 *context ) BOOL WINAPI IsDebuggerPresent(void) { BOOL ret = FALSE; - struct get_process_info_request *req = get_req_buffer(); - req->handle = GetCurrentProcess(); - if (!server_call( REQ_GET_PROCESS_INFO )) ret = req->debugged; + SERVER_START_REQ + { + struct get_process_info_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = GetCurrentProcess(); + if (!server_call( REQ_GET_PROCESS_INFO )) ret = req->debugged; + } + SERVER_END_REQ; return ret; } diff --git a/scheduler/event.c b/scheduler/event.c index c26112478d12faf1e5024ddecabe1f6fcad72289..af968acf5ca67273ac885b24fd62ad5bf1406bbc 100644 --- a/scheduler/event.c +++ b/scheduler/event.c @@ -7,6 +7,7 @@ #include <assert.h> #include <string.h> #include "winerror.h" +#include "wine/unicode.h" #include "syslevel.h" #include "server.h" @@ -17,16 +18,28 @@ HANDLE WINAPI CreateEventA( SECURITY_ATTRIBUTES *sa, BOOL manual_reset, BOOL initial_state, LPCSTR name ) { - struct create_event_request *req = get_req_buffer(); - - req->manual_reset = manual_reset; - req->initial_state = initial_state; - req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); - server_strcpyAtoW( req->name, name ); - SetLastError(0); - server_call( REQ_CREATE_EVENT ); - if (req->handle == -1) return 0; - return req->handle; + HANDLE ret; + DWORD len = name ? MultiByteToWideChar( CP_ACP, 0, name, strlen(name), NULL, 0 ) : 0; + if (len >= MAX_PATH) + { + SetLastError( ERROR_FILENAME_EXCED_RANGE ); + return 0; + } + SERVER_START_REQ + { + struct create_event_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) ); + + req->manual_reset = manual_reset; + req->initial_state = initial_state; + req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); + if (len) MultiByteToWideChar( CP_ACP, 0, name, strlen(name), server_data_ptr(req), len ); + SetLastError(0); + server_call( REQ_CREATE_EVENT ); + ret = req->handle; + } + SERVER_END_REQ; + if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ + return ret; } @@ -36,16 +49,28 @@ HANDLE WINAPI CreateEventA( SECURITY_ATTRIBUTES *sa, BOOL manual_reset, HANDLE WINAPI CreateEventW( SECURITY_ATTRIBUTES *sa, BOOL manual_reset, BOOL initial_state, LPCWSTR name ) { - struct create_event_request *req = get_req_buffer(); - - req->manual_reset = manual_reset; - req->initial_state = initial_state; - req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); - server_strcpyW( req->name, name ); - SetLastError(0); - server_call( REQ_CREATE_EVENT ); - if (req->handle == -1) return 0; - return req->handle; + HANDLE ret; + DWORD len = name ? strlenW(name) : 0; + if (len >= MAX_PATH) + { + SetLastError( ERROR_FILENAME_EXCED_RANGE ); + return 0; + } + SERVER_START_REQ + { + struct create_event_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) ); + + req->manual_reset = manual_reset; + req->initial_state = initial_state; + req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); + memcpy( server_data_ptr(req), name, len * sizeof(WCHAR) ); + SetLastError(0); + server_call( REQ_CREATE_EVENT ); + ret = req->handle; + } + SERVER_END_REQ; + if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ + return ret; } /*********************************************************************** @@ -62,14 +87,26 @@ HANDLE WINAPI WIN16_CreateEvent( BOOL manual_reset, BOOL initial_state ) */ HANDLE WINAPI OpenEventA( DWORD access, BOOL inherit, LPCSTR name ) { - struct open_event_request *req = get_req_buffer(); - - req->access = access; - req->inherit = inherit; - server_strcpyAtoW( req->name, name ); - server_call( REQ_OPEN_EVENT ); - if (req->handle == -1) return 0; /* must return 0 on failure, not -1 */ - return req->handle; + HANDLE ret; + DWORD len = name ? MultiByteToWideChar( CP_ACP, 0, name, strlen(name), NULL, 0 ) : 0; + if (len >= MAX_PATH) + { + SetLastError( ERROR_FILENAME_EXCED_RANGE ); + return 0; + } + SERVER_START_REQ + { + struct open_event_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) ); + + req->access = access; + req->inherit = inherit; + if (len) MultiByteToWideChar( CP_ACP, 0, name, strlen(name), server_data_ptr(req), len ); + server_call( REQ_OPEN_EVENT ); + ret = req->handle; + } + SERVER_END_REQ; + if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ + return ret; } @@ -78,14 +115,26 @@ HANDLE WINAPI OpenEventA( DWORD access, BOOL inherit, LPCSTR name ) */ HANDLE WINAPI OpenEventW( DWORD access, BOOL inherit, LPCWSTR name ) { - struct open_event_request *req = get_req_buffer(); - - req->access = access; - req->inherit = inherit; - server_strcpyW( req->name, name ); - server_call( REQ_OPEN_EVENT ); - if (req->handle == -1) return 0; /* must return 0 on failure, not -1 */ - return req->handle; + HANDLE ret; + DWORD len = name ? strlenW(name) : 0; + if (len >= MAX_PATH) + { + SetLastError( ERROR_FILENAME_EXCED_RANGE ); + return 0; + } + SERVER_START_REQ + { + struct open_event_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) ); + + req->access = access; + req->inherit = inherit; + memcpy( server_data_ptr(req), name, len * sizeof(WCHAR) ); + server_call( REQ_OPEN_EVENT ); + ret = req->handle; + } + SERVER_END_REQ; + if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ + return ret; } @@ -96,10 +145,16 @@ HANDLE WINAPI OpenEventW( DWORD access, BOOL inherit, LPCWSTR name ) */ static BOOL EVENT_Operation( HANDLE handle, enum event_op op ) { - struct event_op_request *req = get_req_buffer(); - req->handle = handle; - req->op = op; - return !server_call( REQ_EVENT_OP ); + BOOL ret; + SERVER_START_REQ + { + struct event_op_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = handle; + req->op = op; + ret = !server_call( REQ_EVENT_OP ); + } + SERVER_END_REQ; + return ret; } diff --git a/scheduler/handle.c b/scheduler/handle.c index 5640feed927c18569c5a7689f81547c95bfa0e73..6fbe913d93c3c8fde3bcf260ac2390916dae49d1 100644 --- a/scheduler/handle.c +++ b/scheduler/handle.c @@ -18,14 +18,17 @@ DEFAULT_DEBUG_CHANNEL(win32) */ BOOL WINAPI CloseHandle( HANDLE handle ) { - struct close_handle_request *req = get_req_buffer(); + NTSTATUS status; + /* stdio handles need special treatment */ if ((handle == STD_INPUT_HANDLE) || (handle == STD_OUTPUT_HANDLE) || (handle == STD_ERROR_HANDLE)) handle = GetStdHandle( handle ); - req->handle = handle; - return !server_call( REQ_CLOSE_HANDLE ); + + status = NtClose( handle ); + if (status) SetLastError( RtlNtStatusToDosError(status) ); + return !status; } @@ -34,11 +37,16 @@ BOOL WINAPI CloseHandle( HANDLE handle ) */ BOOL WINAPI GetHandleInformation( HANDLE handle, LPDWORD flags ) { - struct get_handle_info_request *req = get_req_buffer(); - req->handle = handle; - if (server_call( REQ_GET_HANDLE_INFO )) return FALSE; - if (flags) *flags = req->flags; - return TRUE; + BOOL ret; + SERVER_START_REQ + { + struct get_handle_info_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = handle; + ret = !server_call( REQ_GET_HANDLE_INFO ); + if (ret && flags) *flags = req->flags; + } + SERVER_END_REQ; + return ret; } @@ -47,11 +55,17 @@ BOOL WINAPI GetHandleInformation( HANDLE handle, LPDWORD flags ) */ BOOL WINAPI SetHandleInformation( HANDLE handle, DWORD mask, DWORD flags ) { - struct set_handle_info_request *req = get_req_buffer(); - req->handle = handle; - req->flags = flags; - req->mask = mask; - return !server_call( REQ_SET_HANDLE_INFO ); + BOOL ret; + SERVER_START_REQ + { + struct set_handle_info_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = handle; + req->flags = flags; + req->mask = mask; + ret = !server_call( REQ_SET_HANDLE_INFO ); + } + SERVER_END_REQ; + return ret; } @@ -62,18 +76,23 @@ BOOL WINAPI DuplicateHandle( HANDLE source_process, HANDLE source, HANDLE dest_process, HANDLE *dest, DWORD access, BOOL inherit, DWORD options ) { - struct dup_handle_request *req = get_req_buffer(); - - req->src_process = source_process; - req->src_handle = source; - req->dst_process = dest_process; - req->access = access; - req->inherit = inherit; - req->options = options; - - if (server_call( REQ_DUP_HANDLE )) return FALSE; - if (dest) *dest = req->handle; - return TRUE; + BOOL ret; + SERVER_START_REQ + { + struct dup_handle_request *req = server_alloc_req( sizeof(*req), 0 ); + + req->src_process = source_process; + req->src_handle = source; + req->dst_process = dest_process; + req->access = access; + req->inherit = inherit; + req->options = options; + + ret = !server_call( REQ_DUP_HANDLE ); + if (ret && dest) *dest = req->handle; + } + SERVER_END_REQ; + return ret; } @@ -82,17 +101,10 @@ BOOL WINAPI DuplicateHandle( HANDLE source_process, HANDLE source, */ HANDLE WINAPI ConvertToGlobalHandle(HANDLE hSrc) { - struct dup_handle_request *req = get_req_buffer(); - - req->src_process = GetCurrentProcess(); - req->src_handle = hSrc; - req->dst_process = -1; - req->access = 0; - req->inherit = FALSE; - req->options = DUP_HANDLE_MAKE_GLOBAL | DUP_HANDLE_SAME_ACCESS | DUP_HANDLE_CLOSE_SOURCE; - - server_call( REQ_DUP_HANDLE ); - return req->handle; + HANDLE ret = -1; + DuplicateHandle( GetCurrentProcess(), hSrc, (HANDLE)-1, &ret, 0, FALSE, + DUP_HANDLE_MAKE_GLOBAL | DUP_HANDLE_SAME_ACCESS | DUP_HANDLE_CLOSE_SOURCE ); + return ret; } /*********************************************************************** diff --git a/scheduler/mutex.c b/scheduler/mutex.c index f656ed384d467563f79b28a0e3e1812d65e77316..c0d3a69df95c5b0cfe16a3cf4b99d762d72abfe9 100644 --- a/scheduler/mutex.c +++ b/scheduler/mutex.c @@ -7,6 +7,7 @@ #include <assert.h> #include <string.h> #include "winerror.h" +#include "wine/unicode.h" #include "server.h" @@ -15,15 +16,27 @@ */ HANDLE WINAPI CreateMutexA( SECURITY_ATTRIBUTES *sa, BOOL owner, LPCSTR name ) { - struct create_mutex_request *req = get_req_buffer(); + HANDLE ret; + DWORD len = name ? MultiByteToWideChar( CP_ACP, 0, name, strlen(name), NULL, 0 ) : 0; + if (len >= MAX_PATH) + { + SetLastError( ERROR_FILENAME_EXCED_RANGE ); + return 0; + } + SERVER_START_REQ + { + struct create_mutex_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) ); - req->owned = owner; - req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); - server_strcpyAtoW( req->name, name ); - SetLastError(0); - server_call( REQ_CREATE_MUTEX ); - if (req->handle == -1) return 0; - return req->handle; + req->owned = owner; + req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); + if (len) MultiByteToWideChar( CP_ACP, 0, name, strlen(name), server_data_ptr(req), len ); + SetLastError(0); + server_call( REQ_CREATE_MUTEX ); + ret = req->handle; + } + SERVER_END_REQ; + if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ + return ret; } @@ -32,15 +45,27 @@ HANDLE WINAPI CreateMutexA( SECURITY_ATTRIBUTES *sa, BOOL owner, LPCSTR name ) */ HANDLE WINAPI CreateMutexW( SECURITY_ATTRIBUTES *sa, BOOL owner, LPCWSTR name ) { - struct create_mutex_request *req = get_req_buffer(); + HANDLE ret; + DWORD len = name ? strlenW(name) : 0; + if (len >= MAX_PATH) + { + SetLastError( ERROR_FILENAME_EXCED_RANGE ); + return 0; + } + SERVER_START_REQ + { + struct create_mutex_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) ); - req->owned = owner; - req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); - server_strcpyW( req->name, name ); - SetLastError(0); - server_call( REQ_CREATE_MUTEX ); - if (req->handle == -1) return 0; - return req->handle; + req->owned = owner; + req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); + memcpy( server_data_ptr(req), name, len * sizeof(WCHAR) ); + SetLastError(0); + server_call( REQ_CREATE_MUTEX ); + ret = req->handle; + } + SERVER_END_REQ; + if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ + return ret; } @@ -49,14 +74,26 @@ HANDLE WINAPI CreateMutexW( SECURITY_ATTRIBUTES *sa, BOOL owner, LPCWSTR name ) */ HANDLE WINAPI OpenMutexA( DWORD access, BOOL inherit, LPCSTR name ) { - struct open_mutex_request *req = get_req_buffer(); + HANDLE ret; + DWORD len = name ? MultiByteToWideChar( CP_ACP, 0, name, strlen(name), NULL, 0 ) : 0; + if (len >= MAX_PATH) + { + SetLastError( ERROR_FILENAME_EXCED_RANGE ); + return 0; + } + SERVER_START_REQ + { + struct open_mutex_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) ); - req->access = access; - req->inherit = inherit; - server_strcpyAtoW( req->name, name ); - server_call( REQ_OPEN_MUTEX ); - if (req->handle == -1) return 0; /* must return 0 on failure, not -1 */ - return req->handle; + req->access = access; + req->inherit = inherit; + if (len) MultiByteToWideChar( CP_ACP, 0, name, strlen(name), server_data_ptr(req), len ); + server_call( REQ_OPEN_MUTEX ); + ret = req->handle; + } + SERVER_END_REQ; + if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ + return ret; } @@ -65,14 +102,26 @@ HANDLE WINAPI OpenMutexA( DWORD access, BOOL inherit, LPCSTR name ) */ HANDLE WINAPI OpenMutexW( DWORD access, BOOL inherit, LPCWSTR name ) { - struct open_mutex_request *req = get_req_buffer(); + HANDLE ret; + DWORD len = name ? strlenW(name) : 0; + if (len >= MAX_PATH) + { + SetLastError( ERROR_FILENAME_EXCED_RANGE ); + return 0; + } + SERVER_START_REQ + { + struct open_mutex_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) ); - req->access = access; - req->inherit = inherit; - server_strcpyW( req->name, name ); - server_call( REQ_OPEN_MUTEX ); - if (req->handle == -1) return 0; /* must return 0 on failure, not -1 */ - return req->handle; + req->access = access; + req->inherit = inherit; + memcpy( server_data_ptr(req), name, len * sizeof(WCHAR) ); + server_call( REQ_OPEN_MUTEX ); + ret = req->handle; + } + SERVER_END_REQ; + if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ + return ret; } @@ -81,7 +130,13 @@ HANDLE WINAPI OpenMutexW( DWORD access, BOOL inherit, LPCWSTR name ) */ BOOL WINAPI ReleaseMutex( HANDLE handle ) { - struct release_mutex_request *req = get_req_buffer(); - req->handle = handle; - return !server_call( REQ_RELEASE_MUTEX ); + BOOL ret; + SERVER_START_REQ + { + struct release_mutex_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = handle; + ret = !server_call( REQ_RELEASE_MUTEX ); + } + SERVER_END_REQ; + return ret; } diff --git a/scheduler/pipe.c b/scheduler/pipe.c index 6b018c7a93ac47c7f97a417c4eb0a88d113af00b..3d83e5373da621669cf1e508387d76f275283a06 100644 --- a/scheduler/pipe.c +++ b/scheduler/pipe.c @@ -16,11 +16,18 @@ BOOL WINAPI CreatePipe( PHANDLE hReadPipe, PHANDLE hWritePipe, LPSECURITY_ATTRIBUTES sa, DWORD size ) { - struct create_pipe_request *req = get_req_buffer(); + BOOL ret; + SERVER_START_REQ + { + struct create_pipe_request *req = server_alloc_req( sizeof(*req), 0 ); - req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); - if (server_call( REQ_CREATE_PIPE )) return FALSE; - *hReadPipe = req->handle_read; - *hWritePipe = req->handle_write; - return TRUE; + req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); + if ((ret = !server_call( REQ_CREATE_PIPE ))) + { + *hReadPipe = req->handle_read; + *hWritePipe = req->handle_write; + } + } + SERVER_END_REQ; + return ret; } diff --git a/scheduler/process.c b/scheduler/process.c index 594d85a0544f9a38a35c428a0ed9257dc6818e8b..a82486d675771beacc0ecdcaf9d25d03d2b23c44 100644 --- a/scheduler/process.c +++ b/scheduler/process.c @@ -164,7 +164,7 @@ void PROCESS_CallUserSignalProc( UINT uCode, HMODULE hModule ) */ static BOOL process_init( char *argv[] ) { - struct init_process_request *req; + BOOL ret; /* store the program name */ argv0 = argv[0]; @@ -183,18 +183,26 @@ static BOOL process_init( char *argv[] ) if (CLIENT_InitThread()) return FALSE; /* Retrieve startup info from the server */ - req = get_req_buffer(); - req->ldt_copy = ldt_copy; - req->ldt_flags = ldt_flags_copy; - req->ppid = getppid(); - if (server_call( REQ_INIT_PROCESS )) return FALSE; - main_exe_file = req->exe_file; - if (req->filename[0]) main_exe_name = strdup( req->filename ); - current_startupinfo.dwFlags = req->start_flags; - current_startupinfo.wShowWindow = req->cmd_show; - current_envdb.hStdin = current_startupinfo.hStdInput = req->hstdin; - current_envdb.hStdout = current_startupinfo.hStdOutput = req->hstdout; - current_envdb.hStderr = current_startupinfo.hStdError = req->hstderr; + SERVER_START_REQ + { + struct init_process_request *req = server_alloc_req( sizeof(*req), 0 ); + + req->ldt_copy = ldt_copy; + req->ldt_flags = ldt_flags_copy; + req->ppid = getppid(); + if ((ret = !server_call( REQ_INIT_PROCESS ))) + { + main_exe_file = req->exe_file; + if (req->filename[0]) main_exe_name = strdup( req->filename ); + current_startupinfo.dwFlags = req->start_flags; + current_startupinfo.wShowWindow = req->cmd_show; + current_envdb.hStdin = current_startupinfo.hStdInput = req->hstdin; + current_envdb.hStdout = current_startupinfo.hStdOutput = req->hstdout; + current_envdb.hStderr = current_startupinfo.hStdError = req->hstderr; + } + } + SERVER_END_REQ; + if (!ret) return FALSE; /* Remember TEB selector of initial process for emergency use */ SYSLEVEL_EmergencyTeb = NtCurrentTeb()->teb_sel; @@ -298,7 +306,6 @@ static inline char *build_command_line( char **argv ) */ static void start_process(void) { - struct init_process_done_request *req = get_req_buffer(); int debugged, console_app; LPTHREAD_START_ROUTINE entry; HMODULE module = current_process.exe_modref->module; @@ -316,12 +323,17 @@ static void start_process(void) if (console_app) current_process.flags |= PDB32_CONSOLE_PROC; /* Signal the parent process to continue */ - req->module = (void *)module; - req->entry = entry; - req->name = ¤t_process.exe_modref->filename; - req->gui = !console_app; - server_call( REQ_INIT_PROCESS_DONE ); - debugged = req->debugged; + SERVER_START_REQ + { + struct init_process_done_request *req = server_alloc_req( sizeof(*req), 0 ); + req->module = (void *)module; + req->entry = entry; + req->name = ¤t_process.exe_modref->filename; + req->gui = !console_app; + server_call( REQ_INIT_PROCESS_DONE ); + debugged = req->debugged; + } + SERVER_END_REQ; /* Install signal handlers; this cannot be done before, since we cannot * send exceptions to the debugger before the create process event that @@ -705,13 +717,13 @@ BOOL PROCESS_Create( HFILE hFile, LPCSTR filename, LPSTR cmd_line, LPCSTR env, BOOL inherit, DWORD flags, LPSTARTUPINFOA startup, LPPROCESS_INFORMATION info, LPCSTR lpCurrentDirectory ) { + BOOL ret; int pid; const char *unixfilename = NULL; const char *unixdir = NULL; DOS_FULL_NAME full_name; HANDLE load_done_evt = -1; struct new_process_request *req = get_req_buffer(); - struct wait_process_request *wait_req = get_req_buffer(); info->hThread = info->hProcess = INVALID_HANDLE_VALUE; @@ -764,16 +776,24 @@ BOOL PROCESS_Create( HFILE hFile, LPCSTR filename, LPSTR cmd_line, LPCSTR env, pid = fork_and_exec( unixfilename, cmd_line, env ? env : GetEnvironmentStringsA(), unixdir ); - wait_req->cancel = (pid == -1); - wait_req->pinherit = (psa && (psa->nLength >= sizeof(*psa)) && psa->bInheritHandle); - wait_req->tinherit = (tsa && (tsa->nLength >= sizeof(*tsa)) && tsa->bInheritHandle); - wait_req->timeout = 2000; - if (server_call( REQ_WAIT_PROCESS ) || (pid == -1)) goto error; - info->dwProcessId = (DWORD)wait_req->pid; - info->dwThreadId = (DWORD)wait_req->tid; - info->hProcess = wait_req->phandle; - info->hThread = wait_req->thandle; - load_done_evt = wait_req->event; + SERVER_START_REQ + { + struct wait_process_request *req = server_alloc_req( sizeof(*req), 0 ); + req->cancel = (pid == -1); + req->pinherit = (psa && (psa->nLength >= sizeof(*psa)) && psa->bInheritHandle); + req->tinherit = (tsa && (tsa->nLength >= sizeof(*tsa)) && tsa->bInheritHandle); + req->timeout = 2000; + if ((ret = !server_call( REQ_WAIT_PROCESS )) && (pid != -1)) + { + info->dwProcessId = (DWORD)req->pid; + info->dwThreadId = (DWORD)req->tid; + info->hProcess = req->phandle; + info->hThread = req->thandle; + load_done_evt = req->event; + } + } + SERVER_END_REQ; + if (!ret || (pid == -1)) goto error; /* Wait until process is initialized (or initialization failed) */ if (load_done_evt != -1) @@ -809,13 +829,16 @@ error: */ void WINAPI ExitProcess( DWORD status ) { - struct terminate_process_request *req = get_req_buffer(); - MODULE_DllProcessDetach( TRUE, (LPVOID)1 ); - /* send the exit code to the server */ - req->handle = GetCurrentProcess(); - req->exit_code = status; - server_call( REQ_TERMINATE_PROCESS ); + SERVER_START_REQ + { + struct terminate_process_request *req = server_alloc_req( sizeof(*req), 0 ); + /* send the exit code to the server */ + req->handle = GetCurrentProcess(); + req->exit_code = status; + server_call( REQ_TERMINATE_PROCESS ); + } + SERVER_END_REQ; exit( status ); } @@ -833,12 +856,9 @@ void WINAPI ExitProcess16( WORD status ) */ BOOL WINAPI TerminateProcess( HANDLE handle, DWORD exit_code ) { - BOOL ret; - struct terminate_process_request *req = get_req_buffer(); - req->handle = handle; - req->exit_code = exit_code; - if ((ret = !server_call( REQ_TERMINATE_PROCESS )) && req->self) exit( exit_code ); - return ret; + NTSTATUS status = NtTerminateProcess( handle, exit_code ); + if (status) SetLastError( RtlNtStatusToDosError(status) ); + return !status; } @@ -973,14 +993,18 @@ void WINAPI SetProcessDword( DWORD dwProcessID, INT offset, DWORD value ) HANDLE WINAPI OpenProcess( DWORD access, BOOL inherit, DWORD id ) { HANDLE ret = 0; - struct open_process_request *req = get_req_buffer(); + SERVER_START_REQ + { + struct open_process_request *req = server_alloc_req( sizeof(*req), 0 ); - req->pid = (void *)id; - req->access = access; - req->inherit = inherit; - if (!server_call( REQ_OPEN_PROCESS )) ret = req->handle; + req->pid = (void *)id; + req->access = access; + req->inherit = inherit; + if (!server_call( REQ_OPEN_PROCESS )) ret = req->handle; + } + SERVER_END_REQ; return ret; -} +} /********************************************************************* * MapProcessHandle (KERNEL.483) @@ -988,9 +1012,13 @@ HANDLE WINAPI OpenProcess( DWORD access, BOOL inherit, DWORD id ) DWORD WINAPI MapProcessHandle( HANDLE handle ) { DWORD ret = 0; - struct get_process_info_request *req = get_req_buffer(); - req->handle = handle; - if (!server_call( REQ_GET_PROCESS_INFO )) ret = (DWORD)req->pid; + SERVER_START_REQ + { + struct get_process_info_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = handle; + if (!server_call( REQ_GET_PROCESS_INFO )) ret = (DWORD)req->pid; + } + SERVER_END_REQ; return ret; } @@ -999,11 +1027,17 @@ DWORD WINAPI MapProcessHandle( HANDLE handle ) */ BOOL WINAPI SetPriorityClass( HANDLE hprocess, DWORD priorityclass ) { - struct set_process_info_request *req = get_req_buffer(); - req->handle = hprocess; - req->priority = priorityclass; - req->mask = SET_PROCESS_INFO_PRIORITY; - return !server_call( REQ_SET_PROCESS_INFO ); + BOOL ret; + SERVER_START_REQ + { + struct set_process_info_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = hprocess; + req->priority = priorityclass; + req->mask = SET_PROCESS_INFO_PRIORITY; + ret = !server_call( REQ_SET_PROCESS_INFO ); + } + SERVER_END_REQ; + return ret; } @@ -1013,9 +1047,13 @@ BOOL WINAPI SetPriorityClass( HANDLE hprocess, DWORD priorityclass ) DWORD WINAPI GetPriorityClass(HANDLE hprocess) { DWORD ret = 0; - struct get_process_info_request *req = get_req_buffer(); - req->handle = hprocess; - if (!server_call( REQ_GET_PROCESS_INFO )) ret = req->priority; + SERVER_START_REQ + { + struct get_process_info_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = hprocess; + if (!server_call( REQ_GET_PROCESS_INFO )) ret = req->priority; + } + SERVER_END_REQ; return ret; } @@ -1025,11 +1063,17 @@ DWORD WINAPI GetPriorityClass(HANDLE hprocess) */ BOOL WINAPI SetProcessAffinityMask( HANDLE hProcess, DWORD affmask ) { - struct set_process_info_request *req = get_req_buffer(); - req->handle = hProcess; - req->affinity = affmask; - req->mask = SET_PROCESS_INFO_AFFINITY; - return !server_call( REQ_SET_PROCESS_INFO ); + BOOL ret; + SERVER_START_REQ + { + struct set_process_info_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = hProcess; + req->affinity = affmask; + req->mask = SET_PROCESS_INFO_AFFINITY; + ret = !server_call( REQ_SET_PROCESS_INFO ); + } + SERVER_END_REQ; + return ret; } /********************************************************************** @@ -1040,14 +1084,18 @@ BOOL WINAPI GetProcessAffinityMask( HANDLE hProcess, LPDWORD lpSystemAffinityMask ) { BOOL ret = FALSE; - struct get_process_info_request *req = get_req_buffer(); - req->handle = hProcess; - if (!server_call( REQ_GET_PROCESS_INFO )) + SERVER_START_REQ { - if (lpProcessAffinityMask) *lpProcessAffinityMask = req->process_affinity; - if (lpSystemAffinityMask) *lpSystemAffinityMask = req->system_affinity; - ret = TRUE; + struct get_process_info_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = hProcess; + if (!server_call( REQ_GET_PROCESS_INFO )) + { + if (lpProcessAffinityMask) *lpProcessAffinityMask = req->process_affinity; + if (lpSystemAffinityMask) *lpSystemAffinityMask = req->system_affinity; + ret = TRUE; + } } + SERVER_END_REQ; return ret; } @@ -1299,14 +1347,15 @@ BOOL WINAPI GetExitCodeProcess( HANDLE hProcess, /* [I] handle to the process */ LPDWORD lpExitCode) /* [O] address to receive termination status */ { - BOOL ret = FALSE; - struct get_process_info_request *req = get_req_buffer(); - req->handle = hProcess; - if (!server_call( REQ_GET_PROCESS_INFO )) + BOOL ret; + SERVER_START_REQ { - if (lpExitCode) *lpExitCode = req->exit_code; - ret = TRUE; + struct get_process_info_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = hProcess; + ret = !server_call( REQ_GET_PROCESS_INFO ); + if (ret && lpExitCode) *lpExitCode = req->exit_code; } + SERVER_END_REQ; return ret; } diff --git a/scheduler/semaphore.c b/scheduler/semaphore.c index e5880a6e5021ebacdec5f50f2ef5e8cf94a1b526..650802665e716590ba744f00633d741425b2ea99 100644 --- a/scheduler/semaphore.c +++ b/scheduler/semaphore.c @@ -7,6 +7,7 @@ #include <assert.h> #include <string.h> #include "winerror.h" +#include "wine/unicode.h" #include "server.h" @@ -15,7 +16,8 @@ */ HANDLE WINAPI CreateSemaphoreA( SECURITY_ATTRIBUTES *sa, LONG initial, LONG max, LPCSTR name ) { - struct create_semaphore_request *req = get_req_buffer(); + HANDLE ret; + DWORD len = name ? MultiByteToWideChar( CP_ACP, 0, name, strlen(name), NULL, 0 ) : 0; /* Check parameters */ @@ -24,15 +26,28 @@ HANDLE WINAPI CreateSemaphoreA( SECURITY_ATTRIBUTES *sa, LONG initial, LONG max, SetLastError( ERROR_INVALID_PARAMETER ); return 0; } + if (len >= MAX_PATH) + { + SetLastError( ERROR_FILENAME_EXCED_RANGE ); + return 0; + } - req->initial = (unsigned int)initial; - req->max = (unsigned int)max; - req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); - server_strcpyAtoW( req->name, name ); - SetLastError(0); - server_call( REQ_CREATE_SEMAPHORE ); - if (req->handle == -1) return 0; - return req->handle; + SERVER_START_REQ + { + struct create_semaphore_request *req = server_alloc_req( sizeof(*req), + len * sizeof(WCHAR) ); + + req->initial = (unsigned int)initial; + req->max = (unsigned int)max; + req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); + if (len) MultiByteToWideChar( CP_ACP, 0, name, strlen(name), server_data_ptr(req), len ); + SetLastError(0); + server_call( REQ_CREATE_SEMAPHORE ); + ret = req->handle; + } + SERVER_END_REQ; + if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ + return ret; } @@ -42,7 +57,8 @@ HANDLE WINAPI CreateSemaphoreA( SECURITY_ATTRIBUTES *sa, LONG initial, LONG max, HANDLE WINAPI CreateSemaphoreW( SECURITY_ATTRIBUTES *sa, LONG initial, LONG max, LPCWSTR name ) { - struct create_semaphore_request *req = get_req_buffer(); + HANDLE ret; + DWORD len = name ? strlenW(name) : 0; /* Check parameters */ @@ -51,15 +67,28 @@ HANDLE WINAPI CreateSemaphoreW( SECURITY_ATTRIBUTES *sa, LONG initial, SetLastError( ERROR_INVALID_PARAMETER ); return 0; } + if (len >= MAX_PATH) + { + SetLastError( ERROR_FILENAME_EXCED_RANGE ); + return 0; + } - req->initial = (unsigned int)initial; - req->max = (unsigned int)max; - req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); - server_strcpyW( req->name, name ); - SetLastError(0); - server_call( REQ_CREATE_SEMAPHORE ); - if (req->handle == -1) return 0; - return req->handle; + SERVER_START_REQ + { + struct create_semaphore_request *req = server_alloc_req( sizeof(*req), + len * sizeof(WCHAR) ); + + req->initial = (unsigned int)initial; + req->max = (unsigned int)max; + req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); + memcpy( server_data_ptr(req), name, len * sizeof(WCHAR) ); + SetLastError(0); + server_call( REQ_CREATE_SEMAPHORE ); + ret = req->handle; + } + SERVER_END_REQ; + if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ + return ret; } @@ -68,14 +97,26 @@ HANDLE WINAPI CreateSemaphoreW( SECURITY_ATTRIBUTES *sa, LONG initial, */ HANDLE WINAPI OpenSemaphoreA( DWORD access, BOOL inherit, LPCSTR name ) { - struct open_semaphore_request *req = get_req_buffer(); - - req->access = access; - req->inherit = inherit; - server_strcpyAtoW( req->name, name ); - server_call( REQ_OPEN_SEMAPHORE ); - if (req->handle == -1) return 0; /* must return 0 on failure, not -1 */ - return req->handle; + HANDLE ret; + DWORD len = name ? MultiByteToWideChar( CP_ACP, 0, name, strlen(name), NULL, 0 ) : 0; + if (len >= MAX_PATH) + { + SetLastError( ERROR_FILENAME_EXCED_RANGE ); + return 0; + } + SERVER_START_REQ + { + struct open_semaphore_request *req = server_alloc_req( sizeof(*req), + len * sizeof(WCHAR) ); + req->access = access; + req->inherit = inherit; + if (len) MultiByteToWideChar( CP_ACP, 0, name, strlen(name), server_data_ptr(req), len ); + server_call( REQ_OPEN_SEMAPHORE ); + ret = req->handle; + } + SERVER_END_REQ; + if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ + return ret; } @@ -84,14 +125,25 @@ HANDLE WINAPI OpenSemaphoreA( DWORD access, BOOL inherit, LPCSTR name ) */ HANDLE WINAPI OpenSemaphoreW( DWORD access, BOOL inherit, LPCWSTR name ) { - struct open_semaphore_request *req = get_req_buffer(); - - req->access = access; - req->inherit = inherit; - server_strcpyW( req->name, name ); - server_call( REQ_OPEN_SEMAPHORE ); - if (req->handle == -1) return 0; /* must return 0 on failure, not -1 */ - return req->handle; + HANDLE ret; + DWORD len = name ? strlenW(name) : 0; + if (len >= MAX_PATH) + { + SetLastError( ERROR_FILENAME_EXCED_RANGE ); + return 0; + } + SERVER_START_REQ + { + struct open_semaphore_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) ); + req->access = access; + req->inherit = inherit; + memcpy( server_data_ptr(req), name, len * sizeof(WCHAR) ); + server_call( REQ_OPEN_SEMAPHORE ); + ret = req->handle; + } + SERVER_END_REQ; + if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ + return ret; } @@ -100,20 +152,7 @@ HANDLE WINAPI OpenSemaphoreW( DWORD access, BOOL inherit, LPCWSTR name ) */ BOOL WINAPI ReleaseSemaphore( HANDLE handle, LONG count, LONG *previous ) { - BOOL ret = FALSE; - struct release_semaphore_request *req = get_req_buffer(); - - if (count < 0) - { - SetLastError( ERROR_INVALID_PARAMETER ); - return FALSE; - } - req->handle = handle; - req->count = (unsigned int)count; - if (!server_call( REQ_RELEASE_SEMAPHORE )) - { - if (previous) *previous = req->prev_count; - ret = TRUE; - } - return ret; + NTSTATUS status = NtReleaseSemaphore( handle, count, previous ); + if (status) SetLastError( RtlNtStatusToDosError(status) ); + return !status; } diff --git a/scheduler/synchro.c b/scheduler/synchro.c index 9bcf55f206f295f9dfd9f1547a687cdedfbf9511..52f112b75b3fe6367d6d142687a1ddde49637043 100644 --- a/scheduler/synchro.c +++ b/scheduler/synchro.c @@ -23,33 +23,39 @@ */ static void call_apcs(void) { - FARPROC proc; - struct get_apc_request *req = get_req_buffer(); + FARPROC proc = NULL; + FILETIME ft; + void *args[4]; for (;;) { - if (server_call( REQ_GET_APC )) return; - switch(req->type) + int type = APC_NONE; + SERVER_START_REQ + { + struct get_apc_request *req = server_alloc_req( sizeof(*req), sizeof(args) ); + if (!server_call( REQ_GET_APC )) + { + type = req->type; + proc = req->func; + memcpy( args, server_data_ptr(req), server_data_size(req) ); + } + } + SERVER_END_REQ; + + switch(type) { case APC_NONE: return; /* no more APCs */ case APC_USER: - if ((proc = req->func)) - { - proc( req->args[0] ); - } + proc( args[0] ); break; case APC_TIMER: - if ((proc = req->func)) - { - FILETIME ft; - /* convert sec/usec to NT time */ - DOSFS_UnixTimeToFileTime( (time_t)req->args[0], &ft, (DWORD)req->args[1] * 10 ); - proc( req->args[2], ft.dwLowDateTime, ft.dwHighDateTime ); - } + /* convert sec/usec to NT time */ + DOSFS_UnixTimeToFileTime( (time_t)args[0], &ft, (DWORD)args[1] * 10 ); + proc( args[2], ft.dwLowDateTime, ft.dwHighDateTime ); break; default: - server_protocol_error( "get_apc_request: bad type %d\n", req->type ); + server_protocol_error( "get_apc_request: bad type %d\n", type ); break; } } @@ -110,7 +116,6 @@ DWORD WINAPI WaitForMultipleObjectsEx( DWORD count, const HANDLE *handles, BOOL wait_all, DWORD timeout, BOOL alertable ) { - struct select_request *req = get_req_buffer(); int i, ret; if (count > MAXIMUM_WAIT_OBJECTS) @@ -119,17 +124,24 @@ DWORD WINAPI WaitForMultipleObjectsEx( DWORD count, const HANDLE *handles, return WAIT_FAILED; } - req->count = count; - req->flags = 0; - req->timeout = timeout; - for (i = 0; i < count; i++) req->handles[i] = handles[i]; + SERVER_START_REQ + { + struct select_request *req = server_alloc_req( sizeof(*req), count * sizeof(int) ); + int *data = server_data_ptr( req ); + + req->flags = 0; + req->timeout = timeout; + for (i = 0; i < count; i++) data[i] = handles[i]; - if (wait_all) req->flags |= SELECT_ALL; - if (alertable) req->flags |= SELECT_ALERTABLE; - if (timeout != INFINITE) req->flags |= SELECT_TIMEOUT; + if (wait_all) req->flags |= SELECT_ALL; + if (alertable) req->flags |= SELECT_ALERTABLE; + if (timeout != INFINITE) req->flags |= SELECT_TIMEOUT; - server_call( REQ_SELECT ); - if ((ret = req->signaled) == STATUS_USER_APC) call_apcs(); + server_call( REQ_SELECT ); + ret = req->signaled; + } + SERVER_END_REQ; + if (ret == STATUS_USER_APC) call_apcs(); return ret; } diff --git a/scheduler/thread.c b/scheduler/thread.c index 5004c7f6ff0fb3991f7a0780bfbc649b909dfd5d..293b3d877b3fec3b81ee4f7a344e202a1e6f01f2 100644 --- a/scheduler/thread.c +++ b/scheduler/thread.c @@ -50,21 +50,30 @@ BOOL THREAD_IsWin16( TEB *teb ) */ TEB *THREAD_IdToTEB( DWORD id ) { - struct get_thread_info_request *req = get_req_buffer(); + TEB *ret = NULL; if (!id || id == GetCurrentThreadId()) return NtCurrentTeb(); - req->handle = -1; - req->tid_in = (void *)id; - if (!server_call_noerr( REQ_GET_THREAD_INFO )) return req->teb; - /* Allow task handles to be used; convert to main thread */ - if ( IsTask16( id ) ) + SERVER_START_REQ { - TDB *pTask = (TDB *)GlobalLock16( id ); - if (pTask) return pTask->teb; + struct get_thread_info_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = -1; + req->tid_in = (void *)id; + if (!server_call_noerr( REQ_GET_THREAD_INFO )) ret = req->teb; } - SetLastError( ERROR_INVALID_PARAMETER ); - return NULL; + SERVER_END_REQ; + + if (!ret) + { + /* Allow task handles to be used; convert to main thread */ + if ( IsTask16( id ) ) + { + TDB *pTask = (TDB *)GlobalLock16( id ); + if (pTask) return pTask->teb; + } + SetLastError( ERROR_INVALID_PARAMETER ); + } + return ret; } @@ -272,16 +281,24 @@ HANDLE WINAPI CreateThread( SECURITY_ATTRIBUTES *sa, DWORD stack, LPTHREAD_START_ROUTINE start, LPVOID param, DWORD flags, LPDWORD id ) { - struct new_thread_request *req = get_req_buffer(); int socket, handle = -1; TEB *teb; - void *tid; + void *tid = 0; - req->suspend = ((flags & CREATE_SUSPENDED) != 0); - req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); - if (server_call_fd( REQ_NEW_THREAD, -1, &socket )) return 0; - handle = req->handle; - tid = req->tid; + SERVER_START_REQ + { + struct new_thread_request *req = server_alloc_req( sizeof(*req), 0 ); + + req->suspend = ((flags & CREATE_SUSPENDED) != 0); + req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); + if (!server_call_fd( REQ_NEW_THREAD, -1, &socket )) + { + handle = req->handle; + tid = req->tid; + } + } + SERVER_END_REQ; + if (handle == -1) return 0; if (!(teb = THREAD_Create( socket, stack, TRUE ))) { @@ -297,6 +314,7 @@ HANDLE WINAPI CreateThread( SECURITY_ATTRIBUTES *sa, DWORD stack, if (SYSDEPS_SpawnThread( teb ) == -1) { CloseHandle( handle ); + THREAD_FreeTEB( teb ); return 0; } return handle; @@ -335,13 +353,20 @@ HANDLE WINAPI CreateThread16( SECURITY_ATTRIBUTES *sa, DWORD stack, */ void WINAPI ExitThread( DWORD code ) /* [in] Exit code for this thread */ { - struct terminate_thread_request *req = get_req_buffer(); + BOOL last; + SERVER_START_REQ + { + struct terminate_thread_request *req = server_alloc_req( sizeof(*req), 0 ); + + /* send the exit code to the server */ + req->handle = GetCurrentThread(); + req->exit_code = code; + server_call( REQ_TERMINATE_THREAD ); + last = req->last; + } + SERVER_END_REQ; - /* send the exit code to the server */ - req->handle = GetCurrentThread(); - req->exit_code = code; - server_call( REQ_TERMINATE_THREAD ); - if (req->last) + if (last) { MODULE_DllProcessDetach( TRUE, (LPVOID)1 ); exit( code ); @@ -474,11 +499,17 @@ BOOL WINAPI TlsSetValue( BOOL WINAPI SetThreadContext( HANDLE handle, /* [in] Handle to thread with context */ const CONTEXT *context ) /* [in] Address of context structure */ { - struct set_thread_context_request *req = get_req_buffer(); - req->handle = handle; - req->flags = context->ContextFlags; - memcpy( &req->context, context, sizeof(*context) ); - return !server_call( REQ_SET_THREAD_CONTEXT ); + BOOL ret; + SERVER_START_REQ + { + struct set_thread_context_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = handle; + req->flags = context->ContextFlags; + memcpy( &req->context, context, sizeof(*context) ); + ret = !server_call( REQ_SET_THREAD_CONTEXT ); + } + SERVER_END_REQ; + return ret; } @@ -492,13 +523,18 @@ BOOL WINAPI SetThreadContext( HANDLE handle, /* [in] Handle to thread BOOL WINAPI GetThreadContext( HANDLE handle, /* [in] Handle to thread with context */ CONTEXT *context ) /* [out] Address of context structure */ { - struct get_thread_context_request *req = get_req_buffer(); - req->handle = handle; - req->flags = context->ContextFlags; - memcpy( &req->context, context, sizeof(*context) ); - if (server_call( REQ_GET_THREAD_CONTEXT )) return FALSE; - memcpy( context, &req->context, sizeof(*context) ); - return TRUE; + BOOL ret; + SERVER_START_REQ + { + struct get_thread_context_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = handle; + req->flags = context->ContextFlags; + memcpy( &req->context, context, sizeof(*context) ); + if ((ret = !server_call( REQ_GET_THREAD_CONTEXT ))) + memcpy( context, &req->context, sizeof(*context) ); + } + SERVER_END_REQ; + return ret; } @@ -513,10 +549,14 @@ INT WINAPI GetThreadPriority( HANDLE hthread) /* [in] Handle to thread */ { INT ret = THREAD_PRIORITY_ERROR_RETURN; - struct get_thread_info_request *req = get_req_buffer(); - req->handle = hthread; - req->tid_in = 0; - if (!server_call( REQ_GET_THREAD_INFO )) ret = req->priority; + SERVER_START_REQ + { + struct get_thread_info_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = hthread; + req->tid_in = 0; + if (!server_call( REQ_GET_THREAD_INFO )) ret = req->priority; + } + SERVER_END_REQ; return ret; } @@ -532,11 +572,17 @@ BOOL WINAPI SetThreadPriority( HANDLE hthread, /* [in] Handle to thread */ INT priority) /* [in] Thread priority level */ { - struct set_thread_info_request *req = get_req_buffer(); - req->handle = hthread; - req->priority = priority; - req->mask = SET_THREAD_INFO_PRIORITY; - return !server_call( REQ_SET_THREAD_INFO ); + BOOL ret; + SERVER_START_REQ + { + struct set_thread_info_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = hthread; + req->priority = priority; + req->mask = SET_THREAD_INFO_PRIORITY; + ret = !server_call( REQ_SET_THREAD_INFO ); + } + SERVER_END_REQ; + return ret; } @@ -581,12 +627,18 @@ BOOL WINAPI SetThreadPriorityBoost( */ DWORD WINAPI SetThreadAffinityMask( HANDLE hThread, DWORD dwThreadAffinityMask ) { - struct set_thread_info_request *req = get_req_buffer(); - req->handle = hThread; - req->affinity = dwThreadAffinityMask; - req->mask = SET_THREAD_INFO_AFFINITY; - if (server_call( REQ_SET_THREAD_INFO )) return 0; - return 1; /* FIXME: should return previous value */ + DWORD ret; + SERVER_START_REQ + { + struct set_thread_info_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = hThread; + req->affinity = dwThreadAffinityMask; + req->mask = SET_THREAD_INFO_AFFINITY; + ret = !server_call( REQ_SET_THREAD_INFO ); + /* FIXME: should return previous value */ + } + SERVER_END_REQ; + return ret; } @@ -597,21 +649,12 @@ DWORD WINAPI SetThreadAffinityMask( HANDLE hThread, DWORD dwThreadAffinityMask ) * Success: TRUE * Failure: FALSE */ -BOOL WINAPI TerminateThread( - HANDLE handle, /* [in] Handle to thread */ - DWORD exitcode) /* [in] Exit code for thread */ +BOOL WINAPI TerminateThread( HANDLE handle, /* [in] Handle to thread */ + DWORD exit_code) /* [in] Exit code for thread */ { - BOOL ret; - struct terminate_thread_request *req = get_req_buffer(); - req->handle = handle; - req->exit_code = exitcode; - if ((ret = !server_call( REQ_TERMINATE_THREAD )) && req->self) - { - PROCESS_CallUserSignalProc( USIG_THREAD_EXIT, 0 ); - if (req->last) exit( exitcode ); - else SYSDEPS_ExitThread( exitcode ); - } - return ret; + NTSTATUS status = NtTerminateThread( handle, exit_code ); + if (status) SetLastError( RtlNtStatusToDosError(status) ); + return !status; } @@ -626,15 +669,16 @@ BOOL WINAPI GetExitCodeThread( HANDLE hthread, /* [in] Handle to thread */ LPDWORD exitcode) /* [out] Address to receive termination status */ { - BOOL ret = FALSE; - struct get_thread_info_request *req = get_req_buffer(); - req->handle = hthread; - req->tid_in = 0; - if (!server_call( REQ_GET_THREAD_INFO )) + BOOL ret; + SERVER_START_REQ { - if (exitcode) *exitcode = req->exit_code; - ret = TRUE; + struct get_thread_info_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = hthread; + req->tid_in = 0; + ret = !server_call( REQ_GET_THREAD_INFO ); + if (ret && exitcode) *exitcode = req->exit_code; } + SERVER_END_REQ; return ret; } @@ -654,9 +698,13 @@ DWORD WINAPI ResumeThread( HANDLE hthread) /* [in] Identifies thread to restart */ { DWORD ret = 0xffffffff; - struct resume_thread_request *req = get_req_buffer(); - req->handle = hthread; - if (!server_call( REQ_RESUME_THREAD )) ret = req->count; + SERVER_START_REQ + { + struct resume_thread_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = hthread; + if (!server_call( REQ_RESUME_THREAD )) ret = req->count; + } + SERVER_END_REQ; return ret; } @@ -672,9 +720,13 @@ DWORD WINAPI SuspendThread( HANDLE hthread) /* [in] Handle to the thread */ { DWORD ret = 0xffffffff; - struct suspend_thread_request *req = get_req_buffer(); - req->handle = hthread; - if (!server_call( REQ_SUSPEND_THREAD )) ret = req->count; + SERVER_START_REQ + { + struct suspend_thread_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = hthread; + if (!server_call( REQ_SUSPEND_THREAD )) ret = req->count; + } + SERVER_END_REQ; return ret; } @@ -684,11 +736,17 @@ DWORD WINAPI SuspendThread( */ DWORD WINAPI QueueUserAPC( PAPCFUNC func, HANDLE hthread, ULONG_PTR data ) { - struct queue_apc_request *req = get_req_buffer(); - req->handle = hthread; - req->func = func; - req->param = (void *)data; - return !server_call( REQ_QUEUE_APC ); + DWORD ret; + SERVER_START_REQ + { + struct queue_apc_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = hthread; + req->func = func; + req->param = (void *)data; + ret = !server_call( REQ_QUEUE_APC ); + } + SERVER_END_REQ; + return ret; } diff --git a/scheduler/timer.c b/scheduler/timer.c index 0992be412fb4616204020f1389778ddfc00eb294..fe8020e4e6f556072dbd1cc84ae7fe3dea180c54 100644 --- a/scheduler/timer.c +++ b/scheduler/timer.c @@ -7,6 +7,7 @@ #include <assert.h> #include <string.h> #include "winerror.h" +#include "wine/unicode.h" #include "file.h" /* for FILETIME routines */ #include "server.h" @@ -16,15 +17,27 @@ */ HANDLE WINAPI CreateWaitableTimerA( SECURITY_ATTRIBUTES *sa, BOOL manual, LPCSTR name ) { - struct create_timer_request *req = get_req_buffer(); - - req->manual = manual; - req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); - server_strcpyAtoW( req->name, name ); - SetLastError(0); - server_call( REQ_CREATE_TIMER ); - if (req->handle == -1) return 0; - return req->handle; + HANDLE ret; + DWORD len = name ? MultiByteToWideChar( CP_ACP, 0, name, strlen(name), NULL, 0 ) : 0; + if (len >= MAX_PATH) + { + SetLastError( ERROR_FILENAME_EXCED_RANGE ); + return 0; + } + SERVER_START_REQ + { + struct create_timer_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) ); + + req->manual = manual; + req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); + if (len) MultiByteToWideChar( CP_ACP, 0, name, strlen(name), server_data_ptr(req), len ); + SetLastError(0); + server_call( REQ_CREATE_TIMER ); + ret = req->handle; + } + SERVER_END_REQ; + if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ + return ret; } @@ -33,15 +46,27 @@ HANDLE WINAPI CreateWaitableTimerA( SECURITY_ATTRIBUTES *sa, BOOL manual, LPCSTR */ HANDLE WINAPI CreateWaitableTimerW( SECURITY_ATTRIBUTES *sa, BOOL manual, LPCWSTR name ) { - struct create_timer_request *req = get_req_buffer(); - - req->manual = manual; - req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); - server_strcpyW( req->name, name ); - SetLastError(0); - server_call( REQ_CREATE_TIMER ); - if (req->handle == -1) return 0; - return req->handle; + HANDLE ret; + DWORD len = name ? strlenW(name) : 0; + if (len >= MAX_PATH) + { + SetLastError( ERROR_FILENAME_EXCED_RANGE ); + return 0; + } + SERVER_START_REQ + { + struct create_timer_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) ); + + req->manual = manual; + req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); + memcpy( server_data_ptr(req), name, len * sizeof(WCHAR) ); + SetLastError(0); + server_call( REQ_CREATE_TIMER ); + ret = req->handle; + } + SERVER_END_REQ; + if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ + return ret; } @@ -50,14 +75,26 @@ HANDLE WINAPI CreateWaitableTimerW( SECURITY_ATTRIBUTES *sa, BOOL manual, LPCWST */ HANDLE WINAPI OpenWaitableTimerA( DWORD access, BOOL inherit, LPCSTR name ) { - struct open_timer_request *req = get_req_buffer(); - - req->access = access; - req->inherit = inherit; - server_strcpyAtoW( req->name, name ); - server_call( REQ_OPEN_TIMER ); - if (req->handle == -1) return 0; /* must return 0 on failure, not -1 */ - return req->handle; + HANDLE ret; + DWORD len = name ? MultiByteToWideChar( CP_ACP, 0, name, strlen(name), NULL, 0 ) : 0; + if (len >= MAX_PATH) + { + SetLastError( ERROR_FILENAME_EXCED_RANGE ); + return 0; + } + SERVER_START_REQ + { + struct open_timer_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) ); + + req->access = access; + req->inherit = inherit; + if (len) MultiByteToWideChar( CP_ACP, 0, name, strlen(name), server_data_ptr(req), len ); + server_call( REQ_OPEN_TIMER ); + ret = req->handle; + } + SERVER_END_REQ; + if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ + return ret; } @@ -66,14 +103,26 @@ HANDLE WINAPI OpenWaitableTimerA( DWORD access, BOOL inherit, LPCSTR name ) */ HANDLE WINAPI OpenWaitableTimerW( DWORD access, BOOL inherit, LPCWSTR name ) { - struct open_timer_request *req = get_req_buffer(); - - req->access = access; - req->inherit = inherit; - server_strcpyW( req->name, name ); - server_call( REQ_OPEN_TIMER ); - if (req->handle == -1) return 0; /* must return 0 on failure, not -1 */ - return req->handle; + HANDLE ret; + DWORD len = name ? strlenW(name) : 0; + if (len >= MAX_PATH) + { + SetLastError( ERROR_FILENAME_EXCED_RANGE ); + return 0; + } + SERVER_START_REQ + { + struct open_timer_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) ); + + req->access = access; + req->inherit = inherit; + memcpy( server_data_ptr(req), name, len * sizeof(WCHAR) ); + server_call( REQ_OPEN_TIMER ); + ret = req->handle; + } + SERVER_END_REQ; + if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ + return ret; } @@ -83,9 +132,9 @@ HANDLE WINAPI OpenWaitableTimerW( DWORD access, BOOL inherit, LPCWSTR name ) BOOL WINAPI SetWaitableTimer( HANDLE handle, const LARGE_INTEGER *when, LONG period, PTIMERAPCROUTINE callback, LPVOID arg, BOOL resume ) { + BOOL ret; FILETIME ft; DWORD remainder; - struct set_timer_request *req = get_req_buffer(); if (when->s.HighPart < 0) /* relative time */ { @@ -102,23 +151,30 @@ BOOL WINAPI SetWaitableTimer( HANDLE handle, const LARGE_INTEGER *when, LONG per ft.dwHighDateTime = when->s.HighPart; } - if (!ft.dwLowDateTime && !ft.dwHighDateTime) - { - /* special case to start timeout on now+period without too many calculations */ - req->sec = 0; - req->usec = 0; - } - else + SERVER_START_REQ { - req->sec = DOSFS_FileTimeToUnixTime( &ft, &remainder ); - req->usec = remainder / 10; /* convert from 100-ns to us units */ + struct set_timer_request *req = server_alloc_req( sizeof(*req), 0 ); + + if (!ft.dwLowDateTime && !ft.dwHighDateTime) + { + /* special case to start timeout on now+period without too many calculations */ + req->sec = 0; + req->usec = 0; + } + else + { + req->sec = DOSFS_FileTimeToUnixTime( &ft, &remainder ); + req->usec = remainder / 10; /* convert from 100-ns to us units */ + } + req->handle = handle; + req->period = period; + req->callback = callback; + req->arg = arg; + if (resume) SetLastError( ERROR_NOT_SUPPORTED ); /* set error but can still succeed */ + ret = !server_call( REQ_SET_TIMER ); } - req->handle = handle; - req->period = period; - req->callback = callback; - req->arg = arg; - if (resume) SetLastError( ERROR_NOT_SUPPORTED ); /* set error but can still succeed */ - return !server_call( REQ_SET_TIMER ); + SERVER_END_REQ; + return ret; } @@ -127,7 +183,13 @@ BOOL WINAPI SetWaitableTimer( HANDLE handle, const LARGE_INTEGER *when, LONG per */ BOOL WINAPI CancelWaitableTimer( HANDLE handle ) { - struct cancel_timer_request *req = get_req_buffer(); - req->handle = handle; - return !server_call( REQ_CANCEL_TIMER ); + BOOL ret; + SERVER_START_REQ + { + struct cancel_timer_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = handle; + ret = !server_call( REQ_CANCEL_TIMER ); + } + SERVER_END_REQ; + return ret; } diff --git a/server/atom.c b/server/atom.c index 1e4652cbe8e23509108cdba1d6f007021d5d3d19..5e65b23ad369a84d86dacd7709b35d2a744349b9 100644 --- a/server/atom.c +++ b/server/atom.c @@ -65,13 +65,17 @@ static struct atom_table *global_table; /* copy an atom name to a temporary area */ -static const WCHAR *copy_name( const WCHAR *str ) +static const WCHAR *copy_name( const WCHAR *str, size_t len ) { static WCHAR buffer[MAX_ATOM_LEN+1]; - WCHAR *p = buffer; - while (p < buffer + sizeof(buffer) - 1) if (!(*p++ = *str++)) break; - *p = 0; + if (len > MAX_ATOM_LEN*sizeof(WCHAR)) + { + set_error( STATUS_INVALID_PARAMETER ); + return NULL; + } + memcpy( buffer, str, len ); + buffer[len / sizeof(WCHAR)] = 0; return buffer; } @@ -261,16 +265,24 @@ static int find_atom( struct atom_table *table, const WCHAR *str ) } /* get an atom name and refcount*/ -static int get_atom_name( struct atom_table *table, int atom, WCHAR *str ) +static size_t get_atom_name( struct atom_table *table, int atom, + WCHAR *str, size_t maxsize, int *count ) { - int count = -1; + int len = 0; struct atom_entry *entry = get_atom_entry( table, atom ); + *count = -1; if (entry) { - strcpyW( str, entry->str ); - count = entry->count; + *count = entry->count; + len = strlenW( entry->str ) * sizeof(WCHAR); + if (len <= maxsize) memcpy( str, entry->str, len ); + else + { + set_error( STATUS_BUFFER_OVERFLOW ); + len = 0; + } } - return count; + return len; } /* add a global atom */ @@ -279,29 +291,34 @@ DECL_HANDLER(add_atom) struct atom_table **table_ptr = req->local ? ¤t->process->atom_table : &global_table; if (!*table_ptr) *table_ptr = create_table(0); - if (*table_ptr) req->atom = add_atom( *table_ptr, copy_name( req->name ) ); + if (*table_ptr) + { + const WCHAR *name = copy_name( get_req_data(req), get_req_data_size(req) ); + if (name) req->atom = add_atom( *table_ptr, name ); + } } /* delete a global atom */ DECL_HANDLER(delete_atom) { - delete_atom( req->local ? current->process->atom_table : global_table, - req->atom ); + delete_atom( req->local ? current->process->atom_table : global_table, req->atom ); } /* find a global atom */ DECL_HANDLER(find_atom) { - req->atom = find_atom( req->local ? current->process->atom_table : global_table, - copy_name( req->name ) ); + const WCHAR *name = copy_name( get_req_data(req), get_req_data_size(req) ); + if (name) + req->atom = find_atom( req->local ? current->process->atom_table : global_table, name ); } /* get global atom name */ DECL_HANDLER(get_atom_name) { - req->name[0] = 0; - req->count = get_atom_name( req->local ? current->process->atom_table : global_table, - req->atom, req->name ); + WCHAR *name = get_req_data(req); + size_t size = get_atom_name( req->local ? current->process->atom_table : global_table, + req->atom, name, get_req_data_size(req), &req->count ); + set_req_data_size( req, size ); } /* init the process atom table */ diff --git a/server/debugger.c b/server/debugger.c index 436d1702f0e2d91db51ac5c8efed22081e1e29e8..371e3043f07f115bf391bf7f2df3fee5a319cc14 100644 --- a/server/debugger.c +++ b/server/debugger.c @@ -254,6 +254,7 @@ static void build_wait_debug_reply( struct thread *thread, struct object *obj, i { struct debug_ctx *debug_ctx = (struct debug_ctx *)obj; struct debug_event *event = find_event_to_send( debug_ctx ); + size_t size = get_req_data_size(req); /* the object that woke us has to be our debug context */ assert( obj->ops == &debug_ctx_ops ); @@ -261,14 +262,15 @@ static void build_wait_debug_reply( struct thread *thread, struct object *obj, i event->state = EVENT_SENT; event->sender->debug_event = event; - req->event.code = event->data.code; - req->pid = event->sender->process; - req->tid = event->sender; - memcpy( &req->event, &event->data, sizeof(req->event) ); + req->pid = event->sender->process; + req->tid = event->sender; + if (size > sizeof(debug_event_t)) size = sizeof(debug_event_t); + memcpy( get_req_data(req), &event->data, size ); + set_req_data_size( req, size ); } else /* timeout or error */ { - req->event.code = 0; + set_req_data_size( req, 0 ); req->pid = 0; req->tid = 0; } @@ -536,9 +538,9 @@ DECL_HANDLER(wait_debug_event) { if (!wait_for_debug_event( req->timeout )) { - req->event.code = 0; req->pid = NULL; req->tid = NULL; + set_req_data_size( req, 0 ); } } diff --git a/server/event.c b/server/event.c index 763c8fb1d0cb9b888665f9eb45f022b42a09ba64..f259b9096971407241a87246593379a983a2be6b 100644 --- a/server/event.c +++ b/server/event.c @@ -114,11 +114,11 @@ static int event_satisfied( struct object *obj, struct thread *thread ) /* create an event */ DECL_HANDLER(create_event) { - size_t len = get_req_strlenW( req, req->name ); struct event *event; req->handle = -1; - if ((event = create_event( req->name, len, req->manual_reset, req->initial_state ))) + if ((event = create_event( get_req_data(req), get_req_data_size(req), + req->manual_reset, req->initial_state ))) { req->handle = alloc_handle( current->process, event, EVENT_ALL_ACCESS, req->inherit ); release_object( event ); @@ -128,8 +128,8 @@ DECL_HANDLER(create_event) /* open a handle to an event */ DECL_HANDLER(open_event) { - size_t len = get_req_strlenW( req, req->name ); - req->handle = open_object( req->name, len, &event_ops, req->access, req->inherit ); + req->handle = open_object( get_req_data(req), get_req_data_size(req), + &event_ops, req->access, req->inherit ); } /* do an event operation */ diff --git a/server/mapping.c b/server/mapping.c index 6976cf47c1b5a784488bb44e106dbac4b4d7a3af..0ad6a5707927a2dbf80034ba8b99896196204aab 100644 --- a/server/mapping.c +++ b/server/mapping.c @@ -281,12 +281,12 @@ int get_page_size(void) /* create a file mapping */ DECL_HANDLER(create_mapping) { - size_t len = get_req_strlenW( req, req->name ); struct object *obj; req->handle = -1; if ((obj = create_mapping( req->size_high, req->size_low, - req->protect, req->file_handle, req->name, len ))) + req->protect, req->file_handle, + get_req_data(req), get_req_data_size(req) ))) { int access = FILE_MAP_ALL_ACCESS; if (!(req->protect & VPROT_WRITE)) access &= ~FILE_MAP_WRITE; @@ -298,8 +298,8 @@ DECL_HANDLER(create_mapping) /* open a handle to a mapping */ DECL_HANDLER(open_mapping) { - size_t len = get_req_strlenW( req, req->name ); - req->handle = open_object( req->name, len, &mapping_ops, req->access, req->inherit ); + req->handle = open_object( get_req_data(req), get_req_data_size(req), + &mapping_ops, req->access, req->inherit ); } /* get a mapping information */ diff --git a/server/mutex.c b/server/mutex.c index 7f74b7b06f4e3aa64536125b4b3eef6958b43876..82b76c26b0525694beb8fbc1bb685541c98a8465 100644 --- a/server/mutex.c +++ b/server/mutex.c @@ -139,11 +139,10 @@ static void mutex_destroy( struct object *obj ) /* create a mutex */ DECL_HANDLER(create_mutex) { - size_t len = get_req_strlenW( req, req->name ); struct mutex *mutex; req->handle = -1; - if ((mutex = create_mutex( req->name, len, req->owned ))) + if ((mutex = create_mutex( get_req_data(req), get_req_data_size(req), req->owned ))) { req->handle = alloc_handle( current->process, mutex, MUTEX_ALL_ACCESS, req->inherit ); release_object( mutex ); @@ -153,8 +152,8 @@ DECL_HANDLER(create_mutex) /* open a handle to a mutex */ DECL_HANDLER(open_mutex) { - size_t len = get_req_strlenW( req, req->name ); - req->handle = open_object( req->name, len, &mutex_ops, req->access, req->inherit ); + req->handle = open_object( get_req_data(req), get_req_data_size(req), + &mutex_ops, req->access, req->inherit ); } /* release a mutex */ diff --git a/server/object.c b/server/object.c index cda7bfefd5bf9b5679bbdd036b3dd4e000a83035..f2a7f1feeb42863accae83619f17228617b2d8cc 100644 --- a/server/object.c +++ b/server/object.c @@ -70,6 +70,7 @@ void *memdup( const void *data, size_t len ) static int get_name_hash( const WCHAR *name, size_t len ) { WCHAR hash = 0; + len /= sizeof(WCHAR); while (len--) hash ^= *name++; return hash % NAME_HASH_SIZE; } @@ -79,11 +80,10 @@ static struct object_name *alloc_name( const WCHAR *name, size_t len ) { struct object_name *ptr; - if ((ptr = mem_alloc( sizeof(*ptr) + len * sizeof(ptr->name[0]) ))) + if ((ptr = mem_alloc( sizeof(*ptr) + len - sizeof(ptr->name) ))) { ptr->len = len; - memcpy( ptr->name, name, len * sizeof(ptr->name[0]) ); - ptr->name[len] = 0; + memcpy( ptr->name, name, len ); } return ptr; } @@ -186,7 +186,7 @@ void dump_object_name( struct object *obj ) else { fprintf( stderr, "name=L\"" ); - dump_strW( obj->name->name, strlenW(obj->name->name), stderr, "\"\"" ); + dump_strW( obj->name->name, obj->name->len/sizeof(WCHAR), stderr, "\"\"" ); fputc( '\"', stderr ); } } @@ -228,11 +228,12 @@ void release_object( void *ptr ) struct object *find_object( const WCHAR *name, size_t len ) { struct object_name *ptr; + if (!name || !len) return NULL; for (ptr = names[ get_name_hash( name, len ) ]; ptr; ptr = ptr->next) { if (ptr->len != len) continue; - if (!memcmp( ptr->name, name, len*sizeof(WCHAR) )) return grab_object( ptr->obj ); + if (!memcmp( ptr->name, name, len )) return grab_object( ptr->obj ); } return NULL; } diff --git a/server/request.h b/server/request.h index aa469020fb115e0e3b11b4f861f8db4822d7ff92..bf9b7977495747f162ca224bb75f55afb174280b 100644 --- a/server/request.h +++ b/server/request.h @@ -54,6 +54,18 @@ inline static void *get_req_data( const void *req ) return ((union generic_request *)req + 1); } +/* get the request vararg size */ +inline static size_t get_req_data_size( const void *req ) +{ + return ((struct request_header *)req)->var_size; +} + +/* set the request vararg size */ +inline static void set_req_data_size( const void *req, size_t size ) +{ + ((struct request_header *)req)->var_size = size; +} + #define REQUEST_END(req) ((char *)(req) + MAX_REQUEST_LENGTH - sizeof(struct server_buffer_info)) diff --git a/server/semaphore.c b/server/semaphore.c index 94fe31fde5eadfdb785bf84a0cad6b7d3ef722d6..25c0c5196115850a124846f4ace7ce43df3ce612 100644 --- a/server/semaphore.c +++ b/server/semaphore.c @@ -122,11 +122,11 @@ static int semaphore_satisfied( struct object *obj, struct thread *thread ) /* create a semaphore */ DECL_HANDLER(create_semaphore) { - size_t len = get_req_strlenW( req, req->name ); struct semaphore *sem; req->handle = -1; - if ((sem = create_semaphore( req->name, len, req->initial, req->max ))) + if ((sem = create_semaphore( get_req_data(req), get_req_data_size(req), + req->initial, req->max ))) { req->handle = alloc_handle( current->process, sem, SEMAPHORE_ALL_ACCESS, req->inherit ); release_object( sem ); @@ -136,8 +136,8 @@ DECL_HANDLER(create_semaphore) /* open a handle to a semaphore */ DECL_HANDLER(open_semaphore) { - size_t len = get_req_strlenW( req, req->name ); - req->handle = open_object( req->name, len, &semaphore_ops, req->access, req->inherit ); + req->handle = open_object( get_req_data(req), get_req_data_size(req), + &semaphore_ops, req->access, req->inherit ); } /* release a semaphore */ diff --git a/server/thread.c b/server/thread.c index c1b79fac56c226af8ef051c83119959115304337..d6e9bef4cdec1f87a6a79e2f32d811eccf7a6620 100644 --- a/server/thread.c +++ b/server/thread.c @@ -787,7 +787,8 @@ DECL_HANDLER(resume_thread) /* select on a handle list */ DECL_HANDLER(select) { - if (!select_on( req->count, req->handles, req->flags, req->timeout )) + int count = get_req_data_size(req) / sizeof(int); + if (!select_on( count, get_req_data(req), req->flags, req->timeout )) req->signaled = -1; } @@ -806,21 +807,31 @@ DECL_HANDLER(queue_apc) DECL_HANDLER(get_apc) { struct thread_apc *apc; + size_t size; - if ((apc = thread_dequeue_apc( current ))) + for (;;) { - req->func = apc->func; - req->type = apc->type; - req->nb_args = apc->nb_args; - memcpy( req->args, apc->args, apc->nb_args * sizeof(req->args[0]) ); + if (!(apc = thread_dequeue_apc( current ))) + { + /* no more APCs */ + req->func = NULL; + req->type = APC_NONE; + set_req_data_size( req, 0 ); + return; + } + /* Optimization: ignore APCs that have a NULL func; they are only used + * to wake up a thread, but since we got here the thread woke up already. + */ + if (apc->func) break; free( apc ); } - else - { - req->func = NULL; - req->type = APC_NONE; - req->nb_args = 0; - } + size = apc->nb_args * sizeof(apc->args[0]); + if (size > get_req_data_size(req)) size = get_req_data_size(req); + req->func = apc->func; + req->type = apc->type; + memcpy( get_req_data(req), apc->args, size ); + set_req_data_size( req, size ); + free( apc ); } /* fetch a selector entry for a thread */ diff --git a/server/timer.c b/server/timer.c index c914d93a56a3ae170c1713912a3ce95301192874..d74fc72fe36398bbe5d2f918a205df9bbe44e016 100644 --- a/server/timer.c +++ b/server/timer.c @@ -173,11 +173,10 @@ static void timer_destroy( struct object *obj ) /* create a timer */ DECL_HANDLER(create_timer) { - size_t len = get_req_strlenW( req, req->name ); struct timer *timer; req->handle = -1; - if ((timer = create_timer( req->name, len, req->manual ))) + if ((timer = create_timer( get_req_data(req), get_req_data_size(req), req->manual ))) { req->handle = alloc_handle( current->process, timer, TIMER_ALL_ACCESS, req->inherit ); release_object( timer ); @@ -187,8 +186,8 @@ DECL_HANDLER(create_timer) /* open a handle to a timer */ DECL_HANDLER(open_timer) { - size_t len = get_req_strlenW( req, req->name ); - req->handle = open_object( req->name, len, &timer_ops, req->access, req->inherit ); + req->handle = open_object( get_req_data(req), get_req_data_size(req), + &timer_ops, req->access, req->inherit ); } /* set a waitable timer */ diff --git a/server/trace.c b/server/trace.c index 34ff39ce917a5a2cb54ac901b8851727a5bf5daf..c6b5e915ddc470918eb6bf406f09251344307e75 100644 --- a/server/trace.c +++ b/server/trace.c @@ -100,13 +100,50 @@ static void dump_exc_record( const void *req, const EXCEPTION_RECORD *rec ) fputc( '}', stderr ); } -static void dump_debug_event_t( const void *req, const debug_event_t *event ) +static void dump_varargs_ints( const void *ptr, size_t len ) { + const int *data = ptr; + len /= sizeof(*data); + + fputc( '{', stderr ); + while (len > 0) + { + fprintf( stderr, "%d", *data++ ); + if (--len) fputc( ',', stderr ); + } + fputc( '}', stderr ); +} + +static void dump_varargs_ptrs( const void *ptr, size_t len ) +{ + void * const *data = ptr; + len /= sizeof(*data); + + fputc( '{', stderr ); + while (len > 0) + { + fprintf( stderr, "%p", *data++ ); + if (--len) fputc( ',', stderr ); + } + fputc( '}', stderr ); +} + +static void dump_varargs_unicode_str( const void *ptr, size_t len ) +{ + fprintf( stderr, "L\"" ); + dump_strW( ptr, len / sizeof(WCHAR), stderr, "\"\"" ); + fputc( '\"', stderr ); +} + +static void dump_varargs_debug_event( const void *ptr, size_t len ) +{ + const debug_event_t *event = ptr; + switch(event->code) { case EXCEPTION_DEBUG_EVENT: fprintf( stderr, "{exception," ); - dump_exc_record( req, &event->info.exception.record ); + dump_exc_record( ptr, &event->info.exception.record ); fprintf( stderr, ",first=%d}", event->info.exception.first ); break; case CREATE_THREAD_DEBUG_EVENT: @@ -156,23 +193,8 @@ static void dump_debug_event_t( const void *req, const debug_event_t *event ) } } - /* dumping for functions for requests that have a variable part */ -static void dump_varargs_select_request( const struct select_request *req ) -{ - int count = min( req->count, get_req_size( req, req->handles, sizeof(int) )); - dump_ints( req->handles, count ); -} - -static void dump_varargs_get_apc_reply( const struct get_apc_request *req ) -{ - int i; - for (i = 0; i < req->nb_args; i++) - fprintf( stderr, "%c%p", i ? ',' : '{', req->args[i] ); - fprintf( stderr, "}" ); -} - static void dump_varargs_get_socket_event_reply( const struct get_socket_event_request *req ) { dump_ints( req->errors, FD_MAX_EVENTS ); @@ -430,9 +452,8 @@ static void dump_get_apc_reply( const struct get_apc_request *req ) { fprintf( stderr, " func=%p,", req->func ); fprintf( stderr, " type=%d,", req->type ); - fprintf( stderr, " nb_args=%d,", req->nb_args ); fprintf( stderr, " args=" ); - dump_varargs_get_apc_reply( req ); + dump_varargs_ptrs( get_req_data(req), get_req_data_size(req) ); } static void dump_close_handle_request( const struct close_handle_request *req ) @@ -486,11 +507,10 @@ static void dump_open_process_reply( const struct open_process_request *req ) static void dump_select_request( const struct select_request *req ) { - fprintf( stderr, " count=%d,", req->count ); fprintf( stderr, " flags=%d,", req->flags ); fprintf( stderr, " timeout=%d,", req->timeout ); fprintf( stderr, " handles=" ); - dump_varargs_select_request( req ); + dump_varargs_ints( get_req_data(req), get_req_data_size(req) ); } static void dump_select_reply( const struct select_request *req ) @@ -504,7 +524,7 @@ static void dump_create_event_request( const struct create_event_request *req ) fprintf( stderr, " initial_state=%d,", req->initial_state ); fprintf( stderr, " inherit=%d,", req->inherit ); fprintf( stderr, " name=" ); - dump_unicode_string( req, req->name ); + dump_varargs_unicode_str( get_req_data(req), get_req_data_size(req) ); } static void dump_create_event_reply( const struct create_event_request *req ) @@ -523,7 +543,7 @@ static void dump_open_event_request( const struct open_event_request *req ) fprintf( stderr, " access=%08x,", req->access ); fprintf( stderr, " inherit=%d,", req->inherit ); fprintf( stderr, " name=" ); - dump_unicode_string( req, req->name ); + dump_varargs_unicode_str( get_req_data(req), get_req_data_size(req) ); } static void dump_open_event_reply( const struct open_event_request *req ) @@ -536,7 +556,7 @@ static void dump_create_mutex_request( const struct create_mutex_request *req ) fprintf( stderr, " owned=%d,", req->owned ); fprintf( stderr, " inherit=%d,", req->inherit ); fprintf( stderr, " name=" ); - dump_unicode_string( req, req->name ); + dump_varargs_unicode_str( get_req_data(req), get_req_data_size(req) ); } static void dump_create_mutex_reply( const struct create_mutex_request *req ) @@ -554,7 +574,7 @@ static void dump_open_mutex_request( const struct open_mutex_request *req ) fprintf( stderr, " access=%08x,", req->access ); fprintf( stderr, " inherit=%d,", req->inherit ); fprintf( stderr, " name=" ); - dump_unicode_string( req, req->name ); + dump_varargs_unicode_str( get_req_data(req), get_req_data_size(req) ); } static void dump_open_mutex_reply( const struct open_mutex_request *req ) @@ -568,7 +588,7 @@ static void dump_create_semaphore_request( const struct create_semaphore_request fprintf( stderr, " max=%08x,", req->max ); fprintf( stderr, " inherit=%d,", req->inherit ); fprintf( stderr, " name=" ); - dump_unicode_string( req, req->name ); + dump_varargs_unicode_str( get_req_data(req), get_req_data_size(req) ); } static void dump_create_semaphore_reply( const struct create_semaphore_request *req ) @@ -592,7 +612,7 @@ static void dump_open_semaphore_request( const struct open_semaphore_request *re fprintf( stderr, " access=%08x,", req->access ); fprintf( stderr, " inherit=%d,", req->inherit ); fprintf( stderr, " name=" ); - dump_unicode_string( req, req->name ); + dump_varargs_unicode_str( get_req_data(req), get_req_data_size(req) ); } static void dump_open_semaphore_reply( const struct open_semaphore_request *req ) @@ -890,7 +910,7 @@ static void dump_create_mapping_request( const struct create_mapping_request *re fprintf( stderr, " inherit=%d,", req->inherit ); fprintf( stderr, " file_handle=%d,", req->file_handle ); fprintf( stderr, " name=" ); - dump_unicode_string( req, req->name ); + dump_varargs_unicode_str( get_req_data(req), get_req_data_size(req) ); } static void dump_create_mapping_reply( const struct create_mapping_request *req ) @@ -903,7 +923,7 @@ static void dump_open_mapping_request( const struct open_mapping_request *req ) fprintf( stderr, " access=%08x,", req->access ); fprintf( stderr, " inherit=%d,", req->inherit ); fprintf( stderr, " name=" ); - dump_unicode_string( req, req->name ); + dump_varargs_unicode_str( get_req_data(req), get_req_data_size(req) ); } static void dump_open_mapping_reply( const struct open_mapping_request *req ) @@ -1002,7 +1022,7 @@ static void dump_wait_debug_event_reply( const struct wait_debug_event_request * fprintf( stderr, " pid=%p,", req->pid ); fprintf( stderr, " tid=%p,", req->tid ); fprintf( stderr, " event=" ); - dump_debug_event_t( req, &req->event ); + dump_varargs_debug_event( get_req_data(req), get_req_data_size(req) ); } static void dump_exception_event_request( const struct exception_event_request *req ) @@ -1232,7 +1252,7 @@ static void dump_create_timer_request( const struct create_timer_request *req ) fprintf( stderr, " inherit=%d,", req->inherit ); fprintf( stderr, " manual=%d,", req->manual ); fprintf( stderr, " name=" ); - dump_unicode_string( req, req->name ); + dump_varargs_unicode_str( get_req_data(req), get_req_data_size(req) ); } static void dump_create_timer_reply( const struct create_timer_request *req ) @@ -1245,7 +1265,7 @@ static void dump_open_timer_request( const struct open_timer_request *req ) fprintf( stderr, " access=%08x,", req->access ); fprintf( stderr, " inherit=%d,", req->inherit ); fprintf( stderr, " name=" ); - dump_unicode_string( req, req->name ); + dump_varargs_unicode_str( get_req_data(req), get_req_data_size(req) ); } static void dump_open_timer_reply( const struct open_timer_request *req ) @@ -1305,7 +1325,7 @@ static void dump_add_atom_request( const struct add_atom_request *req ) { fprintf( stderr, " local=%d,", req->local ); fprintf( stderr, " name=" ); - dump_unicode_string( req, req->name ); + dump_varargs_unicode_str( get_req_data(req), get_req_data_size(req) ); } static void dump_add_atom_reply( const struct add_atom_request *req ) @@ -1323,7 +1343,7 @@ static void dump_find_atom_request( const struct find_atom_request *req ) { fprintf( stderr, " local=%d,", req->local ); fprintf( stderr, " name=" ); - dump_unicode_string( req, req->name ); + dump_varargs_unicode_str( get_req_data(req), get_req_data_size(req) ); } static void dump_find_atom_reply( const struct find_atom_request *req ) @@ -1341,7 +1361,7 @@ static void dump_get_atom_name_reply( const struct get_atom_name_request *req ) { fprintf( stderr, " count=%d,", req->count ); fprintf( stderr, " name=" ); - dump_unicode_string( req, req->name ); + dump_varargs_unicode_str( get_req_data(req), get_req_data_size(req) ); } static void dump_init_atom_table_request( const struct init_atom_table_request *req ) diff --git a/tools/make_requests b/tools/make_requests index fd5aed9a48f987ec43a6f574941b169a9de18e7c..7dcad4eb6cf947458f837ac31cfb29de446c90a7 100755 --- a/tools/make_requests +++ b/tools/make_requests @@ -121,7 +121,7 @@ sub DO_REQUEST { $dir = $1; $var = $2; - $type = "&" . $3; + $type = "&dump_varargs_" . $3; } elsif (/^\s*(IN|OUT)\s*(\w+\**(\s+\w+\**)*)\s+(\w+)(\[[1]\])?;/) { @@ -178,8 +178,17 @@ sub DO_DUMP_FUNC } else # must be some varargs format { - push @trace_lines, " fprintf( stderr, \" $var=\" );\n"; - push @trace_lines, " dump_varargs_${name}_${req}( req );\n"; + if ($type =~ /^&(.*)/) + { + my $func = $1; + push @trace_lines, " fprintf( stderr, \" $var=\" );\n"; + push @trace_lines, " $func( get_req_data(req), get_req_data_size(req) );\n"; + } + else + { + push @trace_lines, " fprintf( stderr, \" $var=\" );\n"; + push @trace_lines, " dump_varargs_${name}_${req}( req );\n"; + } } } push @trace_lines, "}\n\n"; diff --git a/win32/console.c b/win32/console.c index 4cb35c97be1c9cc74a255e6ac45077814cb1b76a..03728aeade937bc18049cf37330bee8678093f5e 100644 --- a/win32/console.c +++ b/win32/console.c @@ -647,14 +647,15 @@ UINT WINAPI GetConsoleOutputCP(VOID) */ BOOL WINAPI GetConsoleMode(HANDLE hcon,LPDWORD mode) { - BOOL ret = FALSE; - struct get_console_mode_request *req = get_req_buffer(); - req->handle = hcon; - if (!server_call( REQ_GET_CONSOLE_MODE )) + BOOL ret; + SERVER_START_REQ { - if (mode) *mode = req->mode; - ret = TRUE; + struct get_console_mode_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = hcon; + ret = !server_call( REQ_GET_CONSOLE_MODE ); + if (ret && mode) *mode = req->mode; } + SERVER_END_REQ; return ret; } @@ -672,10 +673,16 @@ BOOL WINAPI GetConsoleMode(HANDLE hcon,LPDWORD mode) */ BOOL WINAPI SetConsoleMode( HANDLE hcon, DWORD mode ) { - struct set_console_mode_request *req = get_req_buffer(); - req->handle = hcon; - req->mode = mode; - return !server_call( REQ_SET_CONSOLE_MODE ); + BOOL ret; + SERVER_START_REQ + { + struct set_console_mode_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = hcon; + req->mode = mode; + ret = !server_call( REQ_SET_CONSOLE_MODE ); + } + SERVER_END_REQ; + return ret; } diff --git a/win32/device.c b/win32/device.c index ce5f29ad56e52ad0de0b34845b223305e8b94504..b95ec82e5a7e104f74f0335f60d2f88137b2344e 100644 --- a/win32/device.c +++ b/win32/device.c @@ -330,18 +330,22 @@ HANDLE DEVICE_Open( LPCSTR filename, DWORD access, static const struct VxDInfo *DEVICE_GetInfo( HANDLE handle ) { - struct get_file_info_request *req = get_req_buffer(); - - req->handle = handle; - if (!server_call( REQ_GET_FILE_INFO ) && - (req->type == FILE_TYPE_UNKNOWN) && - (req->attr & 0x10000)) + const struct VxDInfo *info = NULL; + SERVER_START_REQ { - const struct VxDInfo *info; - for (info = VxDList; info->name; info++) - if (info->id == LOWORD(req->attr)) return info; + struct get_file_info_request *req = server_alloc_req( sizeof(*req), 0 ); + + req->handle = handle; + if (!server_call( REQ_GET_FILE_INFO ) && + (req->type == FILE_TYPE_UNKNOWN) && + (req->attr & 0x10000)) + { + for (info = VxDList; info->name; info++) + if (info->id == LOWORD(req->attr)) break; + } } - return NULL; + SERVER_END_REQ; + return info; } /**************************************************************************** diff --git a/windows/queue.c b/windows/queue.c index 4a5408d789165118853782462a5989626016633c..add3b32946ff181431cba5bf54bf90fbd5d4ed74 100644 --- a/windows/queue.c +++ b/windows/queue.c @@ -441,9 +441,9 @@ void QUEUE_SetExitingQueue( HQUEUE16 hQueue ) static HQUEUE16 QUEUE_CreateMsgQueue( BOOL16 bCreatePerQData ) { HQUEUE16 hQueue; + HANDLE handle = -1; MESSAGEQUEUE * msgQueue; TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() ); - struct get_msg_queue_request *req = get_req_buffer(); TRACE_(msg)("(): Creating message queue...\n"); @@ -455,13 +455,19 @@ static HQUEUE16 QUEUE_CreateMsgQueue( BOOL16 bCreatePerQData ) if ( !msgQueue ) return 0; - if (server_call( REQ_GET_MSG_QUEUE )) + SERVER_START_REQ + { + struct get_msg_queue_request *req = server_alloc_req( sizeof(*req), 0 ); + if (!server_call( REQ_GET_MSG_QUEUE )) handle = req->handle; + } + SERVER_END_REQ; + if (handle == -1) { ERR_(msg)("Cannot get thread queue"); GlobalFree16( hQueue ); return 0; } - msgQueue->server_queue = req->handle; + msgQueue->server_queue = handle; msgQueue->server_queue = ConvertToGlobalHandle( msgQueue->server_queue ); msgQueue->self = hQueue; @@ -629,7 +635,7 @@ void QUEUE_SetWakeBit( MESSAGEQUEUE *queue, WORD bit ) if (queue->wakeMask & bit) { queue->wakeMask = 0; - + /* Wake up thread waiting for message */ if ( THREAD_IsWin16( queue->teb ) ) { @@ -639,10 +645,14 @@ void QUEUE_SetWakeBit( MESSAGEQUEUE *queue, WORD bit ) } else { - struct wake_queue_request *req = get_req_buffer(); - req->handle = queue->server_queue; - req->bits = bit; - server_call( REQ_WAKE_QUEUE ); + SERVER_START_REQ + { + struct wake_queue_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = queue->server_queue; + req->bits = bit; + server_call( REQ_WAKE_QUEUE ); + } + SERVER_END_REQ; } } } @@ -1500,16 +1510,21 @@ BOOL16 WINAPI GetInputState16(void) DWORD WINAPI WaitForInputIdle (HANDLE hProcess, DWORD dwTimeOut) { DWORD cur_time, ret; - HANDLE idle_event; - struct wait_input_idle_request *req = get_req_buffer(); + HANDLE idle_event = -1; - req->handle = hProcess; - req->timeout = dwTimeOut; - if (server_call( REQ_WAIT_INPUT_IDLE )) return 0xffffffff; - if ((idle_event = req->event) == -1) return 0; /* no event to wait on */ + SERVER_START_REQ + { + struct wait_input_idle_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = hProcess; + req->timeout = dwTimeOut; + if (!(ret = server_call( REQ_WAIT_INPUT_IDLE ))) idle_event = req->event; + } + SERVER_END_REQ; + if (ret) return 0xffffffff; /* error */ + if (idle_event == -1) return 0; /* no event to wait on */ cur_time = GetTickCount(); - + TRACE_(msg)("waiting for %x\n", idle_event ); while ( dwTimeOut > GetTickCount() - cur_time || dwTimeOut == INFINITE ) {