On Fri, May 9, 2014 at 9:21 AM, erik quanstrom <quans...@quanstro.net> 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

Reply via email to