Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241221061541.GU10433@brightrain.aerifal.cx>
Date: Sat, 21 Dec 2024 01:15:41 -0500
From: Rich Felker <dalias@...c.org>
To: Markus Wichmann <nullplan@....net>
Cc: musl@...ts.openwall.com
Subject: Re: struct mq_attr wrong on x32?

On Tue, Dec 17, 2024 at 07:46:28PM +0100, Markus Wichmann wrote:
> Hi all,
> 
> just something I saw in the code just now. I didn't test it, but I think
> struct mq_attr is wrong for x32. The kernel defines the structure like
> this:
> 
> struct mq_attr {
>     __kernel_long_t mq_flags;       /* message queue flags                  */
>     __kernel_long_t mq_maxmsg;      /* maximum number of messages           */
>     __kernel_long_t mq_msgsize;     /* maximum message size                 */
>     __kernel_long_t mq_curmsgs;     /* number of messages currently queued  */
>     __kernel_long_t __reserved[4];  /* ignored for input, zeroed for output */
> };
> 
> The type __kernel_long_t is defined as long on all architectures except
> x32, where it is defined as long long. musl defines the same structure
> with the type long on all architectures. POSIX requires these fields to
> be typed as long, so the only choice we have is to define mq_attr as
> 
> struct mq_attr {
>     long mq_flags;
>     long __r0;
>     long mq_maxmsg;
>     long __r1;
>     long mq_msgsize;
>     long __r2;
>     long mq_curmsgs;
>     long __r3;
>     long long __reserved[4]; /* sets correct structure alignment and size */
> };
> 
> on x32 only. Yeah, I know, it is ugly. We could put this in a bits/
> header, but it would have the same content on all architectures except
> one, so that would be ugly as well. Auditing them would turn into a
> find-the-differences puzzle. Oh well.

I recall something about this coming up before. I'll dig and see what
I can find. It's not clear to me if we should fix this in the
interface type (leaving behind any broken stuff already compiled using
the mismatched definition) or translate it in libc (keeping ABI same
and fixing existing binaries too).

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.