Skip to content

Commit 0158102

Browse files
authored
[ENV] Fixed race condition of init/uninit of rolling logs (#3289)
I had issues using this feature to trace wps office
1 parent 7586bd4 commit 0158102

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/box64context.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,20 +135,25 @@ static void atfork_child_box64context(void)
135135
init_mutexes(my_context);
136136
}
137137

138+
int box64_cycle_log_initialized = 0;
139+
138140
void freeCycleLog(box64context_t* ctx)
139141
{
140-
if(BOX64ENV(rolling_log)) {
142+
if (BOX64ENV(rolling_log) && box64_cycle_log_initialized) {
141143
box_free(ctx->log_call);
142144
box_free(ctx->log_ret);
143145
ctx->log_call = NULL;
144146
ctx->log_ret = NULL;
147+
box64_cycle_log_initialized = 0;
145148
}
146149
}
150+
147151
void initCycleLog(box64context_t* context)
148152
{
149153
if(context && BOX64ENV(rolling_log)) {
150154
context->log_call = (char*)box_calloc(BOX64ENV(rolling_log), 256*sizeof(char));
151155
context->log_ret = (char*)box_calloc(BOX64ENV(rolling_log), 128*sizeof(char));
156+
box64_cycle_log_initialized = 1;
152157
}
153158
}
154159

src/tools/env.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ static void parseRange(const char* s, uintptr_t* start, uintptr_t* end)
144144
void AddNewLibs(const char* list);
145145
int canNCpuBeChanged();
146146

147+
extern int box64_cycle_log_initialized;
148+
147149
static void applyCustomRules()
148150
{
149151
if (BOX64ENV(log) == LOG_NEVER) {
@@ -152,8 +154,7 @@ static void applyCustomRules()
152154
}
153155

154156
#ifndef _WIN32
155-
if(box64env.is_cycle_log_overridden) {
156-
freeCycleLog(my_context);
157+
if (box64env.is_cycle_log_overridden) {
157158
box64env.rolling_log = BOX64ENV(cycle_log);
158159

159160
if (BOX64ENV(rolling_log) == 1) {
@@ -162,7 +163,7 @@ static void applyCustomRules()
162163
if (BOX64ENV(rolling_log) && BOX64ENV(log) > LOG_INFO) {
163164
box64env.rolling_log = 0;
164165
}
165-
initCycleLog(my_context);
166+
if (!box64_cycle_log_initialized) initCycleLog(my_context);
166167
}
167168

168169
if (box64env.is_dynarec_gdbjit_str_overridden) {

0 commit comments

Comments
 (0)