Skip to content
Snippets Groups Projects
Commit c2e25f24 authored by Cheng Shao's avatar Cheng Shao
Browse files

rts: add missing ccs_mutex guard to internal_dlopen

See added comment for details. Closes #24423.

(cherry picked from commit 20f80b77)
parent da874a80
No related branches found
No related tags found
No related merge requests found
......@@ -598,8 +598,27 @@ internal_dlopen(const char *dll_name)
// (see POSIX also)
ACQUIRE_LOCK(&dl_mutex);
// When dlopen() loads a profiled dynamic library, it calls the
// ctors which will call registerCcsList() to append the defined
// CostCentreStacks to CCS_LIST. This execution path starting from
// addDLL() was only protected by dl_mutex previously. However,
// another thread may be doing other things with the RTS linker
// that transitively calls refreshProfilingCCSs() which also
// accesses CCS_LIST, and those execution paths are protected by
// linker_mutex. So there's a risk of data race that may lead to
// segfaults (#24423), and we need to ensure the ctors are also
// protected by ccs_mutex.
#if defined(PROFILING)
ACQUIRE_LOCK(&ccs_mutex);
#endif
hdl = dlopen(dll_name, RTLD_LAZY|RTLD_LOCAL); /* see Note [RTLD_LOCAL] */
#if defined(PROFILING)
RELEASE_LOCK(&ccs_mutex);
#endif
errmsg = NULL;
if (hdl == NULL) {
/* dlopen failed; return a ptr to the error msg. */
......
......@@ -58,7 +58,7 @@ CostCentre *CC_LIST = NULL;
static CostCentreStack *CCS_LIST = NULL;
#if defined(THREADED_RTS)
static Mutex ccs_mutex;
Mutex ccs_mutex;
#endif
/*
......
......@@ -55,6 +55,10 @@ extern Arena *prof_arena;
void debugCCS( CostCentreStack *ccs );
#endif
#if defined(THREADED_RTS)
extern Mutex ccs_mutex;
#endif
#endif
#include "EndPrivate.h"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment