Skip to content

Port transform and use libbsd #13

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

Merged
Merged
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ config.status
config
configure
libtool

.dirstamp
2 changes: 1 addition & 1 deletion INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ Prepare your system
2. Install dtrace (to generate provider.h)
sudo apt-get install systemtap-sdt-dev
3. Install libdispatch pre-reqs
sudo apt-get install libblocksruntime-dev libkqueue-dev libpthread-workqueue-dev
sudo apt-get install libblocksruntime-dev libkqueue-dev libpthread-workqueue-dev libbsd-dev

Build:
sh autogen.sh
Expand Down
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 @@ -241,7 +248,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
2 changes: 0 additions & 2 deletions os/linux_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ typedef void (*dispatch_mach_handler_function_t)(void*, dispatch_mach_reason_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
2 changes: 1 addition & 1 deletion private/voucher_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,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 +427,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
8 changes: 4 additions & 4 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@ 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_LDFLAGS=-avoid-version
libdispatch_la_LIBADD=$(KQUEUE_LIBS) $(PTHREAD_WORKQUEUE_LIBS)

if HAVE_PTHREAD_WORKQUEUES
PTHREAD_WORKQUEUE_LIBS=-lpthread_workqueue
endif

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

if HAVE_DARWIN_LD
libdispatch_la_LDFLAGS+=-Wl,-compatibility_version,1 \
-Wl,-current_version,$(VERSION) -Wl,-dead_strip \
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
4 changes: 4 additions & 0 deletions 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 @@ -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
6 changes: 1 addition & 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 @@ -328,10 +324,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
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
Empty file removed src/shims/.dirstamp
Empty file.
10 changes: 10 additions & 0 deletions src/shims/hw_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ static inline uint32_t
_dispatch_hw_get_config(_dispatch_hw_config_t c)
{
uint32_t val = 1;
#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);
}
#else
const char *name = NULL;
int r;
#if defined(__APPLE__)
Expand All @@ -106,6 +115,7 @@ _dispatch_hw_get_config(_dispatch_hw_config_t c)
if (r > 0) val = (uint32_t)r;
#endif
}
#endif
return val;
}

Expand Down
33 changes: 4 additions & 29 deletions src/shims/linux_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,66 +24,41 @@
*/

#include <stdint.h>

#include <syscall.h>
#include <config/config.h>

#include "pthread.h"

#define program_invocation_short_name "hi"

#include "os/linux_base.h"
#include "internal.h"


#undef LINUX_PORT_ERROR
#define LINUX_PORT_ERROR() do { printf("LINUX_PORT_ERROR_CALLED %s:%d: %s\n",__FILE__,__LINE__,__FUNCTION__); abort(); } while (0)

void _dispatch_mach_msg_dispose() { LINUX_PORT_ERROR(); }

unsigned long _dispatch_mach_probe(dispatch_mach_t dm) {
LINUX_PORT_ERROR();
}

dispatch_block_t _dispatch_block_create(dispatch_block_flags_t flags,
voucher_t voucher, pthread_priority_t priority,
dispatch_block_t block) {
LINUX_PORT_ERROR();
}

void _dispatch_mach_invoke() { LINUX_PORT_ERROR(); }

size_t _dispatch_mach_msg_debug(dispatch_mach_msg_t dmsg, char* buf, size_t bufsiz) {
LINUX_PORT_ERROR();
}
void _dispatch_mach_dispose() { LINUX_PORT_ERROR(); }
void _dispatch_mach_msg_invoke() { LINUX_PORT_ERROR(); }

unsigned long _dispatch_runloop_queue_probe(dispatch_queue_t dq) {
LINUX_PORT_ERROR();
}
void _dispatch_runloop_queue_xref_dispose() { LINUX_PORT_ERROR(); }

void strlcpy() { 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() {
return (mach_port_t)pthread_self();
mach_port_t pthread_mach_thread_np(void) {
return (pid_t)syscall(SYS_gettid);
}

mach_port_t mach_task_self() {
mach_port_t mach_task_self(void) {
return (mach_port_t)pthread_self();
}

int sysctlbyname(const char *name, void *oldp, size_t *oldlenp,
void *newp, size_t newlen) {
LINUX_PORT_ERROR();
}

/*
* Stubbed out static data
*/
Expand Down
3 changes: 0 additions & 3 deletions src/shims/linux_stubs.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
#ifndef __DISPATCH__STUBS__INTERNAL
#define __DISPATCH__STUBS__INTERNAL

int sysctlbyname(const char *name, void *oldp, size_t *oldlenp,
void *newp, size_t newlen);

mach_port_t pthread_mach_thread_np();

mach_port_t mach_task_self();
Expand Down
Loading