Store all object names as Unicode in the server.
diff --git a/scheduler/semaphore.c b/scheduler/semaphore.c
index 890efa8..a9b130f 100644
--- a/scheduler/semaphore.c
+++ b/scheduler/semaphore.c
@@ -7,7 +7,6 @@
#include <assert.h>
#include <string.h>
#include "winerror.h"
-#include "heap.h"
#include "server.h"
@@ -29,7 +28,7 @@
req->initial = (unsigned int)initial;
req->max = (unsigned int)max;
req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
- lstrcpynA( req->name, name ? name : "", server_remaining(req->name) );
+ server_strcpyAtoW( req->name, name );
SetLastError(0);
server_call( REQ_CREATE_SEMAPHORE );
if (req->handle == -1) return 0;
@@ -43,10 +42,24 @@
HANDLE WINAPI CreateSemaphoreW( SECURITY_ATTRIBUTES *sa, LONG initial,
LONG max, LPCWSTR name )
{
- LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, name );
- HANDLE ret = CreateSemaphoreA( sa, initial, max, nameA );
- if (nameA) HeapFree( GetProcessHeap(), 0, nameA );
- return ret;
+ struct create_semaphore_request *req = get_req_buffer();
+
+ /* Check parameters */
+
+ if ((max <= 0) || (initial < 0) || (initial > max))
+ {
+ SetLastError( ERROR_INVALID_PARAMETER );
+ 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;
}
@@ -59,7 +72,7 @@
req->access = access;
req->inherit = inherit;
- lstrcpynA( req->name, name ? name : "", server_remaining(req->name) );
+ 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;
@@ -71,10 +84,14 @@
*/
HANDLE WINAPI OpenSemaphoreW( DWORD access, BOOL inherit, LPCWSTR name )
{
- LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, name );
- HANDLE ret = OpenSemaphoreA( access, inherit, nameA );
- if (nameA) HeapFree( GetProcessHeap(), 0, nameA );
- return ret;
+ 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;
}
@@ -83,6 +100,7 @@
*/
BOOL WINAPI ReleaseSemaphore( HANDLE handle, LONG count, LONG *previous )
{
+ BOOL ret = FALSE;
struct release_semaphore_request *req = get_req_buffer();
if (count < 0)
@@ -92,7 +110,10 @@
}
req->handle = handle;
req->count = (unsigned int)count;
- if (server_call( REQ_RELEASE_SEMAPHORE )) return FALSE;
- if (previous) *previous = req->prev_count;
- return TRUE;
+ if (!server_call( REQ_RELEASE_SEMAPHORE ))
+ {
+ if (previous) *previous = req->prev_count;
+ ret = TRUE;
+ }
+ return ret;
}