From 07a7300100521124402cf88b70da03e9ad9a7402 Mon Sep 17 00:00:00 2001
From: yan cui <ccuiyyan@gmail.com>
Date: Tue, 7 Jun 2016 00:47:47 +0000
Subject: [PATCH] add PTHREAD_STACK_MIN

---
 lib/libc/gen/sysconf.c        | 3 ++-
 lib/libpthread/pthread.h      | 2 ++
 lib/libpthread/pthread_attr.c | 2 +-
 3 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/lib/libc/gen/sysconf.c b/lib/libc/gen/sysconf.c
index b416238..6be2a24 100644
--- a/lib/libc/gen/sysconf.c
+++ b/lib/libc/gen/sysconf.c
@@ -53,6 +53,7 @@ __RCSID("$NetBSD: sysconf.c,v 1.37 2016/02/26 17:13:01 christos Exp $");
 #include <unistd.h>
 #include <paths.h>
 #include <pwd.h>
+#include <pthread.h>
 
 #ifdef __weak_alias
 __weak_alias(sysconf,__sysconf)
@@ -399,7 +400,7 @@ yesno:		if (sysctl(mib, mib_len, &value, &len, NULL, 0) == -1)
 	case _SC_THREAD_KEYS_MAX:
 		return _POSIX_THREAD_KEYS_MAX;
 	case _SC_THREAD_STACK_MIN:
-		return _getpagesize();
+		return PTHREAD_STACK_MIN;
 	case _SC_THREAD_THREADS_MAX:
 		if (sysctlgetmibinfo("kern.maxproc", &mib[0], &mib_len,
 		    NULL, NULL, NULL, SYSCTL_VERSION))	/* XXX */
diff --git a/lib/libpthread/pthread.h b/lib/libpthread/pthread.h
index 6d0c74f..6e0e1a2 100644
--- a/lib/libpthread/pthread.h
+++ b/lib/libpthread/pthread.h
@@ -38,6 +38,7 @@
 #include <sys/featuretest.h>
 
 #include <pthread_types.h>
+#include <signal.h>
 
 __BEGIN_DECLS
 int	pthread_atfork(void (*)(void), void (*)(void), void (*)(void));
@@ -240,6 +241,7 @@ __END_DECLS
 #define PTHREAD_CANCEL_DISABLE		1
 
 #define PTHREAD_BARRIER_SERIAL_THREAD	1234567
+#define PTHREAD_STACK_MIN	MINSIGSTKSZ
 
 /*
  * POSIX 1003.1-2001, section 2.5.9.3: "The symbolic constant
diff --git a/lib/libpthread/pthread_attr.c b/lib/libpthread/pthread_attr.c
index d0b861e..005a17a 100644
--- a/lib/libpthread/pthread_attr.c
+++ b/lib/libpthread/pthread_attr.c
@@ -361,7 +361,7 @@ pthread_attr_setstacksize(pthread_attr_t *attr, size_t size)
 {
 	struct pthread_attr_private *p;
 
-	if (size < (size_t)sysconf(_SC_THREAD_STACK_MIN))
+	if (size < (size_t)PTHREAD_STACK_MIN)
 		return EINVAL;
 
 	p = pthread__attr_init_private(attr);
-- 
2.6.4

