about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2022-10-26 14:20:39 +0200
committerptitSeb <sebastien.chev@gmail.com>2022-10-26 14:20:39 +0200
commit612e94be9d1511c8b56155918b2c462588b8ee54 (patch)
tree432927f5afa74251e610f29544e0c7f1c9327ce2 /src
parent7a95c78ba014bcf9c65bac82828f1035142affdd (diff)
downloadbox64-612e94be9d1511c8b56155918b2c462588b8ee54.tar.gz
box64-612e94be9d1511c8b56155918b2c462588b8ee54.zip
More flexibility for BOX64_ROLLING_LOG
Diffstat (limited to 'src')
-rwxr-xr-xsrc/box64context.c14
-rwxr-xr-xsrc/emu/x64int3.c2
-rwxr-xr-xsrc/include/box64context.h6
-rwxr-xr-xsrc/libtools/signals.c6
-rwxr-xr-xsrc/main.c13
-rwxr-xr-xsrc/wrapped/wrappedlibc.c6
6 files changed, 27 insertions, 20 deletions
diff --git a/src/box64context.c b/src/box64context.c
index 46860a08..d5e1700f 100755
--- a/src/box64context.c
+++ b/src/box64context.c
@@ -148,11 +148,14 @@ box64context_t *NewBox64Context(int argc)
     // init and put default values
     box64context_t *context = my_context = (box64context_t*)box_calloc(1, sizeof(box64context_t));
 
-    if(cycle_log)
-        for(int i=0; i<CYCLE_LOG; ++i) {
+    if(cycle_log) {
+        context->log_call = (char**)box_calloc(cycle_log, sizeof(char*));
+        context->log_ret = (char**)box_calloc(cycle_log, sizeof(char*));
+        for(int i=0; i<cycle_log; ++i) {
             context->log_call[i] = (char*)box_calloc(256, 1);
             context->log_ret[i] = (char*)box_calloc(128, 1);
         }
+    }
 
     context->deferedInit = 1;
     context->sel_serial = 1;
@@ -296,11 +299,14 @@ void FreeBox64Context(box64context_t** context)
     pthread_mutex_destroy(&ctx->mutex_thread);
     pthread_mutex_destroy(&ctx->mutex_bridge);
 
-    if(cycle_log)
-        for(int i=0; i<CYCLE_LOG; ++i) {
+    if(cycle_log) {
+        for(int i=0; i<cycle_log; ++i) {
             box_free(ctx->log_call[i]);
             box_free(ctx->log_ret[i]);
         }
+        box_free(ctx->log_call);
+        box_free(ctx->log_ret);
+    }
 
     box_free(ctx);
 }
diff --git a/src/emu/x64int3.c b/src/emu/x64int3.c
index f56e66ca..dc2b02a2 100755
--- a/src/emu/x64int3.c
+++ b/src/emu/x64int3.c
@@ -104,7 +104,7 @@ void x64Int3(x64emu_t* emu, uintptr_t* addr)
                 char* buffret = cycle_log?my_context->log_ret[my_context->current_line]:NULL;
                 if(buffret) buffret[0] = '\0';
                 if(cycle_log)
-                    my_context->current_line = (my_context->current_line+1)&(CYCLE_LOG-1);
+                    my_context->current_line = (my_context->current_line+1)%cycle_log;
                 char *tmp;
                 int post = 0;
                 int perr = 0;
diff --git a/src/include/box64context.h b/src/include/box64context.h
index da1f91af..9eb130ec 100755
--- a/src/include/box64context.h
+++ b/src/include/box64context.h
@@ -62,8 +62,6 @@ typedef struct base_segment_s {
     pthread_key_t   key;
 } base_segment_t;
 
-#define CYCLE_LOG   16
-
 typedef struct box64context_s {
     path_collection_t   box64_path;     // PATH env. variable
     path_collection_t   box64_ld_lib;   // LD_LIBRARY_PATH env. variable
@@ -180,8 +178,8 @@ typedef struct box64context_s {
     int                 stack_clone_used;
 
     // rolling logs
-    char*               log_call[CYCLE_LOG];
-    char*               log_ret[CYCLE_LOG];
+    char*               *log_call;
+    char*               *log_ret;
     int                 current_line;
 
 } box64context_t;
diff --git a/src/libtools/signals.c b/src/libtools/signals.c
index 9fdac6e1..6dcfb8b0 100755
--- a/src/libtools/signals.c
+++ b/src/libtools/signals.c
@@ -999,9 +999,9 @@ exit(-1);
             }
         }
         if(cycle_log) {
-            int j = (my_context->current_line+1)&(CYCLE_LOG-1);
-            for (int i=0; i<CYCLE_LOG; ++i) {
-                int k = (i+j)&(CYCLE_LOG-1);
+            int j = (my_context->current_line+1)%cycle_log;
+            for (int i=0; i<cycle_log; ++i) {
+                int k = (i+j)%cycle_log;
                 if(my_context->log_call[k][0]) {
                     printf_log(log_minimum, "%s => return %s\n", my_context->log_call[k], my_context->log_ret[k]);
                 }
diff --git a/src/main.c b/src/main.c
index 542cdea1..4a661e48 100755
--- a/src/main.c
+++ b/src/main.c
@@ -355,17 +355,20 @@ void LoadLogEnv()
     }
     p = getenv("BOX64_ROLLING_LOG");
     if(p) {
-        if(strlen(p)==1) {
-            if(p[0]>='0' && p[0]<='1')
-                cycle_log = p[0]-'0';
-        }
+        int cycle = 0;
+        if(sscanf(p, "%d", &cycle)==1)
+                cycle_log = cycle;
+        if(cycle_log==1)
+            cycle_log = 16;
+        if(cycle_log<0)
+            cycle_log = 0;
         if(cycle_log && box64_log>LOG_INFO) {
             cycle_log = 0;
             printf_log(LOG_NONE, "Incompatible Rolling log and Debug Log, disabling Rolling log\n");
         }
     }
     if(!box64_nobanner && cycle_log)
-        printf_log(LOG_INFO, "Rolling log, showing last %d function call on signals\n", CYCLE_LOG);
+        printf_log(LOG_INFO, "Rolling log, showing last %d function call on signals\n", cycle_log);
     p = getenv("BOX64_DUMP");
     if(p) {
         if(strlen(p)==1) {
diff --git a/src/wrapped/wrappedlibc.c b/src/wrapped/wrappedlibc.c
index b387fccb..36e9031c 100755
--- a/src/wrapped/wrappedlibc.c
+++ b/src/wrapped/wrappedlibc.c
@@ -359,9 +359,9 @@ void EXPORT my___stack_chk_fail(x64emu_t* emu)
     sprintf(buff, "%p: Stack is corrupted, aborting\n", (void*)emu->old_ip);
     #endif
     if(cycle_log) {
-        int j = (my_context->current_line+1)&(CYCLE_LOG-1);
-        for (int i=0; i<CYCLE_LOG; ++i) {
-            int k = (i+j)&(CYCLE_LOG-1);
+        int j = (my_context->current_line+1)%cycle_log;
+        for (int i=0; i<cycle_log; ++i) {
+            int k = (i+j)%cycle_log;
             if(my_context->log_call[k][0]) {
                 printf_log(LOG_INFO, "%s => return %s\n", my_context->log_call[k], my_context->log_ret[k]);
             }