linux: Yet more malloc() avoidance for backtrace()
Turns out, there's an initializer at the top of backtrace() that (on some arches) calls dlopen(). dlopen(), unsurprisingly, calls malloc(). So, call backtrace() early in signal handler setup so we can later safely call it from the signal handler itself.
This commit is contained in:
parent
792dee3854
commit
0b131a5cd9
14
os/osinit.c
14
os/osinit.c
|
@ -59,6 +59,10 @@ SOFTWARE.
|
||||||
#ifdef HAVE_DLFCN_H
|
#ifdef HAVE_DLFCN_H
|
||||||
# include <dlfcn.h>
|
# include <dlfcn.h>
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HAVE_BACKTRACE
|
||||||
|
#include <execinfo.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include "dixstruct.h"
|
#include "dixstruct.h"
|
||||||
|
|
||||||
|
@ -192,6 +196,16 @@ OsInit(void)
|
||||||
siglist[i], strerror(errno));
|
siglist[i], strerror(errno));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifdef HAVE_BACKTRACE
|
||||||
|
/*
|
||||||
|
* initialize the backtracer, since the ctor calls dlopen(), which
|
||||||
|
* calls malloc(), which isn't signal-safe.
|
||||||
|
*/
|
||||||
|
do {
|
||||||
|
void *array;
|
||||||
|
backtrace(&array, 1);
|
||||||
|
} while (0);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef RTLD_DI_SETSIGNAL
|
#ifdef RTLD_DI_SETSIGNAL
|
||||||
/* Tell runtime linker to send a signal we can catch instead of SIGKILL
|
/* Tell runtime linker to send a signal we can catch instead of SIGKILL
|
||||||
|
|
Loading…
Reference in New Issue
Block a user