Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Thu, 24 Mar 2022 11:01:17 +0800
From: 王洪亮 <wanghongliang@...ngson.cn>
To: musl@...ts.openwall.com
Subject: Re: add loongarch64 port

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@...c.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].

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.