2000-09-29 20:48:04 +00:00
|
|
|
/*
|
|
|
|
* Kernel synchronization objects
|
|
|
|
*
|
|
|
|
* Copyright 1998 Alexandre Julliard
|
2002-03-09 23:29:33 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2000-09-29 20:48:04 +00:00
|
|
|
*/
|
|
|
|
|
2001-07-20 18:00:00 +00:00
|
|
|
#include "config.h"
|
2002-08-28 23:42:34 +00:00
|
|
|
#include "wine/port.h"
|
2001-07-20 18:00:00 +00:00
|
|
|
|
2000-09-29 20:48:04 +00:00
|
|
|
#include <string.h>
|
2002-08-17 00:43:16 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
2002-07-25 00:22:03 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#ifdef HAVE_SYS_IOCTL_H
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#endif
|
2005-03-04 12:38:36 +00:00
|
|
|
#ifdef HAVE_POLL_H
|
|
|
|
#include <poll.h>
|
|
|
|
#endif
|
2002-09-04 23:34:03 +00:00
|
|
|
#ifdef HAVE_SYS_POLL_H
|
|
|
|
#include <sys/poll.h>
|
|
|
|
#endif
|
2004-02-12 20:03:53 +00:00
|
|
|
#ifdef HAVE_SYS_SOCKET_H
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#endif
|
2003-09-05 23:08:26 +00:00
|
|
|
#include <stdarg.h>
|
2003-05-20 04:32:53 +00:00
|
|
|
#include <stdio.h>
|
2001-07-20 18:00:00 +00:00
|
|
|
|
2005-04-18 14:57:04 +00:00
|
|
|
#define NONAMELESSUNION
|
|
|
|
#define NONAMELESSSTRUCT
|
|
|
|
|
2003-09-05 23:08:26 +00:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#include "windef.h"
|
2001-07-20 18:00:00 +00:00
|
|
|
#include "winbase.h"
|
2000-09-29 20:48:04 +00:00
|
|
|
#include "winerror.h"
|
|
|
|
#include "winnls.h"
|
2004-03-18 01:36:09 +00:00
|
|
|
#include "winternl.h"
|
2001-07-20 18:00:00 +00:00
|
|
|
|
2001-07-19 00:39:09 +00:00
|
|
|
#include "wine/server.h"
|
2001-07-20 18:00:00 +00:00
|
|
|
#include "wine/unicode.h"
|
2003-12-08 21:58:55 +00:00
|
|
|
#include "wine/winbase16.h"
|
2003-09-18 04:39:13 +00:00
|
|
|
#include "kernel_private.h"
|
2001-07-20 18:00:00 +00:00
|
|
|
|
2002-03-09 23:29:33 +00:00
|
|
|
#include "wine/debug.h"
|
2000-09-29 20:48:04 +00:00
|
|
|
|
2004-02-26 05:30:54 +00:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(sync);
|
2000-09-29 20:48:04 +00:00
|
|
|
|
2003-05-12 03:28:26 +00:00
|
|
|
/* check if current version is NT or Win95 */
|
|
|
|
inline static int is_version_nt(void)
|
|
|
|
{
|
|
|
|
return !(GetVersion() & 0x80000000);
|
|
|
|
}
|
2000-09-29 20:48:04 +00:00
|
|
|
|
|
|
|
|
2003-09-18 04:39:13 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* Sleep (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
VOID WINAPI Sleep( DWORD timeout )
|
|
|
|
{
|
|
|
|
SleepEx( timeout, FALSE );
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* SleepEx (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI SleepEx( DWORD timeout, BOOL alertable )
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
if (timeout == INFINITE) status = NtDelayExecution( alertable, NULL );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LARGE_INTEGER time;
|
|
|
|
|
|
|
|
time.QuadPart = timeout * (ULONGLONG)10000;
|
|
|
|
time.QuadPart = -time.QuadPart;
|
|
|
|
status = NtDelayExecution( alertable, &time );
|
|
|
|
}
|
|
|
|
if (status != STATUS_USER_APC) status = STATUS_SUCCESS;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-11 20:11:01 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* SwitchToThread (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SwitchToThread(void)
|
|
|
|
{
|
|
|
|
return (NtYieldExecution() != STATUS_NO_YIELD_PERFORMED);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-18 04:39:13 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* WaitForSingleObject (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI WaitForSingleObject( HANDLE handle, DWORD timeout )
|
|
|
|
{
|
|
|
|
return WaitForMultipleObjectsEx( 1, &handle, FALSE, timeout, FALSE );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WaitForSingleObjectEx (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI WaitForSingleObjectEx( HANDLE handle, DWORD timeout,
|
|
|
|
BOOL alertable )
|
|
|
|
{
|
|
|
|
return WaitForMultipleObjectsEx( 1, &handle, FALSE, timeout, alertable );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WaitForMultipleObjects (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI WaitForMultipleObjects( DWORD count, const HANDLE *handles,
|
|
|
|
BOOL wait_all, DWORD timeout )
|
|
|
|
{
|
|
|
|
return WaitForMultipleObjectsEx( count, handles, wait_all, timeout, FALSE );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WaitForMultipleObjectsEx (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI WaitForMultipleObjectsEx( DWORD count, const HANDLE *handles,
|
|
|
|
BOOL wait_all, DWORD timeout,
|
|
|
|
BOOL alertable )
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
HANDLE hloc[MAXIMUM_WAIT_OBJECTS];
|
2004-08-10 23:43:21 +00:00
|
|
|
unsigned int i;
|
2003-09-18 04:39:13 +00:00
|
|
|
|
|
|
|
if (count >= MAXIMUM_WAIT_OBJECTS)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return WAIT_FAILED;
|
|
|
|
}
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
if ((handles[i] == (HANDLE)STD_INPUT_HANDLE) ||
|
|
|
|
(handles[i] == (HANDLE)STD_OUTPUT_HANDLE) ||
|
|
|
|
(handles[i] == (HANDLE)STD_ERROR_HANDLE))
|
|
|
|
hloc[i] = GetStdHandle( (DWORD)handles[i] );
|
|
|
|
else
|
|
|
|
hloc[i] = handles[i];
|
|
|
|
|
|
|
|
/* yes, even screen buffer console handles are waitable, and are
|
|
|
|
* handled as a handle to the console itself !!
|
|
|
|
*/
|
|
|
|
if (is_console_handle(hloc[i]))
|
|
|
|
{
|
|
|
|
if (!VerifyConsoleIoHandle(hloc[i]))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
hloc[i] = GetConsoleInputWaitHandle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (timeout == INFINITE)
|
|
|
|
{
|
|
|
|
status = NtWaitForMultipleObjects( count, hloc, wait_all, alertable, NULL );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LARGE_INTEGER time;
|
|
|
|
|
|
|
|
time.QuadPart = timeout * (ULONGLONG)10000;
|
|
|
|
time.QuadPart = -time.QuadPart;
|
|
|
|
status = NtWaitForMultipleObjects( count, hloc, wait_all, alertable, &time );
|
|
|
|
}
|
|
|
|
|
|
|
|
if (HIWORD(status)) /* is it an error code? */
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
status = WAIT_FAILED;
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WaitForSingleObject (KERNEL.460)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI WaitForSingleObject16( HANDLE handle, DWORD timeout )
|
|
|
|
{
|
|
|
|
DWORD retval, mutex_count;
|
|
|
|
|
|
|
|
ReleaseThunkLock( &mutex_count );
|
|
|
|
retval = WaitForSingleObject( handle, timeout );
|
|
|
|
RestoreThunkLock( mutex_count );
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WaitForMultipleObjects (KERNEL.461)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI WaitForMultipleObjects16( DWORD count, const HANDLE *handles,
|
|
|
|
BOOL wait_all, DWORD timeout )
|
|
|
|
{
|
|
|
|
DWORD retval, mutex_count;
|
|
|
|
|
|
|
|
ReleaseThunkLock( &mutex_count );
|
|
|
|
retval = WaitForMultipleObjectsEx( count, handles, wait_all, timeout, FALSE );
|
|
|
|
RestoreThunkLock( mutex_count );
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WaitForMultipleObjectsEx (KERNEL.495)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI WaitForMultipleObjectsEx16( DWORD count, const HANDLE *handles,
|
|
|
|
BOOL wait_all, DWORD timeout, BOOL alertable )
|
|
|
|
{
|
|
|
|
DWORD retval, mutex_count;
|
|
|
|
|
|
|
|
ReleaseThunkLock( &mutex_count );
|
|
|
|
retval = WaitForMultipleObjectsEx( count, handles, wait_all, timeout, alertable );
|
|
|
|
RestoreThunkLock( mutex_count );
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2003-10-09 19:46:43 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* RegisterWaitForSingleObject (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI RegisterWaitForSingleObject(PHANDLE phNewWaitObject, HANDLE hObject,
|
|
|
|
WAITORTIMERCALLBACK Callback, PVOID Context,
|
|
|
|
ULONG dwMilliseconds, ULONG dwFlags)
|
|
|
|
{
|
|
|
|
FIXME("%p %p %p %p %ld %ld\n",
|
|
|
|
phNewWaitObject,hObject,Callback,Context,dwMilliseconds,dwFlags);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RegisterWaitForSingleObjectEx (KERNEL32.@)
|
|
|
|
*/
|
2004-05-18 20:43:29 +00:00
|
|
|
HANDLE WINAPI RegisterWaitForSingleObjectEx( HANDLE hObject,
|
2003-10-09 19:46:43 +00:00
|
|
|
WAITORTIMERCALLBACK Callback, PVOID Context,
|
|
|
|
ULONG dwMilliseconds, ULONG dwFlags )
|
|
|
|
{
|
|
|
|
FIXME("%p %p %p %ld %ld\n",
|
|
|
|
hObject,Callback,Context,dwMilliseconds,dwFlags);
|
2004-05-18 20:43:29 +00:00
|
|
|
return 0;
|
2003-10-09 19:46:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* UnregisterWait (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI UnregisterWait( HANDLE WaitHandle )
|
|
|
|
{
|
|
|
|
FIXME("%p\n",WaitHandle);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* UnregisterWaitEx (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI UnregisterWaitEx( HANDLE WaitHandle, HANDLE CompletionEvent )
|
|
|
|
{
|
|
|
|
FIXME("%p %p\n",WaitHandle, CompletionEvent);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-03-17 01:43:47 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* SignalObjectAndWait (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* Allows to atomically signal any of the synchro objects (semaphore,
|
|
|
|
* mutex, event) and wait on another.
|
|
|
|
*/
|
2005-04-24 17:36:34 +00:00
|
|
|
DWORD WINAPI SignalObjectAndWait( HANDLE hObjectToSignal, HANDLE hObjectToWaitOn,
|
|
|
|
DWORD dwMilliseconds, BOOL bAlertable )
|
2004-03-17 01:43:47 +00:00
|
|
|
{
|
2005-04-24 17:36:34 +00:00
|
|
|
NTSTATUS status;
|
|
|
|
LARGE_INTEGER timeout, *ptimeout = NULL;
|
|
|
|
|
|
|
|
TRACE("%p %p %ld %d\n", hObjectToSignal,
|
|
|
|
hObjectToWaitOn, dwMilliseconds, bAlertable);
|
|
|
|
|
|
|
|
if (dwMilliseconds != INFINITE)
|
|
|
|
{
|
|
|
|
timeout.QuadPart = dwMilliseconds * (ULONGLONG)10000;
|
|
|
|
timeout.QuadPart = -timeout.QuadPart;
|
|
|
|
ptimeout = &timeout;
|
|
|
|
}
|
2004-03-17 01:43:47 +00:00
|
|
|
|
2005-04-24 17:36:34 +00:00
|
|
|
status = NtSignalAndWaitForSingleObject( hObjectToSignal, hObjectToWaitOn,
|
|
|
|
bAlertable, ptimeout );
|
|
|
|
if (HIWORD(status))
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
status = WAIT_FAILED;
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
2004-03-17 01:43:47 +00:00
|
|
|
|
2003-06-24 03:34:15 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* InitializeCriticalSection (KERNEL32.@)
|
2003-09-17 20:05:03 +00:00
|
|
|
*
|
|
|
|
* Initialise a critical section before use.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* crit [O] Critical section to initialise.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Nothing. If the function fails an exception is raised.
|
2003-06-24 03:34:15 +00:00
|
|
|
*/
|
|
|
|
void WINAPI InitializeCriticalSection( CRITICAL_SECTION *crit )
|
|
|
|
{
|
|
|
|
NTSTATUS ret = RtlInitializeCriticalSection( crit );
|
|
|
|
if (ret) RtlRaiseStatus( ret );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* InitializeCriticalSectionAndSpinCount (KERNEL32.@)
|
2003-09-17 20:05:03 +00:00
|
|
|
*
|
|
|
|
* Initialise a critical section with a spin count.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* crit [O] Critical section to initialise.
|
|
|
|
* spincount [I] Number of times to spin upon contention.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE.
|
|
|
|
* Failure: Nothing. If the function fails an exception is raised.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* spincount is ignored on uni-processor systems.
|
2003-06-24 03:34:15 +00:00
|
|
|
*/
|
|
|
|
BOOL WINAPI InitializeCriticalSectionAndSpinCount( CRITICAL_SECTION *crit, DWORD spincount )
|
|
|
|
{
|
|
|
|
NTSTATUS ret = RtlInitializeCriticalSectionAndSpinCount( crit, spincount );
|
|
|
|
if (ret) RtlRaiseStatus( ret );
|
|
|
|
return !ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* MakeCriticalSectionGlobal (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
void WINAPI MakeCriticalSectionGlobal( CRITICAL_SECTION *crit )
|
|
|
|
{
|
|
|
|
/* let's assume that only one thread at a time will try to do this */
|
|
|
|
HANDLE sem = crit->LockSemaphore;
|
|
|
|
if (!sem) NtCreateSemaphore( &sem, SEMAPHORE_ALL_ACCESS, NULL, 0, 1 );
|
|
|
|
crit->LockSemaphore = ConvertToGlobalHandle( sem );
|
2003-08-18 20:03:00 +00:00
|
|
|
if (crit->DebugInfo)
|
|
|
|
{
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, crit->DebugInfo );
|
|
|
|
crit->DebugInfo = NULL;
|
|
|
|
}
|
2003-06-24 03:34:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ReinitializeCriticalSection (KERNEL32.@)
|
2003-09-17 20:05:03 +00:00
|
|
|
*
|
|
|
|
* Initialise an already used critical section.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* crit [O] Critical section to initialise.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Nothing.
|
2003-06-24 03:34:15 +00:00
|
|
|
*/
|
|
|
|
void WINAPI ReinitializeCriticalSection( CRITICAL_SECTION *crit )
|
|
|
|
{
|
|
|
|
if ( !crit->LockSemaphore )
|
|
|
|
RtlInitializeCriticalSection( crit );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* UninitializeCriticalSection (KERNEL32.@)
|
2003-09-17 20:05:03 +00:00
|
|
|
*
|
|
|
|
* UnInitialise a critical section after use.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* crit [O] Critical section to uninitialise (destroy).
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Nothing.
|
2003-06-24 03:34:15 +00:00
|
|
|
*/
|
|
|
|
void WINAPI UninitializeCriticalSection( CRITICAL_SECTION *crit )
|
|
|
|
{
|
|
|
|
RtlDeleteCriticalSection( crit );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-29 20:48:04 +00:00
|
|
|
/***********************************************************************
|
2001-06-13 20:13:18 +00:00
|
|
|
* CreateEventA (KERNEL32.@)
|
2000-09-29 20:48:04 +00:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateEventA( SECURITY_ATTRIBUTES *sa, BOOL manual_reset,
|
|
|
|
BOOL initial_state, LPCSTR name )
|
|
|
|
{
|
2001-11-30 18:46:42 +00:00
|
|
|
WCHAR buffer[MAX_PATH];
|
|
|
|
|
|
|
|
if (!name) return CreateEventW( sa, manual_reset, initial_state, NULL );
|
|
|
|
|
|
|
|
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
|
2000-09-29 20:48:04 +00:00
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
2001-11-30 18:46:42 +00:00
|
|
|
return CreateEventW( sa, manual_reset, initial_state, buffer );
|
2000-09-29 20:48:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 20:13:18 +00:00
|
|
|
* CreateEventW (KERNEL32.@)
|
2000-09-29 20:48:04 +00:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateEventW( SECURITY_ATTRIBUTES *sa, BOOL manual_reset,
|
|
|
|
BOOL initial_state, LPCWSTR name )
|
|
|
|
{
|
|
|
|
HANDLE ret;
|
2004-12-02 18:05:37 +00:00
|
|
|
UNICODE_STRING nameW;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
2000-12-29 03:18:08 +00:00
|
|
|
/* one buggy program needs this
|
|
|
|
* ("Van Dale Groot woordenboek der Nederlandse taal")
|
|
|
|
*/
|
|
|
|
if (sa && IsBadReadPtr(sa,sizeof(SECURITY_ATTRIBUTES)))
|
|
|
|
{
|
|
|
|
ERR("Bad security attributes pointer %p\n",sa);
|
|
|
|
SetLastError( ERROR_INVALID_PARAMETER);
|
|
|
|
return 0;
|
|
|
|
}
|
2004-12-02 18:05:37 +00:00
|
|
|
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.ObjectName = NULL;
|
|
|
|
attr.Attributes = (sa && sa->bInheritHandle) ? OBJ_INHERIT : 0;
|
|
|
|
attr.SecurityDescriptor = sa ? sa->lpSecurityDescriptor : NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
if (name)
|
2000-09-29 20:48:04 +00:00
|
|
|
{
|
2004-12-02 18:05:37 +00:00
|
|
|
RtlInitUnicodeString( &nameW, name );
|
|
|
|
attr.ObjectName = &nameW;
|
2000-09-29 20:48:04 +00:00
|
|
|
}
|
2004-12-02 18:05:37 +00:00
|
|
|
|
|
|
|
status = NtCreateEvent( &ret, EVENT_ALL_ACCESS, &attr, manual_reset, initial_state );
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
2000-09-29 20:48:04 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-07-02 19:59:40 +00:00
|
|
|
* CreateW32Event (KERNEL.457)
|
2000-09-29 20:48:04 +00:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI WIN16_CreateEvent( BOOL manual_reset, BOOL initial_state )
|
|
|
|
{
|
2005-01-07 15:40:09 +00:00
|
|
|
return CreateEventW( NULL, manual_reset, initial_state, NULL );
|
2000-09-29 20:48:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 20:13:18 +00:00
|
|
|
* OpenEventA (KERNEL32.@)
|
2000-09-29 20:48:04 +00:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI OpenEventA( DWORD access, BOOL inherit, LPCSTR name )
|
|
|
|
{
|
2001-11-30 18:46:42 +00:00
|
|
|
WCHAR buffer[MAX_PATH];
|
|
|
|
|
|
|
|
if (!name) return OpenEventW( access, inherit, NULL );
|
|
|
|
|
|
|
|
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
|
2000-09-29 20:48:04 +00:00
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
2001-11-30 18:46:42 +00:00
|
|
|
return OpenEventW( access, inherit, buffer );
|
2000-09-29 20:48:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 20:13:18 +00:00
|
|
|
* OpenEventW (KERNEL32.@)
|
2000-09-29 20:48:04 +00:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI OpenEventW( DWORD access, BOOL inherit, LPCWSTR name )
|
|
|
|
{
|
|
|
|
HANDLE ret;
|
2004-12-02 18:05:37 +00:00
|
|
|
UNICODE_STRING nameW;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
if (!is_version_nt()) access = EVENT_ALL_ACCESS;
|
|
|
|
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.ObjectName = NULL;
|
|
|
|
attr.Attributes = inherit ? OBJ_INHERIT : 0;
|
|
|
|
attr.SecurityDescriptor = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
if (name)
|
2000-09-29 20:48:04 +00:00
|
|
|
{
|
2004-12-02 18:05:37 +00:00
|
|
|
RtlInitUnicodeString( &nameW, name );
|
|
|
|
attr.ObjectName = &nameW;
|
2000-09-29 20:48:04 +00:00
|
|
|
}
|
2003-05-12 03:28:26 +00:00
|
|
|
|
2004-12-02 18:05:37 +00:00
|
|
|
status = NtOpenEvent( &ret, access, &attr );
|
|
|
|
if (status != STATUS_SUCCESS)
|
2000-09-29 20:48:04 +00:00
|
|
|
{
|
2004-12-02 18:05:37 +00:00
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return 0;
|
2000-09-29 20:48:04 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 20:13:18 +00:00
|
|
|
* PulseEvent (KERNEL32.@)
|
2000-09-29 20:48:04 +00:00
|
|
|
*/
|
|
|
|
BOOL WINAPI PulseEvent( HANDLE handle )
|
|
|
|
{
|
2004-03-18 01:36:09 +00:00
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
if ((status = NtPulseEvent( handle, NULL )))
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return !status;
|
2000-09-29 20:48:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-07-11 18:56:41 +00:00
|
|
|
* SetW32Event (KERNEL.458)
|
2001-06-13 20:13:18 +00:00
|
|
|
* SetEvent (KERNEL32.@)
|
2000-09-29 20:48:04 +00:00
|
|
|
*/
|
|
|
|
BOOL WINAPI SetEvent( HANDLE handle )
|
|
|
|
{
|
2004-03-18 01:36:09 +00:00
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
if ((status = NtSetEvent( handle, NULL )))
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return !status;
|
2000-09-29 20:48:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-07-11 18:56:41 +00:00
|
|
|
* ResetW32Event (KERNEL.459)
|
2001-06-13 20:13:18 +00:00
|
|
|
* ResetEvent (KERNEL32.@)
|
2000-09-29 20:48:04 +00:00
|
|
|
*/
|
|
|
|
BOOL WINAPI ResetEvent( HANDLE handle )
|
|
|
|
{
|
2004-03-18 01:36:09 +00:00
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
if ((status = NtResetEvent( handle, NULL )))
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return !status;
|
2000-09-29 20:48:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* NOTE: The Win95 VWin32_Event routines given below are really low-level
|
|
|
|
* routines implemented directly by VWin32. The user-mode libraries
|
|
|
|
* implement Win32 synchronisation routines on top of these low-level
|
|
|
|
* primitives. We do it the other way around here :-)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* VWin32_EventCreate (KERNEL.442)
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI VWin32_EventCreate(VOID)
|
|
|
|
{
|
2005-01-07 15:40:09 +00:00
|
|
|
HANDLE hEvent = CreateEventW( NULL, FALSE, 0, NULL );
|
2000-09-29 20:48:04 +00:00
|
|
|
return ConvertToGlobalHandle( hEvent );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* VWin32_EventDestroy (KERNEL.443)
|
|
|
|
*/
|
|
|
|
VOID WINAPI VWin32_EventDestroy(HANDLE event)
|
|
|
|
{
|
|
|
|
CloseHandle( event );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2002-05-31 23:06:46 +00:00
|
|
|
* VWin32_EventWait (KERNEL.450)
|
2000-09-29 20:48:04 +00:00
|
|
|
*/
|
|
|
|
VOID WINAPI VWin32_EventWait(HANDLE event)
|
|
|
|
{
|
2000-11-15 23:41:46 +00:00
|
|
|
DWORD mutex_count;
|
|
|
|
|
|
|
|
ReleaseThunkLock( &mutex_count );
|
2000-09-29 20:48:04 +00:00
|
|
|
WaitForSingleObject( event, INFINITE );
|
2000-11-15 23:41:46 +00:00
|
|
|
RestoreThunkLock( mutex_count );
|
2000-09-29 20:48:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-19 18:20:47 +00:00
|
|
|
* VWin32_EventSet (KERNEL.451)
|
2001-07-02 19:59:40 +00:00
|
|
|
* KERNEL_479 (KERNEL.479)
|
2000-09-29 20:48:04 +00:00
|
|
|
*/
|
|
|
|
VOID WINAPI VWin32_EventSet(HANDLE event)
|
|
|
|
{
|
|
|
|
SetEvent( event );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 20:13:18 +00:00
|
|
|
* CreateMutexA (KERNEL32.@)
|
2000-09-29 20:48:04 +00:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateMutexA( SECURITY_ATTRIBUTES *sa, BOOL owner, LPCSTR name )
|
|
|
|
{
|
2001-11-30 18:46:42 +00:00
|
|
|
WCHAR buffer[MAX_PATH];
|
|
|
|
|
|
|
|
if (!name) return CreateMutexW( sa, owner, NULL );
|
|
|
|
|
|
|
|
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
|
2000-09-29 20:48:04 +00:00
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
2001-11-30 18:46:42 +00:00
|
|
|
return CreateMutexW( sa, owner, buffer );
|
2000-09-29 20:48:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 20:13:18 +00:00
|
|
|
* CreateMutexW (KERNEL32.@)
|
2000-09-29 20:48:04 +00:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateMutexW( SECURITY_ATTRIBUTES *sa, BOOL owner, LPCWSTR name )
|
|
|
|
{
|
|
|
|
HANDLE ret;
|
2004-12-02 18:05:37 +00:00
|
|
|
UNICODE_STRING nameW;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.ObjectName = NULL;
|
|
|
|
attr.Attributes = (sa && sa->bInheritHandle) ? OBJ_INHERIT : 0;
|
|
|
|
attr.SecurityDescriptor = sa ? sa->lpSecurityDescriptor : NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
if (name)
|
2000-09-29 20:48:04 +00:00
|
|
|
{
|
2004-12-02 18:05:37 +00:00
|
|
|
RtlInitUnicodeString( &nameW, name );
|
|
|
|
attr.ObjectName = &nameW;
|
2000-09-29 20:48:04 +00:00
|
|
|
}
|
2004-12-02 18:05:37 +00:00
|
|
|
|
|
|
|
status = NtCreateMutant( &ret, MUTEX_ALL_ACCESS, &attr, owner );
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
2000-09-29 20:48:04 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 20:13:18 +00:00
|
|
|
* OpenMutexA (KERNEL32.@)
|
2000-09-29 20:48:04 +00:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI OpenMutexA( DWORD access, BOOL inherit, LPCSTR name )
|
|
|
|
{
|
2001-11-30 18:46:42 +00:00
|
|
|
WCHAR buffer[MAX_PATH];
|
|
|
|
|
|
|
|
if (!name) return OpenMutexW( access, inherit, NULL );
|
|
|
|
|
|
|
|
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
|
2000-09-29 20:48:04 +00:00
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
2001-11-30 18:46:42 +00:00
|
|
|
return OpenMutexW( access, inherit, buffer );
|
2000-09-29 20:48:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 20:13:18 +00:00
|
|
|
* OpenMutexW (KERNEL32.@)
|
2000-09-29 20:48:04 +00:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI OpenMutexW( DWORD access, BOOL inherit, LPCWSTR name )
|
|
|
|
{
|
|
|
|
HANDLE ret;
|
2004-12-02 18:05:37 +00:00
|
|
|
UNICODE_STRING nameW;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
if (!is_version_nt()) access = MUTEX_ALL_ACCESS;
|
|
|
|
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.ObjectName = NULL;
|
|
|
|
attr.Attributes = inherit ? OBJ_INHERIT : 0;
|
|
|
|
attr.SecurityDescriptor = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
if (name)
|
2000-09-29 20:48:04 +00:00
|
|
|
{
|
2004-12-02 18:05:37 +00:00
|
|
|
RtlInitUnicodeString( &nameW, name );
|
|
|
|
attr.ObjectName = &nameW;
|
2000-09-29 20:48:04 +00:00
|
|
|
}
|
2003-05-12 03:28:26 +00:00
|
|
|
|
2004-12-02 18:05:37 +00:00
|
|
|
status = NtOpenMutant( &ret, access, &attr );
|
|
|
|
if (status != STATUS_SUCCESS)
|
2000-09-29 20:48:04 +00:00
|
|
|
{
|
2004-12-02 18:05:37 +00:00
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return 0;
|
2000-09-29 20:48:04 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 20:13:18 +00:00
|
|
|
* ReleaseMutex (KERNEL32.@)
|
2000-09-29 20:48:04 +00:00
|
|
|
*/
|
|
|
|
BOOL WINAPI ReleaseMutex( HANDLE handle )
|
|
|
|
{
|
2004-12-02 18:05:37 +00:00
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
status = NtReleaseMutant(handle, NULL);
|
|
|
|
if (status != STATUS_SUCCESS)
|
2000-09-29 20:48:04 +00:00
|
|
|
{
|
2004-12-02 18:05:37 +00:00
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return FALSE;
|
2000-09-29 20:48:04 +00:00
|
|
|
}
|
2004-12-02 18:05:37 +00:00
|
|
|
return TRUE;
|
2000-09-29 20:48:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Semaphores
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 20:13:18 +00:00
|
|
|
* CreateSemaphoreA (KERNEL32.@)
|
2000-09-29 20:48:04 +00:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateSemaphoreA( SECURITY_ATTRIBUTES *sa, LONG initial, LONG max, LPCSTR name )
|
|
|
|
{
|
2001-11-30 18:46:42 +00:00
|
|
|
WCHAR buffer[MAX_PATH];
|
2000-09-29 20:48:04 +00:00
|
|
|
|
2001-11-30 18:46:42 +00:00
|
|
|
if (!name) return CreateSemaphoreW( sa, initial, max, NULL );
|
2000-09-29 20:48:04 +00:00
|
|
|
|
2001-11-30 18:46:42 +00:00
|
|
|
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
|
2000-09-29 20:48:04 +00:00
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
2001-11-30 18:46:42 +00:00
|
|
|
return CreateSemaphoreW( sa, initial, max, buffer );
|
2000-09-29 20:48:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 20:13:18 +00:00
|
|
|
* CreateSemaphoreW (KERNEL32.@)
|
2000-09-29 20:48:04 +00:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateSemaphoreW( SECURITY_ATTRIBUTES *sa, LONG initial,
|
2004-12-02 18:05:37 +00:00
|
|
|
LONG max, LPCWSTR name )
|
2000-09-29 20:48:04 +00:00
|
|
|
{
|
|
|
|
HANDLE ret;
|
2004-12-02 18:05:37 +00:00
|
|
|
UNICODE_STRING nameW;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
NTSTATUS status;
|
2000-09-29 20:48:04 +00:00
|
|
|
|
2004-12-02 18:05:37 +00:00
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.ObjectName = NULL;
|
|
|
|
attr.Attributes = (sa && sa->bInheritHandle) ? OBJ_INHERIT : 0;
|
|
|
|
attr.SecurityDescriptor = sa ? sa->lpSecurityDescriptor : NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
if (name)
|
2000-09-29 20:48:04 +00:00
|
|
|
{
|
2004-12-02 18:05:37 +00:00
|
|
|
RtlInitUnicodeString( &nameW, name );
|
|
|
|
attr.ObjectName = &nameW;
|
2000-09-29 20:48:04 +00:00
|
|
|
}
|
|
|
|
|
2004-12-02 18:05:37 +00:00
|
|
|
status = NtCreateSemaphore( &ret, SEMAPHORE_ALL_ACCESS, &attr, initial, max );
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
2000-09-29 20:48:04 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 20:13:18 +00:00
|
|
|
* OpenSemaphoreA (KERNEL32.@)
|
2000-09-29 20:48:04 +00:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI OpenSemaphoreA( DWORD access, BOOL inherit, LPCSTR name )
|
|
|
|
{
|
2001-11-30 18:46:42 +00:00
|
|
|
WCHAR buffer[MAX_PATH];
|
|
|
|
|
|
|
|
if (!name) return OpenSemaphoreW( access, inherit, NULL );
|
|
|
|
|
|
|
|
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
|
2000-09-29 20:48:04 +00:00
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
2001-11-30 18:46:42 +00:00
|
|
|
return OpenSemaphoreW( access, inherit, buffer );
|
2000-09-29 20:48:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 20:13:18 +00:00
|
|
|
* OpenSemaphoreW (KERNEL32.@)
|
2000-09-29 20:48:04 +00:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI OpenSemaphoreW( DWORD access, BOOL inherit, LPCWSTR name )
|
|
|
|
{
|
|
|
|
HANDLE ret;
|
2004-12-02 18:05:37 +00:00
|
|
|
UNICODE_STRING nameW;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
if (!is_version_nt()) access = SEMAPHORE_ALL_ACCESS;
|
|
|
|
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.ObjectName = NULL;
|
|
|
|
attr.Attributes = inherit ? OBJ_INHERIT : 0;
|
|
|
|
attr.SecurityDescriptor = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
if (name)
|
2000-09-29 20:48:04 +00:00
|
|
|
{
|
2004-12-02 18:05:37 +00:00
|
|
|
RtlInitUnicodeString( &nameW, name );
|
|
|
|
attr.ObjectName = &nameW;
|
2000-09-29 20:48:04 +00:00
|
|
|
}
|
2003-05-12 03:28:26 +00:00
|
|
|
|
2004-12-02 18:05:37 +00:00
|
|
|
status = NtOpenSemaphore( &ret, access, &attr );
|
|
|
|
if (status != STATUS_SUCCESS)
|
2000-09-29 20:48:04 +00:00
|
|
|
{
|
2004-12-02 18:05:37 +00:00
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return 0;
|
2000-09-29 20:48:04 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 20:13:18 +00:00
|
|
|
* ReleaseSemaphore (KERNEL32.@)
|
2000-09-29 20:48:04 +00:00
|
|
|
*/
|
|
|
|
BOOL WINAPI ReleaseSemaphore( HANDLE handle, LONG count, LONG *previous )
|
|
|
|
{
|
2005-08-17 10:28:35 +00:00
|
|
|
NTSTATUS status = NtReleaseSemaphore( handle, count, (PULONG)previous );
|
2000-09-29 20:48:04 +00:00
|
|
|
if (status) SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return !status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-20 04:14:45 +00:00
|
|
|
/*
|
|
|
|
* Timers
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CreateWaitableTimerA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateWaitableTimerA( SECURITY_ATTRIBUTES *sa, BOOL manual, LPCSTR name )
|
|
|
|
{
|
|
|
|
WCHAR buffer[MAX_PATH];
|
|
|
|
|
|
|
|
if (!name) return CreateWaitableTimerW( sa, manual, NULL );
|
|
|
|
|
|
|
|
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return CreateWaitableTimerW( sa, manual, buffer );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CreateWaitableTimerW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateWaitableTimerW( SECURITY_ATTRIBUTES *sa, BOOL manual, LPCWSTR name )
|
|
|
|
{
|
2004-12-02 18:05:37 +00:00
|
|
|
HANDLE handle;
|
|
|
|
NTSTATUS status;
|
|
|
|
UNICODE_STRING nameW;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
2003-05-20 04:14:45 +00:00
|
|
|
|
2004-12-02 18:05:37 +00:00
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.ObjectName = NULL;
|
|
|
|
attr.Attributes = (sa && sa->bInheritHandle) ? OBJ_INHERIT : 0;
|
|
|
|
attr.SecurityDescriptor = sa ? sa->lpSecurityDescriptor : NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
if (name)
|
2003-05-20 04:14:45 +00:00
|
|
|
{
|
2004-12-02 18:05:37 +00:00
|
|
|
RtlInitUnicodeString( &nameW, name );
|
|
|
|
attr.ObjectName = &nameW;
|
2003-05-20 04:14:45 +00:00
|
|
|
}
|
2004-12-02 18:05:37 +00:00
|
|
|
|
|
|
|
status = NtCreateTimer(&handle, TIMER_ALL_ACCESS, &attr,
|
|
|
|
manual ? NotificationTimer : SynchronizationTimer);
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
2003-05-20 04:14:45 +00:00
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* OpenWaitableTimerA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI OpenWaitableTimerA( DWORD access, BOOL inherit, LPCSTR name )
|
|
|
|
{
|
|
|
|
WCHAR buffer[MAX_PATH];
|
|
|
|
|
|
|
|
if (!name) return OpenWaitableTimerW( access, inherit, NULL );
|
|
|
|
|
|
|
|
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return OpenWaitableTimerW( access, inherit, buffer );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* OpenWaitableTimerW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI OpenWaitableTimerW( DWORD access, BOOL inherit, LPCWSTR name )
|
|
|
|
{
|
2004-12-02 18:05:37 +00:00
|
|
|
HANDLE handle;
|
|
|
|
UNICODE_STRING nameW;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
NTSTATUS status;
|
2003-05-20 04:14:45 +00:00
|
|
|
|
2005-01-03 14:43:15 +00:00
|
|
|
if (!is_version_nt()) access = TIMER_ALL_ACCESS;
|
2004-12-02 18:05:37 +00:00
|
|
|
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.ObjectName = NULL;
|
|
|
|
attr.Attributes = inherit ? OBJ_INHERIT : 0;
|
|
|
|
attr.SecurityDescriptor = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
RtlInitUnicodeString( &nameW, name );
|
|
|
|
attr.ObjectName = &nameW;
|
|
|
|
}
|
2003-05-20 04:14:45 +00:00
|
|
|
|
2004-12-02 18:05:37 +00:00
|
|
|
status = NtOpenTimer(&handle, access, &attr);
|
2003-05-20 04:14:45 +00:00
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetWaitableTimer (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetWaitableTimer( HANDLE handle, const LARGE_INTEGER *when, LONG period,
|
|
|
|
PTIMERAPCROUTINE callback, LPVOID arg, BOOL resume )
|
|
|
|
{
|
2005-06-10 19:33:47 +00:00
|
|
|
NTSTATUS status = NtSetTimer(handle, when, (PTIMER_APC_ROUTINE)callback,
|
|
|
|
arg, resume, period, NULL);
|
2003-05-20 04:14:45 +00:00
|
|
|
|
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
if (status != STATUS_TIMER_RESUME_IGNORED) return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CancelWaitableTimer (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI CancelWaitableTimer( HANDLE handle )
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
status = NtCancelTimer(handle, NULL);
|
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CreateTimerQueue (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateTimerQueue(void)
|
|
|
|
{
|
|
|
|
FIXME("stub\n");
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DeleteTimerQueueEx (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DeleteTimerQueueEx(HANDLE TimerQueue, HANDLE CompletionEvent)
|
|
|
|
{
|
|
|
|
FIXME("(%p, %p): stub\n", TimerQueue, CompletionEvent);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CreateTimerQueueTimer (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* Creates a timer-queue timer. This timer expires at the specified due
|
|
|
|
* time (in ms), then after every specified period (in ms). When the timer
|
|
|
|
* expires, the callback function is called.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* nonzero on success or zero on faillure
|
|
|
|
*
|
|
|
|
* BUGS
|
|
|
|
* Unimplemented
|
|
|
|
*/
|
|
|
|
BOOL WINAPI CreateTimerQueueTimer( PHANDLE phNewTimer, HANDLE TimerQueue,
|
|
|
|
WAITORTIMERCALLBACK Callback, PVOID Parameter,
|
|
|
|
DWORD DueTime, DWORD Period, ULONG Flags )
|
|
|
|
{
|
|
|
|
FIXME("stub\n");
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DeleteTimerQueueTimer (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* Cancels a timer-queue timer.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* nonzero on success or zero on faillure
|
|
|
|
*
|
|
|
|
* BUGS
|
|
|
|
* Unimplemented
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DeleteTimerQueueTimer( HANDLE TimerQueue, HANDLE Timer,
|
|
|
|
HANDLE CompletionEvent )
|
|
|
|
{
|
|
|
|
FIXME("stub\n");
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-29 20:48:04 +00:00
|
|
|
/*
|
|
|
|
* Pipes
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 20:13:18 +00:00
|
|
|
* CreateNamedPipeA (KERNEL32.@)
|
2000-09-29 20:48:04 +00:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateNamedPipeA( LPCSTR name, DWORD dwOpenMode,
|
|
|
|
DWORD dwPipeMode, DWORD nMaxInstances,
|
|
|
|
DWORD nOutBufferSize, DWORD nInBufferSize,
|
|
|
|
DWORD nDefaultTimeOut, LPSECURITY_ATTRIBUTES attr )
|
|
|
|
{
|
2001-11-30 18:46:42 +00:00
|
|
|
WCHAR buffer[MAX_PATH];
|
2001-07-10 19:16:49 +00:00
|
|
|
|
2001-11-30 18:46:42 +00:00
|
|
|
if (!name) return CreateNamedPipeW( NULL, dwOpenMode, dwPipeMode, nMaxInstances,
|
|
|
|
nOutBufferSize, nInBufferSize, nDefaultTimeOut, attr );
|
2001-07-10 19:16:49 +00:00
|
|
|
|
2001-11-30 18:46:42 +00:00
|
|
|
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
|
2001-07-10 19:16:49 +00:00
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
2003-05-06 00:19:59 +00:00
|
|
|
return INVALID_HANDLE_VALUE;
|
2001-07-10 19:16:49 +00:00
|
|
|
}
|
2001-11-30 18:46:42 +00:00
|
|
|
return CreateNamedPipeW( buffer, dwOpenMode, dwPipeMode, nMaxInstances,
|
|
|
|
nOutBufferSize, nInBufferSize, nDefaultTimeOut, attr );
|
2000-09-29 20:48:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 20:13:18 +00:00
|
|
|
* CreateNamedPipeW (KERNEL32.@)
|
2000-09-29 20:48:04 +00:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateNamedPipeW( LPCWSTR name, DWORD dwOpenMode,
|
|
|
|
DWORD dwPipeMode, DWORD nMaxInstances,
|
|
|
|
DWORD nOutBufferSize, DWORD nInBufferSize,
|
2005-04-18 14:57:04 +00:00
|
|
|
DWORD nDefaultTimeOut, LPSECURITY_ATTRIBUTES sa )
|
2000-09-29 20:48:04 +00:00
|
|
|
{
|
2005-04-18 14:57:04 +00:00
|
|
|
HANDLE handle;
|
2004-04-30 21:03:09 +00:00
|
|
|
UNICODE_STRING nt_name;
|
2005-04-18 14:57:04 +00:00
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
DWORD options;
|
|
|
|
BOOLEAN pipe_type, read_mode, non_block;
|
|
|
|
NTSTATUS status;
|
|
|
|
IO_STATUS_BLOCK iosb;
|
|
|
|
LARGE_INTEGER timeout;
|
2001-07-10 19:16:49 +00:00
|
|
|
|
|
|
|
TRACE("(%s, %#08lx, %#08lx, %ld, %ld, %ld, %ld, %p)\n",
|
2000-09-29 20:48:04 +00:00
|
|
|
debugstr_w(name), dwOpenMode, dwPipeMode, nMaxInstances,
|
2005-04-18 14:57:04 +00:00
|
|
|
nOutBufferSize, nInBufferSize, nDefaultTimeOut, sa );
|
2000-09-29 20:48:04 +00:00
|
|
|
|
2004-04-30 21:03:09 +00:00
|
|
|
if (!RtlDosPathNameToNtPathName_U( name, &nt_name, NULL, NULL ))
|
2003-02-19 22:06:36 +00:00
|
|
|
{
|
|
|
|
SetLastError( ERROR_PATH_NOT_FOUND );
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
2004-04-30 21:03:09 +00:00
|
|
|
if (nt_name.Length >= MAX_PATH * sizeof(WCHAR) )
|
2001-07-10 19:16:49 +00:00
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
2004-04-30 21:03:09 +00:00
|
|
|
RtlFreeUnicodeString( &nt_name );
|
2003-02-19 22:06:36 +00:00
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
2005-04-18 14:57:04 +00:00
|
|
|
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.ObjectName = &nt_name;
|
|
|
|
attr.Attributes = (sa && sa->bInheritHandle) ? OBJ_INHERIT : 0;
|
|
|
|
attr.SecurityDescriptor = sa ? sa->lpSecurityDescriptor : NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
|
|
|
|
options = 0;
|
|
|
|
if (dwOpenMode & FILE_FLAG_WRITE_THROUGH) options |= FILE_WRITE_THROUGH;
|
|
|
|
if (!(dwOpenMode & FILE_FLAG_OVERLAPPED)) options |= FILE_SYNCHRONOUS_IO_ALERT;
|
|
|
|
if ((dwOpenMode & PIPE_ACCESS_DUPLEX) == PIPE_ACCESS_DUPLEX)
|
|
|
|
options |= FILE_PIPE_FULL_DUPLEX;
|
|
|
|
else if (dwOpenMode & PIPE_ACCESS_INBOUND) options |= FILE_PIPE_INBOUND;
|
|
|
|
else if (dwOpenMode & PIPE_ACCESS_OUTBOUND) options |= FILE_PIPE_OUTBOUND;
|
|
|
|
pipe_type = (dwPipeMode & PIPE_TYPE_MESSAGE) ? TRUE : FALSE;
|
|
|
|
read_mode = (dwPipeMode & PIPE_READMODE_MESSAGE) ? TRUE : FALSE;
|
|
|
|
non_block = (dwPipeMode & PIPE_NOWAIT) ? TRUE : FALSE;
|
2005-04-20 12:51:26 +00:00
|
|
|
if (nMaxInstances >= PIPE_UNLIMITED_INSTANCES) nMaxInstances = ~0UL;
|
2005-04-18 14:57:04 +00:00
|
|
|
|
|
|
|
timeout.QuadPart = (ULONGLONG)nDefaultTimeOut * -10000;
|
|
|
|
|
|
|
|
SetLastError(0);
|
|
|
|
|
|
|
|
status = NtCreateNamedPipeFile(&handle, 0, &attr, &iosb, 0, FILE_OVERWRITE_IF,
|
|
|
|
options, pipe_type, read_mode, non_block,
|
|
|
|
nMaxInstances, nInBufferSize, nOutBufferSize,
|
|
|
|
&timeout);
|
|
|
|
|
|
|
|
RtlFreeUnicodeString( &nt_name );
|
|
|
|
if (status)
|
2001-07-10 19:16:49 +00:00
|
|
|
{
|
2005-04-18 14:57:04 +00:00
|
|
|
handle = INVALID_HANDLE_VALUE;
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
2001-07-10 19:16:49 +00:00
|
|
|
}
|
2005-04-18 14:57:04 +00:00
|
|
|
return handle;
|
2000-09-29 20:48:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 20:13:18 +00:00
|
|
|
* PeekNamedPipe (KERNEL32.@)
|
2000-09-29 20:48:04 +00:00
|
|
|
*/
|
|
|
|
BOOL WINAPI PeekNamedPipe( HANDLE hPipe, LPVOID lpvBuffer, DWORD cbBuffer,
|
|
|
|
LPDWORD lpcbRead, LPDWORD lpcbAvail, LPDWORD lpcbMessage )
|
|
|
|
{
|
2002-07-31 20:04:20 +00:00
|
|
|
#ifdef FIONREAD
|
2003-12-02 04:19:56 +00:00
|
|
|
int avail=0, fd, ret, flags;
|
2002-07-25 00:22:03 +00:00
|
|
|
|
2005-03-22 18:23:44 +00:00
|
|
|
TRACE("(%p,%p,%lu,%p,%p,%p)\n", hPipe, lpvBuffer, cbBuffer, lpcbRead, lpcbAvail, lpcbMessage);
|
|
|
|
|
2004-08-18 00:04:58 +00:00
|
|
|
ret = wine_server_handle_to_fd( hPipe, GENERIC_READ, &fd, &flags );
|
2003-12-02 04:19:56 +00:00
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(ret) );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (flags & FD_FLAG_RECV_SHUTDOWN)
|
|
|
|
{
|
|
|
|
wine_server_release_fd( hPipe, fd );
|
|
|
|
SetLastError ( ERROR_PIPE_NOT_CONNECTED );
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-09-04 23:34:03 +00:00
|
|
|
|
2002-07-25 00:22:03 +00:00
|
|
|
if (ioctl(fd,FIONREAD, &avail ) != 0)
|
2002-09-04 23:34:03 +00:00
|
|
|
{
|
|
|
|
TRACE("FIONREAD failed reason: %s\n",strerror(errno));
|
2003-12-02 04:19:56 +00:00
|
|
|
wine_server_release_fd( hPipe, fd );
|
2002-09-04 23:34:03 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!avail) /* check for closed pipe */
|
|
|
|
{
|
|
|
|
struct pollfd pollfd;
|
|
|
|
pollfd.fd = fd;
|
|
|
|
pollfd.events = POLLIN;
|
|
|
|
pollfd.revents = 0;
|
|
|
|
switch (poll( &pollfd, 1, 0 ))
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case 1: /* got something */
|
|
|
|
if (!(pollfd.revents & (POLLHUP | POLLERR))) break;
|
|
|
|
TRACE("POLLHUP | POLLERR\n");
|
|
|
|
/* fall through */
|
|
|
|
case -1:
|
2003-12-02 04:19:56 +00:00
|
|
|
wine_server_release_fd( hPipe, fd );
|
2002-09-04 23:34:03 +00:00
|
|
|
SetLastError(ERROR_BROKEN_PIPE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2002-07-25 00:22:03 +00:00
|
|
|
TRACE(" 0x%08x bytes available\n", avail );
|
2004-02-12 20:03:53 +00:00
|
|
|
ret = TRUE;
|
|
|
|
if (lpcbAvail)
|
|
|
|
*lpcbAvail = avail;
|
|
|
|
if (lpcbRead)
|
|
|
|
*lpcbRead = 0;
|
2005-03-22 18:23:44 +00:00
|
|
|
if (avail && lpvBuffer && cbBuffer)
|
2004-02-12 20:03:53 +00:00
|
|
|
{
|
|
|
|
int readbytes = (avail < cbBuffer) ? avail : cbBuffer;
|
|
|
|
readbytes = recv(fd, lpvBuffer, readbytes, MSG_PEEK);
|
|
|
|
if (readbytes < 0)
|
|
|
|
{
|
|
|
|
WARN("failed to peek socket (%d)\n", errno);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
else if (lpcbRead)
|
|
|
|
*lpcbRead = readbytes;
|
|
|
|
}
|
|
|
|
wine_server_release_fd( hPipe, fd );
|
|
|
|
return ret;
|
2002-07-31 20:04:20 +00:00
|
|
|
#endif /* defined(FIONREAD) */
|
2002-07-25 00:22:03 +00:00
|
|
|
|
2000-09-29 20:48:04 +00:00
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
2002-07-25 00:22:03 +00:00
|
|
|
FIXME("function not implemented\n");
|
2000-09-29 20:48:04 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2001-11-07 20:14:45 +00:00
|
|
|
/***********************************************************************
|
2005-04-18 14:57:04 +00:00
|
|
|
* PIPE_CompletionWait (Internal)
|
2001-11-07 20:14:45 +00:00
|
|
|
*/
|
2005-04-18 14:57:04 +00:00
|
|
|
static void CALLBACK PIPE_CompletionWait(void *user, PIO_STATUS_BLOCK iosb, ULONG status)
|
2001-11-07 20:14:45 +00:00
|
|
|
{
|
2005-04-18 14:57:04 +00:00
|
|
|
LPOVERLAPPED ovlp = (LPOVERLAPPED)user;
|
2000-09-29 20:48:04 +00:00
|
|
|
|
2005-04-18 14:57:04 +00:00
|
|
|
TRACE("for %p/%p, status=%08lx\n", ovlp, iosb, status);
|
|
|
|
|
|
|
|
if (ovlp)
|
|
|
|
{
|
|
|
|
ovlp->Internal = status;
|
|
|
|
SetEvent(ovlp->hEvent);
|
|
|
|
}
|
|
|
|
TRACE("done\n");
|
|
|
|
}
|
2001-11-07 20:14:45 +00:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WaitNamedPipeA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI WaitNamedPipeA (LPCSTR name, DWORD nTimeOut)
|
|
|
|
{
|
2001-11-30 18:46:42 +00:00
|
|
|
WCHAR buffer[MAX_PATH];
|
2001-11-07 20:14:45 +00:00
|
|
|
|
2001-11-30 18:46:42 +00:00
|
|
|
if (!name) return WaitNamedPipeW( NULL, nTimeOut );
|
2001-08-23 23:29:20 +00:00
|
|
|
|
2001-11-30 18:46:42 +00:00
|
|
|
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
|
2001-11-07 20:14:45 +00:00
|
|
|
{
|
2001-11-30 18:46:42 +00:00
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
2001-11-07 20:14:45 +00:00
|
|
|
}
|
2001-11-30 18:46:42 +00:00
|
|
|
return WaitNamedPipeW( buffer, nTimeOut );
|
2000-09-29 20:48:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 20:13:18 +00:00
|
|
|
* WaitNamedPipeW (KERNEL32.@)
|
2000-09-29 20:48:04 +00:00
|
|
|
*/
|
2001-11-30 18:46:42 +00:00
|
|
|
BOOL WINAPI WaitNamedPipeW (LPCWSTR name, DWORD nTimeOut)
|
2000-09-29 20:48:04 +00:00
|
|
|
{
|
2001-08-23 23:29:20 +00:00
|
|
|
BOOL ret;
|
2001-11-30 18:46:42 +00:00
|
|
|
OVERLAPPED ov;
|
2004-06-14 17:00:21 +00:00
|
|
|
UNICODE_STRING nt_name;
|
|
|
|
static const WCHAR leadin[] = {'\\','?','?','\\','P','I','P','E','\\'};
|
2001-08-23 23:29:20 +00:00
|
|
|
|
2004-06-14 17:00:21 +00:00
|
|
|
TRACE("%s 0x%08lx\n",debugstr_w(name),nTimeOut);
|
|
|
|
|
|
|
|
if (!RtlDosPathNameToNtPathName_U( name, &nt_name, NULL, NULL ))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (nt_name.Length >= MAX_PATH * sizeof(WCHAR) )
|
2001-08-23 23:29:20 +00:00
|
|
|
{
|
2004-06-14 17:00:21 +00:00
|
|
|
RtlFreeUnicodeString( &nt_name );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (nt_name.Length < sizeof(leadin) ||
|
|
|
|
strncmpiW( nt_name.Buffer, leadin, sizeof(leadin)/sizeof(leadin[0])))
|
|
|
|
{
|
|
|
|
RtlFreeUnicodeString( &nt_name );
|
2001-08-23 23:29:20 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2001-07-10 19:16:49 +00:00
|
|
|
|
2003-06-18 19:45:22 +00:00
|
|
|
memset(&ov,0,sizeof(ov));
|
2004-03-29 20:26:39 +00:00
|
|
|
ov.hEvent = CreateEventW( NULL, 0, 0, NULL );
|
2001-11-07 20:14:45 +00:00
|
|
|
if (!ov.hEvent)
|
2001-07-10 19:16:49 +00:00
|
|
|
return FALSE;
|
2001-11-07 20:14:45 +00:00
|
|
|
|
2001-11-30 18:46:42 +00:00
|
|
|
SERVER_START_REQ( wait_named_pipe )
|
|
|
|
{
|
|
|
|
req->timeout = nTimeOut;
|
|
|
|
req->overlapped = &ov;
|
2005-04-18 14:57:04 +00:00
|
|
|
req->func = PIPE_CompletionWait;
|
2004-06-14 17:00:21 +00:00
|
|
|
wine_server_add_data( req, nt_name.Buffer + 4, nt_name.Length - 4*sizeof(WCHAR) );
|
2001-11-30 18:46:42 +00:00
|
|
|
ret = !wine_server_call_err( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
2004-06-14 17:00:21 +00:00
|
|
|
RtlFreeUnicodeString( &nt_name );
|
|
|
|
|
2001-11-07 20:14:45 +00:00
|
|
|
if(ret)
|
|
|
|
{
|
|
|
|
if (WAIT_OBJECT_0==WaitForSingleObject(ov.hEvent,INFINITE))
|
|
|
|
{
|
2005-02-08 12:08:04 +00:00
|
|
|
SetLastError(RtlNtStatusToDosError(ov.Internal));
|
2001-11-07 20:14:45 +00:00
|
|
|
ret = (ov.Internal==STATUS_SUCCESS);
|
|
|
|
}
|
2001-07-10 19:16:49 +00:00
|
|
|
}
|
2001-11-07 20:14:45 +00:00
|
|
|
CloseHandle(ov.hEvent);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2005-04-18 14:57:04 +00:00
|
|
|
* ConnectNamedPipe (KERNEL32.@)
|
2001-11-07 20:14:45 +00:00
|
|
|
*/
|
2005-04-18 14:57:04 +00:00
|
|
|
BOOL WINAPI ConnectNamedPipe(HANDLE hPipe, LPOVERLAPPED overlapped)
|
2001-11-07 20:14:45 +00:00
|
|
|
{
|
2005-04-18 14:57:04 +00:00
|
|
|
BOOL ret;
|
|
|
|
LPOVERLAPPED pov;
|
|
|
|
OVERLAPPED ov;
|
2001-11-07 20:14:45 +00:00
|
|
|
|
2005-04-18 14:57:04 +00:00
|
|
|
TRACE("(%p,%p)\n", hPipe, overlapped);
|
2001-11-07 20:14:45 +00:00
|
|
|
|
2005-04-18 14:57:04 +00:00
|
|
|
if (!overlapped)
|
|
|
|
{
|
|
|
|
memset(&ov, 0, sizeof(ov));
|
|
|
|
ov.hEvent = CreateEventW(NULL, 0, 0, NULL);
|
|
|
|
if (!ov.hEvent) return FALSE;
|
|
|
|
pov = &ov;
|
|
|
|
}
|
|
|
|
else pov = overlapped;
|
|
|
|
|
|
|
|
pov->Internal = STATUS_PENDING;
|
2001-07-10 19:16:49 +00:00
|
|
|
|
|
|
|
SERVER_START_REQ( connect_named_pipe )
|
|
|
|
{
|
|
|
|
req->handle = hPipe;
|
2005-04-18 14:57:04 +00:00
|
|
|
req->overlapped = pov;
|
|
|
|
req->func = PIPE_CompletionWait;
|
2001-11-30 18:46:42 +00:00
|
|
|
ret = !wine_server_call_err( req );
|
2001-07-10 19:16:49 +00:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
2005-04-18 14:57:04 +00:00
|
|
|
if (ret)
|
2003-06-06 18:10:36 +00:00
|
|
|
{
|
2005-04-18 14:57:04 +00:00
|
|
|
if (overlapped)
|
|
|
|
{
|
2003-06-06 18:10:36 +00:00
|
|
|
SetLastError( ERROR_IO_PENDING );
|
2005-04-18 14:57:04 +00:00
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
else
|
2001-11-07 20:14:45 +00:00
|
|
|
{
|
2005-04-18 14:57:04 +00:00
|
|
|
ret = GetOverlappedResult(hPipe, &ov, NULL, TRUE);
|
|
|
|
CloseHandle(ov.hEvent);
|
2001-11-07 20:14:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-23 23:29:20 +00:00
|
|
|
return ret;
|
2001-07-10 19:16:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DisconnectNamedPipe (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DisconnectNamedPipe(HANDLE hPipe)
|
|
|
|
{
|
2001-08-23 23:29:20 +00:00
|
|
|
BOOL ret;
|
|
|
|
|
2002-10-25 21:02:30 +00:00
|
|
|
TRACE("(%p)\n",hPipe);
|
2001-08-23 23:29:20 +00:00
|
|
|
|
|
|
|
SERVER_START_REQ( disconnect_named_pipe )
|
|
|
|
{
|
|
|
|
req->handle = hPipe;
|
2001-11-30 18:46:42 +00:00
|
|
|
ret = !wine_server_call_err( req );
|
2003-05-15 04:22:45 +00:00
|
|
|
if (ret && reply->fd != -1) close( reply->fd );
|
2001-08-23 23:29:20 +00:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
|
|
|
return ret;
|
2001-07-10 19:16:49 +00:00
|
|
|
}
|
|
|
|
|
2001-08-24 19:15:35 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* TransactNamedPipe (KERNEL32.@)
|
2005-01-19 17:00:48 +00:00
|
|
|
*
|
|
|
|
* BUGS
|
|
|
|
* should be done as a single operation in the wineserver or kernel
|
2001-08-24 19:15:35 +00:00
|
|
|
*/
|
|
|
|
BOOL WINAPI TransactNamedPipe(
|
2005-01-19 17:00:48 +00:00
|
|
|
HANDLE handle, LPVOID lpInput, DWORD dwInputSize, LPVOID lpOutput,
|
2001-08-24 19:15:35 +00:00
|
|
|
DWORD dwOutputSize, LPDWORD lpBytesRead, LPOVERLAPPED lpOverlapped)
|
|
|
|
{
|
2005-01-19 17:00:48 +00:00
|
|
|
BOOL r;
|
|
|
|
DWORD count;
|
|
|
|
|
|
|
|
TRACE("%p %p %ld %p %ld %p %p\n",
|
|
|
|
handle, lpInput, dwInputSize, lpOutput,
|
2001-08-24 19:15:35 +00:00
|
|
|
dwOutputSize, lpBytesRead, lpOverlapped);
|
2005-01-19 17:00:48 +00:00
|
|
|
|
|
|
|
if (lpOverlapped)
|
|
|
|
{
|
|
|
|
FIXME("Doesn't support overlapped operation as yet\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = WriteFile(handle, lpOutput, dwOutputSize, &count, NULL);
|
|
|
|
if (r)
|
|
|
|
r = ReadFile(handle, lpInput, dwInputSize, lpBytesRead, NULL);
|
|
|
|
|
|
|
|
return r;
|
2001-08-24 19:15:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetNamedPipeInfo (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetNamedPipeInfo(
|
|
|
|
HANDLE hNamedPipe, LPDWORD lpFlags, LPDWORD lpOutputBufferSize,
|
|
|
|
LPDWORD lpInputBufferSize, LPDWORD lpMaxInstances)
|
|
|
|
{
|
2001-08-27 19:03:42 +00:00
|
|
|
BOOL ret;
|
|
|
|
|
2002-10-25 21:02:30 +00:00
|
|
|
TRACE("%p %p %p %p %p\n", hNamedPipe, lpFlags,
|
2001-08-24 19:15:35 +00:00
|
|
|
lpOutputBufferSize, lpInputBufferSize, lpMaxInstances);
|
2001-08-27 19:03:42 +00:00
|
|
|
|
|
|
|
SERVER_START_REQ( get_named_pipe_info )
|
|
|
|
{
|
|
|
|
req->handle = hNamedPipe;
|
2001-11-30 18:46:42 +00:00
|
|
|
ret = !wine_server_call_err( req );
|
2005-04-18 14:57:04 +00:00
|
|
|
if (lpFlags)
|
|
|
|
{
|
|
|
|
*lpFlags = 0;
|
|
|
|
if (reply->flags & NAMED_PIPE_MESSAGE_STREAM_WRITE)
|
|
|
|
*lpFlags |= PIPE_TYPE_MESSAGE;
|
|
|
|
if (reply->flags & NAMED_PIPE_MESSAGE_STREAM_READ)
|
|
|
|
*lpFlags |= PIPE_READMODE_MESSAGE;
|
|
|
|
if (reply->flags & NAMED_PIPE_NONBLOCKING_MODE)
|
|
|
|
*lpFlags |= PIPE_NOWAIT;
|
|
|
|
}
|
|
|
|
if (lpOutputBufferSize) *lpOutputBufferSize = reply->outsize;
|
|
|
|
if (lpInputBufferSize) *lpInputBufferSize = reply->outsize;
|
|
|
|
if (lpMaxInstances) *lpMaxInstances = reply->maxinstances;
|
2001-08-27 19:03:42 +00:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
|
|
|
return ret;
|
2001-08-24 19:15:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetNamedPipeHandleStateA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetNamedPipeHandleStateA(
|
|
|
|
HANDLE hNamedPipe, LPDWORD lpState, LPDWORD lpCurInstances,
|
|
|
|
LPDWORD lpMaxCollectionCount, LPDWORD lpCollectDataTimeout,
|
|
|
|
LPSTR lpUsername, DWORD nUsernameMaxSize)
|
|
|
|
{
|
2002-10-25 21:02:30 +00:00
|
|
|
FIXME("%p %p %p %p %p %p %ld\n",
|
2001-08-24 19:15:35 +00:00
|
|
|
hNamedPipe, lpState, lpCurInstances,
|
|
|
|
lpMaxCollectionCount, lpCollectDataTimeout,
|
|
|
|
lpUsername, nUsernameMaxSize);
|
2002-05-31 23:06:46 +00:00
|
|
|
|
2001-08-24 19:15:35 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetNamedPipeHandleStateW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetNamedPipeHandleStateW(
|
|
|
|
HANDLE hNamedPipe, LPDWORD lpState, LPDWORD lpCurInstances,
|
|
|
|
LPDWORD lpMaxCollectionCount, LPDWORD lpCollectDataTimeout,
|
|
|
|
LPWSTR lpUsername, DWORD nUsernameMaxSize)
|
|
|
|
{
|
2002-10-25 21:02:30 +00:00
|
|
|
FIXME("%p %p %p %p %p %p %ld\n",
|
2001-08-24 19:15:35 +00:00
|
|
|
hNamedPipe, lpState, lpCurInstances,
|
|
|
|
lpMaxCollectionCount, lpCollectDataTimeout,
|
|
|
|
lpUsername, nUsernameMaxSize);
|
2002-05-31 23:06:46 +00:00
|
|
|
|
2001-08-24 19:15:35 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetNamedPipeHandleState (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetNamedPipeHandleState(
|
|
|
|
HANDLE hNamedPipe, LPDWORD lpMode, LPDWORD lpMaxCollectionCount,
|
|
|
|
LPDWORD lpCollectDataTimeout)
|
|
|
|
{
|
2005-06-05 18:03:38 +00:00
|
|
|
/* should be a fixme, but this function is called a lot by the RPC
|
|
|
|
* runtime, and it slows down InstallShield a fair bit. */
|
|
|
|
WARN("stub: %p %p/%ld %p %p\n",
|
|
|
|
hNamedPipe, lpMode, lpMode ? *lpMode : 0, lpMaxCollectionCount, lpCollectDataTimeout);
|
2001-08-24 19:15:35 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CallNamedPipeA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI CallNamedPipeA(
|
2004-10-19 21:08:58 +00:00
|
|
|
LPCSTR lpNamedPipeName, LPVOID lpInput, DWORD dwInputSize,
|
|
|
|
LPVOID lpOutput, DWORD dwOutputSize,
|
2001-08-24 19:15:35 +00:00
|
|
|
LPDWORD lpBytesRead, DWORD nTimeout)
|
|
|
|
{
|
2004-10-19 21:08:58 +00:00
|
|
|
DWORD len;
|
|
|
|
LPWSTR str = NULL;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
TRACE("%s %p %ld %p %ld %p %ld\n",
|
|
|
|
debugstr_a(lpNamedPipeName), lpInput, dwInputSize,
|
|
|
|
lpOutput, dwOutputSize, lpBytesRead, nTimeout);
|
|
|
|
|
|
|
|
if( lpNamedPipeName )
|
|
|
|
{
|
|
|
|
len = MultiByteToWideChar( CP_ACP, 0, lpNamedPipeName, -1, NULL, 0 );
|
|
|
|
str = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, lpNamedPipeName, -1, str, len );
|
|
|
|
}
|
|
|
|
ret = CallNamedPipeW( str, lpInput, dwInputSize, lpOutput,
|
|
|
|
dwOutputSize, lpBytesRead, nTimeout );
|
|
|
|
if( lpNamedPipeName )
|
|
|
|
HeapFree( GetProcessHeap(), 0, str );
|
|
|
|
|
|
|
|
return ret;
|
2001-08-24 19:15:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CallNamedPipeW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI CallNamedPipeW(
|
|
|
|
LPCWSTR lpNamedPipeName, LPVOID lpInput, DWORD lpInputSize,
|
|
|
|
LPVOID lpOutput, DWORD lpOutputSize,
|
|
|
|
LPDWORD lpBytesRead, DWORD nTimeout)
|
|
|
|
{
|
|
|
|
FIXME("%s %p %ld %p %ld %p %ld\n",
|
|
|
|
debugstr_w(lpNamedPipeName), lpInput, lpInputSize,
|
|
|
|
lpOutput, lpOutputSize, lpBytesRead, nTimeout);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-05-20 04:32:53 +00:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* CreatePipe (KERNEL32.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI CreatePipe( PHANDLE hReadPipe, PHANDLE hWritePipe,
|
|
|
|
LPSECURITY_ATTRIBUTES sa, DWORD size )
|
|
|
|
{
|
|
|
|
static unsigned index = 0;
|
2004-12-07 14:23:03 +00:00
|
|
|
WCHAR name[64];
|
2003-05-20 04:32:53 +00:00
|
|
|
HANDLE hr, hw;
|
|
|
|
unsigned in_index = index;
|
|
|
|
|
|
|
|
*hReadPipe = *hWritePipe = INVALID_HANDLE_VALUE;
|
|
|
|
/* generate a unique pipe name (system wide) */
|
|
|
|
do
|
|
|
|
{
|
2004-12-07 14:23:03 +00:00
|
|
|
static const WCHAR nameFmt[] = { '\\','\\','.','\\','p','i','p','e',
|
|
|
|
'\\','W','i','n','3','2','.','P','i','p','e','s','.','%','0','8','l',
|
|
|
|
'u','.','%','0','8','u','\0' };
|
|
|
|
snprintfW(name, sizeof(name) / sizeof(name[0]), nameFmt,
|
|
|
|
GetCurrentProcessId(), ++index);
|
|
|
|
hr = CreateNamedPipeW(name, PIPE_ACCESS_INBOUND,
|
2003-05-20 04:32:53 +00:00
|
|
|
PIPE_TYPE_BYTE | PIPE_WAIT, 1, size, size,
|
|
|
|
NMPWAIT_USE_DEFAULT_WAIT, sa);
|
|
|
|
} while (hr == INVALID_HANDLE_VALUE && index != in_index);
|
|
|
|
/* from completion sakeness, I think system resources might be exhausted before this happens !! */
|
|
|
|
if (hr == INVALID_HANDLE_VALUE) return FALSE;
|
|
|
|
|
2004-12-07 14:23:03 +00:00
|
|
|
hw = CreateFileW(name, GENERIC_WRITE, 0, sa, OPEN_EXISTING, 0, 0);
|
2003-05-20 04:32:53 +00:00
|
|
|
if (hw == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
CloseHandle(hr);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*hReadPipe = hr;
|
|
|
|
*hWritePipe = hw;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2003-06-24 03:34:15 +00:00
|
|
|
|
|
|
|
|
2003-09-15 22:07:50 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* CreateMailslotA [KERNEL32.@]
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateMailslotA( LPCSTR lpName, DWORD nMaxMessageSize,
|
|
|
|
DWORD lReadTimeout, LPSECURITY_ATTRIBUTES sa )
|
|
|
|
{
|
|
|
|
DWORD len;
|
|
|
|
HANDLE handle;
|
|
|
|
LPWSTR name = NULL;
|
|
|
|
|
|
|
|
TRACE("%s %ld %ld %p\n", debugstr_a(lpName),
|
|
|
|
nMaxMessageSize, lReadTimeout, sa);
|
|
|
|
|
|
|
|
if( lpName )
|
|
|
|
{
|
|
|
|
len = MultiByteToWideChar( CP_ACP, 0, lpName, -1, NULL, 0 );
|
|
|
|
name = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, lpName, -1, name, len );
|
|
|
|
}
|
|
|
|
|
|
|
|
handle = CreateMailslotW( name, nMaxMessageSize, lReadTimeout, sa );
|
|
|
|
|
2004-12-23 17:06:43 +00:00
|
|
|
HeapFree( GetProcessHeap(), 0, name );
|
2003-09-15 22:07:50 +00:00
|
|
|
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
2003-09-17 20:05:03 +00:00
|
|
|
* CreateMailslotW [KERNEL32.@]
|
|
|
|
*
|
|
|
|
* Create a mailslot with specified name.
|
2003-09-15 22:07:50 +00:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpName [I] Pointer to string for mailslot name
|
|
|
|
* nMaxMessageSize [I] Maximum message size
|
|
|
|
* lReadTimeout [I] Milliseconds before read time-out
|
|
|
|
* sa [I] Pointer to security structure
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: Handle to mailslot
|
|
|
|
* Failure: INVALID_HANDLE_VALUE
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateMailslotW( LPCWSTR lpName, DWORD nMaxMessageSize,
|
|
|
|
DWORD lReadTimeout, LPSECURITY_ATTRIBUTES sa )
|
|
|
|
{
|
2005-03-28 10:03:56 +00:00
|
|
|
HANDLE handle = INVALID_HANDLE_VALUE;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
UNICODE_STRING nameW;
|
|
|
|
LARGE_INTEGER timeout;
|
|
|
|
IO_STATUS_BLOCK iosb;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
TRACE("%s %ld %ld %p\n", debugstr_w(lpName),
|
2003-09-15 22:07:50 +00:00
|
|
|
nMaxMessageSize, lReadTimeout, sa);
|
2005-03-28 10:03:56 +00:00
|
|
|
|
|
|
|
if (!RtlDosPathNameToNtPathName_U( lpName, &nameW, NULL, NULL ))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_PATH_NOT_FOUND );
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nameW.Length >= MAX_PATH * sizeof(WCHAR) )
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
RtlFreeUnicodeString( &nameW );
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.Attributes = OBJ_CASE_INSENSITIVE;
|
|
|
|
attr.ObjectName = &nameW;
|
|
|
|
attr.SecurityDescriptor = sa ? sa->lpSecurityDescriptor : NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
|
|
|
|
timeout.QuadPart = (ULONGLONG) lReadTimeout * -10000;
|
|
|
|
|
|
|
|
status = NtCreateMailslotFile( &handle, GENERIC_READ | GENERIC_WRITE, &attr,
|
|
|
|
&iosb, 0, 0, nMaxMessageSize, &timeout );
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
handle = INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RtlFreeUnicodeString( &nameW );
|
|
|
|
return handle;
|
2003-09-15 22:07:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
2003-09-17 20:05:03 +00:00
|
|
|
* GetMailslotInfo [KERNEL32.@]
|
|
|
|
*
|
|
|
|
* Retrieve information about a mailslot.
|
2003-09-15 22:07:50 +00:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hMailslot [I] Mailslot handle
|
|
|
|
* lpMaxMessageSize [O] Address of maximum message size
|
|
|
|
* lpNextSize [O] Address of size of next message
|
|
|
|
* lpMessageCount [O] Address of number of messages
|
|
|
|
* lpReadTimeout [O] Address of read time-out
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetMailslotInfo( HANDLE hMailslot, LPDWORD lpMaxMessageSize,
|
|
|
|
LPDWORD lpNextSize, LPDWORD lpMessageCount,
|
|
|
|
LPDWORD lpReadTimeout )
|
|
|
|
{
|
2005-04-11 14:20:49 +00:00
|
|
|
FILE_MAILSLOT_QUERY_INFORMATION info;
|
|
|
|
IO_STATUS_BLOCK iosb;
|
|
|
|
NTSTATUS status;
|
2005-03-30 19:02:15 +00:00
|
|
|
|
2005-04-11 14:20:49 +00:00
|
|
|
TRACE("%p %p %p %p %p\n",hMailslot, lpMaxMessageSize,
|
|
|
|
lpNextSize, lpMessageCount, lpReadTimeout);
|
2005-03-30 19:02:15 +00:00
|
|
|
|
2005-04-11 14:20:49 +00:00
|
|
|
status = NtQueryInformationFile( hMailslot, &iosb, &info, sizeof info,
|
|
|
|
FileMailslotQueryInformation );
|
|
|
|
|
|
|
|
if( status != STATUS_SUCCESS )
|
2005-03-30 19:02:15 +00:00
|
|
|
{
|
2005-04-11 14:20:49 +00:00
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return FALSE;
|
2005-03-30 19:02:15 +00:00
|
|
|
}
|
|
|
|
|
2005-04-11 14:20:49 +00:00
|
|
|
if( lpMaxMessageSize )
|
|
|
|
*lpMaxMessageSize = info.MaximumMessageSize;
|
|
|
|
if( lpNextSize )
|
|
|
|
*lpNextSize = info.NextMessageSize;
|
|
|
|
if( lpMessageCount )
|
|
|
|
*lpMessageCount = info.MessagesAvailable;
|
|
|
|
if( lpReadTimeout )
|
|
|
|
*lpReadTimeout = info.ReadTimeout.QuadPart / -10000;
|
|
|
|
|
|
|
|
return TRUE;
|
2003-09-15 22:07:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
2003-09-17 20:05:03 +00:00
|
|
|
* SetMailslotInfo [KERNEL32.@]
|
|
|
|
*
|
|
|
|
* Set the read timeout of a mailslot.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hMailslot [I] Mailslot handle
|
|
|
|
* dwReadTimeout [I] Timeout in milliseconds.
|
2003-09-15 22:07:50 +00:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetMailslotInfo( HANDLE hMailslot, DWORD dwReadTimeout)
|
|
|
|
{
|
2005-04-11 14:20:49 +00:00
|
|
|
FILE_MAILSLOT_SET_INFORMATION info;
|
|
|
|
IO_STATUS_BLOCK iosb;
|
|
|
|
NTSTATUS status;
|
2005-03-30 19:02:15 +00:00
|
|
|
|
|
|
|
TRACE("%p %ld\n", hMailslot, dwReadTimeout);
|
|
|
|
|
2005-04-11 14:20:49 +00:00
|
|
|
info.ReadTimeout.QuadPart = dwReadTimeout * -10000;
|
|
|
|
status = NtSetInformationFile( hMailslot, &iosb, &info, sizeof info,
|
|
|
|
FileMailslotSetInformation );
|
|
|
|
if( status != STATUS_SUCCESS )
|
2005-03-30 19:02:15 +00:00
|
|
|
{
|
2005-04-11 14:20:49 +00:00
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return FALSE;
|
2005-03-30 19:02:15 +00:00
|
|
|
}
|
2005-04-11 14:20:49 +00:00
|
|
|
return TRUE;
|
2003-09-15 22:07:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-08 04:24:49 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* CreateIoCompletionPort (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateIoCompletionPort(HANDLE hFileHandle, HANDLE hExistingCompletionPort,
|
2004-10-19 23:55:15 +00:00
|
|
|
ULONG_PTR CompletionKey, DWORD dwNumberOfConcurrentThreads)
|
2003-10-08 04:24:49 +00:00
|
|
|
{
|
|
|
|
FIXME("(%p, %p, %08lx, %08lx): stub.\n",
|
2004-10-19 23:55:15 +00:00
|
|
|
hFileHandle, hExistingCompletionPort, CompletionKey, dwNumberOfConcurrentThreads);
|
2003-10-08 04:24:49 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* GetQueuedCompletionStatus (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetQueuedCompletionStatus( HANDLE CompletionPort, LPDWORD lpNumberOfBytesTransferred,
|
2004-10-19 23:55:15 +00:00
|
|
|
PULONG_PTR pCompletionKey, LPOVERLAPPED *lpOverlapped,
|
2003-10-08 04:24:49 +00:00
|
|
|
DWORD dwMilliseconds )
|
|
|
|
{
|
|
|
|
FIXME("(%p,%p,%p,%p,%ld), stub!\n",
|
2004-10-19 23:55:15 +00:00
|
|
|
CompletionPort,lpNumberOfBytesTransferred,pCompletionKey,lpOverlapped,dwMilliseconds);
|
2003-10-08 04:24:49 +00:00
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2003-11-03 22:12:15 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* CreateJobObjectW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateJobObjectW( LPSECURITY_ATTRIBUTES attr, LPCWSTR name )
|
|
|
|
{
|
|
|
|
FIXME("%p %s\n", attr, debugstr_w(name) );
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* CreateJobObjectA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateJobObjectA( LPSECURITY_ATTRIBUTES attr, LPCSTR name )
|
|
|
|
{
|
|
|
|
LPWSTR str = NULL;
|
|
|
|
UINT len;
|
|
|
|
HANDLE r;
|
|
|
|
|
|
|
|
TRACE("%p %s\n", attr, debugstr_a(name) );
|
|
|
|
|
|
|
|
if( name )
|
|
|
|
{
|
|
|
|
len = MultiByteToWideChar( CP_ACP, 0, name, -1, NULL, 0 );
|
|
|
|
str = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
|
|
|
|
if( !str )
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_OUTOFMEMORY );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
len = MultiByteToWideChar( CP_ACP, 0, name, -1, str, len );
|
|
|
|
}
|
|
|
|
|
|
|
|
r = CreateJobObjectW( attr, str );
|
|
|
|
|
2004-12-23 17:06:43 +00:00
|
|
|
HeapFree( GetProcessHeap(), 0, str );
|
2003-11-03 22:12:15 +00:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* AssignProcessToJobObject (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI AssignProcessToJobObject( HANDLE hJob, HANDLE hProcess )
|
|
|
|
{
|
|
|
|
FIXME("%p %p\n", hJob, hProcess);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-06-24 03:34:15 +00:00
|
|
|
#ifdef __i386__
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* InterlockedCompareExchange (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
/* LONG WINAPI InterlockedCompareExchange( PLONG dest, LONG xchg, LONG compare ); */
|
|
|
|
__ASM_GLOBAL_FUNC(InterlockedCompareExchange,
|
|
|
|
"movl 12(%esp),%eax\n\t"
|
|
|
|
"movl 8(%esp),%ecx\n\t"
|
|
|
|
"movl 4(%esp),%edx\n\t"
|
|
|
|
"lock; cmpxchgl %ecx,(%edx)\n\t"
|
2004-06-14 17:00:21 +00:00
|
|
|
"ret $12")
|
2003-06-24 03:34:15 +00:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* InterlockedExchange (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
/* LONG WINAPI InterlockedExchange( PLONG dest, LONG val ); */
|
|
|
|
__ASM_GLOBAL_FUNC(InterlockedExchange,
|
|
|
|
"movl 8(%esp),%eax\n\t"
|
|
|
|
"movl 4(%esp),%edx\n\t"
|
|
|
|
"lock; xchgl %eax,(%edx)\n\t"
|
2004-06-14 17:00:21 +00:00
|
|
|
"ret $8")
|
2003-06-24 03:34:15 +00:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* InterlockedExchangeAdd (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
/* LONG WINAPI InterlockedExchangeAdd( PLONG dest, LONG incr ); */
|
|
|
|
__ASM_GLOBAL_FUNC(InterlockedExchangeAdd,
|
|
|
|
"movl 8(%esp),%eax\n\t"
|
|
|
|
"movl 4(%esp),%edx\n\t"
|
|
|
|
"lock; xaddl %eax,(%edx)\n\t"
|
2004-06-14 17:00:21 +00:00
|
|
|
"ret $8")
|
2003-06-24 03:34:15 +00:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* InterlockedIncrement (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
/* LONG WINAPI InterlockedIncrement( PLONG dest ); */
|
|
|
|
__ASM_GLOBAL_FUNC(InterlockedIncrement,
|
|
|
|
"movl 4(%esp),%edx\n\t"
|
|
|
|
"movl $1,%eax\n\t"
|
|
|
|
"lock; xaddl %eax,(%edx)\n\t"
|
|
|
|
"incl %eax\n\t"
|
2004-06-14 17:00:21 +00:00
|
|
|
"ret $4")
|
2003-06-24 03:34:15 +00:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* InterlockedDecrement (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
__ASM_GLOBAL_FUNC(InterlockedDecrement,
|
|
|
|
"movl 4(%esp),%edx\n\t"
|
|
|
|
"movl $-1,%eax\n\t"
|
|
|
|
"lock; xaddl %eax,(%edx)\n\t"
|
|
|
|
"decl %eax\n\t"
|
2004-06-14 17:00:21 +00:00
|
|
|
"ret $4")
|
2003-06-24 03:34:15 +00:00
|
|
|
|
|
|
|
#else /* __i386__ */
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* InterlockedCompareExchange (KERNEL32.@)
|
2003-09-17 20:05:03 +00:00
|
|
|
*
|
|
|
|
* Atomically swap one value with another.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* dest [I/O] The value to replace
|
|
|
|
* xchq [I] The value to be swapped
|
|
|
|
* compare [I] The value to compare to dest
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The resulting value of dest.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* dest is updated only if it is equal to compare, otherwise no swap is done.
|
2003-06-24 03:34:15 +00:00
|
|
|
*/
|
|
|
|
LONG WINAPI InterlockedCompareExchange( PLONG dest, LONG xchg, LONG compare )
|
|
|
|
{
|
|
|
|
return interlocked_cmpxchg( dest, xchg, compare );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* InterlockedExchange (KERNEL32.@)
|
2003-09-17 20:05:03 +00:00
|
|
|
*
|
|
|
|
* Atomically swap one value with another.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* dest [I/O] The value to replace
|
|
|
|
* val [I] The value to be swapped
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The resulting value of dest.
|
2003-06-24 03:34:15 +00:00
|
|
|
*/
|
|
|
|
LONG WINAPI InterlockedExchange( PLONG dest, LONG val )
|
|
|
|
{
|
|
|
|
return interlocked_xchg( dest, val );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* InterlockedExchangeAdd (KERNEL32.@)
|
2003-09-17 20:05:03 +00:00
|
|
|
*
|
|
|
|
* Atomically add one value to another.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* dest [I/O] The value to add to
|
|
|
|
* incr [I] The value to be added
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The resulting value of dest.
|
2003-06-24 03:34:15 +00:00
|
|
|
*/
|
|
|
|
LONG WINAPI InterlockedExchangeAdd( PLONG dest, LONG incr )
|
|
|
|
{
|
|
|
|
return interlocked_xchg_add( dest, incr );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* InterlockedIncrement (KERNEL32.@)
|
2003-09-17 20:05:03 +00:00
|
|
|
*
|
|
|
|
* Atomically increment a value.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* dest [I/O] The value to increment
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The resulting value of dest.
|
2003-06-24 03:34:15 +00:00
|
|
|
*/
|
|
|
|
LONG WINAPI InterlockedIncrement( PLONG dest )
|
|
|
|
{
|
|
|
|
return interlocked_xchg_add( dest, 1 ) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* InterlockedDecrement (KERNEL32.@)
|
2003-09-17 20:05:03 +00:00
|
|
|
*
|
|
|
|
* Atomically decrement a value.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* dest [I/O] The value to decrement
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The resulting value of dest.
|
2003-06-24 03:34:15 +00:00
|
|
|
*/
|
|
|
|
LONG WINAPI InterlockedDecrement( PLONG dest )
|
|
|
|
{
|
|
|
|
return interlocked_xchg_add( dest, -1 ) - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* __i386__ */
|