From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/8557 Path: news.gmane.org!not-for-mail From: Jens Gustedt Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH] help static analysis by avoiding to hold state in a pointer that is subject to arithmetic Date: Thu, 24 Sep 2015 10:51:36 +0200 Message-ID: <1443084581.3492.2.camel@dysnomia.u-strasbg.fr> References: <1443079354.23868.25.camel@inria.fr> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1443084718 16609 80.91.229.3 (24 Sep 2015 08:51:58 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 24 Sep 2015 08:51:58 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-8569-gllmg-musl=m.gmane.org@lists.openwall.com Thu Sep 24 10:51:55 2015 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1Zf2Fs-0005CI-QT for gllmg-musl@m.gmane.org; Thu, 24 Sep 2015 10:51:52 +0200 Original-Received: (qmail 23737 invoked by uid 550); 24 Sep 2015 08:51:50 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 23702 invoked from network); 24 Sep 2015 08:51:47 -0000 X-IronPort-AV: E=Sophos;i="5.17,580,1437429600"; d="scan'208";a="179210288" In-Reply-To: <1443079354.23868.25.camel@inria.fr> Resent-From: Jens Gustedt Resent-To: musl@lists.openwall.com X-Mailer: Evolution 3.12.9-1+b1 Xref: news.gmane.org gmane.linux.lib.musl.general:8557 Archived-At: --- src/thread/pthread_create.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/thread/pthread_create.c b/src/thread/pthread_create.c index e7df34a..c00c3fe 100644 --- a/src/thread/pthread_create.c +++ b/src/thread/pthread_create.c @@ -181,7 +181,7 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att int ret, c11 = (attrp == __ATTRP_C11_THREAD); size_t size, guard; struct pthread *self, *new; - unsigned char *map = 0, *stack = 0, *tsd = 0, *stack_limit; + unsigned char *map = 0, *stack = 0, *tsd, *stack_limit; unsigned flags = CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND | CLONE_THREAD | CLONE_SYSVSEM | CLONE_SETTLS | CLONE_PARENT_SETTID | CLONE_CHILD_CLEARTID | CLONE_DETACHED; @@ -218,6 +218,7 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att tsd = stack - __pthread_tsd_size; stack = tsd - libc.tls_size; memset(stack, 0, need); + goto setup; } else { size = ROUND(need); guard = 0; @@ -228,26 +229,25 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att + libc.tls_size + __pthread_tsd_size); } - if (!tsd) { - if (guard) { - map = __mmap(0, size, PROT_NONE, MAP_PRIVATE|MAP_ANON, -1, 0); - if (map == MAP_FAILED) goto fail; - if (__mprotect(map+guard, size-guard, PROT_READ|PROT_WRITE) - && errno != ENOSYS) { - __munmap(map, size); - goto fail; - } - } else { - map = __mmap(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0); - if (map == MAP_FAILED) goto fail; - } - tsd = map + size - __pthread_tsd_size; - if (!stack) { - stack = tsd - libc.tls_size; - stack_limit = map + guard; + if (guard) { + map = __mmap(0, size, PROT_NONE, MAP_PRIVATE|MAP_ANON, -1, 0); + if (map == MAP_FAILED) goto fail; + if (__mprotect(map+guard, size-guard, PROT_READ|PROT_WRITE) + && errno != ENOSYS) { + __munmap(map, size); + goto fail; } + } else { + map = __mmap(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0); + if (map == MAP_FAILED) goto fail; + } + tsd = map + size - __pthread_tsd_size; + if (!stack) { + stack = tsd - libc.tls_size; + stack_limit = map + guard; } +setup: new = __copy_tls(tsd - libc.tls_size); new->map_base = map; new->map_size = size; -- 2.1.4