[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 ****************************************************************/ /* FUNCTIONS ****************************************************************/
/* /*
* @implemented * @implemented
*/ */
HANDLE HANDLE
WINAPI WINAPI
CreateJobObjectA(LPSECURITY_ATTRIBUTES lpJobAttributes, CreateJobObjectA(IN LPSECURITY_ATTRIBUTES lpJobAttributes,
LPCSTR lpName) IN LPCSTR lpName)
{ {
/* Call the W(ide) function */ /* Call the W(ide) function */
ConvertWin32AnsiObjectApiToUnicodeApi(JobObject, lpName, lpJobAttributes); ConvertWin32AnsiObjectApiToUnicodeApi(JobObject, lpName, lpJobAttributes);
} }
/* /*
* @implemented * @implemented
*/ */
HANDLE HANDLE
WINAPI WINAPI
CreateJobObjectW(LPSECURITY_ATTRIBUTES lpJobAttributes, CreateJobObjectW(IN LPSECURITY_ATTRIBUTES lpJobAttributes,
LPCWSTR lpName) IN LPCWSTR lpName)
{ {
UNICODE_STRING JobName; /* Create the NT object */
OBJECT_ATTRIBUTES ObjectAttributes; CreateNtObjectFromWin32Api(JobObject, JobObject, JOB, lpJobAttributes, lpName);
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;
} }
/* /*
* @implemented * @implemented
*/ */

View file

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