From patchwork Sun May 19 20:36:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164530 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp4799070ili; Sun, 19 May 2019 14:09:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqytQMvMe3cePYyXbSvhqhf8g2F1TFObHRhREkCH7txC5edsS3Mg+2YunTz9suJZNtOBfrAm X-Received: by 2002:a05:6402:16d2:: with SMTP id r18mr71164774edx.261.1558300152135; Sun, 19 May 2019 14:09:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558300152; cv=none; d=google.com; s=arc-20160816; b=VH1xr7Vf0ItkKtAXqU3CCDxcz5alYzIJZcIDk2Z1heKN77EBki6in8AfFveZVbOk+v ve1EhaDSvqCUDxdKB5qwyA0Mit+giukubW0R5RkdH+bZ6YLa53LI3rqEFuIgeEL4TdCQ RmulgIknIBRS1jsHnPPP//GIYKJAT7Z98iMzd/aPggOi3Pp/1firDPB/mC90qiQZf1TQ CU0+Mh/+c7WDSkUt9H0HnoHXFNGGy49SBDMWVudNb+/MnNXjxb4OnCQ/d4hxahLYArAF a4XivuxRdGdkmBGdppGFknIr6RsuF/YFkTmJlQaD0YaoNeUhFpoyQGKv0J9Vv6FGMnk7 MTtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=AI0qmlYjgj5NtbNVWKgQPuyo9CkZotUm28Hs9oy8FWY=; b=rVVQazGsq/FcNKiL1QwrAeL6qLh+eI4BVpAUMkoKApV8y+YoB0QzeQY7Q2xCfkwuG5 d2PC0YeRXYobLT7E6I9MSQuITfC7EI+lcbr2cBrRU6eb0CWbuirIGK4LLxcB14FjHfeg Ahcc6lXsY1BuJasvxtJUC0+3JJ6EYFX/R5CWxLSJp83wGQCLnavVJU9QeCUMyBX9Ra+2 3kM5W8IpSLz4zN6EPxo6shBAn7AbrCjntu5yuJFHXqykNpfpZoNKOm78D4SONSL2dx1q ZTcEaMRbVAZxybo0iN2lK48NidQMVMK8glyz1IIzw9s1h8TWdpg/wN1vKYmFeOI3398v 7hng== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=WDiAzAWB; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id j15si9790264ejz.123.2019.05.19.14.09.11 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 19 May 2019 14:09:12 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=WDiAzAWB; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:53552 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hST3O-0004T2-Uc for patch@linaro.org; Sun, 19 May 2019 17:09:11 -0400 Received: from eggs.gnu.org ([209.51.188.92]:50815) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hSSZi-0003ie-Qj for qemu-devel@nongnu.org; Sun, 19 May 2019 16:38:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hSSZh-0004X3-BL for qemu-devel@nongnu.org; Sun, 19 May 2019 16:38:30 -0400 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:44713) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hSSZh-0004W5-1T for qemu-devel@nongnu.org; Sun, 19 May 2019 16:38:29 -0400 Received: by mail-pg1-x542.google.com with SMTP id z16so5724088pgv.11 for ; Sun, 19 May 2019 13:38:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=AI0qmlYjgj5NtbNVWKgQPuyo9CkZotUm28Hs9oy8FWY=; b=WDiAzAWBoYrx+T/f1r514LVxPvjELJd8UIHCR8Cr8GWYn5WVntha55DkeNUQE2z2we MUbkuYQJaFCBtmdTgMwFMXQ2X7B90J1yR5s6SH7Wi1RUTybLjBW8goKWVwx8bYaWYgue /GwLb2E3sSQaxM54uduTRpK2wCApQob7Bzz0+mZ7aLegGqB1TlZrif2klOcWj536pjxb b+D6ziPYs4LyMAdkfXVWP0/82RHPlVtj/fLTMHroupF0IE3Ee4jez40ZB7A0e2EsGN4R iQPYXqjqlvNjUcVV4iMz7yYqHtvjCBO9mmOj/024MkRRBcjR+gYroI/d0urevPElf53n LH9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=AI0qmlYjgj5NtbNVWKgQPuyo9CkZotUm28Hs9oy8FWY=; b=D0YHcSGPTEDdcxVmrbhUlY3vjmj/oLB2ZtoNWE4iJdVtBjuAZU9ONv0Yyi93glDK/R Z/x6HJdhPo4Gf8UKQX4+nQf2wycJZrc+hyDiHVgE4O7MbxwG2TqAbb5d8vNVJxMEu0rr VjB6mF/y9Lsp8Vma2Z8ic3ZxuvYzg1Hrz2aNt9Ig48Hvx+cFhHT4aJHufaIE/WSPLVAB xDTpYkjyCVHUhdBBC54nYf1V9EDck05bg2HQxAjWvYUIH3WM0ge3pgmwol6irkZrsi7x kvKGXsmetBif8uP0hwVH3TxH7UHjD7Z7HbHA0wYjpWa+HXeFUB3aJUUiPksEZTjTAkPp GhSg== X-Gm-Message-State: APjAAAUVjXgH6Tkd+/kYVlnglU54KfpwoOfzZwwkghmG75tksGBogSqV RbAfDyXSpwLJfn12DCr4Hi1EUBBoDDI= X-Received: by 2002:a63:4346:: with SMTP id q67mr71033800pga.241.1558298307785; Sun, 19 May 2019 13:38:27 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id i7sm11397448pfo.19.2019.05.19.13.38.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 19 May 2019 13:38:26 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sun, 19 May 2019 13:36:58 -0700 Message-Id: <20190519203726.20729-47-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190519203726.20729-1-richard.henderson@linaro.org> References: <20190519203726.20729-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::542 Subject: [Qemu-devel] [PATCH v7 46/74] linux-user: Move syscall_init to the end 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: laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" No functional change. This will aid moving everything related to ioctls to a separate file. Signed-off-by: Richard Henderson --- linux-user/syscall.c | 113 +++++++++++++++++++++++-------------------- 1 file changed, 61 insertions(+), 52 deletions(-) -- 2.17.1 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 5343486a58..d0e76c392e 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -4831,58 +4831,6 @@ _syscall1(int, sys_setgid, gid_t, gid) _syscall3(int, sys_setresuid, uid_t, ruid, uid_t, euid, uid_t, suid) _syscall3(int, sys_setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid) -void syscall_init(void) -{ - IOCTLEntry *ie; - const argtype *arg_type; - int size; - int i; - - thunk_init(STRUCT_MAX); - -#define STRUCT(name, ...) thunk_register_struct(STRUCT_ ## name, #name, struct_ ## name ## _def); -#define STRUCT_SPECIAL(name) thunk_register_struct_direct(STRUCT_ ## name, #name, &struct_ ## name ## _def); -#include "syscall_types.h" -#undef STRUCT -#undef STRUCT_SPECIAL - - /* Build target_to_host_errno_table[] table from - * host_to_target_errno_table[]. */ - for (i = 0; i < ERRNO_TABLE_SIZE; i++) { - target_to_host_errno_table[host_to_target_errno_table[i]] = i; - } - - /* we patch the ioctl size if necessary. We rely on the fact that - no ioctl has all the bits at '1' in the size field */ - ie = ioctl_entries; - while (ie->target_cmd != 0) { - if (((ie->target_cmd >> TARGET_IOC_SIZESHIFT) & TARGET_IOC_SIZEMASK) == - TARGET_IOC_SIZEMASK) { - arg_type = ie->arg_type; - if (arg_type[0] != TYPE_PTR) { - fprintf(stderr, "cannot patch size for ioctl 0x%x\n", - ie->target_cmd); - exit(1); - } - arg_type++; - size = thunk_type_size(arg_type, 0); - ie->target_cmd = (ie->target_cmd & - ~(TARGET_IOC_SIZEMASK << TARGET_IOC_SIZESHIFT)) | - (size << TARGET_IOC_SIZESHIFT); - } - - /* automatic consistency check if same arch */ -#if (defined(__i386__) && defined(TARGET_I386) && defined(TARGET_ABI32)) || \ - (defined(__x86_64__) && defined(TARGET_X86_64)) - if (unlikely(ie->target_cmd != ie->host_cmd)) { - fprintf(stderr, "ERROR: ioctl(%s): target=0x%x host=0x%x\n", - ie->name, ie->target_cmd, ie->host_cmd); - } -#endif - ie++; - } -} - static inline uint64_t target_offset64(abi_ulong word0, abi_ulong word1) { #if TARGET_ABI_BITS == 64 @@ -9072,3 +9020,64 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, trace_guest_user_syscall_ret(cpu, num, ret); return ret; } + +void syscall_init(void) +{ + IOCTLEntry *ie; + const argtype *arg_type; + int size; + int i; + + thunk_init(STRUCT_MAX); + +#define STRUCT(name, ...) \ + thunk_register_struct(STRUCT_ ## name, #name, struct_ ## name ## _def); +#define STRUCT_SPECIAL(name) \ + thunk_register_struct_direct(STRUCT_ ## name, #name, \ + &struct_ ## name ## _def); + +#include "syscall_types.h" + +#undef STRUCT +#undef STRUCT_SPECIAL + + /* + * Build target_to_host_errno_table[] table from + * host_to_target_errno_table[]. + */ + for (i = 0; i < ERRNO_TABLE_SIZE; i++) { + target_to_host_errno_table[host_to_target_errno_table[i]] = i; + } + + /* + * We patch the ioctl size if necessary. We rely on the fact that + * no ioctl has all the bits at '1' in the size field. + */ + ie = ioctl_entries; + while (ie->target_cmd != 0) { + if (((ie->target_cmd >> TARGET_IOC_SIZESHIFT) & TARGET_IOC_SIZEMASK) == + TARGET_IOC_SIZEMASK) { + arg_type = ie->arg_type; + if (arg_type[0] != TYPE_PTR) { + fprintf(stderr, "cannot patch size for ioctl 0x%x\n", + ie->target_cmd); + exit(1); + } + arg_type++; + size = thunk_type_size(arg_type, 0); + ie->target_cmd = (ie->target_cmd & + ~(TARGET_IOC_SIZEMASK << TARGET_IOC_SIZESHIFT)) | + (size << TARGET_IOC_SIZESHIFT); + } + + /* automatic consistency check if same arch */ +#if (defined(__i386__) && defined(TARGET_I386) && defined(TARGET_ABI32)) || \ + (defined(__x86_64__) && defined(TARGET_X86_64)) + if (unlikely(ie->target_cmd != ie->host_cmd)) { + fprintf(stderr, "ERROR: ioctl(%s): target=0x%x host=0x%x\n", + ie->name, ie->target_cmd, ie->host_cmd); + } +#endif + ie++; + } +}