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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "wine/port.h"
29 #ifdef HAVE_SYS_IOCTL_H
30 #include <sys/ioctl.h>
32 #ifdef HAVE_SYS_POLL_H
35 #ifdef HAVE_SYS_SOCKET_H
36 #include <sys/socket.h>
49 #include "wine/server.h"
50 #include "wine/unicode.h"
51 #include "wine/winbase16.h"
52 #include "kernel_private.h"
54 #include "wine/debug.h"
56 WINE_DEFAULT_DEBUG_CHANNEL(sync);
58 /* check if current version is NT or Win95 */
59 inline static int is_version_nt(void)
61 return !(GetVersion() & 0x80000000);
65 /***********************************************************************
68 VOID WINAPI Sleep( DWORD timeout )
70 SleepEx( timeout, FALSE );
73 /******************************************************************************
74 * SleepEx (KERNEL32.@)
76 DWORD WINAPI SleepEx( DWORD timeout, BOOL alertable )
80 if (timeout == INFINITE) status = NtDelayExecution( alertable, NULL );
85 time.QuadPart = timeout * (ULONGLONG)10000;
86 time.QuadPart = -time.QuadPart;
87 status = NtDelayExecution( alertable, &time );
89 if (status != STATUS_USER_APC) status = STATUS_SUCCESS;
94 /***********************************************************************
95 * SwitchToThread (KERNEL32.@)
97 BOOL WINAPI SwitchToThread(void)
99 return (NtYieldExecution() != STATUS_NO_YIELD_PERFORMED);
103 /***********************************************************************
104 * WaitForSingleObject (KERNEL32.@)
106 DWORD WINAPI WaitForSingleObject( HANDLE handle, DWORD timeout )
108 return WaitForMultipleObjectsEx( 1, &handle, FALSE, timeout, FALSE );
112 /***********************************************************************
113 * WaitForSingleObjectEx (KERNEL32.@)
115 DWORD WINAPI WaitForSingleObjectEx( HANDLE handle, DWORD timeout,
118 return WaitForMultipleObjectsEx( 1, &handle, FALSE, timeout, alertable );
122 /***********************************************************************
123 * WaitForMultipleObjects (KERNEL32.@)
125 DWORD WINAPI WaitForMultipleObjects( DWORD count, const HANDLE *handles,
126 BOOL wait_all, DWORD timeout )
128 return WaitForMultipleObjectsEx( count, handles, wait_all, timeout, FALSE );
132 /***********************************************************************
133 * WaitForMultipleObjectsEx (KERNEL32.@)
135 DWORD WINAPI WaitForMultipleObjectsEx( DWORD count, const HANDLE *handles,
136 BOOL wait_all, DWORD timeout,
140 HANDLE hloc[MAXIMUM_WAIT_OBJECTS];
143 if (count >= MAXIMUM_WAIT_OBJECTS)
145 SetLastError(ERROR_INVALID_PARAMETER);
148 for (i = 0; i < count; i++)
150 if ((handles[i] == (HANDLE)STD_INPUT_HANDLE) ||
151 (handles[i] == (HANDLE)STD_OUTPUT_HANDLE) ||
152 (handles[i] == (HANDLE)STD_ERROR_HANDLE))
153 hloc[i] = GetStdHandle( (DWORD)handles[i] );
155 hloc[i] = handles[i];
157 /* yes, even screen buffer console handles are waitable, and are
158 * handled as a handle to the console itself !!
160 if (is_console_handle(hloc[i]))
162 if (!VerifyConsoleIoHandle(hloc[i]))
166 hloc[i] = GetConsoleInputWaitHandle();
170 if (timeout == INFINITE)
172 status = NtWaitForMultipleObjects( count, hloc, wait_all, alertable, NULL );
178 time.QuadPart = timeout * (ULONGLONG)10000;
179 time.QuadPart = -time.QuadPart;
180 status = NtWaitForMultipleObjects( count, hloc, wait_all, alertable, &time );
183 if (HIWORD(status)) /* is it an error code? */
185 SetLastError( RtlNtStatusToDosError(status) );
186 status = WAIT_FAILED;
192 /***********************************************************************
193 * WaitForSingleObject (KERNEL.460)
195 DWORD WINAPI WaitForSingleObject16( HANDLE handle, DWORD timeout )
197 DWORD retval, mutex_count;
199 ReleaseThunkLock( &mutex_count );
200 retval = WaitForSingleObject( handle, timeout );
201 RestoreThunkLock( mutex_count );
205 /***********************************************************************
206 * WaitForMultipleObjects (KERNEL.461)
208 DWORD WINAPI WaitForMultipleObjects16( DWORD count, const HANDLE *handles,
209 BOOL wait_all, DWORD timeout )
211 DWORD retval, mutex_count;
213 ReleaseThunkLock( &mutex_count );
214 retval = WaitForMultipleObjectsEx( count, handles, wait_all, timeout, FALSE );
215 RestoreThunkLock( mutex_count );
219 /***********************************************************************
220 * WaitForMultipleObjectsEx (KERNEL.495)
222 DWORD WINAPI WaitForMultipleObjectsEx16( DWORD count, const HANDLE *handles,
223 BOOL wait_all, DWORD timeout, BOOL alertable )
225 DWORD retval, mutex_count;
227 ReleaseThunkLock( &mutex_count );
228 retval = WaitForMultipleObjectsEx( count, handles, wait_all, timeout, alertable );
229 RestoreThunkLock( mutex_count );
233 /***********************************************************************
234 * RegisterWaitForSingleObject (KERNEL32.@)
236 BOOL WINAPI RegisterWaitForSingleObject(PHANDLE phNewWaitObject, HANDLE hObject,
237 WAITORTIMERCALLBACK Callback, PVOID Context,
238 ULONG dwMilliseconds, ULONG dwFlags)
240 FIXME("%p %p %p %p %ld %ld\n",
241 phNewWaitObject,hObject,Callback,Context,dwMilliseconds,dwFlags);
245 /***********************************************************************
246 * RegisterWaitForSingleObjectEx (KERNEL32.@)
248 HANDLE WINAPI RegisterWaitForSingleObjectEx( HANDLE hObject,
249 WAITORTIMERCALLBACK Callback, PVOID Context,
250 ULONG dwMilliseconds, ULONG dwFlags )
252 FIXME("%p %p %p %ld %ld\n",
253 hObject,Callback,Context,dwMilliseconds,dwFlags);
257 /***********************************************************************
258 * UnregisterWait (KERNEL32.@)
260 BOOL WINAPI UnregisterWait( HANDLE WaitHandle )
262 FIXME("%p\n",WaitHandle);
266 /***********************************************************************
267 * UnregisterWaitEx (KERNEL32.@)
269 BOOL WINAPI UnregisterWaitEx( HANDLE WaitHandle, HANDLE CompletionEvent )
271 FIXME("%p %p\n",WaitHandle, CompletionEvent);
275 /***********************************************************************
276 * SignalObjectAndWait (KERNEL32.@)
278 * Allows to atomically signal any of the synchro objects (semaphore,
279 * mutex, event) and wait on another.
281 DWORD WINAPI SignalObjectAndWait( HANDLE hObjectToSignal, HANDLE hObjectToWaitOn, DWORD dwMilliseconds, BOOL bAlertable )
283 FIXME("(%p %p %ld %d): stub\n", hObjectToSignal, hObjectToWaitOn, dwMilliseconds, bAlertable);
284 return WAIT_OBJECT_0;
288 /***********************************************************************
289 * InitializeCriticalSection (KERNEL32.@)
291 * Initialise a critical section before use.
294 * crit [O] Critical section to initialise.
297 * Nothing. If the function fails an exception is raised.
299 void WINAPI InitializeCriticalSection( CRITICAL_SECTION *crit )
301 NTSTATUS ret = RtlInitializeCriticalSection( crit );
302 if (ret) RtlRaiseStatus( ret );
305 /***********************************************************************
306 * InitializeCriticalSectionAndSpinCount (KERNEL32.@)
308 * Initialise a critical section with a spin count.
311 * crit [O] Critical section to initialise.
312 * spincount [I] Number of times to spin upon contention.
316 * Failure: Nothing. If the function fails an exception is raised.
319 * spincount is ignored on uni-processor systems.
321 BOOL WINAPI InitializeCriticalSectionAndSpinCount( CRITICAL_SECTION *crit, DWORD spincount )
323 NTSTATUS ret = RtlInitializeCriticalSectionAndSpinCount( crit, spincount );
324 if (ret) RtlRaiseStatus( ret );
328 /***********************************************************************
329 * MakeCriticalSectionGlobal (KERNEL32.@)
331 void WINAPI MakeCriticalSectionGlobal( CRITICAL_SECTION *crit )
333 /* let's assume that only one thread at a time will try to do this */
334 HANDLE sem = crit->LockSemaphore;
335 if (!sem) NtCreateSemaphore( &sem, SEMAPHORE_ALL_ACCESS, NULL, 0, 1 );
336 crit->LockSemaphore = ConvertToGlobalHandle( sem );
339 RtlFreeHeap( GetProcessHeap(), 0, crit->DebugInfo );
340 crit->DebugInfo = NULL;
345 /***********************************************************************
346 * ReinitializeCriticalSection (KERNEL32.@)
348 * Initialise an already used critical section.
351 * crit [O] Critical section to initialise.
356 void WINAPI ReinitializeCriticalSection( CRITICAL_SECTION *crit )
358 if ( !crit->LockSemaphore )
359 RtlInitializeCriticalSection( crit );
363 /***********************************************************************
364 * UninitializeCriticalSection (KERNEL32.@)
366 * UnInitialise a critical section after use.
369 * crit [O] Critical section to uninitialise (destroy).
374 void WINAPI UninitializeCriticalSection( CRITICAL_SECTION *crit )
376 RtlDeleteCriticalSection( crit );
380 /***********************************************************************
381 * CreateEventA (KERNEL32.@)
383 HANDLE WINAPI CreateEventA( SECURITY_ATTRIBUTES *sa, BOOL manual_reset,
384 BOOL initial_state, LPCSTR name )
386 WCHAR buffer[MAX_PATH];
388 if (!name) return CreateEventW( sa, manual_reset, initial_state, NULL );
390 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
392 SetLastError( ERROR_FILENAME_EXCED_RANGE );
395 return CreateEventW( sa, manual_reset, initial_state, buffer );
399 /***********************************************************************
400 * CreateEventW (KERNEL32.@)
402 HANDLE WINAPI CreateEventW( SECURITY_ATTRIBUTES *sa, BOOL manual_reset,
403 BOOL initial_state, LPCWSTR name )
406 UNICODE_STRING nameW;
407 OBJECT_ATTRIBUTES attr;
410 /* one buggy program needs this
411 * ("Van Dale Groot woordenboek der Nederlandse taal")
413 if (sa && IsBadReadPtr(sa,sizeof(SECURITY_ATTRIBUTES)))
415 ERR("Bad security attributes pointer %p\n",sa);
416 SetLastError( ERROR_INVALID_PARAMETER);
420 attr.Length = sizeof(attr);
421 attr.RootDirectory = 0;
422 attr.ObjectName = NULL;
423 attr.Attributes = (sa && sa->bInheritHandle) ? OBJ_INHERIT : 0;
424 attr.SecurityDescriptor = sa ? sa->lpSecurityDescriptor : NULL;
425 attr.SecurityQualityOfService = NULL;
428 RtlInitUnicodeString( &nameW, name );
429 attr.ObjectName = &nameW;
432 status = NtCreateEvent( &ret, EVENT_ALL_ACCESS, &attr, manual_reset, initial_state );
433 SetLastError( RtlNtStatusToDosError(status) );
438 /***********************************************************************
439 * CreateW32Event (KERNEL.457)
441 HANDLE WINAPI WIN16_CreateEvent( BOOL manual_reset, BOOL initial_state )
443 return CreateEventW( NULL, manual_reset, initial_state, NULL );
447 /***********************************************************************
448 * OpenEventA (KERNEL32.@)
450 HANDLE WINAPI OpenEventA( DWORD access, BOOL inherit, LPCSTR name )
452 WCHAR buffer[MAX_PATH];
454 if (!name) return OpenEventW( access, inherit, NULL );
456 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
458 SetLastError( ERROR_FILENAME_EXCED_RANGE );
461 return OpenEventW( access, inherit, buffer );
465 /***********************************************************************
466 * OpenEventW (KERNEL32.@)
468 HANDLE WINAPI OpenEventW( DWORD access, BOOL inherit, LPCWSTR name )
471 UNICODE_STRING nameW;
472 OBJECT_ATTRIBUTES attr;
475 if (!is_version_nt()) access = EVENT_ALL_ACCESS;
477 attr.Length = sizeof(attr);
478 attr.RootDirectory = 0;
479 attr.ObjectName = NULL;
480 attr.Attributes = inherit ? OBJ_INHERIT : 0;
481 attr.SecurityDescriptor = NULL;
482 attr.SecurityQualityOfService = NULL;
485 RtlInitUnicodeString( &nameW, name );
486 attr.ObjectName = &nameW;
489 status = NtOpenEvent( &ret, access, &attr );
490 if (status != STATUS_SUCCESS)
492 SetLastError( RtlNtStatusToDosError(status) );
498 /***********************************************************************
499 * PulseEvent (KERNEL32.@)
501 BOOL WINAPI PulseEvent( HANDLE handle )
505 if ((status = NtPulseEvent( handle, NULL )))
506 SetLastError( RtlNtStatusToDosError(status) );
511 /***********************************************************************
512 * SetW32Event (KERNEL.458)
513 * SetEvent (KERNEL32.@)
515 BOOL WINAPI SetEvent( HANDLE handle )
519 if ((status = NtSetEvent( handle, NULL )))
520 SetLastError( RtlNtStatusToDosError(status) );
525 /***********************************************************************
526 * ResetW32Event (KERNEL.459)
527 * ResetEvent (KERNEL32.@)
529 BOOL WINAPI ResetEvent( HANDLE handle )
533 if ((status = NtResetEvent( handle, NULL )))
534 SetLastError( RtlNtStatusToDosError(status) );
539 /***********************************************************************
540 * NOTE: The Win95 VWin32_Event routines given below are really low-level
541 * routines implemented directly by VWin32. The user-mode libraries
542 * implement Win32 synchronisation routines on top of these low-level
543 * primitives. We do it the other way around here :-)
546 /***********************************************************************
547 * VWin32_EventCreate (KERNEL.442)
549 HANDLE WINAPI VWin32_EventCreate(VOID)
551 HANDLE hEvent = CreateEventW( NULL, FALSE, 0, NULL );
552 return ConvertToGlobalHandle( hEvent );
555 /***********************************************************************
556 * VWin32_EventDestroy (KERNEL.443)
558 VOID WINAPI VWin32_EventDestroy(HANDLE event)
560 CloseHandle( event );
563 /***********************************************************************
564 * VWin32_EventWait (KERNEL.450)
566 VOID WINAPI VWin32_EventWait(HANDLE event)
570 ReleaseThunkLock( &mutex_count );
571 WaitForSingleObject( event, INFINITE );
572 RestoreThunkLock( mutex_count );
575 /***********************************************************************
576 * VWin32_EventSet (KERNEL.451)
577 * KERNEL_479 (KERNEL.479)
579 VOID WINAPI VWin32_EventSet(HANDLE event)
586 /***********************************************************************
587 * CreateMutexA (KERNEL32.@)
589 HANDLE WINAPI CreateMutexA( SECURITY_ATTRIBUTES *sa, BOOL owner, LPCSTR name )
591 WCHAR buffer[MAX_PATH];
593 if (!name) return CreateMutexW( sa, owner, NULL );
595 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
597 SetLastError( ERROR_FILENAME_EXCED_RANGE );
600 return CreateMutexW( sa, owner, buffer );
604 /***********************************************************************
605 * CreateMutexW (KERNEL32.@)
607 HANDLE WINAPI CreateMutexW( SECURITY_ATTRIBUTES *sa, BOOL owner, LPCWSTR name )
610 UNICODE_STRING nameW;
611 OBJECT_ATTRIBUTES attr;
614 attr.Length = sizeof(attr);
615 attr.RootDirectory = 0;
616 attr.ObjectName = NULL;
617 attr.Attributes = (sa && sa->bInheritHandle) ? OBJ_INHERIT : 0;
618 attr.SecurityDescriptor = sa ? sa->lpSecurityDescriptor : NULL;
619 attr.SecurityQualityOfService = NULL;
622 RtlInitUnicodeString( &nameW, name );
623 attr.ObjectName = &nameW;
626 status = NtCreateMutant( &ret, MUTEX_ALL_ACCESS, &attr, owner );
627 SetLastError( RtlNtStatusToDosError(status) );
632 /***********************************************************************
633 * OpenMutexA (KERNEL32.@)
635 HANDLE WINAPI OpenMutexA( DWORD access, BOOL inherit, LPCSTR name )
637 WCHAR buffer[MAX_PATH];
639 if (!name) return OpenMutexW( access, inherit, NULL );
641 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
643 SetLastError( ERROR_FILENAME_EXCED_RANGE );
646 return OpenMutexW( access, inherit, buffer );
650 /***********************************************************************
651 * OpenMutexW (KERNEL32.@)
653 HANDLE WINAPI OpenMutexW( DWORD access, BOOL inherit, LPCWSTR name )
656 UNICODE_STRING nameW;
657 OBJECT_ATTRIBUTES attr;
660 if (!is_version_nt()) access = MUTEX_ALL_ACCESS;
662 attr.Length = sizeof(attr);
663 attr.RootDirectory = 0;
664 attr.ObjectName = NULL;
665 attr.Attributes = inherit ? OBJ_INHERIT : 0;
666 attr.SecurityDescriptor = NULL;
667 attr.SecurityQualityOfService = NULL;
670 RtlInitUnicodeString( &nameW, name );
671 attr.ObjectName = &nameW;
674 status = NtOpenMutant( &ret, access, &attr );
675 if (status != STATUS_SUCCESS)
677 SetLastError( RtlNtStatusToDosError(status) );
684 /***********************************************************************
685 * ReleaseMutex (KERNEL32.@)
687 BOOL WINAPI ReleaseMutex( HANDLE handle )
691 status = NtReleaseMutant(handle, NULL);
692 if (status != STATUS_SUCCESS)
694 SetLastError( RtlNtStatusToDosError(status) );
706 /***********************************************************************
707 * CreateSemaphoreA (KERNEL32.@)
709 HANDLE WINAPI CreateSemaphoreA( SECURITY_ATTRIBUTES *sa, LONG initial, LONG max, LPCSTR name )
711 WCHAR buffer[MAX_PATH];
713 if (!name) return CreateSemaphoreW( sa, initial, max, NULL );
715 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
717 SetLastError( ERROR_FILENAME_EXCED_RANGE );
720 return CreateSemaphoreW( sa, initial, max, buffer );
724 /***********************************************************************
725 * CreateSemaphoreW (KERNEL32.@)
727 HANDLE WINAPI CreateSemaphoreW( SECURITY_ATTRIBUTES *sa, LONG initial,
728 LONG max, LPCWSTR name )
731 UNICODE_STRING nameW;
732 OBJECT_ATTRIBUTES attr;
735 attr.Length = sizeof(attr);
736 attr.RootDirectory = 0;
737 attr.ObjectName = NULL;
738 attr.Attributes = (sa && sa->bInheritHandle) ? OBJ_INHERIT : 0;
739 attr.SecurityDescriptor = sa ? sa->lpSecurityDescriptor : NULL;
740 attr.SecurityQualityOfService = NULL;
743 RtlInitUnicodeString( &nameW, name );
744 attr.ObjectName = &nameW;
747 status = NtCreateSemaphore( &ret, SEMAPHORE_ALL_ACCESS, &attr, initial, max );
748 SetLastError( RtlNtStatusToDosError(status) );
753 /***********************************************************************
754 * OpenSemaphoreA (KERNEL32.@)
756 HANDLE WINAPI OpenSemaphoreA( DWORD access, BOOL inherit, LPCSTR name )
758 WCHAR buffer[MAX_PATH];
760 if (!name) return OpenSemaphoreW( access, inherit, NULL );
762 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
764 SetLastError( ERROR_FILENAME_EXCED_RANGE );
767 return OpenSemaphoreW( access, inherit, buffer );
771 /***********************************************************************
772 * OpenSemaphoreW (KERNEL32.@)
774 HANDLE WINAPI OpenSemaphoreW( DWORD access, BOOL inherit, LPCWSTR name )
777 UNICODE_STRING nameW;
778 OBJECT_ATTRIBUTES attr;
781 if (!is_version_nt()) access = SEMAPHORE_ALL_ACCESS;
783 attr.Length = sizeof(attr);
784 attr.RootDirectory = 0;
785 attr.ObjectName = NULL;
786 attr.Attributes = inherit ? OBJ_INHERIT : 0;
787 attr.SecurityDescriptor = NULL;
788 attr.SecurityQualityOfService = NULL;
791 RtlInitUnicodeString( &nameW, name );
792 attr.ObjectName = &nameW;
795 status = NtOpenSemaphore( &ret, access, &attr );
796 if (status != STATUS_SUCCESS)
798 SetLastError( RtlNtStatusToDosError(status) );
805 /***********************************************************************
806 * ReleaseSemaphore (KERNEL32.@)
808 BOOL WINAPI ReleaseSemaphore( HANDLE handle, LONG count, LONG *previous )
810 NTSTATUS status = NtReleaseSemaphore( handle, count, previous );
811 if (status) SetLastError( RtlNtStatusToDosError(status) );
821 /***********************************************************************
822 * CreateWaitableTimerA (KERNEL32.@)
824 HANDLE WINAPI CreateWaitableTimerA( SECURITY_ATTRIBUTES *sa, BOOL manual, LPCSTR name )
826 WCHAR buffer[MAX_PATH];
828 if (!name) return CreateWaitableTimerW( sa, manual, NULL );
830 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
832 SetLastError( ERROR_FILENAME_EXCED_RANGE );
835 return CreateWaitableTimerW( sa, manual, buffer );
839 /***********************************************************************
840 * CreateWaitableTimerW (KERNEL32.@)
842 HANDLE WINAPI CreateWaitableTimerW( SECURITY_ATTRIBUTES *sa, BOOL manual, LPCWSTR name )
846 UNICODE_STRING nameW;
847 OBJECT_ATTRIBUTES attr;
849 attr.Length = sizeof(attr);
850 attr.RootDirectory = 0;
851 attr.ObjectName = NULL;
852 attr.Attributes = (sa && sa->bInheritHandle) ? OBJ_INHERIT : 0;
853 attr.SecurityDescriptor = sa ? sa->lpSecurityDescriptor : NULL;
854 attr.SecurityQualityOfService = NULL;
857 RtlInitUnicodeString( &nameW, name );
858 attr.ObjectName = &nameW;
861 status = NtCreateTimer(&handle, TIMER_ALL_ACCESS, &attr,
862 manual ? NotificationTimer : SynchronizationTimer);
863 SetLastError( RtlNtStatusToDosError(status) );
868 /***********************************************************************
869 * OpenWaitableTimerA (KERNEL32.@)
871 HANDLE WINAPI OpenWaitableTimerA( DWORD access, BOOL inherit, LPCSTR name )
873 WCHAR buffer[MAX_PATH];
875 if (!name) return OpenWaitableTimerW( access, inherit, NULL );
877 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
879 SetLastError( ERROR_FILENAME_EXCED_RANGE );
882 return OpenWaitableTimerW( access, inherit, buffer );
886 /***********************************************************************
887 * OpenWaitableTimerW (KERNEL32.@)
889 HANDLE WINAPI OpenWaitableTimerW( DWORD access, BOOL inherit, LPCWSTR name )
892 UNICODE_STRING nameW;
893 OBJECT_ATTRIBUTES attr;
896 if (!is_version_nt()) access = TIMER_ALL_ACCESS;
898 attr.Length = sizeof(attr);
899 attr.RootDirectory = 0;
900 attr.ObjectName = NULL;
901 attr.Attributes = inherit ? OBJ_INHERIT : 0;
902 attr.SecurityDescriptor = NULL;
903 attr.SecurityQualityOfService = NULL;
906 RtlInitUnicodeString( &nameW, name );
907 attr.ObjectName = &nameW;
910 status = NtOpenTimer(&handle, access, &attr);
911 if (status != STATUS_SUCCESS)
913 SetLastError( RtlNtStatusToDosError(status) );
920 /***********************************************************************
921 * SetWaitableTimer (KERNEL32.@)
923 BOOL WINAPI SetWaitableTimer( HANDLE handle, const LARGE_INTEGER *when, LONG period,
924 PTIMERAPCROUTINE callback, LPVOID arg, BOOL resume )
926 NTSTATUS status = NtSetTimer(handle, when, callback, arg, resume, period, NULL);
928 if (status != STATUS_SUCCESS)
930 SetLastError( RtlNtStatusToDosError(status) );
931 if (status != STATUS_TIMER_RESUME_IGNORED) return FALSE;
937 /***********************************************************************
938 * CancelWaitableTimer (KERNEL32.@)
940 BOOL WINAPI CancelWaitableTimer( HANDLE handle )
944 status = NtCancelTimer(handle, NULL);
945 if (status != STATUS_SUCCESS)
947 SetLastError( RtlNtStatusToDosError(status) );
954 /***********************************************************************
955 * CreateTimerQueue (KERNEL32.@)
957 HANDLE WINAPI CreateTimerQueue(void)
960 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
965 /***********************************************************************
966 * DeleteTimerQueueEx (KERNEL32.@)
968 BOOL WINAPI DeleteTimerQueueEx(HANDLE TimerQueue, HANDLE CompletionEvent)
970 FIXME("(%p, %p): stub\n", TimerQueue, CompletionEvent);
971 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
975 /***********************************************************************
976 * CreateTimerQueueTimer (KERNEL32.@)
978 * Creates a timer-queue timer. This timer expires at the specified due
979 * time (in ms), then after every specified period (in ms). When the timer
980 * expires, the callback function is called.
983 * nonzero on success or zero on faillure
988 BOOL WINAPI CreateTimerQueueTimer( PHANDLE phNewTimer, HANDLE TimerQueue,
989 WAITORTIMERCALLBACK Callback, PVOID Parameter,
990 DWORD DueTime, DWORD Period, ULONG Flags )
993 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
997 /***********************************************************************
998 * DeleteTimerQueueTimer (KERNEL32.@)
1000 * Cancels a timer-queue timer.
1003 * nonzero on success or zero on faillure
1008 BOOL WINAPI DeleteTimerQueueTimer( HANDLE TimerQueue, HANDLE Timer,
1009 HANDLE CompletionEvent )
1012 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1022 /***********************************************************************
1023 * CreateNamedPipeA (KERNEL32.@)
1025 HANDLE WINAPI CreateNamedPipeA( LPCSTR name, DWORD dwOpenMode,
1026 DWORD dwPipeMode, DWORD nMaxInstances,
1027 DWORD nOutBufferSize, DWORD nInBufferSize,
1028 DWORD nDefaultTimeOut, LPSECURITY_ATTRIBUTES attr )
1030 WCHAR buffer[MAX_PATH];
1032 if (!name) return CreateNamedPipeW( NULL, dwOpenMode, dwPipeMode, nMaxInstances,
1033 nOutBufferSize, nInBufferSize, nDefaultTimeOut, attr );
1035 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
1037 SetLastError( ERROR_FILENAME_EXCED_RANGE );
1038 return INVALID_HANDLE_VALUE;
1040 return CreateNamedPipeW( buffer, dwOpenMode, dwPipeMode, nMaxInstances,
1041 nOutBufferSize, nInBufferSize, nDefaultTimeOut, attr );
1045 /***********************************************************************
1046 * CreateNamedPipeW (KERNEL32.@)
1048 HANDLE WINAPI CreateNamedPipeW( LPCWSTR name, DWORD dwOpenMode,
1049 DWORD dwPipeMode, DWORD nMaxInstances,
1050 DWORD nOutBufferSize, DWORD nInBufferSize,
1051 DWORD nDefaultTimeOut, LPSECURITY_ATTRIBUTES attr )
1054 UNICODE_STRING nt_name;
1055 static const WCHAR leadin[] = {'\\','?','?','\\','P','I','P','E','\\'};
1057 TRACE("(%s, %#08lx, %#08lx, %ld, %ld, %ld, %ld, %p)\n",
1058 debugstr_w(name), dwOpenMode, dwPipeMode, nMaxInstances,
1059 nOutBufferSize, nInBufferSize, nDefaultTimeOut, attr );
1061 if (!RtlDosPathNameToNtPathName_U( name, &nt_name, NULL, NULL ))
1063 SetLastError( ERROR_PATH_NOT_FOUND );
1064 return INVALID_HANDLE_VALUE;
1066 if (nt_name.Length >= MAX_PATH * sizeof(WCHAR) )
1068 SetLastError( ERROR_FILENAME_EXCED_RANGE );
1069 RtlFreeUnicodeString( &nt_name );
1070 return INVALID_HANDLE_VALUE;
1072 if (nt_name.Length < sizeof(leadin) ||
1073 strncmpiW( nt_name.Buffer, leadin, sizeof(leadin)/sizeof(leadin[0])))
1075 SetLastError( ERROR_INVALID_NAME );
1076 RtlFreeUnicodeString( &nt_name );
1077 return INVALID_HANDLE_VALUE;
1079 SERVER_START_REQ( create_named_pipe )
1081 req->openmode = dwOpenMode;
1082 req->pipemode = dwPipeMode;
1083 req->maxinstances = nMaxInstances;
1084 req->outsize = nOutBufferSize;
1085 req->insize = nInBufferSize;
1086 req->timeout = nDefaultTimeOut;
1087 req->inherit = (attr && (attr->nLength>=sizeof(*attr)) && attr->bInheritHandle);
1088 wine_server_add_data( req, nt_name.Buffer + 4, nt_name.Length - 4*sizeof(WCHAR) );
1090 if (!wine_server_call_err( req )) ret = reply->handle;
1091 else ret = INVALID_HANDLE_VALUE;
1094 RtlFreeUnicodeString( &nt_name );
1099 /***********************************************************************
1100 * PeekNamedPipe (KERNEL32.@)
1102 BOOL WINAPI PeekNamedPipe( HANDLE hPipe, LPVOID lpvBuffer, DWORD cbBuffer,
1103 LPDWORD lpcbRead, LPDWORD lpcbAvail, LPDWORD lpcbMessage )
1106 int avail=0, fd, ret, flags;
1108 ret = wine_server_handle_to_fd( hPipe, GENERIC_READ, &fd, &flags );
1111 SetLastError( RtlNtStatusToDosError(ret) );
1114 if (flags & FD_FLAG_RECV_SHUTDOWN)
1116 wine_server_release_fd( hPipe, fd );
1117 SetLastError ( ERROR_PIPE_NOT_CONNECTED );
1121 if (ioctl(fd,FIONREAD, &avail ) != 0)
1123 TRACE("FIONREAD failed reason: %s\n",strerror(errno));
1124 wine_server_release_fd( hPipe, fd );
1127 if (!avail) /* check for closed pipe */
1129 struct pollfd pollfd;
1131 pollfd.events = POLLIN;
1133 switch (poll( &pollfd, 1, 0 ))
1137 case 1: /* got something */
1138 if (!(pollfd.revents & (POLLHUP | POLLERR))) break;
1139 TRACE("POLLHUP | POLLERR\n");
1142 wine_server_release_fd( hPipe, fd );
1143 SetLastError(ERROR_BROKEN_PIPE);
1147 TRACE(" 0x%08x bytes available\n", avail );
1153 if (avail && lpvBuffer)
1155 int readbytes = (avail < cbBuffer) ? avail : cbBuffer;
1156 readbytes = recv(fd, lpvBuffer, readbytes, MSG_PEEK);
1159 WARN("failed to peek socket (%d)\n", errno);
1163 *lpcbRead = readbytes;
1165 wine_server_release_fd( hPipe, fd );
1167 #endif /* defined(FIONREAD) */
1169 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1170 FIXME("function not implemented\n");
1174 /***********************************************************************
1175 * SYNC_CompletePipeOverlapped (Internal)
1177 static void CALLBACK SYNC_CompletePipeOverlapped (LPOVERLAPPED overlapped, DWORD result)
1179 TRACE("for %p result %08lx\n",overlapped,result);
1182 overlapped->Internal = result;
1183 SetEvent(overlapped->hEvent);
1187 /***********************************************************************
1188 * WaitNamedPipeA (KERNEL32.@)
1190 BOOL WINAPI WaitNamedPipeA (LPCSTR name, DWORD nTimeOut)
1192 WCHAR buffer[MAX_PATH];
1194 if (!name) return WaitNamedPipeW( NULL, nTimeOut );
1196 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
1198 SetLastError( ERROR_FILENAME_EXCED_RANGE );
1201 return WaitNamedPipeW( buffer, nTimeOut );
1205 /***********************************************************************
1206 * WaitNamedPipeW (KERNEL32.@)
1208 BOOL WINAPI WaitNamedPipeW (LPCWSTR name, DWORD nTimeOut)
1212 UNICODE_STRING nt_name;
1213 static const WCHAR leadin[] = {'\\','?','?','\\','P','I','P','E','\\'};
1215 TRACE("%s 0x%08lx\n",debugstr_w(name),nTimeOut);
1217 if (!RtlDosPathNameToNtPathName_U( name, &nt_name, NULL, NULL ))
1220 if (nt_name.Length >= MAX_PATH * sizeof(WCHAR) )
1222 RtlFreeUnicodeString( &nt_name );
1225 if (nt_name.Length < sizeof(leadin) ||
1226 strncmpiW( nt_name.Buffer, leadin, sizeof(leadin)/sizeof(leadin[0])))
1228 RtlFreeUnicodeString( &nt_name );
1232 memset(&ov,0,sizeof(ov));
1233 ov.hEvent = CreateEventW( NULL, 0, 0, NULL );
1237 SERVER_START_REQ( wait_named_pipe )
1239 req->timeout = nTimeOut;
1240 req->overlapped = &ov;
1241 req->func = SYNC_CompletePipeOverlapped;
1242 wine_server_add_data( req, nt_name.Buffer + 4, nt_name.Length - 4*sizeof(WCHAR) );
1243 ret = !wine_server_call_err( req );
1247 RtlFreeUnicodeString( &nt_name );
1251 if (WAIT_OBJECT_0==WaitForSingleObject(ov.hEvent,INFINITE))
1253 SetLastError(RtlNtStatusToDosError(ov.Internal));
1254 ret = (ov.Internal==STATUS_SUCCESS);
1257 CloseHandle(ov.hEvent);
1262 /***********************************************************************
1263 * SYNC_ConnectNamedPipe (Internal)
1265 static BOOL SYNC_ConnectNamedPipe(HANDLE hPipe, LPOVERLAPPED overlapped)
1272 overlapped->Internal = STATUS_PENDING;
1274 SERVER_START_REQ( connect_named_pipe )
1276 req->handle = hPipe;
1277 req->overlapped = overlapped;
1278 req->func = SYNC_CompletePipeOverlapped;
1279 ret = !wine_server_call_err( req );
1286 /***********************************************************************
1287 * ConnectNamedPipe (KERNEL32.@)
1289 BOOL WINAPI ConnectNamedPipe(HANDLE hPipe, LPOVERLAPPED overlapped)
1294 TRACE("(%p,%p)\n",hPipe, overlapped);
1298 if(SYNC_ConnectNamedPipe(hPipe,overlapped))
1299 SetLastError( ERROR_IO_PENDING );
1303 memset(&ov,0,sizeof(ov));
1304 ov.hEvent = CreateEventW(NULL,0,0,NULL);
1308 ret=SYNC_ConnectNamedPipe(hPipe, &ov);
1311 if (WAIT_OBJECT_0==WaitForSingleObject(ov.hEvent,INFINITE))
1313 SetLastError(RtlNtStatusToDosError(ov.Internal));
1314 ret = (ov.Internal==STATUS_SUCCESS);
1318 CloseHandle(ov.hEvent);
1323 /***********************************************************************
1324 * DisconnectNamedPipe (KERNEL32.@)
1326 BOOL WINAPI DisconnectNamedPipe(HANDLE hPipe)
1330 TRACE("(%p)\n",hPipe);
1332 SERVER_START_REQ( disconnect_named_pipe )
1334 req->handle = hPipe;
1335 ret = !wine_server_call_err( req );
1336 if (ret && reply->fd != -1) close( reply->fd );
1343 /***********************************************************************
1344 * TransactNamedPipe (KERNEL32.@)
1347 * should be done as a single operation in the wineserver or kernel
1349 BOOL WINAPI TransactNamedPipe(
1350 HANDLE handle, LPVOID lpInput, DWORD dwInputSize, LPVOID lpOutput,
1351 DWORD dwOutputSize, LPDWORD lpBytesRead, LPOVERLAPPED lpOverlapped)
1356 TRACE("%p %p %ld %p %ld %p %p\n",
1357 handle, lpInput, dwInputSize, lpOutput,
1358 dwOutputSize, lpBytesRead, lpOverlapped);
1362 FIXME("Doesn't support overlapped operation as yet\n");
1366 r = WriteFile(handle, lpOutput, dwOutputSize, &count, NULL);
1368 r = ReadFile(handle, lpInput, dwInputSize, lpBytesRead, NULL);
1373 /***********************************************************************
1374 * GetNamedPipeInfo (KERNEL32.@)
1376 BOOL WINAPI GetNamedPipeInfo(
1377 HANDLE hNamedPipe, LPDWORD lpFlags, LPDWORD lpOutputBufferSize,
1378 LPDWORD lpInputBufferSize, LPDWORD lpMaxInstances)
1382 TRACE("%p %p %p %p %p\n", hNamedPipe, lpFlags,
1383 lpOutputBufferSize, lpInputBufferSize, lpMaxInstances);
1385 SERVER_START_REQ( get_named_pipe_info )
1387 req->handle = hNamedPipe;
1388 ret = !wine_server_call_err( req );
1389 if(lpFlags) *lpFlags = reply->flags;
1390 if(lpOutputBufferSize) *lpOutputBufferSize = reply->outsize;
1391 if(lpInputBufferSize) *lpInputBufferSize = reply->outsize;
1392 if(lpMaxInstances) *lpMaxInstances = reply->maxinstances;
1399 /***********************************************************************
1400 * GetNamedPipeHandleStateA (KERNEL32.@)
1402 BOOL WINAPI GetNamedPipeHandleStateA(
1403 HANDLE hNamedPipe, LPDWORD lpState, LPDWORD lpCurInstances,
1404 LPDWORD lpMaxCollectionCount, LPDWORD lpCollectDataTimeout,
1405 LPSTR lpUsername, DWORD nUsernameMaxSize)
1407 FIXME("%p %p %p %p %p %p %ld\n",
1408 hNamedPipe, lpState, lpCurInstances,
1409 lpMaxCollectionCount, lpCollectDataTimeout,
1410 lpUsername, nUsernameMaxSize);
1415 /***********************************************************************
1416 * GetNamedPipeHandleStateW (KERNEL32.@)
1418 BOOL WINAPI GetNamedPipeHandleStateW(
1419 HANDLE hNamedPipe, LPDWORD lpState, LPDWORD lpCurInstances,
1420 LPDWORD lpMaxCollectionCount, LPDWORD lpCollectDataTimeout,
1421 LPWSTR lpUsername, DWORD nUsernameMaxSize)
1423 FIXME("%p %p %p %p %p %p %ld\n",
1424 hNamedPipe, lpState, lpCurInstances,
1425 lpMaxCollectionCount, lpCollectDataTimeout,
1426 lpUsername, nUsernameMaxSize);
1431 /***********************************************************************
1432 * SetNamedPipeHandleState (KERNEL32.@)
1434 BOOL WINAPI SetNamedPipeHandleState(
1435 HANDLE hNamedPipe, LPDWORD lpMode, LPDWORD lpMaxCollectionCount,
1436 LPDWORD lpCollectDataTimeout)
1438 FIXME("%p %p %p %p\n",
1439 hNamedPipe, lpMode, lpMaxCollectionCount, lpCollectDataTimeout);
1443 /***********************************************************************
1444 * CallNamedPipeA (KERNEL32.@)
1446 BOOL WINAPI CallNamedPipeA(
1447 LPCSTR lpNamedPipeName, LPVOID lpInput, DWORD dwInputSize,
1448 LPVOID lpOutput, DWORD dwOutputSize,
1449 LPDWORD lpBytesRead, DWORD nTimeout)
1455 TRACE("%s %p %ld %p %ld %p %ld\n",
1456 debugstr_a(lpNamedPipeName), lpInput, dwInputSize,
1457 lpOutput, dwOutputSize, lpBytesRead, nTimeout);
1459 if( lpNamedPipeName )
1461 len = MultiByteToWideChar( CP_ACP, 0, lpNamedPipeName, -1, NULL, 0 );
1462 str = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
1463 MultiByteToWideChar( CP_ACP, 0, lpNamedPipeName, -1, str, len );
1465 ret = CallNamedPipeW( str, lpInput, dwInputSize, lpOutput,
1466 dwOutputSize, lpBytesRead, nTimeout );
1467 if( lpNamedPipeName )
1468 HeapFree( GetProcessHeap(), 0, str );
1473 /***********************************************************************
1474 * CallNamedPipeW (KERNEL32.@)
1476 BOOL WINAPI CallNamedPipeW(
1477 LPCWSTR lpNamedPipeName, LPVOID lpInput, DWORD lpInputSize,
1478 LPVOID lpOutput, DWORD lpOutputSize,
1479 LPDWORD lpBytesRead, DWORD nTimeout)
1481 FIXME("%s %p %ld %p %ld %p %ld\n",
1482 debugstr_w(lpNamedPipeName), lpInput, lpInputSize,
1483 lpOutput, lpOutputSize, lpBytesRead, nTimeout);
1487 /******************************************************************
1488 * CreatePipe (KERNEL32.@)
1491 BOOL WINAPI CreatePipe( PHANDLE hReadPipe, PHANDLE hWritePipe,
1492 LPSECURITY_ATTRIBUTES sa, DWORD size )
1494 static unsigned index = 0;
1497 unsigned in_index = index;
1499 *hReadPipe = *hWritePipe = INVALID_HANDLE_VALUE;
1500 /* generate a unique pipe name (system wide) */
1503 static const WCHAR nameFmt[] = { '\\','\\','.','\\','p','i','p','e',
1504 '\\','W','i','n','3','2','.','P','i','p','e','s','.','%','0','8','l',
1505 'u','.','%','0','8','u','\0' };
1506 snprintfW(name, sizeof(name) / sizeof(name[0]), nameFmt,
1507 GetCurrentProcessId(), ++index);
1508 hr = CreateNamedPipeW(name, PIPE_ACCESS_INBOUND,
1509 PIPE_TYPE_BYTE | PIPE_WAIT, 1, size, size,
1510 NMPWAIT_USE_DEFAULT_WAIT, sa);
1511 } while (hr == INVALID_HANDLE_VALUE && index != in_index);
1512 /* from completion sakeness, I think system resources might be exhausted before this happens !! */
1513 if (hr == INVALID_HANDLE_VALUE) return FALSE;
1515 hw = CreateFileW(name, GENERIC_WRITE, 0, sa, OPEN_EXISTING, 0, 0);
1516 if (hw == INVALID_HANDLE_VALUE)
1528 /******************************************************************************
1529 * CreateMailslotA [KERNEL32.@]
1531 HANDLE WINAPI CreateMailslotA( LPCSTR lpName, DWORD nMaxMessageSize,
1532 DWORD lReadTimeout, LPSECURITY_ATTRIBUTES sa )
1538 TRACE("%s %ld %ld %p\n", debugstr_a(lpName),
1539 nMaxMessageSize, lReadTimeout, sa);
1543 len = MultiByteToWideChar( CP_ACP, 0, lpName, -1, NULL, 0 );
1544 name = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
1545 MultiByteToWideChar( CP_ACP, 0, lpName, -1, name, len );
1548 handle = CreateMailslotW( name, nMaxMessageSize, lReadTimeout, sa );
1550 HeapFree( GetProcessHeap(), 0, name );
1556 /******************************************************************************
1557 * CreateMailslotW [KERNEL32.@]
1559 * Create a mailslot with specified name.
1562 * lpName [I] Pointer to string for mailslot name
1563 * nMaxMessageSize [I] Maximum message size
1564 * lReadTimeout [I] Milliseconds before read time-out
1565 * sa [I] Pointer to security structure
1568 * Success: Handle to mailslot
1569 * Failure: INVALID_HANDLE_VALUE
1571 HANDLE WINAPI CreateMailslotW( LPCWSTR lpName, DWORD nMaxMessageSize,
1572 DWORD lReadTimeout, LPSECURITY_ATTRIBUTES sa )
1574 FIXME("(%s,%ld,%ld,%p): stub\n", debugstr_w(lpName),
1575 nMaxMessageSize, lReadTimeout, sa);
1576 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1577 return INVALID_HANDLE_VALUE;
1581 /******************************************************************************
1582 * GetMailslotInfo [KERNEL32.@]
1584 * Retrieve information about a mailslot.
1587 * hMailslot [I] Mailslot handle
1588 * lpMaxMessageSize [O] Address of maximum message size
1589 * lpNextSize [O] Address of size of next message
1590 * lpMessageCount [O] Address of number of messages
1591 * lpReadTimeout [O] Address of read time-out
1597 BOOL WINAPI GetMailslotInfo( HANDLE hMailslot, LPDWORD lpMaxMessageSize,
1598 LPDWORD lpNextSize, LPDWORD lpMessageCount,
1599 LPDWORD lpReadTimeout )
1601 FIXME("(%p): stub\n",hMailslot);
1602 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1607 /******************************************************************************
1608 * SetMailslotInfo [KERNEL32.@]
1610 * Set the read timeout of a mailslot.
1613 * hMailslot [I] Mailslot handle
1614 * dwReadTimeout [I] Timeout in milliseconds.
1620 BOOL WINAPI SetMailslotInfo( HANDLE hMailslot, DWORD dwReadTimeout)
1622 FIXME("%p %ld: stub\n", hMailslot, dwReadTimeout);
1623 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1628 /******************************************************************************
1629 * CreateIoCompletionPort (KERNEL32.@)
1631 HANDLE WINAPI CreateIoCompletionPort(HANDLE hFileHandle, HANDLE hExistingCompletionPort,
1632 ULONG_PTR CompletionKey, DWORD dwNumberOfConcurrentThreads)
1634 FIXME("(%p, %p, %08lx, %08lx): stub.\n",
1635 hFileHandle, hExistingCompletionPort, CompletionKey, dwNumberOfConcurrentThreads);
1640 /******************************************************************************
1641 * GetQueuedCompletionStatus (KERNEL32.@)
1643 BOOL WINAPI GetQueuedCompletionStatus( HANDLE CompletionPort, LPDWORD lpNumberOfBytesTransferred,
1644 PULONG_PTR pCompletionKey, LPOVERLAPPED *lpOverlapped,
1645 DWORD dwMilliseconds )
1647 FIXME("(%p,%p,%p,%p,%ld), stub!\n",
1648 CompletionPort,lpNumberOfBytesTransferred,pCompletionKey,lpOverlapped,dwMilliseconds);
1649 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1653 /******************************************************************************
1654 * CreateJobObjectW (KERNEL32.@)
1656 HANDLE WINAPI CreateJobObjectW( LPSECURITY_ATTRIBUTES attr, LPCWSTR name )
1658 FIXME("%p %s\n", attr, debugstr_w(name) );
1659 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1663 /******************************************************************************
1664 * CreateJobObjectA (KERNEL32.@)
1666 HANDLE WINAPI CreateJobObjectA( LPSECURITY_ATTRIBUTES attr, LPCSTR name )
1672 TRACE("%p %s\n", attr, debugstr_a(name) );
1676 len = MultiByteToWideChar( CP_ACP, 0, name, -1, NULL, 0 );
1677 str = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
1680 SetLastError( ERROR_OUTOFMEMORY );
1683 len = MultiByteToWideChar( CP_ACP, 0, name, -1, str, len );
1686 r = CreateJobObjectW( attr, str );
1688 HeapFree( GetProcessHeap(), 0, str );
1693 /******************************************************************************
1694 * AssignProcessToJobObject (KERNEL32.@)
1696 BOOL WINAPI AssignProcessToJobObject( HANDLE hJob, HANDLE hProcess )
1698 FIXME("%p %p\n", hJob, hProcess);
1704 /***********************************************************************
1705 * InterlockedCompareExchange (KERNEL32.@)
1707 /* LONG WINAPI InterlockedCompareExchange( PLONG dest, LONG xchg, LONG compare ); */
1708 __ASM_GLOBAL_FUNC(InterlockedCompareExchange,
1709 "movl 12(%esp),%eax\n\t"
1710 "movl 8(%esp),%ecx\n\t"
1711 "movl 4(%esp),%edx\n\t"
1712 "lock; cmpxchgl %ecx,(%edx)\n\t"
1715 /***********************************************************************
1716 * InterlockedExchange (KERNEL32.@)
1718 /* LONG WINAPI InterlockedExchange( PLONG dest, LONG val ); */
1719 __ASM_GLOBAL_FUNC(InterlockedExchange,
1720 "movl 8(%esp),%eax\n\t"
1721 "movl 4(%esp),%edx\n\t"
1722 "lock; xchgl %eax,(%edx)\n\t"
1725 /***********************************************************************
1726 * InterlockedExchangeAdd (KERNEL32.@)
1728 /* LONG WINAPI InterlockedExchangeAdd( PLONG dest, LONG incr ); */
1729 __ASM_GLOBAL_FUNC(InterlockedExchangeAdd,
1730 "movl 8(%esp),%eax\n\t"
1731 "movl 4(%esp),%edx\n\t"
1732 "lock; xaddl %eax,(%edx)\n\t"
1735 /***********************************************************************
1736 * InterlockedIncrement (KERNEL32.@)
1738 /* LONG WINAPI InterlockedIncrement( PLONG dest ); */
1739 __ASM_GLOBAL_FUNC(InterlockedIncrement,
1740 "movl 4(%esp),%edx\n\t"
1742 "lock; xaddl %eax,(%edx)\n\t"
1746 /***********************************************************************
1747 * InterlockedDecrement (KERNEL32.@)
1749 __ASM_GLOBAL_FUNC(InterlockedDecrement,
1750 "movl 4(%esp),%edx\n\t"
1752 "lock; xaddl %eax,(%edx)\n\t"
1756 #else /* __i386__ */
1758 /***********************************************************************
1759 * InterlockedCompareExchange (KERNEL32.@)
1761 * Atomically swap one value with another.
1764 * dest [I/O] The value to replace
1765 * xchq [I] The value to be swapped
1766 * compare [I] The value to compare to dest
1769 * The resulting value of dest.
1772 * dest is updated only if it is equal to compare, otherwise no swap is done.
1774 LONG WINAPI InterlockedCompareExchange( PLONG dest, LONG xchg, LONG compare )
1776 return interlocked_cmpxchg( dest, xchg, compare );
1779 /***********************************************************************
1780 * InterlockedExchange (KERNEL32.@)
1782 * Atomically swap one value with another.
1785 * dest [I/O] The value to replace
1786 * val [I] The value to be swapped
1789 * The resulting value of dest.
1791 LONG WINAPI InterlockedExchange( PLONG dest, LONG val )
1793 return interlocked_xchg( dest, val );
1796 /***********************************************************************
1797 * InterlockedExchangeAdd (KERNEL32.@)
1799 * Atomically add one value to another.
1802 * dest [I/O] The value to add to
1803 * incr [I] The value to be added
1806 * The resulting value of dest.
1808 LONG WINAPI InterlockedExchangeAdd( PLONG dest, LONG incr )
1810 return interlocked_xchg_add( dest, incr );
1813 /***********************************************************************
1814 * InterlockedIncrement (KERNEL32.@)
1816 * Atomically increment a value.
1819 * dest [I/O] The value to increment
1822 * The resulting value of dest.
1824 LONG WINAPI InterlockedIncrement( PLONG dest )
1826 return interlocked_xchg_add( dest, 1 ) + 1;
1829 /***********************************************************************
1830 * InterlockedDecrement (KERNEL32.@)
1832 * Atomically decrement a value.
1835 * dest [I/O] The value to decrement
1838 * The resulting value of dest.
1840 LONG WINAPI InterlockedDecrement( PLONG dest )
1842 return interlocked_xchg_add( dest, -1 ) - 1;
1845 #endif /* __i386__ */