mirror of
https://github.com/reactos/reactos.git
synced 2025-06-19 06:45:43 +00:00
[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:
parent
d06e82af03
commit
761add0ea0
2 changed files with 26 additions and 35 deletions
|
@ -51,35 +51,8 @@ OpenJobObjectW(DWORD dwDesiredAccess,
|
||||||
BOOL bInheritHandle,
|
BOOL bInheritHandle,
|
||||||
LPCWSTR lpName)
|
LPCWSTR lpName)
|
||||||
{
|
{
|
||||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
/* Open the NT object */
|
||||||
UNICODE_STRING JobName;
|
OpenNtObjectFromWin32Api(JobObject, dwDesiredAccess, bInheritHandle, lpName);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -87,18 +87,18 @@
|
||||||
// It makes use of BasepConvertObjectAttributes and allows for a custom access
|
// 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
|
// mode to be used, and also sets the correct error codes in case of a collision
|
||||||
//
|
//
|
||||||
#define CreateNtObjectFromWin32ApiPrologue(sec, name) \
|
#define CreateNtObjectFromWin32ApiPrologue \
|
||||||
{ \
|
{ \
|
||||||
NTSTATUS Status; \
|
NTSTATUS Status; \
|
||||||
OBJECT_ATTRIBUTES LocalAttributes; \
|
|
||||||
POBJECT_ATTRIBUTES ObjectAttributes; \
|
POBJECT_ATTRIBUTES ObjectAttributes; \
|
||||||
HANDLE Handle; \
|
HANDLE Handle; \
|
||||||
UNICODE_STRING ObjectName; \
|
UNICODE_STRING ObjectName; \
|
||||||
|
OBJECT_ATTRIBUTES LocalAttributes;
|
||||||
|
#define CreateNtObjectFromWin32ApiBody(ntobj, sec, name, access, ...) \
|
||||||
if (name) RtlInitUnicodeString(&ObjectName, name); \
|
if (name) RtlInitUnicodeString(&ObjectName, name); \
|
||||||
ObjectAttributes = BasepConvertObjectAttributes(&LocalAttributes, \
|
ObjectAttributes = BasepConvertObjectAttributes(&LocalAttributes, \
|
||||||
sec, \
|
sec, \
|
||||||
name ? &ObjectName : NULL);
|
name ? &ObjectName : NULL); \
|
||||||
#define CreateNtObjectFromWin32ApiBody(ntobj, access, ...) \
|
|
||||||
Status = NtCreate##ntobj(&Handle, access, ObjectAttributes, ##__VA_ARGS__);
|
Status = NtCreate##ntobj(&Handle, access, ObjectAttributes, ##__VA_ARGS__);
|
||||||
#define CreateNtObjectFromWin32ApiEpilogue \
|
#define CreateNtObjectFromWin32ApiEpilogue \
|
||||||
if (NT_SUCCESS(Status)) \
|
if (NT_SUCCESS(Status)) \
|
||||||
|
@ -123,7 +123,25 @@
|
||||||
// above does support this.
|
// above does support this.
|
||||||
//
|
//
|
||||||
#define CreateNtObjectFromWin32Api(obj, ntobj, capsobj, sec, name, ...) \
|
#define CreateNtObjectFromWin32Api(obj, ntobj, capsobj, sec, name, ...) \
|
||||||
CreateNtObjectFromWin32ApiPrologue(sec, name); \
|
CreateNtObjectFromWin32ApiPrologue \
|
||||||
CreateNtObjectFromWin32ApiBody(ntobj, capsobj##_ALL_ACCESS, ##__VA_ARGS__); \
|
CreateNtObjectFromWin32ApiBody(ntobj, sec, name, capsobj##_ALL_ACCESS, ##__VA_ARGS__); \
|
||||||
CreateNtObjectFromWin32ApiEpilogue
|
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; \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue