[KERNEL32]: Make Mutex APIs use the macros too. Fixes bugs #16/#17, same as #14/#15.

svn path=/trunk/; revision=52793
This commit is contained in:
Alex Ionescu
2011-07-23 10:00:32 +00:00
parent 9560a7dff9
commit fd601c6a41
+7 -187
View File
@@ -782,112 +782,6 @@ ReleaseSemaphore(IN HANDLE hSemaphore,
return FALSE;
}
/*
* @implemented
*/
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
*/
@@ -897,15 +791,7 @@ 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 @@ CreateMutexW(IN LPSECURITY_ATTRIBUTES lpMutexAttributes OPTIONAL,
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 @@ OpenMutexA(IN DWORD dwDesiredAccess,
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 @@ OpenMutexW(IN DWORD dwDesiredAccess,
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);
}
/*