about summary refs log tree commit diff stats
path: root/src/include/box32.h
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2024-08-17 12:24:26 +0200
committerptitSeb <sebastien.chev@gmail.com>2024-08-17 12:24:26 +0200
commitfa87b0fcef3dff593a507b3200ef83d846101d64 (patch)
tree66894b342323cf40892b43d6f92bc8793c792489 /src/include/box32.h
parent0f1bce0f32a8429fc414f92cb6b85ff0d30b5d8f (diff)
downloadbox64-fa87b0fcef3dff593a507b3200ef83d846101d64.tar.gz
box64-fa87b0fcef3dff593a507b3200ef83d846101d64.zip
[BOX32] prepare elfheader_t structure for 32bits elfs
Diffstat (limited to 'src/include/box32.h')
-rw-r--r--src/include/box32.h112
1 files changed, 112 insertions, 0 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_