Skip to content

Commit 31f1d2b

Browse files
dgrove-ossdas
authored andcommitted
Eliminate dummy mach-specific functions from linux_stubs
Get rid of mach_error_string, mach_vm_deallocate, and mach_test_self by adding missing #if HAVE_MACH in the last couple places it was missing. Avoid needing pthread_mach_thread_np by replacing uses of the _dispatch_thread_port() macro with _dispatch_tid_self() Signed-off-by: Daniel A. Steffen <[email protected]>
1 parent 7518545 commit 31f1d2b

File tree

5 files changed

+17
-26
lines changed

5 files changed

+17
-26
lines changed

src/data.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,12 @@ _dispatch_data_destroy_buffer(const void* buffer, size_t size,
155155
free((void*)buffer);
156156
} else if (destructor == DISPATCH_DATA_DESTRUCTOR_NONE) {
157157
// do nothing
158+
#if HAVE_MACH
158159
} else if (destructor == DISPATCH_DATA_DESTRUCTOR_VM_DEALLOCATE) {
159160
mach_vm_size_t vm_size = size;
160161
mach_vm_address_t vm_addr = (uintptr_t)buffer;
161162
mach_vm_deallocate(mach_task_self(), vm_addr, vm_size);
163+
#endif
162164
} else {
163165
if (!queue) {
164166
queue = dispatch_get_global_queue(

src/init.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,12 +580,14 @@ _dispatch_bug_client(const char* msg)
580580
_dispatch_bug_log("BUG in libdispatch client: %s", msg);
581581
}
582582

583+
#if HAVE_MACH
583584
void
584585
_dispatch_bug_mach_client(const char* msg, mach_msg_return_t kr)
585586
{
586587
_dispatch_bug_log("BUG in libdispatch client: %s %s - 0x%x", msg,
587588
mach_error_string(kr), kr);
588589
}
590+
#endif
589591

590592
void
591593
_dispatch_bug_kevent_client(const char* msg, const char* filter,

src/queue.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ dispatch_assert_queue(dispatch_queue_t dq)
553553
if (unlikely(_dq_state_drain_pended(dq_state))) {
554554
goto fail;
555555
}
556-
if (likely(_dq_state_drain_owner(dq_state) == _dispatch_thread_port())) {
556+
if (likely(_dq_state_drain_owner(dq_state) == _dispatch_tid_self())) {
557557
return;
558558
}
559559
if (likely(dq->dq_width > 1)) {
@@ -580,7 +580,7 @@ dispatch_assert_queue_not(dispatch_queue_t dq)
580580
if (_dq_state_drain_pended(dq_state)) {
581581
return;
582582
}
583-
if (likely(_dq_state_drain_owner(dq_state) != _dispatch_thread_port())) {
583+
if (likely(_dq_state_drain_owner(dq_state) != _dispatch_tid_self())) {
584584
if (likely(dq->dq_width == 1)) {
585585
// we can look at the width: if it is changing while we read it,
586586
// it means that a barrier is running on `dq` concurrently, which
@@ -1602,7 +1602,7 @@ _dispatch_queue_resume(dispatch_queue_t dq, bool activate)
16021602
DISPATCH_QUEUE_WIDTH_FULL_BIT) {
16031603
value = full_width;
16041604
value &= ~DISPATCH_QUEUE_DIRTY;
1605-
value |= _dispatch_thread_port();
1605+
value |= _dispatch_tid_self();
16061606
}
16071607
}
16081608
}
@@ -2334,7 +2334,7 @@ _dispatch_queue_is_exclusively_owned_by_current_thread_4IOHID(
23342334
DISPATCH_CLIENT_CRASH(dq->dq_width, "Invalid queue type");
23352335
}
23362336
uint64_t dq_state = os_atomic_load2o(dq, dq_state, relaxed);
2337-
return _dq_state_drain_locked_by(dq_state, _dispatch_thread_port());
2337+
return _dq_state_drain_locked_by(dq_state, _dispatch_tid_self());
23382338
}
23392339
#endif
23402340

@@ -2471,7 +2471,7 @@ _dispatch_set_priority_and_mach_voucher_slow(pthread_priority_t pp,
24712471
pflags |= _PTHREAD_SET_SELF_QOS_FLAG;
24722472
}
24732473
if (unlikely(DISPATCH_QUEUE_DRAIN_OWNER(&_dispatch_mgr_q) ==
2474-
_dispatch_thread_port())) {
2474+
_dispatch_tid_self())) {
24752475
DISPATCH_INTERNAL_CRASH(pp,
24762476
"Changing the QoS while on the manager queue");
24772477
}
@@ -2773,7 +2773,7 @@ _dispatch_block_invoke_direct(const struct dispatch_block_private_data_s *dbcpd)
27732773
v = dbpd->dbpd_voucher;
27742774
}
27752775
ov = _dispatch_adopt_priority_and_set_voucher(p, v, adopt_flags);
2776-
dbpd->dbpd_thread = _dispatch_thread_port();
2776+
dbpd->dbpd_thread = _dispatch_tid_self();
27772777
_dispatch_client_callout(dbpd->dbpd_block,
27782778
_dispatch_Block_invoke(dbpd->dbpd_block));
27792779
_dispatch_reset_priority_and_voucher(op, ov);
@@ -3123,7 +3123,7 @@ _dispatch_async_redirect_invoke(dispatch_continuation_t dc,
31233123
old_dp = _dispatch_set_defaultpriority(dq->dq_priority, &dp);
31243124
op = dq->dq_override;
31253125
if (op > (dp & _PTHREAD_PRIORITY_QOS_CLASS_MASK)) {
3126-
_dispatch_wqthread_override_start(_dispatch_thread_port(), op);
3126+
_dispatch_wqthread_override_start(_dispatch_tid_self(), op);
31273127
// Ensure that the root queue sees that this thread was overridden.
31283128
_dispatch_set_defaultpriority_override();
31293129
}
@@ -3543,7 +3543,7 @@ _dispatch_barrier_sync_f_slow(dispatch_queue_t dq, void *ctxt,
35433543
_dispatch_introspection_barrier_sync_begin(dq, func);
35443544
}
35453545
#endif
3546-
uint32_t th_self = _dispatch_thread_port();
3546+
uint32_t th_self = _dispatch_tid_self();
35473547
struct dispatch_continuation_s dbss = {
35483548
.dc_flags = DISPATCH_OBJ_BARRIER_BIT | DISPATCH_OBJ_SYNC_SLOW_BIT,
35493549
.dc_func = _dispatch_barrier_sync_f_slow_invoke,
@@ -3709,7 +3709,7 @@ _dispatch_non_barrier_complete(dispatch_queue_t dq)
37093709
DISPATCH_QUEUE_WIDTH_FULL_BIT) {
37103710
new_state = full_width;
37113711
new_state &= ~DISPATCH_QUEUE_DIRTY;
3712-
new_state |= _dispatch_thread_port();
3712+
new_state |= _dispatch_tid_self();
37133713
}
37143714
}
37153715
}
@@ -3736,7 +3736,7 @@ _dispatch_sync_f_slow(dispatch_queue_t dq, void *ctxt, dispatch_function_t func,
37363736
}
37373737
dispatch_thread_event_s event;
37383738
_dispatch_thread_event_init(&event);
3739-
uint32_t th_self = _dispatch_thread_port();
3739+
uint32_t th_self = _dispatch_tid_self();
37403740
struct dispatch_continuation_s dc = {
37413741
.dc_flags = DISPATCH_OBJ_SYNC_SLOW_BIT,
37423742
#if DISPATCH_INTROSPECTION
@@ -4430,7 +4430,7 @@ _dispatch_main_queue_drain(void)
44304430
" after dispatch_main()");
44314431
}
44324432
mach_port_t owner = DISPATCH_QUEUE_DRAIN_OWNER(dq);
4433-
if (slowpath(owner != _dispatch_thread_port())) {
4433+
if (slowpath(owner != _dispatch_tid_self())) {
44344434
DISPATCH_CLIENT_CRASH(owner, "_dispatch_main_queue_callback_4CF called"
44354435
" from the wrong thread");
44364436
}
@@ -4655,7 +4655,7 @@ _dispatch_queue_drain_deferred_invoke(dispatch_queue_t dq,
46554655
}
46564656

46574657
if (dq) {
4658-
uint32_t self = _dispatch_thread_port();
4658+
uint32_t self = _dispatch_tid_self();
46594659
os_atomic_rmw_loop2o(dq, dq_state, old_state, new_state, release,{
46604660
new_state = old_state;
46614661
if (!_dq_state_drain_pended(old_state) ||
@@ -5091,7 +5091,7 @@ _dispatch_queue_class_wakeup(dispatch_queue_t dq, pthread_priority_t pp,
50915091
uint64_t pending_barrier_width =
50925092
(dq->dq_width - 1) * DISPATCH_QUEUE_WIDTH_INTERVAL;
50935093
uint64_t xor_owner_and_set_full_width_and_in_barrier =
5094-
_dispatch_thread_port() | DISPATCH_QUEUE_WIDTH_FULL_BIT |
5094+
_dispatch_tid_self() | DISPATCH_QUEUE_WIDTH_FULL_BIT |
50955095
DISPATCH_QUEUE_IN_BARRIER;
50965096

50975097
#ifdef DLOCK_NOWAITERS_BIT

src/shims/linux_stubs.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,6 @@ unsigned long _dispatch_runloop_queue_probe(dispatch_queue_t dq) {
3939
void _dispatch_runloop_queue_xref_dispose() { LINUX_PORT_ERROR(); }
4040

4141
void _dispatch_runloop_queue_dispose() { LINUX_PORT_ERROR(); }
42-
char* mach_error_string(mach_msg_return_t x) {
43-
LINUX_PORT_ERROR();
44-
}
45-
void mach_vm_deallocate() { LINUX_PORT_ERROR(); }
46-
47-
mach_port_t pthread_mach_thread_np(void) {
48-
return (pid_t)syscall(SYS_gettid);
49-
}
50-
mach_port_t mach_task_self(void) {
51-
return (mach_port_t)pthread_self();
52-
}
5342

5443
/*
5544
* Stubbed out static data

src/shims/linux_stubs.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ typedef void (*dispatch_mach_handler_function_t)(void*, dispatch_mach_reason_t,
6262

6363
typedef void (*dispatch_mach_msg_destructor_t)(void*);
6464

65-
mach_port_t mach_task_self();
66-
6765
// Print a warning when an unported code path executes.
6866
#define LINUX_PORT_ERROR() do { printf("LINUX_PORT_ERROR_CALLED %s:%d: %s\n",__FILE__,__LINE__,__FUNCTION__); } while (0)
6967

0 commit comments

Comments
 (0)