Added exception handling wrapper to a number of server requests.
Changed a few requests to use the new vararg mechanism.
diff --git a/dlls/kernel/toolhelp.c b/dlls/kernel/toolhelp.c
index e4872f7..077308c 100644
--- a/dlls/kernel/toolhelp.c
+++ b/dlls/kernel/toolhelp.c
@@ -184,7 +184,7 @@
*/
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 @@
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 @@
*/
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 @@
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 @@
*/
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 @@
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 @@
*/
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 ed3878e..6ec746a 100644
--- a/dlls/ntdll/exception.c
+++ b/dlls/ntdll/exception.c
@@ -86,18 +86,24 @@
/**********************************************************************
- * 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 e9b90ef..092a4e3 100644
--- a/dlls/ntdll/nt.c
+++ b/dlls/ntdll/nt.c
@@ -75,10 +75,17 @@
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 @@
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 8a3da06..3e31fc8 100644
--- a/dlls/ntdll/om.c
+++ b/dlls/ntdll/om.c
@@ -215,9 +215,15 @@
*/
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 e701d30..7409b4a 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 @@
/******************************************************************************
* 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 @@
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 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 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 @@
/******************************************************************************
* 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 @@
* 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 @@
* 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 80ea17e..ab07418 100644
--- a/files/change.c
+++ b/files/change.c
@@ -28,13 +28,19 @@
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 1252f0b..c619724 100644
--- a/files/file.c
+++ b/files/file.c
@@ -368,14 +368,20 @@
*/
HFILE FILE_CreateDevice( int client_id, DWORD access, LPSECURITY_ATTRIBUTES sa )
{
- struct create_device_request *req = get_req_buffer();
+ 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 );
- return req->handle;
+ 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 @@
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 @@
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 @@
"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 @@
*/
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 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 @@
*/
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 @@
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 LockFile( HANDLE hFile, DWORD dwFileOffsetLow, DWORD dwFileOffsetHigh,
DWORD nNumberOfBytesToLockLow, DWORD nNumberOfBytesToLockHigh )
{
- struct lock_file_request *req = get_req_buffer();
+ 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;
- return !server_call( REQ_LOCK_FILE );
+ 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 UnlockFile( HANDLE hFile, DWORD dwFileOffsetLow, DWORD dwFileOffsetHigh,
DWORD nNumberOfBytesToUnlockLow, DWORD nNumberOfBytesToUnlockHigh )
{
- struct unlock_file_request *req = get_req_buffer();
+ 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;
- return !server_call( REQ_UNLOCK_FILE );
+ 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 959bba2..73fadfc 100644
--- a/include/ntddk.h
+++ b/include/ntddk.h
@@ -910,12 +910,10 @@
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 2c8b06d..777f396 100644
--- a/include/server.h
+++ b/include/server.h
@@ -350,8 +350,7 @@
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 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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 e1198b9..6fe6178 100644
--- a/loader/module.c
+++ b/loader/module.c
@@ -1526,12 +1526,14 @@
/* 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 15a3dc1..aff2b48 100644
--- a/loader/ne/module.c
+++ b/loader/ne/module.c
@@ -992,7 +992,6 @@
*/
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 @@
TDB *pTask;
LPSTR cmdline;
WORD cmdShow;
- HANDLE hThread;
+ HANDLE hThread = -1;
int socket;
/* Load module */
@@ -1046,10 +1045,15 @@
/* 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 9380f98..4267c5c 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 @@
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 5f32e08..38ae92a 100644
--- a/memory/atom.c
+++ b/memory/atom.c
@@ -401,9 +401,15 @@
*/
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
}
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 @@
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 @@
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 c12b620..392de3e 100644
--- a/memory/selector.c
+++ b/memory/selector.c
@@ -606,7 +606,7 @@
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 @@
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 846820c..8eda710 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 @@
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 @@
/* 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 @@
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 @@
/* 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 @@
BOOL inherit, /* [in] Inherit flag */
LPCSTR name ) /* [in] Name of file-mapping object */
{
- struct open_mapping_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_mapping_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_MAPPING );
- 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_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 OpenFileMappingW( DWORD access, BOOL inherit, LPCWSTR name)
{
- struct open_mapping_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_mapping_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_MAPPING );
- 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_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 4462ef8..ddf2fc1 100644
--- a/misc/registry.c
+++ b/misc/registry.c
@@ -1323,16 +1323,19 @@
/* 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 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 9231a89..f3d5df6 100644
--- a/scheduler/debugger.c
+++ b/scheduler/debugger.c
@@ -26,72 +26,83 @@
*/
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 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 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 @@
*/
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 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 @@
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 c261124..af968ac 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();
+ 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);
- server_strcpyAtoW( req->name, name );
- SetLastError(0);
- server_call( REQ_CREATE_EVENT );
- if (req->handle == -1) return 0;
- return req->handle;
+ 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 CreateEventW( SECURITY_ATTRIBUTES *sa, BOOL manual_reset,
BOOL initial_state, LPCWSTR name )
{
- struct create_event_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_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);
- server_strcpyW( req->name, name );
- SetLastError(0);
- server_call( REQ_CREATE_EVENT );
- if (req->handle == -1) return 0;
- return req->handle;
+ 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 OpenEventA( DWORD access, BOOL inherit, LPCSTR name )
{
- struct open_event_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_event_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_EVENT );
- 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_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 OpenEventW( DWORD access, BOOL inherit, LPCWSTR name )
{
- struct open_event_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_event_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_EVENT );
- 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_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 @@
*/
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 5640fee..6fbe913 100644
--- a/scheduler/handle.c
+++ b/scheduler/handle.c
@@ -18,14 +18,17 @@
*/
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 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 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 @@
HANDLE dest_process, HANDLE *dest,
DWORD access, BOOL inherit, DWORD options )
{
- struct dup_handle_request *req = get_req_buffer();
+ 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;
+ 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;
+ ret = !server_call( REQ_DUP_HANDLE );
+ if (ret && dest) *dest = req->handle;
+ }
+ SERVER_END_REQ;
+ return ret;
}
@@ -82,17 +101,10 @@
*/
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 f656ed3..c0d3a69 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 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 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 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 @@
*/
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 6b018c7..3d83e53 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 594d85a..a82486d 100644
--- a/scheduler/process.c
+++ b/scheduler/process.c
@@ -164,7 +164,7 @@
*/
static BOOL process_init( char *argv[] )
{
- struct init_process_request *req;
+ BOOL ret;
/* store the program name */
argv0 = argv[0];
@@ -183,18 +183,26 @@
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 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 @@
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 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 @@
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 @@
*/
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 @@
*/
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 @@
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 @@
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 @@
*/
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 @@
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 @@
*/
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 @@
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 @@
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 e5880a6..6508026 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 @@
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 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 @@
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 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 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 @@
*/
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 9bcf55f..52f112b 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 @@
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 @@
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 );
- if (wait_all) req->flags |= SELECT_ALL;
- if (alertable) req->flags |= SELECT_ALERTABLE;
- if (timeout != INFINITE) req->flags |= SELECT_TIMEOUT;
+ req->flags = 0;
+ req->timeout = timeout;
+ for (i = 0; i < count; i++) data[i] = handles[i];
- server_call( REQ_SELECT );
- if ((ret = req->signaled) == STATUS_USER_APC) call_apcs();
+ if (wait_all) req->flags |= SELECT_ALL;
+ if (alertable) req->flags |= SELECT_ALERTABLE;
+ if (timeout != INFINITE) req->flags |= SELECT_TIMEOUT;
+
+ 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 5004c7f..293b3d8 100644
--- a/scheduler/thread.c
+++ b/scheduler/thread.c
@@ -50,21 +50,30 @@
*/
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 @@
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 @@
if (SYSDEPS_SpawnThread( teb ) == -1)
{
CloseHandle( handle );
+ THREAD_FreeTEB( teb );
return 0;
}
return handle;
@@ -335,13 +353,20 @@
*/
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 );
- if (req->last)
+ /* 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;
+
+ if (last)
{
MODULE_DllProcessDetach( TRUE, (LPVOID)1 );
exit( code );
@@ -474,11 +499,17 @@
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 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 @@
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 @@
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 @@
*/
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 @@
* 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 @@
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 @@
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 @@
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 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 0992be4..fe8020e 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();
+ 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);
- server_strcpyAtoW( req->name, name );
- SetLastError(0);
- server_call( REQ_CREATE_TIMER );
- if (req->handle == -1) return 0;
- return req->handle;
+ 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 CreateWaitableTimerW( SECURITY_ATTRIBUTES *sa, BOOL manual, LPCWSTR name )
{
- struct create_timer_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_timer_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) );
- 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;
+ 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 OpenWaitableTimerA( DWORD access, BOOL inherit, LPCSTR name )
{
- struct open_timer_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_timer_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_TIMER );
- 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_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 OpenWaitableTimerW( DWORD access, BOOL inherit, LPCWSTR name )
{
- struct open_timer_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_timer_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_TIMER );
- 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_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 @@
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 @@
ft.dwHighDateTime = when->s.HighPart;
}
- if (!ft.dwLowDateTime && !ft.dwHighDateTime)
+ SERVER_START_REQ
{
- /* special case to start timeout on now+period without too many calculations */
- req->sec = 0;
- req->usec = 0;
+ 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 );
}
- 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 */
- return !server_call( REQ_SET_TIMER );
+ SERVER_END_REQ;
+ return ret;
}
@@ -127,7 +183,13 @@
*/
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 1e4652c..5e65b23 100644
--- a/server/atom.c
+++ b/server/atom.c
@@ -65,13 +65,17 @@
/* 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 @@
}
/* 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 @@
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 436d170..371e304 100644
--- a/server/debugger.c
+++ b/server/debugger.c
@@ -254,6 +254,7 @@
{
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 @@
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 @@
{
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 763c8fb..f259b90 100644
--- a/server/event.c
+++ b/server/event.c
@@ -114,11 +114,11 @@
/* 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 @@
/* 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 6976cf4..0ad6a57 100644
--- a/server/mapping.c
+++ b/server/mapping.c
@@ -281,12 +281,12 @@
/* 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 @@
/* 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 7f74b7b..82b76c2 100644
--- a/server/mutex.c
+++ b/server/mutex.c
@@ -139,11 +139,10 @@
/* 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 @@
/* 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 cda7bfe..f2a7f1f 100644
--- a/server/object.c
+++ b/server/object.c
@@ -70,6 +70,7 @@
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 @@
{
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 @@
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 @@
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 aa46902..bf9b797 100644
--- a/server/request.h
+++ b/server/request.h
@@ -54,6 +54,18 @@
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 94fe31f..25c0c51 100644
--- a/server/semaphore.c
+++ b/server/semaphore.c
@@ -122,11 +122,11 @@
/* 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 @@
/* 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 c1b79fa..d6e9bef 100644
--- a/server/thread.c
+++ b/server/thread.c
@@ -787,7 +787,8 @@
/* 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(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 c914d93..d74fc72 100644
--- a/server/timer.c
+++ b/server/timer.c
@@ -173,11 +173,10 @@
/* 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 @@
/* 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 34ff39c..c6b5e91 100644
--- a/server/trace.c
+++ b/server/trace.c
@@ -100,13 +100,50 @@
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 @@
}
}
-
/* 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 @@
{
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_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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
{
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 @@
{
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 @@
{
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 fd5aed9..7dcad4e 100755
--- a/tools/make_requests
+++ b/tools/make_requests
@@ -121,7 +121,7 @@
{
$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 @@
}
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 4cb35c9..03728ae 100644
--- a/win32/console.c
+++ b/win32/console.c
@@ -647,14 +647,15 @@
*/
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 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 ce5f29a..b95ec82 100644
--- a/win32/device.c
+++ b/win32/device.c
@@ -330,18 +330,22 @@
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 4a5408d..add3b32 100644
--- a/windows/queue.c
+++ b/windows/queue.c
@@ -441,9 +441,9 @@
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 @@
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 @@
if (queue->wakeMask & bit)
{
queue->wakeMask = 0;
-
+
/* Wake up thread waiting for message */
if ( THREAD_IsWin16( queue->teb ) )
{
@@ -639,10 +645,14 @@
}
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 @@
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 ) {