Skip to content

Commit b10e35b

Browse files
committed
sysprof: disable runtime host symtab updates
The symtab update for newly loaded shared libraries requires memory allocation, which is not signal-safe and can cause crashes. Updating symtab in a VM hook is not a viable option either, as there are no guarantees that the symbol will be dumped before its address is streamed. This patch completely disables the runtime updates of the symtab for host symbols. That means all Lua-C modules, FFI modules, and shared libraries must be loaded before starting the profiler. There is no test along with the patch for two main reasons: 1. The signal should land on an instruction inside the allocator such that the second allocator call would cause a crash because of an inconsistent inner state. Although we have ptrace-based machinery for testing, the control is not that fine-grained. The only option we have left is to rely on empirical offsets, which is not a robust solution. Moreover, it is possible to build LuaJIT with `malloc` as an allocator, and the test should be adapted to that too. Needless to say, malloc sources may differ from platform to platform, making the test unreliable. 2. Regression is unlikely here since this patch removes the only call that could allocate memory inside the signal handler. Resolves tarantool/tarantool#8140
1 parent 2ab0419 commit b10e35b

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/lj_sysprof.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ struct sysprof {
7575
luam_Sysprof_backtracer backtracer; /* Backtracing function for the host stack. */
7676
lj_profile_timer timer; /* Profiling timer. */
7777
int saved_errno; /* Saved errno when profiler failed. */
78-
uint32_t lib_adds; /* Number of libs loaded. Monotonic. */
7978
};
8079
/*
8180
** XXX: Only one VM can be profiled at a time.
@@ -100,7 +99,11 @@ static int is_unconfigured(struct sysprof *sp)
10099

101100
static void stream_prologue(struct sysprof *sp)
102101
{
103-
lj_symtab_dump(&sp->out, sp->g, &sp->lib_adds);
102+
/*
103+
** XXX: Must be zero for the symtab module to dump all loaded libraries.
104+
*/
105+
uint32_t unused_lib_adds = 0;
106+
lj_symtab_dump(&sp->out, sp->g, &unused_lib_adds);
104107
lj_wbuf_addn(&sp->out, ljp_header, sizeof(ljp_header));
105108
}
106109

@@ -256,8 +259,6 @@ static void stream_guest(struct sysprof *sp, uint32_t vmstate)
256259

257260
static void stream_host(struct sysprof *sp, uint32_t vmstate)
258261
{
259-
struct lua_State *L = gco2th(gcref(sp->g->cur_L));
260-
lj_symtab_dump_newc(&sp->lib_adds, &sp->out, LJP_SYMTAB_CFUNC_EVENT, L);
261262
lj_wbuf_addbyte(&sp->out, (uint8_t)vmstate);
262263
stream_backtrace_host(sp);
263264
}

0 commit comments

Comments
 (0)