Align hard stack allocation to pthread stack setup changes
* dcrt0.cc (CYGWIN_GUARD): Remove. (child_info_fork::alloc_stack_hard_way): Align stack commit to changes of thread stack setup in CygwinCreateThread. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
parent
a54bc198b1
commit
14e3fd1b22
|
@ -1,3 +1,9 @@
|
||||||
|
2015-07-05 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
|
* dcrt0.cc (CYGWIN_GUARD): Remove.
|
||||||
|
(child_info_fork::alloc_stack_hard_way): Align stack commit to changes
|
||||||
|
of thread stack setup in CygwinCreateThread.
|
||||||
|
|
||||||
2015-07-05 Corinna Vinschen <corinna@vinschen.de>
|
2015-07-05 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
* miscfuncs.cc (struct pthread_wrapper_arg): Add member guardsize.
|
* miscfuncs.cc (struct pthread_wrapper_arg): Add member guardsize.
|
||||||
|
|
|
@ -16,6 +16,7 @@ details. */
|
||||||
#include "glob.h"
|
#include "glob.h"
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
|
#include <sys/param.h>
|
||||||
#include "environ.h"
|
#include "environ.h"
|
||||||
#include "sigproc.h"
|
#include "sigproc.h"
|
||||||
#include "pinfo.h"
|
#include "pinfo.h"
|
||||||
|
@ -404,8 +405,6 @@ check_sanity_and_sync (per_process *p)
|
||||||
|
|
||||||
child_info NO_COPY *child_proc_info;
|
child_info NO_COPY *child_proc_info;
|
||||||
|
|
||||||
#define CYGWIN_GUARD (PAGE_READWRITE | PAGE_GUARD)
|
|
||||||
|
|
||||||
void
|
void
|
||||||
child_info_fork::alloc_stack_hard_way (volatile char *b)
|
child_info_fork::alloc_stack_hard_way (volatile char *b)
|
||||||
{
|
{
|
||||||
|
@ -421,7 +420,7 @@ child_info_fork::alloc_stack_hard_way (volatile char *b)
|
||||||
|| is_mmapped_region ((caddr_t) stacktop, (caddr_t) stackbottom))
|
|| is_mmapped_region ((caddr_t) stacktop, (caddr_t) stackbottom))
|
||||||
return;
|
return;
|
||||||
/* First, try to reserve the entire stack. */
|
/* First, try to reserve the entire stack. */
|
||||||
stacksize = (SIZE_T) stackbottom - (SIZE_T) stackaddr;
|
stacksize = (PBYTE) stackbottom - (PBYTE) stackaddr;
|
||||||
if (!VirtualAlloc (stackaddr, stacksize, MEM_RESERVE, PAGE_NOACCESS))
|
if (!VirtualAlloc (stackaddr, stacksize, MEM_RESERVE, PAGE_NOACCESS))
|
||||||
{
|
{
|
||||||
PTEB teb = NtCurrentTeb ();
|
PTEB teb = NtCurrentTeb ();
|
||||||
|
@ -429,25 +428,32 @@ child_info_fork::alloc_stack_hard_way (volatile char *b)
|
||||||
"%p - %p, (child has %p - %p), %E",
|
"%p - %p, (child has %p - %p), %E",
|
||||||
stackaddr, stackbottom, teb->DeallocationStack, _tlsbase);
|
stackaddr, stackbottom, teb->DeallocationStack, _tlsbase);
|
||||||
}
|
}
|
||||||
stacksize = (SIZE_T) stackbottom - (SIZE_T) stacktop;
|
stacksize = (PBYTE) stackbottom - (PBYTE) stacktop;
|
||||||
stack_ptr = VirtualAlloc (stacktop, stacksize, MEM_COMMIT, PAGE_READWRITE);
|
stack_ptr = VirtualAlloc (stacktop, stacksize, MEM_COMMIT, PAGE_READWRITE);
|
||||||
if (!stack_ptr)
|
if (!stack_ptr)
|
||||||
abort ("can't commit memory for stack %p(%ly), %E", stacktop, stacksize);
|
abort ("can't commit memory for stack %p(%ly), %E", stacktop, stacksize);
|
||||||
if (guardsize != (size_t) -1)
|
if (guardsize != (size_t) -1)
|
||||||
{
|
{
|
||||||
|
ULONG real_guardsize = guardsize
|
||||||
|
? roundup2 (guardsize, wincap.page_size ())
|
||||||
|
: wincap.def_guard_page_size ();
|
||||||
/* Allocate PAGE_GUARD page if it still fits. */
|
/* Allocate PAGE_GUARD page if it still fits. */
|
||||||
if (stack_ptr > stackaddr)
|
if (stack_ptr > stackaddr)
|
||||||
{
|
{
|
||||||
stack_ptr = (void *) ((LPBYTE) stack_ptr
|
stack_ptr = (void *) ((PBYTE) stack_ptr - real_guardsize);
|
||||||
- wincap.page_size ());
|
if (!VirtualAlloc (stack_ptr, real_guardsize, MEM_COMMIT,
|
||||||
if (!VirtualAlloc (stack_ptr, wincap.page_size (), MEM_COMMIT,
|
PAGE_READWRITE | PAGE_GUARD))
|
||||||
CYGWIN_GUARD))
|
|
||||||
api_fatal ("fork: couldn't allocate new stack guard page %p, %E",
|
api_fatal ("fork: couldn't allocate new stack guard page %p, %E",
|
||||||
stack_ptr);
|
stack_ptr);
|
||||||
}
|
}
|
||||||
/* Allocate POSIX guard pages. */
|
/* On post-XP systems, set thread stack guarantee matching the guardsize.
|
||||||
if (guardsize > 0)
|
Note that the guardsize is one page bigger than the guarantee. */
|
||||||
VirtualAlloc (stackaddr, guardsize, MEM_COMMIT, PAGE_NOACCESS);
|
if (wincap.has_set_thread_stack_guarantee ()
|
||||||
|
&& real_guardsize > wincap.def_guard_page_size ())
|
||||||
|
{
|
||||||
|
real_guardsize -= wincap.page_size ();
|
||||||
|
SetThreadStackGuarantee (&real_guardsize);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
b[0] = '\0';
|
b[0] = '\0';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue