kernel32: Move event functions to kernelbase.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2019-06-27 15:53:28 +02:00
parent 2a455ce049
commit 558e48aafd
8 changed files with 326 additions and 216 deletions

View File

@ -175,7 +175,7 @@
# @ stub BaseFormatObjectAttributes # @ stub BaseFormatObjectAttributes
# @ stub BaseFormatTimeOut # @ stub BaseFormatTimeOut
# @ stub BaseGenerateAppCompatData # @ stub BaseGenerateAppCompatData
# @ stub BaseGetNamedObjectDirectory @ stdcall -import BaseGetNamedObjectDirectory(ptr)
@ stub BaseInitAppcompatCache @ stub BaseInitAppcompatCache
@ stub BaseInitAppcompatCacheSupport @ stub BaseInitAppcompatCacheSupport
# @ stub BaseIsAppcompatInfrastructureDisabled # @ stub BaseIsAppcompatInfrastructureDisabled
@ -274,10 +274,10 @@
# @ stub CreateDirectoryTransactedA # @ stub CreateDirectoryTransactedA
# @ stub CreateDirectoryTransactedW # @ stub CreateDirectoryTransactedW
@ stdcall CreateDirectoryW(wstr ptr) @ stdcall CreateDirectoryW(wstr ptr)
@ stdcall CreateEventA(ptr long long str) @ stdcall -import CreateEventA(ptr long long str)
@ stdcall CreateEventExA(ptr str long long) @ stdcall -import CreateEventExA(ptr str long long)
@ stdcall CreateEventExW(ptr wstr long long) @ stdcall -import CreateEventExW(ptr wstr long long)
@ stdcall CreateEventW(ptr long long wstr) @ stdcall -import CreateEventW(ptr long long wstr)
@ stdcall CreateFiber(long ptr ptr) @ stdcall CreateFiber(long ptr ptr)
@ stdcall CreateFiberEx(long long long ptr ptr) @ stdcall CreateFiberEx(long long long ptr ptr)
@ stdcall CreateFile2(wstr long long long ptr) @ stdcall CreateFile2(wstr long long long ptr)
@ -1112,8 +1112,8 @@
# @ stub NumaVirtualQueryNode # @ stub NumaVirtualQueryNode
@ stdcall OpenConsoleW(wstr long long long) @ stdcall OpenConsoleW(wstr long long long)
@ stub OpenDataFile @ stub OpenDataFile
@ stdcall OpenEventA(long long str) @ stdcall -import OpenEventA(long long str)
@ stdcall OpenEventW(long long wstr) @ stdcall -import OpenEventW(long long wstr)
@ stdcall OpenFile(str ptr long) @ stdcall OpenFile(str ptr long)
@ stdcall OpenFileById(long ptr long long ptr long) @ stdcall OpenFileById(long ptr long long ptr long)
@ stdcall OpenFileMappingA(long long str) @ stdcall OpenFileMappingA(long long str)
@ -1153,7 +1153,7 @@
@ stdcall Process32Next (ptr ptr) @ stdcall Process32Next (ptr ptr)
@ stdcall Process32NextW (ptr ptr) @ stdcall Process32NextW (ptr ptr)
@ stdcall ProcessIdToSessionId(long ptr) @ stdcall ProcessIdToSessionId(long ptr)
@ stdcall PulseEvent(long) @ stdcall -import PulseEvent(long)
@ stdcall PurgeComm(long long) @ stdcall PurgeComm(long long)
@ stdcall -i386 -private -norelay QT_Thunk() krnl386.exe16.QT_Thunk @ stdcall -i386 -private -norelay QT_Thunk() krnl386.exe16.QT_Thunk
@ stdcall QueryActCtxSettingsW(long ptr wstr wstr ptr long ptr) @ stdcall QueryActCtxSettingsW(long ptr wstr wstr ptr long ptr)
@ -1279,7 +1279,7 @@
# @ stub ReplacePartitionUnit # @ stub ReplacePartitionUnit
@ stdcall RequestDeviceWakeup(long) @ stdcall RequestDeviceWakeup(long)
@ stdcall RequestWakeupLatency(long) @ stdcall RequestWakeupLatency(long)
@ stdcall ResetEvent(long) @ stdcall -import ResetEvent(long)
@ stdcall ResetWriteWatch(ptr long) @ stdcall ResetWriteWatch(ptr long)
@ stdcall ResolveDelayLoadedAPI(ptr ptr ptr ptr ptr long) ntdll.LdrResolveDelayLoadedAPI @ stdcall ResolveDelayLoadedAPI(ptr ptr ptr ptr ptr long) ntdll.LdrResolveDelayLoadedAPI
@ stdcall ResolveLocaleName(wstr ptr long) @ stdcall ResolveLocaleName(wstr ptr long)
@ -1389,7 +1389,7 @@
@ stdcall SetEnvironmentVariableA(str str) @ stdcall SetEnvironmentVariableA(str str)
@ stdcall SetEnvironmentVariableW(wstr wstr) @ stdcall SetEnvironmentVariableW(wstr wstr)
@ stdcall SetErrorMode(long) @ stdcall SetErrorMode(long)
@ stdcall SetEvent(long) @ stdcall -import SetEvent(long)
@ stdcall SetEventWhenCallbackReturns(ptr long) ntdll.TpCallbackSetEventOnCompletion @ stdcall SetEventWhenCallbackReturns(ptr long) ntdll.TpCallbackSetEventOnCompletion
@ stdcall SetFileApisToANSI() @ stdcall SetFileApisToANSI()
@ stdcall SetFileApisToOEM() @ stdcall SetFileApisToOEM()

