diff options
| author | ptitSeb <sebastien.chev@gmail.com> | 2021-06-03 15:31:22 +0200 |
|---|---|---|
| committer | ptitSeb <sebastien.chev@gmail.com> | 2021-06-03 15:31:22 +0200 |
| commit | b1b9d106564bbe091303c54556427ac3a1ec02ea (patch) | |
| tree | d1904cfa3a689b8e4c0d3aa24ec5683c041b1ed7 /src | |
| parent | 506f78eb32b94a6c553440317303c988cbdc0621 (diff) | |
| download | box64-b1b9d106564bbe091303c54556427ac3a1ec02ea.tar.gz box64-b1b9d106564bbe091303c54556427ac3a1ec02ea.zip | |
Added a wrokaround for libtinfo global variables
Diffstat (limited to 'src')
| -rwxr-xr-x | src/include/globalsymbols.h | 14 | ||||
| -rwxr-xr-x | src/librarian/globalsymbols.c | 90 | ||||
| -rwxr-xr-x | src/wrapped/wrappedlibncurses.c | 10 | ||||
| -rwxr-xr-x | src/wrapped/wrappedlibncurses6.c | 11 | ||||
| -rwxr-xr-x | src/wrapped/wrappedlibncurses6_private.h | 2 | ||||
| -rwxr-xr-x | src/wrapped/wrappedlibncurses_private.h | 2 | ||||
| -rwxr-xr-x | src/wrapped/wrappedlibncursesw.c | 11 | ||||
| -rwxr-xr-x | src/wrapped/wrappedlibncursesw_private.h | 2 |
8 files changed, 139 insertions, 3 deletions
diff --git a/src/include/globalsymbols.h b/src/include/globalsymbols.h new file mode 100755 index 00000000..e2bd19d3 --- /dev/null +++ b/src/include/globalsymbols.h @@ -0,0 +1,14 @@ +#ifndef _GLOBAL_SYMBOLS_H_ +#define _GLOBAL_SYMBOLS_H_ + +//GTK stuff +//void my_checkGlobalGdkDisplay(); +//void my_setGlobalGThreadsInit(); + +//void** my_GetGTKDisplay(); +//void** my_GetGthreadsGotInitialized(); // defined in wrappedgthread2 + +// NCurse / TInfo +void my_checkGlobalTInfo(); + +#endif //_GLOBAL_SYMBOLS_H_ \ No newline at end of file diff --git a/src/librarian/globalsymbols.c b/src/librarian/globalsymbols.c new file mode 100755 index 00000000..5b9b81d4 --- /dev/null +++ b/src/librarian/globalsymbols.c @@ -0,0 +1,90 @@ +#define _GNU_SOURCE +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <dlfcn.h> + +#include "wrappedlibs.h" + +#include "debug.h" +#include "wrapper.h" +#include "bridge.h" +#include "callback.h" +#include "box64context.h" +#include "librarian.h" +#include "library.h" + +// workaround for Globals symbols + +#define GLOB(A) \ + if (GetGlobalNoWeakSymbolStartEnd(my_context->maplib, #A, &globoffs, &globend, -1, NULL)) { \ + printf_log(LOG_DEBUG, "Global " #A " workaround, @%p <= %p\n", (void*)globoffs, &A); \ + memcpy((void*)globoffs, &A, sizeof(A)); \ + } + + +// *********** GTK ***************** +#if 0 +EXPORT void* gdk_display = NULL; // in case it's used... + +void my_checkGlobalGdkDisplay() +{ + uintptr_t globoffs, globend; + GLOB(gdk_display) +} + +void my_setGlobalGThreadsInit() +{ + int val = 1; + uintptr_t globoffs, globend; + if (GetGlobalNoWeakSymbolStartEnd(my_context->maplib, "g_threads_got_initialized", &globoffs, &globend, -1, NULL)) { + printf_log(LOG_DEBUG, "Global g_threads_got_initialized workaround, @%p <= %p\n", (void*)globoffs, (void*)val); + memcpy((void*)globoffs, &val, sizeof(val)); + } +} + +char* getGDKX11LibName(); +void** my_GetGTKDisplay() +{ + if(gdk_display) + return &gdk_display; + + char* name = getGDKX11LibName(); + library_t * lib = GetLibInternal(name?name:"libgtk-1.2.so.0"); + if(!lib) return &gdk_display; // mmm, that will crash later probably + void* s = dlsym(GetHandle(lib), "gdk_display"); + gdk_display = *(void**)s; + return s; +} + +#endif +// **************** NCurses **************** +EXPORT void* COLS; +EXPORT void* LINES; +EXPORT void* TABSIZE; +EXPORT void* curscr; +EXPORT void* newscr; +EXPORT void* stdscr; +EXPORT void* acs_map[128]; +EXPORT void* UP; +EXPORT void* BC; +EXPORT uint8_t PC; +EXPORT uint16_t ospeed; +EXPORT void* ttytype; + +void my_checkGlobalTInfo() +{ + uintptr_t globoffs, globend; + GLOB(COLS) + GLOB(LINES) + GLOB(TABSIZE) + GLOB(curscr) + GLOB(newscr) + GLOB(stdscr) + GLOB(acs_map) + GLOB(UP) + GLOB(BC) + GLOB(PC) + GLOB(ospeed) + GLOB(ttytype) +} \ No newline at end of file diff --git a/src/wrapped/wrappedlibncurses.c b/src/wrapped/wrappedlibncurses.c index c7a876b1..e9f49643 100755 --- a/src/wrapped/wrappedlibncurses.c +++ b/src/wrapped/wrappedlibncurses.c @@ -17,6 +17,7 @@ #include "box64context.h" #include "emu/x64emu_private.h" #include "myalign.h" +#include "globalsymbols.h" const char* libncursesName = "libncurses.so.5"; #define LIBNAME libncurses @@ -25,11 +26,13 @@ static library_t* my_lib = NULL; // this is a simple copy of libncursesw wrapper. TODO: check if ok +typedef void* (*pFv_t)(); typedef int (*iFppV_t)(void*, void*, va_list); typedef int (*iFpiip_t)(void*, int32_t, int32_t, void*); typedef int (*iFiipV_t)(int, int, void*, ...); #define SUPER() \ + GO(initscr, pFv_t) \ GO(mvwprintw, iFpiip_t) \ GO(vwprintw, iFppV_t) \ GO(stdscr, void*) \ @@ -104,6 +107,13 @@ EXPORT int my_mvprintw(x64emu_t* emu, int x, int y, void* fmt, void* b) return ret; } +EXPORT void* my_initscr() +{ + libncurses_my_t *my = (libncurses_my_t*)my_lib->priv.w.p2; + void* ret = my->initscr(); + my_checkGlobalTInfo(); + return ret; +} #define CUSTOM_INIT \ lib->priv.w.p2 = getNCursesMy(lib); \ diff --git a/src/wrapped/wrappedlibncurses6.c b/src/wrapped/wrappedlibncurses6.c index 243a26be..3878d159 100755 --- a/src/wrapped/wrappedlibncurses6.c +++ b/src/wrapped/wrappedlibncurses6.c @@ -17,6 +17,7 @@ #include "box64context.h" #include "emu/x64emu_private.h" #include "myalign.h" +#include "globalsymbols.h" const char* libncurses6Name = "libncurses.so.6"; #define LIBNAME libncurses6 @@ -25,10 +26,12 @@ static library_t* my_lib = NULL; // this is a simple copy of libncursesw wrapper. TODO: check if ok +typedef void* (*pFv_t)(); typedef int (*iFppV_t)(void*, void*, va_list); typedef int (*iFpiip_t)(void*, int32_t, int32_t, void*); #define SUPER() \ + GO(initscr, pFv_t) \ GO(mvwprintw, iFpiip_t) \ GO(vwprintw, iFppV_t) \ GO(stdscr, void*) @@ -87,6 +90,14 @@ EXPORT int my6_vwprintw(x64emu_t* emu, void* p, void* fmt, x64_va_list_t b) return my->vwprintw(p, fmt, VARARGS); } +EXPORT void* my6_initscr() +{ + libncurses6_my_t *my = (libncurses6_my_t*)my_lib->priv.w.p2; + void* ret = my->initscr(); + my_checkGlobalTInfo(); + return ret; +} + #define CUSTOM_INIT \ lib->priv.w.p2 = getNCurses6My(lib); \ my_lib = lib; \ diff --git a/src/wrapped/wrappedlibncurses6_private.h b/src/wrapped/wrappedlibncurses6_private.h index 1446bdec..d5e7a7a7 100755 --- a/src/wrapped/wrappedlibncurses6_private.h +++ b/src/wrapped/wrappedlibncurses6_private.h @@ -55,7 +55,7 @@ GO(immedok, vFpi) GO(inch, LFv) GO(inchnstr, iFpi) GO(inchstr, iFp) -GO(initscr, pFv) +GOM(initscr, pFv) GO(init_color, iFwwww) GO(init_pair, iFwww) GO(innstr, iFpi) diff --git a/src/wrapped/wrappedlibncurses_private.h b/src/wrapped/wrappedlibncurses_private.h index 82165dd0..a3701b22 100755 --- a/src/wrapped/wrappedlibncurses_private.h +++ b/src/wrapped/wrappedlibncurses_private.h @@ -55,7 +55,7 @@ GO(immedok, vFpi) GO(inch, LFv) GO(inchnstr, iFpi) GO(inchstr, iFp) -GO(initscr, pFv) +GOM(initscr, pFv) GO(init_color, iFwwww) GO(init_pair, iFwww) GO(innstr, iFpi) diff --git a/src/wrapped/wrappedlibncursesw.c b/src/wrapped/wrappedlibncursesw.c index 6628dc6f..402239c1 100755 --- a/src/wrapped/wrappedlibncursesw.c +++ b/src/wrapped/wrappedlibncursesw.c @@ -17,16 +17,19 @@ #include "box64context.h" #include "emu/x64emu_private.h" #include "myalign.h" +#include "globalsymbols.h" const char* libncurseswName = "libncursesw.so.5"; #define LIBNAME libncursesw static library_t* my_lib = NULL; +typedef void* (*pFv_t)(); typedef int (*iFppV_t)(void*, void*, va_list); typedef int (*iFpiip_t)(void*, int32_t, int32_t, void*); #define SUPER() \ + GO(initscr, pFv_t) \ GO(mvwprintw, iFpiip_t) \ GO(vwprintw, iFppV_t) \ GO(stdscr, void*) @@ -85,6 +88,14 @@ EXPORT int myw_vwprintw(x64emu_t* emu, void* p, void* fmt, x64_va_list_t b) return my->vwprintw(p, fmt, VARARGS); } +EXPORT void* myw_initscr() +{ + libncursesw_my_t *my = (libncursesw_my_t*)my_lib->priv.w.p2; + void* ret = my->initscr(); + my_checkGlobalTInfo(); + return ret; +} + #define CUSTOM_INIT \ lib->priv.w.p2 = getNCurseswMy(lib); \ my_lib = lib; \ diff --git a/src/wrapped/wrappedlibncursesw_private.h b/src/wrapped/wrappedlibncursesw_private.h index b204cfc2..c835bfc1 100755 --- a/src/wrapped/wrappedlibncursesw_private.h +++ b/src/wrapped/wrappedlibncursesw_private.h @@ -55,7 +55,7 @@ GO(immedok, vFpi) GO(inch, LFv) GO(inchnstr, iFpi) GO(inchstr, iFp) -GO(initscr, pFv) +GOM(initscr, pFv) GO(init_color, iFwwww) GO(init_pair, iFwww) GO(innstr, iFpi) |