Author: ion
Date: Sat Jul 23 10:00:32 2011
New Revision: 52793
URL:
http://svn.reactos.org/svn/reactos?rev=52793&view=rev
Log:
[KERNEL32]: Make Mutex APIs use the macros too. Fixes bugs #16/#17, same as #14/#15.
Modified:
trunk/reactos/dll/win32/kernel32/client/synch.c
Modified: trunk/reactos/dll/win32/kernel32/client/synch.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/client/…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/client/synch.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/client/synch.c [iso-8859-1] Sat Jul 23 10:00:32 2011
@@ -787,125 +787,11 @@
*/
HANDLE
WINAPI
-CreateMutexExA(IN LPSECURITY_ATTRIBUTES lpMutexAttributes OPTIONAL,
- IN LPCSTR lpName OPTIONAL,
- IN DWORD dwFlags,
- IN DWORD dwDesiredAccess)
-{
- NTSTATUS Status;
- ANSI_STRING AnsiName;
- PUNICODE_STRING UnicodeCache;
- LPCWSTR UnicodeName = NULL;
-
- /* Check for a name */
- if (lpName)
- {
- /* Use TEB Cache */
- UnicodeCache = &NtCurrentTeb()->StaticUnicodeString;
-
- /* Convert to unicode */
- RtlInitAnsiString(&AnsiName, lpName);
- Status = RtlAnsiStringToUnicodeString(UnicodeCache, &AnsiName, FALSE);
- if (!NT_SUCCESS(Status))
- {
- /* Conversion failed */
- SetLastErrorByStatus(Status);
- return NULL;
- }
-
- /* Otherwise, save the buffer */
- UnicodeName = (LPCWSTR)UnicodeCache->Buffer;
- }
-
- /* Call the Unicode API */
- return CreateMutexExW(lpMutexAttributes,
- UnicodeName,
- dwFlags,
- dwDesiredAccess);
-}
-
-/*
- * @implemented
- */
-HANDLE
-WINAPI
-CreateMutexExW(IN LPSECURITY_ATTRIBUTES lpMutexAttributes OPTIONAL,
- IN LPCWSTR lpName OPTIONAL,
- IN DWORD dwFlags,
- IN DWORD dwDesiredAccess)
-{
- NTSTATUS Status;
- OBJECT_ATTRIBUTES LocalAttributes;
- POBJECT_ATTRIBUTES ObjectAttributes;
- HANDLE Handle;
- UNICODE_STRING ObjectName;
- BOOLEAN InitialOwner;
-
- /* Now check if we got a name */
- if (lpName) RtlInitUnicodeString(&ObjectName, lpName);
-
- if (dwFlags & ~(CREATE_MUTEX_INITIAL_OWNER))
- {
- SetLastError(ERROR_INVALID_PARAMETER);
- return NULL;
- }
-
- InitialOwner = (dwFlags & CREATE_MUTEX_INITIAL_OWNER) != 0;
-
- /* Now convert the object attributes */
- ObjectAttributes = BasepConvertObjectAttributes(&LocalAttributes,
- lpMutexAttributes,
- lpName ? &ObjectName : NULL);
-
- /* Create the mutant */
- Status = NtCreateMutant(&Handle,
- (ACCESS_MASK)dwDesiredAccess,
- ObjectAttributes,
- InitialOwner);
- if (NT_SUCCESS(Status))
- {
- /* Check if the object already existed */
- if (Status == STATUS_OBJECT_NAME_EXISTS)
- {
- /* Set distinguished Win32 error code */
- SetLastError(ERROR_ALREADY_EXISTS);
- }
- else
- {
- /* Otherwise, set success */
- SetLastError(ERROR_SUCCESS);
- }
-
- /* Return the handle */
- return Handle;
- }
- else
- {
- /* Convert the NT Status and fail */
- SetLastErrorByStatus(Status);
- return NULL;
- }
-
-}
-
-/*
- * @implemented
- */
-HANDLE
-WINAPI
CreateMutexA(IN LPSECURITY_ATTRIBUTES lpMutexAttributes OPTIONAL,
IN BOOL bInitialOwner,
IN LPCSTR lpName OPTIONAL)
{
- DWORD dwFlags = 0;
-
- if (bInitialOwner)
- dwFlags |= CREATE_MUTEX_INITIAL_OWNER;
-
- return CreateMutexExA(lpMutexAttributes,
- lpName,
- dwFlags,
- MUTANT_ALL_ACCESS);
+ CreateNtObjectFromWin32Api(Mutex, lpMutexAttributes, bInitialOwner, lpName);
}
/*
@@ -917,15 +803,10 @@
IN BOOL bInitialOwner,
IN LPCWSTR lpName OPTIONAL)
{
- DWORD dwFlags = 0;
-
- if (bInitialOwner)
- dwFlags |= CREATE_MUTEX_INITIAL_OWNER;
-
- return CreateMutexExW(lpMutexAttributes,
- lpName,
- dwFlags,
- MUTANT_ALL_ACCESS);
+ CreateNtObjectFromWin32ApiW(Mutex, Mutant, MUTEX,
+ lpMutexAttributes,
+ bInitialOwner,
+ lpName);
}
/*
@@ -937,37 +818,7 @@
IN BOOL bInheritHandle,
IN LPCSTR lpName)
{
- NTSTATUS Status;
- ANSI_STRING AnsiName;
- PUNICODE_STRING UnicodeCache;
-
- /* Check for a name */
- if (lpName)
- {
- /* Use TEB Cache */
- UnicodeCache = &NtCurrentTeb()->StaticUnicodeString;
-
- /* Convert to unicode */
- RtlInitAnsiString(&AnsiName, lpName);
- Status = RtlAnsiStringToUnicodeString(UnicodeCache, &AnsiName, FALSE);
- if (!NT_SUCCESS(Status))
- {
- /* Conversion failed */
- SetLastErrorByStatus(Status);
- return NULL;
- }
- }
- else
- {
- /* We need a name */
- SetLastError(ERROR_INVALID_PARAMETER);
- return NULL;
- }
-
- /* Call the Unicode API */
- return OpenMutexW(dwDesiredAccess,
- bInheritHandle,
- (LPCWSTR)UnicodeCache->Buffer);
+ OpenNtObjectFromWin32Api(Mutex, dwDesiredAccess, bInheritHandle, lpName);
}
/*
@@ -979,38 +830,7 @@
IN BOOL bInheritHandle,
IN LPCWSTR lpName)
{
- OBJECT_ATTRIBUTES ObjectAttributes;
- UNICODE_STRING ObjectName;
- NTSTATUS Status;
- HANDLE Handle;
-
- /* Make sure we got a name */
- if (!lpName)
- {
- /* Fail without one */
- SetLastErrorByStatus(STATUS_INVALID_PARAMETER);
- return NULL;
- }
-
- /* Initialize the object name and attributes */
- RtlInitUnicodeString(&ObjectName, lpName);
- InitializeObjectAttributes(&ObjectAttributes,
- &ObjectName,
- bInheritHandle ? OBJ_INHERIT : 0,
- hBaseDir,
- NULL);
-
- /* Open the mutant */
- Status = NtOpenMutant(&Handle, dwDesiredAccess, &ObjectAttributes);
- if (!NT_SUCCESS(Status))
- {
- /* Convert the status and fail */
- SetLastErrorByStatus(Status);
- return NULL;
- }
-
- /* Return the handle */
- return Handle;
+ OpenNtObjectFromWin32ApiW(Mutant, dwDesiredAccess, bInheritHandle, lpName);
}
/*