Re: [PATCH] Remove extra shift in __SI_CODE macro

From: Robert H. de Vries (rhdv@rhdv.cistron.nl)
Date: Sun Jul 23 2000 - 14:12:05 EST


On Sun, 23 Jul 2000, Linus Torvalds wrote:
>On Sun, 23 Jul 2000, Robert H. de Vries wrote:
>> The __SI_CODE macro shifts its argument 16 bits to the left while the only
>> argument used is already shifted 16 bits to the left. In this way no bits
>> are left on a 32 bit architecture.
>> Hence this patch, which removes the superfluous shift.
>
>Sounds like the _users_ of __SI_CODE should be fixed, rather than
>__SI_CODE. The new definition of __SI_CODE doesn't make much sense, in my
>opinion.

>From include/asm-i386/siginfo.h

#define __SI_TIMER (1 << 16)

#define __SI_CODE(T,N) ((T) | ((N) & 0xffff))

#define SI_TIMER __SI_CODE(__SI_TIMER,-2) /* sent by timer expiration */

>From arch/i386/kernel/signal.c

int copy_siginfo_to_user(siginfo_t *to, siginfo_t *from)
{
   ....

                switch (from->si_code >> 16) {
                case __SI_FAULT >> 16:
                        break;
            case __SI_CHLD >> 16:
                   ....
            default:
                ....

The trick employed here is of si_code that the upper 16 bits are used to
store something of the __SI_* family, while the lower 16 bits are used to
store the user visible si_code value.
In the routine copy_siginfo_to_user the lower 16 bits of si_code get copied
to user space while the upper 16 bits are used to select which parts of the
siginfo get copied to user space.
What happens is that if the definition of __SI_CODE performs an extra shift
of 16 on __SI_TIMER all bits are gone.
To me it looks like some leftover from development. Nobody gets bitten by
this bug except for me, with my POSIX timer patch (by the way, is it possible
to put my timer patch in the kernel (pretty please :-)).

        Robert

-- 
Robert de Vries
rhdv@rhdv.cistron.nl

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sun Jul 23 2000 - 21:00:20 EST