mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Jens Gustedt <Jens.Gustedt@inria.fr>
To: musl@lists.openwall.com
Subject: [PATCH 2/5] Clarify the implementation of the dummy alias used for pthread_self.
Date: Sat, 16 Feb 2013 00:23:39 +0100	[thread overview]
Message-ID: <af173b4d4be85eb3e4b10cf946385016cba6f5f4.1360968989.git.Jens.Gustedt@inria.fr> (raw)
In-Reply-To: <cover.1360968989.git.Jens.Gustedt@inria.fr>

In fact this points to a readonly location that is meant to crash the
executable if pthread_keys are used without having properly linked to
pthread_key_create. This can be of the correct type now.

7	4	src/thread/pthread_self.c

diff --git a/src/thread/pthread_self.c b/src/thread/pthread_self.c
index 23dbaa5..87158a7 100644
--- a/src/thread/pthread_self.c
+++ b/src/thread/pthread_self.c
@@ -2,9 +2,12 @@
 
 static struct pthread *main_thread = &(struct pthread){0};
 
-/* pthread_key_create.c overrides this */
-static const void *dummy[1] = { 0 };
-weak_alias(dummy, __pthread_tsd_main);
+/* pthread_key_create.c overrides this with a modifiable array
+   whenever the executable is linked with pthread_key_create. If it is
+   not, and an attempt is made to write to the pthread_key system, the
+   program will crash, since this is in a read-only segment. */
+WEAK_PROVIDE_DUMMY;
+_Readonly_alias void* __pthread_tsd_main[PTHREAD_KEYS_MAX];
 
 static int init_main_thread()
 {
@@ -12,7 +15,7 @@ static int init_main_thread()
 		SIGPT_SET, 0, __SYSCALL_SSLEN);
 	if (__set_thread_area(TP_ADJ(main_thread)) < 0) return -1;
 	main_thread->canceldisable = libc.canceldisable;
-	main_thread->tsd = (void **)__pthread_tsd_main;
+	main_thread->tsd = __pthread_tsd_main;
 	main_thread->errno_ptr = __errno_location();
 	main_thread->self = main_thread;
 	main_thread->tid = main_thread->pid =
-- 
1.7.9.5



  parent reply	other threads:[~2013-02-15 23:23 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-15 23:22 [PATCH 0/5] reorganize the use of weak symbols Jens Gustedt
2013-02-15 23:23 ` [PATCH 1/5] Clearly identify the readonly replacement symbols that serve as 'dummies' that could (or could not) be provided by other compilation units Jens Gustedt
2013-02-15 23:23 ` Jens Gustedt [this message]
2013-02-15 23:24 ` [PATCH 3/5] identify the weak function symbols that provide a real default action Jens Gustedt
2013-02-15 23:24 ` [PATCH 4/5] add three macros for empty dummy functions that do nothing Jens Gustedt
2013-02-15 23:25 ` [PATCH 5/5] Use the weak functions that do nothing as aliases for the default actions Jens Gustedt
2013-02-16  5:59 ` [PATCH 0/5] reorganize the use of weak symbols Rich Felker
2013-02-16  8:16   ` Jens Gustedt

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=af173b4d4be85eb3e4b10cf946385016cba6f5f4.1360968989.git.Jens.Gustedt@inria.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).