Subject: Re: N_GETMAGIC
To: None <current-users@netbsd.org, smd@ebone.net>
From: Wolfgang Helbig <helbig@Informatik.BA-Stuttgart.DE>
List: current-users
Date: 11/15/1998 10:32:20
> QMAGIC: 204, ZMAGIC: 267, CURRENT_N_GETMAGIC: -2138701824, N_GETMAGIC: 267
>
> I don't have a non-egcs -386 around to play with just this moment. :(

The same error occurs on non-egcs -386. The N_GET... macros in exec_aout.h
are broken for little Endian architectures, i. e. architectures that
don't have network byte order.
The bytes of (ex).a_midmag should to be swapped *before* any computing is
done:

#define WORKING_N_GETMAGIC(ex) \ 
    (((ntohl((ex).a_midmag))&0xffff0000) ? \
    (ntohl((u_int32_t)(((ex).a_midmag)))&0xffff) : ((ex).a_midmag))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ argument to ntohl (correct)

> #define CURRENT_N_GETMAGIC(ex) \
>     ((((ex).a_midmag)&0xffff0000) ? \
>     (ntohl((u_int32_t)(((ex).a_midmag))&0xffff)) : ((ex).a_midmag))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ argument to ntohl (wrong)


Wolfgang