refactor: reduce global var in trap.c to one pointer
[mate.git] / ffi / trap.c
index 1d18ebade214e270d77b06a4c3763f7ea2d85c25..0302c5ea0667659c4ce21bd6728c31b49f574a8a 100644 (file)
@@ -22,8 +22,9 @@
 #include <sys/ucontext.h>
 
 unsigned int getMethodEntry(unsigned int, unsigned int);
-unsigned int getStaticFieldAddr(unsigned int, void*);
+unsigned int getStaticFieldAddr(unsigned int);
 unsigned int getTrapType(unsigned int, unsigned int);
+unsigned int mallocObject(int);
 
 #ifdef DBG_TRAP
 #define dprintf(args...) do { printf (args); } while (0);
@@ -31,27 +32,17 @@ unsigned int getTrapType(unsigned int, unsigned int);
 #define dprintf(args...)
 #endif
 
-#define NEW_MAP(prefix) \
-       void* prefix ## _map = NULL; \
-       void set_ ## prefix ## map(void *map) \
-       { \
-               dprintf("set_%s: 0x%08x\n", #prefix , (unsigned int) map); \
-               prefix ## _map = map; \
-       } \
-       void *get_ ## prefix ## map() \
-       { \
-               dprintf("get_%s: 0x%08x\n", #prefix , (unsigned int) prefix ## _map); \
-               return prefix ## _map; \
-       }
+void *mate_ctx = NULL;
 
-NEW_MAP(method)
-NEW_MAP(trap)
-NEW_MAP(class)
-NEW_MAP(virtual)
-NEW_MAP(strings)
-NEW_MAP(interfaces)
-NEW_MAP(interfacemethod)
+void *get_mate_context()
+{
+       return mate_ctx;
+}
 
+void *set_mate_context(void *ctx)
+{
+       mate_ctx = ctx;
+}
 
 void mainresult(unsigned int a)
 {
@@ -130,7 +121,7 @@ void sigsegvtrap(int nSignal, siginfo_t *info, void *ctx)
                                dprintf("staticfieldtrap: something is wrong here. abort\n");
                                exit(0);
                        }
-                       unsigned int patchme = getStaticFieldAddr(from, trap_map);
+                       unsigned int patchme = getStaticFieldAddr(from);
 
                        dprintf(" to_patch: 0x%08x\n", (unsigned int) to_patch);
                        dprintf("*to_patch: 0x%08x\n", *to_patch);
@@ -160,7 +151,7 @@ unsigned int getaddr(void)
        return (unsigned int) mainresult;
 }
 
-unsigned int getMallocAddr(void)
+unsigned int getMallocObjectAddr(void)
 {
-       return (unsigned int) malloc;
+       return (unsigned int) mallocObject;
 }