Added a wrokaround for libtinfo global variables

This commit is contained in:
ptitSeb 2021-06-03 15:31:22 +02:00
parent 506f78eb32
commit b1b9d10656
9 changed files with 140 additions and 3 deletions

View File

@ -164,6 +164,7 @@ set(ELFLOADER_SRC
"${BOX64_ROOT}/src/librarian/librarian.c"
"${BOX64_ROOT}/src/librarian/library.c"
"${BOX64_ROOT}/src/librarian/dictionnary.c"
"${BOX64_ROOT}/src/librarian/globalsymbols.c"
"${BOX64_ROOT}/src/librarian/symbols.c"
"${BOX64_ROOT}/src/libtools/auxval.c"
"${BOX64_ROOT}/src/libtools/myalign.c"

14
src/include/globalsymbols.h Executable file
View File

@ -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_

90
src/librarian/globalsymbols.c Executable file
View File

@ -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)
}

View File

@ -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); \

View File

@ -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; \

View File

@ -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)

View File

@ -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)

View File

@ -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; \

View File

@ -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)