From patchwork Fri Jan 18 21:31:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 156096 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3762287jaa; Fri, 18 Jan 2019 14:17:58 -0800 (PST) X-Google-Smtp-Source: ALg8bN6eTbcHnqxVf+RAFHy75/NtTFp17dolkQ0VOwTzgVY46EYw9z/PF1i1B4JWJ/adLWzreyFs X-Received: by 2002:a5d:6a42:: with SMTP id t2mr19695516wrw.50.1547849878395; Fri, 18 Jan 2019 14:17:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547849878; cv=none; d=google.com; s=arc-20160816; b=deJve27byMquYwkQYFwNgiy92HWZ6kj9ibi5Fhk9U00zihFYLwC00XqDiLVVXzLOZ8 s6brumQ2897pZ7asZ5rzIawUeEG9NY5IheZtLuLoSelJZSwaCpmmsvPbNw4mW5Zuv9We keAwe8ZqoPR9UTrV0NQXnYlPArYxRtwE8FJF4p8e4T5uTQDM8DZibGIhxmmmLEAOYjDJ OvZsxkG4jBPgR0HotLMOYAoF6hdE+/J4erkxkOHDBio69dbCY7CW60KUjTYsUg8iv5pu LoTsN5/IMuhlfFND+ztUABtgk/ednuuXSRuD8YtxZvexw1kP4q4szlvw4hGVLU0zF/Nt HT5w== 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=9nUzq8HAn9hIBb4vo9SImCmbGSK+P9J37KbeA0FCTpI=; b=kIbywM3Pk7DKIYM66jPYsrmf7HZ3m2/clGzy7J3wP0WAnY+STWt7csmMtebc5U+osx yABx4wOQMV1rg2XykQ1SEt6L+/fXJv5HY6tdKRr7IuUzAap594PL8kk33QMMQTiNSXPh 5yeCtQxc/CRHTesvwegvXpNsrJiActIxWcnWs62rSJR0IzC+tWe+7pvVu2b+NSMxXqz5 sddWre1NJI8s+yMTm/Cutb/3Q2aUK6W1ojpDBXgxOStY4Y27X9XHpJJ5/Amb1nB5DWUb QoGESR75OqY2iAOvrLM5qy4aQSoSfSwsdQo9nrq3QRLoeDqddL+qRT/8jeo67lMZXZ2h DSOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=crFywOam; 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 a10si57635990wrt.328.2019.01.18.14.17.57 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 18 Jan 2019 14:17:58 -0800 (PST) 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=crFywOam; 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]:48063 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkcSb-0007VH-6R for patch@linaro.org; Fri, 18 Jan 2019 17:17:57 -0500 Received: from eggs.gnu.org ([209.51.188.92]:56562) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkbll-0006AN-PE for qemu-devel@nongnu.org; Fri, 18 Jan 2019 16:33:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gkblj-0006HU-Vt for qemu-devel@nongnu.org; Fri, 18 Jan 2019 16:33:41 -0500 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:44931) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gkbli-0005ob-4g for qemu-devel@nongnu.org; Fri, 18 Jan 2019 16:33:39 -0500 Received: by mail-pg1-x542.google.com with SMTP id t13so6635893pgr.11 for ; Fri, 18 Jan 2019 13:33:18 -0800 (PST) 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=9nUzq8HAn9hIBb4vo9SImCmbGSK+P9J37KbeA0FCTpI=; b=crFywOamw5KY1TeqoRgeTd3sw7qu8VC5qYjUIzsSmDFgv6p+KMbRGf/99YyWgfx9Dd Yp04s2yTBZTVAEJRQYqKWGMY3FuuempFUxW74zsC1GdSTDDPWQ3EvpnxdlY70fn/V3Vd v5xhS4vUNuW4cbBb3gW+FEu02Rk8WYZaBNIIs= 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=9nUzq8HAn9hIBb4vo9SImCmbGSK+P9J37KbeA0FCTpI=; b=RGde5hEOJUzVdRFXDg4pQbnrOMFYrBMX/9MFGs0Fqfv3rZqB2/dFsAFCCQU/c6gjSi tXBUvsWwPXBnpC4ZfeyO9qLBltMvbWqz9fNyrCwKXvit804TQu+mci5dVfCvcQjIKml/ Fx0itBxMXCovn6xmauuxX8fpXU9pgajhM2+Zf5JWuqzCx/pcZq1TkY4EYWcuGPrZd65p yhc8N3cHtmho68In7MVU18VO943Zor07hhuZ6c1OFq1bwKEl7nQ2xSx+PQ0oVK3muX/T F8Tvp/szhGyucsCthcm5qZRKk1UAwgJexCmeKDAMt6vZNCdXkAu6U3KL0dGOND3GpGvA ssKA== X-Gm-Message-State: AJcUukehBo2XCcAbHMsrYuq6MPqmL3w0Ye0po5g2T3oTNhZFhc7bu71B 5opZFDUckA+8Tfy4cx6nAv3GC9zijHg= X-Received: by 2002:a63:24c2:: with SMTP id k185mr18909967pgk.406.1547847197036; Fri, 18 Jan 2019 13:33:17 -0800 (PST) Received: from cloudburst.twiddle.net ([2001:8000:10e0:a000:c673:a6b6:fdef:1933]) by smtp.gmail.com with ESMTPSA id v12sm5833667pgg.41.2019.01.18.13.33.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 18 Jan 2019 13:33:16 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sat, 19 Jan 2019 08:31:20 +1100 Message-Id: <20190118213122.22865-47-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190118213122.22865-1-richard.henderson@linaro.org> References: <20190118213122.22865-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 v6 47/49] 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.2 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 33d536262f..82b7267b20 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -4778,58 +4778,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 @@ -8983,3 +8931,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++; + } +}