More flockfile

This commit is contained in:
Ivan Chikish 2023-07-13 23:34:46 +03:00
parent 66bc415dc3
commit 653eff3d16
2 changed files with 7 additions and 1 deletions

View file

@ -77,11 +77,12 @@ void rx::printStackTrace(ucontext_t *context, orbis::Thread *thread,
unw_cursor_t cursor;
char buffer[1024];
flockfile(stderr);
if (int r = unw_init_local2(&cursor, context, UNW_INIT_SIGNAL_FRAME)) {
int len = snprintf(buffer, sizeof(buffer), "unw_init_local: %s\n",
unw_strerror(r));
write(fileno, buffer, len);
funlockfile(stderr);
return;
}
@ -123,4 +124,5 @@ void rx::printStackTrace(ucontext_t *context, orbis::Thread *thread,
write(fileno, buffer, offset);
count++;
} while (unw_step(&cursor) > 0 && count < 32);
funlockfile(stderr);
}

View file

@ -178,6 +178,7 @@ static void onSysEnter(orbis::Thread *thread, int id, uint64_t *args,
if (true || !g_traceSyscalls) {
return;
}
flockfile(stdout);
std::printf(" [%u] ", thread->tid);
if (auto name = getSyscallName(thread, id)) {
@ -195,6 +196,7 @@ static void onSysEnter(orbis::Thread *thread, int id, uint64_t *args,
}
std::printf(")\n");
funlockfile(stdout);
}
static void onSysExit(orbis::Thread *thread, int id, uint64_t *args,
@ -203,6 +205,7 @@ static void onSysExit(orbis::Thread *thread, int id, uint64_t *args,
return;
}
flockfile(stdout);
std::printf("%c: [%u] ", result.isError() ? 'E' : 'S', thread->tid);
if (auto name = getSyscallName(thread, id)) {
@ -221,6 +224,7 @@ static void onSysExit(orbis::Thread *thread, int id, uint64_t *args,
std::printf(") -> Status %d, Value %lx:%lx\n", result.value(),
thread->retval[0], thread->retval[1]);
funlockfile(stdout);
}
static int ps4Exec(orbis::Process *mainProcess,