Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various box32 wrapped libs and script fixes #1889

Merged
merged 3 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions rebuild_wrappers_32.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ def __init__(self, name_t: Tuple[str, 'CType.ReadWrite'], clause: Clause, filesp
self.structname = self.name
self.structname2 = self.name
elif self.type is CType.ReadWrite.readonly:
self.structname = "s" + self.name + "_"
self.structname = "r" + self.name + "_"
self.structname2 = "struct_" + self.name
elif self.type is CType.ReadWrite.writeonly:
self.structname = "B" + self.name + "_"
Expand Down Expand Up @@ -556,7 +556,7 @@ def generate_converters(self) -> None:

self.asret = "\n#error TODO? Cannot return custom structure\n"
self.aspre = f"struct_{self.name}_t arg_{{p}}={{{{0}}}}; " + ("" if not self.type.pre else \
f"from_{self.structname2}(&arg_{{p}}, *(ptr_t*)(from_ptr((R_ESP + {{p}})))); ")
f"if (*(ptr_t*)(from_ptr((R_ESP + {{p}})))) from_{self.structname2}(&arg_{{p}}, *(ptr_t*)(from_ptr((R_ESP + {{p}})))); ")
self.asarg = "*(ptr_t*)(from_ptr((R_ESP + {p}))) ? &arg_{p} : NULL, "
self.aspost = "" if not self.type.post else \
(" if (*(ptr_t*)(from_ptr((R_ESP + {p})))) to_" + self.structname2 + \
Expand Down Expand Up @@ -632,11 +632,11 @@ def __init__(self, string: str, clause: Clause, filespec: FileSpec) -> None:
raise NotImplementedError("x64emu_t* not as the first parameter")
if len(self.orig.replaced) < 4:
raise NotImplementedError("Type {0} too short".format(self.orig.replaced))
chk_type = self.orig.recursive[0].name + ''.join(map(lambda ct: ct.name, self.orig.recursive[3:]))
chk_type = self.orig.recursive[0].structname + ''.join(map(lambda ct: ct.structname, self.orig.recursive[3:]))
else:
if len(self.orig.replaced) < 3:
raise NotImplementedError("Type {0} too short".format(self.orig.replaced))
chk_type = self.orig.recursive[0].name + ''.join(map(lambda ct: ct.name, self.orig.recursive[2:]))
chk_type = self.orig.recursive[0].structname + ''.join(map(lambda ct: ct.structname, self.orig.recursive[2:]))
self.withoutE = _BareFunctionType(string[0:2] + chk_type[1:], clause, filespec, isinstance(self, StructFunctionType))
self._bare = _BareFunctionType(self.orig.name, clause, filespec, isinstance(self, StructFunctionType))
if len(chk_type) < 2:
Expand Down Expand Up @@ -1392,9 +1392,9 @@ def generate_files(root: str, files: Iterable[str], ver: str, gbls: SortedGlobal
#endif // __{filename}UNDEFS32_H_
"""
}
banner = "/********************************************************" + ('*'*len(ver)) + "***\n" \
banner = "/***********************************************************" + ('*'*len(ver)) + "***\n" \
" * File automatically generated by rebuild_wrappers_32.py (v" + ver + ") *\n" \
" ********************************************************" + ('*'*len(ver)) + "***/\n"
" ***********************************************************" + ('*'*len(ver)) + "***/\n"
trim: Callable[[str], str] = lambda string: '\n'.join(line[2:] for line in string.splitlines())[1:]
# Yes, the for loops are inverted. This is because both dicts should have the same keys.
for fhdr in files_guard:
Expand Down Expand Up @@ -1636,6 +1636,6 @@ def main(root: str, files: Iterable[str], ver: str):
if v == "--":
limit.append(i)
Define.defines = list(map(DefineType, sys.argv[2:limit[0]]))
if main(sys.argv[1], sys.argv[limit[0]+1:], "0.0.1.1") != 0:
if main(sys.argv[1], sys.argv[limit[0]+1:], "0.0.2.2") != 0:
exit(2)
exit(0)
4 changes: 1 addition & 3 deletions src/libtools/signal32.c
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ EXPORT int my32_setcontext(x64emu_t* emu, void* ucp)
return R_EAX;
}

EXPORT int my32_makecontext(x64emu_t* emu, void* ucp, void* fnc, int32_t argc, int32_t* argv)
EXPORT void my32_makecontext(x64emu_t* emu, void* ucp, void* fnc, int32_t argc, int32_t* argv)
{
// printf_log(LOG_NONE, "Warning: call to unimplemented makecontext\n");
i386_ucontext_t *u = (i386_ucontext_t*)ucp;
Expand All @@ -906,8 +906,6 @@ EXPORT int my32_makecontext(x64emu_t* emu, void* ucp, void* fnc, int32_t argc, i
--esp;
*esp = to_ptr(my_context->exit_bridge);
u->uc_mcontext.gregs[I386_ESP] = (uintptr_t)esp;

return 0;
}

EXPORT int my32_swapcontext(x64emu_t* emu, void* ucp1, void* ucp2)
Expand Down
4 changes: 1 addition & 3 deletions src/libtools/signals.c
Original file line number Diff line number Diff line change
Expand Up @@ -2240,7 +2240,7 @@ EXPORT int my_setcontext(x64emu_t* emu, void* ucp)
return R_EAX;
}

EXPORT int my_makecontext(x64emu_t* emu, void* ucp, void* fnc, int32_t argc, int64_t* argv)
EXPORT void my_makecontext(x64emu_t* emu, void* ucp, void* fnc, int32_t argc, int64_t* argv)
{
// printf_log(LOG_NONE, "Warning: call to unimplemented makecontext\n");
x64_ucontext_t *u = (x64_ucontext_t*)ucp;
Expand Down Expand Up @@ -2276,8 +2276,6 @@ EXPORT int my_makecontext(x64emu_t* emu, void* ucp, void* fnc, int32_t argc, int
--rsp;
*rsp = my_context->exit_bridge;
u->uc_mcontext.gregs[X64_RSP] = (uintptr_t)rsp;

return 0;
}

EXPORT int my_swapcontext(x64emu_t* emu, void* ucp1, void* ucp2)
Expand Down
10 changes: 5 additions & 5 deletions src/wrapped/wrappedlibdl_private.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#if defined(GO) && defined(GOM) && defined(GO2) && defined(DATA)
#if !(defined(GO) && defined(GOM) && defined(GO2) && defined(DATA))
#error Meh...
#endif

GOM(dladdr, iFEpp)
GOM(dladdr1, iFEpppi)
GOM(dlclose, iFEp)
GOM(dlerror, pFEv)
#ifdef STATICBUILD
//DATAB(_dlfcn_hook, sizeof(void*))
//DATAB(_dlfcn_hook, 8)
#else
DATAB(_dlfcn_hook, sizeof(void*))
DATAB(_dlfcn_hook, 8)
#endif
GOM(dlinfo, iFEpip)
GOM(dlmopen, pFEppi)
GOM(dlopen, pFEpi)
GOM(dlsym, pFEpp)
GOM(dlvsym, pFEppp) // Weak
GOM(_dl_find_object, iFEpp)

#endif
3 changes: 2 additions & 1 deletion src/wrapped/wrappedlibgl_private.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#if !(defined(GO) && defined(GOM) && defined(GO2) && defined(DATA))
#error meh!
#error Meh...
#endif

//VERSION_1_0
GO(glAccum, vFuf)
GO(glAlphaFunc, vFuf)
Expand Down
24 changes: 24 additions & 0 deletions src/wrapped32/generated/converter32.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ void to_struct_p(ptr_t d, const struct_p_t *src) {
*(ptr_t*)dest = to_ptrv(src->p0); dest += 4;
}

void from_struct_l(struct_l_t *dest, ptr_t s) {
if(!s) return;
uint8_t* src = (uint8_t*)from_ptrv(s);
dest->L0 = from_long(*(long_t*)src); src += 4;
}
void to_struct_l(ptr_t d, const struct_l_t *src) {
if (!src) return;
uint8_t* dest = (uint8_t*)from_ptrv(d);
*(long_t*)dest = to_long(src->L0); dest += 4;
}

void from_struct_L(struct_L_t *dest, ptr_t s) {
if(!s) return;
uint8_t* src = (uint8_t*)from_ptrv(s);
Expand All @@ -22,6 +33,19 @@ void to_struct_L(ptr_t d, const struct_L_t *src) {
*(ulong_t*)dest = to_ulong(src->L0); dest += 4;
}

void from_struct_ll(struct_ll_t *dest, ptr_t s) {
if(!s) return;
uint8_t* src = (uint8_t*)from_ptrv(s);
dest->L0 = from_long(*(long_t*)src); src += 4;
dest->L1 = from_long(*(long_t*)src); src += 4;
}
void to_struct_ll(ptr_t d, const struct_ll_t *src) {
if (!src) return;
uint8_t* dest = (uint8_t*)from_ptrv(d);
*(long_t*)dest = to_long(src->L0); dest += 4;
*(long_t*)dest = to_long(src->L1); dest += 4;
}

void from_struct_LL(struct_LL_t *dest, ptr_t s) {
if(!s) return;
uint8_t* src = (uint8_t*)from_ptrv(s);
Expand Down
11 changes: 11 additions & 0 deletions src/wrapped32/generated/converter32.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,22 @@ typedef struct struct_p_s {
} struct_p_t;
void from_struct_p(struct_p_t *dest, ptr_t src);
void to_struct_p(ptr_t dest, const struct_p_t *src);
typedef struct struct_l_s {
long L0;
} struct_l_t;
void from_struct_l(struct_l_t *dest, ptr_t src);
void to_struct_l(ptr_t dest, const struct_l_t *src);
typedef struct struct_L_s {
unsigned long L0;
} struct_L_t;
void from_struct_L(struct_L_t *dest, ptr_t src);
void to_struct_L(ptr_t dest, const struct_L_t *src);
typedef struct struct_ll_s {
long L0;
long L1;
} struct_ll_t;
void from_struct_ll(struct_ll_t *dest, ptr_t src);
void to_struct_ll(ptr_t dest, const struct_ll_t *src);
typedef struct struct_LL_s {
unsigned long L0;
unsigned long L1;
Expand Down
Loading