Date: Thu, 8 Jan 2004 15:42:49 -0500 From: John Baldwin <jhb@FreeBSD.org> To: des@des.no (Dag-Erling =?iso-8859-1?q?Sm=F8rgrav?=), alpha@freebsd.org Subject: Re: structure padding Message-ID: <200401081542.49500.jhb@FreeBSD.org> In-Reply-To: <xzpoete42r1.fsf@dwp.des.no> References: <xzpoete42r1.fsf@dwp.des.no>
next in thread | previous in thread | raw e-mail | index | archive | help
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@FreeBSD.org> <>< http://www.FreeBSD.org/~jhb/
"Power Users Use the Power to Serve" = http://www.FreeBSD.org
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200401081542.49500.jhb>
