1313#ifndef __OS_LINUX_BASE__
1414#define __OS_LINUX_BASE__
1515
16- // #include <sys/event.h>
1716#include <sys/user.h>
17+ #include <sys/param.h>
1818
19- // marker for hacks we have made to make progress
20- #define __LINUX_PORT_HDD__ 1
21-
22- /*
23- * Stub out defines for some mach types and related macros
24- */
25-
26- typedef uint32_t mach_port_t ;
27-
28- #define MACH_PORT_NULL (0)
29- #define MACH_PORT_DEAD (-1)
30-
31- #define EVFILT_MACHPORT (-8)
32-
33- typedef uint32_t mach_error_t ;
34-
35- typedef uint32_t mach_vm_size_t ;
36-
37- typedef uint32_t mach_msg_return_t ;
38-
39- typedef uintptr_t mach_vm_address_t ;
40-
41- typedef uint32_t dispatch_mach_msg_t ;
42-
43- typedef uint32_t dispatch_mach_t ;
44-
45- typedef uint32_t dispatch_mach_reason_t ;
46-
47- typedef uint32_t voucher_activity_mode_t ;
48-
49- typedef uint32_t voucher_activity_trace_id_t ;
50-
51- typedef uint32_t voucher_activity_id_t ;
52-
53- typedef uint32_t _voucher_activity_buffer_hook_t ;;
54-
55- typedef uint32_t voucher_activity_flag_t ;
56-
57- typedef struct
58- {
59- } mach_msg_header_t ;
60-
61-
62- typedef void (* dispatch_mach_handler_function_t )(void * , dispatch_mach_reason_t ,
63- dispatch_mach_msg_t , mach_error_t );
64-
65- typedef void (* dispatch_mach_msg_destructor_t )(void * );
66-
67- // Print a warning when an unported code path executes.
68- #define LINUX_PORT_ERROR () do { printf("LINUX_PORT_ERROR_CALLED %s:%d: %s\n",__FILE__,__LINE__,__FUNCTION__); } while (0)
69-
70- /*
71- * Stub out defines for other missing types
72- */
73-
74- #if __linux__
75- // we fall back to use kevent
76- #define kevent64_s kevent
77- #define kevent64 (kq ,cl ,nc ,el ,ne ,f ,to ) kevent(kq,cl,nc,el,ne,to)
19+ #if __GNUC__
20+ #define OS_EXPECT (x , v ) __builtin_expect((x), (v))
21+ #else
22+ #define OS_EXPECT (x , v ) (x)
7823#endif
7924
80- // SIZE_T_MAX should not be hardcoded like this here.
81- #define SIZE_T_MAX (0x7fffffff)
25+ #ifndef os_likely
26+ #define os_likely (x ) OS_EXPECT(!!(x), 1)
27+ #endif
28+ #ifndef os_unlikely
29+ #define os_unlikely (x ) OS_EXPECT(!!(x), 0)
30+ #endif
8231
83- // Define to 0 the NOTE_ values that are not present on Linux.
84- // Revisit this...would it be better to ifdef out the uses instead??
32+ #if __has_feature (assume_nonnull )
33+ #define OS_ASSUME_NONNULL_BEGIN _Pragma("clang assume_nonnull begin")
34+ #define OS_ASSUME_NONNULL_END _Pragma("clang assume_nonnull end")
35+ #else
36+ #define OS_ASSUME_NONNULL_BEGIN
37+ #define OS_ASSUME_NONNULL_END
38+ #endif
8539
86- // The following values are passed as part of the EVFILT_TIMER requests
40+ #if __has_builtin (__builtin_assume )
41+ #define OS_COMPILER_CAN_ASSUME (expr ) __builtin_assume(expr)
42+ #else
43+ #define OS_COMPILER_CAN_ASSUME (expr ) ((void)(expr))
44+ #endif
8745
88- #define IGNORE_KEVENT64_EXT /* will force the kevent64_s.ext[] to not be used -> leeway ignored */
46+ #if __has_feature (attribute_availability_swift )
47+ // equivalent to __SWIFT_UNAVAILABLE from Availability.h
48+ #define OS_SWIFT_UNAVAILABLE (_msg ) \
49+ __attribute__((__availability__(swift, unavailable, message=_msg)))
50+ #else
51+ #define OS_SWIFT_UNAVAILABLE (_msg )
52+ #endif
8953
90- #define NOTE_SECONDS 0x01
91- #define NOTE_USECONDS 0x02
92- #define NOTE_NSECONDS 0x04
93- #define NOTE_ABSOLUTE 0x08
94- #define NOTE_CRITICAL 0x10
95- #define NOTE_BACKGROUND 0x20
96- #define NOTE_LEEWAY 0x40
54+ #if __has_attribute (swift_private )
55+ # define OS_REFINED_FOR_SWIFT __attribute__((__swift_private__))
56+ #else
57+ # define OS_REFINED_FOR_SWIFT
58+ #endif
9759
98- // need to catch the following usage if it happens ..
99- // we simply return '0' as a value probably not correct
60+ #if __has_attribute (swift_name )
61+ # define OS_SWIFT_NAME (_name ) __attribute__((__swift_name__(#_name)))
62+ #else
63+ # define OS_SWIFT_NAME (_name )
64+ #endif
10065
101- #define NOTE_VM_PRESSURE ({LINUX_PORT_ERROR(); 0;})
66+ #define __OS_STRINGIFY (s ) #s
67+ #define OS_STRINGIFY (s ) __OS_STRINGIFY(s)
68+ #define __OS_CONCAT (x , y ) x ## y
69+ #define OS_CONCAT (x , y ) __OS_CONCAT(x, y)
10270
10371/*
10472 * Stub out misc linking and compilation attributes
@@ -123,12 +91,4 @@ typedef void (*dispatch_mach_msg_destructor_t)(void*);
12391#endif
12492#define OS_NOTHROW
12593
126-
127- // These and similar macros come from Availabilty.h on OS X
128- // Need a better way to do this long term.
129- #define __OSX_AVAILABLE_BUT_DEPRECATED (a ,b ,c ,d ) //
130- #define __OSX_AVAILABLE_BUT_DEPRECATED_MSG (a ,b ,c ,d ,msg ) //
131-
132-
133-
13494#endif /* __OS_LINUX_BASE__ */
0 commit comments