From mboxrd@z Thu Jan 1 00:00:00 1970 MIME-Version: 1.0 In-Reply-To: <51d4d8ec419f841a99baf30ede300c25@brasstown.quanstro.net> References: <51d4d8ec419f841a99baf30ede300c25@brasstown.quanstro.net> Date: Fri, 9 May 2014 09:28:53 -0500 Message-ID: From: Steven Stallion To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Content-Type: text/plain; charset=UTF-8 Subject: Re: [9fans] ureg alignment Topicbox-Message-UUID: e4c6439e-ead8-11e9-9d60-3106f5b1d025 On Fri, May 9, 2014 at 9:21 AM, erik quanstrom wrote: > on 64-bit machines, the unions in the ureg.h can lead to > internal padding. (power64 avoids this issue because everything > is 64-bit aligned anyway.) to sidestep the issue, i think > it might make sense to use #defines. for example, for arm > the conversion would look something like this: > > typedef struct Ureg { > ulong r0; > ulong r1; > ulong r2; > ulong r3; > ulong r4; > ulong r5; > ulong r6; > ulong r7; > ulong r8; > ulong r9; > ulong r10; > ulong r11; > ulong r12; /* sb */ > ulong r13; > #define sp r13 > ulong r14; > #define link r14 > ulong type; /* of exception */ > ulong psr; > ulong pc; /* interrupted addr */ > } Ureg; > > is there any reason not to do this? Ugh, no! Is there a case where the padding is a problem? Normally registers belonging to the same union are uniform in size. Those defines will expand anywhere and not behave as expected: ulong sp = ureg->sp; This could lead to all sorts of entertaining problems. Steve