From patchwork Thu Dec 20 20:56:13 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 207706 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 7C4E92C0089 for ; Fri, 21 Dec 2012 07:57:37 +1100 (EST) Received: from localhost ([::1]:46286 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TlnBP-0002Rf-Nm for incoming@patchwork.ozlabs.org; Thu, 20 Dec 2012 15:57:35 -0500 Received: from eggs.gnu.org ([208.118.235.92]:59188) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TlnB0-0001SB-B1 for qemu-devel@nongnu.org; Thu, 20 Dec 2012 15:57:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TlnAw-00050u-Ce for qemu-devel@nongnu.org; Thu, 20 Dec 2012 15:57:10 -0500 Received: from smtp6-g21.free.fr ([2a01:e0c:1:1599::15]:48604) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TlnAo-0004vz-10 for qemu-devel@nongnu.org; Thu, 20 Dec 2012 15:57:06 -0500 Received: from localhost.localdomain (unknown [78.238.229.36]) by smtp6-g21.free.fr (Postfix) with ESMTP id E5007822BE; Thu, 20 Dec 2012 21:56:15 +0100 (CET) From: Laurent Vivier To: qemu-devel@nongnu.org Date: Thu, 20 Dec 2012 21:56:13 +0100 Message-Id: <1356036973-19376-1-git-send-email-laurent@vivier.eu> X-Mailer: git-send-email 1.7.10.4 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a01:e0c:1:1599::15 Cc: Riku Voipio , Laurent Vivier Subject: [Qemu-devel] [PATCH] linux-user: add string type in rtentry struct X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This allows to pass the device name. You can test this with the "route" command. WITHOUT this patch: $ sudo route add -net default gw 10.0.3.1 eth0 SIOCADDRT: Bad address $ netstat -nr Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 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 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 0 0 eth0 10.0.3.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 64 ++++++++++++++++++++++++++++++++++++++++++++ linux-user/syscall_types.h | 4 ++- 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 501002b..c2a2343 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -3691,6 +3691,70 @@ static IOCTLEntry ioctl_entries[] = { { 0, 0, }, }; +static void target_to_host_string (void *dst, const void *src) +{ +#if HOST_LONG_BITS == 32 && TARGET_ABI_BITS == 32 + if (*(uint32_t*)src == 0) { + *(uint32_t*)dst = 0; + return; + } + *(uint32_t *)dst = (uint32_t)g2h(tswap32(*(uint32_t *)src)); +#elif HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 32 + if (*(uint32_t*)src == 0) { + *(uint64_t*)dst = 0; + return; + } + *(uint64_t *)dst = (uint64_t)g2h(tswap32(*(uint32_t *)src)); +#elif HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 64 + if (*(uint64_t*)src == 0) { + *(uint64_t*)dst = 0; + return; + } + *(uint64_t *)dst = (uint64_t)g2h(tswap64(*(uint64_t *)src)); +#elif HOST_LONG_BITS == 32 && TARGET_ABI_BITS == 64 + if (*(uint64_t*)src == 0) { + *(uint32_t*)dst = 0; + return; + } + *(uint32_t *)dst = (uint32_t)g2h(tswap64(*(uint64_t *)src)); +#endif +} + +static void host_to_target_string (void *dst, const void *src) +{ +#if HOST_LONG_BITS == 32 && TARGET_ABI_BITS == 32 + if (*(uint32_t*)src == 0) { + *(uint32_t*)dst = 0; + return; + } + *(uint32_t *)dst = tswap32(h2g(*(uint32_t *)src)); +#elif HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 32 + if (*(uint64_t*)src == 0) { + *(uint32_t*)dst = 0; + return; + } + *(uint32_t *)dst = tswap32(h2g(*(uint64_t *)src)); +#elif HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 64 + if (*(uint64_t*)src == 0) { + *(uint64_t*)dst = 0; + return; + } + *(uint64_t *)dst = tswap64(h2g(*(uint64_t *)src)); +#elif HOST_LONG_BITS == 32 && TARGET_ABI_BITS == 64 + if (*(uint32_t*)src == 0) { + *(uint64_t*)dst = 0; + return; + } + *(uint64_t *)dst = tswap64(h2g(*(uint32_t *)src)); +#endif +} + +static const StructEntry struct_string_def = { + .convert = { host_to_target_string, target_to_host_string }, + .size = { sizeof(target_long), sizeof(long) }, + .align = { __alignof__(target_long), __alignof__(long) }, +}; + /* ??? Implement proper locking for ioctls. */ /* do_ioctl() Must return target values and target errnos. */ static abi_long do_ioctl(int fd, abi_long cmd, abi_long arg) diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h index 44b6a58..51fc023 100644 --- a/linux-user/syscall_types.h +++ b/linux-user/syscall_types.h @@ -14,9 +14,11 @@ STRUCT(serial_icounter_struct, STRUCT(sockaddr, TYPE_SHORT, MK_ARRAY(TYPE_CHAR, 14)) +STRUCT_SPECIAL(string) + STRUCT(rtentry, TYPE_ULONG, MK_STRUCT(STRUCT_sockaddr), MK_STRUCT(STRUCT_sockaddr), MK_STRUCT(STRUCT_sockaddr), - TYPE_SHORT, TYPE_SHORT, TYPE_ULONG, TYPE_PTRVOID, TYPE_SHORT, TYPE_PTRVOID, + TYPE_SHORT, TYPE_SHORT, TYPE_ULONG, TYPE_PTRVOID, TYPE_SHORT, MK_STRUCT(STRUCT_string), TYPE_ULONG, TYPE_ULONG, TYPE_SHORT) STRUCT(ifmap,