Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions PlayTools/PlayLoader.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include <Foundation/Foundation.h>
#include <errno.h>
#include <stdatomic.h>
#include <string.h>
#include <sys/sysctl.h>

#import "PlayLoader.h"
Expand Down Expand Up @@ -327,6 +329,33 @@ static int pt_usleep(useconds_t time) {
DYLD_INTERPOSE(pt_unlink, unlink)
DYLD_INTERPOSE(pt_usleep, usleep)

static _Atomic(void *) pt_ogles_handle = NULL;

// Redirect gl* dlsym(RTLD_DEFAULT, ...) lookups to OpenGLES when loaded so macOS libGL.dylib does not shadow it.
static void *pt_dlsym(void *handle, const char *symbol) {
if (handle == RTLD_DEFAULT && symbol != NULL && strncmp(symbol, "gl", 2) == 0) {
void *ogles = atomic_load_explicit(&pt_ogles_handle, memory_order_relaxed);
if (ogles == NULL) {
ogles = dlopen("/System/iOSSupport/System/Library/Frameworks/OpenGLES.framework/OpenGLES", RTLD_LAZY | RTLD_NOLOAD);
if (ogles == NULL) {
ogles = dlopen("/System/Library/Frameworks/OpenGLES.framework/OpenGLES", RTLD_LAZY | RTLD_NOLOAD);
}
if (ogles != NULL) {
atomic_store_explicit(&pt_ogles_handle, ogles, memory_order_relaxed);
}
}
if (ogles != NULL) {
void *sym = dlsym(ogles, symbol);
if (sym != NULL) {
return sym;
}
}
}
return dlsym(handle, symbol);
}

DYLD_INTERPOSE(pt_dlsym, dlsym)

@implementation PlayLoader

static void __attribute__((constructor)) initialize(void) {
Expand Down