summaryrefslogtreecommitdiff
path: root/libpthread
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2005-09-08 03:19:01 +0000
committerMike Frysinger <vapier@gentoo.org>2005-09-08 03:19:01 +0000
commit1fa40663d322a95532f64be8bf03d74bd73b8a51 (patch)
treeec1b6c63b563b675a5bfd71ffc18b4e5e2856a3a /libpthread
parent2be79fd8f7a9e6d68d0c1a6a8fb936761137e416 (diff)
import pthread_attr_{get,set}stack functions from glibc along with a few attr fixes
Diffstat (limited to 'libpthread')
-rw-r--r--libpthread/linuxthreads/attr.c87
1 files changed, 76 insertions, 11 deletions
diff --git a/libpthread/linuxthreads/attr.c b/libpthread/linuxthreads/attr.c
index 4432a04d1..b1e2d5745 100644
--- a/libpthread/linuxthreads/attr.c
+++ b/libpthread/linuxthreads/attr.c
@@ -12,26 +12,32 @@
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU Library General Public License for more details. */
-/* changed for uClibc */
+/* Handling of thread attributes */
+
+/* mods for uClibc */
+#define __getpagesize getpagesize
#define __sched_get_priority_min sched_get_priority_min
#define __sched_get_priority_max sched_get_priority_max
-/* Handling of thread attributes */
-
+#include <features.h>
+#define __USE_GNU
#include <errno.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdio_ext.h>
+#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/param.h>
+#include <sys/resource.h>
#include "pthread.h"
#include "internals.h"
-extern int __getpagesize(void);
-
/* NOTE: With uClibc I don't think we need this versioning stuff.
* Therefore, define the function pthread_attr_init() here using
* a strong symbol. */
-//int __pthread_attr_init_2_1(pthread_attr_t *attr)
+/*int __pthread_attr_init_2_1(pthread_attr_t *attr)*/
int pthread_attr_init(pthread_attr_t *attr)
{
size_t ps = __getpagesize ();
@@ -41,7 +47,11 @@ int pthread_attr_init(pthread_attr_t *attr)
attr->__schedparam.sched_priority = 0;
attr->__inheritsched = PTHREAD_EXPLICIT_SCHED;
attr->__scope = PTHREAD_SCOPE_SYSTEM;
+#ifdef NEED_SEPARATE_REGISTER_STACK
+ attr->__guardsize = ps + ps;
+#else
attr->__guardsize = ps;
+#endif
attr->__stackaddr = NULL;
attr->__stackaddr_set = 0;
attr->__stacksize = STACK_SIZE - ps;
@@ -156,11 +166,6 @@ int pthread_attr_getscope(const pthread_attr_t *attr, int *scope)
int __pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize)
{
- size_t ps = __getpagesize ();
-
- /* First round up the guard size. */
- guardsize = roundup (guardsize, ps);
-
/* The guard size must not be larger than the stack itself */
if (guardsize >= attr->__stacksize) return EINVAL;
@@ -185,6 +190,9 @@ int __pthread_attr_setstackaddr(pthread_attr_t *attr, void *stackaddr)
}
weak_alias (__pthread_attr_setstackaddr, pthread_attr_setstackaddr)
+link_warning (pthread_attr_setstackaddr,
+ "the use of `pthread_attr_setstackaddr' is deprecated, use `pthread_attr_setstack'")
+
int __pthread_attr_getstackaddr(const pthread_attr_t *attr, void **stackaddr)
{
/* XXX This function has a stupid definition. The standard specifies
@@ -195,8 +203,26 @@ int __pthread_attr_getstackaddr(const pthread_attr_t *attr, void **stackaddr)
}
weak_alias (__pthread_attr_getstackaddr, pthread_attr_getstackaddr)
+link_warning (pthread_attr_getstackaddr,
+ "the use of `pthread_attr_getstackaddr' is deprecated, use `pthread_attr_getstack'")
+
int __pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize)
{
+#ifdef FLOATING_STACKS
+ /* We have to check against the maximum allowed stack size. This is no
+ problem if the manager is already started and we determined it. If
+ this hasn't happened, we have to find the limit outself. */
+ if (__pthread_max_stacksize == 0)
+ __pthread_init_max_stacksize ();
+
+ if (stacksize > __pthread_max_stacksize)
+ return EINVAL;
+#else
+ /* We have a fixed size limit. */
+ if (stacksize > STACK_SIZE)
+ return EINVAL;
+#endif
+
/* We don't accept value smaller than PTHREAD_STACK_MIN. */
if (stacksize < PTHREAD_STACK_MIN)
return EINVAL;
@@ -212,3 +238,42 @@ int __pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize)
return 0;
}
weak_alias (__pthread_attr_getstacksize, pthread_attr_getstacksize)
+
+int __pthread_attr_setstack (pthread_attr_t *attr, void *stackaddr,
+ size_t stacksize)
+{
+ int err;
+
+ if ((((uintptr_t) stackaddr)
+ & (__alignof__ (struct _pthread_descr_struct) - 1)) != 0)
+ err = EINVAL;
+ else
+ err = __pthread_attr_setstacksize (attr, stacksize);
+ if (err == 0)
+ {
+#ifndef _STACK_GROWS_UP
+ attr->__stackaddr = (char *) stackaddr + stacksize;
+#else
+ attr->__stackaddr = stackaddr;
+#endif
+ attr->__stackaddr_set = 1;
+ }
+
+ return err;
+}
+
+int __pthread_attr_getstack (const pthread_attr_t *attr, void **stackaddr,
+ size_t *stacksize)
+{
+ /* XXX This function has a stupid definition. The standard specifies
+ no error value but what is if no stack address was set? We simply
+ return the value we have in the member. */
+#ifndef _STACK_GROWS_UP
+ *stackaddr = (char *) attr->__stackaddr - attr->__stacksize;
+#else
+ *stackaddr = attr->__stackaddr;
+#endif
+ *stacksize = attr->__stacksize;
+ return 0;
+}
+weak_alias (__pthread_attr_getstack, pthread_attr_getstack)