Commit 80869310 authored by Alexandre Julliard's avatar Alexandre Julliard

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

parent a7aa192a
...@@ -81,6 +81,23 @@ HANDLE get_BaseNamedObjects_handle(void) ...@@ -81,6 +81,23 @@ HANDLE get_BaseNamedObjects_handle(void)
return handle; 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, static BOOL get_open_object_attributes( OBJECT_ATTRIBUTES *attr, UNICODE_STRING *nameW,
BOOL inherit, const WCHAR *name ) BOOL inherit, const WCHAR *name )
{ {
...@@ -490,18 +507,7 @@ HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventExW( SECURITY_ATTRIBUTES *sa, LPCWSTR ...@@ -490,18 +507,7 @@ HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventExW( SECURITY_ATTRIBUTES *sa, LPCWSTR
return 0; return 0;
} }
attr.Length = sizeof(attr); get_create_object_attributes( &attr, &nameW, sa, name );
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();
}
status = NtCreateEvent( &ret, access, &attr, status = NtCreateEvent( &ret, access, &attr,
(flags & CREATE_EVENT_MANUAL_RESET) ? NotificationEvent : SynchronizationEvent, (flags & CREATE_EVENT_MANUAL_RESET) ? NotificationEvent : SynchronizationEvent,
...@@ -643,18 +649,7 @@ HANDLE WINAPI DECLSPEC_HOTPATCH CreateMutexExW( SECURITY_ATTRIBUTES *sa, LPCWSTR ...@@ -643,18 +649,7 @@ HANDLE WINAPI DECLSPEC_HOTPATCH CreateMutexExW( SECURITY_ATTRIBUTES *sa, LPCWSTR
OBJECT_ATTRIBUTES attr; OBJECT_ATTRIBUTES attr;
NTSTATUS status; NTSTATUS status;
attr.Length = sizeof(attr); get_create_object_attributes( &attr, &nameW, sa, name );
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();
}
status = NtCreateMutant( &ret, access, &attr, (flags & CREATE_MUTEX_INITIAL_OWNER) != 0 ); status = NtCreateMutant( &ret, access, &attr, (flags & CREATE_MUTEX_INITIAL_OWNER) != 0 );
if (status == STATUS_OBJECT_NAME_EXISTS) if (status == STATUS_OBJECT_NAME_EXISTS)
...@@ -777,18 +772,7 @@ HANDLE WINAPI DECLSPEC_HOTPATCH CreateSemaphoreExW( SECURITY_ATTRIBUTES *sa, LON ...@@ -777,18 +772,7 @@ HANDLE WINAPI DECLSPEC_HOTPATCH CreateSemaphoreExW( SECURITY_ATTRIBUTES *sa, LON
OBJECT_ATTRIBUTES attr; OBJECT_ATTRIBUTES attr;
NTSTATUS status; NTSTATUS status;
attr.Length = sizeof(attr); get_create_object_attributes( &attr, &nameW, sa, name );
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();
}
status = NtCreateSemaphore( &ret, access, &attr, initial, max ); status = NtCreateSemaphore( &ret, access, &attr, initial, max );
if (status == STATUS_OBJECT_NAME_EXISTS) if (status == STATUS_OBJECT_NAME_EXISTS)
...@@ -866,18 +850,7 @@ HANDLE WINAPI CreateJobObjectW( LPSECURITY_ATTRIBUTES sa, LPCWSTR name ) ...@@ -866,18 +850,7 @@ HANDLE WINAPI CreateJobObjectW( LPSECURITY_ATTRIBUTES sa, LPCWSTR name )
OBJECT_ATTRIBUTES attr; OBJECT_ATTRIBUTES attr;
NTSTATUS status; NTSTATUS status;
attr.Length = sizeof(attr); get_create_object_attributes( &attr, &nameW, sa, name );
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();
}
status = NtCreateJobObject( &ret, JOB_OBJECT_ALL_ACCESS, &attr ); status = NtCreateJobObject( &ret, JOB_OBJECT_ALL_ACCESS, &attr );
if (status == STATUS_OBJECT_NAME_EXISTS) if (status == STATUS_OBJECT_NAME_EXISTS)
...@@ -1057,18 +1030,7 @@ HANDLE WINAPI CreateWaitableTimerExW( SECURITY_ATTRIBUTES *sa, LPCWSTR name, DWO ...@@ -1057,18 +1030,7 @@ HANDLE WINAPI CreateWaitableTimerExW( SECURITY_ATTRIBUTES *sa, LPCWSTR name, DWO
UNICODE_STRING nameW; UNICODE_STRING nameW;
OBJECT_ATTRIBUTES attr; OBJECT_ATTRIBUTES attr;
attr.Length = sizeof(attr); get_create_object_attributes( &attr, &nameW, sa, name );
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();
}
status = NtCreateTimer( &handle, access, &attr, status = NtCreateTimer( &handle, access, &attr,
(flags & CREATE_WAITABLE_TIMER_MANUAL_RESET) ? NotificationTimer : SynchronizationTimer ); (flags & CREATE_WAITABLE_TIMER_MANUAL_RESET) ? NotificationTimer : SynchronizationTimer );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment