Skip to content

Clang and linux portability fixes #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ AC_CHECK_HEADER(sys/event.h, [],
[PKG_CHECK_MODULES(KQUEUE, libkqueue)]
)

AC_CHECK_FUNCS([strlcpy getprogname], [],
[PKG_CHECK_MODULES(BSD_OVERLAY, libbsd-overlay,[
AC_DEFINE(HAVE_STRLCPY, 1, [])
AC_DEFINE(HAVE_GETPROGNAME, 1, [])
])], [#include <string.h>]
)

#
# Checks for header files.
#
Expand Down Expand Up @@ -238,7 +245,7 @@ AC_CHECK_DECLS([FD_COPY], [], [], [[#include <sys/select.h>]])
AC_CHECK_DECLS([SIGEMT], [], [], [[#include <signal.h>]])
AC_CHECK_DECLS([VQ_UPDATE, VQ_VERYLOWDISK], [], [], [[#include <sys/mount.h>]])
AC_CHECK_DECLS([program_invocation_short_name], [], [], [[#include <errno.h>]])
AC_CHECK_FUNCS([pthread_key_init_np pthread_main_np mach_absolute_time malloc_create_zone sysconf getprogname])
AC_CHECK_FUNCS([pthread_key_init_np pthread_main_np mach_absolute_time malloc_create_zone sysconf])

AC_CHECK_DECLS([POSIX_SPAWN_START_SUSPENDED],
[have_posix_spawn_start_suspended=true], [have_posix_spawn_start_suspended=false],
Expand Down
37 changes: 17 additions & 20 deletions os/linux_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
#define __OS_LINUX_BASE__

// #include <sys/event.h>
#include <sys/types.h>
#include <assert.h>
#include <pthread.h>
#include <syscall.h>
#include <unistd.h>
#include <stdint.h>

// marker for hacks we have made to make progress
#define __LINUX_PORT_HDD__ 1
Expand All @@ -30,11 +36,20 @@

typedef uint32_t mach_port_t;

#define MACH_PORT_NULL (0)
#define MACH_PORT_DEAD (-1)
static inline mach_port_t
pthread_mach_thread_np(pthread_t th)
{
assert(th == pthread_self());
return (pid_t)syscall(SYS_gettid);
}

#define MACH_PORT_NULL (0)
#define MACH_PORT_DEAD (-1)

#define EVFILT_MACHPORT (-8)

typedef struct mach_msg_header_t mach_msg_header_t;

typedef uint32_t mach_error_t;

typedef uint32_t mach_vm_size_t;
Expand All @@ -43,12 +58,6 @@ typedef uint32_t mach_msg_return_t;

typedef uintptr_t mach_vm_address_t;

typedef uint32_t dispatch_mach_msg_t;

typedef uint32_t dispatch_mach_t;

typedef uint32_t dispatch_mach_reason_t;

typedef uint32_t voucher_activity_mode_t;

typedef uint32_t voucher_activity_trace_id_t;
Expand All @@ -59,18 +68,6 @@ typedef uint32_t _voucher_activity_buffer_hook_t;;

typedef uint32_t voucher_activity_flag_t;

typedef struct
{
} mach_msg_header_t;


typedef void (*dispatch_mach_handler_function_t)(void*, dispatch_mach_reason_t,
dispatch_mach_msg_t, mach_error_t);

typedef void (*dispatch_mach_msg_destructor_t)(void*);

typedef uint32_t voucher_activity_mode_t;

struct voucher_offsets_s {
uint32_t vo_version;
};
Expand Down
4 changes: 3 additions & 1 deletion private/voucher_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ voucher_decrement_importance_count4CF(voucher_t voucher);
*/
#define DISPATCH_BLOCK_NO_VOUCHER (0x40)

#ifdef __BLOCKS__
/*!
* @function dispatch_block_create_with_voucher
*
Expand Down Expand Up @@ -335,6 +336,7 @@ dispatch_block_t
dispatch_block_create_with_voucher_and_qos_class(dispatch_block_flags_t flags,
voucher_t voucher, dispatch_qos_class_t qos_class,
int relative_priority, dispatch_block_t block);
#endif

/*!
* @group Voucher dispatch queue SPI
Expand Down Expand Up @@ -404,7 +406,6 @@ dispatch_queue_create_with_accounting_override_voucher(const char *label,

#ifdef __APPLE__
#include <mach/mach.h>
#endif

/*!
* @function voucher_create_with_mach_msg
Expand All @@ -428,6 +429,7 @@ OS_VOUCHER_EXPORT OS_OBJECT_RETURNS_RETAINED OS_WARN_RESULT OS_NOTHROW
voucher_t
voucher_create_with_mach_msg(mach_msg_header_t *msg);

#endif
__END_DECLS

#endif // __OS_VOUCHER_PRIVATE__
Expand Down
3 changes: 2 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ AM_CPPFLAGS=-I$(top_builddir) -I$(top_srcdir) \
-I$(top_srcdir)/private -I$(top_srcdir)/os

DISPATCH_CFLAGS=-Wall $(VISIBILITY_FLAGS) $(OMIT_LEAF_FP_FLAGS) \
$(MARCH_FLAGS) $(KQUEUE_CFLAGS)
$(MARCH_FLAGS) $(KQUEUE_CFLAGS) $(BSD_OVERLAY_CFLAGS)
AM_CFLAGS=$(DISPATCH_CFLAGS) $(CBLOCKS_FLAGS)
AM_OBJCFLAGS=$(DISPATCH_CFLAGS) $(CBLOCKS_FLAGS)
AM_CXXFLAGS=$(DISPATCH_CFLAGS) $(CXXBLOCKS_FLAGS)
AM_OBJCXXFLAGS=$(DISPATCH_CFLAGS) $(CXXBLOCKS_FLAGS)

libdispatch_la_LIBADD = $(KQUEUE_LIBS) $(BSD_OVERLAY_LIBS)
libdispatch_la_LDFLAGS=-avoid-version

if HAVE_DARWIN_LD
Expand Down
2 changes: 1 addition & 1 deletion src/allocator.c
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ _dispatch_malloc_init(void)
malloc_set_zone_name(_dispatch_ccache_zone, "DispatchContinuations");
}
#else
static inline void _dispatch_malloc_init(void) {}
#define _dispatch_malloc_init() ((void)0)
#endif // DISPATCH_USE_MALLOCZONE

static dispatch_continuation_t
Expand Down
6 changes: 5 additions & 1 deletion src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ DISPATCH_VTABLE_INSTANCE(source,
.do_debug = _dispatch_source_debug,
);

#if HAVE_MACH
DISPATCH_VTABLE_INSTANCE(mach,
.do_type = DISPATCH_MACH_CHANNEL_TYPE,
.do_kind = "mach-channel",
Expand All @@ -351,6 +352,7 @@ DISPATCH_VTABLE_INSTANCE(mach_msg,
.do_invoke = _dispatch_mach_msg_invoke,
.do_debug = _dispatch_mach_msg_debug,
);
#endif

#if !USE_OBJC
DISPATCH_VTABLE_INSTANCE(data,
Expand Down Expand Up @@ -522,7 +524,7 @@ _dispatch_logv_init(void *context DISPATCH_UNUSED)
#endif
dprintf(dispatch_logfile, "=== log file opened for %s[%u] at "
"%ld.%06u ===\n", getprogname() ?: "", getpid(),
tv.tv_sec, tv.tv_usec);
tv.tv_sec, (unsigned)tv.tv_usec);
}
}
}
Expand Down Expand Up @@ -793,6 +795,7 @@ _dispatch_client_callout2(void *ctxt, size_t i, void (*f)(void *, size_t))
_dispatch_set_unwind_tsd(u);
}

#if HAVE_MACH
#undef _dispatch_client_callout4
void
_dispatch_client_callout4(void *ctxt, dispatch_mach_reason_t reason,
Expand All @@ -807,6 +810,7 @@ _dispatch_client_callout4(void *ctxt, dispatch_mach_reason_t reason,
_dispatch_free_unwind_tsd();
_dispatch_set_unwind_tsd(u);
}
#endif

#endif // DISPATCH_USE_CLIENT_CALLOUT

Expand Down
4 changes: 4 additions & 0 deletions src/inline_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ DISPATCH_NOTHROW void
_dispatch_client_callout(void *ctxt, dispatch_function_t f);
DISPATCH_NOTHROW void
_dispatch_client_callout2(void *ctxt, size_t i, void (*f)(void *, size_t));
#if HAVE_MACH
DISPATCH_NOTHROW void
_dispatch_client_callout4(void *ctxt, dispatch_mach_reason_t reason,
dispatch_mach_msg_t dmsg, mach_error_t error,
dispatch_mach_handler_function_t f);
#endif

#else // !DISPATCH_USE_CLIENT_CALLOUT

Expand All @@ -59,6 +61,7 @@ _dispatch_client_callout2(void *ctxt, size_t i, void (*f)(void *, size_t))
return f(ctxt, i);
}

#if HAVE_MACH
DISPATCH_ALWAYS_INLINE
static inline void
_dispatch_client_callout4(void *ctxt, dispatch_mach_reason_t reason,
Expand All @@ -67,6 +70,7 @@ _dispatch_client_callout4(void *ctxt, dispatch_mach_reason_t reason,
{
return f(ctxt, reason, dmsg, error);
}
#endif

#endif // !DISPATCH_USE_CLIENT_CALLOUT

Expand Down
7 changes: 2 additions & 5 deletions src/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,7 @@ DISPATCH_EXPORT DISPATCH_NOTHROW void dispatch_atfork_child(void);
#if !TARGET_OS_WIN32
#include <sys/event.h>
#include <sys/mount.h>
#ifdef __linux__
#include <shims/sys_queue.h>
#else
#include <sys/queue.h>
#endif
#include <sys/sysctl.h>
#include <sys/socket.h>
#include <sys/time.h>
Expand Down Expand Up @@ -241,6 +237,7 @@ DISPATCH_EXPORT DISPATCH_NOTHROW void dispatch_atfork_child(void);
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -328,10 +325,10 @@ DISPATCH_NOINLINE
void _dispatch_bug_client(const char* msg);
DISPATCH_NOINLINE
void _dispatch_bug_mach_client(const char *msg, mach_msg_return_t kr);
#endif
DISPATCH_NOINLINE
void _dispatch_bug_kevent_client(const char* msg, const char* filter,
const char *operation, int err);
#endif

DISPATCH_NOINLINE DISPATCH_NORETURN
void _dispatch_abort(size_t line, long val);
Expand Down
17 changes: 10 additions & 7 deletions src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -1601,7 +1601,8 @@ _dispatch_disk_init(dispatch_fd_entry_t fd_entry, dev_t dev)
TAILQ_INIT(&disk->operations);
disk->cur_rq = TAILQ_FIRST(&disk->operations);
char label[45];
snprintf(label, sizeof(label), "com.apple.libdispatch-io.deviceq.%d", dev);
snprintf(label, sizeof(label), "com.apple.libdispatch-io.deviceq.%ld",
(long)dev);
disk->pick_queue = dispatch_queue_create(label, NULL);
TAILQ_INSERT_TAIL(&_dispatch_io_devs[hash], disk, disk_list);
out:
Expand Down Expand Up @@ -2067,7 +2068,9 @@ static void
_dispatch_operation_advise(dispatch_operation_t op, size_t chunk_size)
{
#ifndef F_RDADVISE
LINUX_PORT_ERROR();
(void)op;
(void)chunk_size;
LINUX_PORT_ERROR();
#else
int err;
struct radvisory advise;
Expand Down Expand Up @@ -2346,7 +2349,7 @@ _dispatch_io_debug_attr(dispatch_io_t channel, char* buf, size_t bufsiz)
dispatch_queue_t target = channel->do_targetq;
return dsnprintf(buf, bufsiz, "type = %s, fd = 0x%x, %sfd_entry = %p, "
"queue = %p, target = %s[%p], barrier_queue = %p, barrier_group = "
"%p, err = 0x%x, low = 0x%zx, high = 0x%zx, interval%s = %llu ",
"%p, err = 0x%x, low = 0x%zx, high = 0x%zx, interval%s = %"PRIu64" ",
channel->params.type == DISPATCH_IO_STREAM ? "stream" : "random",
channel->fd_actual, channel->atomic_flags & DIO_STOPPED ?
"stopped, " : channel->atomic_flags & DIO_CLOSED ? "closed, " : "",
Expand Down Expand Up @@ -2381,14 +2384,14 @@ _dispatch_operation_debug_attr(dispatch_operation_t op, char* buf,
"channel = %p, queue = %p -> %s[%p], target = %s[%p], "
"offset = %lld, length = %zu, done = %zu, undelivered = %zu, "
"flags = %u, err = 0x%x, low = 0x%zx, high = 0x%zx, "
"interval%s = %llu ", op->params.type == DISPATCH_IO_STREAM ?
"interval%s = %"PRIu64" ", op->params.type == DISPATCH_IO_STREAM ?
"stream" : "random", op->direction == DOP_DIR_READ ? "read" :
"write", op->fd_entry ? op->fd_entry->fd : -1, op->fd_entry,
op->channel, op->op_q, oqtarget && oqtarget->dq_label ?
oqtarget->dq_label : "", oqtarget, target && target->dq_label ?
target->dq_label : "", target, op->offset, op->length, op->total,
op->undelivered + op->buf_len, op->flags, op->err, op->params.low,
op->params.high, op->params.interval_flags &
target->dq_label : "", target, (long long)op->offset, op->length,
op->total, op->undelivered + op->buf_len, op->flags, op->err,
op->params.low, op->params.high, op->params.interval_flags &
DISPATCH_IO_STRICT_INTERVAL ? "(strict)" : "", op->params.interval);
}

Expand Down
2 changes: 2 additions & 0 deletions src/object.m
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ - (NSString *)debugDescription {
}
}

#if HAVE_MACH
#undef _dispatch_client_callout4
void
_dispatch_client_callout4(void *ctxt, dispatch_mach_reason_t reason,
Expand All @@ -537,6 +538,7 @@ - (NSString *)debugDescription {
objc_terminate();
}
}
#endif

#endif // DISPATCH_USE_CLIENT_CALLOUT

Expand Down
6 changes: 5 additions & 1 deletion src/queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,7 @@ _dispatch_root_queue_init_pthread_pool(dispatch_root_queue_context_t qc,
thread_pool_size = pool_size;
}
qc->dgq_thread_pool_size = thread_pool_size;
#if HAVE_PTHREAD_WORKQUEUES
if (qc->dgq_qos) {
(void)dispatch_assume_zero(pthread_attr_init(&pqc->dpq_thread_attr));
(void)dispatch_assume_zero(pthread_attr_setdetachstate(
Expand All @@ -867,6 +868,7 @@ _dispatch_root_queue_init_pthread_pool(dispatch_root_queue_context_t qc,
&pqc->dpq_thread_attr, qc->dgq_qos, 0));
#endif
}
#endif
#if USE_MACH_SEM
// override the default FIFO behavior for the pool semaphores
kern_return_t kr = semaphore_create(mach_task_self(),
Expand Down Expand Up @@ -1464,6 +1466,7 @@ static dispatch_once_t _dispatch_mgr_sched_pred;

// TODO: switch to "event-reflector thread" property <rdar://problem/18126138>

#if HAVE_PTHREAD_WORKQUEUE_QOS
// Must be kept in sync with list of qos classes in sys/qos.h
static const int _dispatch_mgr_sched_qos2prio[] = {
[_DISPATCH_QOS_CLASS_MAINTENANCE] = 4,
Expand All @@ -1473,6 +1476,7 @@ static const int _dispatch_mgr_sched_qos2prio[] = {
[_DISPATCH_QOS_CLASS_USER_INITIATED] = 37,
[_DISPATCH_QOS_CLASS_USER_INTERACTIVE] = 47,
};
#endif

static void
_dispatch_mgr_sched_init(void *ctxt DISPATCH_UNUSED)
Expand Down Expand Up @@ -4056,7 +4060,7 @@ _dispatch_queue_push_override(dispatch_queue_t dq, dispatch_queue_t tq,

_dispatch_queue_push(rq, dc, 0);
#else
(void)dq; (void)tq; (void)p;
(void)dq; (void)tq; (void)p; (void)owning;
#endif
}

Expand Down
10 changes: 9 additions & 1 deletion src/shims/hw_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,15 @@ _dispatch_hw_get_config(_dispatch_hw_config_t c)
(void)dispatch_assume_zero(r);
dispatch_assert(valsz == sizeof(uint32_t));
} else {
#if HAVE_SYSCONF && defined(_SC_NPROCESSORS_ONLN)
#if defined(__linux__)
switch (c) {
case _dispatch_hw_config_logical_cpus:
case _dispatch_hw_config_physical_cpus:
return sysconf(_SC_NPROCESSORS_CONF);
case _dispatch_hw_config_active_cpus:
return sysconf(_SC_NPROCESSORS_ONLN);
}
#elif HAVE_SYSCONF && defined(_SC_NPROCESSORS_ONLN)
r = (int)sysconf(_SC_NPROCESSORS_ONLN);
if (r > 0) val = (uint32_t)r;
#endif
Expand Down
Loading