From patchwork Mon May 14 18:19:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 913187 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=vivier.eu Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40l8JJ5YYLz9s1R for ; Tue, 15 May 2018 04:25:20 +1000 (AEST) Received: from localhost ([::1]:47614 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fII9u-0000lS-Dt for incoming@patchwork.ozlabs.org; Mon, 14 May 2018 14:25:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54769) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fII4f-0005Gj-5B for qemu-devel@nongnu.org; Mon, 14 May 2018 14:19:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fII4a-0005LA-Kj for qemu-devel@nongnu.org; Mon, 14 May 2018 14:19:52 -0400 Received: from mout.kundenserver.de ([212.227.126.130]:43111) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fII4a-0005JM-9R for qemu-devel@nongnu.org; Mon, 14 May 2018 14:19:48 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue006 [212.227.15.167]) with ESMTPSA (Nemesis) id 0MdRyx-1f0tXg44YN-00IRdo; Mon, 14 May 2018 20:19:36 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Mon, 14 May 2018 20:19:28 +0200 Message-Id: <20180514181928.18034-8-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180514181928.18034-1-laurent@vivier.eu> References: <20180514181928.18034-1-laurent@vivier.eu> X-Provags-ID: V03:K1:bs00MlDvELKh1pi8qPs5AsWzR6pUpdw1euPNfJC0dRVmW8yk3Ne gpYmX+D3Db8xqXkP8fqjgEz+03/dWWqx37Z4YxDpUhBfOArJ1pJ6FcHpLCZq1rXgwryN/6T aVET6phVfhEoZEtUTYDj5i2Us58WCASYurKkvcMd2HS8/W5DDph76LJ3lSWyr458lZiegb/ 2DNIvsrMiZmZ8/LDW9cEw== X-UI-Out-Filterresults: notjunk:1; V01:K0:wkt+H0zRjDw=:SMuH5CmNzx4Ig9qjDLK3EU /rPqXetp+Nx8XA6h+jpqH14Cwe5kPDEq57IG6pzT+J9yvtg7ztRIfUVimZrYH6RyydrkQLwvJ sdWiI+D/A2ppfykl8qydXoqgM0ESXSqOLE7cddmLy/GGXIjHMTP4+N+ybadigvr4Kqm99O/p7 1Y1T+EoUwC1djRciaq2+kdLhg/RyfhBmIcL5MbGR2TPsuCu7v/IWBiEbDZxxeVI5N8wWQPm3k wlCBIwKkoHGA7SSwWdnKYRFY9rhCDp9e4pGR2lP7+NKDmpet73Bu90k66mZ0mZrS0/SwIjPeY dzbXth+zhv/3GOgJUHoMYW+DMljnPlm8fewdsOfMAZnsHb9jmYsf0hgvNK0e1mZtyAK2jVVjv aYUGkUolH/vVxu+VIQA8g7KKq2wP2SN7YDdkqIN4PPKQiZSIKr0p2ErUtqbaouKkFKW3tsOzR Zun2PgcNIMWNJDiuDEjWQlNcSDSeaGC9aBoVu6wXN4JwSh8Y1cOeUXQFUnZhK1MnwjO2Te/0y ruUlRQBdose9QPo2qVIS3rj1bi7KEUaPT8BY6Azc0I1zxfzfvw5fm8CgSwqUxkGaJKviRBBMe nxRWILL5/tz5alb6VleZME9xLsZg/OQccpwfo8ikeODwGD6A/fotakOSADYByxdseF9YvOAhl 2iDO1S6jjx9S9miNOr5o8uC0P10ul9tuWsme963eN8f+WdyCqwCJnjrhYNk52Uo9lo8w= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.126.130 Subject: [Qemu-devel] [PULL 7/7] linux-user: correctly align types in thunking code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Riku Voipio , Laurent Vivier Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This is a follow up of patch: commit c2e3dee6e03527baf8698698cce76b1a3174969a Author: Laurent Vivier 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 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 m68k 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 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 Signed-off-by: Laurent Vivier Reviewed-by: Peter Maydell Message-Id: <20180510205949.26455-1-laurent@vivier.eu> --- include/exec/user/thunk.h | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/include/exec/user/thunk.h b/include/exec/user/thunk.h index f19ef4b230..8f55b233b3 100644 --- a/include/exec/user/thunk.h +++ b/include/exec/user/thunk.h @@ -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: