Skip to content

Commit 394d9a1

Browse files
committed
Merge pull request swiftlang#5 from dgrove-oss/linux-port-hdd-cp2
libdispatch now builds on Linux and ping/pong test runs successfully.
2 parents acd56f6 + 61715e4 commit 394d9a1

21 files changed

+1176
-29
lines changed

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,16 @@ project.xcworkspace
1616
Build
1717
.build
1818

19+
# build files generated by autotools
20+
Makefile
21+
Makefile.in
22+
config.log
23+
configure
24+
aclocal.m4
25+
autom4te.cache
26+
config.log
27+
config.status
28+
config
29+
configure
30+
libtool
31+

configure.ac

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -297,15 +297,17 @@ AS_IF([test "x$dispatch_cv_cc_omit_leaf_fp" != "xno"], [
297297
])
298298
AC_SUBST([OMIT_LEAF_FP_FLAGS])
299299

300-
AC_CACHE_CHECK([for darwin linker], [dispatch_cv_ld_darwin], [
301-
saveLDFLAGS="$LDFLAGS"
302-
LDFLAGS="$LDFLAGS -dynamiclib -compatibility_version 1.2.3 -current_version 4.5.6 -dead_strip"
303-
AC_LINK_IFELSE([AC_LANG_PROGRAM([
304-
extern int foo; int foo;], [foo = 0;])],
305-
[dispatch_cv_ld_darwin="yes"], [dispatch_cv_ld_darwin="no"])
306-
LDFLAGS="$saveLDFLAGS"
300+
AS_IF([test "x$have_mach" = "xtrue"], [
301+
AC_CACHE_CHECK([for darwin linker], [dispatch_cv_ld_darwin], [
302+
saveLDFLAGS="$LDFLAGS"
303+
LDFLAGS="$LDFLAGS -dynamiclib -compatibility_version 1.2.3 -current_version 4.5.6 -dead_strip"
304+
AC_LINK_IFELSE([AC_LANG_PROGRAM([
305+
extern int foo; int foo;], [foo = 0;])],
306+
[dispatch_cv_ld_darwin="yes"], [dispatch_cv_ld_darwin="no"])
307+
LDFLAGS="$saveLDFLAGS"
308+
])
307309
])
308-
AM_CONDITIONAL(HAVE_DARWIN_LD, [test "x$dispatch_cv_ld_darwin" != "xno"])
310+
AM_CONDITIONAL(HAVE_DARWIN_LD, [test "x$dispatch_cv_ld_darwin" == "xyes"])
309311

310312
#
311313
# Temporary: some versions of clang do not mark __builtin_trap() as

m4/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
libtool.m4
2+
ltoptions.m4
3+
ltsugar.m4
4+
ltversion.m4
5+
lt~obsolete.m4

os/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
osdir=$(includedir)/os
66

77
os_HEADERS= \
8-
object.h
8+
object.h \
9+
linux_base.h
910

1011
noinst_HEADERS= \
1112
object_private.h

os/linux_base.h

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
/*
2+
* @APPLE_APACHE_LICENSE_HEADER_START@
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* @APPLE_APACHE_LICENSE_HEADER_END@
17+
*/
18+
19+
#ifndef __OS_LINUX_BASE__
20+
#define __OS_LINUX_BASE__
21+
22+
// #include <sys/event.h>
23+
24+
// marker for hacks we have made to make progress
25+
#define __LINUX_PORT_HDD__ 1
26+
27+
/*
28+
* Stub out defines for some mach types and related macros
29+
*/
30+
31+
typedef uint32_t mach_port_t;
32+
33+
#define MACH_PORT_NULL (0)
34+
#define MACH_PORT_DEAD (-1)
35+
36+
#define EVFILT_MACHPORT (-8)
37+
38+
typedef uint32_t mach_error_t;
39+
40+
typedef uint32_t mach_vm_size_t;
41+
42+
typedef uint32_t mach_msg_return_t;
43+
44+
typedef uintptr_t mach_vm_address_t;
45+
46+
typedef uint32_t dispatch_mach_msg_t;
47+
48+
typedef uint32_t dispatch_mach_t;
49+
50+
typedef uint32_t dispatch_mach_reason_t;
51+
52+
typedef uint32_t voucher_activity_mode_t;
53+
54+
typedef uint32_t voucher_activity_trace_id_t;
55+
56+
typedef uint32_t voucher_activity_id_t;
57+
58+
typedef uint32_t _voucher_activity_buffer_hook_t;;
59+
60+
typedef uint32_t voucher_activity_flag_t;
61+
62+
typedef struct
63+
{
64+
} mach_msg_header_t;
65+
66+
67+
typedef void (*dispatch_mach_handler_function_t)(void*, dispatch_mach_reason_t,
68+
dispatch_mach_msg_t, mach_error_t);
69+
70+
typedef void (*dispatch_mach_msg_destructor_t)(void*);
71+
72+
typedef uint32_t voucher_activity_mode_t;
73+
74+
struct voucher_offsets_s {
75+
uint32_t vo_version;
76+
};
77+
78+
79+
/*
80+
* Stub out defines for other missing types
81+
*/
82+
83+
// Pulled from OS X man page for kevent
84+
struct kevent64_s {
85+
uint64_t ident; /* identifier for this event */
86+
int16_t filter; /* filter for event */
87+
uint16_t flags; /* general flags */
88+
uint32_t fflags; /* filter-specific flags */
89+
int64_t data; /* filter-specific data */
90+
uint64_t udata; /* opaque user data identifier */
91+
uint64_t ext[2]; /* filter-specific extensions */
92+
};
93+
94+
95+
// PAGE_SIZE and SIZE_T_MAX should not be hardcoded like this here.
96+
#define PAGE_SIZE (4096)
97+
#define SIZE_T_MAX (0x7fffffff)
98+
99+
// Define to 0 the NOTE_ values that are not present on Linux.
100+
// Revisit this...would it be better to ifdef out the uses instead??
101+
#define NOTE_VM_PRESSURE 0
102+
#define NOTE_ABSOLUTE 0
103+
#define NOTE_NSECONDS 0
104+
#define NOTE_LEEWAY 0
105+
#define NOTE_CRITICAL 0
106+
#define NOTE_BACKGROUND 0
107+
108+
/*
109+
* Stub out misc linking and compilation attributes
110+
*/
111+
112+
#ifdef OS_EXPORT
113+
#undef OS_EXPORT
114+
#endif
115+
#define OS_EXPORT
116+
117+
#ifdef OS_WARN_RESULT_NEEDS_RELEASE
118+
#undef OS_WARN_RESULT_NEEDS_RELEASE
119+
#endif
120+
121+
#ifdef OS_WARN_RESULT
122+
#undef OS_WARN_RESULT
123+
#endif
124+
#define OS_WARN_RESULT
125+
126+
#ifdef OS_NOTHROW
127+
#undef OS_NOTHROW
128+
#endif
129+
#define OS_NOTHROW
130+
131+
132+
// These and similar macros come from Availabilty.h on OS X
133+
// Need a better way to do this long term.
134+
#define __OSX_AVAILABLE_BUT_DEPRECATED(a,b,c,d) //
135+
#define __OSX_AVAILABLE_BUT_DEPRECATED_MSG(a,b,c,d,msg) //
136+
137+
138+
// Print a warning when an unported code path executes.
139+
#define LINUX_PORT_ERROR() do { printf("LINUX_PORT_ERROR_CALLED %s:%d: %s\n",__FILE__,__LINE__,__FUNCTION__); } while (0)
140+
141+
142+
#endif /* __OS_LINUX_BASE__ */

os/object.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@
2424
#ifdef __APPLE__
2525
#include <Availability.h>
2626
#endif
27+
#ifndef __linux__
2728
#include <os/base.h>
29+
#else
30+
#include <os/linux_base.h>
31+
#endif
2832

2933
/*!
3034
* @header

private/voucher_activity_private.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
#ifndef __OS_VOUCHER_ACTIVITY_PRIVATE__
2222
#define __OS_VOUCHER_ACTIVITY_PRIVATE__
2323

24+
#ifndef __linux__
2425
#include <os/base.h>
26+
#endif
2527
#include <os/object.h>
2628
#if !defined(__DISPATCH_BUILDING_DISPATCH__)
2729
#include <os/voucher_private.h>

private/voucher_private.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
#ifndef __OS_VOUCHER_PRIVATE__
2222
#define __OS_VOUCHER_PRIVATE__
2323

24+
#ifndef __linux__
2425
#include <os/base.h>
26+
#endif
2527
#include <os/object.h>
2628

2729
#define OS_VOUCHER_SPI_VERSION 20141203
@@ -400,7 +402,9 @@ dispatch_queue_create_with_accounting_override_voucher(const char *label,
400402
* voucher ports directly.
401403
*/
402404

405+
#ifdef __APPLE__
403406
#include <mach/mach.h>
407+
#endif
404408

405409
/*!
406410
* @function voucher_create_with_mach_msg

src/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
provider.h
2+
.libs
3+
*.lo
4+
*.la
5+

src/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ libdispatch_la_SOURCES= \
3939
shims/atomic_sfb.h \
4040
shims/getprogname.h \
4141
shims/hw_config.h \
42+
shims/linux_stubs.c \
43+
shims/linux_stubs.h \
4244
shims/perfmon.h \
4345
shims/time.h \
4446
shims/tsd.h \

src/init.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,9 @@ const struct dispatch_tsd_indexes_s dispatch_tsd_indexes = {
162162
.dti_qos_class_index = dispatch_priority_key,
163163
};
164164
#else // DISPATCH_USE_DIRECT_TSD
165+
#ifndef __LINUX_PORT_HDD__
165166
#error Not implemented on this platform
167+
#endif
166168
#endif // DISPATCH_USE_DIRECT_TSD
167169

168170
// 6618342 Contact the team that owns the Instrument DTrace probe before
@@ -1157,7 +1159,10 @@ const struct dispatch_source_type_s _dispatch_source_type_vnode = {
11571159
.flags = EV_CLEAR|EV_UDATA_SPECIFIC,
11581160
},
11591161
.mask = NOTE_DELETE|NOTE_WRITE|NOTE_EXTEND|NOTE_ATTRIB|NOTE_LINK|
1160-
NOTE_RENAME|NOTE_REVOKE
1162+
NOTE_RENAME
1163+
#if HAVE_DECL_NOTE_REVOKE
1164+
|NOTE_REVOKE
1165+
#endif
11611166
#if HAVE_DECL_NOTE_NONE
11621167
|NOTE_NONE
11631168
#endif

src/internal.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,11 @@ DISPATCH_EXPORT DISPATCH_NOTHROW void dispatch_atfork_child(void);
208208
#if !TARGET_OS_WIN32
209209
#include <sys/event.h>
210210
#include <sys/mount.h>
211+
#ifdef __linux__
212+
#include <shims/sys_queue.h>
213+
#else
211214
#include <sys/queue.h>
215+
#endif
212216
#include <sys/sysctl.h>
213217
#include <sys/socket.h>
214218
#include <sys/time.h>

src/io.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,11 @@ dispatch_io_create_with_path(dispatch_io_type_t type, const char *path,
387387
int err = 0;
388388
struct stat st;
389389
_dispatch_io_syscall_switch_noerr(err,
390-
(path_data->oflag & O_NOFOLLOW) == O_NOFOLLOW ||
391-
(path_data->oflag & O_SYMLINK) == O_SYMLINK ?
392-
lstat(path_data->path, &st) : stat(path_data->path, &st),
390+
(path_data->oflag & O_NOFOLLOW) == O_NOFOLLOW
391+
#ifndef __linux__
392+
|| (path_data->oflag & O_SYMLINK) == O_SYMLINK
393+
#endif
394+
? lstat(path_data->path, &st) : stat(path_data->path, &st),
393395
case 0:
394396
err = _dispatch_io_validate_type(channel, st.st_mode);
395397
break;
@@ -2064,6 +2066,9 @@ _dispatch_disk_perform(void *ctxt)
20642066
static void
20652067
_dispatch_operation_advise(dispatch_operation_t op, size_t chunk_size)
20662068
{
2069+
#ifndef F_RDADVISE
2070+
LINUX_PORT_ERROR();
2071+
#else
20672072
int err;
20682073
struct radvisory advise;
20692074
// No point in issuing a read advise for the next chunk if we are already
@@ -2090,6 +2095,7 @@ _dispatch_operation_advise(dispatch_operation_t op, size_t chunk_size)
20902095
// TODO: set disk status on error
20912096
default: (void)dispatch_assume_zero(err); break;
20922097
);
2098+
#endif
20932099
}
20942100

20952101
static int

0 commit comments

Comments
 (0)