2 * Kernel synchronization objects
4 * Copyright 1998 Alexandre Julliard
10 #include "wine/unicode.h"
12 #include "debugtools.h"
14 DEFAULT_DEBUG_CHANNEL(win32);
21 /***********************************************************************
22 * CreateEventA (KERNEL32.156)
24 HANDLE WINAPI CreateEventA( SECURITY_ATTRIBUTES *sa, BOOL manual_reset,
25 BOOL initial_state, LPCSTR name )
28 DWORD len = name ? MultiByteToWideChar( CP_ACP, 0, name, strlen(name), NULL, 0 ) : 0;
31 SetLastError( ERROR_FILENAME_EXCED_RANGE );
34 SERVER_START_VAR_REQ( create_event, len * sizeof(WCHAR) )
36 req->manual_reset = manual_reset;
37 req->initial_state = initial_state;
38 req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
39 if (len) MultiByteToWideChar( CP_ACP, 0, name, strlen(name), server_data_ptr(req), len );
49 /***********************************************************************
50 * CreateEventW (KERNEL32.157)
52 HANDLE WINAPI CreateEventW( SECURITY_ATTRIBUTES *sa, BOOL manual_reset,
53 BOOL initial_state, LPCWSTR name )
56 DWORD len = name ? strlenW(name) : 0;
59 SetLastError( ERROR_FILENAME_EXCED_RANGE );
62 /* one buggy program needs this
63 * ("Van Dale Groot woordenboek der Nederlandse taal")
65 if (sa && IsBadReadPtr(sa,sizeof(SECURITY_ATTRIBUTES)))
67 ERR("Bad security attributes pointer %p\n",sa);
68 SetLastError( ERROR_INVALID_PARAMETER);
71 SERVER_START_VAR_REQ( create_event, len * sizeof(WCHAR) )
73 req->manual_reset = manual_reset;
74 req->initial_state = initial_state;
75 req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
76 memcpy( server_data_ptr(req), name, len * sizeof(WCHAR) );
86 /***********************************************************************
87 * WIN16_CreateEvent (KERNEL.457)
89 HANDLE WINAPI WIN16_CreateEvent( BOOL manual_reset, BOOL initial_state )
91 return CreateEventA( NULL, manual_reset, initial_state, NULL );
95 /***********************************************************************
96 * OpenEventA (KERNEL32.536)
98 HANDLE WINAPI OpenEventA( DWORD access, BOOL inherit, LPCSTR name )
101 DWORD len = name ? MultiByteToWideChar( CP_ACP, 0, name, strlen(name), NULL, 0 ) : 0;
104 SetLastError( ERROR_FILENAME_EXCED_RANGE );
107 SERVER_START_VAR_REQ( open_event, len * sizeof(WCHAR) )
109 req->access = access;
110 req->inherit = inherit;
111 if (len) MultiByteToWideChar( CP_ACP, 0, name, strlen(name), server_data_ptr(req), len );
120 /***********************************************************************
121 * OpenEventW (KERNEL32.537)
123 HANDLE WINAPI OpenEventW( DWORD access, BOOL inherit, LPCWSTR name )
126 DWORD len = name ? strlenW(name) : 0;
129 SetLastError( ERROR_FILENAME_EXCED_RANGE );
132 SERVER_START_VAR_REQ( open_event, len * sizeof(WCHAR) )
134 req->access = access;
135 req->inherit = inherit;
136 memcpy( server_data_ptr(req), name, len * sizeof(WCHAR) );
145 /***********************************************************************
148 * Execute an event operation (set,reset,pulse).
150 static BOOL EVENT_Operation( HANDLE handle, enum event_op op )
153 SERVER_START_REQ( event_op )
155 req->handle = handle;
157 ret = !SERVER_CALL_ERR();
164 /***********************************************************************
165 * PulseEvent (KERNEL32.557)
167 BOOL WINAPI PulseEvent( HANDLE handle )
169 return EVENT_Operation( handle, PULSE_EVENT );
173 /***********************************************************************
174 * SetEvent (KERNEL.458)
175 * SetEvent (KERNEL32.644)
177 BOOL WINAPI SetEvent( HANDLE handle )
179 return EVENT_Operation( handle, SET_EVENT );
183 /***********************************************************************
184 * ResetEvent (KERNEL.459)
185 * ResetEvent (KERNEL32.586)
187 BOOL WINAPI ResetEvent( HANDLE handle )
189 return EVENT_Operation( handle, RESET_EVENT );
193 /***********************************************************************
194 * NOTE: The Win95 VWin32_Event routines given below are really low-level
195 * routines implemented directly by VWin32. The user-mode libraries
196 * implement Win32 synchronisation routines on top of these low-level
197 * primitives. We do it the other way around here :-)
200 /***********************************************************************
201 * VWin32_EventCreate (KERNEL.442)
203 HANDLE WINAPI VWin32_EventCreate(VOID)
205 HANDLE hEvent = CreateEventA( NULL, FALSE, 0, NULL );
206 return ConvertToGlobalHandle( hEvent );
209 /***********************************************************************
210 * VWin32_EventDestroy (KERNEL.443)
212 VOID WINAPI VWin32_EventDestroy(HANDLE event)
214 CloseHandle( event );
217 /***********************************************************************
218 * VWin32_EventWait (KERNEL.450)
220 VOID WINAPI VWin32_EventWait(HANDLE event)
224 ReleaseThunkLock( &mutex_count );
225 WaitForSingleObject( event, INFINITE );
226 RestoreThunkLock( mutex_count );
229 /***********************************************************************
230 * VWin32_EventSet (KERNEL.479)
232 VOID WINAPI VWin32_EventSet(HANDLE event)
239 /***********************************************************************
240 * CreateMutexA (KERNEL32.166)
242 HANDLE WINAPI CreateMutexA( SECURITY_ATTRIBUTES *sa, BOOL owner, LPCSTR name )
245 DWORD len = name ? MultiByteToWideChar( CP_ACP, 0, name, strlen(name), NULL, 0 ) : 0;
248 SetLastError( ERROR_FILENAME_EXCED_RANGE );
251 SERVER_START_VAR_REQ( create_mutex, len * sizeof(WCHAR) )
254 req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
255 if (len) MultiByteToWideChar( CP_ACP, 0, name, strlen(name), server_data_ptr(req), len );
265 /***********************************************************************
266 * CreateMutexW (KERNEL32.167)
268 HANDLE WINAPI CreateMutexW( SECURITY_ATTRIBUTES *sa, BOOL owner, LPCWSTR name )
271 DWORD len = name ? strlenW(name) : 0;
274 SetLastError( ERROR_FILENAME_EXCED_RANGE );
277 SERVER_START_VAR_REQ( create_mutex, len * sizeof(WCHAR) )
280 req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
281 memcpy( server_data_ptr(req), name, len * sizeof(WCHAR) );
296 /***********************************************************************
297 * OpenMutexA (KERNEL32.541)
299 HANDLE WINAPI OpenMutexA( DWORD access, BOOL inherit, LPCSTR name )
302 DWORD len = name ? MultiByteToWideChar( CP_ACP, 0, name, strlen(name), NULL, 0 ) : 0;
305 SetLastError( ERROR_FILENAME_EXCED_RANGE );
308 SERVER_START_VAR_REQ( open_mutex, len * sizeof(WCHAR) )
310 req->access = access;
311 req->inherit = inherit;
312 if (len) MultiByteToWideChar( CP_ACP, 0, name, strlen(name), server_data_ptr(req), len );
321 /***********************************************************************
322 * OpenMutexW (KERNEL32.542)
324 HANDLE WINAPI OpenMutexW( DWORD access, BOOL inherit, LPCWSTR name )
327 DWORD len = name ? strlenW(name) : 0;
330 SetLastError( ERROR_FILENAME_EXCED_RANGE );
333 SERVER_START_VAR_REQ( open_mutex, len * sizeof(WCHAR) )
335 req->access = access;
336 req->inherit = inherit;
337 memcpy( server_data_ptr(req), name, len * sizeof(WCHAR) );
346 /***********************************************************************
347 * ReleaseMutex (KERNEL32.582)
349 BOOL WINAPI ReleaseMutex( HANDLE handle )
352 SERVER_START_REQ( release_mutex )
354 req->handle = handle;
355 ret = !SERVER_CALL_ERR();
367 /***********************************************************************
368 * CreateSemaphoreA (KERNEL32.174)
370 HANDLE WINAPI CreateSemaphoreA( SECURITY_ATTRIBUTES *sa, LONG initial, LONG max, LPCSTR name )
373 DWORD len = name ? MultiByteToWideChar( CP_ACP, 0, name, strlen(name), NULL, 0 ) : 0;
375 /* Check parameters */
377 if ((max <= 0) || (initial < 0) || (initial > max))
379 SetLastError( ERROR_INVALID_PARAMETER );
384 SetLastError( ERROR_FILENAME_EXCED_RANGE );
388 SERVER_START_VAR_REQ( create_semaphore, len * sizeof(WCHAR) )
390 req->initial = (unsigned int)initial;
391 req->max = (unsigned int)max;
392 req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
393 if (len) MultiByteToWideChar( CP_ACP, 0, name, strlen(name), server_data_ptr(req), len );
403 /***********************************************************************
404 * CreateSemaphoreW (KERNEL32.175)
406 HANDLE WINAPI CreateSemaphoreW( SECURITY_ATTRIBUTES *sa, LONG initial,
407 LONG max, LPCWSTR name )
410 DWORD len = name ? strlenW(name) : 0;
412 /* Check parameters */
414 if ((max <= 0) || (initial < 0) || (initial > max))
416 SetLastError( ERROR_INVALID_PARAMETER );
421 SetLastError( ERROR_FILENAME_EXCED_RANGE );
425 SERVER_START_VAR_REQ( create_semaphore, len * sizeof(WCHAR) )
427 req->initial = (unsigned int)initial;
428 req->max = (unsigned int)max;
429 req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
430 memcpy( server_data_ptr(req), name, len * sizeof(WCHAR) );
440 /***********************************************************************
441 * OpenSemaphoreA (KERNEL32.545)
443 HANDLE WINAPI OpenSemaphoreA( DWORD access, BOOL inherit, LPCSTR name )
446 DWORD len = name ? MultiByteToWideChar( CP_ACP, 0, name, strlen(name), NULL, 0 ) : 0;
449 SetLastError( ERROR_FILENAME_EXCED_RANGE );
452 SERVER_START_VAR_REQ( open_semaphore, len * sizeof(WCHAR) )
454 req->access = access;
455 req->inherit = inherit;
456 if (len) MultiByteToWideChar( CP_ACP, 0, name, strlen(name), server_data_ptr(req), len );
465 /***********************************************************************
466 * OpenSemaphoreW (KERNEL32.546)
468 HANDLE WINAPI OpenSemaphoreW( DWORD access, BOOL inherit, LPCWSTR name )
471 DWORD len = name ? strlenW(name) : 0;
474 SetLastError( ERROR_FILENAME_EXCED_RANGE );
477 SERVER_START_VAR_REQ( open_semaphore, len * sizeof(WCHAR) )
479 req->access = access;
480 req->inherit = inherit;
481 memcpy( server_data_ptr(req), name, len * sizeof(WCHAR) );
490 /***********************************************************************
491 * ReleaseSemaphore (KERNEL32.583)
493 BOOL WINAPI ReleaseSemaphore( HANDLE handle, LONG count, LONG *previous )
495 NTSTATUS status = NtReleaseSemaphore( handle, count, previous );
496 if (status) SetLastError( RtlNtStatusToDosError(status) );
506 /***********************************************************************
507 * CreateNamedPipeA (KERNEL32.168)
509 HANDLE WINAPI CreateNamedPipeA( LPCSTR name, DWORD dwOpenMode,
510 DWORD dwPipeMode, DWORD nMaxInstances,
511 DWORD nOutBufferSize, DWORD nInBufferSize,
512 DWORD nDefaultTimeOut, LPSECURITY_ATTRIBUTES attr )
514 FIXME("(Name=%s, OpenMode=%#08lx, dwPipeMode=%#08lx, MaxInst=%ld, OutBSize=%ld, InBuffSize=%ld, DefTimeOut=%ld, SecAttr=%p): stub\n",
515 debugstr_a(name), dwOpenMode, dwPipeMode, nMaxInstances,
516 nOutBufferSize, nInBufferSize, nDefaultTimeOut, attr );
517 SetLastError (ERROR_UNKNOWN);
518 return INVALID_HANDLE_VALUE;
522 /***********************************************************************
523 * CreateNamedPipeW (KERNEL32.169)
525 HANDLE WINAPI CreateNamedPipeW( LPCWSTR name, DWORD dwOpenMode,
526 DWORD dwPipeMode, DWORD nMaxInstances,
527 DWORD nOutBufferSize, DWORD nInBufferSize,
528 DWORD nDefaultTimeOut, LPSECURITY_ATTRIBUTES attr )
530 FIXME("(Name=%s, OpenMode=%#08lx, dwPipeMode=%#08lx, MaxInst=%ld, OutBSize=%ld, InBuffSize=%ld, DefTimeOut=%ld, SecAttr=%p): stub\n",
531 debugstr_w(name), dwOpenMode, dwPipeMode, nMaxInstances,
532 nOutBufferSize, nInBufferSize, nDefaultTimeOut, attr );
534 SetLastError (ERROR_UNKNOWN);
535 return INVALID_HANDLE_VALUE;
539 /***********************************************************************
540 * PeekNamedPipe (KERNEL32.552)
542 BOOL WINAPI PeekNamedPipe( HANDLE hPipe, LPVOID lpvBuffer, DWORD cbBuffer,
543 LPDWORD lpcbRead, LPDWORD lpcbAvail, LPDWORD lpcbMessage )
545 FIXME("(%08x, %p, %08lx, %p, %p, %p): stub\n",
546 hPipe, lpvBuffer, cbBuffer, lpcbRead, lpcbAvail, lpcbMessage);
547 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
552 /***********************************************************************
553 * WaitNamedPipeA (KERNEL32.725)
555 BOOL WINAPI WaitNamedPipeA (LPCSTR lpNamedPipeName, DWORD nTimeOut)
557 FIXME("%s 0x%08lx\n",lpNamedPipeName,nTimeOut);
558 SetLastError(ERROR_PIPE_NOT_CONNECTED);
563 /***********************************************************************
564 * WaitNamedPipeW (KERNEL32.726)
566 BOOL WINAPI WaitNamedPipeW (LPCWSTR lpNamedPipeName, DWORD nTimeOut)
568 FIXME("%s 0x%08lx\n",debugstr_w(lpNamedPipeName),nTimeOut);
569 SetLastError(ERROR_PIPE_NOT_CONNECTED);