Alexandre Julliard : kernel32: Add a helper function to fill object attributes in Create* functions.

Alexandre Julliard julliard at winehq.org
Fri Mar 2 12:16:44 CST 2018


Module: wine
Branch: master
Commit: 808693102e15025d1a08cbc2e27be7441e98aa75
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=808693102e15025d1a08cbc2e27be7441e98aa75

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Fri Mar  2 10:41:12 2018 +0100

kernel32: Add a helper function to fill object attributes in Create* functions.

Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/kernel32/sync.c | 82 ++++++++++++++--------------------------------------
 1 file changed, 22 insertions(+), 60 deletions(-)

diff --git a/dlls/kernel32/sync.c b/dlls/kernel32/sync.c
index fbe5c3b..c8dcdfc 100644
--- a/dlls/kernel32/sync.c
+++ b/dlls/kernel32/sync.c
@@ -81,6 +81,23 @@ HANDLE get_BaseNamedObjects_handle(void)
     return handle;
 }
 
+static void get_create_object_attributes( OBJECT_ATTRIBUTES *attr, UNICODE_STRING *nameW,
+                                          SECURITY_ATTRIBUTES *sa, const WCHAR *name )
+{
+    attr->Length                   = sizeof(*attr);
+    attr->RootDirectory            = 0;
+    attr->ObjectName               = NULL;
+    attr->Attributes               = OBJ_OPENIF | ((sa && sa->bInheritHandle) ? OBJ_INHERIT : 0);
+    attr->SecurityDescriptor       = sa ? sa->lpSecurityDescriptor : NULL;
+    attr->SecurityQualityOfService = NULL;
+    if (name)
+    {
+        RtlInitUnicodeString( nameW, name );
+        attr->ObjectName = nameW;
+        attr->RootDirectory = get_BaseNamedObjects_handle();
+    }
+}
+
 static BOOL get_open_object_attributes( OBJECT_ATTRIBUTES *attr, UNICODE_STRING *nameW,
                                         BOOL inherit, const WCHAR *name )
 {
@@ -490,18 +507,7 @@ HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventExW( SECURITY_ATTRIBUTES *sa, LPCWSTR
         return 0;
     }
 
-    attr.Length                   = sizeof(attr);
-    attr.RootDirectory            = 0;
-    attr.ObjectName               = NULL;
-    attr.Attributes               = OBJ_OPENIF | ((sa && sa->bInheritHandle) ? OBJ_INHERIT : 0);
-    attr.SecurityDescriptor       = sa ? sa->lpSecurityDescriptor : NULL;
-    attr.SecurityQualityOfService = NULL;
-    if (name)
-    {
-        RtlInitUnicodeString( &nameW, name );
-        attr.ObjectName = &nameW;
-        attr.RootDirectory = get_BaseNamedObjects_handle();
-    }
+    get_create_object_attributes( &attr, &nameW, sa, name );
 
     status = NtCreateEvent( &ret, access, &attr,
                             (flags & CREATE_EVENT_MANUAL_RESET) ? NotificationEvent : SynchronizationEvent,
@@ -643,18 +649,7 @@ HANDLE WINAPI DECLSPEC_HOTPATCH CreateMutexExW( SECURITY_ATTRIBUTES *sa, LPCWSTR
     OBJECT_ATTRIBUTES attr;
     NTSTATUS status;
 
-    attr.Length                   = sizeof(attr);
-    attr.RootDirectory            = 0;
-    attr.ObjectName               = NULL;
-    attr.Attributes               = OBJ_OPENIF | ((sa && sa->bInheritHandle) ? OBJ_INHERIT : 0);
-    attr.SecurityDescriptor       = sa ? sa->lpSecurityDescriptor : NULL;
-    attr.SecurityQualityOfService = NULL;
-    if (name)
-    {
-        RtlInitUnicodeString( &nameW, name );
-        attr.ObjectName = &nameW;
-        attr.RootDirectory = get_BaseNamedObjects_handle();
-    }
+    get_create_object_attributes( &attr, &nameW, sa, name );
 
     status = NtCreateMutant( &ret, access, &attr, (flags & CREATE_MUTEX_INITIAL_OWNER) != 0 );
     if (status == STATUS_OBJECT_NAME_EXISTS)
@@ -777,18 +772,7 @@ HANDLE WINAPI DECLSPEC_HOTPATCH CreateSemaphoreExW( SECURITY_ATTRIBUTES *sa, LON
     OBJECT_ATTRIBUTES attr;
     NTSTATUS status;
 
-    attr.Length                   = sizeof(attr);
-    attr.RootDirectory            = 0;
-    attr.ObjectName               = NULL;
-    attr.Attributes               = OBJ_OPENIF | ((sa && sa->bInheritHandle) ? OBJ_INHERIT : 0);
-    attr.SecurityDescriptor       = sa ? sa->lpSecurityDescriptor : NULL;
-    attr.SecurityQualityOfService = NULL;
-    if (name)
-    {
-        RtlInitUnicodeString( &nameW, name );
-        attr.ObjectName = &nameW;
-        attr.RootDirectory = get_BaseNamedObjects_handle();
-    }
+    get_create_object_attributes( &attr, &nameW, sa, name );
 
     status = NtCreateSemaphore( &ret, access, &attr, initial, max );
     if (status == STATUS_OBJECT_NAME_EXISTS)
@@ -866,18 +850,7 @@ HANDLE WINAPI CreateJobObjectW( LPSECURITY_ATTRIBUTES sa, LPCWSTR name )
     OBJECT_ATTRIBUTES attr;
     NTSTATUS status;
 
-    attr.Length                   = sizeof(attr);
-    attr.RootDirectory            = 0;
-    attr.ObjectName               = NULL;
-    attr.Attributes               = OBJ_OPENIF | ((sa && sa->bInheritHandle) ? OBJ_INHERIT : 0);
-    attr.SecurityDescriptor       = sa ? sa->lpSecurityDescriptor : NULL;
-    attr.SecurityQualityOfService = NULL;
-    if (name)
-    {
-        RtlInitUnicodeString( &nameW, name );
-        attr.ObjectName = &nameW;
-        attr.RootDirectory = get_BaseNamedObjects_handle();
-    }
+    get_create_object_attributes( &attr, &nameW, sa, name );
 
     status = NtCreateJobObject( &ret, JOB_OBJECT_ALL_ACCESS, &attr );
     if (status == STATUS_OBJECT_NAME_EXISTS)
@@ -1057,18 +1030,7 @@ HANDLE WINAPI CreateWaitableTimerExW( SECURITY_ATTRIBUTES *sa, LPCWSTR name, DWO
     UNICODE_STRING nameW;
     OBJECT_ATTRIBUTES attr;
 
-    attr.Length                   = sizeof(attr);
-    attr.RootDirectory            = 0;
-    attr.ObjectName               = NULL;
-    attr.Attributes               = OBJ_OPENIF | ((sa && sa->bInheritHandle) ? OBJ_INHERIT : 0);
-    attr.SecurityDescriptor       = sa ? sa->lpSecurityDescriptor : NULL;
-    attr.SecurityQualityOfService = NULL;
-    if (name)
-    {
-        RtlInitUnicodeString( &nameW, name );
-        attr.ObjectName = &nameW;
-        attr.RootDirectory = get_BaseNamedObjects_handle();
-    }
+    get_create_object_attributes( &attr, &nameW, sa, name );
 
     status = NtCreateTimer( &handle, access, &attr,
                  (flags & CREATE_WAITABLE_TIMER_MANUAL_RESET) ? NotificationTimer : SynchronizationTimer );




More information about the wine-cvs mailing list