Skip to content

Commit

Permalink
Merge pull request #1290 from Sonicadvance1/thunk_init_constructor
Browse files Browse the repository at this point in the history
Thunks: Adds init helpers with function call
  • Loading branch information
Sonicadvance1 authored Oct 2, 2021
2 parents 8d13261 + cab0cf6 commit 98bee5a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
38 changes: 36 additions & 2 deletions ThunkLibs/include/common/Guest.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,39 @@ struct LoadlibArgs {
uintptr_t CallbackThunks;
};

#define LOAD_LIB(name) MAKE_THUNK(fex, loadlib, "0x27, 0x7e, 0xb7, 0x69, 0x5b, 0xe9, 0xab, 0x12, 0x6e, 0xf7, 0x85, 0x9d, 0x4b, 0xc9, 0xa2, 0x44, 0x46, 0xcf, 0xbd, 0xb5, 0x87, 0x43, 0xef, 0x28, 0xa2, 0x65, 0xba, 0xfc, 0x89, 0x0f, 0x77, 0x80") __attribute__((constructor)) static void loadlib() { LoadlibArgs args = { #name, 0 }; fexthunks_fex_loadlib(&args); }
#define LOAD_LIB_WITH_CALLBACKS(name) MAKE_THUNK(fex, loadlib, "0x27, 0x7e, 0xb7, 0x69, 0x5b, 0xe9, 0xab, 0x12, 0x6e, 0xf7, 0x85, 0x9d, 0x4b, 0xc9, 0xa2, 0x44, 0x46, 0xcf, 0xbd, 0xb5, 0x87, 0x43, 0xef, 0x28, 0xa2, 0x65, 0xba, 0xfc, 0x89, 0x0f, 0x77, 0x80") __attribute__((constructor)) static void loadlib() { LoadlibArgs args = { #name, (uintptr_t)&callback_unpacks }; fexthunks_fex_loadlib(&args); }
#define LOAD_LIB(name) \
MAKE_THUNK(fex, loadlib, "0x27, 0x7e, 0xb7, 0x69, 0x5b, 0xe9, 0xab, 0x12, 0x6e, 0xf7, 0x85, 0x9d, 0x4b, 0xc9, 0xa2, 0x44, 0x46, 0xcf, 0xbd, 0xb5, 0x87, 0x43, 0xef, 0x28, 0xa2, 0x65, 0xba, 0xfc, 0x89, 0x0f, 0x77, 0x80") \
__attribute__((constructor)) static void loadlib() \
{ \
LoadlibArgs args = { #name, 0 }; \
fexthunks_fex_loadlib(&args); \
fex_malloc_NoOptimize(); \
}
#define LOAD_LIB_INIT(name, init_fn) \
MAKE_THUNK(fex, loadlib, "0x27, 0x7e, 0xb7, 0x69, 0x5b, 0xe9, 0xab, 0x12, 0x6e, 0xf7, 0x85, 0x9d, 0x4b, 0xc9, 0xa2, 0x44, 0x46, 0xcf, 0xbd, 0xb5, 0x87, 0x43, 0xef, 0x28, 0xa2, 0x65, 0xba, 0xfc, 0x89, 0x0f, 0x77, 0x80") \
__attribute__((constructor)) static void loadlib() \
{ \
LoadlibArgs args = { #name, 0 }; \
fexthunks_fex_loadlib(&args); \
init_fn (); \
fex_malloc_NoOptimize(); \
}

#define LOAD_LIB_WITH_CALLBACKS(name) \
MAKE_THUNK(fex, loadlib, "0x27, 0x7e, 0xb7, 0x69, 0x5b, 0xe9, 0xab, 0x12, 0x6e, 0xf7, 0x85, 0x9d, 0x4b, 0xc9, 0xa2, 0x44, 0x46, 0xcf, 0xbd, 0xb5, 0x87, 0x43, 0xef, 0x28, 0xa2, 0x65, 0xba, 0xfc, 0x89, 0x0f, 0x77, 0x80") \
__attribute__((constructor)) static void loadlib() \
{ \
LoadlibArgs args = { #name, (uintptr_t)&callback_unpacks }; \
fexthunks_fex_loadlib(&args); \
fex_malloc_NoOptimize(); \
}

#define LOAD_LIB_WITH_CALLBACKS_INIT(name, init_fn) \
MAKE_THUNK(fex, loadlib, "0x27, 0x7e, 0xb7, 0x69, 0x5b, 0xe9, 0xab, 0x12, 0x6e, 0xf7, 0x85, 0x9d, 0x4b, 0xc9, 0xa2, 0x44, 0x46, 0xcf, 0xbd, 0xb5, 0x87, 0x43, 0xef, 0x28, 0xa2, 0x65, 0xba, 0xfc, 0x89, 0x0f, 0x77, 0x80") \
__attribute__((constructor)) static void loadlib() \
{ \
LoadlibArgs args = { #name, (uintptr_t)&callback_unpacks }; \
fexthunks_fex_loadlib(&args); \
init_fn (); \
fex_malloc_NoOptimize(); \
}
7 changes: 7 additions & 0 deletions ThunkLibs/include/common/Host.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@ static fex_call_callback_t* call_guest;

#define EXPORTS(name) extern "C" { ExportEntry* fexthunks_exports_##name(void *a0, uintptr_t a1) { call_guest = (fex_call_callback_t*)a0; fexldr_init_##name(); return exports; } }
#define EXPORTS_WITH_CALLBACKS(name) extern "C" { ExportEntry* fexthunks_exports_##name(void *a0, uintptr_t a1) { call_guest = (fex_call_callback_t*)a0; (uintptr_t&)callback_unpacks = a1; fexldr_init_##name(); return exports; } }

#define LOAD_LIB_INIT(init_fn) \
__attribute__((constructor)) static void loadlib() \
{ \
init_fn (); \
}

0 comments on commit 98bee5a

Please sign in to comment.