Skip to content

Commit

Permalink
[BOX32][wrapper] Added some basic 32bits X11 wrapping, fixed 32bits s…
Browse files Browse the repository at this point in the history
…em_XXX wrapping, and more 32bits wrapped functions
  • Loading branch information
ptitSeb committed Sep 22, 2024
1 parent 710d537 commit d2aecc0
Show file tree
Hide file tree
Showing 30 changed files with 5,326 additions and 250 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,7 @@ if(BOX32)
"${BOX64_ROOT}/src/wrapped32/wrappedlibglu.c"
"${BOX64_ROOT}/src/wrapped32/wrappedsdl1.c"
"${BOX64_ROOT}/src/wrapped32/wrappedlibasound.c"
"${BOX64_ROOT}/src/wrapped32/wrappedlibx11.c"
)
endif()
string(REPLACE ".c" "_private.h" MODROOT ${BOX64_ROOT})
Expand Down
19 changes: 12 additions & 7 deletions rebuild_wrappers_32.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,8 @@ def __init__(self, name: str, repl: str) -> None:
# CONSTANT- rvalues: valid replacement values (outside of structures)
# CONSTANT- validrepl: valid replacement values (for structures)
# structs: structure ids and additional data
values: Sequence[str] = ['E', 'v', 'c', 'w', 'i', 'I', 'C', 'W', 'u', 'U', 'f', 'd', 'D', 'K', 'l', 'L', 'p', 'h', 'H', 'a', 'A', 'V', 'O', 'S', '2', 'P', 'N', 'M', 's', 'r', 'b', 'B', '_', 't']
rvalues: Sequence[str] = ['E', 'v', 'c', 'w', 'i', 'I', 'C', 'W', 'u', 'U', 'f', 'd', 'D', 'K', 'l', 'L', 'p', 'h', 'H', 'a', 'A', 'V', 'O', 'S', '2', 'P', 'N', 'M', 's', 'r', 'b', 'B', '_', 't']
values: Sequence[str] = ['E', 'v', 'c', 'w', 'i', 'I', 'C', 'W', 'u', 'U', 'f', 'd', 'D', 'K', 'l', 'L', 'p', 'h', 'H', 'a', 'A', 'V', 'O', 'S', '2', 'P', 'N', 'M', 's', 'r', 'b', 'B', '_', 't', 'X']
rvalues: Sequence[str] = ['E', 'v', 'c', 'w', 'i', 'I', 'C', 'W', 'u', 'U', 'f', 'd', 'D', 'K', 'l', 'L', 'p', 'h', 'H', 'a', 'A', 'V', 'O', 'S', '2', 'P', 'N', 'M', 's', 'r', 'b', 'B', '_', 't', 'X']
validrepl: Sequence[str] = ['c', 'w', 'i', 'I', 'C', 'W', 'u', 'U', 'f', 'd', 'D', 'K', 'l', 'L', 'p', 'h', 'H', 'a', 'A', 'V', 'O', 'S', '2', 'P', 'N', 'M', 's', 'r', 'b', 'B', '_']

