1999-03-09 18:47:51 +01:00
|
|
|
/*
|
|
|
|
* Process synchronisation
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
2003-05-20 06:00:42 +02:00
|
|
|
* Copyright 1996, 1997, 1998 Marcus Meissner
|
|
|
|
* Copyright 1997, 1999 Alexandre Julliard
|
2002-03-10 00:29:33 +01:00
|
|
|
* Copyright 1999, 2000 Juergen Schmied
|
2003-05-20 06:00:42 +02:00
|
|
|
* Copyright 2003 Eric Pouech
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
1999-03-09 18:47:51 +01:00
|
|
|
*/
|
|
|
|
|
2003-03-31 03:37:04 +02:00
|
|
|
#include "config.h"
|
2013-08-28 21:10:50 +02:00
|
|
|
#include "wine/port.h"
|
2003-03-31 03:37:04 +02:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
2019-02-06 03:21:07 +01:00
|
|
|
#include <limits.h>
|
2003-03-31 03:37:04 +02:00
|
|
|
#include <signal.h>
|
2019-02-06 03:21:07 +01:00
|
|
|
#ifdef HAVE_SYS_SYSCALL_H
|
|
|
|
#include <sys/syscall.h>
|
|
|
|
#endif
|
2003-03-31 03:37:04 +02:00
|
|
|
#ifdef HAVE_SYS_TIME_H
|
|
|
|
# include <sys/time.h>
|
|
|
|
#endif
|
2005-03-04 13:38:36 +01:00
|
|
|
#ifdef HAVE_POLL_H
|
|
|
|
#include <poll.h>
|
|
|
|
#endif
|
2003-03-31 03:37:04 +02:00
|
|
|
#ifdef HAVE_SYS_POLL_H
|
|
|
|
# include <sys/poll.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
2004-10-09 04:26:29 +02:00
|
|
|
#ifdef HAVE_SCHED_H
|
|
|
|
# include <sched.h>
|
|
|
|
#endif
|
2003-03-31 03:37:04 +02:00
|
|
|
#include <string.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
1999-06-12 16:55:11 +02:00
|
|
|
#include <stdio.h>
|
1999-03-09 18:47:51 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
2005-11-28 17:32:54 +01:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
2015-03-14 03:38:17 +01:00
|
|
|
#define NONAMELESSUNION
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2008-03-01 11:57:00 +01:00
|
|
|
#include "winternl.h"
|
2003-03-31 03:37:04 +02:00
|
|
|
#include "wine/server.h"
|
|
|
|
#include "wine/debug.h"
|
- implementation of RtlReg* (read access), RtlEvent*, RtlSemaphore*,
NtAllocateLocallyUniqueId
- implementation or stubs for NtAccessCheck, NtSetSecurityObject,
RtlClearBits, RtlEqualPrefixSid, RtlFindClearBits,
RtlFormatCurrentUserKeyPath, RtlGetControlSecurityDescriptor,
RtlIdentifierAuthoritySid, RtlImpersonateSelf, RtlInitializeBitMap,
RtlInitializeGenericTable, RtlMakeSelfRelativeSD,
RtlPrefixUnicodeString, RtlSetBits, RtlUnicodeToMultiByteN,
RtlUpcaseUnicodeStringToOemString, RtlUpcaseUnicodeToOemN,
RtlValidSid, RtlxUnicodeStringToOemSize
- corrected most RtlString* functions, added documentation
- more fixes and partial implementations
2000-01-23 23:35:33 +01:00
|
|
|
#include "ntdll_misc.h"
|
1999-03-09 18:47:51 +01:00
|
|
|
|
2019-06-10 17:07:53 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(sync);
|
- implementation of RtlReg* (read access), RtlEvent*, RtlSemaphore*,
NtAllocateLocallyUniqueId
- implementation or stubs for NtAccessCheck, NtSetSecurityObject,
RtlClearBits, RtlEqualPrefixSid, RtlFindClearBits,
RtlFormatCurrentUserKeyPath, RtlGetControlSecurityDescriptor,
RtlIdentifierAuthoritySid, RtlImpersonateSelf, RtlInitializeBitMap,
RtlInitializeGenericTable, RtlMakeSelfRelativeSD,
RtlPrefixUnicodeString, RtlSetBits, RtlUnicodeToMultiByteN,
RtlUpcaseUnicodeStringToOemString, RtlUpcaseUnicodeToOemN,
RtlValidSid, RtlxUnicodeStringToOemSize
- corrected most RtlString* functions, added documentation
- more fixes and partial implementations
2000-01-23 23:35:33 +01:00
|
|
|
|
2013-08-28 21:10:50 +02:00
|
|
|
HANDLE keyed_event = NULL;
|
|
|
|
|
2018-10-26 08:50:14 +02:00
|
|
|
static const LARGE_INTEGER zero_timeout;
|
|
|
|
|
2019-02-06 03:21:07 +01:00
|
|
|
#define TICKSPERSEC 10000000
|
|
|
|
|
|
|
|
#ifdef __linux__
|
|
|
|
|
2019-06-10 17:07:53 +02:00
|
|
|
#define FUTEX_WAIT 0
|
|
|
|
#define FUTEX_WAKE 1
|
|
|
|
#define FUTEX_WAIT_BITSET 9
|
|
|
|
#define FUTEX_WAKE_BITSET 10
|
|
|
|
|
|
|
|
static int futex_private = 128;
|
2019-02-06 03:21:07 +01:00
|
|
|
|
|
|
|
static inline int futex_wait( const int *addr, int val, struct timespec *timeout )
|
|
|
|
{
|
2019-06-10 17:07:53 +02:00
|
|
|
return syscall( __NR_futex, addr, FUTEX_WAIT | futex_private, val, timeout, 0, 0 );
|
2019-02-06 03:21:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int futex_wake( const int *addr, int val )
|
|
|
|
{
|
2019-06-10 17:07:53 +02:00
|
|
|
return syscall( __NR_futex, addr, FUTEX_WAKE | futex_private, val, NULL, 0, 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int futex_wait_bitset( const int *addr, int val, struct timespec *timeout, int mask )
|
|
|
|
{
|
|
|
|
return syscall( __NR_futex, addr, FUTEX_WAIT_BITSET | futex_private, val, timeout, 0, mask );
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int futex_wake_bitset( const int *addr, int val, int mask )
|
|
|
|
{
|
|
|
|
return syscall( __NR_futex, addr, FUTEX_WAKE_BITSET | futex_private, val, NULL, 0, mask );
|
2019-02-06 03:21:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int use_futexes(void)
|
|
|
|
{
|
|
|
|
static int supported = -1;
|
|
|
|
|
|
|
|
if (supported == -1)
|
|
|
|
{
|
|
|
|
futex_wait( &supported, 10, NULL );
|
|
|
|
if (errno == ENOSYS)
|
|
|
|
{
|
2019-06-10 17:07:53 +02:00
|
|
|
futex_private = 0;
|
2019-02-06 03:21:07 +01:00
|
|
|
futex_wait( &supported, 10, NULL );
|
|
|
|
}
|
|
|
|
supported = (errno != ENOSYS);
|
|
|
|
}
|
|
|
|
return supported;
|
|
|
|
}
|
2019-02-10 19:26:45 +01:00
|
|
|
|
|
|
|
static void timespec_from_timeout( struct timespec *timespec, const LARGE_INTEGER *timeout )
|
|
|
|
{
|
|
|
|
LARGE_INTEGER now;
|
|
|
|
timeout_t diff;
|
|
|
|
|
|
|
|
if (timeout->QuadPart > 0)
|
|
|
|
{
|
|
|
|
NtQuerySystemTime( &now );
|
|
|
|
diff = timeout->QuadPart - now.QuadPart;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
diff = -timeout->QuadPart;
|
|
|
|
|
|
|
|
timespec->tv_sec = diff / TICKSPERSEC;
|
|
|
|
timespec->tv_nsec = (diff % TICKSPERSEC) * 100;
|
|
|
|
}
|
2019-02-06 03:21:07 +01:00
|
|
|
#endif
|
|
|
|
|
2007-10-25 20:09:54 +02:00
|
|
|
/* creates a struct security_descriptor and contained information in one contiguous piece of memory */
|
2016-01-15 09:40:56 +01:00
|
|
|
NTSTATUS alloc_object_attributes( const OBJECT_ATTRIBUTES *attr, struct object_attributes **ret,
|
|
|
|
data_size_t *ret_len )
|
2007-10-24 17:04:42 +02:00
|
|
|
{
|
2016-01-15 09:40:56 +01:00
|
|
|
unsigned int len = sizeof(**ret);
|
2017-09-12 14:33:37 +02:00
|
|
|
PSID owner = NULL, group = NULL;
|
2007-10-24 17:04:42 +02:00
|
|
|
ACL *dacl, *sacl;
|
2017-09-12 14:33:37 +02:00
|
|
|
BOOLEAN dacl_present, sacl_present, defaulted;
|
2016-01-15 09:40:56 +01:00
|
|
|
PSECURITY_DESCRIPTOR sd;
|
2007-10-24 17:04:42 +02:00
|
|
|
NTSTATUS status;
|
|
|
|
|
2016-01-15 09:40:56 +01:00
|
|
|
*ret = NULL;
|
|
|
|
*ret_len = 0;
|
|
|
|
|
2016-01-15 10:25:58 +01:00
|
|
|
if (!attr) return STATUS_SUCCESS;
|
2007-10-24 17:04:42 +02:00
|
|
|
|
2016-01-29 16:30:25 +01:00
|
|
|
if (attr->Length != sizeof(*attr)) return STATUS_INVALID_PARAMETER;
|
|
|
|
|
2016-01-15 09:40:56 +01:00
|
|
|
if ((sd = attr->SecurityDescriptor))
|
|
|
|
{
|
|
|
|
len += sizeof(struct security_descriptor);
|
|
|
|
|
2017-09-12 14:33:37 +02:00
|
|
|
if ((status = RtlGetOwnerSecurityDescriptor( sd, &owner, &defaulted ))) return status;
|
|
|
|
if ((status = RtlGetGroupSecurityDescriptor( sd, &group, &defaulted ))) return status;
|
2016-01-15 09:40:56 +01:00
|
|
|
if ((status = RtlGetSaclSecurityDescriptor( sd, &sacl_present, &sacl, &defaulted ))) return status;
|
|
|
|
if ((status = RtlGetDaclSecurityDescriptor( sd, &dacl_present, &dacl, &defaulted ))) return status;
|
2017-09-12 14:33:37 +02:00
|
|
|
if (owner) len += RtlLengthSid( owner );
|
|
|
|
if (group) len += RtlLengthSid( group );
|
2016-01-15 09:40:56 +01:00
|
|
|
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);
|
|
|
|
}
|
2007-10-24 17:04:42 +02:00
|
|
|
|
2016-01-15 09:40:56 +01:00
|
|
|
if (attr->ObjectName)
|
|
|
|
{
|
2016-01-19 07:52:35 +01:00
|
|
|
if (attr->ObjectName->Length & (sizeof(WCHAR) - 1)) return STATUS_OBJECT_NAME_INVALID;
|
|
|
|
len += attr->ObjectName->Length;
|
2016-01-15 09:40:56 +01:00
|
|
|
}
|
2016-01-28 13:24:12 +01:00
|
|
|
else if (attr->RootDirectory) return STATUS_OBJECT_NAME_INVALID;
|
2007-10-24 17:04:42 +02:00
|
|
|
|
2018-09-20 12:59:32 +02:00
|
|
|
len = (len + 3) & ~3; /* DWORD-align the entire structure */
|
|
|
|
|
2016-01-15 09:40:56 +01:00
|
|
|
*ret = RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY, len );
|
|
|
|
if (!*ret) return STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
(*ret)->rootdir = wine_server_obj_handle( attr->RootDirectory );
|
2016-01-15 09:53:34 +01:00
|
|
|
(*ret)->attributes = attr->Attributes;
|
2016-01-15 09:40:56 +01:00
|
|
|
|
|
|
|
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;
|
2017-09-12 14:33:37 +02:00
|
|
|
if (owner) descr->owner_len = RtlLengthSid( owner );
|
|
|
|
if (group) descr->group_len = RtlLengthSid( group );
|
2016-01-15 09:40:56 +01:00
|
|
|
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;
|
2016-01-19 07:52:35 +01:00
|
|
|
(*ret)->name_len = attr->ObjectName->Length;
|
2016-01-15 09:40:56 +01:00
|
|
|
memcpy( ptr, attr->ObjectName->Buffer, (*ret)->name_len );
|
|
|
|
}
|
|
|
|
|
|
|
|
*ret_len = len;
|
|
|
|
return STATUS_SUCCESS;
|
2007-10-24 17:04:42 +02:00
|
|
|
}
|
|
|
|
|
2016-01-29 06:57:04 +01:00
|
|
|
NTSTATUS validate_open_object_attributes( const OBJECT_ATTRIBUTES *attr )
|
|
|
|
{
|
2016-01-29 16:30:25 +01:00
|
|
|
if (!attr || attr->Length != sizeof(*attr)) return STATUS_INVALID_PARAMETER;
|
2016-01-29 06:57:04 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
1999-03-09 18:47:51 +01:00
|
|
|
/*
|
- implementation of RtlReg* (read access), RtlEvent*, RtlSemaphore*,
NtAllocateLocallyUniqueId
- implementation or stubs for NtAccessCheck, NtSetSecurityObject,
RtlClearBits, RtlEqualPrefixSid, RtlFindClearBits,
RtlFormatCurrentUserKeyPath, RtlGetControlSecurityDescriptor,
RtlIdentifierAuthoritySid, RtlImpersonateSelf, RtlInitializeBitMap,
RtlInitializeGenericTable, RtlMakeSelfRelativeSD,
RtlPrefixUnicodeString, RtlSetBits, RtlUnicodeToMultiByteN,
RtlUpcaseUnicodeStringToOemString, RtlUpcaseUnicodeToOemN,
RtlValidSid, RtlxUnicodeStringToOemSize
- corrected most RtlString* functions, added documentation
- more fixes and partial implementations
2000-01-23 23:35:33 +01:00
|
|
|
* Semaphores
|
1999-03-09 18:47:51 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/******************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* NtCreateSemaphore (NTDLL.@)
|
1999-03-09 18:47:51 +01:00
|
|
|
*/
|
2000-08-30 02:00:48 +02:00
|
|
|
NTSTATUS WINAPI NtCreateSemaphore( OUT PHANDLE SemaphoreHandle,
|
|
|
|
IN ACCESS_MASK access,
|
|
|
|
IN const OBJECT_ATTRIBUTES *attr OPTIONAL,
|
2004-12-02 19:05:37 +01:00
|
|
|
IN LONG InitialCount,
|
|
|
|
IN LONG MaximumCount )
|
1999-03-09 18:47:51 +01:00
|
|
|
{
|
2000-01-26 02:39:51 +01:00
|
|
|
NTSTATUS ret;
|
2016-01-15 09:40:56 +01:00
|
|
|
data_size_t len;
|
|
|
|
struct object_attributes *objattr;
|
2000-01-26 02:39:51 +01:00
|
|
|
|
2004-12-02 19:05:37 +01:00
|
|
|
if (MaximumCount <= 0 || InitialCount < 0 || InitialCount > MaximumCount)
|
2000-01-26 02:39:51 +01:00
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
|
2016-01-15 09:40:56 +01:00
|
|
|
if ((ret = alloc_object_attributes( attr, &objattr, &len ))) return ret;
|
2007-10-25 16:42:53 +02:00
|
|
|
|
2001-11-30 19:46:42 +01:00
|
|
|
SERVER_START_REQ( create_semaphore )
|
2000-08-30 02:00:48 +02:00
|
|
|
{
|
2004-12-02 19:05:37 +01:00
|
|
|
req->access = access;
|
2000-08-30 02:00:48 +02:00
|
|
|
req->initial = InitialCount;
|
|
|
|
req->max = MaximumCount;
|
2016-01-15 09:40:56 +01:00
|
|
|
wine_server_add_data( req, objattr, len );
|
2001-11-30 19:46:42 +01:00
|
|
|
ret = wine_server_call( req );
|
2008-12-08 16:05:17 +01:00
|
|
|
*SemaphoreHandle = wine_server_ptr_handle( reply->handle );
|
2000-08-30 02:00:48 +02:00
|
|
|
}
|
2001-11-30 19:46:42 +01:00
|
|
|
SERVER_END_REQ;
|
2007-10-25 16:42:53 +02:00
|
|
|
|
2016-01-15 09:40:56 +01:00
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, objattr );
|
2000-01-26 02:39:51 +01:00
|
|
|
return ret;
|
1999-03-09 18:47:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* NtOpenSemaphore (NTDLL.@)
|
1999-03-09 18:47:51 +01:00
|
|
|
*/
|
2016-01-29 06:57:04 +01:00
|
|
|
NTSTATUS WINAPI NtOpenSemaphore( HANDLE *handle, ACCESS_MASK access, const OBJECT_ATTRIBUTES *attr )
|
1999-03-09 18:47:51 +01:00
|
|
|
{
|
2000-01-26 02:39:51 +01:00
|
|
|
NTSTATUS ret;
|
|
|
|
|
2016-01-29 06:57:04 +01:00
|
|
|
if ((ret = validate_open_object_attributes( attr ))) return ret;
|
|
|
|
|
2001-11-30 19:46:42 +01:00
|
|
|
SERVER_START_REQ( open_semaphore )
|
2000-08-30 02:00:48 +02:00
|
|
|
{
|
2016-01-29 06:57:04 +01:00
|
|
|
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 );
|
2001-11-30 19:46:42 +01:00
|
|
|
ret = wine_server_call( req );
|
2016-01-29 06:57:04 +01:00
|
|
|
*handle = wine_server_ptr_handle( reply->handle );
|
2000-08-30 02:00:48 +02:00
|
|
|
}
|
2001-11-30 19:46:42 +01:00
|
|
|
SERVER_END_REQ;
|
2000-01-26 02:39:51 +01:00
|
|
|
return ret;
|
1999-03-09 18:47:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* NtQuerySemaphore (NTDLL.@)
|
1999-03-09 18:47:51 +01:00
|
|
|
*/
|
2013-12-25 05:28:36 +01:00
|
|
|
NTSTATUS WINAPI NtQuerySemaphore( HANDLE handle, SEMAPHORE_INFORMATION_CLASS class,
|
|
|
|
void *info, ULONG len, ULONG *ret_len )
|
1999-03-09 18:47:51 +01:00
|
|
|
{
|
2013-12-25 05:28:36 +01:00
|
|
|
NTSTATUS ret;
|
|
|
|
SEMAPHORE_BASIC_INFORMATION *out = info;
|
|
|
|
|
2016-05-03 02:55:56 +02:00
|
|
|
TRACE("(%p, %u, %p, %u, %p)\n", handle, class, info, len, ret_len);
|
|
|
|
|
2013-12-25 05:28:36 +01:00
|
|
|
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;
|
1999-03-09 18:47:51 +01:00
|
|
|
}
|
2000-08-30 02:00:48 +02:00
|
|
|
|
1999-03-09 18:47:51 +01:00
|
|
|
/******************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* NtReleaseSemaphore (NTDLL.@)
|
1999-03-09 18:47:51 +01:00
|
|
|
*/
|
2000-08-30 02:00:48 +02:00
|
|
|
NTSTATUS WINAPI NtReleaseSemaphore( HANDLE handle, ULONG count, PULONG previous )
|
1999-03-09 18:47:51 +01:00
|
|
|
{
|
2000-01-26 02:39:51 +01:00
|
|
|
NTSTATUS ret;
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_START_REQ( release_semaphore )
|
2000-01-26 02:39:51 +01:00
|
|
|
{
|
2008-12-08 16:05:17 +01:00
|
|
|
req->handle = wine_server_obj_handle( handle );
|
2000-08-30 02:00:48 +02:00
|
|
|
req->count = count;
|
2001-11-30 19:46:42 +01:00
|
|
|
if (!(ret = wine_server_call( req )))
|
2000-08-30 02:00:48 +02:00
|
|
|
{
|
2001-11-30 19:46:42 +01:00
|
|
|
if (previous) *previous = reply->prev_count;
|
2000-08-30 02:00:48 +02:00
|
|
|
}
|
2000-01-26 02:39:51 +01:00
|
|
|
}
|
2000-08-30 02:00:48 +02:00
|
|
|
SERVER_END_REQ;
|
2000-01-26 02:39:51 +01:00
|
|
|
return ret;
|
1999-03-09 18:47:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
- implementation of RtlReg* (read access), RtlEvent*, RtlSemaphore*,
NtAllocateLocallyUniqueId
- implementation or stubs for NtAccessCheck, NtSetSecurityObject,
RtlClearBits, RtlEqualPrefixSid, RtlFindClearBits,
RtlFormatCurrentUserKeyPath, RtlGetControlSecurityDescriptor,
RtlIdentifierAuthoritySid, RtlImpersonateSelf, RtlInitializeBitMap,
RtlInitializeGenericTable, RtlMakeSelfRelativeSD,
RtlPrefixUnicodeString, RtlSetBits, RtlUnicodeToMultiByteN,
RtlUpcaseUnicodeStringToOemString, RtlUpcaseUnicodeToOemN,
RtlValidSid, RtlxUnicodeStringToOemSize
- corrected most RtlString* functions, added documentation
- more fixes and partial implementations
2000-01-23 23:35:33 +01:00
|
|
|
* Events
|
1999-03-09 18:47:51 +01:00
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-03-09 18:47:51 +01:00
|
|
|
/**************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* NtCreateEvent (NTDLL.@)
|
2001-07-11 20:56:41 +02:00
|
|
|
* ZwCreateEvent (NTDLL.@)
|
1999-03-09 18:47:51 +01:00
|
|
|
*/
|
2010-01-18 20:34:54 +01:00
|
|
|
NTSTATUS WINAPI NtCreateEvent( PHANDLE EventHandle, ACCESS_MASK DesiredAccess,
|
|
|
|
const OBJECT_ATTRIBUTES *attr, EVENT_TYPE type, BOOLEAN InitialState)
|
1999-03-09 18:47:51 +01:00
|
|
|
{
|
2000-01-26 02:39:51 +01:00
|
|
|
NTSTATUS ret;
|
2016-01-15 09:40:56 +01:00
|
|
|
data_size_t len;
|
|
|
|
struct object_attributes *objattr;
|
2000-01-26 02:39:51 +01:00
|
|
|
|
2016-01-15 09:40:56 +01:00
|
|
|
if ((ret = alloc_object_attributes( attr, &objattr, &len ))) return ret;
|
2007-10-24 17:04:42 +02:00
|
|
|
|
2001-11-30 19:46:42 +01:00
|
|
|
SERVER_START_REQ( create_event )
|
2000-08-30 02:00:48 +02:00
|
|
|
{
|
2004-12-02 19:05:37 +01:00
|
|
|
req->access = DesiredAccess;
|
2010-01-18 20:34:54 +01:00
|
|
|
req->manual_reset = (type == NotificationEvent);
|
2000-08-30 02:00:48 +02:00
|
|
|
req->initial_state = InitialState;
|
2016-01-15 09:40:56 +01:00
|
|
|
wine_server_add_data( req, objattr, len );
|
2001-11-30 19:46:42 +01:00
|
|
|
ret = wine_server_call( req );
|
2008-12-08 16:05:17 +01:00
|
|
|
*EventHandle = wine_server_ptr_handle( reply->handle );
|
2000-08-30 02:00:48 +02:00
|
|
|
}
|
2001-11-30 19:46:42 +01:00
|
|
|
SERVER_END_REQ;
|
2007-10-24 17:04:42 +02:00
|
|
|
|
2016-01-15 09:40:56 +01:00
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, objattr );
|
2000-01-26 02:39:51 +01:00
|
|
|
return ret;
|
1999-03-09 18:47:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* NtOpenEvent (NTDLL.@)
|
2001-07-11 20:56:41 +02:00
|
|
|
* ZwOpenEvent (NTDLL.@)
|
1999-03-09 18:47:51 +01:00
|
|
|
*/
|
2016-01-29 06:57:04 +01:00
|
|
|
NTSTATUS WINAPI NtOpenEvent( HANDLE *handle, ACCESS_MASK access, const OBJECT_ATTRIBUTES *attr )
|
1999-03-09 18:47:51 +01:00
|
|
|
{
|
2000-01-26 02:39:51 +01:00
|
|
|
NTSTATUS ret;
|
|
|
|
|
2016-01-29 06:57:04 +01:00
|
|
|
if ((ret = validate_open_object_attributes( attr ))) return ret;
|
|
|
|
|
2001-11-30 19:46:42 +01:00
|
|
|
SERVER_START_REQ( open_event )
|
2000-08-30 02:00:48 +02:00
|
|
|
{
|
2016-01-29 06:57:04 +01:00
|
|
|
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 );
|
2001-11-30 19:46:42 +01:00
|
|
|
ret = wine_server_call( req );
|
2016-01-29 06:57:04 +01:00
|
|
|
*handle = wine_server_ptr_handle( reply->handle );
|
2000-08-30 02:00:48 +02:00
|
|
|
}
|
2001-11-30 19:46:42 +01:00
|
|
|
SERVER_END_REQ;
|
2000-01-26 02:39:51 +01:00
|
|
|
return ret;
|
- implementation of RtlReg* (read access), RtlEvent*, RtlSemaphore*,
NtAllocateLocallyUniqueId
- implementation or stubs for NtAccessCheck, NtSetSecurityObject,
RtlClearBits, RtlEqualPrefixSid, RtlFindClearBits,
RtlFormatCurrentUserKeyPath, RtlGetControlSecurityDescriptor,
RtlIdentifierAuthoritySid, RtlImpersonateSelf, RtlInitializeBitMap,
RtlInitializeGenericTable, RtlMakeSelfRelativeSD,
RtlPrefixUnicodeString, RtlSetBits, RtlUnicodeToMultiByteN,
RtlUpcaseUnicodeStringToOemString, RtlUpcaseUnicodeToOemN,
RtlValidSid, RtlxUnicodeStringToOemSize
- corrected most RtlString* functions, added documentation
- more fixes and partial implementations
2000-01-23 23:35:33 +01:00
|
|
|
}
|
|
|
|
|
1999-03-09 18:47:51 +01:00
|
|
|
|
|
|
|
/******************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* NtSetEvent (NTDLL.@)
|
2001-07-11 20:56:41 +02:00
|
|
|
* ZwSetEvent (NTDLL.@)
|
1999-03-09 18:47:51 +01:00
|
|
|
*/
|
2019-03-11 18:06:32 +01:00
|
|
|
NTSTATUS WINAPI NtSetEvent( HANDLE handle, LONG *prev_state )
|
1999-03-09 18:47:51 +01:00
|
|
|
{
|
2000-08-30 02:00:48 +02:00
|
|
|
NTSTATUS ret;
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_START_REQ( event_op )
|
2000-08-30 02:00:48 +02:00
|
|
|
{
|
2008-12-08 16:05:17 +01:00
|
|
|
req->handle = wine_server_obj_handle( handle );
|
2000-08-30 02:00:48 +02:00
|
|
|
req->op = SET_EVENT;
|
2001-11-30 19:46:42 +01:00
|
|
|
ret = wine_server_call( req );
|
2019-03-11 18:06:39 +01:00
|
|
|
if (!ret && prev_state) *prev_state = reply->state;
|
2000-08-30 02:00:48 +02:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return ret;
|
1999-03-09 18:47:51 +01:00
|
|
|
}
|
|
|
|
|
- implementation of RtlReg* (read access), RtlEvent*, RtlSemaphore*,
NtAllocateLocallyUniqueId
- implementation or stubs for NtAccessCheck, NtSetSecurityObject,
RtlClearBits, RtlEqualPrefixSid, RtlFindClearBits,
RtlFormatCurrentUserKeyPath, RtlGetControlSecurityDescriptor,
RtlIdentifierAuthoritySid, RtlImpersonateSelf, RtlInitializeBitMap,
RtlInitializeGenericTable, RtlMakeSelfRelativeSD,
RtlPrefixUnicodeString, RtlSetBits, RtlUnicodeToMultiByteN,
RtlUpcaseUnicodeStringToOemString, RtlUpcaseUnicodeToOemN,
RtlValidSid, RtlxUnicodeStringToOemSize
- corrected most RtlString* functions, added documentation
- more fixes and partial implementations
2000-01-23 23:35:33 +01:00
|
|
|
/******************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* NtResetEvent (NTDLL.@)
|
- implementation of RtlReg* (read access), RtlEvent*, RtlSemaphore*,
NtAllocateLocallyUniqueId
- implementation or stubs for NtAccessCheck, NtSetSecurityObject,
RtlClearBits, RtlEqualPrefixSid, RtlFindClearBits,
RtlFormatCurrentUserKeyPath, RtlGetControlSecurityDescriptor,
RtlIdentifierAuthoritySid, RtlImpersonateSelf, RtlInitializeBitMap,
RtlInitializeGenericTable, RtlMakeSelfRelativeSD,
RtlPrefixUnicodeString, RtlSetBits, RtlUnicodeToMultiByteN,
RtlUpcaseUnicodeStringToOemString, RtlUpcaseUnicodeToOemN,
RtlValidSid, RtlxUnicodeStringToOemSize
- corrected most RtlString* functions, added documentation
- more fixes and partial implementations
2000-01-23 23:35:33 +01:00
|
|
|
*/
|
2019-03-11 18:06:32 +01:00
|
|
|
NTSTATUS WINAPI NtResetEvent( HANDLE handle, LONG *prev_state )
|
- implementation of RtlReg* (read access), RtlEvent*, RtlSemaphore*,
NtAllocateLocallyUniqueId
- implementation or stubs for NtAccessCheck, NtSetSecurityObject,
RtlClearBits, RtlEqualPrefixSid, RtlFindClearBits,
RtlFormatCurrentUserKeyPath, RtlGetControlSecurityDescriptor,
RtlIdentifierAuthoritySid, RtlImpersonateSelf, RtlInitializeBitMap,
RtlInitializeGenericTable, RtlMakeSelfRelativeSD,
RtlPrefixUnicodeString, RtlSetBits, RtlUnicodeToMultiByteN,
RtlUpcaseUnicodeStringToOemString, RtlUpcaseUnicodeToOemN,
RtlValidSid, RtlxUnicodeStringToOemSize
- corrected most RtlString* functions, added documentation
- more fixes and partial implementations
2000-01-23 23:35:33 +01:00
|
|
|
{
|
2000-08-30 02:00:48 +02:00
|
|
|
NTSTATUS ret;
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_START_REQ( event_op )
|
2000-08-30 02:00:48 +02:00
|
|
|
{
|
2008-12-08 16:05:17 +01:00
|
|
|
req->handle = wine_server_obj_handle( handle );
|
2000-08-30 02:00:48 +02:00
|
|
|
req->op = RESET_EVENT;
|
2001-11-30 19:46:42 +01:00
|
|
|
ret = wine_server_call( req );
|
2019-03-11 18:06:39 +01:00
|
|
|
if (!ret && prev_state) *prev_state = reply->state;
|
2000-08-30 02:00:48 +02:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return ret;
|
- implementation of RtlReg* (read access), RtlEvent*, RtlSemaphore*,
NtAllocateLocallyUniqueId
- implementation or stubs for NtAccessCheck, NtSetSecurityObject,
RtlClearBits, RtlEqualPrefixSid, RtlFindClearBits,
RtlFormatCurrentUserKeyPath, RtlGetControlSecurityDescriptor,
RtlIdentifierAuthoritySid, RtlImpersonateSelf, RtlInitializeBitMap,
RtlInitializeGenericTable, RtlMakeSelfRelativeSD,
RtlPrefixUnicodeString, RtlSetBits, RtlUnicodeToMultiByteN,
RtlUpcaseUnicodeStringToOemString, RtlUpcaseUnicodeToOemN,
RtlValidSid, RtlxUnicodeStringToOemSize
- corrected most RtlString* functions, added documentation
- more fixes and partial implementations
2000-01-23 23:35:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* NtClearEvent (NTDLL.@)
|
- implementation of RtlReg* (read access), RtlEvent*, RtlSemaphore*,
NtAllocateLocallyUniqueId
- implementation or stubs for NtAccessCheck, NtSetSecurityObject,
RtlClearBits, RtlEqualPrefixSid, RtlFindClearBits,
RtlFormatCurrentUserKeyPath, RtlGetControlSecurityDescriptor,
RtlIdentifierAuthoritySid, RtlImpersonateSelf, RtlInitializeBitMap,
RtlInitializeGenericTable, RtlMakeSelfRelativeSD,
RtlPrefixUnicodeString, RtlSetBits, RtlUnicodeToMultiByteN,
RtlUpcaseUnicodeStringToOemString, RtlUpcaseUnicodeToOemN,
RtlValidSid, RtlxUnicodeStringToOemSize
- corrected most RtlString* functions, added documentation
- more fixes and partial implementations
2000-01-23 23:35:33 +01:00
|
|
|
*
|
|
|
|
* FIXME
|
|
|
|
* same as NtResetEvent ???
|
|
|
|
*/
|
2000-08-30 02:00:48 +02:00
|
|
|
NTSTATUS WINAPI NtClearEvent ( HANDLE handle )
|
- implementation of RtlReg* (read access), RtlEvent*, RtlSemaphore*,
NtAllocateLocallyUniqueId
- implementation or stubs for NtAccessCheck, NtSetSecurityObject,
RtlClearBits, RtlEqualPrefixSid, RtlFindClearBits,
RtlFormatCurrentUserKeyPath, RtlGetControlSecurityDescriptor,
RtlIdentifierAuthoritySid, RtlImpersonateSelf, RtlInitializeBitMap,
RtlInitializeGenericTable, RtlMakeSelfRelativeSD,
RtlPrefixUnicodeString, RtlSetBits, RtlUnicodeToMultiByteN,
RtlUpcaseUnicodeStringToOemString, RtlUpcaseUnicodeToOemN,
RtlValidSid, RtlxUnicodeStringToOemSize
- corrected most RtlString* functions, added documentation
- more fixes and partial implementations
2000-01-23 23:35:33 +01:00
|
|
|
{
|
2000-08-30 02:00:48 +02:00
|
|
|
return NtResetEvent( handle, NULL );
|
- implementation of RtlReg* (read access), RtlEvent*, RtlSemaphore*,
NtAllocateLocallyUniqueId
- implementation or stubs for NtAccessCheck, NtSetSecurityObject,
RtlClearBits, RtlEqualPrefixSid, RtlFindClearBits,
RtlFormatCurrentUserKeyPath, RtlGetControlSecurityDescriptor,
RtlIdentifierAuthoritySid, RtlImpersonateSelf, RtlInitializeBitMap,
RtlInitializeGenericTable, RtlMakeSelfRelativeSD,
RtlPrefixUnicodeString, RtlSetBits, RtlUnicodeToMultiByteN,
RtlUpcaseUnicodeStringToOemString, RtlUpcaseUnicodeToOemN,
RtlValidSid, RtlxUnicodeStringToOemSize
- corrected most RtlString* functions, added documentation
- more fixes and partial implementations
2000-01-23 23:35:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* NtPulseEvent (NTDLL.@)
|
- implementation of RtlReg* (read access), RtlEvent*, RtlSemaphore*,
NtAllocateLocallyUniqueId
- implementation or stubs for NtAccessCheck, NtSetSecurityObject,
RtlClearBits, RtlEqualPrefixSid, RtlFindClearBits,
RtlFormatCurrentUserKeyPath, RtlGetControlSecurityDescriptor,
RtlIdentifierAuthoritySid, RtlImpersonateSelf, RtlInitializeBitMap,
RtlInitializeGenericTable, RtlMakeSelfRelativeSD,
RtlPrefixUnicodeString, RtlSetBits, RtlUnicodeToMultiByteN,
RtlUpcaseUnicodeStringToOemString, RtlUpcaseUnicodeToOemN,
RtlValidSid, RtlxUnicodeStringToOemSize
- corrected most RtlString* functions, added documentation
- more fixes and partial implementations
2000-01-23 23:35:33 +01:00
|
|
|
*
|
|
|
|
* FIXME
|
|
|
|
* PulseCount
|
|
|
|
*/
|
2019-03-11 18:06:32 +01:00
|
|
|
NTSTATUS WINAPI NtPulseEvent( HANDLE handle, LONG *prev_state )
|
- implementation of RtlReg* (read access), RtlEvent*, RtlSemaphore*,
NtAllocateLocallyUniqueId
- implementation or stubs for NtAccessCheck, NtSetSecurityObject,
RtlClearBits, RtlEqualPrefixSid, RtlFindClearBits,
RtlFormatCurrentUserKeyPath, RtlGetControlSecurityDescriptor,
RtlIdentifierAuthoritySid, RtlImpersonateSelf, RtlInitializeBitMap,
RtlInitializeGenericTable, RtlMakeSelfRelativeSD,
RtlPrefixUnicodeString, RtlSetBits, RtlUnicodeToMultiByteN,
RtlUpcaseUnicodeStringToOemString, RtlUpcaseUnicodeToOemN,
RtlValidSid, RtlxUnicodeStringToOemSize
- corrected most RtlString* functions, added documentation
- more fixes and partial implementations
2000-01-23 23:35:33 +01:00
|
|
|
{
|
2000-08-30 02:00:48 +02:00
|
|
|
NTSTATUS ret;
|
2004-04-01 23:01:53 +02:00
|
|
|
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_START_REQ( event_op )
|
2000-08-30 02:00:48 +02:00
|
|
|
{
|
2008-12-08 16:05:17 +01:00
|
|
|
req->handle = wine_server_obj_handle( handle );
|
2000-08-30 02:00:48 +02:00
|
|
|
req->op = PULSE_EVENT;
|
2001-11-30 19:46:42 +01:00
|
|
|
ret = wine_server_call( req );
|
2019-03-11 18:06:39 +01:00
|
|
|
if (!ret && prev_state) *prev_state = reply->state;
|
2000-08-30 02:00:48 +02:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return ret;
|
- implementation of RtlReg* (read access), RtlEvent*, RtlSemaphore*,
NtAllocateLocallyUniqueId
- implementation or stubs for NtAccessCheck, NtSetSecurityObject,
RtlClearBits, RtlEqualPrefixSid, RtlFindClearBits,
RtlFormatCurrentUserKeyPath, RtlGetControlSecurityDescriptor,
RtlIdentifierAuthoritySid, RtlImpersonateSelf, RtlInitializeBitMap,
RtlInitializeGenericTable, RtlMakeSelfRelativeSD,
RtlPrefixUnicodeString, RtlSetBits, RtlUnicodeToMultiByteN,
RtlUpcaseUnicodeStringToOemString, RtlUpcaseUnicodeToOemN,
RtlValidSid, RtlxUnicodeStringToOemSize
- corrected most RtlString* functions, added documentation
- more fixes and partial implementations
2000-01-23 23:35:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* NtQueryEvent (NTDLL.@)
|
- implementation of RtlReg* (read access), RtlEvent*, RtlSemaphore*,
NtAllocateLocallyUniqueId
- implementation or stubs for NtAccessCheck, NtSetSecurityObject,
RtlClearBits, RtlEqualPrefixSid, RtlFindClearBits,
RtlFormatCurrentUserKeyPath, RtlGetControlSecurityDescriptor,
RtlIdentifierAuthoritySid, RtlImpersonateSelf, RtlInitializeBitMap,
RtlInitializeGenericTable, RtlMakeSelfRelativeSD,
RtlPrefixUnicodeString, RtlSetBits, RtlUnicodeToMultiByteN,
RtlUpcaseUnicodeStringToOemString, RtlUpcaseUnicodeToOemN,
RtlValidSid, RtlxUnicodeStringToOemSize
- corrected most RtlString* functions, added documentation
- more fixes and partial implementations
2000-01-23 23:35:33 +01:00
|
|
|
*/
|
2013-08-26 11:52:51 +02:00
|
|
|
NTSTATUS WINAPI NtQueryEvent( HANDLE handle, EVENT_INFORMATION_CLASS class,
|
|
|
|
void *info, ULONG len, ULONG *ret_len )
|
- implementation of RtlReg* (read access), RtlEvent*, RtlSemaphore*,
NtAllocateLocallyUniqueId
- implementation or stubs for NtAccessCheck, NtSetSecurityObject,
RtlClearBits, RtlEqualPrefixSid, RtlFindClearBits,
RtlFormatCurrentUserKeyPath, RtlGetControlSecurityDescriptor,
RtlIdentifierAuthoritySid, RtlImpersonateSelf, RtlInitializeBitMap,
RtlInitializeGenericTable, RtlMakeSelfRelativeSD,
RtlPrefixUnicodeString, RtlSetBits, RtlUnicodeToMultiByteN,
RtlUpcaseUnicodeStringToOemString, RtlUpcaseUnicodeToOemN,
RtlValidSid, RtlxUnicodeStringToOemSize
- corrected most RtlString* functions, added documentation
- more fixes and partial implementations
2000-01-23 23:35:33 +01:00
|
|
|
{
|
2013-08-26 11:52:51 +02:00
|
|
|
NTSTATUS ret;
|
|
|
|
EVENT_BASIC_INFORMATION *out = info;
|
|
|
|
|
2016-05-03 02:55:56 +02:00
|
|
|
TRACE("(%p, %u, %p, %u, %p)\n", handle, class, info, len, ret_len);
|
|
|
|
|
2013-08-26 11:52:51 +02:00
|
|
|
if (class != EventBasicInformation)
|
|
|
|
{
|
|
|
|
FIXME("(%p, %d, %d) Unknown class\n",
|
|
|
|
handle, class, len);
|
|
|
|
return STATUS_INVALID_INFO_CLASS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len != sizeof(EVENT_BASIC_INFORMATION)) return STATUS_INFO_LENGTH_MISMATCH;
|
|
|
|
|
|
|
|
SERVER_START_REQ( query_event )
|
|
|
|
{
|
|
|
|
req->handle = wine_server_obj_handle( handle );
|
|
|
|
if (!(ret = wine_server_call( req )))
|
|
|
|
{
|
|
|
|
out->EventType = reply->manual_reset ? NotificationEvent : SynchronizationEvent;
|
|
|
|
out->EventState = reply->state;
|
|
|
|
if (ret_len) *ret_len = sizeof(EVENT_BASIC_INFORMATION);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
|
|
|
return ret;
|
- implementation of RtlReg* (read access), RtlEvent*, RtlSemaphore*,
NtAllocateLocallyUniqueId
- implementation or stubs for NtAccessCheck, NtSetSecurityObject,
RtlClearBits, RtlEqualPrefixSid, RtlFindClearBits,
RtlFormatCurrentUserKeyPath, RtlGetControlSecurityDescriptor,
RtlIdentifierAuthoritySid, RtlImpersonateSelf, RtlInitializeBitMap,
RtlInitializeGenericTable, RtlMakeSelfRelativeSD,
RtlPrefixUnicodeString, RtlSetBits, RtlUnicodeToMultiByteN,
RtlUpcaseUnicodeStringToOemString, RtlUpcaseUnicodeToOemN,
RtlValidSid, RtlxUnicodeStringToOemSize
- corrected most RtlString* functions, added documentation
- more fixes and partial implementations
2000-01-23 23:35:33 +01:00
|
|
|
}
|
2003-03-31 03:37:04 +02:00
|
|
|
|
2004-12-02 19:05:37 +01:00
|
|
|
/*
|
|
|
|
* Mutants (known as Mutexes in Kernel32)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* NtCreateMutant [NTDLL.@]
|
|
|
|
* ZwCreateMutant [NTDLL.@]
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtCreateMutant(OUT HANDLE* MutantHandle,
|
|
|
|
IN ACCESS_MASK access,
|
|
|
|
IN const OBJECT_ATTRIBUTES* attr OPTIONAL,
|
|
|
|
IN BOOLEAN InitialOwner)
|
|
|
|
{
|
2007-10-25 16:43:05 +02:00
|
|
|
NTSTATUS status;
|
2016-01-15 09:40:56 +01:00
|
|
|
data_size_t len;
|
|
|
|
struct object_attributes *objattr;
|
2004-12-02 19:05:37 +01:00
|
|
|
|
2016-01-15 09:40:56 +01:00
|
|
|
if ((status = alloc_object_attributes( attr, &objattr, &len ))) return status;
|
2007-10-25 16:43:05 +02:00
|
|
|
|
2004-12-02 19:05:37 +01:00
|
|
|
SERVER_START_REQ( create_mutex )
|
|
|
|
{
|
|
|
|
req->access = access;
|
|
|
|
req->owned = InitialOwner;
|
2016-01-15 09:40:56 +01:00
|
|
|
wine_server_add_data( req, objattr, len );
|
2004-12-02 19:05:37 +01:00
|
|
|
status = wine_server_call( req );
|
2008-12-08 16:05:17 +01:00
|
|
|
*MutantHandle = wine_server_ptr_handle( reply->handle );
|
2004-12-02 19:05:37 +01:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
2007-10-25 16:43:05 +02:00
|
|
|
|
2016-01-15 09:40:56 +01:00
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, objattr );
|
2004-12-02 19:05:37 +01:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* NtOpenMutant [NTDLL.@]
|
|
|
|
* ZwOpenMutant [NTDLL.@]
|
|
|
|
*/
|
2016-01-29 06:57:04 +01:00
|
|
|
NTSTATUS WINAPI NtOpenMutant( HANDLE *handle, ACCESS_MASK access, const OBJECT_ATTRIBUTES *attr )
|
2004-12-02 19:05:37 +01:00
|
|
|
{
|
|
|
|
NTSTATUS status;
|
2016-01-29 06:57:04 +01:00
|
|
|
|
|
|
|
if ((status = validate_open_object_attributes( attr ))) return status;
|
2004-12-02 19:05:37 +01:00
|
|
|
|
|
|
|
SERVER_START_REQ( open_mutex )
|
|
|
|
{
|
|
|
|
req->access = access;
|
2016-01-29 06:57:04 +01:00
|
|
|
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 );
|
2004-12-02 19:05:37 +01:00
|
|
|
status = wine_server_call( req );
|
2016-01-29 06:57:04 +01:00
|
|
|
*handle = wine_server_ptr_handle( reply->handle );
|
2004-12-02 19:05:37 +01:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* NtReleaseMutant [NTDLL.@]
|
|
|
|
* ZwReleaseMutant [NTDLL.@]
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtReleaseMutant( IN HANDLE handle, OUT PLONG prev_count OPTIONAL)
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
SERVER_START_REQ( release_mutex )
|
|
|
|
{
|
2008-12-08 16:05:17 +01:00
|
|
|
req->handle = wine_server_obj_handle( handle );
|
2004-12-02 19:05:37 +01:00
|
|
|
status = wine_server_call( req );
|
2016-05-03 02:55:43 +02:00
|
|
|
if (prev_count) *prev_count = 1 - reply->prev_count;
|
2004-12-02 19:05:37 +01:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* NtQueryMutant [NTDLL.@]
|
|
|
|
* ZwQueryMutant [NTDLL.@]
|
|
|
|
*/
|
2016-05-03 02:55:34 +02:00
|
|
|
NTSTATUS WINAPI NtQueryMutant( HANDLE handle, MUTANT_INFORMATION_CLASS class,
|
|
|
|
void *info, ULONG len, ULONG *ret_len )
|
2004-12-02 19:05:37 +01:00
|
|
|
{
|
2016-05-03 02:55:34 +02:00
|
|
|
NTSTATUS ret;
|
|
|
|
MUTANT_BASIC_INFORMATION *out = info;
|
|
|
|
|
|
|
|
TRACE("(%p, %u, %p, %u, %p)\n", handle, class, info, len, ret_len);
|
|
|
|
|
|
|
|
if (class != MutantBasicInformation)
|
|
|
|
{
|
|
|
|
FIXME("(%p, %d, %d) Unknown class\n",
|
|
|
|
handle, class, len);
|
|
|
|
return STATUS_INVALID_INFO_CLASS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len != sizeof(MUTANT_BASIC_INFORMATION)) return STATUS_INFO_LENGTH_MISMATCH;
|
|
|
|
|
|
|
|
SERVER_START_REQ( query_mutex )
|
|
|
|
{
|
|
|
|
req->handle = wine_server_obj_handle( handle );
|
|
|
|
if (!(ret = wine_server_call( req )))
|
|
|
|
{
|
|
|
|
out->CurrentCount = 1 - reply->count;
|
|
|
|
out->OwnedByCaller = reply->owned;
|
|
|
|
out->AbandonedState = reply->abandoned;
|
|
|
|
if (ret_len) *ret_len = sizeof(MUTANT_BASIC_INFORMATION);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
|
|
|
return ret;
|
2004-12-02 19:05:37 +01:00
|
|
|
}
|
2003-03-31 03:37:04 +02:00
|
|
|
|
2008-09-04 22:47:13 +02:00
|
|
|
/*
|
|
|
|
* Jobs
|
|
|
|
*/
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* NtCreateJobObject [NTDLL.@]
|
|
|
|
* ZwCreateJobObject [NTDLL.@]
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtCreateJobObject( PHANDLE handle, ACCESS_MASK access, const OBJECT_ATTRIBUTES *attr )
|
|
|
|
{
|
2015-02-26 02:25:23 +01:00
|
|
|
NTSTATUS ret;
|
2016-01-15 09:40:56 +01:00
|
|
|
data_size_t len;
|
|
|
|
struct object_attributes *objattr;
|
2015-02-26 02:25:23 +01:00
|
|
|
|
2016-01-15 09:40:56 +01:00
|
|
|
if ((ret = alloc_object_attributes( attr, &objattr, &len ))) return ret;
|
2015-02-26 02:25:23 +01:00
|
|
|
|
|
|
|
SERVER_START_REQ( create_job )
|
|
|
|
{
|
|
|
|
req->access = access;
|
2016-01-15 09:40:56 +01:00
|
|
|
wine_server_add_data( req, objattr, len );
|
2015-02-26 02:25:23 +01:00
|
|
|
ret = wine_server_call( req );
|
|
|
|
*handle = wine_server_ptr_handle( reply->handle );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
2016-01-15 09:40:56 +01:00
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, objattr );
|
2015-02-26 02:25:23 +01:00
|
|
|
return ret;
|
2008-09-04 22:47:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* NtOpenJobObject [NTDLL.@]
|
|
|
|
* ZwOpenJobObject [NTDLL.@]
|
|
|
|
*/
|
2016-01-29 06:57:04 +01:00
|
|
|
NTSTATUS WINAPI NtOpenJobObject( HANDLE *handle, ACCESS_MASK access, const OBJECT_ATTRIBUTES *attr )
|
2008-09-04 22:47:13 +02:00
|
|
|
{
|
2016-01-28 17:32:22 +01:00
|
|
|
NTSTATUS ret;
|
|
|
|
|
2016-01-29 06:57:04 +01:00
|
|
|
if ((ret = validate_open_object_attributes( attr ))) return ret;
|
|
|
|
|
2016-01-28 17:32:22 +01:00
|
|
|
SERVER_START_REQ( open_job )
|
|
|
|
{
|
2016-01-29 06:57:04 +01:00
|
|
|
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 );
|
2016-01-28 17:32:22 +01:00
|
|
|
ret = wine_server_call( req );
|
|
|
|
*handle = wine_server_ptr_handle( reply->handle );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return ret;
|
2008-09-04 22:47:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* NtTerminateJobObject [NTDLL.@]
|
|
|
|
* ZwTerminateJobObject [NTDLL.@]
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtTerminateJobObject( HANDLE handle, NTSTATUS status )
|
|
|
|
{
|
2015-04-03 08:19:45 +02:00
|
|
|
NTSTATUS ret;
|
|
|
|
|
|
|
|
TRACE( "(%p, %d)\n", handle, status );
|
|
|
|
|
|
|
|
SERVER_START_REQ( terminate_job )
|
|
|
|
{
|
|
|
|
req->handle = wine_server_obj_handle( handle );
|
|
|
|
req->status = status;
|
|
|
|
ret = wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
|
|
|
return ret;
|
2008-09-04 22:47:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* NtQueryInformationJobObject [NTDLL.@]
|
|
|
|
* ZwQueryInformationJobObject [NTDLL.@]
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtQueryInformationJobObject( HANDLE handle, JOBOBJECTINFOCLASS class, PVOID info,
|
|
|
|
ULONG len, PULONG ret_len )
|
|
|
|
{
|
|
|
|
FIXME( "stub: %p %u %p %u %p\n", handle, class, info, len, ret_len );
|
2015-07-31 07:48:47 +02:00
|
|
|
|
|
|
|
if (class >= MaxJobObjectInfoClass)
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
switch (class)
|
|
|
|
{
|
2017-04-23 23:22:25 +02:00
|
|
|
case JobObjectBasicAccountingInformation:
|
|
|
|
{
|
|
|
|
JOBOBJECT_BASIC_ACCOUNTING_INFORMATION *accounting;
|
|
|
|
if (len < sizeof(*accounting))
|
|
|
|
return STATUS_INFO_LENGTH_MISMATCH;
|
|
|
|
|
|
|
|
accounting = (JOBOBJECT_BASIC_ACCOUNTING_INFORMATION *)info;
|
|
|
|
memset(accounting, 0, sizeof(*accounting));
|
|
|
|
if (ret_len) *ret_len = sizeof(*accounting);
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
case JobObjectBasicProcessIdList:
|
|
|
|
{
|
|
|
|
JOBOBJECT_BASIC_PROCESS_ID_LIST *process;
|
|
|
|
if (len < sizeof(*process))
|
|
|
|
return STATUS_INFO_LENGTH_MISMATCH;
|
|
|
|
|
|
|
|
process = (JOBOBJECT_BASIC_PROCESS_ID_LIST *)info;
|
|
|
|
memset(process, 0, sizeof(*process));
|
|
|
|
if (ret_len) *ret_len = sizeof(*process);
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2015-07-31 07:48:47 +02:00
|
|
|
case JobObjectExtendedLimitInformation:
|
|
|
|
{
|
|
|
|
JOBOBJECT_EXTENDED_LIMIT_INFORMATION *extended_limit;
|
|
|
|
if (len < sizeof(*extended_limit))
|
|
|
|
return STATUS_INFO_LENGTH_MISMATCH;
|
|
|
|
|
|
|
|
extended_limit = (JOBOBJECT_EXTENDED_LIMIT_INFORMATION *)info;
|
|
|
|
memset(extended_limit, 0, sizeof(*extended_limit));
|
|
|
|
if (ret_len) *ret_len = sizeof(*extended_limit);
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
case JobObjectBasicLimitInformation:
|
|
|
|
{
|
|
|
|
JOBOBJECT_BASIC_LIMIT_INFORMATION *basic_limit;
|
|
|
|
if (len < sizeof(*basic_limit))
|
|
|
|
return STATUS_INFO_LENGTH_MISMATCH;
|
|
|
|
|
|
|
|
basic_limit = (JOBOBJECT_BASIC_LIMIT_INFORMATION *)info;
|
|
|
|
memset(basic_limit, 0, sizeof(*basic_limit));
|
|
|
|
if (ret_len) *ret_len = sizeof(*basic_limit);
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
2008-09-04 22:47:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* NtSetInformationJobObject [NTDLL.@]
|
|
|
|
* ZwSetInformationJobObject [NTDLL.@]
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtSetInformationJobObject( HANDLE handle, JOBOBJECTINFOCLASS class, PVOID info, ULONG len )
|
|
|
|
{
|
2015-04-04 23:04:25 +02:00
|
|
|
NTSTATUS status = STATUS_NOT_IMPLEMENTED;
|
2015-04-02 11:40:15 +02:00
|
|
|
JOBOBJECT_BASIC_LIMIT_INFORMATION *basic_limit;
|
|
|
|
ULONG info_size = sizeof(JOBOBJECT_BASIC_LIMIT_INFORMATION);
|
|
|
|
DWORD limit_flags = JOB_OBJECT_BASIC_LIMIT_VALID_FLAGS;
|
|
|
|
|
|
|
|
TRACE( "(%p, %u, %p, %u)\n", handle, class, info, len );
|
|
|
|
|
|
|
|
if (class >= MaxJobObjectInfoClass)
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
switch (class)
|
|
|
|
{
|
|
|
|
|
|
|
|
case JobObjectExtendedLimitInformation:
|
|
|
|
info_size = sizeof(JOBOBJECT_EXTENDED_LIMIT_INFORMATION);
|
|
|
|
limit_flags = JOB_OBJECT_EXTENDED_LIMIT_VALID_FLAGS;
|
|
|
|
/* fallthrough */
|
|
|
|
case JobObjectBasicLimitInformation:
|
|
|
|
if (len != info_size)
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
basic_limit = info;
|
|
|
|
if (basic_limit->LimitFlags & ~limit_flags)
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
SERVER_START_REQ( set_job_limits )
|
|
|
|
{
|
|
|
|
req->handle = wine_server_obj_handle( handle );
|
|
|
|
req->limit_flags = basic_limit->LimitFlags;
|
|
|
|
status = wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
break;
|
|
|
|
|
2015-04-01 23:56:55 +02:00
|
|
|
case JobObjectAssociateCompletionPortInformation:
|
|
|
|
if (len != sizeof(JOBOBJECT_ASSOCIATE_COMPLETION_PORT))
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
SERVER_START_REQ( set_job_completion_port )
|
|
|
|
{
|
|
|
|
JOBOBJECT_ASSOCIATE_COMPLETION_PORT *port_info = info;
|
|
|
|
req->job = wine_server_obj_handle( handle );
|
|
|
|
req->port = wine_server_obj_handle( port_info->CompletionPort );
|
|
|
|
req->key = wine_server_client_ptr( port_info->CompletionKey );
|
|
|
|
status = wine_server_call(req);
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
break;
|
|
|
|
|
2015-04-04 23:04:25 +02:00
|
|
|
case JobObjectBasicUIRestrictions:
|
|
|
|
status = STATUS_SUCCESS;
|
|
|
|
/* fallthrough */
|
2015-04-02 11:40:15 +02:00
|
|
|
default:
|
|
|
|
FIXME( "stub: %p %u %p %u\n", handle, class, info, len );
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
2008-09-04 22:47:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* NtIsProcessInJob [NTDLL.@]
|
|
|
|
* ZwIsProcessInJob [NTDLL.@]
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtIsProcessInJob( HANDLE process, HANDLE job )
|
|
|
|
{
|
2015-04-01 00:27:34 +02:00
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
TRACE( "(%p %p)\n", job, process );
|
|
|
|
|
|
|
|
SERVER_START_REQ( process_in_job )
|
|
|
|
{
|
|
|
|
req->job = wine_server_obj_handle( job );
|
|
|
|
req->process = wine_server_obj_handle( process );
|
|
|
|
status = wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
|
|
|
return status;
|
2008-09-04 22:47:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* NtAssignProcessToJobObject [NTDLL.@]
|
|
|
|
* ZwAssignProcessToJobObject [NTDLL.@]
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtAssignProcessToJobObject( HANDLE job, HANDLE process )
|
|
|
|
{
|
2015-04-01 00:10:16 +02:00
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
TRACE( "(%p %p)\n", job, process );
|
|
|
|
|
|
|
|
SERVER_START_REQ( assign_job )
|
|
|
|
{
|
|
|
|
req->job = wine_server_obj_handle( job );
|
|
|
|
req->process = wine_server_obj_handle( process );
|
|
|
|
status = wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
|
|
|
return status;
|
2008-09-04 22:47:13 +02:00
|
|
|
}
|
|
|
|
|
2003-05-20 06:00:42 +02:00
|
|
|
/*
|
|
|
|
* Timers
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* NtCreateTimer [NTDLL.@]
|
|
|
|
* ZwCreateTimer [NTDLL.@]
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtCreateTimer(OUT HANDLE *handle,
|
|
|
|
IN ACCESS_MASK access,
|
2004-12-02 19:05:37 +01:00
|
|
|
IN const OBJECT_ATTRIBUTES *attr OPTIONAL,
|
2003-05-20 06:00:42 +02:00
|
|
|
IN TIMER_TYPE timer_type)
|
|
|
|
{
|
2016-01-15 10:47:06 +01:00
|
|
|
NTSTATUS status;
|
|
|
|
data_size_t len;
|
|
|
|
struct object_attributes *objattr;
|
2004-12-02 19:05:37 +01:00
|
|
|
|
2003-05-20 06:00:42 +02:00
|
|
|
if (timer_type != NotificationTimer && timer_type != SynchronizationTimer)
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
|
2016-01-15 10:47:06 +01:00
|
|
|
if ((status = alloc_object_attributes( attr, &objattr, &len ))) return status;
|
|
|
|
|
2003-05-20 06:00:42 +02:00
|
|
|
SERVER_START_REQ( create_timer )
|
|
|
|
{
|
2004-12-02 19:05:37 +01:00
|
|
|
req->access = access;
|
2014-01-12 10:48:16 +01:00
|
|
|
req->manual = (timer_type == NotificationTimer);
|
2016-01-15 10:47:06 +01:00
|
|
|
wine_server_add_data( req, objattr, len );
|
2003-05-20 06:00:42 +02:00
|
|
|
status = wine_server_call( req );
|
2008-12-08 16:05:17 +01:00
|
|
|
*handle = wine_server_ptr_handle( reply->handle );
|
2003-05-20 06:00:42 +02:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
2016-01-15 10:47:06 +01:00
|
|
|
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, objattr );
|
2003-05-20 06:00:42 +02:00
|
|
|
return status;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* NtOpenTimer [NTDLL.@]
|
|
|
|
* ZwOpenTimer [NTDLL.@]
|
|
|
|
*/
|
2016-01-29 06:57:04 +01:00
|
|
|
NTSTATUS WINAPI NtOpenTimer( HANDLE *handle, ACCESS_MASK access, const OBJECT_ATTRIBUTES *attr )
|
2003-05-20 06:00:42 +02:00
|
|
|
{
|
2016-01-29 06:57:04 +01:00
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
if ((status = validate_open_object_attributes( attr ))) return status;
|
2003-05-20 06:00:42 +02:00
|
|
|
|
|
|
|
SERVER_START_REQ( open_timer )
|
|
|
|
{
|
2016-01-29 06:57:04 +01:00
|
|
|
req->access = access;
|
|
|
|
req->attributes = attr->Attributes;
|
2016-02-06 01:02:06 +01:00
|
|
|
req->rootdir = wine_server_obj_handle( attr->RootDirectory );
|
2016-01-29 06:57:04 +01:00
|
|
|
if (attr->ObjectName)
|
|
|
|
wine_server_add_data( req, attr->ObjectName->Buffer, attr->ObjectName->Length );
|
2003-05-20 06:00:42 +02:00
|
|
|
status = wine_server_call( req );
|
2008-12-08 16:05:17 +01:00
|
|
|
*handle = wine_server_ptr_handle( reply->handle );
|
2003-05-20 06:00:42 +02:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* NtSetTimer [NTDLL.@]
|
|
|
|
* ZwSetTimer [NTDLL.@]
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtSetTimer(IN HANDLE handle,
|
|
|
|
IN const LARGE_INTEGER* when,
|
2005-06-10 21:33:47 +02:00
|
|
|
IN PTIMER_APC_ROUTINE callback,
|
2003-05-20 06:00:42 +02:00
|
|
|
IN PVOID callback_arg,
|
|
|
|
IN BOOLEAN resume,
|
|
|
|
IN ULONG period OPTIONAL,
|
|
|
|
OUT PBOOLEAN state OPTIONAL)
|
|
|
|
{
|
|
|
|
NTSTATUS status = STATUS_SUCCESS;
|
|
|
|
|
2016-05-05 05:33:07 +02:00
|
|
|
TRACE("(%p,%p,%p,%p,%08x,0x%08x,%p)\n",
|
2003-05-20 06:00:42 +02:00
|
|
|
handle, when, callback, callback_arg, resume, period, state);
|
|
|
|
|
|
|
|
SERVER_START_REQ( set_timer )
|
|
|
|
{
|
2008-12-08 16:05:17 +01:00
|
|
|
req->handle = wine_server_obj_handle( handle );
|
2003-05-20 06:00:42 +02:00
|
|
|
req->period = period;
|
2007-04-17 20:08:59 +02:00
|
|
|
req->expire = when->QuadPart;
|
2008-12-29 17:43:01 +01:00
|
|
|
req->callback = wine_server_client_ptr( callback );
|
|
|
|
req->arg = wine_server_client_ptr( callback_arg );
|
2003-05-20 06:00:42 +02:00
|
|
|
status = wine_server_call( req );
|
|
|
|
if (state) *state = reply->signaled;
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
|
|
|
/* set error but can still succeed */
|
|
|
|
if (resume && status == STATUS_SUCCESS) return STATUS_TIMER_RESUME_IGNORED;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* NtCancelTimer [NTDLL.@]
|
|
|
|
* ZwCancelTimer [NTDLL.@]
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtCancelTimer(IN HANDLE handle, OUT BOOLEAN* state)
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
SERVER_START_REQ( cancel_timer )
|
|
|
|
{
|
2008-12-08 16:05:17 +01:00
|
|
|
req->handle = wine_server_obj_handle( handle );
|
2003-05-20 06:00:42 +02:00
|
|
|
status = wine_server_call( req );
|
|
|
|
if (state) *state = reply->signaled;
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2004-12-13 22:10:58 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* NtQueryTimer (NTDLL.@)
|
|
|
|
*
|
|
|
|
* Retrieves information about a timer.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* TimerHandle [I] The timer to retrieve information about.
|
|
|
|
* TimerInformationClass [I] The type of information to retrieve.
|
|
|
|
* TimerInformation [O] Pointer to buffer to store information in.
|
|
|
|
* Length [I] The length of the buffer pointed to by TimerInformation.
|
|
|
|
* ReturnLength [O] Optional. The size of buffer actually used.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: STATUS_SUCCESS
|
|
|
|
* Failure: STATUS_INFO_LENGTH_MISMATCH, if Length doesn't match the required data
|
|
|
|
* size for the class specified.
|
|
|
|
* STATUS_INVALID_INFO_CLASS, if an invalid TimerInformationClass was specified.
|
|
|
|
* STATUS_ACCESS_DENIED, if TimerHandle does not have TIMER_QUERY_STATE access
|
|
|
|
* to the timer.
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtQueryTimer(
|
|
|
|
HANDLE TimerHandle,
|
|
|
|
TIMER_INFORMATION_CLASS TimerInformationClass,
|
|
|
|
PVOID TimerInformation,
|
|
|
|
ULONG Length,
|
|
|
|
PULONG ReturnLength)
|
|
|
|
{
|
2009-03-17 00:12:11 +01:00
|
|
|
TIMER_BASIC_INFORMATION * basic_info = TimerInformation;
|
2004-12-13 22:10:58 +01:00
|
|
|
NTSTATUS status;
|
|
|
|
LARGE_INTEGER now;
|
|
|
|
|
2006-10-16 13:49:06 +02:00
|
|
|
TRACE("(%p,%d,%p,0x%08x,%p)\n", TimerHandle, TimerInformationClass,
|
2004-12-13 22:10:58 +01:00
|
|
|
TimerInformation, Length, ReturnLength);
|
|
|
|
|
|
|
|
switch (TimerInformationClass)
|
|
|
|
{
|
|
|
|
case TimerBasicInformation:
|
|
|
|
if (Length < sizeof(TIMER_BASIC_INFORMATION))
|
|
|
|
return STATUS_INFO_LENGTH_MISMATCH;
|
|
|
|
|
|
|
|
SERVER_START_REQ(get_timer_info)
|
|
|
|
{
|
2008-12-08 16:05:17 +01:00
|
|
|
req->handle = wine_server_obj_handle( TimerHandle );
|
2004-12-13 22:10:58 +01:00
|
|
|
status = wine_server_call(req);
|
|
|
|
|
|
|
|
/* convert server time to absolute NTDLL time */
|
2007-04-17 20:08:59 +02:00
|
|
|
basic_info->RemainingTime.QuadPart = reply->when;
|
2004-12-13 22:10:58 +01:00
|
|
|
basic_info->TimerState = reply->signaled;
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
|
|
|
/* convert from absolute into relative time */
|
|
|
|
NtQuerySystemTime(&now);
|
|
|
|
if (now.QuadPart > basic_info->RemainingTime.QuadPart)
|
|
|
|
basic_info->RemainingTime.QuadPart = 0;
|
|
|
|
else
|
|
|
|
basic_info->RemainingTime.QuadPart -= now.QuadPart;
|
|
|
|
|
|
|
|
if (ReturnLength) *ReturnLength = sizeof(TIMER_BASIC_INFORMATION);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
FIXME("Unhandled class %d\n", TimerInformationClass);
|
|
|
|
return STATUS_INVALID_INFO_CLASS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-20 06:00:42 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* NtQueryTimerResolution [NTDLL.@]
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtQueryTimerResolution(OUT ULONG* min_resolution,
|
|
|
|
OUT ULONG* max_resolution,
|
|
|
|
OUT ULONG* current_resolution)
|
|
|
|
{
|
|
|
|
FIXME("(%p,%p,%p), stub!\n",
|
|
|
|
min_resolution, max_resolution, current_resolution);
|
|
|
|
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* NtSetTimerResolution [NTDLL.@]
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtSetTimerResolution(IN ULONG resolution,
|
|
|
|
IN BOOLEAN set_resolution,
|
|
|
|
OUT ULONG* current_resolution )
|
|
|
|
{
|
2006-10-16 13:49:06 +02:00
|
|
|
FIXME("(%u,%u,%p), stub!\n",
|
2003-05-20 06:00:42 +02:00
|
|
|
resolution, set_resolution, current_resolution);
|
|
|
|
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-31 03:37:04 +02:00
|
|
|
|
2003-06-30 23:00:15 +02:00
|
|
|
/* wait operations */
|
|
|
|
|
2015-08-24 08:17:54 +02:00
|
|
|
static NTSTATUS wait_objects( DWORD count, const HANDLE *handles,
|
|
|
|
BOOLEAN wait_any, BOOLEAN alertable,
|
|
|
|
const LARGE_INTEGER *timeout )
|
2003-06-30 23:00:15 +02:00
|
|
|
{
|
2013-08-22 10:53:45 +02:00
|
|
|
select_op_t select_op;
|
|
|
|
UINT i, flags = SELECT_INTERRUPTIBLE;
|
2003-06-30 23:00:15 +02:00
|
|
|
|
|
|
|
if (!count || count > MAXIMUM_WAIT_OBJECTS) return STATUS_INVALID_PARAMETER_1;
|
|
|
|
|
|
|
|
if (alertable) flags |= SELECT_ALERTABLE;
|
2014-09-01 08:40:42 +02:00
|
|
|
select_op.wait.op = wait_any ? SELECT_WAIT : SELECT_WAIT_ALL;
|
2013-08-22 10:53:45 +02:00
|
|
|
for (i = 0; i < count; i++) select_op.wait.handles[i] = wine_server_obj_handle( handles[i] );
|
2013-08-22 11:27:15 +02:00
|
|
|
return server_select( &select_op, offsetof( select_op_t, wait.handles[count] ), flags, timeout );
|
2003-06-30 23:00:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-24 08:17:54 +02:00
|
|
|
/******************************************************************
|
|
|
|
* NtWaitForMultipleObjects (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtWaitForMultipleObjects( DWORD count, const HANDLE *handles,
|
|
|
|
BOOLEAN wait_any, BOOLEAN alertable,
|
|
|
|
const LARGE_INTEGER *timeout )
|
|
|
|
{
|
|
|
|
return wait_objects( count, handles, wait_any, alertable, timeout );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-31 03:37:04 +02:00
|
|
|
/******************************************************************
|
|
|
|
* NtWaitForSingleObject (NTDLL.@)
|
|
|
|
*/
|
2003-06-30 23:00:15 +02:00
|
|
|
NTSTATUS WINAPI NtWaitForSingleObject(HANDLE handle, BOOLEAN alertable, const LARGE_INTEGER *timeout )
|
2003-03-31 03:37:04 +02:00
|
|
|
{
|
2015-08-24 08:17:54 +02:00
|
|
|
return wait_objects( 1, &handle, FALSE, alertable, timeout );
|
2003-03-31 03:37:04 +02:00
|
|
|
}
|
2003-06-30 23:00:15 +02:00
|
|
|
|
|
|
|
|
2005-04-24 19:35:52 +02:00
|
|
|
/******************************************************************
|
|
|
|
* NtSignalAndWaitForSingleObject (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtSignalAndWaitForSingleObject( HANDLE hSignalObject, HANDLE hWaitObject,
|
|
|
|
BOOLEAN alertable, const LARGE_INTEGER *timeout )
|
|
|
|
{
|
2013-08-22 10:53:45 +02:00
|
|
|
select_op_t select_op;
|
2005-04-24 19:35:52 +02:00
|
|
|
UINT flags = SELECT_INTERRUPTIBLE;
|
|
|
|
|
|
|
|
if (!hSignalObject) return STATUS_INVALID_HANDLE;
|
2013-08-22 11:15:44 +02:00
|
|
|
|
2005-04-24 19:35:52 +02:00
|
|
|
if (alertable) flags |= SELECT_ALERTABLE;
|
2013-08-22 11:15:44 +02:00
|
|
|
select_op.signal_and_wait.op = SELECT_SIGNAL_AND_WAIT;
|
|
|
|
select_op.signal_and_wait.wait = wine_server_obj_handle( hWaitObject );
|
|
|
|
select_op.signal_and_wait.signal = wine_server_obj_handle( hSignalObject );
|
2013-08-22 11:27:15 +02:00
|
|
|
return server_select( &select_op, sizeof(select_op.signal_and_wait), flags, timeout );
|
2005-04-24 19:35:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-11 22:11:01 +02:00
|
|
|
/******************************************************************
|
|
|
|
* NtYieldExecution (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtYieldExecution(void)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_SCHED_YIELD
|
|
|
|
sched_yield();
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
#else
|
|
|
|
return STATUS_NO_YIELD_PERFORMED;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-30 23:00:15 +02:00
|
|
|
/******************************************************************
|
|
|
|
* NtDelayExecution (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtDelayExecution( BOOLEAN alertable, const LARGE_INTEGER *timeout )
|
|
|
|
{
|
2007-06-04 18:17:16 +02:00
|
|
|
/* if alertable, we need to query the server */
|
|
|
|
if (alertable)
|
2013-08-22 11:27:15 +02:00
|
|
|
return server_select( NULL, 0, SELECT_INTERRUPTIBLE | SELECT_ALERTABLE, timeout );
|
2003-06-30 23:00:15 +02:00
|
|
|
|
2007-04-17 20:08:59 +02:00
|
|
|
if (!timeout || timeout->QuadPart == TIMEOUT_INFINITE) /* sleep forever */
|
2003-06-30 23:00:15 +02:00
|
|
|
{
|
|
|
|
for (;;) select( 0, NULL, NULL, NULL, NULL );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-04-17 20:08:59 +02:00
|
|
|
LARGE_INTEGER now;
|
|
|
|
timeout_t when, diff;
|
2003-06-30 23:00:15 +02:00
|
|
|
|
2007-04-17 20:08:59 +02:00
|
|
|
if ((when = timeout->QuadPart) < 0)
|
|
|
|
{
|
|
|
|
NtQuerySystemTime( &now );
|
|
|
|
when = now.QuadPart - when;
|
|
|
|
}
|
2004-11-02 20:32:03 +01:00
|
|
|
|
|
|
|
/* Note that we yield after establishing the desired timeout */
|
|
|
|
NtYieldExecution();
|
2007-04-17 20:08:59 +02:00
|
|
|
if (!when) return STATUS_SUCCESS;
|
2004-11-02 20:32:03 +01:00
|
|
|
|
2003-06-30 23:00:15 +02:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
struct timeval tv;
|
2007-04-17 20:08:59 +02:00
|
|
|
NtQuerySystemTime( &now );
|
|
|
|
diff = (when - now.QuadPart + 9) / 10;
|
|
|
|
if (diff <= 0) break;
|
|
|
|
tv.tv_sec = diff / 1000000;
|
|
|
|
tv.tv_usec = diff % 1000000;
|
2003-06-30 23:00:15 +02:00
|
|
|
if (select( 0, NULL, NULL, NULL, &tv ) != -1) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
2006-04-19 10:26:11 +02:00
|
|
|
|
2013-08-21 12:51:31 +02:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* NtCreateKeyedEvent (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtCreateKeyedEvent( HANDLE *handle, ACCESS_MASK access,
|
|
|
|
const OBJECT_ATTRIBUTES *attr, ULONG flags )
|
|
|
|
{
|
2013-08-21 12:54:17 +02:00
|
|
|
NTSTATUS ret;
|
2016-01-15 09:40:56 +01:00
|
|
|
data_size_t len;
|
|
|
|
struct object_attributes *objattr;
|
2013-08-21 12:54:17 +02:00
|
|
|
|
2016-01-15 09:40:56 +01:00
|
|
|
if ((ret = alloc_object_attributes( attr, &objattr, &len ))) return ret;
|
2013-08-21 12:54:17 +02:00
|
|
|
|
|
|
|
SERVER_START_REQ( create_keyed_event )
|
|
|
|
{
|
|
|
|
req->access = access;
|
2016-01-15 09:40:56 +01:00
|
|
|
wine_server_add_data( req, objattr, len );
|
2013-08-21 12:54:17 +02:00
|
|
|
ret = wine_server_call( req );
|
|
|
|
*handle = wine_server_ptr_handle( reply->handle );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
2016-01-15 09:40:56 +01:00
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, objattr );
|
2013-08-21 12:54:17 +02:00
|
|
|
return ret;
|
2013-08-21 12:51:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* NtOpenKeyedEvent (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtOpenKeyedEvent( HANDLE *handle, ACCESS_MASK access, const OBJECT_ATTRIBUTES *attr )
|
|
|
|
{
|
2013-08-21 12:54:17 +02:00
|
|
|
NTSTATUS ret;
|
|
|
|
|
2016-01-29 06:57:04 +01:00
|
|
|
if ((ret = validate_open_object_attributes( attr ))) return ret;
|
|
|
|
|
2013-08-22 10:27:46 +02:00
|
|
|
SERVER_START_REQ( open_keyed_event )
|
2013-08-21 12:54:17 +02:00
|
|
|
{
|
2016-01-29 06:57:04 +01:00
|
|
|
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 );
|
2013-08-21 12:54:17 +02:00
|
|
|
ret = wine_server_call( req );
|
|
|
|
*handle = wine_server_ptr_handle( reply->handle );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return ret;
|
2013-08-21 12:51:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* NtWaitForKeyedEvent (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtWaitForKeyedEvent( HANDLE handle, const void *key,
|
|
|
|
BOOLEAN alertable, const LARGE_INTEGER *timeout )
|
|
|
|
{
|
2013-08-22 17:53:15 +02:00
|
|
|
select_op_t select_op;
|
|
|
|
UINT flags = SELECT_INTERRUPTIBLE;
|
|
|
|
|
2018-10-26 11:27:11 +02:00
|
|
|
if (!handle) handle = keyed_event;
|
2013-08-22 17:53:15 +02:00
|
|
|
if ((ULONG_PTR)key & 1) return STATUS_INVALID_PARAMETER_1;
|
|
|
|
if (alertable) flags |= SELECT_ALERTABLE;
|
|
|
|
select_op.keyed_event.op = SELECT_KEYED_EVENT_WAIT;
|
|
|
|
select_op.keyed_event.handle = wine_server_obj_handle( handle );
|
|
|
|
select_op.keyed_event.key = wine_server_client_ptr( key );
|
|
|
|
return server_select( &select_op, sizeof(select_op.keyed_event), flags, timeout );
|
2013-08-21 12:51:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* NtReleaseKeyedEvent (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtReleaseKeyedEvent( HANDLE handle, const void *key,
|
|
|
|
BOOLEAN alertable, const LARGE_INTEGER *timeout )
|
|
|
|
{
|
2013-08-22 17:53:15 +02:00
|
|
|
select_op_t select_op;
|
|
|
|
UINT flags = SELECT_INTERRUPTIBLE;
|
|
|
|
|
2018-10-26 11:27:11 +02:00
|
|
|
if (!handle) handle = keyed_event;
|
2013-08-22 17:53:15 +02:00
|
|
|
if ((ULONG_PTR)key & 1) return STATUS_INVALID_PARAMETER_1;
|
|
|
|
if (alertable) flags |= SELECT_ALERTABLE;
|
|
|
|
select_op.keyed_event.op = SELECT_KEYED_EVENT_RELEASE;
|
|
|
|
select_op.keyed_event.handle = wine_server_obj_handle( handle );
|
|
|
|
select_op.keyed_event.key = wine_server_client_ptr( key );
|
|
|
|
return server_select( &select_op, sizeof(select_op.keyed_event), flags, timeout );
|
2013-08-21 12:51:31 +02:00
|
|
|
}
|
|
|
|
|
2006-05-12 00:34:55 +02:00
|
|
|
/******************************************************************
|
2007-06-02 00:30:14 +02:00
|
|
|
* NtCreateIoCompletion (NTDLL.@)
|
|
|
|
* ZwCreateIoCompletion (NTDLL.@)
|
|
|
|
*
|
|
|
|
* Creates I/O completion object.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* CompletionPort [O] created completion object handle will be placed there
|
|
|
|
* DesiredAccess [I] desired access to a handle (combination of IO_COMPLETION_*)
|
|
|
|
* ObjectAttributes [I] completion object attributes
|
|
|
|
* NumberOfConcurrentThreads [I] desired number of concurrent active worker threads
|
|
|
|
*
|
2006-05-12 00:34:55 +02:00
|
|
|
*/
|
2006-04-19 10:26:11 +02:00
|
|
|
NTSTATUS WINAPI NtCreateIoCompletion( PHANDLE CompletionPort, ACCESS_MASK DesiredAccess,
|
2016-01-15 12:49:38 +01:00
|
|
|
POBJECT_ATTRIBUTES attr, ULONG NumberOfConcurrentThreads )
|
2006-04-19 10:26:11 +02:00
|
|
|
{
|
2007-09-17 22:00:45 +02:00
|
|
|
NTSTATUS status;
|
2016-01-15 12:49:38 +01:00
|
|
|
data_size_t len;
|
|
|
|
struct object_attributes *objattr;
|
2007-09-17 22:00:45 +02:00
|
|
|
|
2016-01-15 12:49:38 +01:00
|
|
|
TRACE("(%p, %x, %p, %d)\n", CompletionPort, DesiredAccess, attr, NumberOfConcurrentThreads);
|
2007-09-17 22:00:45 +02:00
|
|
|
|
|
|
|
if (!CompletionPort)
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
|
2016-01-15 12:49:38 +01:00
|
|
|
if ((status = alloc_object_attributes( attr, &objattr, &len ))) return status;
|
|
|
|
|
2007-09-17 22:00:45 +02:00
|
|
|
SERVER_START_REQ( create_completion )
|
|
|
|
{
|
|
|
|
req->access = DesiredAccess;
|
|
|
|
req->concurrent = NumberOfConcurrentThreads;
|
2016-01-15 12:49:38 +01:00
|
|
|
wine_server_add_data( req, objattr, len );
|
2007-09-17 22:00:45 +02:00
|
|
|
if (!(status = wine_server_call( req )))
|
2008-12-08 16:05:17 +01:00
|
|
|
*CompletionPort = wine_server_ptr_handle( reply->handle );
|
2007-09-17 22:00:45 +02:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
2016-01-15 12:49:38 +01:00
|
|
|
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, objattr );
|
2007-09-17 22:00:45 +02:00
|
|
|
return status;
|
2006-04-19 10:26:11 +02:00
|
|
|
}
|
|
|
|
|
2007-06-02 00:30:14 +02:00
|
|
|
/******************************************************************
|
|
|
|
* NtSetIoCompletion (NTDLL.@)
|
|
|
|
* ZwSetIoCompletion (NTDLL.@)
|
|
|
|
*
|
|
|
|
* Inserts completion message into queue
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* CompletionPort [I] HANDLE to completion object
|
|
|
|
* CompletionKey [I] completion key
|
|
|
|
* CompletionValue [I] completion value (usually pointer to OVERLAPPED)
|
|
|
|
* Status [I] operation status
|
|
|
|
* NumberOfBytesTransferred [I] number of bytes transferred
|
|
|
|
*/
|
2006-04-19 10:26:11 +02:00
|
|
|
NTSTATUS WINAPI NtSetIoCompletion( HANDLE CompletionPort, ULONG_PTR CompletionKey,
|
2007-06-02 00:30:14 +02:00
|
|
|
ULONG_PTR CompletionValue, NTSTATUS Status,
|
2013-08-20 13:20:39 +02:00
|
|
|
SIZE_T NumberOfBytesTransferred )
|
2006-04-19 10:26:11 +02:00
|
|
|
{
|
2007-09-17 22:00:45 +02:00
|
|
|
NTSTATUS status;
|
|
|
|
|
2013-08-20 13:20:39 +02:00
|
|
|
TRACE("(%p, %lx, %lx, %x, %lx)\n", CompletionPort, CompletionKey,
|
2007-09-17 22:00:45 +02:00
|
|
|
CompletionValue, Status, NumberOfBytesTransferred);
|
|
|
|
|
|
|
|
SERVER_START_REQ( add_completion )
|
|
|
|
{
|
2008-12-08 16:05:17 +01:00
|
|
|
req->handle = wine_server_obj_handle( CompletionPort );
|
2007-09-17 22:00:45 +02:00
|
|
|
req->ckey = CompletionKey;
|
|
|
|
req->cvalue = CompletionValue;
|
|
|
|
req->status = Status;
|
|
|
|
req->information = NumberOfBytesTransferred;
|
|
|
|
status = wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return status;
|
2006-04-19 10:26:11 +02:00
|
|
|
}
|
|
|
|
|
2007-06-02 00:30:14 +02:00
|
|
|
/******************************************************************
|
|
|
|
* NtRemoveIoCompletion (NTDLL.@)
|
|
|
|
* ZwRemoveIoCompletion (NTDLL.@)
|
|
|
|
*
|
|
|
|
* (Wait for and) retrieve first completion message from completion object's queue
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* CompletionPort [I] HANDLE to I/O completion object
|
|
|
|
* CompletionKey [O] completion key
|
|
|
|
* CompletionValue [O] Completion value given in NtSetIoCompletion or in async operation
|
|
|
|
* iosb [O] IO_STATUS_BLOCK of completed asynchronous operation
|
|
|
|
* WaitTime [I] optional wait time in NTDLL format
|
|
|
|
*
|
|
|
|
*/
|
2006-04-19 10:26:11 +02:00
|
|
|
NTSTATUS WINAPI NtRemoveIoCompletion( HANDLE CompletionPort, PULONG_PTR CompletionKey,
|
2007-06-02 00:30:14 +02:00
|
|
|
PULONG_PTR CompletionValue, PIO_STATUS_BLOCK iosb,
|
2006-04-19 10:26:11 +02:00
|
|
|
PLARGE_INTEGER WaitTime )
|
|
|
|
{
|
2007-09-17 22:00:45 +02:00
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
TRACE("(%p, %p, %p, %p, %p)\n", CompletionPort, CompletionKey,
|
2007-06-02 00:30:14 +02:00
|
|
|
CompletionValue, iosb, WaitTime);
|
2007-09-17 22:00:45 +02:00
|
|
|
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
SERVER_START_REQ( remove_completion )
|
|
|
|
{
|
2008-12-08 16:05:17 +01:00
|
|
|
req->handle = wine_server_obj_handle( CompletionPort );
|
2007-09-17 22:00:45 +02:00
|
|
|
if (!(status = wine_server_call( req )))
|
|
|
|
{
|
|
|
|
*CompletionKey = reply->ckey;
|
|
|
|
*CompletionValue = reply->cvalue;
|
|
|
|
iosb->Information = reply->information;
|
|
|
|
iosb->u.Status = reply->status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
if (status != STATUS_PENDING) break;
|
|
|
|
|
|
|
|
status = NtWaitForSingleObject( CompletionPort, FALSE, WaitTime );
|
|
|
|
if (status != WAIT_OBJECT_0) break;
|
|
|
|
}
|
|
|
|
return status;
|
2007-06-02 00:30:14 +02:00
|
|
|
}
|
|
|
|
|
2018-09-30 23:59:47 +02:00
|
|
|
/******************************************************************
|
|
|
|
* NtRemoveIoCompletionEx (NTDLL.@)
|
|
|
|
* ZwRemoveIoCompletionEx (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtRemoveIoCompletionEx( HANDLE port, FILE_IO_COMPLETION_INFORMATION *info, ULONG count,
|
|
|
|
ULONG *written, LARGE_INTEGER *timeout, BOOLEAN alertable )
|
|
|
|
{
|
|
|
|
NTSTATUS ret;
|
|
|
|
ULONG i = 0;
|
|
|
|
|
|
|
|
TRACE("%p %p %u %p %p %u\n", port, info, count, written, timeout, alertable);
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
2018-11-18 03:06:17 +01:00
|
|
|
while (i < count)
|
2018-09-30 23:59:47 +02:00
|
|
|
{
|
|
|
|
SERVER_START_REQ( remove_completion )
|
|
|
|
{
|
|
|
|
req->handle = wine_server_obj_handle( port );
|
|
|
|
if (!(ret = wine_server_call( req )))
|
|
|
|
{
|
|
|
|
info[i].CompletionKey = reply->ckey;
|
|
|
|
info[i].CompletionValue = reply->cvalue;
|
|
|
|
info[i].IoStatusBlock.Information = reply->information;
|
|
|
|
info[i].IoStatusBlock.u.Status = reply->status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
|
|
|
if (ret != STATUS_SUCCESS) break;
|
|
|
|
|
2018-11-18 03:06:17 +01:00
|
|
|
++i;
|
2018-09-30 23:59:47 +02:00
|
|
|
}
|
|
|
|
|
2018-11-18 03:06:16 +01:00
|
|
|
if (i || ret != STATUS_PENDING)
|
2018-09-30 23:59:47 +02:00
|
|
|
{
|
2018-11-18 03:06:16 +01:00
|
|
|
if (ret == STATUS_PENDING)
|
|
|
|
ret = STATUS_SUCCESS;
|
2018-09-30 23:59:47 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = NtWaitForSingleObject( port, alertable, timeout );
|
|
|
|
if (ret != WAIT_OBJECT_0) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
*written = i ? i : 1;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-06-02 00:30:14 +02:00
|
|
|
/******************************************************************
|
|
|
|
* NtOpenIoCompletion (NTDLL.@)
|
|
|
|
* ZwOpenIoCompletion (NTDLL.@)
|
|
|
|
*
|
|
|
|
* Opens I/O completion object
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* CompletionPort [O] completion object handle will be placed there
|
|
|
|
* DesiredAccess [I] desired access to a handle (combination of IO_COMPLETION_*)
|
|
|
|
* ObjectAttributes [I] completion object name
|
|
|
|
*
|
|
|
|
*/
|
2016-01-29 06:57:04 +01:00
|
|
|
NTSTATUS WINAPI NtOpenIoCompletion( HANDLE *handle, ACCESS_MASK access, const OBJECT_ATTRIBUTES *attr )
|
2007-06-02 00:30:14 +02:00
|
|
|
{
|
2007-09-17 22:00:45 +02:00
|
|
|
NTSTATUS status;
|
|
|
|
|
2016-01-29 06:57:04 +01:00
|
|
|
if (!handle) return STATUS_INVALID_PARAMETER;
|
|
|
|
if ((status = validate_open_object_attributes( attr ))) return status;
|
2007-09-17 22:00:45 +02:00
|
|
|
|
|
|
|
SERVER_START_REQ( open_completion )
|
|
|
|
{
|
2016-01-29 06:57:04 +01:00
|
|
|
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 );
|
|
|
|
status = wine_server_call( req );
|
|
|
|
*handle = wine_server_ptr_handle( reply->handle );
|
2007-09-17 22:00:45 +02:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return status;
|
2007-06-02 00:30:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* NtQueryIoCompletion (NTDLL.@)
|
|
|
|
* ZwQueryIoCompletion (NTDLL.@)
|
|
|
|
*
|
|
|
|
* Requests information about given I/O completion object
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* CompletionPort [I] HANDLE to completion port to request
|
|
|
|
* InformationClass [I] information class
|
|
|
|
* CompletionInformation [O] user-provided buffer for data
|
|
|
|
* BufferLength [I] buffer length
|
|
|
|
* RequiredLength [O] required buffer length
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtQueryIoCompletion( HANDLE CompletionPort, IO_COMPLETION_INFORMATION_CLASS InformationClass,
|
|
|
|
PVOID CompletionInformation, ULONG BufferLength, PULONG RequiredLength )
|
|
|
|
{
|
2007-09-17 22:00:45 +02:00
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
TRACE("(%p, %d, %p, 0x%x, %p)\n", CompletionPort, InformationClass, CompletionInformation,
|
|
|
|
BufferLength, RequiredLength);
|
|
|
|
|
|
|
|
if (!CompletionInformation) return STATUS_INVALID_PARAMETER;
|
|
|
|
switch( InformationClass )
|
|
|
|
{
|
|
|
|
case IoCompletionBasicInformation:
|
|
|
|
{
|
2009-03-17 00:12:11 +01:00
|
|
|
ULONG *info = CompletionInformation;
|
2007-09-17 22:00:45 +02:00
|
|
|
|
|
|
|
if (RequiredLength) *RequiredLength = sizeof(*info);
|
|
|
|
if (BufferLength != sizeof(*info))
|
|
|
|
status = STATUS_INFO_LENGTH_MISMATCH;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SERVER_START_REQ( query_completion )
|
|
|
|
{
|
2008-12-08 16:05:17 +01:00
|
|
|
req->handle = wine_server_obj_handle( CompletionPort );
|
2007-09-17 22:00:45 +02:00
|
|
|
if (!(status = wine_server_call( req )))
|
|
|
|
*info = reply->depth;
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
status = STATUS_INVALID_PARAMETER;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return status;
|
2006-04-19 10:26:11 +02:00
|
|
|
}
|
2007-11-09 23:12:07 +01:00
|
|
|
|
2008-12-15 13:30:25 +01:00
|
|
|
NTSTATUS NTDLL_AddCompletion( HANDLE hFile, ULONG_PTR CompletionValue,
|
2019-02-21 15:10:14 +01:00
|
|
|
NTSTATUS CompletionStatus, ULONG Information, BOOL async )
|
2007-11-09 23:12:07 +01:00
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
SERVER_START_REQ( add_fd_completion )
|
|
|
|
{
|
2008-12-08 16:05:17 +01:00
|
|
|
req->handle = wine_server_obj_handle( hFile );
|
2007-11-09 23:12:07 +01:00
|
|
|
req->cvalue = CompletionValue;
|
|
|
|
req->status = CompletionStatus;
|
|
|
|
req->information = Information;
|
2019-02-21 15:10:14 +01:00
|
|
|
req->async = async;
|
2007-11-09 23:12:07 +01:00
|
|
|
status = wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return status;
|
|
|
|
}
|
2012-07-22 16:33:14 +02:00
|
|
|
|
2013-08-28 21:10:50 +02:00
|
|
|
/******************************************************************
|
|
|
|
* RtlRunOnceInitialize (NTDLL.@)
|
|
|
|
*/
|
|
|
|
void WINAPI RtlRunOnceInitialize( RTL_RUN_ONCE *once )
|
|
|
|
{
|
|
|
|
once->Ptr = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* RtlRunOnceBeginInitialize (NTDLL.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI RtlRunOnceBeginInitialize( RTL_RUN_ONCE *once, ULONG flags, void **context )
|
|
|
|
{
|
|
|
|
if (flags & RTL_RUN_ONCE_CHECK_ONLY)
|
|
|
|
{
|
|
|
|
ULONG_PTR val = (ULONG_PTR)once->Ptr;
|
|
|
|
|
|
|
|
if (flags & RTL_RUN_ONCE_ASYNC) return STATUS_INVALID_PARAMETER;
|
|
|
|
if ((val & 3) != 2) return STATUS_UNSUCCESSFUL;
|
|
|
|
if (context) *context = (void *)(val & ~3);
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
ULONG_PTR next, val = (ULONG_PTR)once->Ptr;
|
|
|
|
|
|
|
|
switch (val & 3)
|
|
|
|
{
|
|
|
|
case 0: /* first time */
|
|
|
|
if (!interlocked_cmpxchg_ptr( &once->Ptr,
|
|
|
|
(flags & RTL_RUN_ONCE_ASYNC) ? (void *)3 : (void *)1, 0 ))
|
|
|
|
return STATUS_PENDING;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1: /* in progress, wait */
|
|
|
|
if (flags & RTL_RUN_ONCE_ASYNC) return STATUS_INVALID_PARAMETER;
|
|
|
|
next = val & ~3;
|
|
|
|
if (interlocked_cmpxchg_ptr( &once->Ptr, (void *)((ULONG_PTR)&next | 1),
|
|
|
|
(void *)val ) == (void *)val)
|
2018-10-26 11:27:11 +02:00
|
|
|
NtWaitForKeyedEvent( 0, &next, FALSE, NULL );
|
2013-08-28 21:10:50 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: /* done */
|
|
|
|
if (context) *context = (void *)(val & ~3);
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
|
|
|
|
case 3: /* in progress, async */
|
|
|
|
if (!(flags & RTL_RUN_ONCE_ASYNC)) return STATUS_INVALID_PARAMETER;
|
|
|
|
return STATUS_PENDING;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* RtlRunOnceComplete (NTDLL.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI RtlRunOnceComplete( RTL_RUN_ONCE *once, ULONG flags, void *context )
|
|
|
|
{
|
|
|
|
if ((ULONG_PTR)context & 3) return STATUS_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
if (flags & RTL_RUN_ONCE_INIT_FAILED)
|
|
|
|
{
|
|
|
|
if (context) return STATUS_INVALID_PARAMETER;
|
|
|
|
if (flags & RTL_RUN_ONCE_ASYNC) return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
else context = (void *)((ULONG_PTR)context | 2);
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
ULONG_PTR val = (ULONG_PTR)once->Ptr;
|
|
|
|
|
|
|
|
switch (val & 3)
|
|
|
|
{
|
|
|
|
case 1: /* in progress */
|
|
|
|
if (interlocked_cmpxchg_ptr( &once->Ptr, context, (void *)val ) != (void *)val) break;
|
|
|
|
val &= ~3;
|
|
|
|
while (val)
|
|
|
|
{
|
|
|
|
ULONG_PTR next = *(ULONG_PTR *)val;
|
2018-10-26 11:27:11 +02:00
|
|
|
NtReleaseKeyedEvent( 0, (void *)val, FALSE, NULL );
|
2013-08-28 21:10:50 +02:00
|
|
|
val = next;
|
|
|
|
}
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
|
|
|
|
case 3: /* in progress, async */
|
|
|
|
if (!(flags & RTL_RUN_ONCE_ASYNC)) return STATUS_INVALID_PARAMETER;
|
|
|
|
if (interlocked_cmpxchg_ptr( &once->Ptr, context, (void *)val ) != (void *)val) break;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* RtlRunOnceExecuteOnce (NTDLL.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI RtlRunOnceExecuteOnce( RTL_RUN_ONCE *once, PRTL_RUN_ONCE_INIT_FN func,
|
|
|
|
void *param, void **context )
|
2012-07-22 16:33:14 +02:00
|
|
|
{
|
2013-08-28 21:10:50 +02:00
|
|
|
DWORD ret = RtlRunOnceBeginInitialize( once, 0, context );
|
|
|
|
|
|
|
|
if (ret != STATUS_PENDING) return ret;
|
|
|
|
|
|
|
|
if (!func( once, param, context ))
|
|
|
|
{
|
|
|
|
RtlRunOnceComplete( once, RTL_RUN_ONCE_INIT_FAILED, NULL );
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return RtlRunOnceComplete( once, 0, context ? *context : NULL );
|
2012-07-22 16:33:14 +02:00
|
|
|
}
|
2013-09-03 11:08:42 +02:00
|
|
|
|
2019-06-10 17:07:53 +02:00
|
|
|
#ifdef __linux__
|
|
|
|
|
|
|
|
/* Futex-based SRW lock implementation:
|
|
|
|
*
|
|
|
|
* Since we can rely on the kernel to release all threads and don't need to
|
|
|
|
* worry about NtReleaseKeyedEvent(), we can simplify the layout a bit. The
|
|
|
|
* layout looks like this:
|
|
|
|
*
|
|
|
|
* 31 - Exclusive lock bit, set if the resource is owned exclusively.
|
|
|
|
* 30-16 - Number of exclusive waiters. Unlike the fallback implementation,
|
|
|
|
* this does not include the thread owning the lock, or shared threads
|
|
|
|
* waiting on the lock.
|
2019-06-10 17:07:54 +02:00
|
|
|
* 15 - Does this lock have any shared waiters? We use this as an
|
|
|
|
* optimization to avoid unnecessary FUTEX_WAKE_BITSET calls when
|
|
|
|
* releasing an exclusive lock.
|
|
|
|
* 14-0 - Number of shared owners. Unlike the fallback implementation, this
|
2019-06-10 17:07:53 +02:00
|
|
|
* does not include the number of shared threads waiting on the lock.
|
|
|
|
* Thus the state [1, x, >=1] will never occur.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define SRWLOCK_FUTEX_EXCLUSIVE_LOCK_BIT 0x80000000
|
|
|
|
#define SRWLOCK_FUTEX_EXCLUSIVE_WAITERS_MASK 0x7fff0000
|
|
|
|
#define SRWLOCK_FUTEX_EXCLUSIVE_WAITERS_INC 0x00010000
|
2019-06-10 17:07:54 +02:00
|
|
|
#define SRWLOCK_FUTEX_SHARED_WAITERS_BIT 0x00008000
|
|
|
|
#define SRWLOCK_FUTEX_SHARED_OWNERS_MASK 0x00007fff
|
2019-06-10 17:07:53 +02:00
|
|
|
#define SRWLOCK_FUTEX_SHARED_OWNERS_INC 0x00000001
|
|
|
|
|
|
|
|
/* Futex bitmasks; these are independent from the bits in the lock itself. */
|
|
|
|
#define SRWLOCK_FUTEX_BITSET_EXCLUSIVE 1
|
|
|
|
#define SRWLOCK_FUTEX_BITSET_SHARED 2
|
|
|
|
|
|
|
|
static NTSTATUS fast_try_acquire_srw_exclusive( RTL_SRWLOCK *lock )
|
|
|
|
{
|
|
|
|
int old, new;
|
|
|
|
NTSTATUS ret;
|
|
|
|
|
|
|
|
if (!use_futexes()) return STATUS_NOT_IMPLEMENTED;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
old = *(int *)lock;
|
|
|
|
|
|
|
|
if (!(old & SRWLOCK_FUTEX_EXCLUSIVE_LOCK_BIT)
|
|
|
|
&& !(old & SRWLOCK_FUTEX_SHARED_OWNERS_MASK))
|
|
|
|
{
|
|
|
|
/* Not locked exclusive or shared. We can try to grab it. */
|
|
|
|
new = old | SRWLOCK_FUTEX_EXCLUSIVE_LOCK_BIT;
|
|
|
|
ret = STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
new = old;
|
|
|
|
ret = STATUS_TIMEOUT;
|
|
|
|
}
|
|
|
|
} while (interlocked_cmpxchg( (int *)lock, new, old ) != old);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS fast_acquire_srw_exclusive( RTL_SRWLOCK *lock )
|
|
|
|
{
|
|
|
|
int old, new;
|
|
|
|
BOOLEAN wait;
|
|
|
|
|
|
|
|
if (!use_futexes()) return STATUS_NOT_IMPLEMENTED;
|
|
|
|
|
|
|
|
/* Atomically increment the exclusive waiter count. */
|
|
|
|
do
|
|
|
|
{
|
|
|
|
old = *(int *)lock;
|
|
|
|
new = old + SRWLOCK_FUTEX_EXCLUSIVE_WAITERS_INC;
|
|
|
|
assert(new & SRWLOCK_FUTEX_EXCLUSIVE_WAITERS_MASK);
|
|
|
|
} while (interlocked_cmpxchg( (int *)lock, new, old ) != old);
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
old = *(int *)lock;
|
|
|
|
|
|
|
|
if (!(old & SRWLOCK_FUTEX_EXCLUSIVE_LOCK_BIT)
|
|
|
|
&& !(old & SRWLOCK_FUTEX_SHARED_OWNERS_MASK))
|
|
|
|
{
|
|
|
|
/* Not locked exclusive or shared. We can try to grab it. */
|
|
|
|
new = old | SRWLOCK_FUTEX_EXCLUSIVE_LOCK_BIT;
|
|
|
|
assert(old & SRWLOCK_FUTEX_EXCLUSIVE_WAITERS_MASK);
|
|
|
|
new -= SRWLOCK_FUTEX_EXCLUSIVE_WAITERS_INC;
|
|
|
|
wait = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
new = old;
|
|
|
|
wait = TRUE;
|
|
|
|
}
|
|
|
|
} while (interlocked_cmpxchg( (int *)lock, new, old ) != old);
|
|
|
|
|
|
|
|
if (!wait)
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
|
|
|
|
futex_wait_bitset( (int *)lock, new, NULL, SRWLOCK_FUTEX_BITSET_EXCLUSIVE );
|
|
|
|
}
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS fast_try_acquire_srw_shared( RTL_SRWLOCK *lock )
|
|
|
|
{
|
|
|
|
int new, old;
|
|
|
|
NTSTATUS ret;
|
|
|
|
|
|
|
|
if (!use_futexes()) return STATUS_NOT_IMPLEMENTED;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
old = *(int *)lock;
|
|
|
|
|
|
|
|
if (!(old & SRWLOCK_FUTEX_EXCLUSIVE_LOCK_BIT)
|
|
|
|
&& !(old & SRWLOCK_FUTEX_EXCLUSIVE_WAITERS_MASK))
|
|
|
|
{
|
|
|
|
/* Not locked exclusive, and no exclusive waiters. We can try to
|
|
|
|
* grab it. */
|
|
|
|
new = old + SRWLOCK_FUTEX_SHARED_OWNERS_INC;
|
|
|
|
assert(new & SRWLOCK_FUTEX_SHARED_OWNERS_MASK);
|
|
|
|
ret = STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
new = old;
|
|
|
|
ret = STATUS_TIMEOUT;
|
|
|
|
}
|
|
|
|
} while (interlocked_cmpxchg( (int *)lock, new, old ) != old);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS fast_acquire_srw_shared( RTL_SRWLOCK *lock )
|
|
|
|
{
|
|
|
|
int old, new;
|
|
|
|
BOOLEAN wait;
|
|
|
|
|
|
|
|
if (!use_futexes()) return STATUS_NOT_IMPLEMENTED;
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
old = *(int *)lock;
|
|
|
|
|
|
|
|
if (!(old & SRWLOCK_FUTEX_EXCLUSIVE_LOCK_BIT)
|
|
|
|
&& !(old & SRWLOCK_FUTEX_EXCLUSIVE_WAITERS_MASK))
|
|
|
|
{
|
|
|
|
/* Not locked exclusive, and no exclusive waiters. We can try
|
|
|
|
* to grab it. */
|
|
|
|
new = old + SRWLOCK_FUTEX_SHARED_OWNERS_INC;
|
|
|
|
assert(new & SRWLOCK_FUTEX_SHARED_OWNERS_MASK);
|
|
|
|
wait = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-06-10 17:07:54 +02:00
|
|
|
new = old | SRWLOCK_FUTEX_SHARED_WAITERS_BIT;
|
2019-06-10 17:07:53 +02:00
|
|
|
wait = TRUE;
|
|
|
|
}
|
|
|
|
} while (interlocked_cmpxchg( (int *)lock, new, old ) != old);
|
|
|
|
|
|
|
|
if (!wait)
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
|
|
|
|
futex_wait_bitset( (int *)lock, new, NULL, SRWLOCK_FUTEX_BITSET_SHARED );
|
|
|
|
}
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS fast_release_srw_exclusive( RTL_SRWLOCK *lock )
|
|
|
|
{
|
|
|
|
int old, new;
|
|
|
|
|
|
|
|
if (!use_futexes()) return STATUS_NOT_IMPLEMENTED;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
old = *(int *)lock;
|
|
|
|
|
|
|
|
if (!(old & SRWLOCK_FUTEX_EXCLUSIVE_LOCK_BIT))
|
|
|
|
{
|
|
|
|
ERR("Lock %p is not owned exclusive! (%#x)\n", lock, *(int *)lock);
|
|
|
|
return STATUS_RESOURCE_NOT_OWNED;
|
|
|
|
}
|
|
|
|
|
|
|
|
new = old & ~SRWLOCK_FUTEX_EXCLUSIVE_LOCK_BIT;
|
2019-06-10 17:07:54 +02:00
|
|
|
|
|
|
|
if (!(new & SRWLOCK_FUTEX_EXCLUSIVE_WAITERS_MASK))
|
|
|
|
new &= ~SRWLOCK_FUTEX_SHARED_WAITERS_BIT;
|
2019-06-10 17:07:53 +02:00
|
|
|
} while (interlocked_cmpxchg( (int *)lock, new, old ) != old);
|
|
|
|
|
|
|
|
if (new & SRWLOCK_FUTEX_EXCLUSIVE_WAITERS_MASK)
|
|
|
|
futex_wake_bitset( (int *)lock, 1, SRWLOCK_FUTEX_BITSET_EXCLUSIVE );
|
2019-06-10 17:07:54 +02:00
|
|
|
else if (old & SRWLOCK_FUTEX_SHARED_WAITERS_BIT)
|
2019-06-10 17:07:53 +02:00
|
|
|
futex_wake_bitset( (int *)lock, INT_MAX, SRWLOCK_FUTEX_BITSET_SHARED );
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS fast_release_srw_shared( RTL_SRWLOCK *lock )
|
|
|
|
{
|
|
|
|
int old, new;
|
|
|
|
|
|
|
|
if (!use_futexes()) return STATUS_NOT_IMPLEMENTED;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
old = *(int *)lock;
|
|
|
|
|
|
|
|
if (old & SRWLOCK_FUTEX_EXCLUSIVE_LOCK_BIT)
|
|
|
|
{
|
|
|
|
ERR("Lock %p is owned exclusive! (%#x)\n", lock, *(int *)lock);
|
|
|
|
return STATUS_RESOURCE_NOT_OWNED;
|
|
|
|
}
|
|
|
|
else if (!(old & SRWLOCK_FUTEX_SHARED_OWNERS_MASK))
|
|
|
|
{
|
|
|
|
ERR("Lock %p is not owned shared! (%#x)\n", lock, *(int *)lock);
|
|
|
|
return STATUS_RESOURCE_NOT_OWNED;
|
|
|
|
}
|
|
|
|
|
|
|
|
new = old - SRWLOCK_FUTEX_SHARED_OWNERS_INC;
|
|
|
|
} while (interlocked_cmpxchg( (int *)lock, new, old ) != old);
|
|
|
|
|
|
|
|
/* Optimization: only bother waking if there are actually exclusive waiters. */
|
|
|
|
if (!(new & SRWLOCK_FUTEX_SHARED_OWNERS_MASK) && (new & SRWLOCK_FUTEX_EXCLUSIVE_WAITERS_MASK))
|
|
|
|
futex_wake_bitset( (int *)lock, 1, SRWLOCK_FUTEX_BITSET_EXCLUSIVE );
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
static NTSTATUS fast_try_acquire_srw_exclusive( RTL_SRWLOCK *lock )
|
|
|
|
{
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS fast_acquire_srw_exclusive( RTL_SRWLOCK *lock )
|
|
|
|
{
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS fast_try_acquire_srw_shared( RTL_SRWLOCK *lock )
|
|
|
|
{
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS fast_acquire_srw_shared( RTL_SRWLOCK *lock )
|
|
|
|
{
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS fast_release_srw_exclusive( RTL_SRWLOCK *lock )
|
|
|
|
{
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS fast_release_srw_shared( RTL_SRWLOCK *lock )
|
|
|
|
{
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2014-01-11 02:18:10 +01:00
|
|
|
|
|
|
|
/* SRW locks implementation
|
|
|
|
*
|
|
|
|
* The memory layout used by the lock is:
|
|
|
|
*
|
|
|
|
* 32 31 16 0
|
|
|
|
* ________________ ________________
|
|
|
|
* | X| #exclusive | #shared |
|
|
|
|
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
|
|
* Since there is no space left for a separate counter of shared access
|
|
|
|
* threads inside the locked section the #shared field is used for multiple
|
|
|
|
* purposes. The following table lists all possible states the lock can be
|
|
|
|
* in, notation: [X, #exclusive, #shared]:
|
|
|
|
*
|
2016-08-02 00:10:09 +02:00
|
|
|
* [0, 0, N] -> locked by N shared access threads, if N=0 it's unlocked
|
2014-01-11 02:18:10 +01:00
|
|
|
* [0, >=1, >=1] -> threads are requesting exclusive locks, but there are
|
|
|
|
* still shared access threads inside. #shared should not be incremented
|
|
|
|
* anymore!
|
|
|
|
* [1, >=1, >=0] -> lock is owned by an exclusive thread and the #shared
|
|
|
|
* counter can be used again to count the number of threads waiting in the
|
|
|
|
* queue for shared access.
|
|
|
|
*
|
|
|
|
* the following states are invalid and will never occur:
|
|
|
|
* [0, >=1, 0], [1, 0, >=0]
|
|
|
|
*
|
|
|
|
* The main problem arising from the fact that we have no separate counter
|
|
|
|
* of shared access threads inside the locked section is that in the state
|
|
|
|
* [0, >=1, >=1] above we cannot add additional waiting threads to the
|
|
|
|
* shared access queue - it wouldn't be possible to distinguish waiting
|
|
|
|
* threads and those that are still inside. To solve this problem the lock
|
2014-02-07 22:42:49 +01:00
|
|
|
* uses the following approach: a thread that isn't able to allocate a
|
2014-01-11 02:18:10 +01:00
|
|
|
* shared lock just uses the exclusive queue instead. As soon as the thread
|
2014-02-07 22:42:49 +01:00
|
|
|
* is woken up it is in the state [1, >=1, >=0]. In this state it's again
|
2014-01-11 02:18:10 +01:00
|
|
|
* possible to use the shared access queue. The thread atomically moves
|
2014-02-07 22:42:49 +01:00
|
|
|
* itself to the shared access queue and releases the exclusive lock, so
|
2014-01-11 02:18:10 +01:00
|
|
|
* that the "real" exclusive access threads have a chance. As soon as they
|
|
|
|
* are all ready the shared access threads are processed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define SRWLOCK_MASK_IN_EXCLUSIVE 0x80000000
|
|
|
|
#define SRWLOCK_MASK_EXCLUSIVE_QUEUE 0x7fff0000
|
|
|
|
#define SRWLOCK_MASK_SHARED_QUEUE 0x0000ffff
|
|
|
|
#define SRWLOCK_RES_EXCLUSIVE 0x00010000
|
|
|
|
#define SRWLOCK_RES_SHARED 0x00000001
|
|
|
|
|
|
|
|
#ifdef WORDS_BIGENDIAN
|
|
|
|
#define srwlock_key_exclusive(lock) (&lock->Ptr)
|
|
|
|
#define srwlock_key_shared(lock) ((void *)((char *)&lock->Ptr + 2))
|
|
|
|
#else
|
|
|
|
#define srwlock_key_exclusive(lock) ((void *)((char *)&lock->Ptr + 2))
|
|
|
|
#define srwlock_key_shared(lock) (&lock->Ptr)
|
|
|
|
#endif
|
|
|
|
|
2014-01-21 22:04:20 +01:00
|
|
|
static inline void srwlock_check_invalid( unsigned int val )
|
|
|
|
{
|
|
|
|
/* Throw exception if it's impossible to acquire/release this lock. */
|
|
|
|
if ((val & SRWLOCK_MASK_EXCLUSIVE_QUEUE) == SRWLOCK_MASK_EXCLUSIVE_QUEUE ||
|
|
|
|
(val & SRWLOCK_MASK_SHARED_QUEUE) == SRWLOCK_MASK_SHARED_QUEUE)
|
|
|
|
RtlRaiseStatus(STATUS_RESOURCE_NOT_OWNED);
|
|
|
|
}
|
|
|
|
|
2014-01-11 02:18:10 +01:00
|
|
|
static inline unsigned int srwlock_lock_exclusive( unsigned int *dest, int incr )
|
|
|
|
{
|
|
|
|
unsigned int val, tmp;
|
|
|
|
/* Atomically modifies the value of *dest by adding incr. If the shared
|
|
|
|
* queue is empty and there are threads waiting for exclusive access, then
|
|
|
|
* sets the mark SRWLOCK_MASK_IN_EXCLUSIVE to signal other threads that
|
2014-02-07 22:42:49 +01:00
|
|
|
* they are allowed again to use the shared queue counter. */
|
2014-01-11 02:18:10 +01:00
|
|
|
for (val = *dest;; val = tmp)
|
|
|
|
{
|
|
|
|
tmp = val + incr;
|
2014-01-21 22:04:20 +01:00
|
|
|
srwlock_check_invalid( tmp );
|
2014-01-11 02:18:10 +01:00
|
|
|
if ((tmp & SRWLOCK_MASK_EXCLUSIVE_QUEUE) && !(tmp & SRWLOCK_MASK_SHARED_QUEUE))
|
|
|
|
tmp |= SRWLOCK_MASK_IN_EXCLUSIVE;
|
|
|
|
if ((tmp = interlocked_cmpxchg( (int *)dest, tmp, val )) == val)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned int srwlock_unlock_exclusive( unsigned int *dest, int incr )
|
|
|
|
{
|
|
|
|
unsigned int val, tmp;
|
|
|
|
/* Atomically modifies the value of *dest by adding incr. If the queue of
|
|
|
|
* threads waiting for exclusive access is empty, then remove the
|
|
|
|
* SRWLOCK_MASK_IN_EXCLUSIVE flag (only the shared queue counter will
|
|
|
|
* remain). */
|
|
|
|
for (val = *dest;; val = tmp)
|
|
|
|
{
|
|
|
|
tmp = val + incr;
|
2014-01-21 22:04:20 +01:00
|
|
|
srwlock_check_invalid( tmp );
|
2014-01-11 02:18:10 +01:00
|
|
|
if (!(tmp & SRWLOCK_MASK_EXCLUSIVE_QUEUE))
|
|
|
|
tmp &= SRWLOCK_MASK_SHARED_QUEUE;
|
|
|
|
if ((tmp = interlocked_cmpxchg( (int *)dest, tmp, val )) == val)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void srwlock_leave_exclusive( RTL_SRWLOCK *lock, unsigned int val )
|
|
|
|
{
|
|
|
|
/* Used when a thread leaves an exclusive section. If there are other
|
2014-02-07 22:42:49 +01:00
|
|
|
* exclusive access threads they are processed first, followed by
|
2014-01-11 02:18:10 +01:00
|
|
|
* the shared waiters. */
|
|
|
|
if (val & SRWLOCK_MASK_EXCLUSIVE_QUEUE)
|
2018-10-26 11:27:11 +02:00
|
|
|
NtReleaseKeyedEvent( 0, srwlock_key_exclusive(lock), FALSE, NULL );
|
2014-01-11 02:18:10 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
val &= SRWLOCK_MASK_SHARED_QUEUE; /* remove SRWLOCK_MASK_IN_EXCLUSIVE */
|
|
|
|
while (val--)
|
2018-10-26 11:27:11 +02:00
|
|
|
NtReleaseKeyedEvent( 0, srwlock_key_shared(lock), FALSE, NULL );
|
2014-01-11 02:18:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void srwlock_leave_shared( RTL_SRWLOCK *lock, unsigned int val )
|
|
|
|
{
|
|
|
|
/* Wake up one exclusive thread as soon as the last shared access thread
|
|
|
|
* has left. */
|
|
|
|
if ((val & SRWLOCK_MASK_EXCLUSIVE_QUEUE) && !(val & SRWLOCK_MASK_SHARED_QUEUE))
|
2018-10-26 11:27:11 +02:00
|
|
|
NtReleaseKeyedEvent( 0, srwlock_key_exclusive(lock), FALSE, NULL );
|
2014-01-11 02:18:10 +01:00
|
|
|
}
|
|
|
|
|
2013-09-03 11:08:42 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* RtlInitializeSRWLock (NTDLL.@)
|
2014-01-11 02:18:10 +01:00
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Please note that SRWLocks do not keep track of the owner of a lock.
|
|
|
|
* It doesn't make any difference which thread for example unlocks an
|
|
|
|
* SRWLock (see corresponding tests). This implementation uses two
|
|
|
|
* keyed events (one for the exclusive waiters and one for the shared
|
|
|
|
* waiters) and is limited to 2^15-1 waiting threads.
|
2013-09-03 11:08:42 +02:00
|
|
|
*/
|
|
|
|
void WINAPI RtlInitializeSRWLock( RTL_SRWLOCK *lock )
|
|
|
|
{
|
|
|
|
lock->Ptr = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RtlAcquireSRWLockExclusive (NTDLL.@)
|
2014-01-11 02:18:10 +01:00
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Unlike RtlAcquireResourceExclusive this function doesn't allow
|
|
|
|
* nested calls from the same thread. "Upgrading" a shared access lock
|
|
|
|
* to an exclusive access lock also doesn't seem to be supported.
|
2013-09-03 11:08:42 +02:00
|
|
|
*/
|
|
|
|
void WINAPI RtlAcquireSRWLockExclusive( RTL_SRWLOCK *lock )
|
|
|
|
{
|
2019-06-10 17:07:53 +02:00
|
|
|
if (fast_acquire_srw_exclusive( lock ) != STATUS_NOT_IMPLEMENTED)
|
|
|
|
return;
|
|
|
|
|
2014-01-11 02:18:10 +01:00
|
|
|
if (srwlock_lock_exclusive( (unsigned int *)&lock->Ptr, SRWLOCK_RES_EXCLUSIVE ))
|
2018-10-26 11:27:11 +02:00
|
|
|
NtWaitForKeyedEvent( 0, srwlock_key_exclusive(lock), FALSE, NULL );
|
2013-09-03 11:08:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RtlAcquireSRWLockShared (NTDLL.@)
|
2014-01-21 22:18:10 +01:00
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Do not call this function recursively - it will only succeed when
|
|
|
|
* there are no threads waiting for an exclusive lock!
|
2013-09-03 11:08:42 +02:00
|
|
|
*/
|
|
|
|
void WINAPI RtlAcquireSRWLockShared( RTL_SRWLOCK *lock )
|
|
|
|
{
|
2014-01-11 02:18:10 +01:00
|
|
|
unsigned int val, tmp;
|
2019-06-10 17:07:53 +02:00
|
|
|
|
|
|
|
if (fast_acquire_srw_shared( lock ) != STATUS_NOT_IMPLEMENTED)
|
|
|
|
return;
|
|
|
|
|
2014-01-11 02:18:10 +01:00
|
|
|
/* Acquires a shared lock. If it's currently not possible to add elements to
|
|
|
|
* the shared queue, then request exclusive access instead. */
|
|
|
|
for (val = *(unsigned int *)&lock->Ptr;; val = tmp)
|
|
|
|
{
|
|
|
|
if ((val & SRWLOCK_MASK_EXCLUSIVE_QUEUE) && !(val & SRWLOCK_MASK_IN_EXCLUSIVE))
|
|
|
|
tmp = val + SRWLOCK_RES_EXCLUSIVE;
|
|
|
|
else
|
|
|
|
tmp = val + SRWLOCK_RES_SHARED;
|
|
|
|
if ((tmp = interlocked_cmpxchg( (int *)&lock->Ptr, tmp, val )) == val)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Drop exclusive access again and instead requeue for shared access. */
|
|
|
|
if ((val & SRWLOCK_MASK_EXCLUSIVE_QUEUE) && !(val & SRWLOCK_MASK_IN_EXCLUSIVE))
|
|
|
|
{
|
2018-10-26 11:27:11 +02:00
|
|
|
NtWaitForKeyedEvent( 0, srwlock_key_exclusive(lock), FALSE, NULL );
|
2014-01-11 02:18:10 +01:00
|
|
|
val = srwlock_unlock_exclusive( (unsigned int *)&lock->Ptr, (SRWLOCK_RES_SHARED
|
|
|
|
- SRWLOCK_RES_EXCLUSIVE) ) - SRWLOCK_RES_EXCLUSIVE;
|
|
|
|
srwlock_leave_exclusive( lock, val );
|
|
|
|
}
|
|
|
|
|
|
|
|
if (val & SRWLOCK_MASK_EXCLUSIVE_QUEUE)
|
2018-10-26 11:27:11 +02:00
|
|
|
NtWaitForKeyedEvent( 0, srwlock_key_shared(lock), FALSE, NULL );
|
2013-09-03 11:08:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RtlReleaseSRWLockExclusive (NTDLL.@)
|
|
|
|
*/
|
|
|
|
void WINAPI RtlReleaseSRWLockExclusive( RTL_SRWLOCK *lock )
|
|
|
|
{
|
2019-06-10 17:07:53 +02:00
|
|
|
if (fast_release_srw_exclusive( lock ) != STATUS_NOT_IMPLEMENTED)
|
|
|
|
return;
|
|
|
|
|
2014-01-11 02:18:10 +01:00
|
|
|
srwlock_leave_exclusive( lock, srwlock_unlock_exclusive( (unsigned int *)&lock->Ptr,
|
|
|
|
- SRWLOCK_RES_EXCLUSIVE ) - SRWLOCK_RES_EXCLUSIVE );
|
2013-09-03 11:08:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RtlReleaseSRWLockShared (NTDLL.@)
|
|
|
|
*/
|
|
|
|
void WINAPI RtlReleaseSRWLockShared( RTL_SRWLOCK *lock )
|
|
|
|
{
|
2019-06-10 17:07:53 +02:00
|
|
|
if (fast_release_srw_shared( lock ) != STATUS_NOT_IMPLEMENTED)
|
|
|
|
return;
|
|
|
|
|
2014-01-11 02:18:10 +01:00
|
|
|
srwlock_leave_shared( lock, srwlock_lock_exclusive( (unsigned int *)&lock->Ptr,
|
|
|
|
- SRWLOCK_RES_SHARED ) - SRWLOCK_RES_SHARED );
|
2013-09-03 11:08:42 +02:00
|
|
|
}
|
2014-01-05 03:48:34 +01:00
|
|
|
|
2014-01-21 22:18:10 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* RtlTryAcquireSRWLockExclusive (NTDLL.@)
|
|
|
|
*
|
|
|
|
* NOTES
|
2019-12-12 11:22:59 +01:00
|
|
|
* Similarly to AcquireSRWLockExclusive, recursive calls are not allowed
|
|
|
|
* and will fail with a FALSE return value.
|
2014-01-21 22:18:10 +01:00
|
|
|
*/
|
|
|
|
BOOLEAN WINAPI RtlTryAcquireSRWLockExclusive( RTL_SRWLOCK *lock )
|
|
|
|
{
|
2019-06-10 17:07:53 +02:00
|
|
|
NTSTATUS ret;
|
|
|
|
|
|
|
|
if ((ret = fast_try_acquire_srw_exclusive( lock )) != STATUS_NOT_IMPLEMENTED)
|
|
|
|
return (ret == STATUS_SUCCESS);
|
|
|
|
|
2014-01-21 22:18:10 +01:00
|
|
|
return interlocked_cmpxchg( (int *)&lock->Ptr, SRWLOCK_MASK_IN_EXCLUSIVE |
|
|
|
|
SRWLOCK_RES_EXCLUSIVE, 0 ) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RtlTryAcquireSRWLockShared (NTDLL.@)
|
|
|
|
*/
|
|
|
|
BOOLEAN WINAPI RtlTryAcquireSRWLockShared( RTL_SRWLOCK *lock )
|
|
|
|
{
|
|
|
|
unsigned int val, tmp;
|
2019-06-10 17:07:53 +02:00
|
|
|
NTSTATUS ret;
|
|
|
|
|
|
|
|
if ((ret = fast_try_acquire_srw_shared( lock )) != STATUS_NOT_IMPLEMENTED)
|
|
|
|
return (ret == STATUS_SUCCESS);
|
|
|
|
|
2014-01-21 22:18:10 +01:00
|
|
|
for (val = *(unsigned int *)&lock->Ptr;; val = tmp)
|
|
|
|
{
|
|
|
|
if (val & SRWLOCK_MASK_EXCLUSIVE_QUEUE)
|
|
|
|
return FALSE;
|
|
|
|
if ((tmp = interlocked_cmpxchg( (int *)&lock->Ptr, val + SRWLOCK_RES_SHARED, val )) == val)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-02-10 19:26:45 +01:00
|
|
|
#ifdef __linux__
|
|
|
|
static NTSTATUS fast_wait_cv( RTL_CONDITION_VARIABLE *variable, int val, const LARGE_INTEGER *timeout )
|
|
|
|
{
|
|
|
|
struct timespec timespec;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!use_futexes())
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
|
|
|
|
if (timeout && timeout->QuadPart != TIMEOUT_INFINITE)
|
|
|
|
{
|
|
|
|
timespec_from_timeout( ×pec, timeout );
|
|
|
|
ret = futex_wait( (int *)&variable->Ptr, val, ×pec );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = futex_wait( (int *)&variable->Ptr, val, NULL );
|
|
|
|
|
|
|
|
if (ret == -1 && errno == ETIMEDOUT)
|
|
|
|
return STATUS_TIMEOUT;
|
|
|
|
return STATUS_WAIT_0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS fast_wake_cv( RTL_CONDITION_VARIABLE *variable, int count )
|
|
|
|
{
|
|
|
|
if (!use_futexes()) return STATUS_NOT_IMPLEMENTED;
|
|
|
|
|
|
|
|
futex_wake( (int *)&variable->Ptr, count );
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static NTSTATUS fast_wait_cv( RTL_CONDITION_VARIABLE *variable, int val, const LARGE_INTEGER *timeout )
|
|
|
|
{
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS fast_wake_cv( RTL_CONDITION_VARIABLE *variable, int count )
|
|
|
|
{
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-01-05 03:48:34 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* RtlInitializeConditionVariable (NTDLL.@)
|
|
|
|
*
|
|
|
|
* Initializes the condition variable with NULL.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* variable [O] condition variable
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Nothing.
|
|
|
|
*/
|
|
|
|
void WINAPI RtlInitializeConditionVariable( RTL_CONDITION_VARIABLE *variable )
|
|
|
|
{
|
|
|
|
variable->Ptr = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RtlWakeConditionVariable (NTDLL.@)
|
|
|
|
*
|
|
|
|
* Wakes up one thread waiting on the condition variable.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* variable [I/O] condition variable to wake up.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Nothing.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* The calling thread does not have to own any lock in order to call
|
|
|
|
* this function.
|
|
|
|
*/
|
|
|
|
void WINAPI RtlWakeConditionVariable( RTL_CONDITION_VARIABLE *variable )
|
|
|
|
{
|
2019-02-07 19:39:46 +01:00
|
|
|
interlocked_xchg_add( (int *)&variable->Ptr, 1 );
|
2019-02-10 19:26:45 +01:00
|
|
|
if (fast_wake_cv( variable, 1 ) == STATUS_NOT_IMPLEMENTED)
|
|
|
|
RtlWakeAddressSingle( variable );
|
2014-01-05 03:48:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RtlWakeAllConditionVariable (NTDLL.@)
|
|
|
|
*
|
|
|
|
* See WakeConditionVariable, wakes up all waiting threads.
|
|
|
|
*/
|
|
|
|
void WINAPI RtlWakeAllConditionVariable( RTL_CONDITION_VARIABLE *variable )
|
|
|
|
{
|
2019-02-07 19:39:46 +01:00
|
|
|
interlocked_xchg_add( (int *)&variable->Ptr, 1 );
|
2019-02-10 19:26:45 +01:00
|
|
|
if (fast_wake_cv( variable, INT_MAX ) == STATUS_NOT_IMPLEMENTED)
|
|
|
|
RtlWakeAddressAll( variable );
|
2014-01-05 03:48:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RtlSleepConditionVariableCS (NTDLL.@)
|
|
|
|
*
|
|
|
|
* Atomically releases the critical section and suspends the thread,
|
|
|
|
* waiting for a Wake(All)ConditionVariable event. Afterwards it enters
|
|
|
|
* the critical section again and returns.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* variable [I/O] condition variable
|
|
|
|
* crit [I/O] critical section to leave temporarily
|
|
|
|
* timeout [I] timeout
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* see NtWaitForKeyedEvent for all possible return values.
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI RtlSleepConditionVariableCS( RTL_CONDITION_VARIABLE *variable, RTL_CRITICAL_SECTION *crit,
|
|
|
|
const LARGE_INTEGER *timeout )
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
2019-02-07 19:39:46 +01:00
|
|
|
int val = *(int *)&variable->Ptr;
|
|
|
|
|
2014-01-05 03:48:34 +01:00
|
|
|
RtlLeaveCriticalSection( crit );
|
|
|
|
|
2019-02-10 19:26:45 +01:00
|
|
|
if ((status = fast_wait_cv( variable, val, timeout )) == STATUS_NOT_IMPLEMENTED)
|
|
|
|
status = RtlWaitOnAddress( &variable->Ptr, &val, sizeof(int), timeout );
|
2014-01-05 03:48:34 +01:00
|
|
|
|
|
|
|
RtlEnterCriticalSection( crit );
|
2019-02-07 19:39:46 +01:00
|
|
|
|
2014-01-05 03:48:34 +01:00
|
|
|
return status;
|
|
|
|
}
|
2014-01-22 01:05:15 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RtlSleepConditionVariableSRW (NTDLL.@)
|
|
|
|
*
|
|
|
|
* Atomically releases the SRWLock and suspends the thread,
|
|
|
|
* waiting for a Wake(All)ConditionVariable event. Afterwards it enters
|
|
|
|
* the SRWLock again with the same access rights and returns.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* variable [I/O] condition variable
|
|
|
|
* lock [I/O] SRWLock to leave temporarily
|
|
|
|
* timeout [I] timeout
|
|
|
|
* flags [I] type of the current lock (exclusive / shared)
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* see NtWaitForKeyedEvent for all possible return values.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* the behaviour is undefined if the thread doesn't own the lock.
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI RtlSleepConditionVariableSRW( RTL_CONDITION_VARIABLE *variable, RTL_SRWLOCK *lock,
|
|
|
|
const LARGE_INTEGER *timeout, ULONG flags )
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
2019-02-07 19:39:46 +01:00
|
|
|
int val = *(int *)&variable->Ptr;
|
2014-01-22 01:05:15 +01:00
|
|
|
|
|
|
|
if (flags & RTL_CONDITION_VARIABLE_LOCKMODE_SHARED)
|
|
|
|
RtlReleaseSRWLockShared( lock );
|
|
|
|
else
|
|
|
|
RtlReleaseSRWLockExclusive( lock );
|
|
|
|
|
2019-02-10 19:26:45 +01:00
|
|
|
if ((status = fast_wait_cv( variable, val, timeout )) == STATUS_NOT_IMPLEMENTED)
|
|
|
|
status = RtlWaitOnAddress( &variable->Ptr, &val, sizeof(int), timeout );
|
2014-01-22 01:05:15 +01:00
|
|
|
|
|
|
|
if (flags & RTL_CONDITION_VARIABLE_LOCKMODE_SHARED)
|
|
|
|
RtlAcquireSRWLockShared( lock );
|
|
|
|
else
|
|
|
|
RtlAcquireSRWLockExclusive( lock );
|
|
|
|
return status;
|
|
|
|
}
|
2018-10-26 08:50:14 +02:00
|
|
|
|
2018-12-01 02:03:57 +01:00
|
|
|
static RTL_CRITICAL_SECTION addr_section;
|
|
|
|
static RTL_CRITICAL_SECTION_DEBUG addr_section_debug =
|
|
|
|
{
|
|
|
|
0, 0, &addr_section,
|
|
|
|
{ &addr_section_debug.ProcessLocksList, &addr_section_debug.ProcessLocksList },
|
|
|
|
0, 0, { (DWORD_PTR)(__FILE__ ": addr_section") }
|
|
|
|
};
|
|
|
|
static RTL_CRITICAL_SECTION addr_section = { &addr_section_debug, -1, 0, 0, 0, 0 };
|
|
|
|
|
2018-12-01 02:03:56 +01:00
|
|
|
static BOOL compare_addr( const void *addr, const void *cmp, SIZE_T size )
|
2018-10-26 08:50:14 +02:00
|
|
|
{
|
|
|
|
switch (size)
|
|
|
|
{
|
|
|
|
case 1:
|
2018-12-01 02:03:56 +01:00
|
|
|
return (*(const UCHAR *)addr == *(const UCHAR *)cmp);
|
2018-10-26 08:50:14 +02:00
|
|
|
case 2:
|
2018-12-01 02:03:56 +01:00
|
|
|
return (*(const USHORT *)addr == *(const USHORT *)cmp);
|
2018-10-26 08:50:14 +02:00
|
|
|
case 4:
|
2018-12-01 02:03:56 +01:00
|
|
|
return (*(const ULONG *)addr == *(const ULONG *)cmp);
|
2018-10-26 08:50:14 +02:00
|
|
|
case 8:
|
2018-12-01 02:03:56 +01:00
|
|
|
return (*(const ULONG64 *)addr == *(const ULONG64 *)cmp);
|
2018-10-26 08:50:14 +02:00
|
|
|
}
|
|
|
|
|
2018-12-01 02:03:56 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-02-06 03:21:07 +01:00
|
|
|
#ifdef __linux__
|
|
|
|
/* We can't map addresses to futex directly, because an application can wait on
|
|
|
|
* 8 bytes, and we can't pass all 8 as the compare value to futex(). Instead we
|
|
|
|
* map all addresses to a small fixed table of futexes. This may result in
|
|
|
|
* spurious wakes, but the application is already expected to handle those. */
|
|
|
|
|
|
|
|
static int addr_futex_table[256];
|
|
|
|
|
|
|
|
static inline int *hash_addr( const void *addr )
|
|
|
|
{
|
|
|
|
ULONG_PTR val = (ULONG_PTR)addr;
|
|
|
|
|
|
|
|
return &addr_futex_table[(val >> 2) & 255];
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline NTSTATUS fast_wait_addr( const void *addr, const void *cmp, SIZE_T size,
|
|
|
|
const LARGE_INTEGER *timeout )
|
|
|
|
{
|
|
|
|
int *futex;
|
|
|
|
int val;
|
|
|
|
struct timespec timespec;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!use_futexes())
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
|
|
|
|
futex = hash_addr( addr );
|
|
|
|
|
|
|
|
/* We must read the previous value of the futex before checking the value
|
|
|
|
* of the address being waited on. That way, if we receive a wake between
|
|
|
|
* now and waiting on the futex, we know that val will have changed.
|
|
|
|
* Use an atomic load so that memory accesses are ordered between this read
|
|
|
|
* and the increment below. */
|
|
|
|
val = interlocked_cmpxchg( futex, 0, 0 );
|
|
|
|
if (!compare_addr( addr, cmp, size ))
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
|
|
|
|
if (timeout)
|
|
|
|
{
|
2019-02-10 19:26:45 +01:00
|
|
|
timespec_from_timeout( ×pec, timeout );
|
2019-02-06 03:21:07 +01:00
|
|
|
ret = futex_wait( futex, val, ×pec );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = futex_wait( futex, val, NULL );
|
|
|
|
|
|
|
|
if (ret == -1 && errno == ETIMEDOUT)
|
|
|
|
return STATUS_TIMEOUT;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline NTSTATUS fast_wake_addr( const void *addr )
|
|
|
|
{
|
|
|
|
int *futex;
|
|
|
|
|
|
|
|
if (!use_futexes())
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
|
|
|
|
futex = hash_addr( addr );
|
|
|
|
|
|
|
|
interlocked_xchg_add( futex, 1 );
|
|
|
|
|
|
|
|
futex_wake( futex, INT_MAX );
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static inline NTSTATUS fast_wait_addr( const void *addr, const void *cmp, SIZE_T size,
|
|
|
|
const LARGE_INTEGER *timeout )
|
|
|
|
{
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline NTSTATUS fast_wake_addr( const void *addr )
|
|
|
|
{
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-12-01 02:03:56 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* RtlWaitOnAddress (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI RtlWaitOnAddress( const void *addr, const void *cmp, SIZE_T size,
|
|
|
|
const LARGE_INTEGER *timeout )
|
|
|
|
{
|
|
|
|
select_op_t select_op;
|
|
|
|
NTSTATUS ret;
|
|
|
|
int cookie;
|
|
|
|
BOOL user_apc = FALSE;
|
|
|
|
obj_handle_t apc_handle = 0;
|
|
|
|
apc_call_t call;
|
|
|
|
apc_result_t result;
|
|
|
|
timeout_t abs_timeout = timeout ? timeout->QuadPart : TIMEOUT_INFINITE;
|
2020-02-05 11:49:40 +01:00
|
|
|
sigset_t old_set;
|
2018-12-01 02:03:56 +01:00
|
|
|
|
|
|
|
if (size != 1 && size != 2 && size != 4 && size != 8)
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
|
2019-02-06 03:21:07 +01:00
|
|
|
if ((ret = fast_wait_addr( addr, cmp, size, timeout )) != STATUS_NOT_IMPLEMENTED)
|
|
|
|
return ret;
|
|
|
|
|
2018-12-01 02:03:56 +01:00
|
|
|
select_op.keyed_event.op = SELECT_KEYED_EVENT_WAIT;
|
|
|
|
select_op.keyed_event.handle = wine_server_obj_handle( keyed_event );
|
|
|
|
select_op.keyed_event.key = wine_server_client_ptr( addr );
|
|
|
|
|
|
|
|
memset( &result, 0, sizeof(result) );
|
|
|
|
|
2020-02-05 11:49:37 +01:00
|
|
|
do
|
2018-12-01 02:03:56 +01:00
|
|
|
{
|
2018-12-01 02:03:57 +01:00
|
|
|
RtlEnterCriticalSection( &addr_section );
|
2018-12-01 02:03:56 +01:00
|
|
|
if (!compare_addr( addr, cmp, size ))
|
2018-12-01 02:03:57 +01:00
|
|
|
{
|
|
|
|
RtlLeaveCriticalSection( &addr_section );
|
2018-12-01 02:03:56 +01:00
|
|
|
return STATUS_SUCCESS;
|
2018-12-01 02:03:57 +01:00
|
|
|
}
|
2018-12-01 02:03:56 +01:00
|
|
|
|
2020-02-05 11:49:40 +01:00
|
|
|
pthread_sigmask( SIG_BLOCK, &server_block_set, &old_set );
|
2020-02-05 11:49:39 +01:00
|
|
|
for (;;)
|
2018-12-01 02:03:56 +01:00
|
|
|
{
|
2020-02-05 11:49:39 +01:00
|
|
|
SERVER_START_REQ( select )
|
|
|
|
{
|
|
|
|
req->flags = SELECT_INTERRUPTIBLE;
|
|
|
|
req->cookie = wine_server_client_ptr( &cookie );
|
|
|
|
req->prev_apc = apc_handle;
|
|
|
|
req->timeout = abs_timeout;
|
|
|
|
wine_server_add_data( req, &result, sizeof(result) );
|
|
|
|
wine_server_add_data( req, &select_op, sizeof(select_op.keyed_event) );
|
2020-02-05 11:49:40 +01:00
|
|
|
ret = server_call_unlocked( req );
|
2020-02-05 11:49:39 +01:00
|
|
|
abs_timeout = reply->timeout;
|
|
|
|
apc_handle = reply->apc_handle;
|
|
|
|
call = reply->call;
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
|
|
|
if (ret != STATUS_KERNEL_APC) break;
|
|
|
|
invoke_apc( &call, &result );
|
2018-12-01 02:03:56 +01:00
|
|
|
}
|
2020-02-05 11:49:40 +01:00
|
|
|
pthread_sigmask( SIG_SETMASK, &old_set, NULL );
|
2018-12-01 02:03:57 +01:00
|
|
|
|
|
|
|
RtlLeaveCriticalSection( &addr_section );
|
|
|
|
|
2020-02-05 11:49:38 +01:00
|
|
|
if (ret == STATUS_USER_APC)
|
2018-12-01 02:03:56 +01:00
|
|
|
{
|
2020-02-05 11:49:38 +01:00
|
|
|
invoke_apc( &call, &result );
|
2018-12-01 02:03:56 +01:00
|
|
|
/* if we ran a user apc we have to check once more if additional apcs are queued,
|
|
|
|
* but we don't want to wait */
|
|
|
|
abs_timeout = 0;
|
|
|
|
user_apc = TRUE;
|
|
|
|
}
|
2020-02-05 11:49:37 +01:00
|
|
|
|
|
|
|
if (ret == STATUS_PENDING) ret = wait_select_reply( &cookie );
|
2018-12-01 02:03:56 +01:00
|
|
|
}
|
2020-02-05 11:49:37 +01:00
|
|
|
while (ret == STATUS_USER_APC || ret == STATUS_KERNEL_APC);
|
2018-12-01 02:03:56 +01:00
|
|
|
|
|
|
|
if (ret == STATUS_TIMEOUT && user_apc) ret = STATUS_USER_APC;
|
|
|
|
|
|
|
|
return ret;
|
2018-10-26 08:50:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RtlWakeAddressAll (NTDLL.@)
|
|
|
|
*/
|
|
|
|
void WINAPI RtlWakeAddressAll( const void *addr )
|
|
|
|
{
|
2019-02-06 03:21:07 +01:00
|
|
|
if (fast_wake_addr( addr ) != STATUS_NOT_IMPLEMENTED)
|
|
|
|
return;
|
|
|
|
|
2018-12-01 02:03:57 +01:00
|
|
|
RtlEnterCriticalSection( &addr_section );
|
2018-10-26 11:27:11 +02:00
|
|
|
while (NtReleaseKeyedEvent( 0, addr, 0, &zero_timeout ) == STATUS_SUCCESS) {}
|
2018-12-01 02:03:57 +01:00
|
|
|
RtlLeaveCriticalSection( &addr_section );
|
2018-10-26 08:50:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RtlWakeAddressSingle (NTDLL.@)
|
|
|
|
*/
|
|
|
|
void WINAPI RtlWakeAddressSingle( const void *addr )
|
|
|
|
{
|
2019-02-06 03:21:07 +01:00
|
|
|
if (fast_wake_addr( addr ) != STATUS_NOT_IMPLEMENTED)
|
|
|
|
return;
|
|
|
|
|
2018-12-01 02:03:57 +01:00
|
|
|
RtlEnterCriticalSection( &addr_section );
|
2018-10-26 11:27:11 +02:00
|
|
|
NtReleaseKeyedEvent( 0, addr, 0, &zero_timeout );
|
2018-12-01 02:03:57 +01:00
|
|
|
RtlLeaveCriticalSection( &addr_section );
|
2018-10-26 08:50:14 +02:00
|
|
|
}
|