For the process that already loaded libthr but still not initialized
threading, fall back to libc method of performing __pthread_map_stacks_exec() job. Reported and tested by: Mykola Dzham <i levsha me>
This commit is contained in:
parent
bf390c1fbd
commit
fad128db86
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=217224
@ -30,6 +30,8 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/queue.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
#include <link.h>
|
||||
@ -139,6 +141,26 @@ _thr_stack_fix_protection(struct pthread *thrd)
|
||||
_rtld_get_stack_prot());
|
||||
}
|
||||
|
||||
static void
|
||||
singlethread_map_stacks_exec(void)
|
||||
{
|
||||
int mib[2];
|
||||
struct rlimit rlim;
|
||||
u_long usrstack;
|
||||
size_t len;
|
||||
|
||||
mib[0] = CTL_KERN;
|
||||
mib[1] = KERN_USRSTACK;
|
||||
len = sizeof(usrstack);
|
||||
if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), &usrstack, &len, NULL, 0)
|
||||
== -1)
|
||||
return;
|
||||
if (getrlimit(RLIMIT_STACK, &rlim) == -1)
|
||||
return;
|
||||
mprotect((void *)(uintptr_t)(usrstack - rlim.rlim_cur),
|
||||
rlim.rlim_cur, _rtld_get_stack_prot());
|
||||
}
|
||||
|
||||
void __pthread_map_stacks_exec(void);
|
||||
void
|
||||
__pthread_map_stacks_exec(void)
|
||||
@ -146,6 +168,10 @@ __pthread_map_stacks_exec(void)
|
||||
struct pthread *curthread, *thrd;
|
||||
struct stack *st;
|
||||
|
||||
if (!_thr_is_inited()) {
|
||||
singlethread_map_stacks_exec();
|
||||
return;
|
||||
}
|
||||
curthread = _get_curthread();
|
||||
THREAD_LIST_RDLOCK(curthread);
|
||||
LIST_FOREACH(st, &mstackq, qe)
|
||||
|
Loading…
Reference in New Issue
Block a user