def __init__(self) -> None:
Expand Down Expand Up @@ -1149,6 +1149,7 @@ def generate_files(root: str, files: Iterable[str], ver: str, gbls: SortedGlobal
"\n#error Invalid return type: wo structure declaration\n", # B
"\n#error Invalid return type: end of structure declaration\n", # _
"R_EAX = to_cstring(fn({0}));", # t
"\n#error Invalid return type: Display* declaration\n", # X
]
asargs = [
"emu, ", # E
Expand Down Expand Up @@ -1184,7 +1185,8 @@ def generate_files(root: str, files: Iterable[str], ver: str, gbls: SortedGlobal
"\n#error Invalid argument type: rw structure declaration\n", # b
"\n#error Invalid argument type: wo structure declaration\n", # B
"\n#error Invalid argument type: end of structure declaration\n", # _
"\n#error Invalid argument type: maybe-high string\n", # t
"\n#error Invalid argument type: maybe-high string\n",# t
"getDisplay(from_ptriv(R_ESP + {p})), ", # X
]
if len(FileSpec.values) != len(asreturns):
raise NotImplementedError("len(values) = {lenval} != len(asreturns) = {lenvals}".format(lenval=len(FileSpec.values), lenvals=len(asreturns)))
Expand Down Expand Up @@ -1292,6 +1294,8 @@ def generate_files(root: str, files: Iterable[str], ver: str, gbls: SortedGlobal
#define ST0val ST0.d
int of_convert32(int);
void* getDisplay(void*);
""",
"wrapper32.h": """
Expand Down Expand Up @@ -1331,6 +1335,7 @@ def generate_files(root: str, files: Iterable[str], ver: str, gbls: SortedGlobal
// B..._ = pointer to write-only structure
// b..._ = pointer to read-write structure
// t = char* as a return value (copies to a lower address if the return address is too high)
// X = Display*
""",
"converter32.c": """
Expand Down Expand Up @@ -1397,8 +1402,8 @@ def generate_files(root: str, files: Iterable[str], ver: str, gbls: SortedGlobal
files_guard[fhdr] = trim(files_guard[fhdr])

# Typedefs
# E v c w i I C W u U f d D K l L p h H a A V O S 2 P N M s r b B _ t
tdtypes = ["x64emu_t*", "void", "int8_t", "int16_t", "int32_t", "int64_t", "uint8_t", "uint16_t", "uint32_t", "uint64_t", "float", "double", "long double", "double", "intptr_t", "uintptr_t", "void*", "uintptr_t", "uintptr_t", "void*", "void*", "void*", "int32_t", "void*", "_2uint_struct_t", "void*", "...", "...", "void*", "\n#error _\n", "\n#error _\n", "\n#error _\n", "\n#error _\n", "char*"]
# E v c w i I C W u U f d D K l L p h H a A V O S 2 P N M s r b B _ t X
tdtypes = ["x64emu_t*", "void", "int8_t", "int16_t", "int32_t", "int64_t", "uint8_t", "uint16_t", "uint32_t", "uint64_t", "float", "double", "long double", "double", "intptr_t", "uintptr_t", "void*", "uintptr_t", "uintptr_t", "void*", "void*", "void*", "int32_t", "void*", "_2uint_struct_t", "void*", "...", "...", "void*", "\n#error _\n", "\n#error _\n", "\n#error _\n", "\n#error _\n", "char*", "void*"]
if len(FileSpec.values) != len(tdtypes):
raise NotImplementedError("len(values) = {lenval} != len(tdtypes) = {lentypes}".format(lenval=len(FileSpec.values), lentypes=len(tdtypes)))
def generate_typedefs(funs: Iterable[FunctionType], file):
Expand All @@ -1423,8 +1428,8 @@ def getstr(i: int, ct: CType) -> str:
for i in range(2, len(funtype.orig.replaced))) + ");\n")

# Wrappers
# E v c w i I C W u U f d D K l L p h H a A V O S 2 P N M s r b B _ t
deltas = [0, 4, 4, 4, 4, 8, 4, 4, 4, 8, 4, 8, 12, 12, 4, 4, 4, 4, 4, 4, 4, 1, 4, 4, 8, 4, 0, 0, 0, 1, 1, 4, 1, 4]
# E v c w i I C W u U f d D K l L p h H a A V O S 2 P N M s r b B _ t X
deltas = [0, 4, 4, 4, 4, 8, 4, 4, 4, 8, 4, 8, 12, 12, 4, 4, 4, 4, 4, 4, 4, 1, 4, 4, 8, 4, 0, 0, 0, 1, 1, 4, 1, 4, 4]
# Asserts
if len(FileSpec.values) != len(deltas):
raise NotImplementedError("len(values) = {lenval} != len(deltas) = {lendeltas}".format(lenval=len(FileSpec.values), lendeltas=len(deltas)))
Expand Down
2 changes: 1 addition & 1 deletion src/emu/x86int3.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ void x86Int3(x64emu_t* emu, uintptr_t* addr)
} else if(!strcmp(s, "vsscanf")) {
snprintf(buff, 255, "%04d|%p: Calling %s(\"%s\", \"%s\", ...)", tid, from_ptrv(*(ptr_t*)from_ptr(R_ESP)), s, from_ptrv(*(ptr_t*)from_ptr(R_ESP+4)), from_ptrv(*(ptr_t*)from_ptr(R_ESP+8)));
} else if(strstr(s, "XCreateWindow")==s) {
snprintf(buff, 255, "%04d|%p: Calling %s(%p, %p, %d, %d, %u, %u, %u, %d, %u, %p, %u, %p)", tid, from_ptrv(*(ptr_t*)from_ptr(R_ESP)), s, from_ptrv(*(ptr_t*)from_ptr(R_ESP+4)), from_ptrv(*(ptr_t*)from_ptr(R_ESP+8)), *(int*)from_ptr(R_ESP+12), *(int*)from_ptr(R_ESP+16), *(uint32_t*)from_ptr(R_ESP+20), *(uint32_t*)from_ptr(R_ESP+24), *(uint32_t*)from_ptr(R_ESP+28), *(int32_t*)from_ptr(R_ESP+32), *(uint32_t*)from_ptr(R_ESP+36), *(void**)from_ptr(R_ESP+40), *(uint32_t*)from_ptr(R_ESP+44), *(void**)from_ptr(R_ESP+48));
snprintf(buff, 255, "%04d|%p: Calling %s(%p, %p, %d, %d, %u, %u, %u, %d, %u, %p, 0x%x, %p)", tid, from_ptrv(*(ptr_t*)from_ptr(R_ESP)), s, from_ptrv(*(ptr_t*)from_ptr(R_ESP+4)), from_ptrv(*(ptr_t*)from_ptr(R_ESP+8)), *(int*)from_ptr(R_ESP+12), *(int*)from_ptr(R_ESP+16), *(uint32_t*)from_ptr(R_ESP+20), *(uint32_t*)from_ptr(R_ESP+24), *(uint32_t*)from_ptr(R_ESP+28), *(int32_t*)from_ptr(R_ESP+32), *(uint32_t*)from_ptr(R_ESP+36), from_ptrv(*(ptr_t*)from_ptr(R_ESP+40)), *(uint32_t*)from_ptr(R_ESP+44), from_ptrv(*(ptr_t*)from_ptr(R_ESP+48)));
} else if(strstr(s, "XLoadQueryFont")==s) {
snprintf(buff, 255, "%04d|%p: Calling %s(%p, \"%s\")", tid, from_ptrv(*(ptr_t*)from_ptr(R_ESP)), s, from_ptrv(*(ptr_t*)from_ptr(R_ESP+4)), from_ptrv(*(ptr_t*)from_ptr(R_ESP+8)));
} else if(strstr(s, "pthread_mutex_lock")==s || strstr(s, "pthread_mutex_unlock")==s) {
Expand Down
2 changes: 1 addition & 1 deletion src/include/box32.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static inline long_t to_long(long l) {
}
static inline ulong_t to_ulong(unsigned long l) {
if(l!=0xffffffffffffffffLL && (l>>32))
printf_log(LOG_NONE, "Warning, ulong 0x%p is not a 32bits value\n", (void*)l);
printf_log(LOG_NONE, "Warning, ulong %p is not a 32bits value\n", (void*)l);
return (ulong_t)l;
}
#else //TEST32
Expand Down
1 change: 1 addition & 0 deletions src/library_list_32.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ GO("libGLU.so.1", libglu)
GO("libSDL-1.2.so.0", sdl1)
GO("libasound.so.2", libasound)
GO("libasound.so", libasound)
GO("libX11.so.6", libx11)

GO("crashhandler.so", crashhandler)
Loading

0 comments on commit d2aecc0

Please sign in to comment.