Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2011-05-15 22:49:40 +0400
committerCorinna Vinschen <corinna@vinschen.de>2011-05-15 22:49:40 +0400
commitcdb4231369f4c06795e170f9cb003d8de1581f5b (patch)
treedd008237ecd92aa1101affbc9577809aa49b8dd5 /winsup/cygwin/thread.cc
parent2922c6c4aaa754fee3fcaecddd618ec9dff84cc5 (diff)
* 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.
Diffstat (limited to 'winsup/cygwin/thread.cc')
-rw-r--r--winsup/cygwin/thread.cc61
1 files changed, 55 insertions, 6 deletions
diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc
index 60a6d3a77..b53fc7f70 100644
--- a/winsup/cygwin/thread.cc
+++ b/winsup/cygwin/thread.cc
@@ -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;
}
@@ -2240,6 +2242,20 @@ pthread_attr_setscope (pthread_attr_t *attr, int contentionscope)
}
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)
{
if (!pthread_attr::is_good_object (attr))
@@ -2251,6 +2267,17 @@ pthread_attr_getstack (const pthread_attr_t *attr, void **addr, size_t *size)
}
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)
{
if (!pthread_attr::is_good_object (attr))
@@ -2282,6 +2309,27 @@ pthread_attr_getstacksize (const pthread_attr_t *attr, size_t *size)
}
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)
{
if (!pthread_attr::is_good_object (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,