View File

@ -23,6 +23,7 @@
#include "wine/server.h" #include "wine/server.h"
NTSTATUS WINAPI BaseGetNamedObjectDirectory( HANDLE *dir );
HANDLE WINAPI OpenConsoleW(LPCWSTR, DWORD, BOOL, DWORD); HANDLE WINAPI OpenConsoleW(LPCWSTR, DWORD, BOOL, DWORD);
BOOL WINAPI VerifyConsoleIoHandle(HANDLE); BOOL WINAPI VerifyConsoleIoHandle(HANDLE);
HANDLE WINAPI DuplicateConsoleHandle(HANDLE, DWORD, BOOL, DWORD); HANDLE WINAPI DuplicateConsoleHandle(HANDLE, DWORD, BOOL, DWORD);

View File

@ -55,34 +55,6 @@ static inline BOOL is_version_nt(void)
return !(GetVersion() & 0x80000000); return !(GetVersion() & 0x80000000);
} }
/* returns directory handle to \\BaseNamedObjects */
static HANDLE get_BaseNamedObjects_handle(void)
{
static HANDLE handle = NULL;
static const WCHAR basenameW[] = {'\\','S','e','s','s','i','o','n','s','\\','%','u',
'\\','B','a','s','e','N','a','m','e','d','O','b','j','e','c','t','s',0};
WCHAR buffer[64];
UNICODE_STRING str;
OBJECT_ATTRIBUTES attr;
if (!handle)
{
HANDLE dir;
sprintfW( buffer, basenameW, NtCurrentTeb()->Peb->SessionId );
RtlInitUnicodeString( &str, buffer );
InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
NtOpenDirectoryObject(&dir, DIRECTORY_CREATE_OBJECT|DIRECTORY_TRAVERSE,
&attr);
if (InterlockedCompareExchangePointer( &handle, dir, 0 ) != 0)
{
/* someone beat us here... */
CloseHandle( dir );
}
}
return handle;
}
static void get_create_object_attributes( OBJECT_ATTRIBUTES *attr, UNICODE_STRING *nameW, static void get_create_object_attributes( OBJECT_ATTRIBUTES *attr, UNICODE_STRING *nameW,
SECURITY_ATTRIBUTES *sa, const WCHAR *name ) SECURITY_ATTRIBUTES *sa, const WCHAR *name )
{ {
@ -96,21 +68,23 @@ static void get_create_object_attributes( OBJECT_ATTRIBUTES *attr, UNICODE_STRIN
{ {
RtlInitUnicodeString( nameW, name ); RtlInitUnicodeString( nameW, name );
attr->ObjectName = nameW; attr->ObjectName = nameW;
attr->RootDirectory = get_BaseNamedObjects_handle(); BaseGetNamedObjectDirectory( &attr->RootDirectory );
} }
} }
static BOOL get_open_object_attributes( OBJECT_ATTRIBUTES *attr, UNICODE_STRING *nameW, static BOOL get_open_object_attributes( OBJECT_ATTRIBUTES *attr, UNICODE_STRING *nameW,
BOOL inherit, const WCHAR *name ) BOOL inherit, const WCHAR *name )
{ {
HANDLE dir;
if (!name) if (!name)
{ {
SetLastError( ERROR_INVALID_PARAMETER ); SetLastError( ERROR_INVALID_PARAMETER );
return FALSE; return FALSE;
} }
RtlInitUnicodeString( nameW, name ); RtlInitUnicodeString( nameW, name );
InitializeObjectAttributes( attr, nameW, inherit ? OBJ_INHERIT : 0, BaseGetNamedObjectDirectory( &dir );
get_BaseNamedObjects_handle(), NULL ); InitializeObjectAttributes( attr, nameW, inherit ? OBJ_INHERIT : 0, dir, NULL );
return TRUE; return TRUE;
} }
@ -444,165 +418,6 @@ void WINAPI UninitializeCriticalSection( CRITICAL_SECTION *crit )
} }
/***********************************************************************
* CreateEventA (KERNEL32.@)
*/
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventA( SECURITY_ATTRIBUTES *sa, BOOL manual_reset,
BOOL initial_state, LPCSTR name )
{
DWORD flags = 0;
if (manual_reset) flags |= CREATE_EVENT_MANUAL_RESET;
if (initial_state) flags |= CREATE_EVENT_INITIAL_SET;
return CreateEventExA( sa, name, flags, EVENT_ALL_ACCESS );
}
/***********************************************************************
* CreateEventW (KERNEL32.@)
*/
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW( SECURITY_ATTRIBUTES *sa, BOOL manual_reset,
BOOL initial_state, LPCWSTR name )
{
DWORD flags = 0;
if (manual_reset) flags |= CREATE_EVENT_MANUAL_RESET;
if (initial_state) flags |= CREATE_EVENT_INITIAL_SET;
return CreateEventExW( sa, name, flags, EVENT_ALL_ACCESS );
}
/***********************************************************************
* CreateEventExA (KERNEL32.@)
*/
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventExA( SECURITY_ATTRIBUTES *sa, LPCSTR name, DWORD flags, DWORD access )
{
WCHAR buffer[MAX_PATH];
if (!name) return CreateEventExW( sa, NULL, flags, access );
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
{
SetLastError( ERROR_FILENAME_EXCED_RANGE );
return 0;
}
return CreateEventExW( sa, buffer, flags, access );
}
/***********************************************************************
* CreateEventExW (KERNEL32.@)
*/
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventExW( SECURITY_ATTRIBUTES *sa, LPCWSTR name, DWORD flags, DWORD access )
{
HANDLE ret = 0;
UNICODE_STRING nameW;
OBJECT_ATTRIBUTES attr;
NTSTATUS status;
/* 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;
}
get_create_object_attributes( &attr, &nameW, sa, name );
status = NtCreateEvent( &ret, access, &attr,
(flags & CREATE_EVENT_MANUAL_RESET) ? NotificationEvent : SynchronizationEvent,
(flags & CREATE_EVENT_INITIAL_SET) != 0 );
if (status == STATUS_OBJECT_NAME_EXISTS)
SetLastError( ERROR_ALREADY_EXISTS );
else
SetLastError( RtlNtStatusToDosError(status) );
return ret;
}
/***********************************************************************
* OpenEventA (KERNEL32.@)
*/
HANDLE WINAPI DECLSPEC_HOTPATCH OpenEventA( DWORD access, BOOL inherit, LPCSTR name )
{
WCHAR buffer[MAX_PATH];
if (!name) return OpenEventW( access, inherit, NULL );
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
{
SetLastError( ERROR_FILENAME_EXCED_RANGE );
return 0;
}
return OpenEventW( access, inherit, buffer );
}
/***********************************************************************
* OpenEventW (KERNEL32.@)
*/
HANDLE WINAPI DECLSPEC_HOTPATCH OpenEventW( DWORD access, BOOL inherit, LPCWSTR name )
{
HANDLE ret;
UNICODE_STRING nameW;
OBJECT_ATTRIBUTES attr;
NTSTATUS status;
if (!is_version_nt()) access = EVENT_ALL_ACCESS;
if (!get_open_object_attributes( &attr, &nameW, inherit, name )) return 0;
status = NtOpenEvent( &ret, access, &attr );
if (status != STATUS_SUCCESS)
{
SetLastError( RtlNtStatusToDosError(status) );
return 0;
}
return ret;
}
/***********************************************************************
* PulseEvent (KERNEL32.@)
*/
BOOL WINAPI DECLSPEC_HOTPATCH PulseEvent( HANDLE handle )
{
NTSTATUS status;
if ((status = NtPulseEvent( handle, NULL )))
SetLastError( RtlNtStatusToDosError(status) );
return !status;
}
/***********************************************************************
* SetEvent (KERNEL32.@)
*/
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent( HANDLE handle )
{
NTSTATUS status;
if ((status = NtSetEvent( handle, NULL )))
SetLastError( RtlNtStatusToDosError(status) );
return !status;
}
/***********************************************************************
* ResetEvent (KERNEL32.@)
*/
BOOL WINAPI DECLSPEC_HOTPATCH ResetEvent( HANDLE handle )
{
NTSTATUS status;
if ((status = NtResetEvent( handle, NULL )))
SetLastError( RtlNtStatusToDosError(status) );
return !status;
}
/*********************************************************************** /***********************************************************************
* CreateMutexA (KERNEL32.@) * CreateMutexA (KERNEL32.@)
*/ */

View File

@ -9,4 +9,5 @@ C_SRCS = \
registry.c \ registry.c \
security.c \ security.c \
string.c \ string.c \
sync.c \
version.c version.c

View File

@ -0,0 +1,33 @@
/*
* Kernelbase internal definitions
*
* Copyright 2019 Alexandre Julliard
*
* 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef __WINE_KERNELBASE_H
#define __WINE_KERNELBASE_H
#include "windef.h"
#include "winbase.h"
static inline BOOL set_ntstatus( NTSTATUS status )
{
if (status) SetLastError( RtlNtStatusToDosError( status ));
return !status;
}
#endif /* __WINE_KERNELBASE_H */

View File

@ -77,7 +77,7 @@
@ stdcall BaseFlushAppcompatCache() kernel32.BaseFlushAppcompatCache @ stdcall BaseFlushAppcompatCache() kernel32.BaseFlushAppcompatCache
# @ stub BaseFormatObjectAttributes # @ stub BaseFormatObjectAttributes
# @ stub BaseFreeAppCompatDataForProcess # @ stub BaseFreeAppCompatDataForProcess
# @ stub BaseGetNamedObjectDirectory @ stdcall BaseGetNamedObjectDirectory(ptr)
@ stub BaseGetProcessDllPath @ stub BaseGetProcessDllPath
@ stub BaseGetProcessExePath @ stub BaseGetProcessExePath
@ stub BaseInitAppcompatCacheSupport @ stub BaseInitAppcompatCacheSupport
@ -179,10 +179,10 @@
@ stdcall CreateDirectoryExW(wstr wstr ptr) kernel32.CreateDirectoryExW @ stdcall CreateDirectoryExW(wstr wstr ptr) kernel32.CreateDirectoryExW
@ stdcall CreateDirectoryW(wstr ptr) kernel32.CreateDirectoryW @ stdcall CreateDirectoryW(wstr ptr) kernel32.CreateDirectoryW
# @ stub CreateEnclave # @ stub CreateEnclave
@ stdcall CreateEventA(ptr long long str) kernel32.CreateEventA @ stdcall CreateEventA(ptr long long str)
@ stdcall CreateEventExA(ptr str long long) kernel32.CreateEventExA @ stdcall CreateEventExA(ptr str long long)
@ stdcall CreateEventExW(ptr wstr long long) kernel32.CreateEventExW @ stdcall CreateEventExW(ptr wstr long long)
@ stdcall CreateEventW(ptr long long wstr) kernel32.CreateEventW @ stdcall CreateEventW(ptr long long wstr)
@ stdcall CreateFiber(long ptr ptr) kernel32.CreateFiber @ stdcall CreateFiber(long ptr ptr) kernel32.CreateFiber
@ stdcall CreateFiberEx(long long long ptr ptr) kernel32.CreateFiberEx @ stdcall CreateFiberEx(long long long ptr ptr) kernel32.CreateFiberEx
@ stdcall CreateFile2(wstr long long long ptr) kernel32.CreateFile2 @ stdcall CreateFile2(wstr long long long ptr) kernel32.CreateFile2
@ -981,8 +981,8 @@
@ stdcall ObjectOpenAuditAlarmW(wstr ptr wstr wstr ptr long long long ptr long long ptr) @ stdcall ObjectOpenAuditAlarmW(wstr ptr wstr wstr ptr long long long ptr long long ptr)
@ stdcall ObjectPrivilegeAuditAlarmW(wstr ptr long long ptr long) @ stdcall ObjectPrivilegeAuditAlarmW(wstr ptr long long ptr long)
# @ stub OfferVirtualMemory # @ stub OfferVirtualMemory
@ stdcall OpenEventA(long long str) kernel32.OpenEventA @ stdcall OpenEventA(long long str)
@ stdcall OpenEventW(long long wstr) kernel32.OpenEventW @ stdcall OpenEventW(long long wstr)
@ stdcall OpenFileById(long ptr long long ptr long) kernel32.OpenFileById @ stdcall OpenFileById(long ptr long long ptr long) kernel32.OpenFileById
# @ stub OpenFileMappingFromApp # @ stub OpenFileMappingFromApp
@ stdcall OpenFileMappingW(long long wstr) kernel32.OpenFileMappingW @ stdcall OpenFileMappingW(long long wstr) kernel32.OpenFileMappingW
@ -1189,7 +1189,7 @@
# @ stub PssWalkMarkerSetPosition # @ stub PssWalkMarkerSetPosition
# @ stub PssWalkSnapshot # @ stub PssWalkSnapshot
# @ stub PublishStateChangeNotification # @ stub PublishStateChangeNotification
@ stdcall PulseEvent(long) kernel32.PulseEvent @ stdcall PulseEvent(long)
@ stdcall PurgeComm(long long) kernel32.PurgeComm @ stdcall PurgeComm(long long) kernel32.PurgeComm
@ stdcall QISearch(ptr ptr ptr ptr) @ stdcall QISearch(ptr ptr ptr ptr)
@ stdcall QueryActCtxSettingsW(long ptr wstr wstr ptr long ptr) kernel32.QueryActCtxSettingsW @ stdcall QueryActCtxSettingsW(long ptr wstr wstr ptr long ptr) kernel32.QueryActCtxSettingsW
@ -1341,7 +1341,7 @@
@ stdcall RemoveVectoredExceptionHandler(ptr) kernel32.RemoveVectoredExceptionHandler @ stdcall RemoveVectoredExceptionHandler(ptr) kernel32.RemoveVectoredExceptionHandler
# @ stub ReplaceFileExInternal # @ stub ReplaceFileExInternal
@ stdcall ReplaceFileW(wstr wstr wstr long ptr ptr) kernel32.ReplaceFileW @ stdcall ReplaceFileW(wstr wstr wstr long ptr ptr) kernel32.ReplaceFileW
@ stdcall ResetEvent(long) kernel32.ResetEvent @ stdcall ResetEvent(long)
# @ stub ResetState # @ stub ResetState
@ stdcall ResetWriteWatch(ptr long) kernel32.ResetWriteWatch @ stdcall ResetWriteWatch(ptr long) kernel32.ResetWriteWatch
@ stdcall ResolveDelayLoadedAPI(ptr ptr ptr ptr ptr long) kernel32.ResolveDelayLoadedAPI @ stdcall ResolveDelayLoadedAPI(ptr ptr ptr ptr ptr long) kernel32.ResolveDelayLoadedAPI
@ -1427,7 +1427,7 @@
@ stdcall SetEnvironmentVariableA(str str) kernel32.SetEnvironmentVariableA @ stdcall SetEnvironmentVariableA(str str) kernel32.SetEnvironmentVariableA
@ stdcall SetEnvironmentVariableW(wstr wstr) kernel32.SetEnvironmentVariableW @ stdcall SetEnvironmentVariableW(wstr wstr) kernel32.SetEnvironmentVariableW
@ stdcall SetErrorMode(long) kernel32.SetErrorMode @ stdcall SetErrorMode(long) kernel32.SetErrorMode
@ stdcall SetEvent(long) kernel32.SetEvent @ stdcall SetEvent(long)
@ stdcall SetEventWhenCallbackReturns(ptr long) kernel32.SetEventWhenCallbackReturns @ stdcall SetEventWhenCallbackReturns(ptr long) kernel32.SetEventWhenCallbackReturns
@ stdcall SetFileApisToANSI() kernel32.SetFileApisToANSI @ stdcall SetFileApisToANSI() kernel32.SetFileApisToANSI
@ stdcall SetFileApisToOEM() kernel32.SetFileApisToOEM @ stdcall SetFileApisToOEM() kernel32.SetFileApisToOEM

View File

@ -30,6 +30,7 @@
#include "winternl.h" #include "winternl.h"
#include "winioctl.h" #include "winioctl.h"
#include "kernelbase.h"
#include "wine/debug.h" #include "wine/debug.h"
#include "wine/heap.h" #include "wine/heap.h"
@ -228,12 +229,6 @@ static const char *debugstr_sid( PSID sid )
return "(too-big)"; return "(too-big)";
} }
static BOOL set_ntstatus( NTSTATUS status )
{
if (status) SetLastError( RtlNtStatusToDosError( status ));
return !status;
}
/****************************************************************************** /******************************************************************************
* AllocateAndInitializeSid (kernelbase.@) * AllocateAndInitializeSid (kernelbase.@)
*/ */

