Skip to content

libdispatch now builds on Linux and ping/pong test runs successfully. #5

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 3 commits into from
Dec 5, 2015
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
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,16 @@ project.xcworkspace
Build
.build

# build files generated by autotools
Makefile
Makefile.in
config.log
configure
aclocal.m4
autom4te.cache
config.log
config.status
config
configure
libtool

18 changes: 10 additions & 8 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -297,15 +297,17 @@ AS_IF([test "x$dispatch_cv_cc_omit_leaf_fp" != "xno"], [
])
AC_SUBST([OMIT_LEAF_FP_FLAGS])

AC_CACHE_CHECK([for darwin linker], [dispatch_cv_ld_darwin], [
saveLDFLAGS="$LDFLAGS"
LDFLAGS="$LDFLAGS -dynamiclib -compatibility_version 1.2.3 -current_version 4.5.6 -dead_strip"
AC_LINK_IFELSE([AC_LANG_PROGRAM([
extern int foo; int foo;], [foo = 0;])],
[dispatch_cv_ld_darwin="yes"], [dispatch_cv_ld_darwin="no"])
LDFLAGS="$saveLDFLAGS"
AS_IF([test "x$have_mach" = "xtrue"], [
AC_CACHE_CHECK([for darwin linker], [dispatch_cv_ld_darwin], [
saveLDFLAGS="$LDFLAGS"
LDFLAGS="$LDFLAGS -dynamiclib -compatibility_version 1.2.3 -current_version 4.5.6 -dead_strip"
AC_LINK_IFELSE([AC_LANG_PROGRAM([
extern int foo; int foo;], [foo = 0;])],
[dispatch_cv_ld_darwin="yes"], [dispatch_cv_ld_darwin="no"])
LDFLAGS="$saveLDFLAGS"
])
])
AM_CONDITIONAL(HAVE_DARWIN_LD, [test "x$dispatch_cv_ld_darwin" != "xno"])
AM_CONDITIONAL(HAVE_DARWIN_LD, [test "x$dispatch_cv_ld_darwin" == "xyes"])

#
# Temporary: some versions of clang do not mark __builtin_trap() as
Expand Down
5 changes: 5 additions & 0 deletions m4/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
libtool.m4
ltoptions.m4
ltsugar.m4
ltversion.m4
lt~obsolete.m4
3 changes: 2 additions & 1 deletion os/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
osdir=$(includedir)/os

os_HEADERS= \
object.h
object.h \
linux_base.h

noinst_HEADERS= \
object_private.h
142 changes: 142 additions & 0 deletions os/linux_base.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/*
* @APPLE_APACHE_LICENSE_HEADER_START@
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @APPLE_APACHE_LICENSE_HEADER_END@
*/

#ifndef __OS_LINUX_BASE__
#define __OS_LINUX_BASE__

// #include <sys/event.h>

// marker for hacks we have made to make progress
#define __LINUX_PORT_HDD__ 1

/*
* Stub out defines for some mach types and related macros
*/

typedef uint32_t mach_port_t;

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

#define EVFILT_MACHPORT (-8)

typedef uint32_t mach_error_t;

typedef uint32_t mach_vm_size_t;

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;

typedef uint32_t voucher_activity_id_t;

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;
};


/*
* Stub out defines for other missing types
*/

// Pulled from OS X man page for kevent
struct kevent64_s {
uint64_t ident; /* identifier for this event */
int16_t filter; /* filter for event */
uint16_t flags; /* general flags */
uint32_t fflags; /* filter-specific flags */
int64_t data; /* filter-specific data */
uint64_t udata; /* opaque user data identifier */
uint64_t ext[2]; /* filter-specific extensions */
};


// PAGE_SIZE and SIZE_T_MAX should not be hardcoded like this here.
#define PAGE_SIZE (4096)
#define SIZE_T_MAX (0x7fffffff)

// Define to 0 the NOTE_ values that are not present on Linux.
// Revisit this...would it be better to ifdef out the uses instead??
#define NOTE_VM_PRESSURE 0
#define NOTE_ABSOLUTE 0
#define NOTE_NSECONDS 0
#define NOTE_LEEWAY 0
#define NOTE_CRITICAL 0
#define NOTE_BACKGROUND 0

/*
* Stub out misc linking and compilation attributes
*/

#ifdef OS_EXPORT
#undef OS_EXPORT
#endif
#define OS_EXPORT

#ifdef OS_WARN_RESULT_NEEDS_RELEASE
#undef OS_WARN_RESULT_NEEDS_RELEASE
#endif

#ifdef OS_WARN_RESULT
#undef OS_WARN_RESULT
#endif
#define OS_WARN_RESULT

#ifdef OS_NOTHROW
#undef OS_NOTHROW
#endif
#define OS_NOTHROW


// These and similar macros come from Availabilty.h on OS X
// Need a better way to do this long term.
#define __OSX_AVAILABLE_BUT_DEPRECATED(a,b,c,d) //
#define __OSX_AVAILABLE_BUT_DEPRECATED_MSG(a,b,c,d,msg) //


// 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)


#endif /* __OS_LINUX_BASE__ */
4 changes: 4 additions & 0 deletions os/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
#ifdef __APPLE__
#include <Availability.h>
#endif
#ifndef __linux__
#include <os/base.h>
#else
#include <os/linux_base.h>
#endif

/*!
* @header
Expand Down
2 changes: 2 additions & 0 deletions private/voucher_activity_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
#ifndef __OS_VOUCHER_ACTIVITY_PRIVATE__
#define __OS_VOUCHER_ACTIVITY_PRIVATE__

#ifndef __linux__
#include <os/base.h>
#endif
#include <os/object.h>
#if !defined(__DISPATCH_BUILDING_DISPATCH__)
#include <os/voucher_private.h>
Expand Down
4 changes: 4 additions & 0 deletions private/voucher_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
#ifndef __OS_VOUCHER_PRIVATE__
#define __OS_VOUCHER_PRIVATE__

#ifndef __linux__
#include <os/base.h>
#endif
#include <os/object.h>

#define OS_VOUCHER_SPI_VERSION 20141203
Expand Down Expand Up @@ -400,7 +402,9 @@ dispatch_queue_create_with_accounting_override_voucher(const char *label,
* voucher ports directly.
*/

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

/*!
* @function voucher_create_with_mach_msg
Expand Down
5 changes: 5 additions & 0 deletions src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
provider.h
.libs
*.lo
*.la

2 changes: 2 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ libdispatch_la_SOURCES= \
shims/atomic_sfb.h \
shims/getprogname.h \
shims/hw_config.h \
shims/linux_stubs.c \
shims/linux_stubs.h \
shims/perfmon.h \
shims/time.h \
shims/tsd.h \
Expand Down
7 changes: 6 additions & 1 deletion src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ const struct dispatch_tsd_indexes_s dispatch_tsd_indexes = {
.dti_qos_class_index = dispatch_priority_key,
};
#else // DISPATCH_USE_DIRECT_TSD
#ifndef __LINUX_PORT_HDD__
#error Not implemented on this platform
#endif
#endif // DISPATCH_USE_DIRECT_TSD

// 6618342 Contact the team that owns the Instrument DTrace probe before
Expand Down Expand Up @@ -1157,7 +1159,10 @@ const struct dispatch_source_type_s _dispatch_source_type_vnode = {
.flags = EV_CLEAR|EV_UDATA_SPECIFIC,
},
.mask = NOTE_DELETE|NOTE_WRITE|NOTE_EXTEND|NOTE_ATTRIB|NOTE_LINK|
NOTE_RENAME|NOTE_REVOKE
NOTE_RENAME
#if HAVE_DECL_NOTE_REVOKE
|NOTE_REVOKE
#endif
#if HAVE_DECL_NOTE_NONE
|NOTE_NONE
#endif
Expand Down
4 changes: 4 additions & 0 deletions src/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,11 @@ 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
12 changes: 9 additions & 3 deletions src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,11 @@ dispatch_io_create_with_path(dispatch_io_type_t type, const char *path,
int err = 0;
struct stat st;
_dispatch_io_syscall_switch_noerr(err,
(path_data->oflag & O_NOFOLLOW) == O_NOFOLLOW ||
(path_data->oflag & O_SYMLINK) == O_SYMLINK ?
lstat(path_data->path, &st) : stat(path_data->path, &st),
(path_data->oflag & O_NOFOLLOW) == O_NOFOLLOW
#ifndef __linux__
|| (path_data->oflag & O_SYMLINK) == O_SYMLINK
#endif
? lstat(path_data->path, &st) : stat(path_data->path, &st),
case 0:
err = _dispatch_io_validate_type(channel, st.st_mode);
break;
Expand Down Expand Up @@ -2064,6 +2066,9 @@ _dispatch_disk_perform(void *ctxt)
static void
_dispatch_operation_advise(dispatch_operation_t op, size_t chunk_size)
{
#ifndef F_RDADVISE
LINUX_PORT_ERROR();
#else
int err;
struct radvisory advise;
// No point in issuing a read advise for the next chunk if we are already
Expand All @@ -2090,6 +2095,7 @@ _dispatch_operation_advise(dispatch_operation_t op, size_t chunk_size)
// TODO: set disk status on error
default: (void)dispatch_assume_zero(err); break;
);
#endif
}

static int
Expand Down
Loading