kernel32: Move condition variable functions to kernelbase.
[wine.git] / dlls / kernelbase / sync.c
blobba64b853ed500fbe99ce70e7bcca3f76b6df7513
1 /*
2 * Kernel synchronization objects
4 * Copyright 1998 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
22 #include <string.h>
23 #include <stdio.h>
25 #include "ntstatus.h"
26 #define WIN32_NO_STATUS
27 #define NONAMELESSUNION
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winerror.h"
31 #include "winnls.h"
32 #include "winternl.h"
33 #include "winioctl.h"
34 #include "ddk/wdm.h"
36 #include "kernelbase.h"
37 #include "wine/asm.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(sync);
42 /* check if current version is NT or Win95 */
43 static inline BOOL is_version_nt(void)
45 return !(GetVersion() & 0x80000000);
48 /* helper for kernel32->ntdll timeout format conversion */
49 static inline LARGE_INTEGER *get_nt_timeout( LARGE_INTEGER *time, DWORD timeout )
51 if (timeout == INFINITE) return NULL;
52 time->QuadPart = (ULONGLONG)timeout * -10000;
53 return time;
57 /***********************************************************************
58 * BaseGetNamedObjectDirectory (kernelbase.@)
60 NTSTATUS WINAPI BaseGetNamedObjectDirectory( HANDLE *dir )
62 static HANDLE handle;
63 static const WCHAR basenameW[] = {'\\','S','e','s','s','i','o','n','s','\\','%','u',
64 '\\','B','a','s','e','N','a','m','e','d','O','b','j','e','c','t','s',0};
65 WCHAR buffer[64];
66 UNICODE_STRING str;
67 OBJECT_ATTRIBUTES attr;
68 NTSTATUS status = STATUS_SUCCESS;
70 if (!handle)
72 HANDLE dir;
74 swprintf( buffer, ARRAY_SIZE(buffer), basenameW, NtCurrentTeb()->Peb->SessionId );
75 RtlInitUnicodeString( &str, buffer );
76 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
77 status = NtOpenDirectoryObject( &dir, DIRECTORY_CREATE_OBJECT|DIRECTORY_TRAVERSE, &attr );
78 if (!status && InterlockedCompareExchangePointer( &handle, dir, 0 ) != 0)
80 /* someone beat us here... */
81 CloseHandle( dir );
84 *dir = handle;
85 return status;
88 static void get_create_object_attributes( OBJECT_ATTRIBUTES *attr, UNICODE_STRING *nameW,
89 SECURITY_ATTRIBUTES *sa, const WCHAR *name )
91 attr->Length = sizeof(*attr);
92 attr->RootDirectory = 0;
93 attr->ObjectName = NULL;
94 attr->Attributes = OBJ_OPENIF | ((sa && sa->bInheritHandle) ? OBJ_INHERIT : 0);
95 attr->SecurityDescriptor = sa ? sa->lpSecurityDescriptor : NULL;
96 attr->SecurityQualityOfService = NULL;
97 if (name)
99 RtlInitUnicodeString( nameW, name );
100 attr->ObjectName = nameW;
101 BaseGetNamedObjectDirectory( &attr->RootDirectory );
105 static BOOL get_open_object_attributes( OBJECT_ATTRIBUTES *attr, UNICODE_STRING *nameW,
106 BOOL inherit, const WCHAR *name )
108 HANDLE dir;
110 if (!name)
112 SetLastError( ERROR_INVALID_PARAMETER );
113 return FALSE;
115 RtlInitUnicodeString( nameW, name );
116 BaseGetNamedObjectDirectory( &dir );
117 InitializeObjectAttributes( attr, nameW, inherit ? OBJ_INHERIT : 0, dir, NULL );
118 return TRUE;
122 /***********************************************************************
123 * Events
124 ***********************************************************************/
127 /***********************************************************************
128 * CreateEventA (kernelbase.@)
130 HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventA( SECURITY_ATTRIBUTES *sa, BOOL manual_reset,
131 BOOL initial_state, LPCSTR name )
133 DWORD flags = 0;
135 if (manual_reset) flags |= CREATE_EVENT_MANUAL_RESET;
136 if (initial_state) flags |= CREATE_EVENT_INITIAL_SET;
137 return CreateEventExA( sa, name, flags, EVENT_ALL_ACCESS );
141 /***********************************************************************
142 * CreateEventW (kernelbase.@)
144 HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW( SECURITY_ATTRIBUTES *sa, BOOL manual_reset,
145 BOOL initial_state, LPCWSTR name )
147 DWORD flags = 0;
149 if (manual_reset) flags |= CREATE_EVENT_MANUAL_RESET;
150 if (initial_state) flags |= CREATE_EVENT_INITIAL_SET;
151 return CreateEventExW( sa, name, flags, EVENT_ALL_ACCESS );
155 /***********************************************************************
156 * CreateEventExA (kernelbase.@)
158 HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventExA( SECURITY_ATTRIBUTES *sa, LPCSTR name,
159 DWORD flags, DWORD access )
161 WCHAR buffer[MAX_PATH];
163 if (!name) return CreateEventExW( sa, NULL, flags, access );
165 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
167 SetLastError( ERROR_FILENAME_EXCED_RANGE );
168 return 0;
170 return CreateEventExW( sa, buffer, flags, access );
174 /***********************************************************************
175 * CreateEventExW (kernelbase.@)
177 HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventExW( SECURITY_ATTRIBUTES *sa, LPCWSTR name,
178 DWORD flags, DWORD access )
180 HANDLE ret = 0;
181 UNICODE_STRING nameW;
182 OBJECT_ATTRIBUTES attr;
183 NTSTATUS status;
185 /* one buggy program needs this
186 * ("Van Dale Groot woordenboek der Nederlandse taal")
188 if (sa && IsBadReadPtr(sa,sizeof(SECURITY_ATTRIBUTES)))
190 ERR("Bad security attributes pointer %p\n",sa);
191 SetLastError( ERROR_INVALID_PARAMETER);
192 return 0;
195 get_create_object_attributes( &attr, &nameW, sa, name );
197 status = NtCreateEvent( &ret, access, &attr,
198 (flags & CREATE_EVENT_MANUAL_RESET) ? NotificationEvent : SynchronizationEvent,
199 (flags & CREATE_EVENT_INITIAL_SET) != 0 );
200 if (status == STATUS_OBJECT_NAME_EXISTS)
201 SetLastError( ERROR_ALREADY_EXISTS );
202 else
203 SetLastError( RtlNtStatusToDosError(status) );
204 return ret;
208 /***********************************************************************
209 * OpenEventA (kernelbase.@)
211 HANDLE WINAPI DECLSPEC_HOTPATCH OpenEventA( DWORD access, BOOL inherit, LPCSTR name )
213 WCHAR buffer[MAX_PATH];
215 if (!name) return OpenEventW( access, inherit, NULL );
217 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
219 SetLastError( ERROR_FILENAME_EXCED_RANGE );
220 return 0;
222 return OpenEventW( access, inherit, buffer );
226 /***********************************************************************
227 * OpenEventW (kernelbase.@)
229 HANDLE WINAPI DECLSPEC_HOTPATCH OpenEventW( DWORD access, BOOL inherit, LPCWSTR name )
231 HANDLE ret;
232 UNICODE_STRING nameW;
233 OBJECT_ATTRIBUTES attr;
234 NTSTATUS status;
236 if (!is_version_nt()) access = EVENT_ALL_ACCESS;
238 if (!get_open_object_attributes( &attr, &nameW, inherit, name )) return 0;
240 status = NtOpenEvent( &ret, access, &attr );
241 if (status != STATUS_SUCCESS)
243 SetLastError( RtlNtStatusToDosError(status) );
244 return 0;
246 return ret;
249 /***********************************************************************
250 * PulseEvent (kernelbase.@)
252 BOOL WINAPI DECLSPEC_HOTPATCH PulseEvent( HANDLE handle )
254 return set_ntstatus( NtPulseEvent( handle, NULL ));
258 /***********************************************************************
259 * SetEvent (kernelbase.@)
261 BOOL WINAPI DECLSPEC_HOTPATCH SetEvent( HANDLE handle )
263 return set_ntstatus( NtSetEvent( handle, NULL ));
267 /***********************************************************************
268 * ResetEvent (kernelbase.@)
270 BOOL WINAPI DECLSPEC_HOTPATCH ResetEvent( HANDLE handle )
272 return set_ntstatus( NtResetEvent( handle, NULL ));
276 /***********************************************************************
277 * Mutexes
278 ***********************************************************************/
281 /***********************************************************************
282 * CreateMutexA (kernelbase.@)
284 HANDLE WINAPI DECLSPEC_HOTPATCH CreateMutexA( SECURITY_ATTRIBUTES *sa, BOOL owner, LPCSTR name )
286 return CreateMutexExA( sa, name, owner ? CREATE_MUTEX_INITIAL_OWNER : 0, MUTEX_ALL_ACCESS );
290 /***********************************************************************
291 * CreateMutexW (kernelbase.@)
293 HANDLE WINAPI DECLSPEC_HOTPATCH CreateMutexW( SECURITY_ATTRIBUTES *sa, BOOL owner, LPCWSTR name )
295 return CreateMutexExW( sa, name, owner ? CREATE_MUTEX_INITIAL_OWNER : 0, MUTEX_ALL_ACCESS );
299 /***********************************************************************
300 * CreateMutexExA (kernelbase.@)
302 HANDLE WINAPI DECLSPEC_HOTPATCH CreateMutexExA( SECURITY_ATTRIBUTES *sa, LPCSTR name,
303 DWORD flags, DWORD access )
305 ANSI_STRING nameA;
306 NTSTATUS status;
308 if (!name) return CreateMutexExW( sa, NULL, flags, access );
310 RtlInitAnsiString( &nameA, name );
311 status = RtlAnsiStringToUnicodeString( &NtCurrentTeb()->StaticUnicodeString, &nameA, FALSE );
312 if (status != STATUS_SUCCESS)
314 SetLastError( ERROR_FILENAME_EXCED_RANGE );
315 return 0;
317 return CreateMutexExW( sa, NtCurrentTeb()->StaticUnicodeString.Buffer, flags, access );
321 /***********************************************************************
322 * CreateMutexExW (kernelbase.@)
324 HANDLE WINAPI DECLSPEC_HOTPATCH CreateMutexExW( SECURITY_ATTRIBUTES *sa, LPCWSTR name,
325 DWORD flags, DWORD access )
327 HANDLE ret = 0;
328 UNICODE_STRING nameW;
329 OBJECT_ATTRIBUTES attr;
330 NTSTATUS status;
332 get_create_object_attributes( &attr, &nameW, sa, name );
334 status = NtCreateMutant( &ret, access, &attr, (flags & CREATE_MUTEX_INITIAL_OWNER) != 0 );
335 if (status == STATUS_OBJECT_NAME_EXISTS)
336 SetLastError( ERROR_ALREADY_EXISTS );
337 else
338 SetLastError( RtlNtStatusToDosError(status) );
339 return ret;
343 /***********************************************************************
344 * OpenMutexW (kernelbase.@)
346 HANDLE WINAPI DECLSPEC_HOTPATCH OpenMutexW( DWORD access, BOOL inherit, LPCWSTR name )
348 HANDLE ret;
349 UNICODE_STRING nameW;
350 OBJECT_ATTRIBUTES attr;
351 NTSTATUS status;
353 if (!is_version_nt()) access = MUTEX_ALL_ACCESS;
355 if (!get_open_object_attributes( &attr, &nameW, inherit, name )) return 0;
357 status = NtOpenMutant( &ret, access, &attr );
358 if (status != STATUS_SUCCESS)
360 SetLastError( RtlNtStatusToDosError(status) );
361 return 0;
363 return ret;
367 /***********************************************************************
368 * ReleaseMutex (kernelbase.@)
370 BOOL WINAPI DECLSPEC_HOTPATCH ReleaseMutex( HANDLE handle )
372 return set_ntstatus( NtReleaseMutant( handle, NULL ));
376 /***********************************************************************
377 * Semaphores
378 ***********************************************************************/
381 /***********************************************************************
382 * CreateSemaphoreW (kernelbase.@)
384 HANDLE WINAPI DECLSPEC_HOTPATCH CreateSemaphoreW( SECURITY_ATTRIBUTES *sa, LONG initial,
385 LONG max, LPCWSTR name )
387 return CreateSemaphoreExW( sa, initial, max, name, 0, SEMAPHORE_ALL_ACCESS );
391 /***********************************************************************
392 * CreateSemaphoreExW (kernelbase.@)
394 HANDLE WINAPI DECLSPEC_HOTPATCH CreateSemaphoreExW( SECURITY_ATTRIBUTES *sa, LONG initial, LONG max,
395 LPCWSTR name, DWORD flags, DWORD access )
397 HANDLE ret = 0;
398 UNICODE_STRING nameW;
399 OBJECT_ATTRIBUTES attr;
400 NTSTATUS status;
402 get_create_object_attributes( &attr, &nameW, sa, name );
404 status = NtCreateSemaphore( &ret, access, &attr, initial, max );
405 if (status == STATUS_OBJECT_NAME_EXISTS)
406 SetLastError( ERROR_ALREADY_EXISTS );
407 else
408 SetLastError( RtlNtStatusToDosError(status) );
409 return ret;
413 /***********************************************************************
414 * OpenSemaphoreW (kernelbase.@)
416 HANDLE WINAPI DECLSPEC_HOTPATCH OpenSemaphoreW( DWORD access, BOOL inherit, LPCWSTR name )
418 HANDLE ret;
419 UNICODE_STRING nameW;
420 OBJECT_ATTRIBUTES attr;
421 NTSTATUS status;
423 if (!is_version_nt()) access = SEMAPHORE_ALL_ACCESS;
425 if (!get_open_object_attributes( &attr, &nameW, inherit, name )) return 0;
427 status = NtOpenSemaphore( &ret, access, &attr );
428 if (status != STATUS_SUCCESS)
430 SetLastError( RtlNtStatusToDosError(status) );
431 return 0;
433 return ret;
437 /***********************************************************************
438 * ReleaseSemaphore (kernelbase.@)
440 BOOL WINAPI DECLSPEC_HOTPATCH ReleaseSemaphore( HANDLE handle, LONG count, LONG *previous )
442 return set_ntstatus( NtReleaseSemaphore( handle, count, (PULONG)previous ));
446 /***********************************************************************
447 * Waitable timers
448 ***********************************************************************/
451 /***********************************************************************
452 * CreateWaitableTimerW (kernelbase.@)
454 HANDLE WINAPI DECLSPEC_HOTPATCH CreateWaitableTimerW( SECURITY_ATTRIBUTES *sa, BOOL manual, LPCWSTR name )
456 return CreateWaitableTimerExW( sa, name, manual ? CREATE_WAITABLE_TIMER_MANUAL_RESET : 0,
457 TIMER_ALL_ACCESS );
461 /***********************************************************************
462 * CreateWaitableTimerExW (kernelbase.@)
464 HANDLE WINAPI DECLSPEC_HOTPATCH CreateWaitableTimerExW( SECURITY_ATTRIBUTES *sa, LPCWSTR name,
465 DWORD flags, DWORD access )
467 HANDLE handle;
468 NTSTATUS status;
469 UNICODE_STRING nameW;
470 OBJECT_ATTRIBUTES attr;
472 get_create_object_attributes( &attr, &nameW, sa, name );
474 status = NtCreateTimer( &handle, access, &attr,
475 (flags & CREATE_WAITABLE_TIMER_MANUAL_RESET) ? NotificationTimer : SynchronizationTimer );
476 if (status == STATUS_OBJECT_NAME_EXISTS)
477 SetLastError( ERROR_ALREADY_EXISTS );
478 else
479 SetLastError( RtlNtStatusToDosError(status) );
480 return handle;
484 /***********************************************************************
485 * OpenWaitableTimerW (kernelbase.@)
487 HANDLE WINAPI DECLSPEC_HOTPATCH OpenWaitableTimerW( DWORD access, BOOL inherit, LPCWSTR name )
489 HANDLE handle;
490 UNICODE_STRING nameW;
491 OBJECT_ATTRIBUTES attr;
492 NTSTATUS status;
494 if (!is_version_nt()) access = TIMER_ALL_ACCESS;
496 if (!get_open_object_attributes( &attr, &nameW, inherit, name )) return 0;
498 status = NtOpenTimer( &handle, access, &attr );
499 if (status != STATUS_SUCCESS)
501 SetLastError( RtlNtStatusToDosError(status) );
502 return 0;
504 return handle;
508 /***********************************************************************
509 * SetWaitableTimer (kernelbase.@)
511 BOOL WINAPI DECLSPEC_HOTPATCH SetWaitableTimer( HANDLE handle, const LARGE_INTEGER *when, LONG period,
512 PTIMERAPCROUTINE callback, LPVOID arg, BOOL resume )
514 NTSTATUS status = NtSetTimer( handle, when, (PTIMER_APC_ROUTINE)callback,
515 arg, resume, period, NULL );
516 return set_ntstatus( status ) || status == STATUS_TIMER_RESUME_IGNORED;
520 /***********************************************************************
521 * SetWaitableTimerEx (kernelbase.@)
523 BOOL WINAPI DECLSPEC_HOTPATCH SetWaitableTimerEx( HANDLE handle, const LARGE_INTEGER *when, LONG period,
524 PTIMERAPCROUTINE callback, LPVOID arg,
525 REASON_CONTEXT *context, ULONG tolerabledelay )
527 static int once;
528 if (!once++) FIXME( "(%p, %p, %d, %p, %p, %p, %d) semi-stub\n",
529 handle, when, period, callback, arg, context, tolerabledelay );
531 return SetWaitableTimer( handle, when, period, callback, arg, FALSE );
535 /***********************************************************************
536 * CancelWaitableTimer (kernelbase.@)
538 BOOL WINAPI DECLSPEC_HOTPATCH CancelWaitableTimer( HANDLE handle )
540 return set_ntstatus( NtCancelTimer( handle, NULL ));
544 /***********************************************************************
545 * Timer queues
546 ***********************************************************************/
549 /***********************************************************************
550 * CreateTimerQueue (kernelbase.@)
552 HANDLE WINAPI DECLSPEC_HOTPATCH CreateTimerQueue(void)
554 HANDLE q;
555 NTSTATUS status = RtlCreateTimerQueue( &q );
557 if (status != STATUS_SUCCESS)
559 SetLastError( RtlNtStatusToDosError( status ));
560 return NULL;
562 return q;
566 /***********************************************************************
567 * CreateTimerQueueTimer (kernelbase.@)
569 BOOL WINAPI DECLSPEC_HOTPATCH CreateTimerQueueTimer( PHANDLE timer, HANDLE queue,
570 WAITORTIMERCALLBACK callback, PVOID arg,
571 DWORD when, DWORD period, ULONG flags )
573 return set_ntstatus( RtlCreateTimer( timer, queue, callback, arg, when, period, flags ));
577 /***********************************************************************
578 * ChangeTimerQueueTimer (kernelbase.@)
580 BOOL WINAPI DECLSPEC_HOTPATCH ChangeTimerQueueTimer( HANDLE queue, HANDLE timer,
581 ULONG when, ULONG period )
583 return set_ntstatus( RtlUpdateTimer( queue, timer, when, period ));
587 /***********************************************************************
588 * DeleteTimerQueueEx (kernelbase.@)
590 BOOL WINAPI DECLSPEC_HOTPATCH DeleteTimerQueueEx( HANDLE queue, HANDLE event )
592 return set_ntstatus( RtlDeleteTimerQueueEx( queue, event ));
596 /***********************************************************************
597 * DeleteTimerQueueTimer (kernelbase.@)
599 BOOL WINAPI DECLSPEC_HOTPATCH DeleteTimerQueueTimer( HANDLE queue, HANDLE timer, HANDLE event )
601 return set_ntstatus( RtlDeleteTimer( queue, timer, event ));
605 /***********************************************************************
606 * Critical sections
607 ***********************************************************************/
610 /***********************************************************************
611 * InitializeCriticalSectionAndSpinCount (kernelbase.@)
613 BOOL WINAPI DECLSPEC_HOTPATCH InitializeCriticalSectionAndSpinCount( CRITICAL_SECTION *crit, DWORD count )
615 return !RtlInitializeCriticalSectionAndSpinCount( crit, count );
618 /***********************************************************************
619 * InitializeCriticalSectionEx (kernelbase.@)
621 BOOL WINAPI DECLSPEC_HOTPATCH InitializeCriticalSectionEx( CRITICAL_SECTION *crit, DWORD spincount,
622 DWORD flags )
624 NTSTATUS ret = RtlInitializeCriticalSectionEx( crit, spincount, flags );
625 if (ret) RtlRaiseStatus( ret );
626 return !ret;
630 /***********************************************************************
631 * File mappings
632 ***********************************************************************/
635 /***********************************************************************
636 * CreateFileMappingW (kernelbase.@)
638 HANDLE WINAPI DECLSPEC_HOTPATCH CreateFileMappingW( HANDLE file, LPSECURITY_ATTRIBUTES sa, DWORD protect,
639 DWORD size_high, DWORD size_low, LPCWSTR name )
641 static const int sec_flags = (SEC_FILE | SEC_IMAGE | SEC_RESERVE | SEC_COMMIT |
642 SEC_NOCACHE | SEC_WRITECOMBINE | SEC_LARGE_PAGES);
643 HANDLE ret;
644 NTSTATUS status;
645 DWORD access, sec_type;
646 LARGE_INTEGER size;
647 UNICODE_STRING nameW;
648 OBJECT_ATTRIBUTES attr;
650 sec_type = protect & sec_flags;
651 protect &= ~sec_flags;
652 if (!sec_type) sec_type = SEC_COMMIT;
654 /* Win9x compatibility */
655 if (!protect && !is_version_nt()) protect = PAGE_READONLY;
657 switch(protect)
659 case PAGE_READONLY:
660 case PAGE_WRITECOPY:
661 access = STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_READ;
662 break;
663 case PAGE_READWRITE:
664 access = STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_READ | SECTION_MAP_WRITE;
665 break;
666 case PAGE_EXECUTE_READ:
667 case PAGE_EXECUTE_WRITECOPY:
668 access = STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_READ | SECTION_MAP_EXECUTE;
669 break;
670 case PAGE_EXECUTE_READWRITE:
671 access = STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_READ | SECTION_MAP_WRITE | SECTION_MAP_EXECUTE;
672 break;
673 default:
674 SetLastError( ERROR_INVALID_PARAMETER );
675 return 0;
678 size.u.LowPart = size_low;
679 size.u.HighPart = size_high;
681 if (file == INVALID_HANDLE_VALUE)
683 file = 0;
684 if (!size.QuadPart)
686 SetLastError( ERROR_INVALID_PARAMETER );
687 return 0;
691 get_create_object_attributes( &attr, &nameW, sa, name );
693 status = NtCreateSection( &ret, access, &attr, &size, protect, sec_type, file );
694 if (status == STATUS_OBJECT_NAME_EXISTS)
695 SetLastError( ERROR_ALREADY_EXISTS );
696 else
697 SetLastError( RtlNtStatusToDosError(status) );
698 return ret;
702 /***********************************************************************
703 * OpenFileMappingW (kernelbase.@)
705 HANDLE WINAPI DECLSPEC_HOTPATCH OpenFileMappingW( DWORD access, BOOL inherit, LPCWSTR name )
707 OBJECT_ATTRIBUTES attr;
708 UNICODE_STRING nameW;
709 HANDLE ret;
710 NTSTATUS status;
712 if (!get_open_object_attributes( &attr, &nameW, inherit, name )) return 0;
714 if (access == FILE_MAP_COPY) access = SECTION_MAP_READ;
716 if (!is_version_nt())
718 /* win9x doesn't do access checks, so try with full access first */
719 if (!NtOpenSection( &ret, access | SECTION_MAP_READ | SECTION_MAP_WRITE, &attr )) return ret;
722 status = NtOpenSection( &ret, access, &attr );
723 if (status != STATUS_SUCCESS)
725 SetLastError( RtlNtStatusToDosError(status) );
726 return 0;
728 return ret;
732 /***********************************************************************
733 * Condition variables
734 ***********************************************************************/
737 /***********************************************************************
738 * SleepConditionVariableCS (kernelbase.@)
740 BOOL WINAPI DECLSPEC_HOTPATCH SleepConditionVariableCS( CONDITION_VARIABLE *variable,
741 CRITICAL_SECTION *crit, DWORD timeout )
743 LARGE_INTEGER time;
745 return set_ntstatus( RtlSleepConditionVariableCS( variable, crit, get_nt_timeout( &time, timeout )));
749 /***********************************************************************
750 * SleepConditionVariableSRW (kernelbase.@)
752 BOOL WINAPI DECLSPEC_HOTPATCH SleepConditionVariableSRW( RTL_CONDITION_VARIABLE *variable,
753 RTL_SRWLOCK *lock, DWORD timeout, ULONG flags )
755 LARGE_INTEGER time;
757 return set_ntstatus( RtlSleepConditionVariableSRW( variable, lock,
758 get_nt_timeout( &time, timeout ), flags ));