mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: PATCH: don't call cleanup handlers after a regular return from the thread start function
Date: Tue, 5 Aug 2014 16:29:45 -0400	[thread overview]
Message-ID: <20140805202945.GJ1674@brightrain.aerifal.cx> (raw)
In-Reply-To: <20140805194117.GI1674@brightrain.aerifal.cx>

On Tue, Aug 05, 2014 at 03:41:17PM -0400, Rich Felker wrote:
> > But I have another reason for wanting that, future compatibility with
> > C threads. Programs that are written for C threads will not be aware
> > of such interdictions. Concretely in our case of my C thread v3 patch
> > a user can longjmp from a once-init-handler (written by her or him)
> > through pthread_once (in libc, for musl with pthread_cleanup_push) to
> > the thread start function (again user code) and then return from
> > there. (All of this seems to be allowed by POSIX)
> 
> Such a longjmp is UB unless it's explicitly permitted by the standard
> -- same as longjmp out of qsort. There's no guarantee to a function
> called as a callback from the standard library that the calling
> function does not have internal state which would be left in an
> inconsistent state by longjmp'ing out.

Actually, I can't find the text which supports this, which is odd
since it seems to be common knowledge that you can implement qsort
with algorithms that use allocation if it succeeds. The standard
_does_ contain such text for atexit and at_quick_exit, and I suppose
qsort is covered by the strict interface contract for the comparison
function (the "shall return" requirement cannot be met if the function
calls longjmp). The only other standard library function I'm aware of
which calls back to application code is call_once, so it's not clear
to me whether lack of consideration of longjmp for call_once is an
omission (likely) or an allowance for it to use longjmp (in which the
"exactly once" is probably under-specified, especially since call_once
does not synchronize until "completion of an effective call").

Rich


  reply	other threads:[~2014-08-05 20:29 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-05 16:51 Jens Gustedt
2014-08-05 17:09 ` Rich Felker
2014-08-05 19:06   ` Jens Gustedt
2014-08-05 19:41     ` Rich Felker
2014-08-05 20:29       ` Rich Felker [this message]
2014-08-05 21:05       ` Jens Gustedt
2014-08-05 21:48         ` Rich Felker
2014-08-05 23:19           ` Jens Gustedt
2014-08-06  2:02             ` Rich Felker
2014-08-06  7:15               ` Jens Gustedt
2014-08-06  9:35                 ` Rich Felker
2014-08-06 10:00                   ` Jens Gustedt
2014-08-06 10:12                     ` Rich Felker

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=20140805202945.GJ1674@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --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).