From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/10688 Path: news.gmane.org!.POSTED!not-for-mail From: =?UTF-8?q?Timo=20Ter=C3=A4s?= Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH] add support for pthread_{get,set}attr_default_np GNU extension Date: Mon, 31 Oct 2016 19:26:58 +0200 Message-ID: <20161031172658.970-1-timo.teras@iki.fi> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1477934847 21613 195.159.176.226 (31 Oct 2016 17:27:27 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 31 Oct 2016 17:27:27 +0000 (UTC) Cc: =?UTF-8?q?Timo=20Ter=C3=A4s?= To: musl@lists.openwall.com Original-X-From: musl-return-10701-gllmg-musl=m.gmane.org@lists.openwall.com Mon Oct 31 18:27:24 2016 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1c1GMg-0004U0-Vm for gllmg-musl@m.gmane.org; Mon, 31 Oct 2016 18:27:19 +0100 Original-Received: (qmail 1715 invoked by uid 550); 31 Oct 2016 17:27:18 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 1680 invoked from network); 31 Oct 2016 17:27:16 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id; bh=aF2ttdQtRC15aiOMoZ8s3miDWp0DeS6c4kEQn5/6qj0=; b=U2X38ctMhLj1Rmv3pOAKVhoTSixqG0XTcXLt0Hg2Jp+nqaXZU5xD4BKqPqTIa5tmCj dI9ACYJtXnW+WxaLdVHjGbKXty+RhuqPFu3Cln9PKgABW2iUfBx0uOlvgAOREvBoJOz9 R9QtCOWvBi3fhZ66rxQH+2oaUvq8TCinatged0pM4fSGjViFHJuEvMkqmazy5J+7PTPm 9MCcBfp13grvakXjBjjCLMy3uf9Y8BXkuj/eWPVuUOeeHQEej2GS6e1HO3dFIHafzoj7 ujKv8SKX0uFiiIa2LDlf0I2+TckFA81Dpk82JHkqhfU3RjYa8K7RBbePU3g4/mIh9KxU AL/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=aF2ttdQtRC15aiOMoZ8s3miDWp0DeS6c4kEQn5/6qj0=; b=CrtkLjzBNNQ1TzdxpNhjSfs42OcrcXtcLgz52ZCQNlmMbCemae/9yrRKUVXqvppDSK MDiT12FUFfqnxdQASTdzTXq0aV/TRSTuIAyqhDgeLxLPWVPG3gTRkte8INlu+HH3uROm ETlH8NpHFBUZKlB7+dafypstdJUIbyGv32TlfMWCDcSoBR/EWuG4kB0ECXfth52FZxSC WQiaLU11hNlFrNtS+vqc7kAAKtnW2cERYkMmwMIXUnQ3xLHrlv0wQ4uho4UiV4D5jovT BgDQPLy2l72i/SYNcABH4b3urIn38+cZnyl+lvOF5WEb423e8r4Mmz/eSt0dLEixKNDK lC/w== X-Gm-Message-State: ABUngvfx+0eFA2ktGAZUR4Pl8klteJKSFlySIWmB45bDZYEj9llwAQNhWJFihDeEdt+gXw== X-Received: by 10.25.24.106 with SMTP id o103mr18393010lfi.74.1477934825230; Mon, 31 Oct 2016 10:27:05 -0700 (PDT) Original-Sender: =?UTF-8?Q?Timo_Ter=C3=A4s?= X-Mailer: git-send-email 2.10.1 Xref: news.gmane.org gmane.linux.lib.musl.general:10688 Archived-At: While generally this is a bad API, it is the only existing API to affect c++ (std::thread) and c11 (thrd_create) thread stack size. This patch allows applications only to increate stack and guard page sizes. --- include/pthread.h | 2 ++ src/thread/pthread_create.c | 7 +++++++ src/thread/pthread_setattr_default_np.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 src/thread/pthread_setattr_default_np.c diff --git a/include/pthread.h b/include/pthread.h index 94ef919..bba9587 100644 --- a/include/pthread.h +++ b/include/pthread.h @@ -215,6 +215,8 @@ int pthread_getaffinity_np(pthread_t, size_t, struct cpu_set_t *); int pthread_setaffinity_np(pthread_t, size_t, const struct cpu_set_t *); int pthread_getattr_np(pthread_t, pthread_attr_t *); int pthread_setname_np(pthread_t, const char *); +int pthread_getattr_default_np(pthread_attr_t *); +int pthread_setattr_default_np(const pthread_attr_t *); int pthread_tryjoin_np(pthread_t, void **); int pthread_timedjoin_np(pthread_t, void **, const struct timespec *); #endif diff --git a/src/thread/pthread_create.c b/src/thread/pthread_create.c index 9f6b98e..28cf6d4 100644 --- a/src/thread/pthread_create.c +++ b/src/thread/pthread_create.c @@ -163,6 +163,8 @@ static void *dummy_tsd[1] = { 0 }; weak_alias(dummy_tsd, __pthread_tsd_main); volatile int __block_new_threads = 0; +size_t __default_stacksize = 0; +size_t __default_guardsize = 0; static FILE *volatile dummy_file = 0; weak_alias(dummy_file, __stdin_used); @@ -204,6 +206,11 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att if (attrp && !c11) attr = *attrp; __acquire_ptc(); + if (!attrp || c11) { + attr._a_stacksize = __default_stacksize; + attr._a_guardsize = __default_guardsize; + } + if (__block_new_threads) __wait(&__block_new_threads, 0, 1, 1); if (attr._a_stackaddr) { diff --git a/src/thread/pthread_setattr_default_np.c b/src/thread/pthread_setattr_default_np.c new file mode 100644 index 0000000..21cd0f3 --- /dev/null +++ b/src/thread/pthread_setattr_default_np.c @@ -0,0 +1,31 @@ +#include "pthread_impl.h" + +extern size_t __default_stacksize; +extern size_t __default_guardsize; + +int pthread_setattr_default_np(const pthread_attr_t *attrp) +{ + if (attrp->_a_stackaddr || attrp->_a_detach || + attrp->_a_sched || attrp->_a_policy || attrp->_a_prio) + return EINVAL; + + __inhibit_ptc(); + if (DEFAULT_STACK_SIZE+attrp->_a_stacksize >= DEFAULT_STACK_SIZE+__default_stacksize) + __default_stacksize = attrp->_a_stacksize; + if (DEFAULT_GUARD_SIZE+attrp->_a_guardsize >= DEFAULT_GUARD_SIZE+__default_guardsize) + __default_guardsize = attrp->_a_guardsize; + __release_ptc(); + + return 0; +} + +int pthread_getattr_default_np(pthread_attr_t *attrp) +{ + __acquire_ptc(); + *attrp = (pthread_attr_t) { + ._a_stacksize = __default_stacksize, + ._a_guardsize = __default_guardsize, + }; + __release_ptc(); + return 0; +} -- 2.10.1