2021-03-17 22:32:41 -07:00
|
|
|
From 17e0fb2e0be8d53b485c96941faaa76d30d0c032 Mon Sep 17 00:00:00 2001
|
2020-12-08 18:56:56 -08:00
|
|
|
From: Zebediah Figura <z.figura12@gmail.com>
|
|
|
|
Date: Mon, 31 Aug 2020 23:03:34 -0500
|
2021-01-24 19:49:00 -08:00
|
|
|
Subject: [PATCH] ntdll: Implement thread-id alerts on top of Mach semaphores
|
|
|
|
on Mac.
|
2020-12-08 18:56:56 -08:00
|
|
|
|
|
|
|
Signed-off-by: Zebediah Figura <z.figura12@gmail.com>
|
|
|
|
---
|
|
|
|
dlls/ntdll/unix/sync.c | 44 ++++++++++++++++++++++++++++++++++
|
|
|
|
dlls/ntdll/unix/thread.c | 4 ++++
|
2021-03-05 19:24:30 -08:00
|
|
|
dlls/ntdll/unix/unix_private.h | 9 +++++++
|
|
|
|
3 files changed, 57 insertions(+)
|
2020-12-08 18:56:56 -08:00
|
|
|
|
|
|
|
diff --git a/dlls/ntdll/unix/sync.c b/dlls/ntdll/unix/sync.c
|
2021-03-05 19:24:30 -08:00
|
|
|
index f4f87ba5642..7d6423083e1 100644
|
2020-12-08 18:56:56 -08:00
|
|
|
--- a/dlls/ntdll/unix/sync.c
|
|
|
|
+++ b/dlls/ntdll/unix/sync.c
|
2021-03-05 19:24:30 -08:00
|
|
|
@@ -2301,6 +2301,10 @@ NTSTATUS WINAPI NtAlertThreadByThreadId( HANDLE tid )
|
2020-12-08 18:56:56 -08:00
|
|
|
if (teb->ClientId.UniqueThread == tid)
|
|
|
|
{
|
|
|
|
pthread_rwlock_unlock( &teb_list_lock );
|
|
|
|
+#ifdef __APPLE__
|
2021-01-24 19:49:00 -08:00
|
|
|
+ semaphore_signal( thread_data->tid_alert_sem );
|
2020-12-08 18:56:56 -08:00
|
|
|
+ return STATUS_SUCCESS;
|
|
|
|
+#else
|
|
|
|
#ifdef __linux__
|
|
|
|
if (use_futexes())
|
|
|
|
{
|
2021-03-05 19:24:30 -08:00
|
|
|
@@ -2312,6 +2316,7 @@ NTSTATUS WINAPI NtAlertThreadByThreadId( HANDLE tid )
|
2020-12-08 18:56:56 -08:00
|
|
|
#endif
|
|
|
|
NtSetEvent( thread_data->tid_alert_event, NULL );
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
+#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-05 19:24:30 -08:00
|
|
|
@@ -2349,6 +2354,44 @@ NTSTATUS WINAPI NtWaitForAlertByThreadId( const void *address, const LARGE_INTEG
|
2020-12-08 18:56:56 -08:00
|
|
|
{
|
|
|
|
TRACE( "%p %s\n", address, debugstr_timeout( timeout ) );
|
|
|
|
|
|
|
|
+#ifdef __APPLE__
|
|
|
|
+ {
|
|
|
|
+ semaphore_t sem = ntdll_get_thread_data()->tid_alert_sem;
|
|
|
|
+ ULONGLONG end;
|
|
|
|
+ kern_return_t ret;
|
|
|
|
+
|
|
|
|
+ if (timeout)
|
|
|
|
+ {
|
|
|
|
+ if (timeout->QuadPart == TIMEOUT_INFINITE)
|
|
|
|
+ timeout = NULL;
|
|
|
|
+ else
|
|
|
|
+ end = get_absolute_timeout( timeout );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for (;;)
|
|
|
|
+ {
|
|
|
|
+ if (timeout)
|
|
|
|
+ {
|
|
|
|
+ LONGLONG timeleft = update_timeout( end );
|
|
|
|
+ mach_timespec_t timespec;
|
|
|
|
+
|
|
|
|
+ timespec.tv_sec = timeleft / (ULONGLONG)TICKSPERSEC;
|
|
|
|
+ timespec.tv_nsec = (timeleft % TICKSPERSEC) * 100;
|
2021-01-24 19:49:00 -08:00
|
|
|
+ ret = semaphore_timedwait( sem, timespec );
|
2020-12-08 18:56:56 -08:00
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ ret = semaphore_wait( sem );
|
|
|
|
+
|
|
|
|
+ switch (ret)
|
|
|
|
+ {
|
|
|
|
+ case KERN_SUCCESS: return STATUS_ALERTED;
|
|
|
|
+ case KERN_ABORTED: continue;
|
|
|
|
+ case KERN_OPERATION_TIMED_OUT: return STATUS_TIMEOUT;
|
|
|
|
+ default: return STATUS_INVALID_HANDLE;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+#else
|
|
|
|
#ifdef __linux__
|
|
|
|
if (use_futexes())
|
|
|
|
{
|
2021-03-05 19:24:30 -08:00
|
|
|
@@ -2384,6 +2427,7 @@ NTSTATUS WINAPI NtWaitForAlertByThreadId( const void *address, const LARGE_INTEG
|
2020-12-08 18:56:56 -08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return NtWaitForSingleObject( ntdll_get_thread_data()->tid_alert_event, FALSE, timeout );
|
|
|
|
+#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
diff --git a/dlls/ntdll/unix/thread.c b/dlls/ntdll/unix/thread.c
|
2021-03-05 19:24:30 -08:00
|
|
|
index 87f5a97131e..e97a9657f03 100644
|
2020-12-08 18:56:56 -08:00
|
|
|
--- a/dlls/ntdll/unix/thread.c
|
|
|
|
+++ b/dlls/ntdll/unix/thread.c
|
|
|
|
@@ -252,7 +252,11 @@ NTSTATUS WINAPI NtCreateThreadEx( HANDLE *handle, ACCESS_MASK access, OBJECT_ATT
|
|
|
|
thread_data->start = start;
|
|
|
|
thread_data->param = param;
|
|
|
|
|
|
|
|
+#ifdef __APPLE__
|
|
|
|
+ semaphore_create( mach_task_self(), &thread_data->tid_alert_sem, SYNC_POLICY_FIFO, 0 );
|
|
|
|
+#else
|
|
|
|
NtCreateEvent( &thread_data->tid_alert_event, EVENT_ALL_ACCESS, NULL, SynchronizationEvent, FALSE );
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
pthread_attr_init( &pthread_attr );
|
|
|
|
pthread_attr_setstack( &pthread_attr, teb->DeallocationStack,
|
|
|
|
diff --git a/dlls/ntdll/unix/unix_private.h b/dlls/ntdll/unix/unix_private.h
|
2021-03-17 22:32:41 -07:00
|
|
|
index 2da19c6844f..3c4d5dd8a2b 100644
|
2020-12-08 18:56:56 -08:00
|
|
|
--- a/dlls/ntdll/unix/unix_private.h
|
|
|
|
+++ b/dlls/ntdll/unix/unix_private.h
|
2021-03-05 19:24:30 -08:00
|
|
|
@@ -27,6 +27,11 @@
|
2021-02-16 14:56:43 -08:00
|
|
|
#include "wine/server.h"
|
2021-01-24 19:49:00 -08:00
|
|
|
#include "wine/list.h"
|
|
|
|
|
|
|
|
+#ifdef __APPLE__
|
2021-03-05 19:24:30 -08:00
|
|
|
+# include <mach/mach.h>
|
2021-01-24 19:49:00 -08:00
|
|
|
+# include <mach/semaphore.h>
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
#ifdef __i386__
|
|
|
|
static const enum cpu_type client_cpu = CPU_x86;
|
2021-03-17 22:32:41 -07:00
|
|
|
static const WORD current_machine = IMAGE_FILE_MACHINE_I386;
|
|
|
|
@@ -62,10 +67,14 @@ struct ntdll_thread_data
|
2020-12-08 18:56:56 -08:00
|
|
|
struct list entry; /* entry in TEB list */
|
|
|
|
PRTL_THREAD_START_ROUTINE start; /* thread entry point */
|
|
|
|
void *param; /* thread entry point parameter */
|
|
|
|
+#ifdef __APPLE__
|
|
|
|
+ semaphore_t tid_alert_sem; /* Mach semaphore for thread-id alerts */
|
|
|
|
+#else
|
|
|
|
#ifdef __linux__
|
|
|
|
int tid_alert_futex; /* futex for thread-id alerts */
|
|
|
|
#endif
|
|
|
|
HANDLE tid_alert_event; /* event for thread-id alerts */
|
|
|
|
+#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
C_ASSERT( sizeof(struct ntdll_thread_data) <= sizeof(((TEB *)0)->GdiTebBatch) );
|
|
|
|
--
|
2021-03-05 19:24:30 -08:00
|
|
|
2.20.1
|
2020-12-08 18:56:56 -08:00
|
|
|
|