structure padding
John Baldwin
jhb at FreeBSD.org
Thu Jan 8 13:24:13 PST 2004
On Thursday 08 January 2004 03:14 pm, Dag-Erling Smørgrav wrote:
> In -STABLE, struct kinfo_proc is currently defined as follows:
>
> struct kinfo_proc {
> struct proc kp_proc;
> struct eproc {
> /* ... */
> char e_login[roundup(MAXLOGNAME, sizeof(long))];
> long e_spare[2];
> } kp_eproc;
> };
>
> I want to add an e_sid field to hold the process's session ID:
>
> struct kinfo_proc {
> struct proc kp_proc;
> struct eproc {
> /* ... */
> char e_login[roundup(MAXLOGNAME, sizeof(long))];
> pid_t e_sid;
> long e_spare[1];
> } kp_eproc;
> };
>
> However, a pid_t is an int, and sizeof int != sizeof long on Alpha.
> I'm not sure what will happen: will alignment rules cause gcc to add
> four bytes of padding before e_spare, conserving the size of struct
> kinfo_proc, or will struct kinfo_proc shrink by four bytes?
Maybe:
struct eproc {
union {
pid_t e_sid;
long e_oldspare;
}
long e_spare[1];
(I think gcc supports anonymous unions like that.)
In 6.0 you could remove the union hack and change the ABI, assuming that you
want to put this in 5.x as well.
--
John Baldwin <jhb at FreeBSD.org> <>< http://www.FreeBSD.org/~jhb/
"Power Users Use the Power to Serve" = http://www.FreeBSD.org
More information about the freebsd-alpha
mailing list