Skip to content

Commit

Permalink
Improved custom named libGL handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitSeb committed Jun 1, 2021
1 parent 9715a2f commit 656e755
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
6 changes: 5 additions & 1 deletion src/librarian/library.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,16 @@ static void initEmulatedLib(const char* path, library_t *lib, box86context_t* co
loadEmulatedLib(libname, lib, context);
}

extern char* libGL;
library_t *NewLibrary(const char* path, box86context_t* context)
{
printf_log(LOG_DEBUG, "Trying to load \"%s\"\n", path);
library_t *lib = (library_t*)calloc(1, sizeof(library_t));
lib->path = strdup(path);
lib->name = Path2Name(path);
if(libGL && !strcmp(path, libGL))
lib->name = strdup("libGL.so.1");
else
lib->name = Path2Name(path);
lib->nbdot = NbDot(lib->name);
lib->context = context;
lib->type = -1;
Expand Down
31 changes: 21 additions & 10 deletions src/wrapped/wrappedsdl2.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
#include "myalign.h"
#include "threads.h"

static void* my_glhandle = NULL;
// DL functions from wrappedlibdl.c
void* my_dlopen(x86emu_t* emu, void *filename, int flag);
int my_dlclose(x86emu_t* emu, void *handle);
void* my_dlsym(x86emu_t* emu, void *handle, void *symbol);

static int sdl_Yes() { return 1;}
static int sdl_No() { return 0;}
int EXPORT my2_SDL_Has3DNow() __attribute__((alias("sdl_No")));
Expand Down Expand Up @@ -679,6 +685,7 @@ EXPORT void my2_SDL_Log(x86emu_t* emu, void* fmt, void *b) {
}

void fillGLProcWrapper(box86context_t*);
extern char* libGL;
EXPORT void* my2_SDL_GL_GetProcAddress(x86emu_t* emu, void* name)
{
khint_t k;
Expand All @@ -688,8 +695,14 @@ EXPORT void* my2_SDL_GL_GetProcAddress(x86emu_t* emu, void* name)
// check if glxprocaddress is filled, and search for lib and fill it if needed
if(!emu->context->glxprocaddress)
emu->context->glxprocaddress = (procaddess_t)my->SDL_GL_GetProcAddress;
if(!emu->context->glwrappers)
if(!emu->context->glwrappers) {
fillGLProcWrapper(emu->context);
// check if libGL is loaded, load it if not (helps DeadCells)
if(!my_glhandle && !GetLibInternal(libGL?libGL:"libGL.so.1")) {
// use a my_dlopen to actually open that lib, like SDL2 is doing...
my_glhandle = my_dlopen(emu, libGL?libGL:"libGL.so.1", RTLD_LAZY|RTLD_GLOBAL);
}
}
// get proc adress using actual glXGetProcAddress
k = kh_get(symbolmap, emu->context->glmymap, rname);
int is_my = (k==kh_end(emu->context->glmymap))?0:1;
Expand Down Expand Up @@ -848,10 +861,6 @@ EXPORT void my2_SDL_DelEventWatch(x86emu_t* emu, void* p, void* userdata)
my->SDL_DelEventWatch(find_eventfilter_Fct(p), userdata);
}

// DL functions from wrappedlibdl.c
void* my_dlopen(x86emu_t* emu, void *filename, int flag);
int my_dlclose(x86emu_t* emu, void *handle);
void* my_dlsym(x86emu_t* emu, void *handle, void *symbol);
EXPORT void* my2_SDL_LoadObject(x86emu_t* emu, void* sofile)
{
return my_dlopen(emu, sofile, 0); // TODO: check correct flag value...
Expand Down Expand Up @@ -975,11 +984,13 @@ EXPORT void* my2_SDL_Vulkan_GetVkGetInstanceProcAddr(x86emu_t* emu)
lib->priv.w.neededlibs[3] = strdup("libpthread.so.0");

#define CUSTOM_FINI \
((sdl2_my_t *)lib->priv.w.p2)->SDL_Quit(); \
freeSDL2My(lib->priv.w.p2); \
free(lib->priv.w.p2); \
((box86context_t*)(lib->context))->sdl2lib = NULL; \
((box86context_t*)(lib->context))->sdl2allocrw = NULL; \
((sdl2_my_t *)lib->priv.w.p2)->SDL_Quit(); \
if(my_glhandle) my_dlclose(thread_get_emu(), my_glhandle); \
my_glhandle = NULL; \
freeSDL2My(lib->priv.w.p2); \
free(lib->priv.w.p2); \
((box86context_t*)(lib->context))->sdl2lib = NULL; \
((box86context_t*)(lib->context))->sdl2allocrw = NULL; \
((box86context_t*)(lib->context))->sdl2freerw = NULL;


Expand Down

0 comments on commit 656e755

Please sign in to comment.