ntdll: Move the semaphore functions to the Unix library.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
a184449841
commit
39915c9bc4
|
@ -246,34 +246,10 @@ NTSTATUS validate_open_object_attributes( const OBJECT_ATTRIBUTES *attr )
|
|||
/******************************************************************************
|
||||
* NtCreateSemaphore (NTDLL.@)
|
||||
*/
|
||||
NTSTATUS WINAPI NtCreateSemaphore( OUT PHANDLE SemaphoreHandle,
|
||||
IN ACCESS_MASK access,
|
||||
IN const OBJECT_ATTRIBUTES *attr OPTIONAL,
|
||||
IN LONG InitialCount,
|
||||
IN LONG MaximumCount )
|
||||
NTSTATUS WINAPI NtCreateSemaphore( HANDLE *handle, ACCESS_MASK access, const OBJECT_ATTRIBUTES *attr,
|
||||
LONG initial, LONG max )
|
||||
{
|
||||
NTSTATUS ret;
|
||||
data_size_t len;
|
||||
struct object_attributes *objattr;
|
||||
|
||||
if (MaximumCount <= 0 || InitialCount < 0 || InitialCount > MaximumCount)
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
|
||||
if ((ret = alloc_object_attributes( attr, &objattr, &len ))) return ret;
|
||||
|
||||
SERVER_START_REQ( create_semaphore )
|
||||
{
|
||||
req->access = access;
|
||||
req->initial = InitialCount;
|
||||
req->max = MaximumCount;
|
||||
wine_server_add_data( req, objattr, len );
|
||||
ret = wine_server_call( req );
|
||||
*SemaphoreHandle = wine_server_ptr_handle( reply->handle );
|
||||
}
|
||||
SERVER_END_REQ;
|
||||
|
||||
RtlFreeHeap( GetProcessHeap(), 0, objattr );
|
||||
return ret;
|
||||
return unix_funcs->NtCreateSemaphore( handle, access, attr, initial, max );
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
|
@ -281,22 +257,7 @@ NTSTATUS WINAPI NtCreateSemaphore( OUT PHANDLE SemaphoreHandle,
|
|||
*/
|
||||
NTSTATUS WINAPI NtOpenSemaphore( HANDLE *handle, ACCESS_MASK access, const OBJECT_ATTRIBUTES *attr )
|
||||
{
|
||||
NTSTATUS ret;
|
||||
|
||||
if ((ret = validate_open_object_attributes( attr ))) return ret;
|
||||
|
||||
SERVER_START_REQ( open_semaphore )
|
||||
{
|
||||
req->access = access;
|
||||
req->attributes = attr->Attributes;
|
||||
req->rootdir = wine_server_obj_handle( attr->RootDirectory );
|
||||
if (attr->ObjectName)
|
||||
wine_server_add_data( req, attr->ObjectName->Buffer, attr->ObjectName->Length );
|
||||
ret = wine_server_call( req );
|
||||
*handle = wine_server_ptr_handle( reply->handle );
|
||||
}
|
||||
SERVER_END_REQ;
|
||||
return ret;
|
||||
return unix_funcs->NtOpenSemaphore( handle, access, attr );
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
|
@ -305,32 +266,7 @@ NTSTATUS WINAPI NtOpenSemaphore( HANDLE *handle, ACCESS_MASK access, const OBJEC
|
|||
NTSTATUS WINAPI NtQuerySemaphore( HANDLE handle, SEMAPHORE_INFORMATION_CLASS class,
|
||||
void *info, ULONG len, ULONG *ret_len )
|
||||
{
|
||||
NTSTATUS ret;
|
||||
SEMAPHORE_BASIC_INFORMATION *out = info;
|
||||
|
||||
TRACE("(%p, %u, %p, %u, %p)\n", handle, class, info, len, ret_len);
|
||||
|
||||
if (class != SemaphoreBasicInformation)
|
||||
{
|
||||
FIXME("(%p,%d,%u) Unknown class\n", handle, class, len);
|
||||
return STATUS_INVALID_INFO_CLASS;
|
||||
}
|
||||
|
||||
if (len != sizeof(SEMAPHORE_BASIC_INFORMATION)) return STATUS_INFO_LENGTH_MISMATCH;
|
||||
|
||||
SERVER_START_REQ( query_semaphore )
|
||||
{
|
||||
req->handle = wine_server_obj_handle( handle );
|
||||
if (!(ret = wine_server_call( req )))
|
||||
{
|
||||
out->CurrentCount = reply->current;
|
||||
out->MaximumCount = reply->max;
|
||||
if (ret_len) *ret_len = sizeof(SEMAPHORE_BASIC_INFORMATION);
|
||||
}
|
||||
}
|
||||
SERVER_END_REQ;
|
||||
|
||||
return ret;
|
||||
return unix_funcs->NtQuerySemaphore( handle, class, info, len, ret_len );
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
|
@ -338,18 +274,7 @@ NTSTATUS WINAPI NtQuerySemaphore( HANDLE handle, SEMAPHORE_INFORMATION_CLASS cla
|
|||
*/
|
||||
NTSTATUS WINAPI NtReleaseSemaphore( HANDLE handle, ULONG count, PULONG previous )
|
||||
{
|
||||
NTSTATUS ret;
|
||||
SERVER_START_REQ( release_semaphore )
|
||||
{
|
||||
req->handle = wine_server_obj_handle( handle );
|
||||
req->count = count;
|
||||
if (!(ret = wine_server_call( req )))
|
||||
{
|
||||
if (previous) *previous = reply->prev_count;
|
||||
}
|
||||
}
|
||||
SERVER_END_REQ;
|
||||
return ret;
|
||||
return unix_funcs->NtReleaseSemaphore( handle, count, previous );
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -986,6 +986,7 @@ static struct unix_funcs unix_funcs =
|
|||
NtAllocateVirtualMemory,
|
||||
NtAreMappedFilesTheSame,
|
||||
NtClose,
|
||||
NtCreateSemaphore,
|
||||
NtCurrentTeb,
|
||||
NtDelayExecution,
|
||||
NtDuplicateObject,
|
||||
|
@ -995,10 +996,13 @@ static struct unix_funcs unix_funcs =
|
|||
NtGetWriteWatch,
|
||||
NtLockVirtualMemory,
|
||||
NtMapViewOfSection,
|
||||
NtOpenSemaphore,
|
||||
NtProtectVirtualMemory,
|
||||
NtQuerySection,
|
||||
NtQuerySemaphore,
|
||||
NtQueryVirtualMemory,
|
||||
NtReadVirtualMemory,
|
||||
NtReleaseSemaphore,
|
||||
NtResetWriteWatch,
|
||||
NtSetContextThread,
|
||||
NtSetLdtEntries,
|
||||
|
|
|
@ -62,8 +62,217 @@
|
|||
#include "windef.h"
|
||||
#include "winternl.h"
|
||||
#include "wine/server.h"
|
||||
#include "wine/debug.h"
|
||||
#include "unix_private.h"
|
||||
|
||||
WINE_DEFAULT_DEBUG_CHANNEL(sync);
|
||||
|
||||
|
||||
/* create a struct security_descriptor and contained information in one contiguous piece of memory */
|
||||
static NTSTATUS alloc_object_attributes( const OBJECT_ATTRIBUTES *attr, struct object_attributes **ret,
|
||||
data_size_t *ret_len )
|
||||
{
|
||||
unsigned int len = sizeof(**ret);
|
||||
PSID owner = NULL, group = NULL;
|
||||
ACL *dacl, *sacl;
|
||||
BOOLEAN dacl_present, sacl_present, defaulted;
|
||||
PSECURITY_DESCRIPTOR sd;
|
||||
NTSTATUS status;
|
||||
|
||||
*ret = NULL;
|
||||
*ret_len = 0;
|
||||
|
||||
if (!attr) return STATUS_SUCCESS;
|
||||
|
||||
if (attr->Length != sizeof(*attr)) return STATUS_INVALID_PARAMETER;
|
||||
|
||||
if ((sd = attr->SecurityDescriptor))
|
||||
{
|
||||
len += sizeof(struct security_descriptor);
|
||||
|
||||
if ((status = RtlGetOwnerSecurityDescriptor( sd, &owner, &defaulted ))) return status;
|
||||
if ((status = RtlGetGroupSecurityDescriptor( sd, &group, &defaulted ))) return status;
|
||||
if ((status = RtlGetSaclSecurityDescriptor( sd, &sacl_present, &sacl, &defaulted ))) return status;
|
||||
if ((status = RtlGetDaclSecurityDescriptor( sd, &dacl_present, &dacl, &defaulted ))) return status;
|
||||
if (owner) len += RtlLengthSid( owner );
|
||||
if (group) len += RtlLengthSid( group );
|
||||
if (sacl_present && sacl) len += sacl->AclSize;
|
||||
if (dacl_present && dacl) len += dacl->AclSize;
|
||||
|
||||
/* fix alignment for the Unicode name that follows the structure */
|
||||
len = (len + sizeof(WCHAR) - 1) & ~(sizeof(WCHAR) - 1);
|
||||
}
|
||||
|
||||
if (attr->ObjectName)
|
||||
{
|
||||
if (attr->ObjectName->Length & (sizeof(WCHAR) - 1)) return STATUS_OBJECT_NAME_INVALID;
|
||||
len += attr->ObjectName->Length;
|
||||
}
|
||||
else if (attr->RootDirectory) return STATUS_OBJECT_NAME_INVALID;
|
||||
|
||||
len = (len + 3) & ~3; /* DWORD-align the entire structure */
|
||||
|
||||
*ret = RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY, len );
|
||||
if (!*ret) return STATUS_NO_MEMORY;
|
||||
|
||||
(*ret)->rootdir = wine_server_obj_handle( attr->RootDirectory );
|
||||
(*ret)->attributes = attr->Attributes;
|
||||
|
||||
if (attr->SecurityDescriptor)
|
||||
{
|
||||
struct security_descriptor *descr = (struct security_descriptor *)(*ret + 1);
|
||||
unsigned char *ptr = (unsigned char *)(descr + 1);
|
||||
|
||||
descr->control = ((SECURITY_DESCRIPTOR *)sd)->Control & ~SE_SELF_RELATIVE;
|
||||
if (owner) descr->owner_len = RtlLengthSid( owner );
|
||||
if (group) descr->group_len = RtlLengthSid( group );
|
||||
if (sacl_present && sacl) descr->sacl_len = sacl->AclSize;
|
||||
if (dacl_present && dacl) descr->dacl_len = dacl->AclSize;
|
||||
|
||||
memcpy( ptr, owner, descr->owner_len );
|
||||
ptr += descr->owner_len;
|
||||
memcpy( ptr, group, descr->group_len );
|
||||
ptr += descr->group_len;
|
||||
memcpy( ptr, sacl, descr->sacl_len );
|
||||
ptr += descr->sacl_len;
|
||||
memcpy( ptr, dacl, descr->dacl_len );
|
||||
(*ret)->sd_len = (sizeof(*descr) + descr->owner_len + descr->group_len + descr->sacl_len +
|
||||
descr->dacl_len + sizeof(WCHAR) - 1) & ~(sizeof(WCHAR) - 1);
|
||||
}
|
||||
|
||||
if (attr->ObjectName)
|
||||
{
|
||||
unsigned char *ptr = (unsigned char *)(*ret + 1) + (*ret)->sd_len;
|
||||
(*ret)->name_len = attr->ObjectName->Length;
|
||||
memcpy( ptr, attr->ObjectName->Buffer, (*ret)->name_len );
|
||||
}
|
||||
|
||||
*ret_len = len;
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static NTSTATUS validate_open_object_attributes( const OBJECT_ATTRIBUTES *attr )
|
||||
{
|
||||
if (!attr || attr->Length != sizeof(*attr)) return STATUS_INVALID_PARAMETER;
|
||||
|
||||
if (attr->ObjectName)
|
||||
{
|
||||
if (attr->ObjectName->Length & (sizeof(WCHAR) - 1)) return STATUS_OBJECT_NAME_INVALID;
|
||||
}
|
||||
else if (attr->RootDirectory) return STATUS_OBJECT_NAME_INVALID;
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* NtCreateSemaphore (NTDLL.@)
|
||||
*/
|
||||
NTSTATUS WINAPI NtCreateSemaphore( HANDLE *handle, ACCESS_MASK access, const OBJECT_ATTRIBUTES *attr,
|
||||
LONG initial, LONG max )
|
||||
{
|
||||
NTSTATUS ret;
|
||||
data_size_t len;
|
||||
struct object_attributes *objattr;
|
||||
|
||||
if (max <= 0 || initial < 0 || initial > max) return STATUS_INVALID_PARAMETER;
|
||||
if ((ret = alloc_object_attributes( attr, &objattr, &len ))) return ret;
|
||||
|
||||
SERVER_START_REQ( create_semaphore )
|
||||
{
|
||||
req->access = access;
|
||||
req->initial = initial;
|
||||
req->max = max;
|
||||
wine_server_add_data( req, objattr, len );
|
||||
ret = wine_server_call( req );
|
||||
*handle = wine_server_ptr_handle( reply->handle );
|
||||
}
|
||||
SERVER_END_REQ;
|
||||
|
||||
RtlFreeHeap( GetProcessHeap(), 0, objattr );
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* NtOpenSemaphore (NTDLL.@)
|
||||
*/
|
||||
NTSTATUS WINAPI NtOpenSemaphore( HANDLE *handle, ACCESS_MASK access, const OBJECT_ATTRIBUTES *attr )
|
||||
{
|
||||
NTSTATUS ret;
|
||||
|
||||
if ((ret = validate_open_object_attributes( attr ))) return ret;
|
||||
|
||||
SERVER_START_REQ( open_semaphore )
|
||||
{
|
||||
req->access = access;
|
||||
req->attributes = attr->Attributes;
|
||||
req->rootdir = wine_server_obj_handle( attr->RootDirectory );
|
||||
if (attr->ObjectName)
|
||||
wine_server_add_data( req, attr->ObjectName->Buffer, attr->ObjectName->Length );
|
||||
ret = wine_server_call( req );
|
||||
*handle = wine_server_ptr_handle( reply->handle );
|
||||
}
|
||||
SERVER_END_REQ;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* NtQuerySemaphore (NTDLL.@)
|
||||
*/
|
||||
NTSTATUS WINAPI NtQuerySemaphore( HANDLE handle, SEMAPHORE_INFORMATION_CLASS class,
|
||||
void *info, ULONG len, ULONG *ret_len )
|
||||
{
|
||||
NTSTATUS ret;
|
||||
SEMAPHORE_BASIC_INFORMATION *out = info;
|
||||
|
||||
TRACE("(%p, %u, %p, %u, %p)\n", handle, class, info, len, ret_len);
|
||||
|
||||
if (class != SemaphoreBasicInformation)
|
||||
{
|
||||
FIXME("(%p,%d,%u) Unknown class\n", handle, class, len);
|
||||
return STATUS_INVALID_INFO_CLASS;
|
||||
}
|
||||
|
||||
if (len != sizeof(SEMAPHORE_BASIC_INFORMATION)) return STATUS_INFO_LENGTH_MISMATCH;
|
||||
|
||||
SERVER_START_REQ( query_semaphore )
|
||||
{
|
||||
req->handle = wine_server_obj_handle( handle );
|
||||
if (!(ret = wine_server_call( req )))
|
||||
{
|
||||
out->CurrentCount = reply->current;
|
||||
out->MaximumCount = reply->max;
|
||||
if (ret_len) *ret_len = sizeof(SEMAPHORE_BASIC_INFORMATION);
|
||||
}
|
||||
}
|
||||
SERVER_END_REQ;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* NtReleaseSemaphore (NTDLL.@)
|
||||
*/
|
||||
NTSTATUS WINAPI NtReleaseSemaphore( HANDLE handle, ULONG count, ULONG *previous )
|
||||
{
|
||||
NTSTATUS ret;
|
||||
|
||||
SERVER_START_REQ( release_semaphore )
|
||||
{
|
||||
req->handle = wine_server_obj_handle( handle );
|
||||
req->count = count;
|
||||
if (!(ret = wine_server_call( req )))
|
||||
{
|
||||
if (previous) *previous = reply->prev_count;
|
||||
}
|
||||
}
|
||||
SERVER_END_REQ;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************
|
||||
* NtWaitForMultipleObjects (NTDLL.@)
|
||||
|
|
|
@ -28,7 +28,7 @@ struct ldt_copy;
|
|||
struct msghdr;
|
||||
|
||||
/* increment this when you change the function table */
|
||||
#define NTDLL_UNIXLIB_VERSION 21
|
||||
#define NTDLL_UNIXLIB_VERSION 22
|
||||
|
||||
struct unix_funcs
|
||||
{
|
||||
|
@ -37,6 +37,8 @@ struct unix_funcs
|
|||
SIZE_T *size_ptr, ULONG type, ULONG protect );
|
||||
NTSTATUS (WINAPI *NtAreMappedFilesTheSame)(PVOID addr1, PVOID addr2);
|
||||
NTSTATUS (WINAPI *NtClose)( HANDLE handle );
|
||||
NTSTATUS (WINAPI *NtCreateSemaphore)( HANDLE *handle, ACCESS_MASK access,
|
||||
const OBJECT_ATTRIBUTES *attr, LONG initial, LONG max );
|
||||
TEB * (WINAPI *NtCurrentTeb)(void);
|
||||
NTSTATUS (WINAPI *NtDelayExecution)( BOOLEAN alertable, const LARGE_INTEGER *timeout );
|
||||
NTSTATUS (WINAPI *NtDuplicateObject)( HANDLE source_process, HANDLE source,
|
||||
|
@ -54,15 +56,20 @@ struct unix_funcs
|
|||
ULONG_PTR zero_bits, SIZE_T commit_size,
|
||||
const LARGE_INTEGER *offset_ptr, SIZE_T *size_ptr,
|
||||
SECTION_INHERIT inherit, ULONG alloc_type, ULONG protect );
|
||||
NTSTATUS (WINAPI *NtOpenSemaphore)( HANDLE *handle, ACCESS_MASK access,
|
||||
const OBJECT_ATTRIBUTES *attr );
|
||||
NTSTATUS (WINAPI *NtProtectVirtualMemory)( HANDLE process, PVOID *addr_ptr, SIZE_T *size_ptr,
|
||||
ULONG new_prot, ULONG *old_prot );
|
||||
NTSTATUS (WINAPI *NtQuerySection)( HANDLE handle, SECTION_INFORMATION_CLASS class,
|
||||
void *ptr, SIZE_T size, SIZE_T *ret_size );
|
||||
NTSTATUS (WINAPI *NtQuerySemaphore)( HANDLE handle, SEMAPHORE_INFORMATION_CLASS class,
|
||||
void *info, ULONG len, ULONG *ret_len );
|
||||
NTSTATUS (WINAPI *NtQueryVirtualMemory)( HANDLE process, LPCVOID addr,
|
||||
MEMORY_INFORMATION_CLASS info_class,
|
||||
PVOID buffer, SIZE_T len, SIZE_T *res_len );
|
||||
NTSTATUS (WINAPI *NtReadVirtualMemory)( HANDLE process, const void *addr, void *buffer,
|
||||
SIZE_T size, SIZE_T *bytes_read );
|
||||
NTSTATUS (WINAPI *NtReleaseSemaphore)( HANDLE handle, ULONG count, ULONG *previous );
|
||||
NTSTATUS (WINAPI *NtResetWriteWatch)( HANDLE process, PVOID base, SIZE_T size );
|
||||
NTSTATUS (WINAPI *NtSetContextThread)( HANDLE handle, const CONTEXT *context );
|
||||
NTSTATUS (WINAPI *NtSetLdtEntries)( ULONG sel1, LDT_ENTRY entry1, ULONG sel2, LDT_ENTRY entry2 );
|
||||
|
|
Loading…
Reference in New Issue