[KERNEL32]: Fix the object macros to be MSVC/C99 compatible. Also allow for the variadic part to contain no arguments.

[KERNEL32]: Fix bugs #7, #8, #9, #10: CreateJobObjectW did not add OBJ_OPENIF to named jobs, it did not add named objects in the BaseNamedObjects directory, it did not correctly set ERROR_ALREADY_EXISTS when collisions happened, and it did not set ERROR_SUCCESS when the object was created. All this was fixed by using the new CreateNtObjectFromWin32Api macro.

svn path=/trunk/; revision=52788
This commit is contained in:
Alex Ionescu 2011-07-23 02:17:26 +00:00
parent 19366d1781
commit 5496adb4bc
2 changed files with 15 additions and 58 deletions

View file

@ -18,73 +18,30 @@
/* FUNCTIONS ****************************************************************/
/*
* @implemented
*/
HANDLE
WINAPI
CreateJobObjectA(LPSECURITY_ATTRIBUTES lpJobAttributes,
LPCSTR lpName)
CreateJobObjectA(IN LPSECURITY_ATTRIBUTES lpJobAttributes,
IN LPCSTR lpName)
{
/* Call the W(ide) function */
ConvertWin32AnsiObjectApiToUnicodeApi(JobObject, lpName, lpJobAttributes);
}
/*
* @implemented
*/
HANDLE
WINAPI
CreateJobObjectW(LPSECURITY_ATTRIBUTES lpJobAttributes,
LPCWSTR lpName)
CreateJobObjectW(IN LPSECURITY_ATTRIBUTES lpJobAttributes,
IN LPCWSTR lpName)
{
UNICODE_STRING JobName;
OBJECT_ATTRIBUTES ObjectAttributes;
ULONG Attributes = 0;
PVOID SecurityDescriptor;
HANDLE hJob;
NTSTATUS Status;
if (lpName != NULL)
{
RtlInitUnicodeString(&JobName, lpName);
}
if (lpJobAttributes != NULL)
{
if (lpJobAttributes->bInheritHandle)
{
Attributes |= OBJ_INHERIT;
}
SecurityDescriptor = lpJobAttributes->lpSecurityDescriptor;
}
else
{
SecurityDescriptor = NULL;
}
InitializeObjectAttributes(&ObjectAttributes,
((lpName != NULL) ? &JobName : NULL),
Attributes,
NULL,
SecurityDescriptor);
Status = NtCreateJobObject(&hJob,
JOB_OBJECT_ALL_ACCESS,
&ObjectAttributes);
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus(Status);
return NULL;
}
return hJob;
/* Create the NT object */
CreateNtObjectFromWin32Api(JobObject, JobObject, JOB, lpJobAttributes, lpName);
}
/*
* @implemented
*/

View file

@ -51,21 +51,21 @@
// This macro uses the ConvertAnsiToUnicode macros above to convert a CreateXxxA
// Win32 API into its equivalent CreateXxxW API.
//
#define ConvertWin32AnsiObjectApiToUnicodeApi(obj, name, args...) \
#define ConvertWin32AnsiObjectApiToUnicodeApi(obj, name, ...) \
ConvertAnsiToUnicodePrologue \
if (!name) return Create##obj##W(args, NULL); \
if (!name) return Create##obj##W(__VA_ARGS__, NULL); \
ConvertAnsiToUnicodeBody(name) \
if (NT_SUCCESS(Status)) return Create##obj##W(args, UnicodeCache->Buffer); \
if (NT_SUCCESS(Status)) return Create##obj##W(__VA_ARGS__, UnicodeCache->Buffer); \
ConvertAnsiToUnicodeEpilogue
//
// This macro uses the ConvertAnsiToUnicode macros above to convert a FindFirst*A
// Win32 API into its equivalent FindFirst*W API.
//
#define ConvertWin32AnsiChangeApiToUnicodeApi(obj, name, args...) \
#define ConvertWin32AnsiChangeApiToUnicodeApi(obj, name, ...) \
ConvertAnsiToUnicodePrologue \
ConvertAnsiToUnicodeBody(name) \
if (NT_SUCCESS(Status)) return obj##W(UnicodeCache->Buffer, args); \
if (NT_SUCCESS(Status)) return obj##W(UnicodeCache->Buffer, ##__VA_ARGS__); \
ConvertAnsiToUnicodeEpilogue
//
@ -87,8 +87,8 @@
ObjectAttributes = BasepConvertObjectAttributes(&LocalAttributes, \
sec, \
name ? &ObjectName : NULL);
#define CreateNtObjectFromWin32ApiBody(ntobj, access, args...) \
Status = NtCreate##ntobj(&Handle, access, ObjectAttributes, args);
#define CreateNtObjectFromWin32ApiBody(ntobj, access, ...) \
Status = NtCreate##ntobj(&Handle, access, ObjectAttributes, ##__VA_ARGS__);
#define CreateNtObjectFromWin32ApiEpilogue \
if (NT_SUCCESS(Status)) \
{ \
@ -111,8 +111,8 @@
// be improved to support caller-specified access masks, as the underlying macro
// above does support this.
//
#define CreateNtObjectFromWin32Api(obj, ntobj, capsobj, sec, name, args...) \
#define CreateNtObjectFromWin32Api(obj, ntobj, capsobj, sec, name, ...) \
CreateNtObjectFromWin32ApiPrologue(sec, name); \
CreateNtObjectFromWin32ApiBody(ntobj, capsobj##_ALL_ACCESS, args); \
CreateNtObjectFromWin32ApiBody(ntobj, capsobj##_ALL_ACCESS, ##__VA_ARGS__); \
CreateNtObjectFromWin32ApiEpilogue