From 761add0ea0f94e08fa0f97066bf35538793e43ae Mon Sep 17 00:00:00 2001 From: Alex Ionescu Date: Sat, 23 Jul 2011 09:40:34 +0000 Subject: [PATCH] [KERNEL32]: Create OpenNtObjectFromWin32Api macro (last one). [KERNEL32]: Make OpenJobObjectW use this macro (nothing fixed, it was already doing the right thing). svn path=/trunk/; revision=52790 --- reactos/dll/win32/kernel32/client/job.c | 31 ++------------------- reactos/dll/win32/kernel32/include/base_x.h | 30 ++++++++++++++++---- 2 files changed, 26 insertions(+), 35 deletions(-) diff --git a/reactos/dll/win32/kernel32/client/job.c b/reactos/dll/win32/kernel32/client/job.c index 4e28f711488..fdfa50726d0 100644 --- a/reactos/dll/win32/kernel32/client/job.c +++ b/reactos/dll/win32/kernel32/client/job.c @@ -51,35 +51,8 @@ OpenJobObjectW(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCWSTR lpName) { - OBJECT_ATTRIBUTES ObjectAttributes; - UNICODE_STRING JobName; - HANDLE hJob; - NTSTATUS Status; - - if (lpName == NULL) - { - SetLastError(ERROR_INVALID_PARAMETER); - return NULL; - } - - RtlInitUnicodeString(&JobName, lpName); - - InitializeObjectAttributes(&ObjectAttributes, - &JobName, - (bInheritHandle ? OBJ_INHERIT : 0), - NULL, - NULL); - - Status = NtOpenJobObject(&hJob, - dwDesiredAccess, - &ObjectAttributes); - if (!NT_SUCCESS(Status)) - { - SetLastErrorByStatus(Status); - return NULL; - } - - return hJob; + /* Open the NT object */ + OpenNtObjectFromWin32Api(JobObject, dwDesiredAccess, bInheritHandle, lpName); } diff --git a/reactos/dll/win32/kernel32/include/base_x.h b/reactos/dll/win32/kernel32/include/base_x.h index 4405710c4c8..5fa6fee8876 100644 --- a/reactos/dll/win32/kernel32/include/base_x.h +++ b/reactos/dll/win32/kernel32/include/base_x.h @@ -87,18 +87,18 @@ // It makes use of BasepConvertObjectAttributes and allows for a custom access // mode to be used, and also sets the correct error codes in case of a collision // -#define CreateNtObjectFromWin32ApiPrologue(sec, name) \ +#define CreateNtObjectFromWin32ApiPrologue \ { \ NTSTATUS Status; \ - OBJECT_ATTRIBUTES LocalAttributes; \ POBJECT_ATTRIBUTES ObjectAttributes; \ HANDLE Handle; \ UNICODE_STRING ObjectName; \ + OBJECT_ATTRIBUTES LocalAttributes; +#define CreateNtObjectFromWin32ApiBody(ntobj, sec, name, access, ...) \ if (name) RtlInitUnicodeString(&ObjectName, name); \ ObjectAttributes = BasepConvertObjectAttributes(&LocalAttributes, \ sec, \ - name ? &ObjectName : NULL); -#define CreateNtObjectFromWin32ApiBody(ntobj, access, ...) \ + name ? &ObjectName : NULL); \ Status = NtCreate##ntobj(&Handle, access, ObjectAttributes, ##__VA_ARGS__); #define CreateNtObjectFromWin32ApiEpilogue \ if (NT_SUCCESS(Status)) \ @@ -123,7 +123,25 @@ // above does support this. // #define CreateNtObjectFromWin32Api(obj, ntobj, capsobj, sec, name, ...) \ - CreateNtObjectFromWin32ApiPrologue(sec, name); \ - CreateNtObjectFromWin32ApiBody(ntobj, capsobj##_ALL_ACCESS, ##__VA_ARGS__); \ + CreateNtObjectFromWin32ApiPrologue \ + CreateNtObjectFromWin32ApiBody(ntobj, sec, name, capsobj##_ALL_ACCESS, ##__VA_ARGS__); \ CreateNtObjectFromWin32ApiEpilogue +// +// This macro opens an NT object based on the Win32 API settings. +// +#define OpenNtObjectFromWin32Api(ntobj, acc, inh, name) \ + CreateNtObjectFromWin32ApiPrologue \ + UNREFERENCED_PARAMETER(ObjectAttributes) \ + if (!name) SetLastErrorByStatus(STATUS_INVALID_PARAMETER); return NULL; \ + RtlInitUnicodeString(&ObjectName, name); \ + InitializeObjectAttributes(&LocalAttributes, \ + &ObjectName, \ + inh ? OBJ_INHERIT : 0, \ + hBaseDir, \ + NULL); \ + Status = NtOpen##ntobj(&Handle, acc, &LocalAttributes); \ + if (!NT_SUCCESS(Status)) SetLastErrorByStatus(Status); return NULL; \ + return Handle; \ +} +