Skip to content

Commit

Permalink
support multiple lib paths (for 32 bit)
Browse files Browse the repository at this point in the history
  • Loading branch information
Etaash-mathamsetty committed Dec 9, 2024
1 parent 6d4da00 commit e24ea28
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions src/gl/shim.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,37 @@
static void* handle = NULL;
static bool mangoHudLoaded = false;

// Load MangoHud after EGL/GLX functions have been intercepted
static void loadMangoHud(void);
static void loadMangoHud() {
if (mangoHudLoaded) return;

//allow user to load custom mangohud libs (useful for testing)
char *libdir = getenv("MANGOHUD_OPENGL_LIB");
// allow user to load custom mangohud libs (useful for testing)
char *libs = getenv("MANGOHUD_OPENGL_LIBS");
char *lib = NULL;

if (libdir)
if (libs)
{
handle = dlopen(libdir, RTLD_LAZY | RTLD_LOCAL | RTLD_DEEPBIND);
lib = strtok(libs, ":");

if (handle) mangoHudLoaded = true;
else {
fprintf(stderr, "shim: Failed to load from: %s\n", libdir);
libdir = NULL;
// when user specifies only one path
if (!lib) lib = libs;

while (lib != NULL)
{
handle = dlopen(lib, RTLD_LAZY | RTLD_LOCAL | RTLD_DEEPBIND);

if (handle)
{
mangoHudLoaded = true;
break;
}
else fprintf(stderr, "shim: Failed to load from: %s\n", lib);

lib = strtok(NULL, ":");
}
}

// Load MangoHud after GLX functions have been intercepted
if(!mangoHudLoaded)
{
handle = dlopen("${ORIGIN}/libMangoHud_opengl.so", RTLD_LAZY | RTLD_LOCAL | RTLD_DEEPBIND);
Expand All @@ -36,7 +48,7 @@ static void loadMangoHud() {

if (mangoHudLoaded) {
printf("shim: Loaded mangohud library\n");
if (libdir) printf("from custom location: %s\n", libdir);
if (lib) printf("from custom location: %s\n", lib);
}
}

Expand Down Expand Up @@ -90,7 +102,7 @@ unsigned int eglSwapBuffers(void* dpy, void* surf) {
// Get the hooked eglSwapBuffers function from the loaded library if available
unsigned int (*peglSwapBuffers)(void*, void*) = dlsym(handle, "eglSwapBuffers");
if (peglSwapBuffers) {
return peglSwapBuffers(dpy, surf);;
return peglSwapBuffers(dpy, surf);
} else {
// Fall back to the original eglSwapBuffers function
peglSwapBuffers = dlsym(RTLD_NEXT, "eglSwapBuffers");
Expand Down

0 comments on commit e24ea28

Please sign in to comment.