* [PATCH] pthread_sigmask: check 'how' only when 'set' is not NULL
@ 2017-03-22 12:19 Yousong Zhou
2017-03-22 12:49 ` Rich Felker
0 siblings, 1 reply; 3+ messages in thread
From: Yousong Zhou @ 2017-03-22 12:19 UTC (permalink / raw)
To: dalias; +Cc: musl, Yousong Zhou
According to POSIX document
If set is a null pointer, the value of the argument how is not
significant and the thread's signal mask shall be unchanged; thus
the call can be used to enquire about currently blocked signals.
This is also how the current Linux kernel syscall is doing. So the
following function call from binutils-gdb should not fail
sigprocmask (0, NULL, &original_signal_mask);
---
src/thread/pthread_sigmask.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/thread/pthread_sigmask.c b/src/thread/pthread_sigmask.c
index 88c333f..f188782 100644
--- a/src/thread/pthread_sigmask.c
+++ b/src/thread/pthread_sigmask.c
@@ -5,7 +5,7 @@
int pthread_sigmask(int how, const sigset_t *restrict set, sigset_t *restrict old)
{
int ret;
- if ((unsigned)how - SIG_BLOCK > 2U) return EINVAL;
+ if (set && (unsigned)how - SIG_BLOCK > 2U) return EINVAL;
ret = -__syscall(SYS_rt_sigprocmask, how, set, old, _NSIG/8);
if (!ret && old) {
if (sizeof old->__bits[0] == 8) {
--
2.6.4
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] pthread_sigmask: check 'how' only when 'set' is not NULL
2017-03-22 12:19 [PATCH] pthread_sigmask: check 'how' only when 'set' is not NULL Yousong Zhou
@ 2017-03-22 12:49 ` Rich Felker
2017-03-24 2:14 ` Yousong Zhou
0 siblings, 1 reply; 3+ messages in thread
From: Rich Felker @ 2017-03-22 12:49 UTC (permalink / raw)
To: musl
On Wed, Mar 22, 2017 at 08:19:43PM +0800, Yousong Zhou wrote:
> According to POSIX document
>
> If set is a null pointer, the value of the argument how is not
> significant and the thread's signal mask shall be unchanged; thus
> the call can be used to enquire about currently blocked signals.
>
> This is also how the current Linux kernel syscall is doing. So the
> following function call from binutils-gdb should not fail
>
> sigprocmask (0, NULL, &original_signal_mask);
> ---
> src/thread/pthread_sigmask.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/thread/pthread_sigmask.c b/src/thread/pthread_sigmask.c
> index 88c333f..f188782 100644
> --- a/src/thread/pthread_sigmask.c
> +++ b/src/thread/pthread_sigmask.c
> @@ -5,7 +5,7 @@
> int pthread_sigmask(int how, const sigset_t *restrict set, sigset_t *restrict old)
> {
> int ret;
> - if ((unsigned)how - SIG_BLOCK > 2U) return EINVAL;
> + if (set && (unsigned)how - SIG_BLOCK > 2U) return EINVAL;
> ret = -__syscall(SYS_rt_sigprocmask, how, set, old, _NSIG/8);
> if (!ret && old) {
> if (sizeof old->__bits[0] == 8) {
> --
> 2.6.4
I don't think this change is conforming. There is a requirement to
produce an error ("shall fail") independent of whether the set
argument is a null pointer:
The pthread_sigmask() and sigprocmask() functions shall fail if:
[EINVAL]
The value of the how argument is not equal to one of the defined
values.
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_sigmask.html
If gdb is calling it with an invalid argument (rather, one that's
conditionally invalid depending on the platform's definitions of the
how macros), a patch should be sent to gdb to fix it.
Rich
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] pthread_sigmask: check 'how' only when 'set' is not NULL
2017-03-22 12:49 ` Rich Felker
@ 2017-03-24 2:14 ` Yousong Zhou
0 siblings, 0 replies; 3+ messages in thread
From: Yousong Zhou @ 2017-03-24 2:14 UTC (permalink / raw)
To: musl
On 22 March 2017 at 20:49, Rich Felker <dalias@libc.org> wrote:
> On Wed, Mar 22, 2017 at 08:19:43PM +0800, Yousong Zhou wrote:
>> According to POSIX document
>>
>> If set is a null pointer, the value of the argument how is not
>> significant and the thread's signal mask shall be unchanged; thus
>> the call can be used to enquire about currently blocked signals.
>>
>> This is also how the current Linux kernel syscall is doing. So the
>> following function call from binutils-gdb should not fail
>>
>> sigprocmask (0, NULL, &original_signal_mask);
>> ---
>> src/thread/pthread_sigmask.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/src/thread/pthread_sigmask.c b/src/thread/pthread_sigmask.c
>> index 88c333f..f188782 100644
>> --- a/src/thread/pthread_sigmask.c
>> +++ b/src/thread/pthread_sigmask.c
>> @@ -5,7 +5,7 @@
>> int pthread_sigmask(int how, const sigset_t *restrict set, sigset_t *restrict old)
>> {
>> int ret;
>> - if ((unsigned)how - SIG_BLOCK > 2U) return EINVAL;
>> + if (set && (unsigned)how - SIG_BLOCK > 2U) return EINVAL;
>> ret = -__syscall(SYS_rt_sigprocmask, how, set, old, _NSIG/8);
>> if (!ret && old) {
>> if (sizeof old->__bits[0] == 8) {
>> --
>> 2.6.4
>
> I don't think this change is conforming. There is a requirement to
> produce an error ("shall fail") independent of whether the set
> argument is a null pointer:
>
> The pthread_sigmask() and sigprocmask() functions shall fail if:
>
> [EINVAL]
> The value of the how argument is not equal to one of the defined
> values.
>
> http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_sigmask.html
>
> If gdb is calling it with an invalid argument (rather, one that's
> conditionally invalid depending on the platform's definitions of the
> how macros), a patch should be sent to gdb to fix it.
>
> Rich
I think you are right in the interpretation of POSIX document on this
topic. I missed the "shall fail" part in ERRORS section.
But it came to me that darwin was thought to be a certificated
POSIX-compliant environment, so I just ran tested that pthread_sigmask
call on my osx 10.11.6 and it worked without error.
https://en.wikipedia.org/wiki/Darwin_(operating_system)
I will patch gdb anyway, to be correct.
Regards,
yousong
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-03-24 2:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-22 12:19 [PATCH] pthread_sigmask: check 'how' only when 'set' is not NULL Yousong Zhou
2017-03-22 12:49 ` Rich Felker
2017-03-24 2:14 ` Yousong Zhou
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).