Skip to content

Commit

Permalink
Support macOS 10.15
Browse files Browse the repository at this point in the history
Fixes #1266
Fixes #1323
Fixes #2154
  • Loading branch information
Jarred-Sumner authored and cirospaciari committed Feb 27, 2023
1 parent e043c63 commit 18948cc
Showing 1 changed file with 75 additions and 4 deletions.
@@ -1,3 +1,7 @@
#ifndef UNLIKELY
#define UNLIKELY(x) __builtin_expect(!!(x), 0)
#endif

// if linux
#if defined(__linux__)

Expand All @@ -8,10 +12,6 @@
#include <errno.h>
#include <dlfcn.h>

#ifndef UNLIKELY
#define UNLIKELY(x) __builtin_expect(!!(x), 0)
#endif

#ifndef _STAT_VER
#if defined(__aarch64__)
#define _STAT_VER 0
Expand Down Expand Up @@ -182,3 +182,74 @@ extern "C" int __wrap_mknodat(int dirfd, const char* path, __mode_t mode, __dev_
}

#endif

// macOS
#if defined(__APPLE__)

#include <dlfcn.h>

extern "C" int pthread_self_is_exiting_np()
{
static void* pthread_self_is_exiting_np_ptr = nullptr;
static bool pthread_self_is_exiting_np_ptr_initialized = false;
if (UNLIKELY(!pthread_self_is_exiting_np_ptr_initialized)) {
pthread_self_is_exiting_np_ptr_initialized = true;
pthread_self_is_exiting_np_ptr = dlsym(RTLD_DEFAULT, "pthread_self_is_exiting_np");
}

if (UNLIKELY(pthread_self_is_exiting_np_ptr == nullptr))
return 0;

return ((int (*)())pthread_self_is_exiting_np_ptr)();
}

extern "C" int posix_spawn_file_actions_addchdir_np(
void* file_actions,
const char* path)
{
static void* posix_spawn_file_actions_addchdir_np_ptr = nullptr;
static bool posix_spawn_file_actions_addchdir_np_ptr_initialized = false;
if (UNLIKELY(!posix_spawn_file_actions_addchdir_np_ptr_initialized)) {
posix_spawn_file_actions_addchdir_np_ptr_initialized = true;
posix_spawn_file_actions_addchdir_np_ptr = dlsym(RTLD_DEFAULT, "posix_spawn_file_actions_addchdir_np");
}

if (UNLIKELY(posix_spawn_file_actions_addchdir_np_ptr == nullptr))
return 0;

return ((int (*)(void*, const char*))posix_spawn_file_actions_addchdir_np_ptr)(file_actions, path);
}

extern "C" int posix_spawn_file_actions_addinherit_np(void* ptr,
int status)
{
static void* posix_spawn_file_actions_addinherit_np_ptr = nullptr;
static bool posix_spawn_file_actions_addinherit_np_ptr_initialized = false;
if (UNLIKELY(!posix_spawn_file_actions_addinherit_np_ptr_initialized)) {
posix_spawn_file_actions_addinherit_np_ptr_initialized = true;
posix_spawn_file_actions_addinherit_np_ptr = dlsym(RTLD_DEFAULT, "posix_spawn_file_actions_addinherit_np");
}

if (UNLIKELY(posix_spawn_file_actions_addinherit_np_ptr == nullptr))
return 0;

return ((int (*)(void*, int))posix_spawn_file_actions_addinherit_np_ptr)(ptr, status);
}

extern "C" int posix_spawn_file_actions_addfchdir_np(void* ptr,
int fd)
{
static void* posix_spawn_file_actions_addfchdir_np_ptr = nullptr;
static bool posix_spawn_file_actions_addfchdir_np_ptr_initialized = false;
if (UNLIKELY(!posix_spawn_file_actions_addfchdir_np_ptr_initialized)) {
posix_spawn_file_actions_addfchdir_np_ptr_initialized = true;
posix_spawn_file_actions_addfchdir_np_ptr = dlsym(RTLD_DEFAULT, "posix_spawn_file_actions_addfchdir_np");
}

if (UNLIKELY(posix_spawn_file_actions_addfchdir_np_ptr == nullptr))
return 0;

return ((int (*)(void*, int))posix_spawn_file_actions_addfchdir_np_ptr)(ptr, fd);
}

#endif

0 comments on commit 18948cc

Please sign in to comment.