rocketbootstrap_dynamic.h 2.9 KB

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