mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: C threads, v. 6.2
Date: Sat, 30 Aug 2014 22:44:29 -0400	[thread overview]
Message-ID: <20140831024429.GA13259@brightrain.aerifal.cx> (raw)
In-Reply-To: <20140831013111.GA12784@brightrain.aerifal.cx>

On Sat, Aug 30, 2014 at 09:31:11PM -0400, Rich Felker wrote:
> On Sat, Aug 30, 2014 at 08:30:34PM -0400, Rich Felker wrote:
> > > For the C thread TU, what would be the mechanics for them to call one
> > > of the (aliased) pthread functions?
> > 
> > With my alternate solution just described, simply including the normal
> > pthread header and casting the pointer when making the call would be
> > fully legal.
> > 
> > With the approach we previously discussed, where we have to ensure
> > that no TU that accesses the contents of a mutex or cv structure can
> > see both the C11 and POSIX versions, The C11 TUs would have to contain
> > prototypes for the aliased POSIX functions like:
> > 
> > int __pthread_mutex_lock(mtx_t *);
> > 
> > Note that this is a perfectly correct prototype because mtx_t is just
> > this TU's typedef name for the tagless "struct { union { ... } __u; }"
> > that it's using, which is "the same type" as pthread_mutex_lock.c's
> > pthread_mutex_t.
> 
> Actually, unless the C11 functions actually access the mutex object,
> their implementation files don't need to avoid having both types
> visible. Only the TUs that dereference the object (i.e. the pthread
> ones) need to ensure that only one version of the type is visible.

The more I think about it, the more I think the visibility of the
other type is utterly irrelevant.

6.5p7: "An object shall have its stored value accessed only by an
lvalue expression that has one of the following types:

a type compatible with the effective type of the object,"

6.2.7p1: "Moreover, two structure, union, or enumerated types declared
in separate translation units are compatible if their tags and members
satisfy the following requirements: If one is declared with a tag, the
other shall be declared with the same tag. If both are completed
anywhere within their respective translation units, then the following
additional requirements apply: there shall be a one-to-one
correspondence between their members such that each pair of
corresponding members are declared with compatible types; if one
member of the pair is declared with an alignment specifier, the other
is declared with an equivalent alignment specifier; and if one member
of the pair is declared with a name, the other is declared with the
same name. For two structures, corresponding members shall be declared
in the same order. For two structures or unions, corresponding
bit-fields shall have the same widths."

As I read this, structure types declared in separate translation
units, where neither has a tag and both have identical bodies, are
compatible types, and thus allowed to alias. This means:

1. The pthread_mutex_t in pthread_mutex_*.c can alias the
pthread_mutex_t in application TUs.

2. The pthread_mutex_t in pthread_mutex_*.c can alias the
mtx_t in application TUs.

3. The mtx_t in mtx_*.c can alias the pthread_mutex_t in application
TUs.

4. The mtx_t in mtx_*.c can alias the mtx_t in application TUs.

The only aliasing that's not permitted is for the pthread_mutex_t and
mtx_t in the _same_ _TU_ to alias each other.

Is there any error in my above interpretation?

Rich


  reply	other threads:[~2014-08-31  2:44 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-27 22:11 Jens Gustedt
2014-08-27 23:46 ` Rich Felker
2014-08-28  9:40   ` Jens Gustedt
2014-08-28 11:41     ` Szabolcs Nagy
2014-08-28 16:15     ` Rich Felker
2014-08-28 19:28       ` Jens Gustedt
2014-08-28 20:00         ` Rich Felker
2014-08-28 20:55           ` Szabolcs Nagy
2014-08-28 21:38             ` Jens Gustedt
2014-08-28 21:34           ` Jens Gustedt
2014-08-28 21:56             ` Rich Felker
2014-08-28 23:25               ` Jens Gustedt
2014-08-28 23:38                 ` Rich Felker
2014-08-29  7:56                   ` Jens Gustedt
2014-08-29  8:02                     ` Jens Gustedt
2014-08-29 15:57                       ` Rich Felker
2014-08-29 19:01                         ` Jens Gustedt
2014-08-30  5:30                           ` Rich Felker
2014-08-30  7:43                             ` Jens Gustedt
2014-08-30  8:54                               ` Jens Gustedt
2014-08-31  0:30                               ` Rich Felker
2014-08-31  1:31                                 ` Rich Felker
2014-08-31  2:44                                   ` Rich Felker [this message]
2014-08-31  7:09                                     ` Jens Gustedt
2014-08-29 15:56                     ` Rich Felker
2014-08-29 18:40                       ` 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=20140831024429.GA13259@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).