This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH 2/4] Add a signal-safe malloc replacement
- From: Paul Pluzhnikov <ppluzhnikov at google dot com>
- To: OndÅej BÃlka <neleai at seznam dot cz>
- Cc: Andrew Hunter <ahh at google dot com>, libc-alpha at sourceware dot org, carlos at redhat dot com
- Date: Wed, 18 Dec 2013 15:54:55 -0800
- Subject: Re: [PATCH 2/4] Add a signal-safe malloc replacement
- Authentication-results: sourceware.org; auth=none
- References: <1386273671-13010-1-git-send-email-ahh at google dot com> <1386722143-10513-1-git-send-email-ahh at google dot com> <1386722143-10513-2-git-send-email-ahh at google dot com> <20131211100309 dot GA24512 at domone dot podge>
On Wed, Dec 11, 2013 at 2:03 AM, OndÅej BÃlka <neleai@seznam.cz> wrote:
> On Tue, Dec 10, 2013 at 04:35:41PM -0800, Andrew Hunter wrote:
>> This is patch 2/4 of the effort to make TLS access async-signal-safe.
> ok with this.
This patch causes a failure in nptl/tst-tls3 (on either x86_64 or i686).
The problem is that nptl/allocatestack.c get_cached_stack does this:
/* Clear the DTV. */
dtv_t *dtv = GET_DTV (TLS_TPADJ (result));
for (size_t cnt = 0; cnt < dtv[-1].counter; ++cnt)
if (! dtv[1 + cnt].pointer.is_static
&& dtv[1 + cnt].pointer.val != TLS_DTV_UNALLOCATED)
free (dtv[1 + cnt].pointer.val);
memset (dtv, '\0', (dtv[-1].counter + 1) * sizeof (dtv_t));
/* Re-initialize the TLS. */
_dl_allocate_tls_init (TLS_TPADJ (result));
return result;
}
But the DTV allocation came from __signal_safe_calloc, not a regular heap,
so free()ing it causes:
*** Error in `/build/nptl/tst-tls3': double free or corruption (out):
0x00007f0484a76010 ***
We can't call __signal_safe_free() here either -- it's hidden in ld.so.
I think the right solution here is to introduce _dl_clear_dtv(), export
it from ld.so, and stop (well, reduce) groveling in ld.so's insides from
within libpthread.
Andrew,
Do you want me to try this, or would you rather fix it yourself?
Thanks,
--
Paul Pluzhnikov