Skip to content

Commit 736552a

Browse files
committed
Added preliminary support for wrapped libEGL
1 parent 162abb0 commit 736552a

13 files changed

+273
-1
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ set(WRAPPEDS
313313
"${BOX64_ROOT}/src/wrapped/wrappedlibform.c"
314314
"${BOX64_ROOT}/src/wrapped/wrappedlibformw.c"
315315
"${BOX64_ROOT}/src/wrapped/wrappedlibfuse.c"
316+
"${BOX64_ROOT}/src/wrapped/wrappedlibegl.c"
316317
"${BOX64_ROOT}/src/wrapped/wrappedlibgl.c"
317318
"${BOX64_ROOT}/src/wrapped/wrappedlibglu.c"
318319
"${BOX64_ROOT}/src/wrapped/wrappedlibice.c"

rebuild_wrappers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ def add_symbol_name(funname: Union[str, None], funsname: Dict[ClausesStr, List[s
388388
or match("sdl1mixer", "sdl2mixer") \
389389
or match("sdl1net", "sdl2net") \
390390
or match("sdl1ttf", "sdl2ttf") \
391+
or match("libGL", "libEGL") \
391392
or match("libc", "tcmallocminimal"):
392393
continue
393394

src/library_list.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
GO("libc.so.6", libc)
66
GO("libpthread.so.0", libpthread)
77
GO("librt.so.1", librt)
8+
GO("libEGL.so.1", libegl)
89
GO("libGL.so.1", libgl)
910
GO("libGL.so", libgl)
1011
GO("libOpenGL.so.0", libgl)

src/wrapped/generated/functions_list.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,6 +1413,7 @@
14131413
#() iFpUUUip
14141414
#() iFpUUUUp
14151415
#() iFpLLppp
1416+
#() iFppiiii
14161417
#() iFppiiip
14171418
#() iFppiiuu
14181419
#() iFppiipi
@@ -2905,6 +2906,9 @@ wrappedlibdl:
29052906
- iFpppi:
29062907
- dladdr1
29072908
wrappedlibdrm:
2909+
wrappedlibegl:
2910+
- pFp:
2911+
- eglGetProcAddress
29082912
wrappedlibform:
29092913
wrappedlibformw:
29102914
wrappedlibfuse:
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*******************************************************************
2+
* File automatically generated by rebuild_wrappers.py (v2.1.0.16) *
3+
*******************************************************************/
4+
#ifndef __wrappedlibeglDEFS_H_
5+
#define __wrappedlibeglDEFS_H_
6+
7+
8+
#endif // __wrappedlibeglDEFS_H_
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*******************************************************************
2+
* File automatically generated by rebuild_wrappers.py (v2.1.0.16) *
3+
*******************************************************************/
4+
#ifndef __wrappedlibeglTYPES_H_
5+
#define __wrappedlibeglTYPES_H_
6+
7+
#ifndef LIBNAME
8+
#error You should only #include this file inside a wrapped*.c file
9+
#endif
10+
#ifndef ADDED_FUNCTIONS
11+
#define ADDED_FUNCTIONS()
12+
#endif
13+
14+
typedef void* (*pFp_t)(void*);
15+
16+
#define SUPER() ADDED_FUNCTIONS() \
17+
GO(eglGetProcAddress, pFp_t)
18+
19+
#endif // __wrappedlibeglTYPES_H_
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*******************************************************************
2+
* File automatically generated by rebuild_wrappers.py (v2.1.0.16) *
3+
*******************************************************************/
4+
#ifndef __wrappedlibeglUNDEFS_H_
5+
#define __wrappedlibeglUNDEFS_H_
6+
7+
8+
#endif // __wrappedlibeglUNDEFS_H_

src/wrapped/generated/wrapper.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,6 +1447,7 @@ typedef int64_t (*iFpUuupp_t)(void*, uint64_t, uint64_t, uint64_t, void*, void*)
14471447
typedef int64_t (*iFpUUUip_t)(void*, uint64_t, uint64_t, uint64_t, int64_t, void*);
14481448
typedef int64_t (*iFpUUUUp_t)(void*, uint64_t, uint64_t, uint64_t, uint64_t, void*);
14491449
typedef int64_t (*iFpLLppp_t)(void*, uintptr_t, uintptr_t, void*, void*, void*);
1450+
typedef int64_t (*iFppiiii_t)(void*, void*, int64_t, int64_t, int64_t, int64_t);
14501451
typedef int64_t (*iFppiiip_t)(void*, void*, int64_t, int64_t, int64_t, void*);
14511452
typedef int64_t (*iFppiiuu_t)(void*, void*, int64_t, int64_t, uint64_t, uint64_t);
14521453
typedef int64_t (*iFppiipi_t)(void*, void*, int64_t, int64_t, void*, int64_t);
@@ -3535,6 +3536,7 @@ void iFpUuupp(x64emu_t *emu, uintptr_t fcn) { iFpUuupp_t fn = (iFpUuupp_t)fcn; R
35353536
void iFpUUUip(x64emu_t *emu, uintptr_t fcn) { iFpUUUip_t fn = (iFpUUUip_t)fcn; R_RAX=(int64_t)fn((void*)R_RDI, (uint64_t)R_RSI, (uint64_t)R_RDX, (uint64_t)R_RCX, (int64_t)R_R8, (void*)R_R9); }
35363537
void iFpUUUUp(x64emu_t *emu, uintptr_t fcn) { iFpUUUUp_t fn = (iFpUUUUp_t)fcn; R_RAX=(int64_t)fn((void*)R_RDI, (uint64_t)R_RSI, (uint64_t)R_RDX, (uint64_t)R_RCX, (uint64_t)R_R8, (void*)R_R9); }
35373538
void iFpLLppp(x64emu_t *emu, uintptr_t fcn) { iFpLLppp_t fn = (iFpLLppp_t)fcn; R_RAX=(int64_t)fn((void*)R_RDI, (uintptr_t)R_RSI, (uintptr_t)R_RDX, (void*)R_RCX, (void*)R_R8, (void*)R_R9); }
3539+
void iFppiiii(x64emu_t *emu, uintptr_t fcn) { iFppiiii_t fn = (iFppiiii_t)fcn; R_RAX=(int64_t)fn((void*)R_RDI, (void*)R_RSI, (int64_t)R_RDX, (int64_t)R_RCX, (int64_t)R_R8, (int64_t)R_R9); }
35383540
void iFppiiip(x64emu_t *emu, uintptr_t fcn) { iFppiiip_t fn = (iFppiiip_t)fcn; R_RAX=(int64_t)fn((void*)R_RDI, (void*)R_RSI, (int64_t)R_RDX, (int64_t)R_RCX, (int64_t)R_R8, (void*)R_R9); }
35393541
void iFppiiuu(x64emu_t *emu, uintptr_t fcn) { iFppiiuu_t fn = (iFppiiuu_t)fcn; R_RAX=(int64_t)fn((void*)R_RDI, (void*)R_RSI, (int64_t)R_RDX, (int64_t)R_RCX, (uint64_t)R_R8, (uint64_t)R_R9); }
35403542
void iFppiipi(x64emu_t *emu, uintptr_t fcn) { iFppiipi_t fn = (iFppiipi_t)fcn; R_RAX=(int64_t)fn((void*)R_RDI, (void*)R_RSI, (int64_t)R_RDX, (int64_t)R_RCX, (void*)R_R8, (int64_t)R_R9); }
@@ -5423,6 +5425,7 @@ int isSimpleWrapper(wrapper_t fun) {
54235425
if (fun == &iFpUUUip) return 1;
54245426
if (fun == &iFpUUUUp) return 1;
54255427
if (fun == &iFpLLppp) return 1;
5428+
if (fun == &iFppiiii) return 1;
54265429
if (fun == &iFppiiip) return 1;
54275430
if (fun == &iFppiiuu) return 1;
54285431
if (fun == &iFppiipi) return 1;

src/wrapped/generated/wrapper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,6 +1446,7 @@ void iFpUuupp(x64emu_t *emu, uintptr_t fnc);
14461446
void iFpUUUip(x64emu_t *emu, uintptr_t fnc);
14471447
void iFpUUUUp(x64emu_t *emu, uintptr_t fnc);
14481448
void iFpLLppp(x64emu_t *emu, uintptr_t fnc);
1449+
void iFppiiii(x64emu_t *emu, uintptr_t fnc);
14491450
void iFppiiip(x64emu_t *emu, uintptr_t fnc);
14501451
void iFppiiuu(x64emu_t *emu, uintptr_t fnc);
14511452
void iFppiipi(x64emu_t *emu, uintptr_t fnc);

src/wrapped/wrappedlibegl.c

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
#define _GNU_SOURCE /* See feature_test_macros(7) */
5+
#include <dlfcn.h>
6+
7+
#include "wrappedlibs.h"
8+
9+
#include "debug.h"
10+
#include "wrapper.h"
11+
#include "bridge.h"
12+
#include "librarian/library_private.h"
13+
#include "x64emu.h"
14+
#include "emu/x64emu_private.h"
15+
#include "box64context.h"
16+
#include "librarian.h"
17+
#include "callback.h"
18+
19+
const char* libeglName = "libEGL.so.1";
20+
#define LIBNAME libegl
21+
22+
#include "generated/wrappedlibegltypes.h"
23+
24+
#include "wrappercallback.h"
25+
26+
// FIXME: old wrapped* type of file, cannot use generated/wrappedlibgltypes.h
27+
28+
void fillGLProcWrapper(box64context_t*);
29+
void freeProcWrapper(kh_symbolmap_t** symbolmap);
30+
31+
EXPORT void* my_eglGetProcAddress(x64emu_t* emu, void* name)
32+
{
33+
khint_t k;
34+
const char* rname = (const char*)name;
35+
if(dlsym_error && box64_log<LOG_DEBUG) printf_log(LOG_NONE, "Calling eglGetProcAddress(\"%s\") => ", rname);
36+
if(!emu->context->glwrappers)
37+
fillGLProcWrapper(emu->context);
38+
// check if glxprocaddress is filled, and search for lib and fill it if needed
39+
// get proc adress using actual glXGetProcAddress
40+
k = kh_get(symbolmap, emu->context->glmymap, rname);
41+
int is_my = (k==kh_end(emu->context->glmymap))?0:1;
42+
void* symbol;
43+
if(is_my) {
44+
// try again, by using custom "my_" now...
45+
char tmp[200];
46+
strcpy(tmp, "my_");
47+
strcat(tmp, rname);
48+
symbol = dlsym(emu->context->box64lib, tmp);
49+
} else
50+
symbol = my->eglGetProcAddress((void*)rname);
51+
if(!symbol) {
52+
if(dlsym_error && box64_log<LOG_DEBUG) printf_log(LOG_NONE, "%p\n", NULL);
53+
return NULL; // easy
54+
}
55+
// check if alread bridged
56+
uintptr_t ret = CheckBridged(emu->context->system, symbol);
57+
if(ret) {
58+
if(dlsym_error && box64_log<LOG_DEBUG) printf_log(LOG_NONE, "%p\n", (void*)ret);
59+
return (void*)ret; // already bridged
60+
}
61+
// get wrapper
62+
k = kh_get(symbolmap, emu->context->glwrappers, rname);
63+
if(k==kh_end(emu->context->glwrappers) && strstr(rname, "ARB")==NULL) {
64+
// try again, adding ARB at the end if not present
65+
char tmp[200];
66+
strcpy(tmp, rname);
67+
strcat(tmp, "ARB");
68+
k = kh_get(symbolmap, emu->context->glwrappers, tmp);
69+
}
70+
if(k==kh_end(emu->context->glwrappers) && strstr(rname, "EXT")==NULL) {
71+
// try again, adding EXT at the end if not present
72+
char tmp[200];
73+
strcpy(tmp, rname);
74+
strcat(tmp, "EXT");
75+
k = kh_get(symbolmap, emu->context->glwrappers, tmp);
76+
}
77+
if(k==kh_end(emu->context->glwrappers)) {
78+
if(dlsym_error && box64_log<LOG_DEBUG) printf_log(LOG_NONE, "%p\n", NULL);
79+
if(dlsym_error && box64_log<LOG_INFO) printf_log(LOG_NONE, "Warning, no wrapper for %s\n", rname);
80+
return NULL;
81+
}
82+
const char* constname = kh_key(emu->context->glwrappers, k);
83+
AddOffsetSymbol(emu->context->maplib, symbol, rname);
84+
ret = AddBridge(emu->context->system, kh_value(emu->context->glwrappers, k), symbol, 0, constname);
85+
if(dlsym_error && box64_log<LOG_DEBUG) printf_log(LOG_NONE, "%p\n", (void*)ret);
86+
return (void*)ret;
87+
88+
}
89+
90+
91+
#define CUSTOM_INIT \
92+
getMy(lib); \
93+
if (!box64->glxprocaddress) \
94+
box64->glxprocaddress = (procaddess_t)my->eglGetProcAddress;
95+
96+
#define CUSTOM_FINI \
97+
freeMy();
98+
99+
100+
#include "wrappedlib_init.h"

0 commit comments

Comments
 (0)