Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date: Thu, 4 Jul 2013 11:26:54 -0400
From: Rich Felker <dalias@...ifal.cx>
To: musl@...ts.openwall.com
Subject: Re: Use of size_t and ssize_t in mseek

On Thu, Jul 04, 2013 at 01:10:54PM +0200, Szabolcs Nagy wrote:
> * Rich Felker <dalias@...ifal.cx> [2013-07-04 04:12:45 -0400]:
> > On Thu, Jul 04, 2013 at 09:11:29AM +0200, Jens Gustedt wrote:
> > > > qsort_s can store the comparison function and context in TLS, and then
> > > > pass to qsort a comparison function that grabs these from TLS and
> > > > calls the original comparison function with the context pointer. This
> > > > is valid assuming qsort does not run the comparisons in new threads.
> > > 
> > > sure, but for an execution of qsort_s this would have a lot of
> > > indirections and a call to TLS for every comparison. For performance
> > > sensible functions like this, this doesn't sound very attractive.
> > 
> > If it's inside musl, the TLS dereference is very cheap on most archs:
> > it's just a constant offset from the thread pointer. Same if the code
> > were static linked in the main program. Otherwise, if it's a dynamic
> > library, then yes it would be fairly costly, like you say.
> 
> it seems to me that if a qsort_s call sets the tls and then before
> the callee reads that pointer a signal interrupts with a handler that
> calls qsort_s again then the tls is overwritten by another pointer
> 
> so you lose signal-safety with the tls design

As long as qsort_s saves the old value from TLS on its stack and
restores it before returning, you don't lose AS-safety except in the
case of a longjmp out of qsort_s. But I agree this is a negative
aspect of the possible design.

Rich

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.