265
dlls/kernelbase/sync.c Normal file
View File

@ -0,0 +1,265 @@
/*
* Kernel synchronization objects
*
* Copyright 1998 Alexandre Julliard
*
* 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <stdarg.h>
#include <string.h>
#include <stdio.h>
#include "ntstatus.h"
#define WIN32_NO_STATUS
#define NONAMELESSUNION
#include "windef.h"
#include "winbase.h"
#include "winerror.h"
#include "winnls.h"
#include "winternl.h"
#include "winioctl.h"
#include "ddk/wdm.h"
#include "kernelbase.h"
#include "wine/asm.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(sync);
/* check if current version is NT or Win95 */
static inline BOOL is_version_nt(void)
{
return !(GetVersion() & 0x80000000);
}
/***********************************************************************
* BaseGetNamedObjectDirectory (kernelbase.@)
*/
NTSTATUS WINAPI BaseGetNamedObjectDirectory( HANDLE *dir )
{
static HANDLE handle;
static const WCHAR basenameW[] = {'\\','S','e','s','s','i','o','n','s','\\','%','u',
'\\','B','a','s','e','N','a','m','e','d','O','b','j','e','c','t','s',0};
WCHAR buffer[64];
UNICODE_STRING str;
OBJECT_ATTRIBUTES attr;
NTSTATUS status = STATUS_SUCCESS;
if (!handle)
{
HANDLE dir;
swprintf( buffer, ARRAY_SIZE(buffer), basenameW, NtCurrentTeb()->Peb->SessionId );
RtlInitUnicodeString( &str, buffer );
InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
status = NtOpenDirectoryObject( &dir, DIRECTORY_CREATE_OBJECT|DIRECTORY_TRAVERSE, &attr );
if (!status && InterlockedCompareExchangePointer( &handle, dir, 0 ) != 0)
{
/* someone beat us here... */
CloseHandle( dir );
}
}
*dir = handle;
return status;
}
static void get_create_object_attributes( OBJECT_ATTRIBUTES *attr, UNICODE_STRING *nameW,
SECURITY_ATTRIBUTES *sa, const WCHAR *name )
{
attr->Length = sizeof(*attr);
attr->RootDirectory = 0;
attr->ObjectName = NULL;
attr->Attributes = OBJ_OPENIF | ((sa && sa->bInheritHandle) ? OBJ_INHERIT : 0);
attr->SecurityDescriptor = sa ? sa->lpSecurityDescriptor : NULL;
attr->SecurityQualityOfService = NULL;
if (name)
{
RtlInitUnicodeString( nameW, name );
attr->ObjectName = nameW;
BaseGetNamedObjectDirectory( &attr->RootDirectory );
}
}
static BOOL get_open_object_attributes( OBJECT_ATTRIBUTES *attr, UNICODE_STRING *nameW,
BOOL inherit, const WCHAR *name )
{
HANDLE dir;
if (!name)
{
SetLastError( ERROR_INVALID_PARAMETER );
return FALSE;
}
RtlInitUnicodeString( nameW, name );
BaseGetNamedObjectDirectory( &dir );
InitializeObjectAttributes( attr, nameW, inherit ? OBJ_INHERIT : 0, dir, NULL );
return TRUE;
}
/***********************************************************************
* Events
***********************************************************************/
/***********************************************************************
* CreateEventA (kernelbase.@)
*/
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventA( SECURITY_ATTRIBUTES *sa, BOOL manual_reset,
BOOL initial_state, LPCSTR name )
{
DWORD flags = 0;
if (manual_reset) flags |= CREATE_EVENT_MANUAL_RESET;
if (initial_state) flags |= CREATE_EVENT_INITIAL_SET;
return CreateEventExA( sa, name, flags, EVENT_ALL_ACCESS );
}
/***********************************************************************
* CreateEventW (kernelbase.@)
*/
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW( SECURITY_ATTRIBUTES *sa, BOOL manual_reset,
BOOL initial_state, LPCWSTR name )
{
DWORD flags = 0;
if (manual_reset) flags |= CREATE_EVENT_MANUAL_RESET;
if (initial_state) flags |= CREATE_EVENT_INITIAL_SET;
return CreateEventExW( sa, name, flags, EVENT_ALL_ACCESS );
}
/***********************************************************************
* CreateEventExA (kernelbase.@)
*/
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventExA( SECURITY_ATTRIBUTES *sa, LPCSTR name,
DWORD flags, DWORD access )
{
WCHAR buffer[MAX_PATH];
if (!name) return CreateEventExW( sa, NULL, flags, access );
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
{
SetLastError( ERROR_FILENAME_EXCED_RANGE );
return 0;
}
return CreateEventExW( sa, buffer, flags, access );
}
/***********************************************************************
* CreateEventExW (kernelbase.@)
*/
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventExW( SECURITY_ATTRIBUTES *sa, LPCWSTR name,
DWORD flags, DWORD access )
{
HANDLE ret = 0;
UNICODE_STRING nameW;
OBJECT_ATTRIBUTES attr;
NTSTATUS status;
/* 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;
}
get_create_object_attributes( &attr, &nameW, sa, name );
status = NtCreateEvent( &ret, access, &attr,
(flags & CREATE_EVENT_MANUAL_RESET) ? NotificationEvent : SynchronizationEvent,
(flags & CREATE_EVENT_INITIAL_SET) != 0 );
if (status == STATUS_OBJECT_NAME_EXISTS)
SetLastError( ERROR_ALREADY_EXISTS );
else
SetLastError( RtlNtStatusToDosError(status) );
return ret;
}
/***********************************************************************
* OpenEventA (kernelbase.@)
*/
HANDLE WINAPI DECLSPEC_HOTPATCH OpenEventA( DWORD access, BOOL inherit, LPCSTR name )
{
WCHAR buffer[MAX_PATH];
if (!name) return OpenEventW( access, inherit, NULL );
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
{
SetLastError( ERROR_FILENAME_EXCED_RANGE );
return 0;
}
return OpenEventW( access, inherit, buffer );
}
/***********************************************************************
* OpenEventW (kernelbase.@)
*/
HANDLE WINAPI DECLSPEC_HOTPATCH OpenEventW( DWORD access, BOOL inherit, LPCWSTR name )
{
HANDLE ret;
UNICODE_STRING nameW;
OBJECT_ATTRIBUTES attr;
NTSTATUS status;
if (!is_version_nt()) access = EVENT_ALL_ACCESS;
if (!get_open_object_attributes( &attr, &nameW, inherit, name )) return 0;
status = NtOpenEvent( &ret, access, &attr );
if (status != STATUS_SUCCESS)
{
SetLastError( RtlNtStatusToDosError(status) );
return 0;
}
return ret;
}
/***********************************************************************
* PulseEvent (kernelbase.@)
*/
BOOL WINAPI DECLSPEC_HOTPATCH PulseEvent( HANDLE handle )
{
return set_ntstatus( NtPulseEvent( handle, NULL ));
}
/***********************************************************************
* SetEvent (kernelbase.@)
*/
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent( HANDLE handle )
{
return set_ntstatus( NtSetEvent( handle, NULL ));
}
/***********************************************************************
* ResetEvent (kernelbase.@)
*/
BOOL WINAPI DECLSPEC_HOTPATCH ResetEvent( HANDLE handle )
{
return set_ntstatus( NtResetEvent( handle, NULL ));
}