Author: ion
Date: Sat Jul 23 09:40:34 2011
New Revision: 52790

URL: http://svn.reactos.org/svn/reactos?rev=52790&view=rev
Log:
[KERNEL32]: Create OpenNtObjectFromWin32Api macro (last one).
[KERNEL32]: Make OpenJobObjectW use this macro (nothing fixed, it was already 
doing the right thing).

Modified:
    trunk/reactos/dll/win32/kernel32/client/job.c
    trunk/reactos/dll/win32/kernel32/include/base_x.h

Modified: trunk/reactos/dll/win32/kernel32/client/job.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/client/job.c?rev=52790&r1=52789&r2=52790&view=diff
==============================================================================
--- trunk/reactos/dll/win32/kernel32/client/job.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/client/job.c [iso-8859-1] Sat Jul 23 
09:40:34 2011
@@ -51,35 +51,8 @@
                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);
 }
 
 

Modified: trunk/reactos/dll/win32/kernel32/include/base_x.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/include/base_x.h?rev=52790&r1=52789&r2=52790&view=diff
==============================================================================
--- trunk/reactos/dll/win32/kernel32/include/base_x.h [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/include/base_x.h [iso-8859-1] Sat Jul 23 
09:40:34 2011
@@ -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;                                                             
 \
+}
+


Reply via email to