diff --git a/src/data.c b/src/data.c index 050eeb47d..b950bae03 100644 --- a/src/data.c +++ b/src/data.c @@ -155,10 +155,12 @@ _dispatch_data_destroy_buffer(const void* buffer, size_t size, free((void*)buffer); } else if (destructor == DISPATCH_DATA_DESTRUCTOR_NONE) { // do nothing +#if HAVE_MACH } else if (destructor == DISPATCH_DATA_DESTRUCTOR_VM_DEALLOCATE) { mach_vm_size_t vm_size = size; mach_vm_address_t vm_addr = (uintptr_t)buffer; mach_vm_deallocate(mach_task_self(), vm_addr, vm_size); +#endif } else { if (!queue) { queue = dispatch_get_global_queue( diff --git a/src/init.c b/src/init.c index e204e7d10..e18dbe732 100644 --- a/src/init.c +++ b/src/init.c @@ -580,12 +580,14 @@ _dispatch_bug_client(const char* msg) _dispatch_bug_log("BUG in libdispatch client: %s", msg); } +#if HAVE_MACH void _dispatch_bug_mach_client(const char* msg, mach_msg_return_t kr) { _dispatch_bug_log("BUG in libdispatch client: %s %s - 0x%x", msg, mach_error_string(kr), kr); } +#endif void _dispatch_bug_kevent_client(const char* msg, const char* filter, diff --git a/src/queue.c b/src/queue.c index 1670783d3..9fb419f90 100644 --- a/src/queue.c +++ b/src/queue.c @@ -553,7 +553,7 @@ dispatch_assert_queue(dispatch_queue_t dq) if (unlikely(_dq_state_drain_pended(dq_state))) { goto fail; } - if (likely(_dq_state_drain_owner(dq_state) == _dispatch_thread_port())) { + if (likely(_dq_state_drain_owner(dq_state) == _dispatch_tid_self())) { return; } if (likely(dq->dq_width > 1)) { @@ -580,7 +580,7 @@ dispatch_assert_queue_not(dispatch_queue_t dq) if (_dq_state_drain_pended(dq_state)) { return; } - if (likely(_dq_state_drain_owner(dq_state) != _dispatch_thread_port())) { + if (likely(_dq_state_drain_owner(dq_state) != _dispatch_tid_self())) { if (likely(dq->dq_width == 1)) { // we can look at the width: if it is changing while we read it, // it means that a barrier is running on `dq` concurrently, which @@ -1602,7 +1602,7 @@ _dispatch_queue_resume(dispatch_queue_t dq, bool activate) DISPATCH_QUEUE_WIDTH_FULL_BIT) { value = full_width; value &= ~DISPATCH_QUEUE_DIRTY; - value |= _dispatch_thread_port(); + value |= _dispatch_tid_self(); } } } @@ -2334,7 +2334,7 @@ _dispatch_queue_is_exclusively_owned_by_current_thread_4IOHID( DISPATCH_CLIENT_CRASH(dq->dq_width, "Invalid queue type"); } uint64_t dq_state = os_atomic_load2o(dq, dq_state, relaxed); - return _dq_state_drain_locked_by(dq_state, _dispatch_thread_port()); + return _dq_state_drain_locked_by(dq_state, _dispatch_tid_self()); } #endif @@ -2471,7 +2471,7 @@ _dispatch_set_priority_and_mach_voucher_slow(pthread_priority_t pp, pflags |= _PTHREAD_SET_SELF_QOS_FLAG; } if (unlikely(DISPATCH_QUEUE_DRAIN_OWNER(&_dispatch_mgr_q) == - _dispatch_thread_port())) { + _dispatch_tid_self())) { DISPATCH_INTERNAL_CRASH(pp, "Changing the QoS while on the manager queue"); } @@ -2775,7 +2775,7 @@ _dispatch_block_invoke_direct(const struct dispatch_block_private_data_s *dbcpd) v = dbpd->dbpd_voucher; } ov = _dispatch_adopt_priority_and_set_voucher(p, v, adopt_flags); - dbpd->dbpd_thread = _dispatch_thread_port(); + dbpd->dbpd_thread = _dispatch_tid_self(); _dispatch_client_callout(dbpd->dbpd_block, _dispatch_Block_invoke(dbpd->dbpd_block)); _dispatch_reset_priority_and_voucher(op, ov); @@ -3125,7 +3125,7 @@ _dispatch_async_redirect_invoke(dispatch_continuation_t dc, old_dp = _dispatch_set_defaultpriority(dq->dq_priority, &dp); op = dq->dq_override; if (op > (dp & _PTHREAD_PRIORITY_QOS_CLASS_MASK)) { - _dispatch_wqthread_override_start(_dispatch_thread_port(), op); + _dispatch_wqthread_override_start(_dispatch_tid_self(), op); // Ensure that the root queue sees that this thread was overridden. _dispatch_set_defaultpriority_override(); } @@ -3545,7 +3545,7 @@ _dispatch_barrier_sync_f_slow(dispatch_queue_t dq, void *ctxt, _dispatch_introspection_barrier_sync_begin(dq, func); } #endif - uint32_t th_self = _dispatch_thread_port(); + uint32_t th_self = _dispatch_tid_self(); struct dispatch_continuation_s dbss = { .dc_flags = DISPATCH_OBJ_BARRIER_BIT | DISPATCH_OBJ_SYNC_SLOW_BIT, .dc_func = _dispatch_barrier_sync_f_slow_invoke, @@ -3711,7 +3711,7 @@ _dispatch_non_barrier_complete(dispatch_queue_t dq) DISPATCH_QUEUE_WIDTH_FULL_BIT) { new_state = full_width; new_state &= ~DISPATCH_QUEUE_DIRTY; - new_state |= _dispatch_thread_port(); + new_state |= _dispatch_tid_self(); } } } @@ -3738,7 +3738,7 @@ _dispatch_sync_f_slow(dispatch_queue_t dq, void *ctxt, dispatch_function_t func, } dispatch_thread_event_s event; _dispatch_thread_event_init(&event); - uint32_t th_self = _dispatch_thread_port(); + uint32_t th_self = _dispatch_tid_self(); struct dispatch_continuation_s dc = { .dc_flags = DISPATCH_OBJ_SYNC_SLOW_BIT, #if DISPATCH_INTROSPECTION @@ -4438,7 +4438,7 @@ _dispatch_main_queue_drain(void) " after dispatch_main()"); } mach_port_t owner = DISPATCH_QUEUE_DRAIN_OWNER(dq); - if (slowpath(owner != _dispatch_thread_port())) { + if (slowpath(owner != _dispatch_tid_self())) { DISPATCH_CLIENT_CRASH(owner, "_dispatch_main_queue_callback_4CF called" " from the wrong thread"); } @@ -4663,7 +4663,7 @@ _dispatch_queue_drain_deferred_invoke(dispatch_queue_t dq, } if (dq) { - uint32_t self = _dispatch_thread_port(); + uint32_t self = _dispatch_tid_self(); os_atomic_rmw_loop2o(dq, dq_state, old_state, new_state, release,{ new_state = old_state; if (!_dq_state_drain_pended(old_state) || @@ -5094,7 +5094,7 @@ _dispatch_queue_class_wakeup(dispatch_queue_t dq, pthread_priority_t pp, uint64_t pending_barrier_width = (dq->dq_width - 1) * DISPATCH_QUEUE_WIDTH_INTERVAL; uint64_t xor_owner_and_set_full_width_and_in_barrier = - _dispatch_thread_port() | DISPATCH_QUEUE_WIDTH_FULL_BIT | + _dispatch_tid_self() | DISPATCH_QUEUE_WIDTH_FULL_BIT | DISPATCH_QUEUE_IN_BARRIER; #ifdef DLOCK_NOWAITERS_BIT diff --git a/src/shims/linux_stubs.c b/src/shims/linux_stubs.c index b209e6f10..fde934144 100644 --- a/src/shims/linux_stubs.c +++ b/src/shims/linux_stubs.c @@ -34,17 +34,6 @@ unsigned long _dispatch_runloop_queue_probe(dispatch_queue_t dq) { void _dispatch_runloop_queue_xref_dispose() { LINUX_PORT_ERROR(); } void _dispatch_runloop_queue_dispose() { LINUX_PORT_ERROR(); } -char* mach_error_string(mach_msg_return_t x) { - LINUX_PORT_ERROR(); -} -void mach_vm_deallocate() { LINUX_PORT_ERROR(); } - -mach_port_t pthread_mach_thread_np(void) { - return (pid_t)syscall(SYS_gettid); -} -mach_port_t mach_task_self(void) { - return (mach_port_t)pthread_self(); -} /* * Stubbed out static data diff --git a/src/shims/linux_stubs.h b/src/shims/linux_stubs.h index 7726e9073..6a70c0b11 100644 --- a/src/shims/linux_stubs.h +++ b/src/shims/linux_stubs.h @@ -62,8 +62,6 @@ typedef void (*dispatch_mach_handler_function_t)(void*, dispatch_mach_reason_t, typedef void (*dispatch_mach_msg_destructor_t)(void*); -mach_port_t mach_task_self(); - // Print a warning when an unported code path executes. #define LINUX_PORT_ERROR() do { printf("LINUX_PORT_ERROR_CALLED %s:%d: %s\n",__FILE__,__LINE__,__FUNCTION__); } while (0)