From: Jens Gustedt <Jens.Gustedt@inria.fr>
To: musl@lists.openwall.com
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 [thread overview]
Message-ID: <1443084581.3492.2.camel@dysnomia.u-strasbg.fr> (raw)
In-Reply-To: <1443079354.23868.25.camel@inria.fr>
---
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
next prev parent reply other threads:[~2015-09-24 8:51 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-23 5:58 Results of static analysis with clang static analyser Khem Raj
2015-09-23 19:38 ` Rich Felker
2015-09-23 20:02 ` Jens Gustedt
2015-09-24 0:34 ` Rich Felker
2015-09-24 7:22 ` Jens Gustedt
2015-09-24 8:51 ` Jens Gustedt [this message]
2015-09-25 15:35 ` Matt Avery
2015-09-25 21:37 ` Jens Gustedt
2015-09-23 20:11 ` Szabolcs Nagy
2015-09-24 6:35 ` Rich Felker
2015-09-23 20:34 ` Szabolcs Nagy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1443084581.3492.2.camel@dysnomia.u-strasbg.fr \
--to=jens.gustedt@inria.fr \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).