From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:48091) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TqAwz-0007Z0-BV for qemu-devel@nongnu.org; Tue, 01 Jan 2013 18:08:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TqAwy-0007vx-04 for qemu-devel@nongnu.org; Tue, 01 Jan 2013 18:08:49 -0500 Received: from moutng.kundenserver.de ([212.227.126.186]:60982) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TqAwx-0007vs-N0 for qemu-devel@nongnu.org; Tue, 01 Jan 2013 18:08:47 -0500 Message-ID: <1357081716.31530.6.camel@Quad> From: Laurent Vivier Date: Wed, 02 Jan 2013 00:08:36 +0100 In-Reply-To: <1356036920-19326-1-git-send-email-laurent@vivier.eu> References: <1356036920-19326-1-git-send-email-laurent@vivier.eu> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] linux-user: correctly align types in thunking code List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Riku Voipio Ping ! Le jeudi 20 d=C3=A9cembre 2012 =C3=A0 21:55 +0100, Laurent Vivier a =C3=A9c= rit : > This is a follow up > of patch: >=20 > commit c2e3dee6e03527baf8698698cce76b1a3174969a > Author: Laurent Vivier > Date: Sun Feb 13 23:37:34 2011 +0100 >=20 > linux-user: Define target alignment size >=20 > In my case m68k aligns "int" on 2 not 4. You can check this with the > following program: >=20 > 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_gatewa= y), > sizeof(rt.rt_gateway)); > printf("rt_genmask %ld %zd\n", offsetof(struct rtentry, rt_genmas= k), > 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)); > } >=20 > And result is : >=20 > i386 >=20 > rt_pad1 0 4 > rt_dst 4 16 > rt_gateway 20 16 > rt_genmask 36 16 > rt_flags 52 2 > rt_pad2 54 2 > rt_pad3 56 4 > rt_pad4 62 2 > rt_metric 64 2 > rt_dev 68 4 > rt_mtu 72 4 > rt_window 76 4 > rt_irtt 80 2 >=20 > m68k >=20 > rt_pad1 0 4 > rt_dst 4 16 > rt_gateway 20 16 > rt_genmask 36 16 > rt_flags 52 2 > rt_pad2 54 2 > rt_pad3 56 4 > rt_pad4 62 2 > rt_metric 64 2 > rt_dev 66 4 > rt_mtu 70 4 > rt_window 74 4 > rt_irtt 78 2 >=20 > This affects the "route" command : >=20 > WITHOUT this patch: >=20 > $ 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 327= 68 eth0 > 10.0.3.0 0.0.0.0 255.255.255.0 U 0 0 0 = eth0 >=20 > WITH this patch: >=20 > $ 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 >=20 > Signed-off-by: Laurent Vivier > --- > include/exec/user/thunk.h | 22 +++++++++++++++++----- > 1 file changed, 17 insertions(+), 5 deletions(-) >=20 > diff --git a/include/exec/user/thunk.h b/include/exec/user/thunk.h > index 87025c3..d3e9f3d 100644 > --- a/include/exec/user/thunk.h > +++ b/include/exec/user/thunk.h > @@ -151,20 +151,32 @@ static inline int thunk_type_align(const argtype *t= ype_ptr, int is_host) > case TYPE_CHAR: > return 1; > case TYPE_SHORT: > - return 2; > + if (is_host) { > + return __alignof__(short); > + } else { > + return TARGET_SHORT_ALIGNMENT; > + } > case TYPE_INT: > - return 4; > + if (is_host) { > + return __alignof__(int); > + } else { > + return TARGET_INT_ALIGNMENT; > + } > case TYPE_LONGLONG: > case TYPE_ULONGLONG: > - return 8; > + if (is_host) { > + return __alignof__(long long); > + } else { > + return TARGET_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 TARGET_LONG_ALIGNMENT; > } > break; > case TYPE_OLDDEVT: --=20 "Just play. Have fun. Enjoy the game." - Michael Jordan "Just play. Have fun. Enjoy the game." - Michael Jordan