Signed long Parameter

To convert a 32-bit signed long parameter to a 64-bit value, the 32-bit value must be sign extended.

The LONG32TOLONG64 macro is provided for this operation. It converts a 32-bit signed value into a 64-bit signed value, as shown in this example:

syscall1(long incr)
    {
        /* If the caller is a 32-bit process, convert
         * 'incr' to a signed, 64-bit value.
         */
        if (!IS64U)
            incr = LONG32TOLONG64(incr);
        .
        .
        .
    }
If a parameter can be either a pointer or a symbolic constant, special handling is needed. For example, if -1 is passed as a pointer argument to indicate a special case, comparing the pointer to -1 will fail, as will unconditionally sign-extending the parameter value. Code similar to the following should be used:

syscall2(void *ptr)
    {
        /* If caller is a 32-bit process,
         * check for special parameter value.
         */
        if (!IS64U && (LONG32TOLONG64(ptr) == -1)
                 ptr = (void *)-1;

        if (ptr == (void *)-1)
            special_handling();
        else {
            .
            .
            .
        }
    }

Similar treatment is required when an unsigned long parameter is interpreted as a signed value.