diff options
| author | ptitSeb <sebastien.chev@gmail.com> | 2024-08-18 16:02:27 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-18 16:02:27 +0200 |
| commit | fda0e9a4cba9b71de60f974fadfa74c7fbff5b15 (patch) | |
| tree | f18d6631d62761d1556abd18a91d4729bd1f41e1 /src/include | |
| parent | f1da5d433a707a1308732884c455ae50ffbe4fe1 (diff) | |
| parent | dead2003fa59cbfa6a2fd8ba285bdf28aac953f3 (diff) | |
| download | box64-fda0e9a4cba9b71de60f974fadfa74c7fbff5b15.tar.gz box64-fda0e9a4cba9b71de60f974fadfa74c7fbff5b15.zip | |
Merge branch 'box32' into main
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/box32.h | 112 | ||||
| -rw-r--r-- | src/include/custommem.h | 3 | ||||
| -rw-r--r-- | src/include/debug.h | 1 | ||||
| -rw-r--r-- | src/include/elfload_dump.h | 32 | ||||
| -rw-r--r-- | src/include/elfloader.h | 3 | ||||
| -rw-r--r-- | src/include/x64run.h | 4 |
6 files changed, 137 insertions, 18 deletions
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 <stdint.h> +#include <stdlib.h> + +#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_ diff --git a/src/include/custommem.h b/src/include/custommem.h index dda21053..ba5441d1 100644 --- a/src/include/custommem.h +++ b/src/include/custommem.h @@ -102,6 +102,7 @@ void* find31bitBlockNearHint(void* hint, size_t size, uintptr_t mask); void* find47bitBlock(size_t size); void* find47bitBlockNearHint(void* hint, size_t size, uintptr_t mask); // mask can be 0 for default one (0xffff) void* find47bitBlockElf(size_t size, int mainbin, uintptr_t mask); +void* find31bitBlockElf(size_t size, int mainbin, uintptr_t mask); int isBlockFree(void* hint, size_t size); // unlock mutex that are locked by current thread (for signal handling). Return a mask of unlock mutex @@ -125,4 +126,6 @@ int checkInHotPage(uintptr_t addr); void* internal_mmap(void *addr, unsigned long length, int prot, int flags, int fd, ssize_t offset); int internal_munmap(void* addr, unsigned long length); +void reserveHighMem(); + #endif //__CUSTOM_MEM__H_ diff --git a/src/include/debug.h b/src/include/debug.h index 1e31b437..e0f81c95 100644 --- a/src/include/debug.h +++ b/src/include/debug.h @@ -16,6 +16,7 @@ extern int box64_ignoreint3; extern int box64_rdtsc; extern int box64_rdtsc_1ghz; extern uint8_t box64_rdtsc_shift; +extern int box64_is32bits; #ifdef DYNAREC extern int box64_dynarec_dump; extern int box64_dynarec_trace; diff --git a/src/include/elfload_dump.h b/src/include/elfload_dump.h index ad2ecd71..3fa0a910 100644 --- a/src/include/elfload_dump.h +++ b/src/include/elfload_dump.h @@ -3,22 +3,26 @@ typedef struct elfheader_s elfheader_t; -const char* DumpSection(Elf64_Shdr *s, char* SST); -const char* DumpDynamic(Elf64_Dyn *s); -const char* DumpPHEntry(Elf64_Phdr *e); -const char* DumpSym(elfheader_t *h, Elf64_Sym* sym, int version); -const char* DumpRelType(int t); -const char* SymName(elfheader_t *h, Elf64_Sym* sym); -const char* IdxSymName(elfheader_t *h, int sym); -void DumpMainHeader(Elf64_Ehdr *header, elfheader_t *h); -void DumpSymTab(elfheader_t *h); -void DumpDynamicSections(elfheader_t *h); +const char* SymName32(elfheader_t *h, Elf32_Sym* sym); +const char* SymName64(elfheader_t *h, Elf64_Sym* sym); +const char* DumpRelType32(int t); +const char* DumpRelType64(int t); +void DumpMainHeader32(Elf32_Ehdr *header, elfheader_t *h); +void DumpMainHeader64(Elf64_Ehdr *header, elfheader_t *h); +void DumpSymTab32(elfheader_t *h); +void DumpSymTab64(elfheader_t *h); +void DumpDynamicSections32(elfheader_t *h); +void DumpDynamicSections64(elfheader_t *h); void DumpDynamicNeeded(elfheader_t *h); void DumpDynamicRPath(elfheader_t *h); -void DumpDynSym(elfheader_t *h); -void DumpRelTable(elfheader_t *h, int cnt, Elf64_Rel *rel, const char* name); -void DumpRelATable(elfheader_t *h, int cnt, Elf64_Rela *rela, const char* name); -void DumpRelRTable(elfheader_t *h, int cnt, Elf64_Relr *relr, const char *name); +void DumpDynSym32(elfheader_t *h); +void DumpDynSym64(elfheader_t *h); +void DumpRelTable32(elfheader_t *h, int cnt, Elf32_Rel *rel, const char* name); +void DumpRelTable64(elfheader_t *h, int cnt, Elf64_Rel *rel, const char* name); +void DumpRelATable32(elfheader_t *h, int cnt, Elf32_Rela *rela, const char* name); +void DumpRelATable64(elfheader_t *h, int cnt, Elf64_Rela *rela, const char* name); +void DumpRelRTable32(elfheader_t *h, int cnt, Elf32_Relr *relr, const char *name); +void DumpRelRTable64(elfheader_t *h, int cnt, Elf64_Relr *relr, const char *name); void DumpBinary(char* p, int sz); diff --git a/src/include/elfloader.h b/src/include/elfloader.h index 770709c8..edaf9771 100644 --- a/src/include/elfloader.h +++ b/src/include/elfloader.h @@ -45,7 +45,6 @@ int CalcLoadAddr(elfheader_t* head); int AllocLoadElfMemory(box64context_t* context, elfheader_t* head, int mainbin); void FreeElfMemory(elfheader_t* head); int isElfHasNeededVer(elfheader_t* head, const char* libname, elfheader_t* verneeded); -void GrabX64CopyMainElfReloc(elfheader_t* head); int RelocateElf(lib_t *maplib, lib_t* local_maplib, int bindnow, int deepbind, elfheader_t* head); int RelocateElfPlt(lib_t *maplib, lib_t* local_maplib, int bindnow, int deepbind, elfheader_t* head); void CalcStack(elfheader_t* h, uint64_t* stacksz, size_t* stackalign); @@ -91,7 +90,7 @@ int GetNeededVersionForLib(elfheader_t* h, const char* libname, const char* ver) void* ElfGetLocalSymbolStartEnd(elfheader_t* head, uintptr_t *offs, uintptr_t *sz, const char* symname, int* ver, const char** vername, int local, int* veropt); void* ElfGetGlobalSymbolStartEnd(elfheader_t* head, uintptr_t *offs, uintptr_t *sz, const char* symname, int* ver, const char** vername, int local, int* veropt); void* ElfGetWeakSymbolStartEnd(elfheader_t* head, uintptr_t *offs, uintptr_t *sz, const char* symname, int* ver, const char** vername, int local, int* veropt); -int ElfGetSymTabStartEnd(elfheader_t* head, uintptr_t *offs, uintptr_t *end, const char* symname); +int ElfGetSymTabStartEnd64(elfheader_t* head, uintptr_t *offs, uintptr_t *end, const char* symname); void* GetNativeSymbolUnversioned(void* lib, const char* name); diff --git a/src/include/x64run.h b/src/include/x64run.h index b6c9e960..a5d4528e 100644 --- a/src/include/x64run.h +++ b/src/include/x64run.h @@ -9,8 +9,8 @@ int RunTest(x64test_t *test); void DynaRun(x64emu_t *emu); uint32_t LibSyscall(x64emu_t *emu); -void PltResolver(x64emu_t* emu); -extern uintptr_t pltResolver; +void PltResolver64(x64emu_t* emu); +extern uintptr_t pltResolver64; int GetTID(void); #endif //__X64RUN_H_ \ No newline at end of file |