linux-user: correctly align types in thunking code
PATCH 1/1 linux-user: correctly align types in thunking code
This is a follow up
of patch:
commit c2e3dee6e03527baf8698698cce76b1a3174969a
Author: Laurent Vivier <[email protected]>
Date: Sun Feb 13 23:37:34 2011 +0100
linux-user: Define target alignment size
In my case m68k aligns "int" on 2 not 4. You can check this with the following program:
int main(void)
{
struct rtentry rt;
printf("rt_pad1 %ld %zd\n", offsetof(struct rtentry, rt_pad1),
sizeof(rt.rt_pad1));
printf("rt_dst %ld %zd\n", offsetof(struct rtentry, rt_dst),
sizeof(rt.rt_dst));
printf("rt_gateway %ld %zd\n", offsetof(struct rtentry, rt_gateway),
sizeof(rt.rt_gateway));
printf("rt_genmask %ld %zd\n", offsetof(struct rtentry, rt_genmask),
sizeof(rt.rt_genmask));
printf("rt_flags %ld %zd\n", offsetof(struct rtentry, rt_flags),
sizeof(rt.rt_flags));
printf("rt_pad2 %ld %zd\n", offsetof(struct rtentry, rt_pad2),
sizeof(rt.rt_pad2));
printf("rt_pad3 %ld %zd\n", offsetof(struct rtentry, rt_pad3),
sizeof(rt.rt_pad3));
printf("rt_pad4 %ld %zd\n", offsetof(struct rtentry, rt_pad4),
sizeof(rt.rt_pad4));
printf("rt_metric %ld %zd\n", offsetof(struct rtentry, rt_metric),
sizeof(rt.rt_metric));
printf("rt_dev %ld %zd\n", offsetof(struct rtentry, rt_dev),
sizeof(rt.rt_dev));
printf("rt_mtu %ld %zd\n", offsetof(struct rtentry, rt_mtu),
sizeof(rt.rt_mtu));
printf("rt_window %ld %zd\n", offsetof(struct rtentry, rt_window),
sizeof(rt.rt_window));
printf("rt_irtt %ld %zd\n", offsetof(struct rtentry, rt_irtt),
sizeof(rt.rt_irtt));
}And result is :
i386
rt_pad1 0 4rt_dst 4 16rt_gateway 20 16rt_genmask 36 16rt_flags 52 2rt_pad2 54 2rt_pad3 56 4rt_pad4 62 2rt_metric 64 2rt_dev 68 4rt_mtu 72 4rt_window 76 4rt_irtt 80 2
m68k
rt_pad1 0 4rt_dst 4 16rt_gateway 20 16rt_genmask 36 16rt_flags 52 2rt_pad2 54 2rt_pad3 56 4rt_pad4 62 2rt_metric 64 2rt_dev 66 4rt_mtu 70 4rt_window 74 4rt_irtt 78 2
This affects the "route" command :
WITHOUT this patch:
$ sudo route add -net default gw 10.0.3.1 window 1024 irtt 2 eth0 $ netstat -nr Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 0.0.0.0 10.0.3.1 0.0.0.0 UG 0 67108866 32768 eth0 10.0.3.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
WITH this patch:
$ sudo route add -net default gw 10.0.3.1 window 1024 irtt 2 eth0 $ netstat -nr Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 0.0.0.0 10.0.3.1 0.0.0.0 UG 0 1024 2 eth0 10.0.3.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
--- include/exec/user/thunk.h | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-)
include/exec/user/thunk.h +17 -5
@@ -149,20 +149,32 @@ static inline int thunk_type_align(const argtype *type_ptr, int is_host)case TYPE_CHAR :return 1 ;case TYPE_SHORT : -return 2 ; +if (is_host) { +return __alignof__(short ); + }else { +return ABI_SHORT_ALIGNMENT ; + }case TYPE_INT : -return 4 ; +if (is_host) { +return __alignof__(int ); + }else { +return ABI_INT_ALIGNMENT ; + }case TYPE_LONGLONG :case TYPE_ULONGLONG : -return 8 ; +if (is_host) { +return __alignof__(long long ); + }else { +return ABI_LLONG_ALIGNMENT ; + }case TYPE_LONG :case TYPE_ULONG :case TYPE_PTRVOID :case TYPE_PTR :if (is_host) { -return sizeof (void *); +return __alignof__(long ); }else { -return TARGET_ABI_BITS /8 ; +return ABI_LONG_ALIGNMENT ; }break ;case TYPE_OLDDEVT :
Signature · 1 line
2.14.3
Quoted 135 lines · Laurent Vivier
This is a follow up
of patch:commit
c2e3dee6e03527baf8698698cce76b1a3174969a
Author: Laurent Vivier <[email protected]>
Date: Sun Feb 13 23:37:34 2011 +0100linux-user: Define target alignment size
In my case m68k aligns "int" on 2 not 4. You can check this with the following program:
int main(void)
{ struct rtentry rt; printf("rt_pad1 %ld %zd\n", offsetof(struct rtentry, rt_pad1), sizeof(rt.rt_pad1)); printf("rt_dst %ld %zd\n", offsetof(struct rtentry, rt_dst), sizeof(rt.rt_dst)); printf("rt_gateway %ld %zd\n", offsetof(struct rtentry, rt_gateway), sizeof(rt.rt_gateway)); printf("rt_genmask %ld %zd\n", offsetof(struct rtentry, rt_genmask), sizeof(rt.rt_genmask)); printf("rt_flags %ld %zd\n", offsetof(struct rtentry, rt_flags), sizeof(rt.rt_flags)); printf("rt_pad2 %ld %zd\n", offsetof(struct rtentry, rt_pad2), sizeof(rt.rt_pad2)); printf("rt_pad3 %ld %zd\n", offsetof(struct rtentry, rt_pad3), sizeof(rt.rt_pad3)); printf("rt_pad4 %ld %zd\n", offsetof(struct rtentry, rt_pad4), sizeof(rt.rt_pad4)); printf("rt_metric %ld %zd\n", offsetof(struct rtentry, rt_metric), sizeof(rt.rt_metric)); printf("rt_dev %ld %zd\n", offsetof(struct rtentry, rt_dev), sizeof(rt.rt_dev)); printf("rt_mtu %ld %zd\n", offsetof(struct rtentry, rt_mtu), sizeof(rt.rt_mtu)); printf("rt_window %ld %zd\n", offsetof(struct rtentry, rt_window), sizeof(rt.rt_window)); printf("rt_irtt %ld %zd\n", offsetof(struct rtentry, rt_irtt), sizeof(rt.rt_irtt)); }And result is :
i386
rt_pad10 4rt_dst4 16rt_gateway20 16rt_genmask36 16rt_flags52 2rt_pad254 2rt_pad356 4rt_pad462 2rt_metric64 2rt_dev68 4rt_mtu72 4rt_window76 4rt_irtt80 2m68k
rt_pad10 4rt_dst4 16rt_gateway20 16rt_genmask36 16rt_flags52 2rt_pad254 2rt_pad356 4rt_pad462 2rt_metric64 2rt_dev66 4rt_mtu70 4rt_window74 4rt_irtt78 2This affects the "route" command :
WITHOUT this patch:
$ sudo route add -net default gw 10.0.3.1 window 1024 irtt 2 eth0 $ netstat -nr Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 0.0.0.0 10.0.3.1 0.0.0.0 UG 0 67108866 32768 eth0 10.0.3.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0WITH this patch:
$ sudo route add -net default gw 10.0.3.1 window 1024 irtt 2 eth0 $ netstat -nr Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 0.0.0.0 10.0.3.1 0.0.0.0 UG 0 1024 2 eth0 10.0.3.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0Signed-off-by Laurent Vivier <[email protected]>--- include/exec/user/thunk.h | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-)include/exec/user/thunk.h +15
-3@@ -149,20 +149,32 @@ static inline int thunk_type_align(const argtype *type_ptr, int is_host)case TYPE_CHAR :return 1 ;case TYPE_SHORT : -return 2 ; +if (is_host) { +return __alignof__(short ); + }else { +return ABI_SHORT_ALIGNMENT ; + }case TYPE_INT : -return 4 ; +if (is_host) { +return __alignof__(int ); + }else { +return ABI_INT_ALIGNMENT ; + }case TYPE_LONGLONG :case TYPE_ULONGLONG : -return 8 ; +if (is_host) { +return __alignof__(long long ); + }else { +return ABI_LLONG_ALIGNMENT ; + }case TYPE_LONG :case TYPE_ULONG :case TYPE_PTRVOID :case TYPE_PTR :
include/exec/user/thunk.h static inline int thunk_type_align(const argtype *type_ptr, int is_host)
Quoted 10 lines
include/exec/user/thunk.h +2
-3if (is_host) { -return sizeof (void *); +return __alignof__(long ); }else { -return TARGET_ABI_BITS /8 ; +return ABI_LONG_ALIGNMENT ; }break ;case TYPE_OLDDEVT : --
This definitely looks like the right thing. As well as m68k, this will also affect sh4 and i386 (where long long is 4 aligned but we were saying it should be 8 aligned) -- I wonder if that fixes any bugs...
thanks
-- PMM