diff options
| author | ptitSeb <sebastien.chev@gmail.com> | 2024-09-09 19:45:48 +0200 |
|---|---|---|
| committer | ptitSeb <sebastien.chev@gmail.com> | 2024-09-09 19:45:48 +0200 |
| commit | 1b48cd157aebdef76a45b8e85c53a544cf7c9b48 (patch) | |
| tree | cbb5cbd22bbe152aaf029cd5dbb550cd4be5eaed /src | |
| parent | 362402ffbf09d4eefde80b6d15b7d73c9b6a377a (diff) | |
| download | box64-1b48cd157aebdef76a45b8e85c53a544cf7c9b48.tar.gz box64-1b48cd157aebdef76a45b8e85c53a544cf7c9b48.zip | |
[RCFILE] Slightly changed how BOX64_ARGS behave, and added BOX64_INSERT_ARGS
Diffstat (limited to 'src')
| -rw-r--r-- | src/core.c | 43 | ||||
| -rw-r--r-- | src/libtools/threads.c | 4 | ||||
| -rw-r--r-- | src/tools/rcfile.c | 8 |
3 files changed, 49 insertions, 6 deletions
diff --git a/src/core.c b/src/core.c index 22d654eb..91223596 100644 --- a/src/core.c +++ b/src/core.c @@ -68,6 +68,7 @@ int box64_ignoreint3 = 0; int box64_rdtsc = 0; int box64_rdtsc_1ghz = 0; uint8_t box64_rdtsc_shift = 0; +char* box64_insert_args = NULL; char* box64_new_args = NULL; #ifdef DYNAREC int box64_dynarec = 1; @@ -1716,10 +1717,16 @@ static void add_argv(const char* what) { if(!strcmp(my_context->argv[i], what)) there = 1; if(!there) { - printf_log(LOG_INFO, "Inserting \"%s\" to the arguments\n", what); + // try to prepend the arg, not appending + static int where = 0; + if(!where) + where = (box64_wine)?2:1; + printf_log(LOG_INFO, "Inserting \"%s\" to the argument %d\n", what, where); my_context->argv = (char**)box_realloc(my_context->argv, (my_context->argc+1)*sizeof(char*)); - my_context->argv[my_context->argc] = box_strdup(what); + memmove(my_context->argv+where+1, my_context->argv+where, (my_context->argc-where)*sizeof(char*)); + my_context->argv[where] = box_strdup(what); my_context->argc++; + where++; } } @@ -2069,11 +2076,39 @@ int initialize(int argc, const char **argv, char** env, x64emu_t** emulator, elf { add_argv("-cef-disable-gpu-compositor"); } + // add new args only if there is no args already if(box64_new_args) { char tmp[256]; char* p = box64_new_args; int state = 0; char* p2 = p; + if(my_context->argc==1 || (my_context->argc==2 && box64_wine)) + while(state>=0) { + switch(*p2) { + case 0: // end of flux + if(state && (p2!=p)) add_argv(p); + state = -1; + break; + case '"': // start/end of quotes + if(state<2) {if(!state) p=p2; state=2;} else state=1; + break; + case ' ': + if(state==1) {strncpy(tmp, p, p2-p); tmp[p2-p]='\0'; add_argv(tmp); state=0;} + break; + default: + if(state==0) {state=1; p=p2;} + break; + } + ++p2; + } + box_free(box64_new_args); + box64_new_args = NULL; + } + if(box64_insert_args) { + char tmp[256]; + char* p = box64_insert_args; + int state = 0; + char* p2 = p; while(state>=0) { switch(*p2) { case 0: // end of flux @@ -2092,8 +2127,8 @@ int initialize(int argc, const char **argv, char** env, x64emu_t** emulator, elf } ++p2; } - box_free(box64_new_args); - box64_new_args = NULL; + box_free(box64_insert_args); + box64_insert_args = NULL; } // check if file exist if(!my_context->argv[0] || !FileExist(my_context->argv[0], IS_FILE)) { diff --git a/src/libtools/threads.c b/src/libtools/threads.c index 8de7f5e9..463777c2 100644 --- a/src/libtools/threads.c +++ b/src/libtools/threads.c @@ -242,8 +242,8 @@ static void* pthread_routine(void* p) Push64(emu, 0); // PUSH BP R_RBP = R_RSP; // MOV BP, SP R_RSP -= 64; // Guard zone - if(R_RSP&0x8) // align if needed (shouldn't be) - R_RSP-=8; + R_RSP &= ~15LL; + R_RSP-=8; // make sure RSP is aligned inside thread function PushExit(emu); R_RIP = et->fnc; R_RDI = (uintptr_t)et->arg; diff --git a/src/tools/rcfile.c b/src/tools/rcfile.c index fd9468a9..0d19901b 100644 --- a/src/tools/rcfile.c +++ b/src/tools/rcfile.c @@ -124,6 +124,7 @@ ENTRYSTRING_(BOX64_ENV2, new_env2) \ ENTRYSTRING_(BOX64_ENV3, new_env3) \ ENTRYSTRING_(BOX64_ENV4, new_env4) \ ENTRYSTRING_(BOX64_ARGS, new_args) \ +ENTRYSTRING_(BOX64_INSERT_ARGS, insert_args) \ ENTRYBOOL(BOX64_RESERVE_HIGH, new_reserve_high) \ #ifdef HAVE_TRACE @@ -501,6 +502,7 @@ extern int ftrace_has_pid; extern FILE* ftrace; extern char* ftrace_name; extern char* box64_new_args; +extern char* box64_insert_args; void openFTrace(const char* newtrace); void addNewEnvVar(const char* s); void AddNewLibs(const char* libs); @@ -655,6 +657,12 @@ void internal_ApplyParams(const char* name, const my_params_t* param) { box_free(box64_new_args); box64_new_args = box_strdup(param->new_args); } + if(param->is_insert_args_present) { + printf_log(LOG_INFO, "Adding \"%s\" arguments to command line\n", param->insert_args); + if(box64_insert_args) + box_free(box64_insert_args); + box64_insert_args = box_strdup(param->insert_args); + } if(param->is_bash_present && FileIsX64ELF(param->bash)) { if(my_context->bashpath) box_free(my_context->bashpath); |