2000-09-29 22:48:04 +02:00
|
|
|
/*
|
|
|
|
* Kernel synchronization objects
|
|
|
|
*
|
|
|
|
* Copyright 1998 Alexandre Julliard
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "winnls.h"
|
|
|
|
#include "wine/unicode.h"
|
|
|
|
#include "server.h"
|
|
|
|
#include "debugtools.h"
|
|
|
|
|
|
|
|
DEFAULT_DEBUG_CHANNEL(win32);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Events
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* CreateEventA (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateEventA( SECURITY_ATTRIBUTES *sa, BOOL manual_reset,
|
|
|
|
BOOL initial_state, LPCSTR name )
|
|
|
|
{
|
|
|
|
HANDLE ret;
|
|
|
|
DWORD len = name ? MultiByteToWideChar( CP_ACP, 0, name, strlen(name), NULL, 0 ) : 0;
|
|
|
|
if (len >= MAX_PATH)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_START_VAR_REQ( create_event, len * sizeof(WCHAR) )
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
|
|
|
req->manual_reset = manual_reset;
|
|
|
|
req->initial_state = initial_state;
|
|
|
|
req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
|
|
|
|
if (len) MultiByteToWideChar( CP_ACP, 0, name, strlen(name), server_data_ptr(req), len );
|
|
|
|
SetLastError(0);
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_CALL_ERR();
|
2000-09-29 22:48:04 +02:00
|
|
|
ret = req->handle;
|
|
|
|
}
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_END_VAR_REQ;
|
2000-09-29 22:48:04 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* CreateEventW (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateEventW( SECURITY_ATTRIBUTES *sa, BOOL manual_reset,
|
|
|
|
BOOL initial_state, LPCWSTR name )
|
|
|
|
{
|
|
|
|
HANDLE ret;
|
|
|
|
DWORD len = name ? strlenW(name) : 0;
|
|
|
|
if (len >= MAX_PATH)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
2000-12-29 04:18:08 +01: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;
|
|
|
|
}
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_START_VAR_REQ( create_event, len * sizeof(WCHAR) )
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
|
|
|
req->manual_reset = manual_reset;
|
|
|
|
req->initial_state = initial_state;
|
|
|
|
req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
|
|
|
|
memcpy( server_data_ptr(req), name, len * sizeof(WCHAR) );
|
|
|
|
SetLastError(0);
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_CALL_ERR();
|
2000-09-29 22:48:04 +02:00
|
|
|
ret = req->handle;
|
|
|
|
}
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_END_VAR_REQ;
|
2000-09-29 22:48:04 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-07-02 21:59:40 +02:00
|
|
|
* CreateW32Event (KERNEL.457)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI WIN16_CreateEvent( BOOL manual_reset, BOOL initial_state )
|
|
|
|
{
|
|
|
|
return CreateEventA( NULL, manual_reset, initial_state, NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* OpenEventA (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI OpenEventA( DWORD access, BOOL inherit, LPCSTR name )
|
|
|
|
{
|
|
|
|
HANDLE ret;
|
|
|
|
DWORD len = name ? MultiByteToWideChar( CP_ACP, 0, name, strlen(name), NULL, 0 ) : 0;
|
|
|
|
if (len >= MAX_PATH)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_START_VAR_REQ( open_event, len * sizeof(WCHAR) )
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
|
|
|
req->access = access;
|
|
|
|
req->inherit = inherit;
|
|
|
|
if (len) MultiByteToWideChar( CP_ACP, 0, name, strlen(name), server_data_ptr(req), len );
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_CALL_ERR();
|
2000-09-29 22:48:04 +02:00
|
|
|
ret = req->handle;
|
|
|
|
}
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_END_VAR_REQ;
|
2000-09-29 22:48:04 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* OpenEventW (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI OpenEventW( DWORD access, BOOL inherit, LPCWSTR name )
|
|
|
|
{
|
|
|
|
HANDLE ret;
|
|
|
|
DWORD len = name ? strlenW(name) : 0;
|
|
|
|
if (len >= MAX_PATH)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_START_VAR_REQ( open_event, len * sizeof(WCHAR) )
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
|
|
|
req->access = access;
|
|
|
|
req->inherit = inherit;
|
|
|
|
memcpy( server_data_ptr(req), name, len * sizeof(WCHAR) );
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_CALL_ERR();
|
2000-09-29 22:48:04 +02:00
|
|
|
ret = req->handle;
|
|
|
|
}
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_END_VAR_REQ;
|
2000-09-29 22:48:04 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* EVENT_Operation
|
|
|
|
*
|
|
|
|
* Execute an event operation (set,reset,pulse).
|
|
|
|
*/
|
|
|
|
static BOOL EVENT_Operation( HANDLE handle, enum event_op op )
|
|
|
|
{
|
|
|
|
BOOL ret;
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_START_REQ( event_op )
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
|
|
|
req->handle = handle;
|
|
|
|
req->op = op;
|
2001-02-27 03:09:16 +01:00
|
|
|
ret = !SERVER_CALL_ERR();
|
2000-09-29 22:48:04 +02:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* PulseEvent (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI PulseEvent( HANDLE handle )
|
|
|
|
{
|
|
|
|
return EVENT_Operation( handle, PULSE_EVENT );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-01-25 23:22:21 +01:00
|
|
|
* SetEvent (KERNEL.458)
|
2001-06-13 22:13:18 +02:00
|
|
|
* SetEvent (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI SetEvent( HANDLE handle )
|
|
|
|
{
|
|
|
|
return EVENT_Operation( handle, SET_EVENT );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-01-25 23:22:21 +01:00
|
|
|
* ResetEvent (KERNEL.459)
|
2001-06-13 22:13:18 +02:00
|
|
|
* ResetEvent (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI ResetEvent( HANDLE handle )
|
|
|
|
{
|
|
|
|
return EVENT_Operation( handle, RESET_EVENT );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* 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)
|
|
|
|
{
|
|
|
|
HANDLE hEvent = CreateEventA( NULL, FALSE, 0, NULL );
|
|
|
|
return ConvertToGlobalHandle( hEvent );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* VWin32_EventDestroy (KERNEL.443)
|
|
|
|
*/
|
|
|
|
VOID WINAPI VWin32_EventDestroy(HANDLE event)
|
|
|
|
{
|
|
|
|
CloseHandle( event );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* VWin32_EventWait (KERNEL.450)
|
|
|
|
*/
|
|
|
|
VOID WINAPI VWin32_EventWait(HANDLE event)
|
|
|
|
{
|
2000-11-16 00:41:46 +01:00
|
|
|
DWORD mutex_count;
|
|
|
|
|
|
|
|
ReleaseThunkLock( &mutex_count );
|
2000-09-29 22:48:04 +02:00
|
|
|
WaitForSingleObject( event, INFINITE );
|
2000-11-16 00:41:46 +01:00
|
|
|
RestoreThunkLock( mutex_count );
|
2000-09-29 22:48:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* VWin32_EventSet (KERNEL.451)
|
2001-07-02 21:59:40 +02:00
|
|
|
* KERNEL_479 (KERNEL.479)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
VOID WINAPI VWin32_EventSet(HANDLE event)
|
|
|
|
{
|
|
|
|
SetEvent( event );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* CreateMutexA (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateMutexA( SECURITY_ATTRIBUTES *sa, BOOL owner, LPCSTR name )
|
|
|
|
{
|
|
|
|
HANDLE ret;
|
|
|
|
DWORD len = name ? MultiByteToWideChar( CP_ACP, 0, name, strlen(name), NULL, 0 ) : 0;
|
|
|
|
if (len >= MAX_PATH)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_START_VAR_REQ( create_mutex, len * sizeof(WCHAR) )
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
|
|
|
req->owned = owner;
|
|
|
|
req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
|
|
|
|
if (len) MultiByteToWideChar( CP_ACP, 0, name, strlen(name), server_data_ptr(req), len );
|
|
|
|
SetLastError(0);
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_CALL_ERR();
|
2000-09-29 22:48:04 +02:00
|
|
|
ret = req->handle;
|
|
|
|
}
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_END_VAR_REQ;
|
2000-09-29 22:48:04 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* CreateMutexW (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateMutexW( SECURITY_ATTRIBUTES *sa, BOOL owner, LPCWSTR name )
|
|
|
|
{
|
|
|
|
HANDLE ret;
|
|
|
|
DWORD len = name ? strlenW(name) : 0;
|
|
|
|
if (len >= MAX_PATH)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_START_VAR_REQ( create_mutex, len * sizeof(WCHAR) )
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
|
|
|
req->owned = owner;
|
|
|
|
req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
|
|
|
|
memcpy( server_data_ptr(req), name, len * sizeof(WCHAR) );
|
|
|
|
SetLastError(0);
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_CALL_ERR();
|
2000-09-29 22:48:04 +02:00
|
|
|
ret = req->handle;
|
|
|
|
}
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_END_VAR_REQ;
|
2000-09-29 22:48:04 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mutexes
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* OpenMutexA (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI OpenMutexA( DWORD access, BOOL inherit, LPCSTR name )
|
|
|
|
{
|
|
|
|
HANDLE ret;
|
|
|
|
DWORD len = name ? MultiByteToWideChar( CP_ACP, 0, name, strlen(name), NULL, 0 ) : 0;
|
|
|
|
if (len >= MAX_PATH)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_START_VAR_REQ( open_mutex, len * sizeof(WCHAR) )
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
|
|
|
req->access = access;
|
|
|
|
req->inherit = inherit;
|
|
|
|
if (len) MultiByteToWideChar( CP_ACP, 0, name, strlen(name), server_data_ptr(req), len );
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_CALL_ERR();
|
2000-09-29 22:48:04 +02:00
|
|
|
ret = req->handle;
|
|
|
|
}
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_END_VAR_REQ;
|
2000-09-29 22:48:04 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* OpenMutexW (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI OpenMutexW( DWORD access, BOOL inherit, LPCWSTR name )
|
|
|
|
{
|
|
|
|
HANDLE ret;
|
|
|
|
DWORD len = name ? strlenW(name) : 0;
|
|
|
|
if (len >= MAX_PATH)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_START_VAR_REQ( open_mutex, len * sizeof(WCHAR) )
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
|
|
|
req->access = access;
|
|
|
|
req->inherit = inherit;
|
|
|
|
memcpy( server_data_ptr(req), name, len * sizeof(WCHAR) );
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_CALL_ERR();
|
2000-09-29 22:48:04 +02:00
|
|
|
ret = req->handle;
|
|
|
|
}
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_END_VAR_REQ;
|
2000-09-29 22:48:04 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* ReleaseMutex (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI ReleaseMutex( HANDLE handle )
|
|
|
|
{
|
|
|
|
BOOL ret;
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_START_REQ( release_mutex )
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
|
|
|
req->handle = handle;
|
2001-02-27 03:09:16 +01:00
|
|
|
ret = !SERVER_CALL_ERR();
|
2000-09-29 22:48:04 +02:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Semaphores
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* CreateSemaphoreA (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateSemaphoreA( SECURITY_ATTRIBUTES *sa, LONG initial, LONG max, LPCSTR name )
|
|
|
|
{
|
|
|
|
HANDLE ret;
|
|
|
|
DWORD len = name ? MultiByteToWideChar( CP_ACP, 0, name, strlen(name), NULL, 0 ) : 0;
|
|
|
|
|
|
|
|
/* Check parameters */
|
|
|
|
|
|
|
|
if ((max <= 0) || (initial < 0) || (initial > max))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (len >= MAX_PATH)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_START_VAR_REQ( create_semaphore, len * sizeof(WCHAR) )
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
|
|
|
req->initial = (unsigned int)initial;
|
|
|
|
req->max = (unsigned int)max;
|
|
|
|
req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
|
|
|
|
if (len) MultiByteToWideChar( CP_ACP, 0, name, strlen(name), server_data_ptr(req), len );
|
|
|
|
SetLastError(0);
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_CALL_ERR();
|
2000-09-29 22:48:04 +02:00
|
|
|
ret = req->handle;
|
|
|
|
}
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_END_VAR_REQ;
|
2000-09-29 22:48:04 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* CreateSemaphoreW (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateSemaphoreW( SECURITY_ATTRIBUTES *sa, LONG initial,
|
|
|
|
LONG max, LPCWSTR name )
|
|
|
|
{
|
|
|
|
HANDLE ret;
|
|
|
|
DWORD len = name ? strlenW(name) : 0;
|
|
|
|
|
|
|
|
/* Check parameters */
|
|
|
|
|
|
|
|
if ((max <= 0) || (initial < 0) || (initial > max))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (len >= MAX_PATH)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_START_VAR_REQ( create_semaphore, len * sizeof(WCHAR) )
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
|
|
|
req->initial = (unsigned int)initial;
|
|
|
|
req->max = (unsigned int)max;
|
|
|
|
req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
|
|
|
|
memcpy( server_data_ptr(req), name, len * sizeof(WCHAR) );
|
|
|
|
SetLastError(0);
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_CALL_ERR();
|
2000-09-29 22:48:04 +02:00
|
|
|
ret = req->handle;
|
|
|
|
}
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_END_VAR_REQ;
|
2000-09-29 22:48:04 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* OpenSemaphoreA (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI OpenSemaphoreA( DWORD access, BOOL inherit, LPCSTR name )
|
|
|
|
{
|
|
|
|
HANDLE ret;
|
|
|
|
DWORD len = name ? MultiByteToWideChar( CP_ACP, 0, name, strlen(name), NULL, 0 ) : 0;
|
|
|
|
if (len >= MAX_PATH)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_START_VAR_REQ( open_semaphore, len * sizeof(WCHAR) )
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
|
|
|
req->access = access;
|
|
|
|
req->inherit = inherit;
|
|
|
|
if (len) MultiByteToWideChar( CP_ACP, 0, name, strlen(name), server_data_ptr(req), len );
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_CALL_ERR();
|
2000-09-29 22:48:04 +02:00
|
|
|
ret = req->handle;
|
|
|
|
}
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_END_VAR_REQ;
|
2000-09-29 22:48:04 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* OpenSemaphoreW (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI OpenSemaphoreW( DWORD access, BOOL inherit, LPCWSTR name )
|
|
|
|
{
|
|
|
|
HANDLE ret;
|
|
|
|
DWORD len = name ? strlenW(name) : 0;
|
|
|
|
if (len >= MAX_PATH)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_START_VAR_REQ( open_semaphore, len * sizeof(WCHAR) )
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
|
|
|
req->access = access;
|
|
|
|
req->inherit = inherit;
|
|
|
|
memcpy( server_data_ptr(req), name, len * sizeof(WCHAR) );
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_CALL_ERR();
|
2000-09-29 22:48:04 +02:00
|
|
|
ret = req->handle;
|
|
|
|
}
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_END_VAR_REQ;
|
2000-09-29 22:48:04 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* ReleaseSemaphore (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI ReleaseSemaphore( HANDLE handle, LONG count, LONG *previous )
|
|
|
|
{
|
|
|
|
NTSTATUS status = NtReleaseSemaphore( handle, count, previous );
|
|
|
|
if (status) SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return !status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pipes
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* CreateNamedPipeA (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateNamedPipeA( LPCSTR name, DWORD dwOpenMode,
|
|
|
|
DWORD dwPipeMode, DWORD nMaxInstances,
|
|
|
|
DWORD nOutBufferSize, DWORD nInBufferSize,
|
|
|
|
DWORD nDefaultTimeOut, LPSECURITY_ATTRIBUTES attr )
|
|
|
|
{
|
2001-07-10 21:16:49 +02:00
|
|
|
HANDLE ret;
|
|
|
|
DWORD len = name ? MultiByteToWideChar( CP_ACP, 0, name, strlen(name), NULL, 0 ) : 0;
|
|
|
|
|
|
|
|
TRACE("(%s, %#08lx, %#08lx, %ld, %ld, %ld, %ld, %p): stub\n",
|
2000-09-29 22:48:04 +02:00
|
|
|
debugstr_a(name), dwOpenMode, dwPipeMode, nMaxInstances,
|
|
|
|
nOutBufferSize, nInBufferSize, nDefaultTimeOut, attr );
|
2001-07-10 21:16:49 +02:00
|
|
|
|
|
|
|
if (len >= MAX_PATH)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
SERVER_START_VAR_REQ( create_named_pipe, len * sizeof(WCHAR) )
|
|
|
|
{
|
|
|
|
req->openmode = dwOpenMode;
|
|
|
|
req->pipemode = dwPipeMode;
|
|
|
|
req->maxinstances = nMaxInstances;
|
|
|
|
req->outsize = nOutBufferSize;
|
|
|
|
req->insize = nInBufferSize;
|
|
|
|
req->timeout = nDefaultTimeOut;
|
|
|
|
|
|
|
|
if (len) MultiByteToWideChar( CP_ACP, 0, name, strlen(name), server_data_ptr(req), len );
|
|
|
|
SetLastError(0);
|
|
|
|
SERVER_CALL_ERR();
|
|
|
|
ret = req->handle;
|
|
|
|
}
|
|
|
|
SERVER_END_VAR_REQ;
|
|
|
|
TRACE("Returned %d\n",ret);
|
|
|
|
return ret;
|
2000-09-29 22:48:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* CreateNamedPipeW (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateNamedPipeW( LPCWSTR name, DWORD dwOpenMode,
|
|
|
|
DWORD dwPipeMode, DWORD nMaxInstances,
|
|
|
|
DWORD nOutBufferSize, DWORD nInBufferSize,
|
|
|
|
DWORD nDefaultTimeOut, LPSECURITY_ATTRIBUTES attr )
|
|
|
|
{
|
2001-07-10 21:16:49 +02:00
|
|
|
HANDLE ret;
|
|
|
|
DWORD len = name ? strlenW(name) : 0;
|
|
|
|
|
|
|
|
TRACE("(%s, %#08lx, %#08lx, %ld, %ld, %ld, %ld, %p)\n",
|
2000-09-29 22:48:04 +02:00
|
|
|
debugstr_w(name), dwOpenMode, dwPipeMode, nMaxInstances,
|
|
|
|
nOutBufferSize, nInBufferSize, nDefaultTimeOut, attr );
|
|
|
|
|
2001-07-10 21:16:49 +02:00
|
|
|
if (len >= MAX_PATH)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
SERVER_START_VAR_REQ( create_named_pipe, len * sizeof(WCHAR) )
|
|
|
|
{
|
|
|
|
req->openmode = dwOpenMode;
|
|
|
|
req->pipemode = dwPipeMode;
|
|
|
|
req->maxinstances = nMaxInstances;
|
|
|
|
req->outsize = nOutBufferSize;
|
|
|
|
req->insize = nInBufferSize;
|
|
|
|
req->timeout = nDefaultTimeOut;
|
|
|
|
|
|
|
|
memcpy( server_data_ptr(req), name, len * sizeof(WCHAR) );
|
|
|
|
SetLastError(0);
|
|
|
|
SERVER_CALL_ERR();
|
|
|
|
ret = req->handle;
|
|
|
|
}
|
|
|
|
SERVER_END_VAR_REQ;
|
|
|
|
return ret;
|
2000-09-29 22:48:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* PeekNamedPipe (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI PeekNamedPipe( HANDLE hPipe, LPVOID lpvBuffer, DWORD cbBuffer,
|
|
|
|
LPDWORD lpcbRead, LPDWORD lpcbAvail, LPDWORD lpcbMessage )
|
|
|
|
{
|
|
|
|
FIXME("(%08x, %p, %08lx, %p, %p, %p): stub\n",
|
|
|
|
hPipe, lpvBuffer, cbBuffer, lpcbRead, lpcbAvail, lpcbMessage);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* WaitNamedPipeA (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI WaitNamedPipeA (LPCSTR lpNamedPipeName, DWORD nTimeOut)
|
|
|
|
{
|
|
|
|
FIXME("%s 0x%08lx\n",lpNamedPipeName,nTimeOut);
|
|
|
|
SetLastError(ERROR_PIPE_NOT_CONNECTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* WaitNamedPipeW (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI WaitNamedPipeW (LPCWSTR lpNamedPipeName, DWORD nTimeOut)
|
|
|
|
{
|
|
|
|
FIXME("%s 0x%08lx\n",debugstr_w(lpNamedPipeName),nTimeOut);
|
|
|
|
SetLastError(ERROR_PIPE_NOT_CONNECTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2001-07-10 21:16:49 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ConnectNamedPipe (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI ConnectNamedPipe(HANDLE hPipe, LPOVERLAPPED overlapped)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
HANDLE event;
|
|
|
|
|
|
|
|
TRACE("(%d,%p):stub\n",hPipe, overlapped);
|
|
|
|
|
|
|
|
if(overlapped)
|
|
|
|
{
|
|
|
|
FIXME("overlapped operation not supported\n");
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
event = CreateEventA(NULL,0,0,NULL);
|
|
|
|
if(event==INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
ERR("create event failed!\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
SERVER_START_REQ( connect_named_pipe )
|
|
|
|
{
|
|
|
|
req->handle = hPipe;
|
|
|
|
req->event = event;
|
|
|
|
ret = SERVER_CALL_ERR();
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
|
|
|
if(ret) {
|
|
|
|
ERR("server returned status %08lx\n",GetLastError());
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
WaitForSingleObject(event,INFINITE);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DisconnectNamedPipe (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DisconnectNamedPipe(HANDLE hPipe)
|
|
|
|
{
|
|
|
|
FIXME("(%d):stub\n",hPipe);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|