mailing list of musl libc
 help / color / mirror / code / Atom feed
From: 王洪亮 <wanghongliang@loongson.cn>
To: musl@lists.openwall.com
Subject: Re: [musl] add loongarch64 port
Date: Thu, 24 Mar 2022 11:01:17 +0800	[thread overview]
Message-ID: <ed570f55-5881-d7a0-6c69-d5afab6a5617@loongson.cn> (raw)
In-Reply-To: <20220322160400.GC7074@brightrain.aerifal.cx>

Hi,

the zero-length array in sigcontext is used for context extend.
this applycation has some advantage:
1.the zero-length array not take up space of struct sigcontext
2.the extended context is continuous with sigcontext.


Hongliang Wang


在 2022/3/23 上午12:04, Rich Felker 写道:
> On Tue, Mar 22, 2022 at 11:06:41AM -0400, Jeffrey Walton wrote:
>> On Tue, Mar 22, 2022 at 8:59 AM Rich Felker <dalias@libc.org> wrote:
>>> On Tue, Mar 22, 2022 at 11:52:35AM +0800, 王洪亮 wrote:
>> ....
>>>> +++ b/arch/loongarch64/bits/signal.h
>>>> @@ -0,0 +1,79 @@
>>>> +#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
>>>> + || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
>>>> +
>>>> +#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
>>>> +#define MINSIGSTKSZ 4096
>>>> +#define SIGSTKSZ 16384
>>>> +#endif
>>>> +
>>>> +typedef unsigned long greg_t, gregset_t[32];
>>>> +
>>>> +typedef struct sigcontext {
>>>> +     unsigned long pc;
>>>> +     gregset_t gregs;
>>>> +     unsigned int flags;
>>>> +     unsigned long extcontext[0] __attribute__((__aligned__(16)));
>>>> +}mcontext_t;
>>> [0] is not valid, and having a flexible array member here is possibly
>>> not even useful since I don't think it would be valid to access it via
>>> uc->uc_mcontext.extcontext[] since the instance of mcontext_t inside
>>> the ucontext struct does not have FAM space belonging to it, even if
>>> additional space was allocated past the end of the ucontext_t. In
>>> other words, I think compilers would be justified in treating attempts
>>> to access it this way as UB and optimizing them out.
>> I believe zero-length arrays are legal in C99. I'm not sure how well
>> it applies here or to Musl on some (older?) platforms.
> No, those are flexible array members and are declared with [] not [0].


  reply	other threads:[~2022-03-24  3:01 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-22  3:52 王洪亮
2022-03-22 12:59 ` Rich Felker
2022-03-22 15:06   ` Jeffrey Walton
2022-03-22 16:04     ` Rich Felker
2022-03-24  3:01       ` 王洪亮 [this message]
2022-03-24  2:22   ` 王洪亮
2022-03-22 19:03 ` Rich Felker
2022-03-22 20:36   ` Arnd Bergmann
2022-03-24  1:53     ` 王洪亮
2022-03-24  1:35   ` 王洪亮
2022-03-29  8:12 ` [musl] " 王洪亮
2022-03-29  8:26   ` Arnd Bergmann

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=ed570f55-5881-d7a0-6c69-d5afab6a5617@loongson.cn \
    --to=wanghongliang@loongson.cn \
    --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).