diff options
| author | ptitSeb <sebastien.chev@gmail.com> | 2024-12-18 17:15:21 +0100 |
|---|---|---|
| committer | ptitSeb <sebastien.chev@gmail.com> | 2024-12-18 17:15:21 +0100 |
| commit | 631da8a53231fb725fa9ed4db254c60b53621024 (patch) | |
| tree | 95da796e7926f2999c9c8fb8611f83a81998adb3 /src | |
| parent | f80886fd68893b82196cd9bd0f3faa36436e1b22 (diff) | |
| download | box64-631da8a53231fb725fa9ed4db254c60b53621024.tar.gz box64-631da8a53231fb725fa9ed4db254c60b53621024.zip | |
Added an helper function to abort and backtrace (used in [BOX32] when pointer address not 32bits compatible)
Diffstat (limited to 'src')
| -rw-r--r-- | src/include/box32.h | 5 | ||||
| -rw-r--r-- | src/libtools/signals.c | 34 |
2 files changed, 37 insertions, 2 deletions
diff --git a/src/include/box32.h b/src/include/box32.h index c8c7424f..d3b245f9 100644 --- a/src/include/box32.h +++ b/src/include/box32.h @@ -30,12 +30,13 @@ uintptr_t from_hash(ulong_t l); uintptr_t from_hash_d(ulong_t l); #ifdef TEST32 #include "debug.h" +void box64_abort(); static inline ptr_t to_ptr(uintptr_t p) { if(p!=0xffffffffffffffffLL && (p>>32)) { printf_log(LOG_NONE, "Warning, uintptr_t %p is not a 32bits value\n", (void*)p); #ifdef TEST_ABORT - abort(); + box64_abort(); #endif } return (ptr_t)p; @@ -45,7 +46,7 @@ static inline ptr_t to_ptrv(void* p2) { if(p!=0xffffffffffffffffLL && (p>>32)) { printf_log(LOG_NONE, "Warning, pointer %p is not a 32bits value\n", p2); #ifdef TEST_ABORT - abort(); + box64_abort(); #endif } return (ptr_t)p; diff --git a/src/libtools/signals.c b/src/libtools/signals.c index 290452a2..04702fe6 100644 --- a/src/libtools/signals.c +++ b/src/libtools/signals.c @@ -2376,6 +2376,40 @@ EXPORT void my_makecontext(x64emu_t* emu, void* ucp, void* fnc, int32_t argc, in u->uc_mcontext.gregs[X64_RSP] = (uintptr_t)rsp; } +void box64_abort() { + if(box64_showbt && LOG_INFO<=box64_log) { + // show native bt + #define BT_BUF_SIZE 100 + int nptrs; + void *buffer[BT_BUF_SIZE]; + char **strings; + x64emu_t* emu = thread_get_emu(); + +#ifndef ANDROID + nptrs = backtrace(buffer, BT_BUF_SIZE); + strings = backtrace_symbols(buffer, nptrs); + if(strings) { + for (int j = 0; j < nptrs; j++) + printf_log(LOG_INFO, "NativeBT: %s\n", strings[j]); + free(strings); + } else + printf_log(LOG_INFO, "NativeBT: none (%d/%s)\n", errno, strerror(errno)); +#endif + extern int my_backtrace_ip(x64emu_t* emu, void** buffer, int size); // in wrappedlibc + extern char** my_backtrace_symbols(x64emu_t* emu, uintptr_t* buffer, int size); + nptrs = my_backtrace_ip(emu, buffer, BT_BUF_SIZE); + strings = my_backtrace_symbols(emu, (uintptr_t*)buffer, nptrs); + if(strings) { + for (int j = 0; j < nptrs; j++) + printf_log(LOG_INFO, "EmulatedBT: %s\n", strings[j]); + free(strings); + } else + printf_log(LOG_INFO, "EmulatedBT: none\n"); + } + abort(); +} + + EXPORT int my_swapcontext(x64emu_t* emu, void* ucp1, void* ucp2) { // printf_log(LOG_NONE, "Warning: call to unimplemented swapcontext\n"); |