Skip to content

Commit 1740287

Browse files
ararslanvtjnash
andauthored
Block thread from receiving profile signal with stackwalk lock (#57089)
This is Jameson's proposed amendment to the changes made in #57035 that introduced a deadlock on FreeBSD, amusingly in service of fixing a deadlock on Linux. On Linux and (non-macOS) BSD, instead of acquiring and releasing a lock on the profiler in `jl_with_stackwalk_lock`, we're just blocking the thread from receiving the profiler's `SIGUSR2` signal at all. This should fix #57058; I don't get the deadlock locally on FreeBSD with this change, but it's AArch64 instead of x86-64 like on CI, so let's see if this also makes CI happy. If so, closes #57059. Co-authored-by: Jameson Nash <[email protected]>
1 parent 1262bf8 commit 1740287

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

src/signals-unix.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -310,23 +310,14 @@ int exc_reg_is_write_fault(uintptr_t esr) {
310310
#include <sys/eventfd.h>
311311
#include <link.h>
312312

313-
typedef struct {
314-
void (*f)(void*) JL_NOTSAFEPOINT;
315-
void *ctx;
316-
} callback_t;
317-
static int with_dl_iterate_phdr_lock(struct dl_phdr_info *info, size_t size, void *data)
318-
{
319-
jl_lock_profile();
320-
callback_t *callback = (callback_t*)data;
321-
callback->f(callback->ctx);
322-
jl_unlock_profile();
323-
return 1; // only call this once
324-
}
325-
326313
void jl_with_stackwalk_lock(void (*f)(void*), void *ctx)
327314
{
328-
callback_t callback = {f, ctx};
329-
dl_iterate_phdr(with_dl_iterate_phdr_lock, &callback);
315+
sigset_t sset, oset;
316+
sigemptyset(&sset);
317+
sigaddset(&sset, SIGUSR2);
318+
pthread_sigmask(SIG_BLOCK, &sset, &oset);
319+
f(ctx);
320+
pthread_sigmask(SIG_SETMASK, &oset, NULL);
330321
}
331322

332323
#if defined(_OS_LINUX_) && (defined(_CPU_X86_64_) || defined(_CPU_X86_))

0 commit comments

Comments
 (0)