forked from rpetrich/RocketBootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrocketbootstrap_dynamic.h
93 lines (88 loc) · 2.86 KB
/
rocketbootstrap_dynamic.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// DONT INCLUDE DIRECTLY
// Set ROCKETBOOTSTRAP_LOAD_DYNAMIC and then include rocketbootstrap.h
#include <dlfcn.h>
__attribute__((unused))
static kern_return_t rocketbootstrap_look_up(mach_port_t bp, const name_t service_name, mach_port_t *sp)
{
static kern_return_t (*impl)(mach_port_t bp, const name_t service_name, mach_port_t *sp);
if (!impl) {
void *handle = dlopen("/usr/lib/librocketbootstrap.dylib", RTLD_LAZY);
if (handle)
impl = dlsym(handle, "rocketbootstrap_look_up");
if (!impl)
impl = bootstrap_look_up;
}
return impl(bp, service_name, sp);
}
__attribute__((unused))
static kern_return_t rocketbootstrap_unlock(const name_t service_name)
{
static kern_return_t (*impl)(const name_t service_name);
if (!impl) {
void *handle = dlopen("/usr/lib/librocketbootstrap.dylib", RTLD_LAZY);
if (handle)
impl = dlsym(handle, "rocketbootstrap_unlock");
if (!impl)
return -1;
}
return impl(service_name);
}
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
__attribute__((unused))
static kern_return_t rocketbootstrap_register(mach_port_t bp, name_t service_name, mach_port_t sp)
{
static kern_return_t (*impl)(mach_port_t bp, name_t service_name, mach_port_t sp);
if (!impl) {
void *handle = dlopen("/usr/lib/librocketbootstrap.dylib", RTLD_LAZY);
if (handle)
impl = dlsym(handle, "rocketbootstrap_register");
if (!impl)
impl = bootstrap_register;
}
return impl(bp, service_name, sp);
}
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
#ifdef __COREFOUNDATION_CFMESSAGEPORT__
__attribute__((unused))
static CFMessagePortRef rocketbootstrap_cfmessageportcreateremote(CFAllocatorRef allocator, CFStringRef name)
{
static CFMessagePortRef (*impl)(CFAllocatorRef allocator, CFStringRef name);
if (!impl) {
void *handle = dlopen("/usr/lib/librocketbootstrap.dylib", RTLD_LAZY);
if (handle)
impl = dlsym(handle, "rocketbootstrap_cfmessageportcreateremote");
if (!impl)
impl = CFMessagePortCreateRemote;
}
return impl(allocator, name);
}
__attribute__((unused))
static kern_return_t rocketbootstrap_cfmessageportexposelocal(CFMessagePortRef messagePort)
{
static kern_return_t (*impl)(CFMessagePortRef messagePort);
if (!impl) {
void *handle = dlopen("/usr/lib/librocketbootstrap.dylib", RTLD_LAZY);
if (handle)
impl = dlsym(handle, "rocketbootstrap_cfmessageportexposelocal");
if (!impl)
return -1;
}
return impl(messagePort);
}
#endif
#ifdef __OBJC__
@class CPDistributedMessagingCenter;
__attribute__((unused))
static void rocketbootstrap_distributedmessagingcenter_apply(CPDistributedMessagingCenter *messaging_center)
{
static void (*impl)(CPDistributedMessagingCenter *messagingCenter);
if (!impl) {
void *handle = dlopen("/usr/lib/librocketbootstrap.dylib", RTLD_LAZY);
if (handle)
impl = dlsym(handle, "rocketbootstrap_distributedmessagingcenter_apply");
if (!impl)
return;
}
impl(messaging_center);
}
#endif