From patchwork Fri Jul 19 08:06:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 1133930 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=209.51.188.17; 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 [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45qkB91K5Qz9s3l for ; Fri, 19 Jul 2019 18:07:13 +1000 (AEST) Received: from localhost ([::1]:42902 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hoNv4-0005vc-T3 for incoming@patchwork.ozlabs.org; Fri, 19 Jul 2019 04:07:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44652) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hoNut-0005kA-01 for qemu-devel@nongnu.org; Fri, 19 Jul 2019 04:06:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hoNuq-0004fE-Q9 for qemu-devel@nongnu.org; Fri, 19 Jul 2019 04:06:58 -0400 Received: from mout.kundenserver.de ([212.227.126.135]:59065) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hoNuq-0004eY-HR for qemu-devel@nongnu.org; Fri, 19 Jul 2019 04:06:56 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MIyiY-1i8eqQ3Xek-00KMeY; Fri, 19 Jul 2019 10:06:17 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Fri, 19 Jul 2019 10:06:08 +0200 Message-Id: <20190719080610.1607-2-laurent@vivier.eu> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190719080610.1607-1-laurent@vivier.eu> References: <20190719080610.1607-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:dgqKW6Sk5FAX+oktD3tKuBxMmTxCzDZxjHuVtFqncFeX+B4aiq+ IojO3Rs9hWGDAY/m39nIHgw1hD+YFnZM8gfA+a7qbC9m2Aoj1pgwZ9Ex14RLa0Sdo6C64rw ZSgP6IQ9p+6fQ3OhprukR3o/lQaByQ4F1nByIIlTSSQr30dfQWd8+B4H/3qyD0beZfnm1x7 vxtQYCPqbZMZW+Hmo8YGg== X-UI-Out-Filterresults: notjunk:1; V03:K0:jVbdCNNlpwY=:y+Cb/4BYXugQsbWqNfiCM/ mglNFxPLmJjqo9t6yWn7FLd+jaN7shR02kho/YCRXQqA27AeWCqP6V5QXNBWx4/rFPTnEVa1X YCiRKH+Y7GD+bN8Z6MtlQ7uUkxPSSoZOj7szgJvmUpa+QHTGA47IdWFXuMlg2H2x7fHGE5AiR +/1KBSnXRGaILk59IFdD3fEDgYFNzYPwS9O6PD5dgDXPJgWQg9KIa1yj/pq5a8vFzE8p8Iwfc Ntqu8OO9uijtsfEc0tVmpqPGUYo+5PO+sFVGo1gBJWLD78uwcdEjp9ot/YAAKYh+0UQhGsFcB qnx349puyVZ06SHXsNJvoL7583JVZYPDtUkOawRDVe87/13AXJN2jIJgBHRyj/6spy2atld62 3pe/rc5uCA38cQNTjBj6Po77AKYUIuWUrL1Bgt+DGmglPA7cg3ZZriWOTO4Ja6Fvv9wvfsnA7 AWC655wX+4rcMuqSfmhykFdwCLzhzT0hIJASwdaOzyvcaeB8z00plGuPKctlLUlCAxxxCe8BW MVE7y82yLPimvycdMZM2W95DqJSKhZX0260/g1SCVzqM8FFSDkWpXnC1KXPlC56NAduQ/xlvq eUG6Osmw5ZzIowYIiJOkWNfBg0w/hMhFu/VFqjRjkHwRy7Td5EYdXBOVQm4Z+a+UvT/5RJyjT ljigyDAedheAnlR3RI23VbXaGpL8XDih0c7VgWDJ83pjE5L5hNU6bVYSo68ipSTFE9cMROdBr oVbfuZXPQkWYL/zBfv9gHQsLLHWaw3KiRpKr2w== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.126.135 Subject: [Qemu-devel] [PULL v2 1/3] linux-user: Fix structure target_ucontext for MIPS X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Dragan Mladjenovic , Aleksandar Rikalo , Riku Voipio , Laurent Vivier , Aleksandar Markovic , Paolo Bonzini , Aurelien Jarno , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Aleksandar Markovic Structure ucontext for MIPS is defined in the following way in Linux kernel: (arch/mips/include/uapi/asm/ucontext.h, lines 54-64) struct ucontext { /* Historic fields matching asm-generic */ unsigned long uc_flags; struct ucontext *uc_link; stack_t uc_stack; struct sigcontext uc_mcontext; sigset_t uc_sigmask; /* Extended context structures may follow ucontext */ unsigned long long uc_extcontext[0]; }; Fix the structure target_ucontext for MIPS to reflect the definition above, except the correction for field uc_extcontext, which will follow at some later time. Fixes: 94c5495d Reported-by: Dragan Mladjenovic Signed-off-by: Aleksandar Markovic Reviewed-by: Laurent Vivier Message-Id: <1562931470-3700-2-git-send-email-aleksandar.markovic@rt-rk.com> Signed-off-by: Laurent Vivier --- linux-user/mips/signal.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/linux-user/mips/signal.c b/linux-user/mips/signal.c index 6aa303ec9c16..455a8a229a83 100644 --- a/linux-user/mips/signal.c +++ b/linux-user/mips/signal.c @@ -71,10 +71,9 @@ struct sigframe { }; struct target_ucontext { - target_ulong tuc_flags; - target_ulong tuc_link; + abi_ulong tuc_flags; + abi_ulong tuc_link; target_stack_t tuc_stack; - target_ulong pad0; struct target_sigcontext tuc_mcontext; target_sigset_t tuc_sigmask; }; From patchwork Fri Jul 19 08:06:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 1133929 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=209.51.188.17; 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 [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45qk9v2HwGz9s3Z for ; Fri, 19 Jul 2019 18:06:57 +1000 (AEST) Received: from localhost ([::1]:42896 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hoNuo-0005CL-Bo for incoming@patchwork.ozlabs.org; Fri, 19 Jul 2019 04:06:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44539) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hoNui-0005C2-L1 for qemu-devel@nongnu.org; Fri, 19 Jul 2019 04:06:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hoNuh-0004Vw-I7 for qemu-devel@nongnu.org; Fri, 19 Jul 2019 04:06:48 -0400 Received: from mout.kundenserver.de ([212.227.126.187]:57363) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hoNuh-0004UU-8v for qemu-devel@nongnu.org; Fri, 19 Jul 2019 04:06:47 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1M2gt5-1hrxLC3wgJ-004CiN; Fri, 19 Jul 2019 10:06:18 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Fri, 19 Jul 2019 10:06:09 +0200 Message-Id: <20190719080610.1607-3-laurent@vivier.eu> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190719080610.1607-1-laurent@vivier.eu> References: <20190719080610.1607-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:3vZTmkp2CIU/uLb9dj5H0NYmh6QWxpKuuZCCkAw/sEStKXXk1RQ wojVnpv63+pcyzFgvI/reAUcF8xlKbpgfVBI74hCJYKG0RokUBeJ5HQg4Dl+ZPxg2xJRTC1 zDItbQQiWgTTNLxwn9UBa0MX7wMhtPXn0llHaoR0BTFZOQBsj38fmuDj8IlaPobeqrRWQ8T Zdx9M59D9FY7I78UDV+3Q== X-UI-Out-Filterresults: notjunk:1; V03:K0:90PKw+tmUqM=:oNjPxE2Kx1sPLSjFtj5TL4 NaMnlUjQrEHn5JhD3FPDwrDbiXd9SNmmktBvy7clYJ9YLKde90Jh5jYtOv/CxqaZ3R231miG/ D/B6NzU/MiOKg1hs6GDYXhM2lR7uyZtnnCFi70lRsS6v/IH/VCT5vR20YiiGytNqZfKQHg4xs sal/Fk0iJ7rz0IVD9KhdW5AsmqTIFvR+uRFnHnTO9UgOdZrDfbhbAO7jBXWWaCqDSXMAjOZjN E05H0FQl6VJknOL0Ytdx3Rr1u/welGKo+xamMDZf1FpbpL1kz6c+QmNZykTHhIyfGPBDneJlH XijY9tVJoYTI8JxMT1rubMa4kMYf+1WrYYiUui8cXfN7SXO1M71oiTMVVePWHFAZt0MDpeyR0 Rxt7vRo/SG1W1w9uNP5CFVfbV2cnFM0IZO1zIougHyIbrYHVOPJaPNYD/PbzYx0/1qPW4M4/R S7fGtRxl7QZxdLF06Nf+bc9JLwI7+Lv0mtPpcUQm1Ntuc0/V0WgMWnkCVELnu8EkkNCQ5HoMt ioIH5LKZogAy8BC3nTDefaHpqQUqiJlZ7xoB5/NQgVXUx/Pjtqc/VEnaaMphSkXKGRd5ldytm QBn2oxKVlwQdMlVeqbA9izPrgHvQZDAV5s+M+8x/1DMkjaxso8IAnZjhn2/8AwFFfmQY0OFMs 89ULtCBtatzrOUY07JycAaWKUeBKCGCAl3uGXULIqkAsuP8aaeDYZXO/JGFGKvKP1tkipDSU2 UasXO6fQanJNbxWnpLJafJ56qArdFz0ltNx3Hjp8D3Mk/x2hqWZf9LAnDfM= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.126.187 Subject: [Qemu-devel] [PULL v2 2/3] linux-user: check valid address in access_ok() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , =?utf-8?q?R=C3=A9mi_Denis-Courmon?= =?utf-8?q?t?= , Aleksandar Rikalo , Riku Voipio , Laurent Vivier , Aleksandar Markovic , Paolo Bonzini , Aurelien Jarno , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Rémi Denis-Courmont Fix a crash with LTP testsuite and aarch64: tst_test.c:1015: INFO: Timeout per run is 0h 05m 00s qemu-aarch64: .../qemu/accel/tcg/translate-all.c:2522: page_check_range: Assertion `start < ((target_ulong)1 << L1_MAP_ADDR_SPACE_BITS)' failed. qemu:handle_cpu_signal received signal outside vCPU context @ pc=0x60001554 page_check_range() should never be called with address outside the guest address space. This patch adds a guest_addr_valid() check in access_ok() to only call page_check_range() with a valid address. Fixes: f6768aa1b4c6 ("target/arm: fix AArch64 virtual address space size") Signed-off-by: Rémi Denis-Courmont Signed-off-by: Laurent Vivier Message-Id: <20190704084115.24713-1-lvivier@redhat.com> Signed-off-by: Laurent Vivier --- include/exec/cpu_ldst.h | 4 ++++ linux-user/qemu.h | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h index 9de8c933031b..9151fdb042c4 100644 --- a/include/exec/cpu_ldst.h +++ b/include/exec/cpu_ldst.h @@ -62,7 +62,11 @@ typedef uint64_t abi_ptr; /* All direct uses of g2h and h2g need to go away for usermode softmmu. */ #define g2h(x) ((void *)((unsigned long)(abi_ptr)(x) + guest_base)) +#if HOST_LONG_BITS <= TARGET_VIRT_ADDR_SPACE_BITS +#define guest_addr_valid(x) (1) +#else #define guest_addr_valid(x) ((x) <= GUEST_ADDR_MAX) +#endif #define h2g_valid(x) guest_addr_valid((unsigned long)(x) - guest_base) static inline int guest_range_valid(unsigned long start, unsigned long len) diff --git a/linux-user/qemu.h b/linux-user/qemu.h index fab287b7ec50..4258e4162d26 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -456,7 +456,9 @@ extern unsigned long guest_stack_size; static inline int access_ok(int type, abi_ulong addr, abi_ulong size) { - return page_check_range((target_ulong)addr, size, + return guest_addr_valid(addr) && + (size == 0 || guest_addr_valid(addr + size - 1)) && + page_check_range((target_ulong)addr, size, (type == VERIFY_READ) ? PAGE_READ : (PAGE_READ | PAGE_WRITE)) == 0; } From patchwork Fri Jul 19 08:06:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 1133931 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=209.51.188.17; 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 [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45qkB86hV6z9s3Z for ; Fri, 19 Jul 2019 18:07:12 +1000 (AEST) Received: from localhost ([::1]:42900 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hoNv4-0005s9-Dv for incoming@patchwork.ozlabs.org; Fri, 19 Jul 2019 04:07:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44633) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hoNur-0005et-MM for qemu-devel@nongnu.org; Fri, 19 Jul 2019 04:06:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hoNuq-0004ef-0O for qemu-devel@nongnu.org; Fri, 19 Jul 2019 04:06:57 -0400 Received: from mout.kundenserver.de ([212.227.126.134]:44407) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hoNup-0004dd-Mp for qemu-devel@nongnu.org; Fri, 19 Jul 2019 04:06:55 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MIyiY-1i8eqP00kc-00KMeY; Fri, 19 Jul 2019 10:06:20 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Fri, 19 Jul 2019 10:06:10 +0200 Message-Id: <20190719080610.1607-4-laurent@vivier.eu> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190719080610.1607-1-laurent@vivier.eu> References: <20190719080610.1607-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:I8i7e3RY6gHCUkvrXaBiI6wB7T8gY4N1ujBA/PXEN/ONZuKEWMV 9FqkWsYfX5aQbVGEl2EIX296TrdP6BzeiScjG1nabNOLpn6ZW7xLyq//uziYzAFGtJ+pR5B iwcOa8C/HH+syrlc//xHBfFhBaydnXnVVWI07v9Vc2kA6r3JrRJMbsMj12xGdE/xw3tTbIu N4zjoKmlCefPVzxWiqM4A== X-UI-Out-Filterresults: notjunk:1; V03:K0:QYbOIgruQtU=:fJqA0mKJ5gNyxRpTjR4M15 trzcSoMJ/UjeAI5RSv7UlU8sreOf3tm+fU4CKNppD2GBHk2Rdd1iP4IgZOH6g5aMyBP0zj2YY t1lwyIL4SBXAqdEy8v7RV6PN7QkGv8bkcwdjPpzxCLfCejaWywlWgUCOr9aCB8l+driYD/Cvj bKKE8aCZ7dDJu5UZvld1K3vo0ey6bVfjyhI9PTOOXUoo03H0FlFA4EUfeMW7FjgJl2rjF9Zon CqoLi2fQRdhDBn7TMF/STbCxid+1ybmPJkfuBuiMKBiWjzvHn9CF1q9v3xzwrFHwY7IYSSmKb nr6TUtMUrEsrT7ObdMinIYDjKBANzQnCfLS+JAZRyed/vbzW3bMkRXfv0eaWaP2k++C7/AVTi bXCq7BhMDZw/iJgubteD2leCPhu9rxeMITkfUolklvGBU4IWTQjH9r3D0wVfihu6bSZv5Oakg /RaXPgQTbcWImru4h1OoE/9cp/TvFIhyp7zNYkpCPKhV5u0Tp90ofv/Sx3fnOuL/jMLB5sa2v dlUkzA0+PINkm6UEqBlBHPxGovLPdf4OeAMnPCqv+ugePgs5ymYk5fiqYPQZBOiMSG+KiFO/V dSl00KUCfxiwoI/xs2EdAFyPBC3ukIjBt11V7ZX4XvEMJchnk24505B5BCLfVna+HUGL3D3Ou ApbMql4k700FXfbvGj1gzvrVA+k6CqY6sKUya/R9haeGgEjUerXewU8lyLnZGXs67QLm0wTR5 BMNxX2+AD5l5T8e7MMHwnCxzBXq9/uleUSiez9/BiSdarsn1Ip6u97SbiL0= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.126.134 Subject: [Qemu-devel] [PULL v2 3/3] linux-user: fix to handle variably sized SIOCGSTAMP with new kernels X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Arnd Bergmann , Aleksandar Rikalo , Riku Voipio , Laurent Vivier , Aleksandar Markovic , Paolo Bonzini , Aurelien Jarno , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Daniel P. Berrangé The SIOCGSTAMP symbol was previously defined in the asm-generic/sockios.h header file. QEMU sees that header indirectly via sys/socket.h In linux kernel commit 0768e17073dc527ccd18ed5f96ce85f9985e9115 the asm-generic/sockios.h header no longer defines SIOCGSTAMP. Instead it provides only SIOCGSTAMP_OLD, which only uses a 32-bit time_t on 32-bit architectures. The linux/sockios.h header then defines SIOCGSTAMP using either SIOCGSTAMP_OLD or SIOCGSTAMP_NEW as appropriate. If SIOCGSTAMP_NEW is used, then the tv_sec field is 64-bit even on 32-bit architectures To cope with this we must now convert the old and new type from the target to the host one. Signed-off-by: Daniel P. Berrangé Signed-off-by: Laurent Vivier Reviewed-by: Arnd Bergmann Message-Id: <20190718130641.15294-1-laurent@vivier.eu> Signed-off-by: Laurent Vivier --- linux-user/ioctls.h | 21 +++++- linux-user/syscall.c | 140 +++++++++++++++++++++++++++++-------- linux-user/syscall_defs.h | 30 +++++++- linux-user/syscall_types.h | 6 -- 4 files changed, 159 insertions(+), 38 deletions(-) diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h index 5e84dc7c3a77..3281c97ca263 100644 --- a/linux-user/ioctls.h +++ b/linux-user/ioctls.h @@ -222,8 +222,25 @@ IOCTL(SIOCGIWNAME, IOC_W | IOC_R, MK_PTR(MK_STRUCT(STRUCT_char_ifreq))) IOCTL(SIOCSPGRP, IOC_W, MK_PTR(TYPE_INT)) /* pid_t */ IOCTL(SIOCGPGRP, IOC_R, MK_PTR(TYPE_INT)) /* pid_t */ - IOCTL(SIOCGSTAMP, IOC_R, MK_PTR(MK_STRUCT(STRUCT_timeval))) - IOCTL(SIOCGSTAMPNS, IOC_R, MK_PTR(MK_STRUCT(STRUCT_timespec))) + + /* + * We can't use IOCTL_SPECIAL() because it will set + * host_cmd to XXX_OLD and XXX_NEW and these macros + * are not defined with kernel prior to 5.2. + * We must set host_cmd to the same value as in target_cmd + * otherwise the consistency check in syscall_init() + * will trigger an error. + * host_cmd is ignored by the do_ioctl_XXX() helpers. + * FIXME: create a macro to define this kind of entry + */ + { TARGET_SIOCGSTAMP_OLD, TARGET_SIOCGSTAMP_OLD, + "SIOCGSTAMP_OLD", IOC_R, do_ioctl_SIOCGSTAMP }, + { TARGET_SIOCGSTAMPNS_OLD, TARGET_SIOCGSTAMPNS_OLD, + "SIOCGSTAMPNS_OLD", IOC_R, do_ioctl_SIOCGSTAMPNS }, + { TARGET_SIOCGSTAMP_NEW, TARGET_SIOCGSTAMP_NEW, + "SIOCGSTAMP_NEW", IOC_R, do_ioctl_SIOCGSTAMP }, + { TARGET_SIOCGSTAMPNS_NEW, TARGET_SIOCGSTAMPNS_NEW, + "SIOCGSTAMPNS_NEW", IOC_R, do_ioctl_SIOCGSTAMPNS }, IOCTL(RNDGETENTCNT, IOC_R, MK_PTR(TYPE_INT)) IOCTL(RNDADDTOENTCNT, IOC_W, MK_PTR(TYPE_INT)) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 39a37496fed5..8367cb138dfe 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -1126,8 +1127,9 @@ static inline abi_long copy_from_user_timeval(struct timeval *tv, { struct target_timeval *target_tv; - if (!lock_user_struct(VERIFY_READ, target_tv, target_tv_addr, 1)) + if (!lock_user_struct(VERIFY_READ, target_tv, target_tv_addr, 1)) { return -TARGET_EFAULT; + } __get_user(tv->tv_sec, &target_tv->tv_sec); __get_user(tv->tv_usec, &target_tv->tv_usec); @@ -1142,8 +1144,26 @@ static inline abi_long copy_to_user_timeval(abi_ulong target_tv_addr, { struct target_timeval *target_tv; - if (!lock_user_struct(VERIFY_WRITE, target_tv, target_tv_addr, 0)) + if (!lock_user_struct(VERIFY_WRITE, target_tv, target_tv_addr, 0)) { + return -TARGET_EFAULT; + } + + __put_user(tv->tv_sec, &target_tv->tv_sec); + __put_user(tv->tv_usec, &target_tv->tv_usec); + + unlock_user_struct(target_tv, target_tv_addr, 1); + + return 0; +} + +static inline abi_long copy_to_user_timeval64(abi_ulong target_tv_addr, + const struct timeval *tv) +{ + struct target__kernel_sock_timeval *target_tv; + + if (!lock_user_struct(VERIFY_WRITE, target_tv, target_tv_addr, 0)) { return -TARGET_EFAULT; + } __put_user(tv->tv_sec, &target_tv->tv_sec); __put_user(tv->tv_usec, &target_tv->tv_usec); @@ -1153,6 +1173,48 @@ static inline abi_long copy_to_user_timeval(abi_ulong target_tv_addr, return 0; } +static inline abi_long target_to_host_timespec(struct timespec *host_ts, + abi_ulong target_addr) +{ + struct target_timespec *target_ts; + + if (!lock_user_struct(VERIFY_READ, target_ts, target_addr, 1)) { + return -TARGET_EFAULT; + } + __get_user(host_ts->tv_sec, &target_ts->tv_sec); + __get_user(host_ts->tv_nsec, &target_ts->tv_nsec); + unlock_user_struct(target_ts, target_addr, 0); + return 0; +} + +static inline abi_long host_to_target_timespec(abi_ulong target_addr, + struct timespec *host_ts) +{ + struct target_timespec *target_ts; + + if (!lock_user_struct(VERIFY_WRITE, target_ts, target_addr, 0)) { + return -TARGET_EFAULT; + } + __put_user(host_ts->tv_sec, &target_ts->tv_sec); + __put_user(host_ts->tv_nsec, &target_ts->tv_nsec); + unlock_user_struct(target_ts, target_addr, 1); + return 0; +} + +static inline abi_long host_to_target_timespec64(abi_ulong target_addr, + struct timespec *host_ts) +{ + struct target__kernel_timespec *target_ts; + + if (!lock_user_struct(VERIFY_WRITE, target_ts, target_addr, 0)) { + return -TARGET_EFAULT; + } + __put_user(host_ts->tv_sec, &target_ts->tv_sec); + __put_user(host_ts->tv_nsec, &target_ts->tv_nsec); + unlock_user_struct(target_ts, target_addr, 1); + return 0; +} + static inline abi_long copy_from_user_timezone(struct timezone *tz, abi_ulong target_tz_addr) { @@ -4899,6 +4961,54 @@ static abi_long do_ioctl_kdsigaccept(const IOCTLEntry *ie, uint8_t *buf_temp, return get_errno(safe_ioctl(fd, ie->host_cmd, sig)); } +static abi_long do_ioctl_SIOCGSTAMP(const IOCTLEntry *ie, uint8_t *buf_temp, + int fd, int cmd, abi_long arg) +{ + struct timeval tv; + abi_long ret; + + ret = get_errno(safe_ioctl(fd, SIOCGSTAMP, &tv)); + if (is_error(ret)) { + return ret; + } + + if (cmd == (int)TARGET_SIOCGSTAMP_OLD) { + if (copy_to_user_timeval(arg, &tv)) { + return -TARGET_EFAULT; + } + } else { + if (copy_to_user_timeval64(arg, &tv)) { + return -TARGET_EFAULT; + } + } + + return ret; +} + +static abi_long do_ioctl_SIOCGSTAMPNS(const IOCTLEntry *ie, uint8_t *buf_temp, + int fd, int cmd, abi_long arg) +{ + struct timespec ts; + abi_long ret; + + ret = get_errno(safe_ioctl(fd, SIOCGSTAMPNS, &ts)); + if (is_error(ret)) { + return ret; + } + + if (cmd == (int)TARGET_SIOCGSTAMPNS_OLD) { + if (host_to_target_timespec(arg, &ts)) { + return -TARGET_EFAULT; + } + } else{ + if (host_to_target_timespec64(arg, &ts)) { + return -TARGET_EFAULT; + } + } + + return ret; +} + #ifdef TIOCGPTPEER static abi_long do_ioctl_tiocgptpeer(const IOCTLEntry *ie, uint8_t *buf_temp, int fd, int cmd, abi_long arg) @@ -6271,32 +6381,6 @@ static inline abi_long target_ftruncate64(void *cpu_env, abi_long arg1, } #endif -static inline abi_long target_to_host_timespec(struct timespec *host_ts, - abi_ulong target_addr) -{ - struct target_timespec *target_ts; - - if (!lock_user_struct(VERIFY_READ, target_ts, target_addr, 1)) - return -TARGET_EFAULT; - __get_user(host_ts->tv_sec, &target_ts->tv_sec); - __get_user(host_ts->tv_nsec, &target_ts->tv_nsec); - unlock_user_struct(target_ts, target_addr, 0); - return 0; -} - -static inline abi_long host_to_target_timespec(abi_ulong target_addr, - struct timespec *host_ts) -{ - struct target_timespec *target_ts; - - if (!lock_user_struct(VERIFY_WRITE, target_ts, target_addr, 0)) - return -TARGET_EFAULT; - __put_user(host_ts->tv_sec, &target_ts->tv_sec); - __put_user(host_ts->tv_nsec, &target_ts->tv_nsec); - unlock_user_struct(target_ts, target_addr, 1); - return 0; -} - static inline abi_long target_to_host_itimerspec(struct itimerspec *host_itspec, abi_ulong target_addr) { diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index fffa89f2564b..06622703008a 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -209,16 +209,34 @@ struct target_linger { abi_int l_linger; /* How long to linger for */ }; +#if defined(TARGET_SPARC64) && !defined(TARGET_ABI32) +struct target_timeval { + abi_long tv_sec; + abi_int tv_usec; +}; +#define target__kernel_sock_timeval target_timeval +#else struct target_timeval { abi_long tv_sec; abi_long tv_usec; }; +struct target__kernel_sock_timeval { + abi_llong tv_sec; + abi_llong tv_usec; +}; +#endif + struct target_timespec { abi_long tv_sec; abi_long tv_nsec; }; +struct target__kernel_timespec { + abi_llong tv_sec; + abi_llong tv_nsec; +}; + struct target_timezone { abi_int tz_minuteswest; abi_int tz_dsttime; @@ -749,8 +767,16 @@ struct target_pollfd { #define TARGET_SIOCGPGRP 0x8904 #endif -#define TARGET_SIOCGSTAMP 0x8906 /* Get stamp (timeval) */ -#define TARGET_SIOCGSTAMPNS 0x8907 /* Get stamp (timespec) */ +#if defined(TARGET_SH4) +#define TARGET_SIOCGSTAMP_OLD TARGET_IOR('s', 100, struct target_timeval) +#define TARGET_SIOCGSTAMPNS_OLD TARGET_IOR('s', 101, struct target_timespec) +#else +#define TARGET_SIOCGSTAMP_OLD 0x8906 +#define TARGET_SIOCGSTAMPNS_OLD 0x8907 +#endif + +#define TARGET_SIOCGSTAMP_NEW TARGET_IOR(0x89, 0x06, abi_llong[2]) +#define TARGET_SIOCGSTAMPNS_NEW TARGET_IOR(0x89, 0x07, abi_llong[2]) /* Networking ioctls */ #define TARGET_SIOCADDRT 0x890B /* add routing table entry */ diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h index b98a23b0f1b0..4e3698382629 100644 --- a/linux-user/syscall_types.h +++ b/linux-user/syscall_types.h @@ -14,12 +14,6 @@ STRUCT(serial_icounter_struct, STRUCT(sockaddr, TYPE_SHORT, MK_ARRAY(TYPE_CHAR, 14)) -STRUCT(timeval, - MK_ARRAY(TYPE_LONG, 2)) - -STRUCT(timespec, - MK_ARRAY(TYPE_LONG, 2)) - 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,