mirror of git://sourceware.org/git/glibc.git
htl: Let Mach place thread stacks
Instead of trying to allocate a thread stack at a specific address, looping over the address space, just set the ANYWHERE flag in vm_allocate (). The previous behavior: - defeats ASLR (for Mach versions that support ASLR), - is particularly slow if the lower 4 GB of the address space are mapped inaccessible, as we're planning to do on 64-bit Hurd, - is just silly. Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230625231751.404120-1-bugaevc@gmail.com>
This commit is contained in:
parent
efdb85183a
commit
019b0bbc84
|
|
@ -19,14 +19,9 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include <mach.h>
|
#include <mach.h>
|
||||||
#include <mach/machine/vm_param.h>
|
|
||||||
|
|
||||||
#include <pt-internal.h>
|
#include <pt-internal.h>
|
||||||
|
|
||||||
/* The next address to use for stack allocation. */
|
|
||||||
static vm_address_t next_stack_base = VM_MIN_ADDRESS;
|
|
||||||
|
|
||||||
|
|
||||||
/* Allocate a new stack of size STACKSIZE. If successful, store the
|
/* Allocate a new stack of size STACKSIZE. If successful, store the
|
||||||
address of the newly allocated stack in *STACKADDR and return 0.
|
address of the newly allocated stack in *STACKADDR and return 0.
|
||||||
Otherwise return an error code (EINVAL for an invalid stack size,
|
Otherwise return an error code (EINVAL for an invalid stack size,
|
||||||
|
|
@ -35,30 +30,12 @@ static vm_address_t next_stack_base = VM_MIN_ADDRESS;
|
||||||
int
|
int
|
||||||
__pthread_stack_alloc (void **stackaddr, size_t stacksize)
|
__pthread_stack_alloc (void **stackaddr, size_t stacksize)
|
||||||
{
|
{
|
||||||
vm_offset_t base;
|
error_t err;
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
get_stack:
|
err = __vm_allocate (__mach_task_self (), (vm_offset_t *) stackaddr,
|
||||||
i++;
|
stacksize, TRUE);
|
||||||
for (base = next_stack_base;
|
|
||||||
base < VM_MAX_ADDRESS
|
|
||||||
&& __vm_allocate (__mach_task_self (), &base,
|
|
||||||
stacksize, FALSE) != KERN_SUCCESS; base += stacksize)
|
|
||||||
;
|
|
||||||
|
|
||||||
if (base >= VM_MAX_ADDRESS)
|
if (err == KERN_NO_SPACE)
|
||||||
{
|
err = EAGAIN;
|
||||||
if (i == 1)
|
return err;
|
||||||
{
|
|
||||||
next_stack_base = VM_MIN_ADDRESS;
|
|
||||||
goto get_stack;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return EAGAIN;
|
|
||||||
}
|
|
||||||
|
|
||||||
next_stack_base = base + stacksize;
|
|
||||||
|
|
||||||
(*stackaddr) = (void *) base;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue