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 * WaitForSingleObject (KERNEL32.@)
97 DWORD WINAPI
WaitForSingleObject( HANDLE handle
, DWORD timeout
)
99 return WaitForMultipleObjectsEx( 1, &handle
, FALSE
, timeout
, FALSE
);
103 /***********************************************************************
104 * WaitForSingleObjectEx (KERNEL32.@)
106 DWORD WINAPI
WaitForSingleObjectEx( HANDLE handle
, DWORD timeout
,
109 return WaitForMultipleObjectsEx( 1, &handle
, FALSE
, timeout
, alertable
);
113 /***********************************************************************
114 * WaitForMultipleObjects (KERNEL32.@)
116 DWORD WINAPI
WaitForMultipleObjects( DWORD count
, const HANDLE
*handles
,
117 BOOL wait_all
, DWORD timeout
)
119 return WaitForMultipleObjectsEx( count
, handles
, wait_all
, timeout
, FALSE
);
123 /***********************************************************************
124 * WaitForMultipleObjectsEx (KERNEL32.@)
126 DWORD WINAPI
WaitForMultipleObjectsEx( DWORD count
, const HANDLE
*handles
,
127 BOOL wait_all
, DWORD timeout
,
131 HANDLE hloc
[MAXIMUM_WAIT_OBJECTS
];
134 if (count
>= MAXIMUM_WAIT_OBJECTS
)
136 SetLastError(ERROR_INVALID_PARAMETER
);
139 for (i
= 0; i
< count
; i
++)
141 if ((handles
[i
] == (HANDLE
)STD_INPUT_HANDLE
) ||
142 (handles
[i
] == (HANDLE
)STD_OUTPUT_HANDLE
) ||
143 (handles
[i
] == (HANDLE
)STD_ERROR_HANDLE
))
144 hloc
[i
] = GetStdHandle( (DWORD
)handles
[i
] );
146 hloc
[i
] = handles
[i
];
148 /* yes, even screen buffer console handles are waitable, and are
149 * handled as a handle to the console itself !!
151 if (is_console_handle(hloc
[i
]))
153 if (!VerifyConsoleIoHandle(hloc
[i
]))
157 hloc
[i
] = GetConsoleInputWaitHandle();
161 if (timeout
== INFINITE
)
163 status
= NtWaitForMultipleObjects( count
, hloc
, wait_all
, alertable
, NULL
);
169 time
.QuadPart
= timeout
* (ULONGLONG
)10000;
170 time
.QuadPart
= -time
.QuadPart
;
171 status
= NtWaitForMultipleObjects( count
, hloc
, wait_all
, alertable
, &time
);
174 if (HIWORD(status
)) /* is it an error code? */
176 SetLastError( RtlNtStatusToDosError(status
) );
177 status
= WAIT_FAILED
;
183 /***********************************************************************
184 * WaitForSingleObject (KERNEL.460)
186 DWORD WINAPI
WaitForSingleObject16( HANDLE handle
, DWORD timeout
)
188 DWORD retval
, mutex_count
;
190 ReleaseThunkLock( &mutex_count
);
191 retval
= WaitForSingleObject( handle
, timeout
);
192 RestoreThunkLock( mutex_count
);
196 /***********************************************************************
197 * WaitForMultipleObjects (KERNEL.461)
199 DWORD WINAPI
WaitForMultipleObjects16( DWORD count
, const HANDLE
*handles
,
200 BOOL wait_all
, DWORD timeout
)
202 DWORD retval
, mutex_count
;
204 ReleaseThunkLock( &mutex_count
);
205 retval
= WaitForMultipleObjectsEx( count
, handles
, wait_all
, timeout
, FALSE
);
206 RestoreThunkLock( mutex_count
);
210 /***********************************************************************
211 * WaitForMultipleObjectsEx (KERNEL.495)
213 DWORD WINAPI
WaitForMultipleObjectsEx16( DWORD count
, const HANDLE
*handles
,
214 BOOL wait_all
, DWORD timeout
, BOOL alertable
)
216 DWORD retval
, mutex_count
;
218 ReleaseThunkLock( &mutex_count
);
219 retval
= WaitForMultipleObjectsEx( count
, handles
, wait_all
, timeout
, alertable
);
220 RestoreThunkLock( mutex_count
);
224 /***********************************************************************
225 * RegisterWaitForSingleObject (KERNEL32.@)
227 BOOL WINAPI
RegisterWaitForSingleObject(PHANDLE phNewWaitObject
, HANDLE hObject
,
228 WAITORTIMERCALLBACK Callback
, PVOID Context
,
229 ULONG dwMilliseconds
, ULONG dwFlags
)
231 FIXME("%p %p %p %p %ld %ld\n",
232 phNewWaitObject
,hObject
,Callback
,Context
,dwMilliseconds
,dwFlags
);
236 /***********************************************************************
237 * RegisterWaitForSingleObjectEx (KERNEL32.@)
239 HANDLE WINAPI
RegisterWaitForSingleObjectEx( HANDLE hObject
,
240 WAITORTIMERCALLBACK Callback
, PVOID Context
,
241 ULONG dwMilliseconds
, ULONG dwFlags
)
243 FIXME("%p %p %p %ld %ld\n",
244 hObject
,Callback
,Context
,dwMilliseconds
,dwFlags
);
248 /***********************************************************************
249 * UnregisterWait (KERNEL32.@)
251 BOOL WINAPI
UnregisterWait( HANDLE WaitHandle
)
253 FIXME("%p\n",WaitHandle
);
257 /***********************************************************************
258 * UnregisterWaitEx (KERNEL32.@)
260 BOOL WINAPI
UnregisterWaitEx( HANDLE WaitHandle
, HANDLE CompletionEvent
)
262 FIXME("%p %p\n",WaitHandle
, CompletionEvent
);
266 /***********************************************************************
267 * SignalObjectAndWait (KERNEL32.@)
269 * Allows to atomically signal any of the synchro objects (semaphore,
270 * mutex, event) and wait on another.
272 DWORD WINAPI
SignalObjectAndWait( HANDLE hObjectToSignal
, HANDLE hObjectToWaitOn
, DWORD dwMilliseconds
, BOOL bAlertable
)
274 FIXME("(%p %p %ld %d): stub\n", hObjectToSignal
, hObjectToWaitOn
, dwMilliseconds
, bAlertable
);
275 return WAIT_OBJECT_0
;
279 /***********************************************************************
280 * InitializeCriticalSection (KERNEL32.@)
282 * Initialise a critical section before use.
285 * crit [O] Critical section to initialise.
288 * Nothing. If the function fails an exception is raised.
290 void WINAPI
InitializeCriticalSection( CRITICAL_SECTION
*crit
)
292 NTSTATUS ret
= RtlInitializeCriticalSection( crit
);
293 if (ret
) RtlRaiseStatus( ret
);
296 /***********************************************************************
297 * InitializeCriticalSectionAndSpinCount (KERNEL32.@)
299 * Initialise a critical section with a spin count.
302 * crit [O] Critical section to initialise.
303 * spincount [I] Number of times to spin upon contention.
307 * Failure: Nothing. If the function fails an exception is raised.
310 * spincount is ignored on uni-processor systems.
312 BOOL WINAPI
InitializeCriticalSectionAndSpinCount( CRITICAL_SECTION
*crit
, DWORD spincount
)
314 NTSTATUS ret
= RtlInitializeCriticalSectionAndSpinCount( crit
, spincount
);
315 if (ret
) RtlRaiseStatus( ret
);
319 /***********************************************************************
320 * MakeCriticalSectionGlobal (KERNEL32.@)
322 void WINAPI
MakeCriticalSectionGlobal( CRITICAL_SECTION
*crit
)
324 /* let's assume that only one thread at a time will try to do this */
325 HANDLE sem
= crit
->LockSemaphore
;
326 if (!sem
) NtCreateSemaphore( &sem
, SEMAPHORE_ALL_ACCESS
, NULL
, 0, 1 );
327 crit
->LockSemaphore
= ConvertToGlobalHandle( sem
);
330 RtlFreeHeap( GetProcessHeap(), 0, crit
->DebugInfo
);
331 crit
->DebugInfo
= NULL
;
336 /***********************************************************************
337 * ReinitializeCriticalSection (KERNEL32.@)
339 * Initialise an already used critical section.
342 * crit [O] Critical section to initialise.
347 void WINAPI
ReinitializeCriticalSection( CRITICAL_SECTION
*crit
)
349 if ( !crit
->LockSemaphore
)
350 RtlInitializeCriticalSection( crit
);
354 /***********************************************************************
355 * UninitializeCriticalSection (KERNEL32.@)
357 * UnInitialise a critical section after use.
360 * crit [O] Critical section to uninitialise (destroy).
365 void WINAPI
UninitializeCriticalSection( CRITICAL_SECTION
*crit
)
367 RtlDeleteCriticalSection( crit
);
371 /***********************************************************************
372 * CreateEventA (KERNEL32.@)
374 HANDLE WINAPI
CreateEventA( SECURITY_ATTRIBUTES
*sa
, BOOL manual_reset
,
375 BOOL initial_state
, LPCSTR name
)
377 WCHAR buffer
[MAX_PATH
];
379 if (!name
) return CreateEventW( sa
, manual_reset
, initial_state
, NULL
);
381 if (!MultiByteToWideChar( CP_ACP
, 0, name
, -1, buffer
, MAX_PATH
))
383 SetLastError( ERROR_FILENAME_EXCED_RANGE
);
386 return CreateEventW( sa
, manual_reset
, initial_state
, buffer
);
390 /***********************************************************************
391 * CreateEventW (KERNEL32.@)
393 HANDLE WINAPI
CreateEventW( SECURITY_ATTRIBUTES
*sa
, BOOL manual_reset
,
394 BOOL initial_state
, LPCWSTR name
)
397 DWORD len
= name
? strlenW(name
) : 0;
400 SetLastError( ERROR_FILENAME_EXCED_RANGE
);
403 /* one buggy program needs this
404 * ("Van Dale Groot woordenboek der Nederlandse taal")
406 if (sa
&& IsBadReadPtr(sa
,sizeof(SECURITY_ATTRIBUTES
)))
408 ERR("Bad security attributes pointer %p\n",sa
);
409 SetLastError( ERROR_INVALID_PARAMETER
);
412 SERVER_START_REQ( create_event
)
414 req
->manual_reset
= manual_reset
;
415 req
->initial_state
= initial_state
;
416 req
->inherit
= (sa
&& (sa
->nLength
>=sizeof(*sa
)) && sa
->bInheritHandle
);
417 wine_server_add_data( req
, name
, len
* sizeof(WCHAR
) );
419 wine_server_call_err( req
);
427 /***********************************************************************
428 * CreateW32Event (KERNEL.457)
430 HANDLE WINAPI
WIN16_CreateEvent( BOOL manual_reset
, BOOL initial_state
)
432 return CreateEventA( NULL
, manual_reset
, initial_state
, NULL
);
436 /***********************************************************************
437 * OpenEventA (KERNEL32.@)
439 HANDLE WINAPI
OpenEventA( DWORD access
, BOOL inherit
, LPCSTR name
)
441 WCHAR buffer
[MAX_PATH
];
443 if (!name
) return OpenEventW( access
, inherit
, NULL
);
445 if (!MultiByteToWideChar( CP_ACP
, 0, name
, -1, buffer
, MAX_PATH
))
447 SetLastError( ERROR_FILENAME_EXCED_RANGE
);
450 return OpenEventW( access
, inherit
, buffer
);
454 /***********************************************************************
455 * OpenEventW (KERNEL32.@)
457 HANDLE WINAPI
OpenEventW( DWORD access
, BOOL inherit
, LPCWSTR name
)
460 DWORD len
= name
? strlenW(name
) : 0;
463 SetLastError( ERROR_FILENAME_EXCED_RANGE
);
466 if (!is_version_nt()) access
= EVENT_ALL_ACCESS
;
468 SERVER_START_REQ( open_event
)
470 req
->access
= access
;
471 req
->inherit
= inherit
;
472 wine_server_add_data( req
, name
, len
* sizeof(WCHAR
) );
473 wine_server_call_err( req
);
480 /***********************************************************************
481 * PulseEvent (KERNEL32.@)
483 BOOL WINAPI
PulseEvent( HANDLE handle
)
487 if ((status
= NtPulseEvent( handle
, NULL
)))
488 SetLastError( RtlNtStatusToDosError(status
) );
493 /***********************************************************************
494 * SetW32Event (KERNEL.458)
495 * SetEvent (KERNEL32.@)
497 BOOL WINAPI
SetEvent( HANDLE handle
)
501 if ((status
= NtSetEvent( handle
, NULL
)))
502 SetLastError( RtlNtStatusToDosError(status
) );
507 /***********************************************************************
508 * ResetW32Event (KERNEL.459)
509 * ResetEvent (KERNEL32.@)
511 BOOL WINAPI
ResetEvent( HANDLE handle
)
515 if ((status
= NtResetEvent( handle
, NULL
)))
516 SetLastError( RtlNtStatusToDosError(status
) );
521 /***********************************************************************
522 * NOTE: The Win95 VWin32_Event routines given below are really low-level
523 * routines implemented directly by VWin32. The user-mode libraries
524 * implement Win32 synchronisation routines on top of these low-level
525 * primitives. We do it the other way around here :-)
528 /***********************************************************************
529 * VWin32_EventCreate (KERNEL.442)
531 HANDLE WINAPI
VWin32_EventCreate(VOID
)
533 HANDLE hEvent
= CreateEventA( NULL
, FALSE
, 0, NULL
);
534 return ConvertToGlobalHandle( hEvent
);
537 /***********************************************************************
538 * VWin32_EventDestroy (KERNEL.443)
540 VOID WINAPI
VWin32_EventDestroy(HANDLE event
)
542 CloseHandle( event
);
545 /***********************************************************************
546 * VWin32_EventWait (KERNEL.450)
548 VOID WINAPI
VWin32_EventWait(HANDLE event
)
552 ReleaseThunkLock( &mutex_count
);
553 WaitForSingleObject( event
, INFINITE
);
554 RestoreThunkLock( mutex_count
);
557 /***********************************************************************
558 * VWin32_EventSet (KERNEL.451)
559 * KERNEL_479 (KERNEL.479)
561 VOID WINAPI
VWin32_EventSet(HANDLE event
)
568 /***********************************************************************
569 * CreateMutexA (KERNEL32.@)
571 HANDLE WINAPI
CreateMutexA( SECURITY_ATTRIBUTES
*sa
, BOOL owner
, LPCSTR name
)
573 WCHAR buffer
[MAX_PATH
];
575 if (!name
) return CreateMutexW( sa
, owner
, NULL
);
577 if (!MultiByteToWideChar( CP_ACP
, 0, name
, -1, buffer
, MAX_PATH
))
579 SetLastError( ERROR_FILENAME_EXCED_RANGE
);
582 return CreateMutexW( sa
, owner
, buffer
);
586 /***********************************************************************
587 * CreateMutexW (KERNEL32.@)
589 HANDLE WINAPI
CreateMutexW( SECURITY_ATTRIBUTES
*sa
, BOOL owner
, LPCWSTR name
)
592 DWORD len
= name
? strlenW(name
) : 0;
595 SetLastError( ERROR_FILENAME_EXCED_RANGE
);
598 SERVER_START_REQ( create_mutex
)
601 req
->inherit
= (sa
&& (sa
->nLength
>=sizeof(*sa
)) && sa
->bInheritHandle
);
602 wine_server_add_data( req
, name
, len
* sizeof(WCHAR
) );
604 wine_server_call_err( req
);
612 /***********************************************************************
613 * OpenMutexA (KERNEL32.@)
615 HANDLE WINAPI
OpenMutexA( DWORD access
, BOOL inherit
, LPCSTR name
)
617 WCHAR buffer
[MAX_PATH
];
619 if (!name
) return OpenMutexW( access
, inherit
, NULL
);
621 if (!MultiByteToWideChar( CP_ACP
, 0, name
, -1, buffer
, MAX_PATH
))
623 SetLastError( ERROR_FILENAME_EXCED_RANGE
);
626 return OpenMutexW( access
, inherit
, buffer
);
630 /***********************************************************************
631 * OpenMutexW (KERNEL32.@)
633 HANDLE WINAPI
OpenMutexW( DWORD access
, BOOL inherit
, LPCWSTR name
)
636 DWORD len
= name
? strlenW(name
) : 0;
639 SetLastError( ERROR_FILENAME_EXCED_RANGE
);
642 if (!is_version_nt()) access
= MUTEX_ALL_ACCESS
;
644 SERVER_START_REQ( open_mutex
)
646 req
->access
= access
;
647 req
->inherit
= inherit
;
648 wine_server_add_data( req
, name
, len
* sizeof(WCHAR
) );
649 wine_server_call_err( req
);
657 /***********************************************************************
658 * ReleaseMutex (KERNEL32.@)
660 BOOL WINAPI
ReleaseMutex( HANDLE handle
)
663 SERVER_START_REQ( release_mutex
)
665 req
->handle
= handle
;
666 ret
= !wine_server_call_err( req
);
678 /***********************************************************************
679 * CreateSemaphoreA (KERNEL32.@)
681 HANDLE WINAPI
CreateSemaphoreA( SECURITY_ATTRIBUTES
*sa
, LONG initial
, LONG max
, LPCSTR name
)
683 WCHAR buffer
[MAX_PATH
];
685 if (!name
) return CreateSemaphoreW( sa
, initial
, max
, NULL
);
687 if (!MultiByteToWideChar( CP_ACP
, 0, name
, -1, buffer
, MAX_PATH
))
689 SetLastError( ERROR_FILENAME_EXCED_RANGE
);
692 return CreateSemaphoreW( sa
, initial
, max
, buffer
);
696 /***********************************************************************
697 * CreateSemaphoreW (KERNEL32.@)
699 HANDLE WINAPI
CreateSemaphoreW( SECURITY_ATTRIBUTES
*sa
, LONG initial
,
700 LONG max
, LPCWSTR name
)
703 DWORD len
= name
? strlenW(name
) : 0;
705 /* Check parameters */
707 if ((max
<= 0) || (initial
< 0) || (initial
> max
))
709 SetLastError( ERROR_INVALID_PARAMETER
);
714 SetLastError( ERROR_FILENAME_EXCED_RANGE
);
718 SERVER_START_REQ( create_semaphore
)
720 req
->initial
= (unsigned int)initial
;
721 req
->max
= (unsigned int)max
;
722 req
->inherit
= (sa
&& (sa
->nLength
>=sizeof(*sa
)) && sa
->bInheritHandle
);
723 wine_server_add_data( req
, name
, len
* sizeof(WCHAR
) );
725 wine_server_call_err( req
);
733 /***********************************************************************
734 * OpenSemaphoreA (KERNEL32.@)
736 HANDLE WINAPI
OpenSemaphoreA( DWORD access
, BOOL inherit
, LPCSTR name
)
738 WCHAR buffer
[MAX_PATH
];
740 if (!name
) return OpenSemaphoreW( access
, inherit
, NULL
);
742 if (!MultiByteToWideChar( CP_ACP
, 0, name
, -1, buffer
, MAX_PATH
))
744 SetLastError( ERROR_FILENAME_EXCED_RANGE
);
747 return OpenSemaphoreW( access
, inherit
, buffer
);
751 /***********************************************************************
752 * OpenSemaphoreW (KERNEL32.@)
754 HANDLE WINAPI
OpenSemaphoreW( DWORD access
, BOOL inherit
, LPCWSTR name
)
757 DWORD len
= name
? strlenW(name
) : 0;
760 SetLastError( ERROR_FILENAME_EXCED_RANGE
);
763 if (!is_version_nt()) access
= SEMAPHORE_ALL_ACCESS
;
765 SERVER_START_REQ( open_semaphore
)
767 req
->access
= access
;
768 req
->inherit
= inherit
;
769 wine_server_add_data( req
, name
, len
* sizeof(WCHAR
) );
770 wine_server_call_err( req
);
778 /***********************************************************************
779 * ReleaseSemaphore (KERNEL32.@)
781 BOOL WINAPI
ReleaseSemaphore( HANDLE handle
, LONG count
, LONG
*previous
)
783 NTSTATUS status
= NtReleaseSemaphore( handle
, count
, previous
);
784 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
794 /***********************************************************************
795 * CreateWaitableTimerA (KERNEL32.@)
797 HANDLE WINAPI
CreateWaitableTimerA( SECURITY_ATTRIBUTES
*sa
, BOOL manual
, LPCSTR name
)
799 WCHAR buffer
[MAX_PATH
];
801 if (!name
) return CreateWaitableTimerW( sa
, manual
, NULL
);
803 if (!MultiByteToWideChar( CP_ACP
, 0, name
, -1, buffer
, MAX_PATH
))
805 SetLastError( ERROR_FILENAME_EXCED_RANGE
);
808 return CreateWaitableTimerW( sa
, manual
, buffer
);
812 /***********************************************************************
813 * CreateWaitableTimerW (KERNEL32.@)
815 HANDLE WINAPI
CreateWaitableTimerW( SECURITY_ATTRIBUTES
*sa
, BOOL manual
, LPCWSTR name
)
821 OBJECT_ATTRIBUTES oa
;
823 if (name
) RtlInitUnicodeString(&us
, name
);
824 if (sa
&& (sa
->nLength
>= sizeof(*sa
)) && sa
->bInheritHandle
)
826 InitializeObjectAttributes(&oa
, name
? &us
: NULL
, attr
,
827 NULL
/* FIXME */, NULL
/* FIXME */);
828 status
= NtCreateTimer(&handle
, TIMER_ALL_ACCESS
, &oa
,
829 manual
? NotificationTimer
: SynchronizationTimer
);
831 if (status
!= STATUS_SUCCESS
)
833 SetLastError( RtlNtStatusToDosError(status
) );
840 /***********************************************************************
841 * OpenWaitableTimerA (KERNEL32.@)
843 HANDLE WINAPI
OpenWaitableTimerA( DWORD access
, BOOL inherit
, LPCSTR name
)
845 WCHAR buffer
[MAX_PATH
];
847 if (!name
) return OpenWaitableTimerW( access
, inherit
, NULL
);
849 if (!MultiByteToWideChar( CP_ACP
, 0, name
, -1, buffer
, MAX_PATH
))
851 SetLastError( ERROR_FILENAME_EXCED_RANGE
);
854 return OpenWaitableTimerW( access
, inherit
, buffer
);
858 /***********************************************************************
859 * OpenWaitableTimerW (KERNEL32.@)
861 HANDLE WINAPI
OpenWaitableTimerW( DWORD access
, BOOL inherit
, LPCWSTR name
)
867 OBJECT_ATTRIBUTES oa
;
869 if (inherit
) attr
|= OBJ_INHERIT
;
871 if (name
) RtlInitUnicodeString(&us
, name
);
872 InitializeObjectAttributes(&oa
, name
? &us
: NULL
, attr
, NULL
/* FIXME */, NULL
/* FIXME */);
873 status
= NtOpenTimer(&handle
, access
, &oa
);
874 if (status
!= STATUS_SUCCESS
)
876 SetLastError( RtlNtStatusToDosError(status
) );
883 /***********************************************************************
884 * SetWaitableTimer (KERNEL32.@)
886 BOOL WINAPI
SetWaitableTimer( HANDLE handle
, const LARGE_INTEGER
*when
, LONG period
,
887 PTIMERAPCROUTINE callback
, LPVOID arg
, BOOL resume
)
889 NTSTATUS status
= NtSetTimer(handle
, when
, callback
, arg
, resume
, period
, NULL
);
891 if (status
!= STATUS_SUCCESS
)
893 SetLastError( RtlNtStatusToDosError(status
) );
894 if (status
!= STATUS_TIMER_RESUME_IGNORED
) return FALSE
;
900 /***********************************************************************
901 * CancelWaitableTimer (KERNEL32.@)
903 BOOL WINAPI
CancelWaitableTimer( HANDLE handle
)
907 status
= NtCancelTimer(handle
, NULL
);
908 if (status
!= STATUS_SUCCESS
)
910 SetLastError( RtlNtStatusToDosError(status
) );
917 /***********************************************************************
918 * CreateTimerQueue (KERNEL32.@)
920 HANDLE WINAPI
CreateTimerQueue(void)
923 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
928 /***********************************************************************
929 * DeleteTimerQueueEx (KERNEL32.@)
931 BOOL WINAPI
DeleteTimerQueueEx(HANDLE TimerQueue
, HANDLE CompletionEvent
)
933 FIXME("(%p, %p): stub\n", TimerQueue
, CompletionEvent
);
934 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
938 /***********************************************************************
939 * CreateTimerQueueTimer (KERNEL32.@)
941 * Creates a timer-queue timer. This timer expires at the specified due
942 * time (in ms), then after every specified period (in ms). When the timer
943 * expires, the callback function is called.
946 * nonzero on success or zero on faillure
951 BOOL WINAPI
CreateTimerQueueTimer( PHANDLE phNewTimer
, HANDLE TimerQueue
,
952 WAITORTIMERCALLBACK Callback
, PVOID Parameter
,
953 DWORD DueTime
, DWORD Period
, ULONG Flags
)
956 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
960 /***********************************************************************
961 * DeleteTimerQueueTimer (KERNEL32.@)
963 * Cancels a timer-queue timer.
966 * nonzero on success or zero on faillure
971 BOOL WINAPI
DeleteTimerQueueTimer( HANDLE TimerQueue
, HANDLE Timer
,
972 HANDLE CompletionEvent
)
975 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
985 /***********************************************************************
986 * CreateNamedPipeA (KERNEL32.@)
988 HANDLE WINAPI
CreateNamedPipeA( LPCSTR name
, DWORD dwOpenMode
,
989 DWORD dwPipeMode
, DWORD nMaxInstances
,
990 DWORD nOutBufferSize
, DWORD nInBufferSize
,
991 DWORD nDefaultTimeOut
, LPSECURITY_ATTRIBUTES attr
)
993 WCHAR buffer
[MAX_PATH
];
995 if (!name
) return CreateNamedPipeW( NULL
, dwOpenMode
, dwPipeMode
, nMaxInstances
,
996 nOutBufferSize
, nInBufferSize
, nDefaultTimeOut
, attr
);
998 if (!MultiByteToWideChar( CP_ACP
, 0, name
, -1, buffer
, MAX_PATH
))
1000 SetLastError( ERROR_FILENAME_EXCED_RANGE
);
1001 return INVALID_HANDLE_VALUE
;
1003 return CreateNamedPipeW( buffer
, dwOpenMode
, dwPipeMode
, nMaxInstances
,
1004 nOutBufferSize
, nInBufferSize
, nDefaultTimeOut
, attr
);
1008 /***********************************************************************
1009 * CreateNamedPipeW (KERNEL32.@)
1011 HANDLE WINAPI
CreateNamedPipeW( LPCWSTR name
, DWORD dwOpenMode
,
1012 DWORD dwPipeMode
, DWORD nMaxInstances
,
1013 DWORD nOutBufferSize
, DWORD nInBufferSize
,
1014 DWORD nDefaultTimeOut
, LPSECURITY_ATTRIBUTES attr
)
1017 UNICODE_STRING nt_name
;
1018 static const WCHAR leadin
[] = {'\\','?','?','\\','P','I','P','E','\\'};
1020 TRACE("(%s, %#08lx, %#08lx, %ld, %ld, %ld, %ld, %p)\n",
1021 debugstr_w(name
), dwOpenMode
, dwPipeMode
, nMaxInstances
,
1022 nOutBufferSize
, nInBufferSize
, nDefaultTimeOut
, attr
);
1024 if (!RtlDosPathNameToNtPathName_U( name
, &nt_name
, NULL
, NULL
))
1026 SetLastError( ERROR_PATH_NOT_FOUND
);
1027 return INVALID_HANDLE_VALUE
;
1029 if (nt_name
.Length
>= MAX_PATH
* sizeof(WCHAR
) )
1031 SetLastError( ERROR_FILENAME_EXCED_RANGE
);
1032 RtlFreeUnicodeString( &nt_name
);
1033 return INVALID_HANDLE_VALUE
;
1035 if (nt_name
.Length
< sizeof(leadin
) ||
1036 strncmpiW( nt_name
.Buffer
, leadin
, sizeof(leadin
)/sizeof(leadin
[0])))
1038 SetLastError( ERROR_INVALID_NAME
);
1039 RtlFreeUnicodeString( &nt_name
);
1040 return INVALID_HANDLE_VALUE
;
1042 SERVER_START_REQ( create_named_pipe
)
1044 req
->openmode
= dwOpenMode
;
1045 req
->pipemode
= dwPipeMode
;
1046 req
->maxinstances
= nMaxInstances
;
1047 req
->outsize
= nOutBufferSize
;
1048 req
->insize
= nInBufferSize
;
1049 req
->timeout
= nDefaultTimeOut
;
1050 req
->inherit
= (attr
&& (attr
->nLength
>=sizeof(*attr
)) && attr
->bInheritHandle
);
1051 wine_server_add_data( req
, nt_name
.Buffer
+ 4, nt_name
.Length
- 4*sizeof(WCHAR
) );
1053 if (!wine_server_call_err( req
)) ret
= reply
->handle
;
1054 else ret
= INVALID_HANDLE_VALUE
;
1057 RtlFreeUnicodeString( &nt_name
);
1062 /***********************************************************************
1063 * PeekNamedPipe (KERNEL32.@)
1065 BOOL WINAPI
PeekNamedPipe( HANDLE hPipe
, LPVOID lpvBuffer
, DWORD cbBuffer
,
1066 LPDWORD lpcbRead
, LPDWORD lpcbAvail
, LPDWORD lpcbMessage
)
1069 int avail
=0, fd
, ret
, flags
;
1071 ret
= wine_server_handle_to_fd( hPipe
, GENERIC_READ
, &fd
, &flags
);
1074 SetLastError( RtlNtStatusToDosError(ret
) );
1077 if (flags
& FD_FLAG_RECV_SHUTDOWN
)
1079 wine_server_release_fd( hPipe
, fd
);
1080 SetLastError ( ERROR_PIPE_NOT_CONNECTED
);
1084 if (ioctl(fd
,FIONREAD
, &avail
) != 0)
1086 TRACE("FIONREAD failed reason: %s\n",strerror(errno
));
1087 wine_server_release_fd( hPipe
, fd
);
1090 if (!avail
) /* check for closed pipe */
1092 struct pollfd pollfd
;
1094 pollfd
.events
= POLLIN
;
1096 switch (poll( &pollfd
, 1, 0 ))
1100 case 1: /* got something */
1101 if (!(pollfd
.revents
& (POLLHUP
| POLLERR
))) break;
1102 TRACE("POLLHUP | POLLERR\n");
1105 wine_server_release_fd( hPipe
, fd
);
1106 SetLastError(ERROR_BROKEN_PIPE
);
1110 TRACE(" 0x%08x bytes available\n", avail
);
1116 if (avail
&& lpvBuffer
)
1118 int readbytes
= (avail
< cbBuffer
) ? avail
: cbBuffer
;
1119 readbytes
= recv(fd
, lpvBuffer
, readbytes
, MSG_PEEK
);
1122 WARN("failed to peek socket (%d)\n", errno
);
1126 *lpcbRead
= readbytes
;
1128 wine_server_release_fd( hPipe
, fd
);
1130 #endif /* defined(FIONREAD) */
1132 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1133 FIXME("function not implemented\n");
1137 /***********************************************************************
1138 * SYNC_CompletePipeOverlapped (Internal)
1140 static void SYNC_CompletePipeOverlapped (LPOVERLAPPED overlapped
, DWORD result
)
1142 TRACE("for %p result %08lx\n",overlapped
,result
);
1145 overlapped
->Internal
= result
;
1146 SetEvent(overlapped
->hEvent
);
1150 /***********************************************************************
1151 * WaitNamedPipeA (KERNEL32.@)
1153 BOOL WINAPI
WaitNamedPipeA (LPCSTR name
, DWORD nTimeOut
)
1155 WCHAR buffer
[MAX_PATH
];
1157 if (!name
) return WaitNamedPipeW( NULL
, nTimeOut
);
1159 if (!MultiByteToWideChar( CP_ACP
, 0, name
, -1, buffer
, MAX_PATH
))
1161 SetLastError( ERROR_FILENAME_EXCED_RANGE
);
1164 return WaitNamedPipeW( buffer
, nTimeOut
);
1168 /***********************************************************************
1169 * WaitNamedPipeW (KERNEL32.@)
1171 BOOL WINAPI
WaitNamedPipeW (LPCWSTR name
, DWORD nTimeOut
)
1175 UNICODE_STRING nt_name
;
1176 static const WCHAR leadin
[] = {'\\','?','?','\\','P','I','P','E','\\'};
1178 TRACE("%s 0x%08lx\n",debugstr_w(name
),nTimeOut
);
1180 if (!RtlDosPathNameToNtPathName_U( name
, &nt_name
, NULL
, NULL
))
1183 if (nt_name
.Length
>= MAX_PATH
* sizeof(WCHAR
) )
1185 RtlFreeUnicodeString( &nt_name
);
1188 if (nt_name
.Length
< sizeof(leadin
) ||
1189 strncmpiW( nt_name
.Buffer
, leadin
, sizeof(leadin
)/sizeof(leadin
[0])))
1191 RtlFreeUnicodeString( &nt_name
);
1195 memset(&ov
,0,sizeof(ov
));
1196 ov
.hEvent
= CreateEventW( NULL
, 0, 0, NULL
);
1200 SERVER_START_REQ( wait_named_pipe
)
1202 req
->timeout
= nTimeOut
;
1203 req
->overlapped
= &ov
;
1204 req
->func
= SYNC_CompletePipeOverlapped
;
1205 wine_server_add_data( req
, nt_name
.Buffer
+ 4, nt_name
.Length
- 4*sizeof(WCHAR
) );
1206 ret
= !wine_server_call_err( req
);
1210 RtlFreeUnicodeString( &nt_name
);
1214 if (WAIT_OBJECT_0
==WaitForSingleObject(ov
.hEvent
,INFINITE
))
1216 SetLastError(ov
.Internal
);
1217 ret
= (ov
.Internal
==STATUS_SUCCESS
);
1220 CloseHandle(ov
.hEvent
);
1225 /***********************************************************************
1226 * SYNC_ConnectNamedPipe (Internal)
1228 static BOOL
SYNC_ConnectNamedPipe(HANDLE hPipe
, LPOVERLAPPED overlapped
)
1235 overlapped
->Internal
= STATUS_PENDING
;
1237 SERVER_START_REQ( connect_named_pipe
)
1239 req
->handle
= hPipe
;
1240 req
->overlapped
= overlapped
;
1241 req
->func
= SYNC_CompletePipeOverlapped
;
1242 ret
= !wine_server_call_err( req
);
1249 /***********************************************************************
1250 * ConnectNamedPipe (KERNEL32.@)
1252 BOOL WINAPI
ConnectNamedPipe(HANDLE hPipe
, LPOVERLAPPED overlapped
)
1257 TRACE("(%p,%p)\n",hPipe
, overlapped
);
1261 if(SYNC_ConnectNamedPipe(hPipe
,overlapped
))
1262 SetLastError( ERROR_IO_PENDING
);
1266 memset(&ov
,0,sizeof(ov
));
1267 ov
.hEvent
= CreateEventA(NULL
,0,0,NULL
);
1271 ret
=SYNC_ConnectNamedPipe(hPipe
, &ov
);
1274 if (WAIT_OBJECT_0
==WaitForSingleObject(ov
.hEvent
,INFINITE
))
1276 SetLastError(ov
.Internal
);
1277 ret
= (ov
.Internal
==STATUS_SUCCESS
);
1281 CloseHandle(ov
.hEvent
);
1286 /***********************************************************************
1287 * DisconnectNamedPipe (KERNEL32.@)
1289 BOOL WINAPI
DisconnectNamedPipe(HANDLE hPipe
)
1293 TRACE("(%p)\n",hPipe
);
1295 SERVER_START_REQ( disconnect_named_pipe
)
1297 req
->handle
= hPipe
;
1298 ret
= !wine_server_call_err( req
);
1299 if (ret
&& reply
->fd
!= -1) close( reply
->fd
);
1306 /***********************************************************************
1307 * TransactNamedPipe (KERNEL32.@)
1309 BOOL WINAPI
TransactNamedPipe(
1310 HANDLE hPipe
, LPVOID lpInput
, DWORD dwInputSize
, LPVOID lpOutput
,
1311 DWORD dwOutputSize
, LPDWORD lpBytesRead
, LPOVERLAPPED lpOverlapped
)
1313 FIXME("%p %p %ld %p %ld %p %p\n",
1314 hPipe
, lpInput
, dwInputSize
, lpOutput
,
1315 dwOutputSize
, lpBytesRead
, lpOverlapped
);
1321 /***********************************************************************
1322 * GetNamedPipeInfo (KERNEL32.@)
1324 BOOL WINAPI
GetNamedPipeInfo(
1325 HANDLE hNamedPipe
, LPDWORD lpFlags
, LPDWORD lpOutputBufferSize
,
1326 LPDWORD lpInputBufferSize
, LPDWORD lpMaxInstances
)
1330 TRACE("%p %p %p %p %p\n", hNamedPipe
, lpFlags
,
1331 lpOutputBufferSize
, lpInputBufferSize
, lpMaxInstances
);
1333 SERVER_START_REQ( get_named_pipe_info
)
1335 req
->handle
= hNamedPipe
;
1336 ret
= !wine_server_call_err( req
);
1337 if(lpFlags
) *lpFlags
= reply
->flags
;
1338 if(lpOutputBufferSize
) *lpOutputBufferSize
= reply
->outsize
;
1339 if(lpInputBufferSize
) *lpInputBufferSize
= reply
->outsize
;
1340 if(lpMaxInstances
) *lpMaxInstances
= reply
->maxinstances
;
1347 /***********************************************************************
1348 * GetNamedPipeHandleStateA (KERNEL32.@)
1350 BOOL WINAPI
GetNamedPipeHandleStateA(
1351 HANDLE hNamedPipe
, LPDWORD lpState
, LPDWORD lpCurInstances
,
1352 LPDWORD lpMaxCollectionCount
, LPDWORD lpCollectDataTimeout
,
1353 LPSTR lpUsername
, DWORD nUsernameMaxSize
)
1355 FIXME("%p %p %p %p %p %p %ld\n",
1356 hNamedPipe
, lpState
, lpCurInstances
,
1357 lpMaxCollectionCount
, lpCollectDataTimeout
,
1358 lpUsername
, nUsernameMaxSize
);
1363 /***********************************************************************
1364 * GetNamedPipeHandleStateW (KERNEL32.@)
1366 BOOL WINAPI
GetNamedPipeHandleStateW(
1367 HANDLE hNamedPipe
, LPDWORD lpState
, LPDWORD lpCurInstances
,
1368 LPDWORD lpMaxCollectionCount
, LPDWORD lpCollectDataTimeout
,
1369 LPWSTR lpUsername
, DWORD nUsernameMaxSize
)
1371 FIXME("%p %p %p %p %p %p %ld\n",
1372 hNamedPipe
, lpState
, lpCurInstances
,
1373 lpMaxCollectionCount
, lpCollectDataTimeout
,
1374 lpUsername
, nUsernameMaxSize
);
1379 /***********************************************************************
1380 * SetNamedPipeHandleState (KERNEL32.@)
1382 BOOL WINAPI
SetNamedPipeHandleState(
1383 HANDLE hNamedPipe
, LPDWORD lpMode
, LPDWORD lpMaxCollectionCount
,
1384 LPDWORD lpCollectDataTimeout
)
1386 FIXME("%p %p %p %p\n",
1387 hNamedPipe
, lpMode
, lpMaxCollectionCount
, lpCollectDataTimeout
);
1391 /***********************************************************************
1392 * CallNamedPipeA (KERNEL32.@)
1394 BOOL WINAPI
CallNamedPipeA(
1395 LPCSTR lpNamedPipeName
, LPVOID lpInput
, DWORD lpInputSize
,
1396 LPVOID lpOutput
, DWORD lpOutputSize
,
1397 LPDWORD lpBytesRead
, DWORD nTimeout
)
1399 FIXME("%s %p %ld %p %ld %p %ld\n",
1400 debugstr_a(lpNamedPipeName
), lpInput
, lpInputSize
,
1401 lpOutput
, lpOutputSize
, lpBytesRead
, nTimeout
);
1405 /***********************************************************************
1406 * CallNamedPipeW (KERNEL32.@)
1408 BOOL WINAPI
CallNamedPipeW(
1409 LPCWSTR lpNamedPipeName
, LPVOID lpInput
, DWORD lpInputSize
,
1410 LPVOID lpOutput
, DWORD lpOutputSize
,
1411 LPDWORD lpBytesRead
, DWORD nTimeout
)
1413 FIXME("%s %p %ld %p %ld %p %ld\n",
1414 debugstr_w(lpNamedPipeName
), lpInput
, lpInputSize
,
1415 lpOutput
, lpOutputSize
, lpBytesRead
, nTimeout
);
1419 /******************************************************************
1420 * CreatePipe (KERNEL32.@)
1423 BOOL WINAPI
CreatePipe( PHANDLE hReadPipe
, PHANDLE hWritePipe
,
1424 LPSECURITY_ATTRIBUTES sa
, DWORD size
)
1426 static unsigned index
= 0;
1429 unsigned in_index
= index
;
1431 *hReadPipe
= *hWritePipe
= INVALID_HANDLE_VALUE
;
1432 /* generate a unique pipe name (system wide) */
1435 sprintf(name
, "\\\\.\\pipe\\Win32.Pipes.%08lu.%08u", GetCurrentProcessId(), ++index
);
1436 hr
= CreateNamedPipeA(name
, PIPE_ACCESS_INBOUND
,
1437 PIPE_TYPE_BYTE
| PIPE_WAIT
, 1, size
, size
,
1438 NMPWAIT_USE_DEFAULT_WAIT
, sa
);
1439 } while (hr
== INVALID_HANDLE_VALUE
&& index
!= in_index
);
1440 /* from completion sakeness, I think system resources might be exhausted before this happens !! */
1441 if (hr
== INVALID_HANDLE_VALUE
) return FALSE
;
1443 hw
= CreateFileA(name
, GENERIC_WRITE
, 0, sa
, OPEN_EXISTING
, 0, 0);
1444 if (hw
== INVALID_HANDLE_VALUE
)
1456 /******************************************************************************
1457 * CreateMailslotA [KERNEL32.@]
1459 HANDLE WINAPI
CreateMailslotA( LPCSTR lpName
, DWORD nMaxMessageSize
,
1460 DWORD lReadTimeout
, LPSECURITY_ATTRIBUTES sa
)
1466 TRACE("%s %ld %ld %p\n", debugstr_a(lpName
),
1467 nMaxMessageSize
, lReadTimeout
, sa
);
1471 len
= MultiByteToWideChar( CP_ACP
, 0, lpName
, -1, NULL
, 0 );
1472 name
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
1473 MultiByteToWideChar( CP_ACP
, 0, lpName
, -1, name
, len
);
1476 handle
= CreateMailslotW( name
, nMaxMessageSize
, lReadTimeout
, sa
);
1479 HeapFree( GetProcessHeap(), 0, name
);
1485 /******************************************************************************
1486 * CreateMailslotW [KERNEL32.@]
1488 * Create a mailslot with specified name.
1491 * lpName [I] Pointer to string for mailslot name
1492 * nMaxMessageSize [I] Maximum message size
1493 * lReadTimeout [I] Milliseconds before read time-out
1494 * sa [I] Pointer to security structure
1497 * Success: Handle to mailslot
1498 * Failure: INVALID_HANDLE_VALUE
1500 HANDLE WINAPI
CreateMailslotW( LPCWSTR lpName
, DWORD nMaxMessageSize
,
1501 DWORD lReadTimeout
, LPSECURITY_ATTRIBUTES sa
)
1503 FIXME("(%s,%ld,%ld,%p): stub\n", debugstr_w(lpName
),
1504 nMaxMessageSize
, lReadTimeout
, sa
);
1505 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1506 return INVALID_HANDLE_VALUE
;
1510 /******************************************************************************
1511 * GetMailslotInfo [KERNEL32.@]
1513 * Retrieve information about a mailslot.
1516 * hMailslot [I] Mailslot handle
1517 * lpMaxMessageSize [O] Address of maximum message size
1518 * lpNextSize [O] Address of size of next message
1519 * lpMessageCount [O] Address of number of messages
1520 * lpReadTimeout [O] Address of read time-out
1526 BOOL WINAPI
GetMailslotInfo( HANDLE hMailslot
, LPDWORD lpMaxMessageSize
,
1527 LPDWORD lpNextSize
, LPDWORD lpMessageCount
,
1528 LPDWORD lpReadTimeout
)
1530 FIXME("(%p): stub\n",hMailslot
);
1531 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1536 /******************************************************************************
1537 * SetMailslotInfo [KERNEL32.@]
1539 * Set the read timeout of a mailslot.
1542 * hMailslot [I] Mailslot handle
1543 * dwReadTimeout [I] Timeout in milliseconds.
1549 BOOL WINAPI
SetMailslotInfo( HANDLE hMailslot
, DWORD dwReadTimeout
)
1551 FIXME("%p %ld: stub\n", hMailslot
, dwReadTimeout
);
1552 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1557 /******************************************************************************
1558 * CreateIoCompletionPort (KERNEL32.@)
1560 HANDLE WINAPI
CreateIoCompletionPort(HANDLE hFileHandle
, HANDLE hExistingCompletionPort
,
1561 DWORD dwCompletionKey
, DWORD dwNumberOfConcurrentThreads
)
1563 FIXME("(%p, %p, %08lx, %08lx): stub.\n",
1564 hFileHandle
, hExistingCompletionPort
, dwCompletionKey
, dwNumberOfConcurrentThreads
);
1569 /******************************************************************************
1570 * GetQueuedCompletionStatus (KERNEL32.@)
1572 BOOL WINAPI
GetQueuedCompletionStatus( HANDLE CompletionPort
, LPDWORD lpNumberOfBytesTransferred
,
1573 LPDWORD lpCompletionKey
, LPOVERLAPPED
*lpOverlapped
,
1574 DWORD dwMilliseconds
)
1576 FIXME("(%p,%p,%p,%p,%ld), stub!\n",
1577 CompletionPort
,lpNumberOfBytesTransferred
,lpCompletionKey
,lpOverlapped
,dwMilliseconds
);
1578 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1582 /******************************************************************************
1583 * CreateJobObjectW (KERNEL32.@)
1585 HANDLE WINAPI
CreateJobObjectW( LPSECURITY_ATTRIBUTES attr
, LPCWSTR name
)
1587 FIXME("%p %s\n", attr
, debugstr_w(name
) );
1588 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1592 /******************************************************************************
1593 * CreateJobObjectA (KERNEL32.@)
1595 HANDLE WINAPI
CreateJobObjectA( LPSECURITY_ATTRIBUTES attr
, LPCSTR name
)
1601 TRACE("%p %s\n", attr
, debugstr_a(name
) );
1605 len
= MultiByteToWideChar( CP_ACP
, 0, name
, -1, NULL
, 0 );
1606 str
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
1609 SetLastError( ERROR_OUTOFMEMORY
);
1612 len
= MultiByteToWideChar( CP_ACP
, 0, name
, -1, str
, len
);
1615 r
= CreateJobObjectW( attr
, str
);
1618 HeapFree( GetProcessHeap(), 0, str
);
1623 /******************************************************************************
1624 * AssignProcessToJobObject (KERNEL32.@)
1626 BOOL WINAPI
AssignProcessToJobObject( HANDLE hJob
, HANDLE hProcess
)
1628 FIXME("%p %p\n", hJob
, hProcess
);
1634 /***********************************************************************
1635 * InterlockedCompareExchange (KERNEL32.@)
1637 /* LONG WINAPI InterlockedCompareExchange( PLONG dest, LONG xchg, LONG compare ); */
1638 __ASM_GLOBAL_FUNC(InterlockedCompareExchange
,
1639 "movl 12(%esp),%eax\n\t"
1640 "movl 8(%esp),%ecx\n\t"
1641 "movl 4(%esp),%edx\n\t"
1642 "lock; cmpxchgl %ecx,(%edx)\n\t"
1645 /***********************************************************************
1646 * InterlockedExchange (KERNEL32.@)
1648 /* LONG WINAPI InterlockedExchange( PLONG dest, LONG val ); */
1649 __ASM_GLOBAL_FUNC(InterlockedExchange
,
1650 "movl 8(%esp),%eax\n\t"
1651 "movl 4(%esp),%edx\n\t"
1652 "lock; xchgl %eax,(%edx)\n\t"
1655 /***********************************************************************
1656 * InterlockedExchangeAdd (KERNEL32.@)
1658 /* LONG WINAPI InterlockedExchangeAdd( PLONG dest, LONG incr ); */
1659 __ASM_GLOBAL_FUNC(InterlockedExchangeAdd
,
1660 "movl 8(%esp),%eax\n\t"
1661 "movl 4(%esp),%edx\n\t"
1662 "lock; xaddl %eax,(%edx)\n\t"
1665 /***********************************************************************
1666 * InterlockedIncrement (KERNEL32.@)
1668 /* LONG WINAPI InterlockedIncrement( PLONG dest ); */
1669 __ASM_GLOBAL_FUNC(InterlockedIncrement
,
1670 "movl 4(%esp),%edx\n\t"
1672 "lock; xaddl %eax,(%edx)\n\t"
1676 /***********************************************************************
1677 * InterlockedDecrement (KERNEL32.@)
1679 __ASM_GLOBAL_FUNC(InterlockedDecrement
,
1680 "movl 4(%esp),%edx\n\t"
1682 "lock; xaddl %eax,(%edx)\n\t"
1686 #else /* __i386__ */
1688 /***********************************************************************
1689 * InterlockedCompareExchange (KERNEL32.@)
1691 * Atomically swap one value with another.
1694 * dest [I/O] The value to replace
1695 * xchq [I] The value to be swapped
1696 * compare [I] The value to compare to dest
1699 * The resulting value of dest.
1702 * dest is updated only if it is equal to compare, otherwise no swap is done.
1704 LONG WINAPI
InterlockedCompareExchange( PLONG dest
, LONG xchg
, LONG compare
)
1706 return interlocked_cmpxchg( dest
, xchg
, compare
);
1709 /***********************************************************************
1710 * InterlockedExchange (KERNEL32.@)
1712 * Atomically swap one value with another.
1715 * dest [I/O] The value to replace
1716 * val [I] The value to be swapped
1719 * The resulting value of dest.
1721 LONG WINAPI
InterlockedExchange( PLONG dest
, LONG val
)
1723 return interlocked_xchg( dest
, val
);
1726 /***********************************************************************
1727 * InterlockedExchangeAdd (KERNEL32.@)
1729 * Atomically add one value to another.
1732 * dest [I/O] The value to add to
1733 * incr [I] The value to be added
1736 * The resulting value of dest.
1738 LONG WINAPI
InterlockedExchangeAdd( PLONG dest
, LONG incr
)
1740 return interlocked_xchg_add( dest
, incr
);
1743 /***********************************************************************
1744 * InterlockedIncrement (KERNEL32.@)
1746 * Atomically increment a value.
1749 * dest [I/O] The value to increment
1752 * The resulting value of dest.
1754 LONG WINAPI
InterlockedIncrement( PLONG dest
)
1756 return interlocked_xchg_add( dest
, 1 ) + 1;
1759 /***********************************************************************
1760 * InterlockedDecrement (KERNEL32.@)
1762 * Atomically decrement a value.
1765 * dest [I/O] The value to decrement
1768 * The resulting value of dest.
1770 LONG WINAPI
InterlockedDecrement( PLONG dest
)
1772 return interlocked_xchg_add( dest
, -1 ) - 1;
1775 #endif /* __i386__ */