[prev in list] [next in list] [prev in thread] [next in thread] 

List:       uclibc
Subject:    Re: [PATCH] bits/waitstatus.h: correctly interpret status 0x007f
From:       James Hogan <james.hogan () imgtec ! com>
Date:       2013-06-29 20:12:16
Message-ID: CAAG0J98XvWPoVL=rKC3Fx2gZNUd5bRc+LkwumWdb7JDuvCQ+4Q () mail ! gmail ! com
[Download RAW message or body]

On 29 June 2013 14:17, Denys Vlasenko <vda.linux@googlemail.com> wrote:
> On Friday 28 June 2013 23:51, James Hogan wrote:
>> On 28 June 2013 22:16, Denys Vlasenko <vda.linux@googlemail.com> wrote:
>> > I'm not sure we really want this (it adds double evaluation in WIFSTOPPED macro),
>> > but this waitpid status does happen on MIPS.
>> >
>> > Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
>>
>> This patch looks correct and optimal to me.
>
>> >  /* Nonzero if STATUS indicates the child is stopped.  */
>> > -#define        __WIFSTOPPED(status)    (((status) & 0xff) == 0x7f)
>> > +#define        __WIFSTOPPED(status)    (((status) & 0xff) == 0x7f && ((status) & 0xff00))
>
> I'm not sure about "optimal".
> Here's another version, which compiles to one less branch:
>
> +/* Nonzero if STATUS indicates the child is stopped.
> + * Low byte should be 0x7f and 2nd byte should be nonzero.
> + * The condition is true if both bytes have at least one set bit in the same
> + * position in bits 0-6, but at least one of 7th bits are clear
> + * (because we must not match 0xffff == WCONTINUED).
> + */
> +#define        __WIFSTOPPED(status)    ((signed char)(((status) >> 8) & (status)) > 0)

Sneaky. Of course it would match certain status codes which aren't
strictly WIFSTOPPED (e.g. 0x0202, WIFSIGNALED && WTERMSIG==2). There's
nothing in the file to say that signalled status codes should have the
second byte clear, so I feel like it should be made explicit in the
comment that WIFSTOPPED assumes it (and therefore if both bytes are
non-zero and != WCONTINUED it must be WIFSTOPPED).

Cheers
James
_______________________________________________
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic