[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
This commit is contained in:
Alex Ionescu 2011-07-23 09:40:34 +00:00
parent d06e82af03
commit 761add0ea0
2 changed files with 26 additions and 35 deletions

View file

@ -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);
}

View file

@ -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; \
}