From 93a5451152ae0a2ab7252bfc422abdabc62d9663 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Thu, 27 Jun 2019 16:05:17 +0200 Subject: [PATCH] kernel32: Move mutex functions to kernelbase. Signed-off-by: Alexandre Julliard --- dlls/kernel32/kernel32.spec | 12 ++-- dlls/kernel32/sync.c | 99 ------------------------------- dlls/kernelbase/kernelbase.spec | 12 ++-- dlls/kernelbase/sync.c | 100 ++++++++++++++++++++++++++++++++ 4 files changed, 112 insertions(+), 111 deletions(-) diff --git a/dlls/kernel32/kernel32.spec b/dlls/kernel32/kernel32.spec index e2d9e67717d..4868df8638d 100644 --- a/dlls/kernel32/kernel32.spec +++ b/dlls/kernel32/kernel32.spec @@ -299,10 +299,10 @@ @ stdcall CreateMailslotA(str long long ptr) @ stdcall CreateMailslotW(wstr long long ptr) @ stdcall CreateMemoryResourceNotification(long) -@ stdcall CreateMutexA(ptr long str) -@ stdcall CreateMutexExA(ptr str long long) -@ stdcall CreateMutexExW(ptr wstr long long) -@ stdcall CreateMutexW(ptr long wstr) +@ stdcall -import CreateMutexA(ptr long str) +@ stdcall -import CreateMutexExA(ptr str long long) +@ stdcall -import CreateMutexExW(ptr wstr long long) +@ stdcall -import CreateMutexW(ptr long wstr) @ stdcall CreateNamedPipeA(str long long long long long long ptr) @ stdcall CreateNamedPipeW(wstr long long long long long long ptr) # @ stub CreateNlsSecurityDescriptor @@ -1121,7 +1121,7 @@ @ stdcall OpenJobObjectA(long long str) @ stdcall OpenJobObjectW(long long wstr) @ stdcall OpenMutexA(long long str) -@ stdcall OpenMutexW(long long wstr) +@ stdcall -import OpenMutexW(long long wstr) # @ stub OpenPrivateNamespaceA # @ stub OpenPrivateNamespaceW @ stdcall OpenProcess(long long long) @@ -1256,7 +1256,7 @@ @ stub RegisterWowExec @ stdcall ReinitializeCriticalSection(ptr) @ stdcall ReleaseActCtx(ptr) -@ stdcall ReleaseMutex(long) +@ stdcall -import ReleaseMutex(long) @ stdcall ReleaseMutexWhenCallbackReturns(ptr long) ntdll.TpCallbackReleaseMutexOnCompletion @ stdcall ReleaseSemaphore(long long ptr) @ stdcall ReleaseSemaphoreWhenCallbackReturns(ptr long long) ntdll.TpCallbackReleaseSemaphoreOnCompletion diff --git a/dlls/kernel32/sync.c b/dlls/kernel32/sync.c index 8a45c4343e8..6bfcfeea161 100644 --- a/dlls/kernel32/sync.c +++ b/dlls/kernel32/sync.c @@ -418,66 +418,6 @@ void WINAPI UninitializeCriticalSection( CRITICAL_SECTION *crit ) } -/*********************************************************************** - * CreateMutexA (KERNEL32.@) - */ -HANDLE WINAPI DECLSPEC_HOTPATCH CreateMutexA( SECURITY_ATTRIBUTES *sa, BOOL owner, LPCSTR name ) -{ - return CreateMutexExA( sa, name, owner ? CREATE_MUTEX_INITIAL_OWNER : 0, MUTEX_ALL_ACCESS ); -} - - -/*********************************************************************** - * CreateMutexW (KERNEL32.@) - */ -HANDLE WINAPI DECLSPEC_HOTPATCH CreateMutexW( SECURITY_ATTRIBUTES *sa, BOOL owner, LPCWSTR name ) -{ - return CreateMutexExW( sa, name, owner ? CREATE_MUTEX_INITIAL_OWNER : 0, MUTEX_ALL_ACCESS ); -} - - -/*********************************************************************** - * CreateMutexExA (KERNEL32.@) - */ -HANDLE WINAPI DECLSPEC_HOTPATCH CreateMutexExA( SECURITY_ATTRIBUTES *sa, LPCSTR name, DWORD flags, DWORD access ) -{ - ANSI_STRING nameA; - NTSTATUS status; - - if (!name) return CreateMutexExW( sa, NULL, flags, access ); - - RtlInitAnsiString( &nameA, name ); - status = RtlAnsiStringToUnicodeString( &NtCurrentTeb()->StaticUnicodeString, &nameA, FALSE ); - if (status != STATUS_SUCCESS) - { - SetLastError( ERROR_FILENAME_EXCED_RANGE ); - return 0; - } - return CreateMutexExW( sa, NtCurrentTeb()->StaticUnicodeString.Buffer, flags, access ); -} - - -/*********************************************************************** - * CreateMutexExW (KERNEL32.@) - */ -HANDLE WINAPI DECLSPEC_HOTPATCH CreateMutexExW( SECURITY_ATTRIBUTES *sa, LPCWSTR name, DWORD flags, DWORD access ) -{ - HANDLE ret = 0; - UNICODE_STRING nameW; - OBJECT_ATTRIBUTES attr; - NTSTATUS status; - - get_create_object_attributes( &attr, &nameW, sa, name ); - - status = NtCreateMutant( &ret, access, &attr, (flags & CREATE_MUTEX_INITIAL_OWNER) != 0 ); - if (status == STATUS_OBJECT_NAME_EXISTS) - SetLastError( ERROR_ALREADY_EXISTS ); - else - SetLastError( RtlNtStatusToDosError(status) ); - return ret; -} - - /*********************************************************************** * OpenMutexA (KERNEL32.@) */ @@ -496,45 +436,6 @@ HANDLE WINAPI DECLSPEC_HOTPATCH OpenMutexA( DWORD access, BOOL inherit, LPCSTR n } -/*********************************************************************** - * OpenMutexW (KERNEL32.@) - */ -HANDLE WINAPI DECLSPEC_HOTPATCH OpenMutexW( DWORD access, BOOL inherit, LPCWSTR name ) -{ - HANDLE ret; - UNICODE_STRING nameW; - OBJECT_ATTRIBUTES attr; - NTSTATUS status; - - if (!is_version_nt()) access = MUTEX_ALL_ACCESS; - - if (!get_open_object_attributes( &attr, &nameW, inherit, name )) return 0; - - status = NtOpenMutant( &ret, access, &attr ); - if (status != STATUS_SUCCESS) - { - SetLastError( RtlNtStatusToDosError(status) ); - return 0; - } - return ret; -} - - -/*********************************************************************** - * ReleaseMutex (KERNEL32.@) - */ -BOOL WINAPI DECLSPEC_HOTPATCH ReleaseMutex( HANDLE handle ) -{ - NTSTATUS status; - - status = NtReleaseMutant(handle, NULL); - if (status != STATUS_SUCCESS) - { - SetLastError( RtlNtStatusToDosError(status) ); - return FALSE; - } - return TRUE; -} /* diff --git a/dlls/kernelbase/kernelbase.spec b/dlls/kernelbase/kernelbase.spec index cb96a704f64..f0c87aeb88c 100644 --- a/dlls/kernelbase/kernelbase.spec +++ b/dlls/kernelbase/kernelbase.spec @@ -195,10 +195,10 @@ @ stdcall CreateHardLinkW(wstr wstr ptr) kernel32.CreateHardLinkW @ stdcall CreateIoCompletionPort(long long long long) kernel32.CreateIoCompletionPort @ stdcall CreateMemoryResourceNotification(long) kernel32.CreateMemoryResourceNotification -@ stdcall CreateMutexA(ptr long str) kernel32.CreateMutexA -@ stdcall CreateMutexExA(ptr str long long) kernel32.CreateMutexExA -@ stdcall CreateMutexExW(ptr wstr long long) kernel32.CreateMutexExW -@ stdcall CreateMutexW(ptr long wstr) kernel32.CreateMutexW +@ stdcall CreateMutexA(ptr long str) +@ stdcall CreateMutexExA(ptr str long long) +@ stdcall CreateMutexExW(ptr wstr long long) +@ stdcall CreateMutexW(ptr long wstr) @ stdcall CreateNamedPipeW(wstr long long long long long long ptr) kernel32.CreateNamedPipeW @ stdcall CreatePipe(ptr ptr ptr long) kernel32.CreatePipe # @ stub CreatePrivateNamespaceW @@ -987,7 +987,7 @@ # @ stub OpenFileMappingFromApp @ stdcall OpenFileMappingW(long long wstr) kernel32.OpenFileMappingW # @ stub OpenGlobalizationUserSettingsKey -@ stdcall OpenMutexW(long long wstr) kernel32.OpenMutexW +@ stdcall OpenMutexW(long long wstr) # @ stub OpenPackageInfoByFullName # @ stub OpenPackageInfoByFullNameForUser # @ stub OpenPrivateNamespaceW @@ -1324,7 +1324,7 @@ @ stdcall RegisterTraceGuidsW(ptr ptr ptr long ptr wstr wstr ptr) ntdll.EtwRegisterTraceGuidsW @ stdcall RegisterWaitForSingleObjectEx(long ptr ptr long long) kernel32.RegisterWaitForSingleObjectEx @ stdcall ReleaseActCtx(ptr) kernel32.ReleaseActCtx -@ stdcall ReleaseMutex(long) kernel32.ReleaseMutex +@ stdcall ReleaseMutex(long) @ stdcall ReleaseMutexWhenCallbackReturns(ptr long) kernel32.ReleaseMutexWhenCallbackReturns @ stdcall ReleaseSRWLockExclusive(ptr) kernel32.ReleaseSRWLockExclusive @ stdcall ReleaseSRWLockShared(ptr) kernel32.ReleaseSRWLockShared diff --git a/dlls/kernelbase/sync.c b/dlls/kernelbase/sync.c index 18ad28f5f31..ebbb20932a9 100644 --- a/dlls/kernelbase/sync.c +++ b/dlls/kernelbase/sync.c @@ -263,3 +263,103 @@ BOOL WINAPI DECLSPEC_HOTPATCH ResetEvent( HANDLE handle ) { return set_ntstatus( NtResetEvent( handle, NULL )); } + + +/*********************************************************************** + * Mutexes + ***********************************************************************/ + + +/*********************************************************************** + * CreateMutexA (kernelbase.@) + */ +HANDLE WINAPI DECLSPEC_HOTPATCH CreateMutexA( SECURITY_ATTRIBUTES *sa, BOOL owner, LPCSTR name ) +{ + return CreateMutexExA( sa, name, owner ? CREATE_MUTEX_INITIAL_OWNER : 0, MUTEX_ALL_ACCESS ); +} + + +/*********************************************************************** + * CreateMutexW (kernelbase.@) + */ +HANDLE WINAPI DECLSPEC_HOTPATCH CreateMutexW( SECURITY_ATTRIBUTES *sa, BOOL owner, LPCWSTR name ) +{ + return CreateMutexExW( sa, name, owner ? CREATE_MUTEX_INITIAL_OWNER : 0, MUTEX_ALL_ACCESS ); +} + + +/*********************************************************************** + * CreateMutexExA (kernelbase.@) + */ +HANDLE WINAPI DECLSPEC_HOTPATCH CreateMutexExA( SECURITY_ATTRIBUTES *sa, LPCSTR name, + DWORD flags, DWORD access ) +{ + ANSI_STRING nameA; + NTSTATUS status; + + if (!name) return CreateMutexExW( sa, NULL, flags, access ); + + RtlInitAnsiString( &nameA, name ); + status = RtlAnsiStringToUnicodeString( &NtCurrentTeb()->StaticUnicodeString, &nameA, FALSE ); + if (status != STATUS_SUCCESS) + { + SetLastError( ERROR_FILENAME_EXCED_RANGE ); + return 0; + } + return CreateMutexExW( sa, NtCurrentTeb()->StaticUnicodeString.Buffer, flags, access ); +} + + +/*********************************************************************** + * CreateMutexExW (kernelbase.@) + */ +HANDLE WINAPI DECLSPEC_HOTPATCH CreateMutexExW( SECURITY_ATTRIBUTES *sa, LPCWSTR name, + DWORD flags, DWORD access ) +{ + HANDLE ret = 0; + UNICODE_STRING nameW; + OBJECT_ATTRIBUTES attr; + NTSTATUS status; + + get_create_object_attributes( &attr, &nameW, sa, name ); + + status = NtCreateMutant( &ret, access, &attr, (flags & CREATE_MUTEX_INITIAL_OWNER) != 0 ); + if (status == STATUS_OBJECT_NAME_EXISTS) + SetLastError( ERROR_ALREADY_EXISTS ); + else + SetLastError( RtlNtStatusToDosError(status) ); + return ret; +} + + +/*********************************************************************** + * OpenMutexW (kernelbase.@) + */ +HANDLE WINAPI DECLSPEC_HOTPATCH OpenMutexW( DWORD access, BOOL inherit, LPCWSTR name ) +{ + HANDLE ret; + UNICODE_STRING nameW; + OBJECT_ATTRIBUTES attr; + NTSTATUS status; + + if (!is_version_nt()) access = MUTEX_ALL_ACCESS; + + if (!get_open_object_attributes( &attr, &nameW, inherit, name )) return 0; + + status = NtOpenMutant( &ret, access, &attr ); + if (status != STATUS_SUCCESS) + { + SetLastError( RtlNtStatusToDosError(status) ); + return 0; + } + return ret; +} + + +/*********************************************************************** + * ReleaseMutex (kernelbase.@) + */ +BOOL WINAPI DECLSPEC_HOTPATCH ReleaseMutex( HANDLE handle ) +{ + return set_ntstatus( NtReleaseMutant( handle, NULL )); +}