From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/2800 Path: news.gmane.org!not-for-mail From: Jens Gustedt Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH 2/5] Clarify the implementation of the dummy alias used for pthread_self. Date: Sat, 16 Feb 2013 00:23:39 +0100 Message-ID: References: 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 1360970630 5984 80.91.229.3 (15 Feb 2013 23:23:50 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 15 Feb 2013 23:23:50 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-2801-gllmg-musl=m.gmane.org@lists.openwall.com Sat Feb 16 00:24:12 2013 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1U6UdX-0008Gw-NW for gllmg-musl@plane.gmane.org; Sat, 16 Feb 2013 00:24:11 +0100 Original-Received: (qmail 10067 invoked by uid 550); 15 Feb 2013 23:23:51 -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 10059 invoked from network); 15 Feb 2013 23:23:51 -0000 X-IronPort-AV: E=Sophos;i="4.84,675,1355094000"; d="scan'208";a="3112314" In-Reply-To: Resent-From: Jens Gustedt Resent-To: musl@lists.openwall.com Resent-Cc: musl X-Mailer: Evolution 3.2.3-0ubuntu6 Xref: news.gmane.org gmane.linux.lib.musl.general:2800 Archived-At: 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