* cygwin.din (pthread_attr_getguardsize): Export.
(pthread_attr_setguardsize): Export. (pthread_attr_setstack): Export. (pthread_attr_setstackaddr): Export. * init.cc (dll_entry): Remove wow64_test_stack_marker. Check for unusual stack address by testing stack addresses from current TEB. Check validity of _my_tls by testing if it's within the stack as given in current TEB. * miscfuncs.cc (struct thread_wrapper_arg): New structure used to push all required information to thread_wrapper function. (thread_wrapper): Wrapper function for actual thread function. If an application stack has been given, change %ebp and %esp so that the thread function runs on that stack. If the thread has been created by CygwinCreateThread, set up the POSIX guard pages if necessary. (CygwinCreateThread): New function. * miscfuncs.h (CygwinCreateThread): Declare. * ntdll.h (struct _TEB): Define all members up to Peb. * posix.sgml (std-susv4): Move pthread_attr_getguardsize, pthread_attr_setguardsize and pthread_attr_setstack here. (std-deprec): Add pthread_attr_setstackaddr. * sysconf.cc (sca): Set _SC_THREAD_ATTR_STACKADDR to _POSIX_THREAD_ATTR_STACKADDR. * thread.cc (pthread::precreate): Copy pthread_attr stackaddr and guardsize members. (pthread::create): Call CygwinCreateThread. (pthread_attr::pthread_attr): Initialize guardsize. (pthread_attr_setstack): New function. (pthread_attr_setstackaddr): New function. (pthread_attr_setguardsize): New function. (pthread_attr_getguardsize): New function. (pthread_getattr_np): Copy attr.guardsize. * thread.h (pthread_attr): Add member guardsize. * include/pthread.h (pthread_attr_getguardsize): Declare. (pthread_attr_setguardsize): Declare. * include/cygwin/version.h: Bump API minor number.
This commit is contained in:
@@ -23,9 +23,6 @@ details. */
|
||||
|
||||
R.Collins, April 2001. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#endif
|
||||
|
||||
#include "winsup.h"
|
||||
#include "miscfuncs.h"
|
||||
#include "path.h"
|
||||
@@ -38,6 +35,7 @@ details. */
|
||||
#include "dtable.h"
|
||||
#include "cygheap.h"
|
||||
#include "ntdll.h"
|
||||
#include "miscfuncs.h"
|
||||
|
||||
extern "C" void __fp_lock_all ();
|
||||
extern "C" void __fp_unlock_all ();
|
||||
@@ -425,7 +423,9 @@ pthread::precreate (pthread_attr *newattr)
|
||||
attr.joinable = newattr->joinable;
|
||||
attr.contentionscope = newattr->contentionscope;
|
||||
attr.inheritsched = newattr->inheritsched;
|
||||
attr.stackaddr = newattr->stackaddr;
|
||||
attr.stacksize = newattr->stacksize;
|
||||
attr.guardsize = newattr->guardsize;
|
||||
}
|
||||
|
||||
if (!pthread_mutex::is_good_object (&verifyable_mutex_obj))
|
||||
@@ -455,8 +455,9 @@ pthread::create (void *(*func) (void *), pthread_attr *newattr,
|
||||
arg = threadarg;
|
||||
|
||||
mutex.lock ();
|
||||
win32_obj_id = ::CreateThread (&sec_none_nih, attr.stacksize,
|
||||
thread_init_wrapper, this, 0, &thread_id);
|
||||
win32_obj_id = CygwinCreateThread (thread_init_wrapper, this,
|
||||
attr.stackaddr, attr.stacksize,
|
||||
attr.guardsize, 0, &thread_id);
|
||||
|
||||
if (!win32_obj_id)
|
||||
{
|
||||
@@ -1087,7 +1088,8 @@ pthread::resume ()
|
||||
|
||||
pthread_attr::pthread_attr ():verifyable_object (PTHREAD_ATTR_MAGIC),
|
||||
joinable (PTHREAD_CREATE_JOINABLE), contentionscope (PTHREAD_SCOPE_PROCESS),
|
||||
inheritsched (PTHREAD_INHERIT_SCHED), stackaddr (NULL), stacksize (0)
|
||||
inheritsched (PTHREAD_INHERIT_SCHED), stackaddr (NULL), stacksize (0),
|
||||
guardsize (0xffffffff)
|
||||
{
|
||||
schedparam.sched_priority = 0;
|
||||
}
|
||||
@@ -2239,6 +2241,20 @@ pthread_attr_setscope (pthread_attr_t *attr, int contentionscope)
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" int
|
||||
pthread_attr_setstack (pthread_attr_t *attr, void *addr, size_t size)
|
||||
{
|
||||
if (!pthread_attr::is_good_object (attr))
|
||||
return EINVAL;
|
||||
if (addr == NULL)
|
||||
return EINVAL;
|
||||
if (size < PTHREAD_STACK_MIN)
|
||||
return EINVAL;
|
||||
(*attr)->stackaddr = addr;
|
||||
(*attr)->stacksize = size;
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" int
|
||||
pthread_attr_getstack (const pthread_attr_t *attr, void **addr, size_t *size)
|
||||
{
|
||||
@@ -2250,6 +2266,17 @@ pthread_attr_getstack (const pthread_attr_t *attr, void **addr, size_t *size)
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" int
|
||||
pthread_attr_setstackaddr (pthread_attr_t *attr, void *addr)
|
||||
{
|
||||
if (!pthread_attr::is_good_object (attr))
|
||||
return EINVAL;
|
||||
if (addr == NULL)
|
||||
return EINVAL;
|
||||
(*attr)->stackaddr = addr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" int
|
||||
pthread_attr_getstackaddr (const pthread_attr_t *attr, void **addr)
|
||||
{
|
||||
@@ -2281,6 +2308,27 @@ pthread_attr_getstacksize (const pthread_attr_t *attr, size_t *size)
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" int
|
||||
pthread_attr_setguardsize (pthread_attr_t *attr, size_t size)
|
||||
{
|
||||
if (!pthread_attr::is_good_object (attr))
|
||||
return EINVAL;
|
||||
/* We don't support a guardsize of more than 1 Meg. */
|
||||
if (size > 1024 * 1024)
|
||||
return EINVAL;
|
||||
(*attr)->guardsize = size;
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" int
|
||||
pthread_attr_getguardsize (const pthread_attr_t *attr, size_t *size)
|
||||
{
|
||||
if (!pthread_attr::is_good_object (attr))
|
||||
return EINVAL;
|
||||
*size = (*attr)->guardsize;
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" int
|
||||
pthread_attr_destroy (pthread_attr_t *attr)
|
||||
{
|
||||
@@ -2429,6 +2477,7 @@ pthread_getattr_np (pthread_t thread, pthread_attr_t *attr)
|
||||
(*attr)->contentionscope = thread->attr.contentionscope;
|
||||
(*attr)->inheritsched = thread->attr.inheritsched;
|
||||
(*attr)->schedparam = thread->attr.schedparam;
|
||||
(*attr)->guardsize = thread->attr.guardsize;
|
||||
|
||||
tbi = (PTHREAD_BASIC_INFORMATION) malloc (sizeof_tbi);
|
||||
ret = NtQueryInformationThread (thread->win32_obj_id, ThreadBasicInformation,
|
||||
|
Reference in New Issue
Block a user