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 CreateEventA( 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
= CreateEventA( 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
= SEMAPHORE_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 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(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
= CreateEventA(NULL
,0,0,NULL
);
1308 ret
=SYNC_ConnectNamedPipe(hPipe
, &ov
);
1311 if (WAIT_OBJECT_0
==WaitForSingleObject(ov
.hEvent
,INFINITE
))
1313 SetLastError(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.@)
1346 BOOL WINAPI
TransactNamedPipe(
1347 HANDLE hPipe
, LPVOID lpInput
, DWORD dwInputSize
, LPVOID lpOutput
,
1348 DWORD dwOutputSize
, LPDWORD lpBytesRead
, LPOVERLAPPED lpOverlapped
)
1350 FIXME("%p %p %ld %p %ld %p %p\n",
1351 hPipe
, lpInput
, dwInputSize
, lpOutput
,
1352 dwOutputSize
, lpBytesRead
, lpOverlapped
);
1358 /***********************************************************************
1359 * GetNamedPipeInfo (KERNEL32.@)
1361 BOOL WINAPI
GetNamedPipeInfo(
1362 HANDLE hNamedPipe
, LPDWORD lpFlags
, LPDWORD lpOutputBufferSize
,
1363 LPDWORD lpInputBufferSize
, LPDWORD lpMaxInstances
)
1367 TRACE("%p %p %p %p %p\n", hNamedPipe
, lpFlags
,
1368 lpOutputBufferSize
, lpInputBufferSize
, lpMaxInstances
);
1370 SERVER_START_REQ( get_named_pipe_info
)
1372 req
->handle
= hNamedPipe
;
1373 ret
= !wine_server_call_err( req
);
1374 if(lpFlags
) *lpFlags
= reply
->flags
;
1375 if(lpOutputBufferSize
) *lpOutputBufferSize
= reply
->outsize
;
1376 if(lpInputBufferSize
) *lpInputBufferSize
= reply
->outsize
;
1377 if(lpMaxInstances
) *lpMaxInstances
= reply
->maxinstances
;
1384 /***********************************************************************
1385 * GetNamedPipeHandleStateA (KERNEL32.@)
1387 BOOL WINAPI
GetNamedPipeHandleStateA(
1388 HANDLE hNamedPipe
, LPDWORD lpState
, LPDWORD lpCurInstances
,
1389 LPDWORD lpMaxCollectionCount
, LPDWORD lpCollectDataTimeout
,
1390 LPSTR lpUsername
, DWORD nUsernameMaxSize
)
1392 FIXME("%p %p %p %p %p %p %ld\n",
1393 hNamedPipe
, lpState
, lpCurInstances
,
1394 lpMaxCollectionCount
, lpCollectDataTimeout
,
1395 lpUsername
, nUsernameMaxSize
);
1400 /***********************************************************************
1401 * GetNamedPipeHandleStateW (KERNEL32.@)
1403 BOOL WINAPI
GetNamedPipeHandleStateW(
1404 HANDLE hNamedPipe
, LPDWORD lpState
, LPDWORD lpCurInstances
,
1405 LPDWORD lpMaxCollectionCount
, LPDWORD lpCollectDataTimeout
,
1406 LPWSTR lpUsername
, DWORD nUsernameMaxSize
)
1408 FIXME("%p %p %p %p %p %p %ld\n",
1409 hNamedPipe
, lpState
, lpCurInstances
,
1410 lpMaxCollectionCount
, lpCollectDataTimeout
,
1411 lpUsername
, nUsernameMaxSize
);
1416 /***********************************************************************
1417 * SetNamedPipeHandleState (KERNEL32.@)
1419 BOOL WINAPI
SetNamedPipeHandleState(
1420 HANDLE hNamedPipe
, LPDWORD lpMode
, LPDWORD lpMaxCollectionCount
,
1421 LPDWORD lpCollectDataTimeout
)
1423 FIXME("%p %p %p %p\n",
1424 hNamedPipe
, lpMode
, lpMaxCollectionCount
, lpCollectDataTimeout
);
1428 /***********************************************************************
1429 * CallNamedPipeA (KERNEL32.@)
1431 BOOL WINAPI
CallNamedPipeA(
1432 LPCSTR lpNamedPipeName
, LPVOID lpInput
, DWORD dwInputSize
,
1433 LPVOID lpOutput
, DWORD dwOutputSize
,
1434 LPDWORD lpBytesRead
, DWORD nTimeout
)
1440 TRACE("%s %p %ld %p %ld %p %ld\n",
1441 debugstr_a(lpNamedPipeName
), lpInput
, dwInputSize
,
1442 lpOutput
, dwOutputSize
, lpBytesRead
, nTimeout
);
1444 if( lpNamedPipeName
)
1446 len
= MultiByteToWideChar( CP_ACP
, 0, lpNamedPipeName
, -1, NULL
, 0 );
1447 str
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
1448 MultiByteToWideChar( CP_ACP
, 0, lpNamedPipeName
, -1, str
, len
);
1450 ret
= CallNamedPipeW( str
, lpInput
, dwInputSize
, lpOutput
,
1451 dwOutputSize
, lpBytesRead
, nTimeout
);
1452 if( lpNamedPipeName
)
1453 HeapFree( GetProcessHeap(), 0, str
);
1458 /***********************************************************************
1459 * CallNamedPipeW (KERNEL32.@)
1461 BOOL WINAPI
CallNamedPipeW(
1462 LPCWSTR lpNamedPipeName
, LPVOID lpInput
, DWORD lpInputSize
,
1463 LPVOID lpOutput
, DWORD lpOutputSize
,
1464 LPDWORD lpBytesRead
, DWORD nTimeout
)
1466 FIXME("%s %p %ld %p %ld %p %ld\n",
1467 debugstr_w(lpNamedPipeName
), lpInput
, lpInputSize
,
1468 lpOutput
, lpOutputSize
, lpBytesRead
, nTimeout
);
1472 /******************************************************************
1473 * CreatePipe (KERNEL32.@)
1476 BOOL WINAPI
CreatePipe( PHANDLE hReadPipe
, PHANDLE hWritePipe
,
1477 LPSECURITY_ATTRIBUTES sa
, DWORD size
)
1479 static unsigned index
= 0;
1482 unsigned in_index
= index
;
1484 *hReadPipe
= *hWritePipe
= INVALID_HANDLE_VALUE
;
1485 /* generate a unique pipe name (system wide) */
1488 static const WCHAR nameFmt
[] = { '\\','\\','.','\\','p','i','p','e',
1489 '\\','W','i','n','3','2','.','P','i','p','e','s','.','%','0','8','l',
1490 'u','.','%','0','8','u','\0' };
1491 snprintfW(name
, sizeof(name
) / sizeof(name
[0]), nameFmt
,
1492 GetCurrentProcessId(), ++index
);
1493 hr
= CreateNamedPipeW(name
, PIPE_ACCESS_INBOUND
,
1494 PIPE_TYPE_BYTE
| PIPE_WAIT
, 1, size
, size
,
1495 NMPWAIT_USE_DEFAULT_WAIT
, sa
);
1496 } while (hr
== INVALID_HANDLE_VALUE
&& index
!= in_index
);
1497 /* from completion sakeness, I think system resources might be exhausted before this happens !! */
1498 if (hr
== INVALID_HANDLE_VALUE
) return FALSE
;
1500 hw
= CreateFileW(name
, GENERIC_WRITE
, 0, sa
, OPEN_EXISTING
, 0, 0);
1501 if (hw
== INVALID_HANDLE_VALUE
)
1513 /******************************************************************************
1514 * CreateMailslotA [KERNEL32.@]
1516 HANDLE WINAPI
CreateMailslotA( LPCSTR lpName
, DWORD nMaxMessageSize
,
1517 DWORD lReadTimeout
, LPSECURITY_ATTRIBUTES sa
)
1523 TRACE("%s %ld %ld %p\n", debugstr_a(lpName
),
1524 nMaxMessageSize
, lReadTimeout
, sa
);
1528 len
= MultiByteToWideChar( CP_ACP
, 0, lpName
, -1, NULL
, 0 );
1529 name
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
1530 MultiByteToWideChar( CP_ACP
, 0, lpName
, -1, name
, len
);
1533 handle
= CreateMailslotW( name
, nMaxMessageSize
, lReadTimeout
, sa
);
1536 HeapFree( GetProcessHeap(), 0, name
);
1542 /******************************************************************************
1543 * CreateMailslotW [KERNEL32.@]
1545 * Create a mailslot with specified name.
1548 * lpName [I] Pointer to string for mailslot name
1549 * nMaxMessageSize [I] Maximum message size
1550 * lReadTimeout [I] Milliseconds before read time-out
1551 * sa [I] Pointer to security structure
1554 * Success: Handle to mailslot
1555 * Failure: INVALID_HANDLE_VALUE
1557 HANDLE WINAPI
CreateMailslotW( LPCWSTR lpName
, DWORD nMaxMessageSize
,
1558 DWORD lReadTimeout
, LPSECURITY_ATTRIBUTES sa
)
1560 FIXME("(%s,%ld,%ld,%p): stub\n", debugstr_w(lpName
),
1561 nMaxMessageSize
, lReadTimeout
, sa
);
1562 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1563 return INVALID_HANDLE_VALUE
;
1567 /******************************************************************************
1568 * GetMailslotInfo [KERNEL32.@]
1570 * Retrieve information about a mailslot.
1573 * hMailslot [I] Mailslot handle
1574 * lpMaxMessageSize [O] Address of maximum message size
1575 * lpNextSize [O] Address of size of next message
1576 * lpMessageCount [O] Address of number of messages
1577 * lpReadTimeout [O] Address of read time-out
1583 BOOL WINAPI
GetMailslotInfo( HANDLE hMailslot
, LPDWORD lpMaxMessageSize
,
1584 LPDWORD lpNextSize
, LPDWORD lpMessageCount
,
1585 LPDWORD lpReadTimeout
)
1587 FIXME("(%p): stub\n",hMailslot
);
1588 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1593 /******************************************************************************
1594 * SetMailslotInfo [KERNEL32.@]
1596 * Set the read timeout of a mailslot.
1599 * hMailslot [I] Mailslot handle
1600 * dwReadTimeout [I] Timeout in milliseconds.
1606 BOOL WINAPI
SetMailslotInfo( HANDLE hMailslot
, DWORD dwReadTimeout
)
1608 FIXME("%p %ld: stub\n", hMailslot
, dwReadTimeout
);
1609 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1614 /******************************************************************************
1615 * CreateIoCompletionPort (KERNEL32.@)
1617 HANDLE WINAPI
CreateIoCompletionPort(HANDLE hFileHandle
, HANDLE hExistingCompletionPort
,
1618 ULONG_PTR CompletionKey
, DWORD dwNumberOfConcurrentThreads
)
1620 FIXME("(%p, %p, %08lx, %08lx): stub.\n",
1621 hFileHandle
, hExistingCompletionPort
, CompletionKey
, dwNumberOfConcurrentThreads
);
1626 /******************************************************************************
1627 * GetQueuedCompletionStatus (KERNEL32.@)
1629 BOOL WINAPI
GetQueuedCompletionStatus( HANDLE CompletionPort
, LPDWORD lpNumberOfBytesTransferred
,
1630 PULONG_PTR pCompletionKey
, LPOVERLAPPED
*lpOverlapped
,
1631 DWORD dwMilliseconds
)
1633 FIXME("(%p,%p,%p,%p,%ld), stub!\n",
1634 CompletionPort
,lpNumberOfBytesTransferred
,pCompletionKey
,lpOverlapped
,dwMilliseconds
);
1635 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1639 /******************************************************************************
1640 * CreateJobObjectW (KERNEL32.@)
1642 HANDLE WINAPI
CreateJobObjectW( LPSECURITY_ATTRIBUTES attr
, LPCWSTR name
)
1644 FIXME("%p %s\n", attr
, debugstr_w(name
) );
1645 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1649 /******************************************************************************
1650 * CreateJobObjectA (KERNEL32.@)
1652 HANDLE WINAPI
CreateJobObjectA( LPSECURITY_ATTRIBUTES attr
, LPCSTR name
)
1658 TRACE("%p %s\n", attr
, debugstr_a(name
) );
1662 len
= MultiByteToWideChar( CP_ACP
, 0, name
, -1, NULL
, 0 );
1663 str
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
1666 SetLastError( ERROR_OUTOFMEMORY
);
1669 len
= MultiByteToWideChar( CP_ACP
, 0, name
, -1, str
, len
);
1672 r
= CreateJobObjectW( attr
, str
);
1675 HeapFree( GetProcessHeap(), 0, str
);
1680 /******************************************************************************
1681 * AssignProcessToJobObject (KERNEL32.@)
1683 BOOL WINAPI
AssignProcessToJobObject( HANDLE hJob
, HANDLE hProcess
)
1685 FIXME("%p %p\n", hJob
, hProcess
);
1691 /***********************************************************************
1692 * InterlockedCompareExchange (KERNEL32.@)
1694 /* LONG WINAPI InterlockedCompareExchange( PLONG dest, LONG xchg, LONG compare ); */
1695 __ASM_GLOBAL_FUNC(InterlockedCompareExchange
,
1696 "movl 12(%esp),%eax\n\t"
1697 "movl 8(%esp),%ecx\n\t"
1698 "movl 4(%esp),%edx\n\t"
1699 "lock; cmpxchgl %ecx,(%edx)\n\t"
1702 /***********************************************************************
1703 * InterlockedExchange (KERNEL32.@)
1705 /* LONG WINAPI InterlockedExchange( PLONG dest, LONG val ); */
1706 __ASM_GLOBAL_FUNC(InterlockedExchange
,
1707 "movl 8(%esp),%eax\n\t"
1708 "movl 4(%esp),%edx\n\t"
1709 "lock; xchgl %eax,(%edx)\n\t"
1712 /***********************************************************************
1713 * InterlockedExchangeAdd (KERNEL32.@)
1715 /* LONG WINAPI InterlockedExchangeAdd( PLONG dest, LONG incr ); */
1716 __ASM_GLOBAL_FUNC(InterlockedExchangeAdd
,
1717 "movl 8(%esp),%eax\n\t"
1718 "movl 4(%esp),%edx\n\t"
1719 "lock; xaddl %eax,(%edx)\n\t"
1722 /***********************************************************************
1723 * InterlockedIncrement (KERNEL32.@)
1725 /* LONG WINAPI InterlockedIncrement( PLONG dest ); */
1726 __ASM_GLOBAL_FUNC(InterlockedIncrement
,
1727 "movl 4(%esp),%edx\n\t"
1729 "lock; xaddl %eax,(%edx)\n\t"
1733 /***********************************************************************
1734 * InterlockedDecrement (KERNEL32.@)
1736 __ASM_GLOBAL_FUNC(InterlockedDecrement
,
1737 "movl 4(%esp),%edx\n\t"
1739 "lock; xaddl %eax,(%edx)\n\t"
1743 #else /* __i386__ */
1745 /***********************************************************************
1746 * InterlockedCompareExchange (KERNEL32.@)
1748 * Atomically swap one value with another.
1751 * dest [I/O] The value to replace
1752 * xchq [I] The value to be swapped
1753 * compare [I] The value to compare to dest
1756 * The resulting value of dest.
1759 * dest is updated only if it is equal to compare, otherwise no swap is done.
1761 LONG WINAPI
InterlockedCompareExchange( PLONG dest
, LONG xchg
, LONG compare
)
1763 return interlocked_cmpxchg( dest
, xchg
, compare
);
1766 /***********************************************************************
1767 * InterlockedExchange (KERNEL32.@)
1769 * Atomically swap one value with another.
1772 * dest [I/O] The value to replace
1773 * val [I] The value to be swapped
1776 * The resulting value of dest.
1778 LONG WINAPI
InterlockedExchange( PLONG dest
, LONG val
)
1780 return interlocked_xchg( dest
, val
);
1783 /***********************************************************************
1784 * InterlockedExchangeAdd (KERNEL32.@)
1786 * Atomically add one value to another.
1789 * dest [I/O] The value to add to
1790 * incr [I] The value to be added
1793 * The resulting value of dest.
1795 LONG WINAPI
InterlockedExchangeAdd( PLONG dest
, LONG incr
)
1797 return interlocked_xchg_add( dest
, incr
);
1800 /***********************************************************************
1801 * InterlockedIncrement (KERNEL32.@)
1803 * Atomically increment a value.
1806 * dest [I/O] The value to increment
1809 * The resulting value of dest.
1811 LONG WINAPI
InterlockedIncrement( PLONG dest
)
1813 return interlocked_xchg_add( dest
, 1 ) + 1;
1816 /***********************************************************************
1817 * InterlockedDecrement (KERNEL32.@)
1819 * Atomically decrement a value.
1822 * dest [I/O] The value to decrement
1825 * The resulting value of dest.
1827 LONG WINAPI
InterlockedDecrement( PLONG dest
)
1829 return interlocked_xchg_add( dest
, -1 ) - 1;
1832 #endif /* __i386__ */