Revert "libthr: Use kern.stacktop for thread stack calculation."
The current ASLR stack gap feature will be removed, and with that the
need for this change, and the kern.stactop sysctl, is gone. Moreover,
the approach taken in this revision does not provide compatibility for
old copies of libthr.so, and the revision should have also updated
__libc_map_stacks_exec().
This reverts commit 78df56ccfc
.
Reviewed by: kib
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D33704
This commit is contained in:
parent
dc7526170d
commit
f75b1ff6e5
@ -61,7 +61,7 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include "libc_private.h"
|
#include "libc_private.h"
|
||||||
#include "thr_private.h"
|
#include "thr_private.h"
|
||||||
|
|
||||||
char *_stacktop;
|
char *_usrstack;
|
||||||
struct pthread *_thr_initial;
|
struct pthread *_thr_initial;
|
||||||
int _libthr_debug;
|
int _libthr_debug;
|
||||||
int _thread_event_mask;
|
int _thread_event_mask;
|
||||||
@ -388,7 +388,7 @@ init_main_thread(struct pthread *thread)
|
|||||||
* resource limits, so this stack needs an explicitly mapped
|
* resource limits, so this stack needs an explicitly mapped
|
||||||
* red zone to protect the thread stack that is just beyond.
|
* red zone to protect the thread stack that is just beyond.
|
||||||
*/
|
*/
|
||||||
if (mmap(_stacktop - _thr_stack_initial -
|
if (mmap(_usrstack - _thr_stack_initial -
|
||||||
_thr_guard_default, _thr_guard_default, 0, MAP_ANON,
|
_thr_guard_default, _thr_guard_default, 0, MAP_ANON,
|
||||||
-1, 0) == MAP_FAILED)
|
-1, 0) == MAP_FAILED)
|
||||||
PANIC("Cannot allocate red zone for initial thread");
|
PANIC("Cannot allocate red zone for initial thread");
|
||||||
@ -402,7 +402,7 @@ init_main_thread(struct pthread *thread)
|
|||||||
* actually free() it; it just puts it in the free
|
* actually free() it; it just puts it in the free
|
||||||
* stack queue for later reuse.
|
* stack queue for later reuse.
|
||||||
*/
|
*/
|
||||||
thread->attr.stackaddr_attr = _stacktop - _thr_stack_initial;
|
thread->attr.stackaddr_attr = _usrstack - _thr_stack_initial;
|
||||||
thread->attr.stacksize_attr = _thr_stack_initial;
|
thread->attr.stacksize_attr = _thr_stack_initial;
|
||||||
thread->attr.guardsize_attr = _thr_guard_default;
|
thread->attr.guardsize_attr = _thr_guard_default;
|
||||||
thread->attr.flags |= THR_STACK_USER;
|
thread->attr.flags |= THR_STACK_USER;
|
||||||
@ -427,7 +427,7 @@ init_main_thread(struct pthread *thread)
|
|||||||
thread->attr.prio = sched_param.sched_priority;
|
thread->attr.prio = sched_param.sched_priority;
|
||||||
|
|
||||||
#ifdef _PTHREAD_FORCED_UNWIND
|
#ifdef _PTHREAD_FORCED_UNWIND
|
||||||
thread->unwind_stackend = _stacktop;
|
thread->unwind_stackend = _usrstack;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Others cleared to zero by thr_alloc() */
|
/* Others cleared to zero by thr_alloc() */
|
||||||
@ -464,13 +464,10 @@ init_private(void)
|
|||||||
__thr_malloc_init();
|
__thr_malloc_init();
|
||||||
/* Find the stack top */
|
/* Find the stack top */
|
||||||
mib[0] = CTL_KERN;
|
mib[0] = CTL_KERN;
|
||||||
mib[1] = KERN_STACKTOP;
|
mib[1] = KERN_USRSTACK;
|
||||||
len = sizeof (_stacktop);
|
len = sizeof (_usrstack);
|
||||||
if (sysctl(mib, 2, &_stacktop, &len, NULL, 0) == -1) {
|
if (sysctl(mib, 2, &_usrstack, &len, NULL, 0) == -1)
|
||||||
mib[1] = KERN_USRSTACK;
|
PANIC("Cannot get kern.usrstack from sysctl");
|
||||||
if (sysctl(mib, 2, &_stacktop, &len, NULL, 0) == -1)
|
|
||||||
PANIC("Cannot get kern.usrstack from sysctl");
|
|
||||||
}
|
|
||||||
env_bigstack = getenv("LIBPTHREAD_BIGSTACK_MAIN");
|
env_bigstack = getenv("LIBPTHREAD_BIGSTACK_MAIN");
|
||||||
env_splitstack = getenv("LIBPTHREAD_SPLITSTACK_MAIN");
|
env_splitstack = getenv("LIBPTHREAD_SPLITSTACK_MAIN");
|
||||||
if (env_bigstack != NULL || env_splitstack == NULL) {
|
if (env_bigstack != NULL || env_splitstack == NULL) {
|
||||||
|
@ -724,7 +724,7 @@ extern int __isthreaded;
|
|||||||
* Global variables for the pthread kernel.
|
* Global variables for the pthread kernel.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern char *_stacktop __hidden;
|
extern char *_usrstack __hidden;
|
||||||
|
|
||||||
/* For debugger */
|
/* For debugger */
|
||||||
extern int _libthr_debug;
|
extern int _libthr_debug;
|
||||||
|
@ -149,20 +149,18 @@ singlethread_map_stacks_exec(void)
|
|||||||
{
|
{
|
||||||
int mib[2];
|
int mib[2];
|
||||||
struct rlimit rlim;
|
struct rlimit rlim;
|
||||||
u_long stacktop;
|
u_long usrstack;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
mib[0] = CTL_KERN;
|
mib[0] = CTL_KERN;
|
||||||
mib[1] = KERN_STACKTOP;
|
mib[1] = KERN_USRSTACK;
|
||||||
len = sizeof(stacktop);
|
len = sizeof(usrstack);
|
||||||
if (sysctl(mib, nitems(mib), &stacktop, &len, NULL, 0) == -1) {
|
if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), &usrstack, &len, NULL, 0)
|
||||||
mib[1] = KERN_USRSTACK;
|
== -1)
|
||||||
if (sysctl(mib, nitems(mib), &stacktop, &len, NULL, 0) == -1)
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (getrlimit(RLIMIT_STACK, &rlim) == -1)
|
if (getrlimit(RLIMIT_STACK, &rlim) == -1)
|
||||||
return;
|
return;
|
||||||
mprotect((void *)(uintptr_t)(stacktop - rlim.rlim_cur),
|
mprotect((void *)(uintptr_t)(usrstack - rlim.rlim_cur),
|
||||||
rlim.rlim_cur, _rtld_get_stack_prot());
|
rlim.rlim_cur, _rtld_get_stack_prot());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,7 +213,7 @@ _thr_stack_alloc(struct pthread_attr *attr)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Use the garbage collector lock for synchronization of the
|
* Use the garbage collector lock for synchronization of the
|
||||||
* spare stack lists and allocations from stacktop.
|
* spare stack lists and allocations from usrstack.
|
||||||
*/
|
*/
|
||||||
THREAD_LIST_WRLOCK(curthread);
|
THREAD_LIST_WRLOCK(curthread);
|
||||||
/*
|
/*
|
||||||
@ -251,11 +249,11 @@ _thr_stack_alloc(struct pthread_attr *attr)
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/*
|
/*
|
||||||
* Allocate a stack from or below stacktop, depending
|
* Allocate a stack from or below usrstack, depending
|
||||||
* on the LIBPTHREAD_BIGSTACK_MAIN env variable.
|
* on the LIBPTHREAD_BIGSTACK_MAIN env variable.
|
||||||
*/
|
*/
|
||||||
if (last_stack == NULL)
|
if (last_stack == NULL)
|
||||||
last_stack = _stacktop - _thr_stack_initial -
|
last_stack = _usrstack - _thr_stack_initial -
|
||||||
_thr_guard_default;
|
_thr_guard_default;
|
||||||
|
|
||||||
/* Allocate a new stack. */
|
/* Allocate a new stack. */
|
||||||
|
Loading…
Reference in New Issue
Block a user