prevent potential corruption of errno in thread lister

See
https://github.com/gperftools/gperftools/issues/500#issuecomment-133814659
for explanations. We of course evolved quite a bit since that comment,
but general issue still applies.
This commit is contained in:
Aliaksey Kandratsenka 2023-07-10 00:20:13 -04:00
parent 2b5743ffa6
commit c44e44cecb

View File

@ -42,6 +42,7 @@
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <sched.h>
#include <signal.h>
#include <stdio.h>
@ -648,6 +649,14 @@ int TCMalloc_ListAllProcessThreads(void *parameter,
}
need_sigprocmask = 1;
// make sure all functions used by parent from local_clone to after
// waitpid have plt entries fully initialized. We cannot afford
// dynamic linker running relocations and messing with errno (see
// comment just below)
(void)prctl(PR_GET_PDEATHSIG, 0);
(void)close(-1);
(void)waitpid(INT_MIN, nullptr, 0);
/* After cloning, both the parent and the child share the same
* instance of errno. We deal with this by being very
* careful. Specifically, child immediately calls into sem_wait