From fa87b0fcef3dff593a507b3200ef83d846101d64 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Sat, 17 Aug 2024 12:24:26 +0200 Subject: [BOX32] prepare elfheader_t structure for 32bits elfs --- src/include/box32.h | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 src/include/box32.h (limited to 'src/include/box32.h') diff --git a/src/include/box32.h b/src/include/box32.h new file mode 100644 index 00000000..ab8fa184 --- /dev/null +++ b/src/include/box32.h @@ -0,0 +1,112 @@ +#ifndef __BOX32_64__H_ +#define __BOX32_64__H_ + +#include +#include + +#ifndef BOX32_DEF +#define BOX32_DEF +typedef uint32_t ptr_t; +typedef int32_t long_t; +typedef uint32_t ulong_t; +#endif + +#define TEST32 +#define TEST_ABORT + +static inline uintptr_t from_ptr(ptr_t p) { + return (uintptr_t)p; +} +static inline void* from_ptrv(ptr_t p) { + return (void*)(uintptr_t)p; +} +static inline long from_long(long_t l) { + return (long)l; +} +static inline unsigned long from_ulong(ulong_t l) { + return (unsigned long)l; +} +uintptr_t from_hash(ulong_t l); +uintptr_t from_hash_d(ulong_t l); +#ifdef TEST32 +#include "debug.h" + +static inline ptr_t to_ptr(uintptr_t p) { + if(p!=0xffffffffffffffffLL && (p>>32)) { + printf_log(LOG_NONE, "Warning, pointer %p is not a 32bits value\n", (void*)p); + #ifdef TEST_ABORT + abort(); + #endif + } + return (ptr_t)p; +} +static inline ptr_t to_ptrv(void* p2) { + uintptr_t p = (uintptr_t)p2; + if(p!=0xffffffffffffffffLL && (p>>32)) { + printf_log(LOG_NONE, "Warning, pointer %p is not a 32bits value\n", (void*)p); + #ifdef TEST_ABORT + abort(); + #endif + } + return (ptr_t)p; +} +static inline long_t to_long(long l) { + long_t ret = (long_t)l; + if(l!=ret) + printf_log(LOG_NONE, "Warning, long %ld is not a 32bits value\n", l); + return ret; +} +static inline ulong_t to_ulong(unsigned long l) { + if(l!=0xffffffffffffffffLL && (l>>32)) + printf_log(LOG_NONE, "Warning, long 0x%p is not a 32bits value\n", (void*)l); + return (ulong_t)l; +} +#else //TEST32 +static inline ptr_t to_ptr(uintptr_t p) { + return (ptr_t)p; +} +static inline ptr_t to_ptrv(void* p) { + return (ptr_t)(uintptr_t)p; +} +static inline long_t to_long(long l) { + return (long_t)l; +} +static inline ulong_t to_ulong(unsigned long l) { + return (ulong_t)l; +} +#endif //TEST32 + +static inline ptr_t to_ptr_silent(uintptr_t p) { + return (ptr_t)p; +} +static inline ptr_t to_ptrv_silent(void* p) { + return (ptr_t)(uintptr_t)p; +} +// indirect l -> T +#define from_ptri(T, l) *(T*)from_ptr(l) +// indirect l -> void* +static inline void* from_ptriv(ptr_t l) { + return from_ptrv(from_ptri(ptr_t, l)); +} + +ulong_t to_hash(uintptr_t p); +ulong_t to_hash_d(uintptr_t p); +static inline ulong_t to_hashv(void* p) {return to_hash((uintptr_t)p);} +static inline ulong_t to_hashv_d(uintptr_t p) {return to_hash_d((uintptr_t)p);} + +void* from_locale(ptr_t l); +void* from_locale_d(ptr_t l); +ptr_t to_locale(void* p); +ptr_t to_locale_d(void* p); + +void init_hash_helper(); +void fini_hash_helper(); + +typedef struct x86emu_s x86emu_t; + +void* my_mmap(x86emu_t* emu, void* addr, unsigned long length, int prot, int flags, int fd, int offset); +void* my_mmap64(x86emu_t* emu, void *addr, unsigned long length, int prot, int flags, int fd, int64_t offset); +int my_munmap(x86emu_t* emu, void* addr, unsigned long length); +int my_mprotect(x86emu_t* emu, void *addr, unsigned long len, int prot); + +#endif //__BOX32_64__H_ -- cgit 1.4.1