From 5496adb4bccc7e648c7514d6c92f9c9f0a9b866b Mon Sep 17 00:00:00 2001 From: Alex Ionescu Date: Sat, 23 Jul 2011 02:17:26 +0000 Subject: [PATCH] [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 --- reactos/dll/win32/kernel32/client/job.c | 55 +++------------------ reactos/dll/win32/kernel32/include/base_x.h | 18 +++---- 2 files changed, 15 insertions(+), 58 deletions(-) diff --git a/reactos/dll/win32/kernel32/client/job.c b/reactos/dll/win32/kernel32/client/job.c index 275790b9d21..6e830ed8685 100644 --- a/reactos/dll/win32/kernel32/client/job.c +++ b/reactos/dll/win32/kernel32/client/job.c @@ -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 */ diff --git a/reactos/dll/win32/kernel32/include/base_x.h b/reactos/dll/win32/kernel32/include/base_x.h index eaa538d661b..877e11375a9 100644 --- a/reactos/dll/win32/kernel32/include/base_x.h +++ b/reactos/dll/win32/kernel32/include/base_x.h @@ -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