From patchwork Fri Jul 7 14:50:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13304991 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6FC7EB64D9 for ; Fri, 7 Jul 2023 14:51:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229754AbjGGOvZ (ORCPT ); Fri, 7 Jul 2023 10:51:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229586AbjGGOvY (ORCPT ); Fri, 7 Jul 2023 10:51:24 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 214861FD7; Fri, 7 Jul 2023 07:51:21 -0700 (PDT) X-QQ-mid: bizesmtp71t1688741466tobmojsz Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 07 Jul 2023 22:51:05 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: 83ShfzFP0oCSFJRDmnjjj0j5ekoT4ERXMCO6n6hwcbXs8sil75ni6bvRy75us qzguPXnlyVBdf0Wd0CWfXadbv6AptN+1ba5GS+C5Yhc6CgjaRBZWuIYKs+H6cKxImIG5dNV kkwEYuHfYioJlOdQXWyUg4cUff0wTc49mOo3K1UaiOhA9xUL5jTbTVINLPvRPKWJZfEKIwy fPLBqjiGF4d4IgtTSe2BOW3MbgwfJDbNOCpfVRfB/zZ89LwmzI3WphCAhw+MpfLsAg6YERd aSQzICbFdn9aESQUtmfxkFwIM0l1zrcnvL0m99MeQdT/egL41FsoUAp6/hJpu8+IeZqSOaD bXizZ/ITicqEMeZqT76lX/A8ZeqH4LnFjE7BbLv3f+HXannpGxpAjHMe9c75A== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 1360114949905121606 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, david.laight@aculab.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, thomas@t-8ch.de Subject: [PATCH v6 01/15] tools/nolibc: arch-*.h: fix up code indent errors Date: Fri, 7 Jul 2023 22:50:34 +0800 Message-Id: <469d9d15a506a58dca5f8ecdcb83c660ee0485c9.1688739492.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org More than 8 whitespaces of the code indent are replaced with "tab + whitespaces" to fix up such errors reported by scripts/checkpatch.pl: ERROR: code indent should use tabs where possible #64: FILE: tools/include/nolibc/arch-mips.h:64: +^I \$ ERROR: code indent should use tabs where possible #72: FILE: tools/include/nolibc/arch-mips.h:72: +^I "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9" \$ This command is used: $ sed -i -e '/^\t* /{s/ /\t/g}' tools/include/nolibc/arch-*.h Signed-off-by: Zhangjin Wu --- tools/include/nolibc/arch-aarch64.h | 14 +++++++------- tools/include/nolibc/arch-arm.h | 14 +++++++------- tools/include/nolibc/arch-i386.h | 12 ++++++------ tools/include/nolibc/arch-mips.h | 24 ++++++++++++------------ tools/include/nolibc/arch-x86_64.h | 14 +++++++------- 5 files changed, 39 insertions(+), 39 deletions(-) diff --git a/tools/include/nolibc/arch-aarch64.h b/tools/include/nolibc/arch-aarch64.h index 11f294a406b7..c911f61365d1 100644 --- a/tools/include/nolibc/arch-aarch64.h +++ b/tools/include/nolibc/arch-aarch64.h @@ -56,7 +56,7 @@ struct sys_stat_struct { ({ \ register long _num __asm__ ("x8") = (num); \ register long _arg1 __asm__ ("x0"); \ - \ + \ __asm__ volatile ( \ "svc #0\n" \ : "=r"(_arg1) \ @@ -70,7 +70,7 @@ struct sys_stat_struct { ({ \ register long _num __asm__ ("x8") = (num); \ register long _arg1 __asm__ ("x0") = (long)(arg1); \ - \ + \ __asm__ volatile ( \ "svc #0\n" \ : "=r"(_arg1) \ @@ -86,7 +86,7 @@ struct sys_stat_struct { register long _num __asm__ ("x8") = (num); \ register long _arg1 __asm__ ("x0") = (long)(arg1); \ register long _arg2 __asm__ ("x1") = (long)(arg2); \ - \ + \ __asm__ volatile ( \ "svc #0\n" \ : "=r"(_arg1) \ @@ -103,7 +103,7 @@ struct sys_stat_struct { register long _arg1 __asm__ ("x0") = (long)(arg1); \ register long _arg2 __asm__ ("x1") = (long)(arg2); \ register long _arg3 __asm__ ("x2") = (long)(arg3); \ - \ + \ __asm__ volatile ( \ "svc #0\n" \ : "=r"(_arg1) \ @@ -121,7 +121,7 @@ struct sys_stat_struct { register long _arg2 __asm__ ("x1") = (long)(arg2); \ register long _arg3 __asm__ ("x2") = (long)(arg3); \ register long _arg4 __asm__ ("x3") = (long)(arg4); \ - \ + \ __asm__ volatile ( \ "svc #0\n" \ : "=r"(_arg1) \ @@ -140,7 +140,7 @@ struct sys_stat_struct { register long _arg3 __asm__ ("x2") = (long)(arg3); \ register long _arg4 __asm__ ("x3") = (long)(arg4); \ register long _arg5 __asm__ ("x4") = (long)(arg5); \ - \ + \ __asm__ volatile ( \ "svc #0\n" \ : "=r" (_arg1) \ @@ -160,7 +160,7 @@ struct sys_stat_struct { register long _arg4 __asm__ ("x3") = (long)(arg4); \ register long _arg5 __asm__ ("x4") = (long)(arg5); \ register long _arg6 __asm__ ("x5") = (long)(arg6); \ - \ + \ __asm__ volatile ( \ "svc #0\n" \ : "=r" (_arg1) \ diff --git a/tools/include/nolibc/arch-arm.h b/tools/include/nolibc/arch-arm.h index ca4c66987497..d5887fd9bc5f 100644 --- a/tools/include/nolibc/arch-arm.h +++ b/tools/include/nolibc/arch-arm.h @@ -90,7 +90,7 @@ struct sys_stat_struct { ({ \ register long _num __asm__(_NOLIBC_SYSCALL_REG) = (num); \ register long _arg1 __asm__ ("r0"); \ - \ + \ __asm__ volatile ( \ _NOLIBC_THUMB_SET_R7 \ "svc #0\n" \ @@ -107,7 +107,7 @@ struct sys_stat_struct { ({ \ register long _num __asm__(_NOLIBC_SYSCALL_REG) = (num); \ register long _arg1 __asm__ ("r0") = (long)(arg1); \ - \ + \ __asm__ volatile ( \ _NOLIBC_THUMB_SET_R7 \ "svc #0\n" \ @@ -125,7 +125,7 @@ struct sys_stat_struct { register long _num __asm__(_NOLIBC_SYSCALL_REG) = (num); \ register long _arg1 __asm__ ("r0") = (long)(arg1); \ register long _arg2 __asm__ ("r1") = (long)(arg2); \ - \ + \ __asm__ volatile ( \ _NOLIBC_THUMB_SET_R7 \ "svc #0\n" \ @@ -144,7 +144,7 @@ struct sys_stat_struct { register long _arg1 __asm__ ("r0") = (long)(arg1); \ register long _arg2 __asm__ ("r1") = (long)(arg2); \ register long _arg3 __asm__ ("r2") = (long)(arg3); \ - \ + \ __asm__ volatile ( \ _NOLIBC_THUMB_SET_R7 \ "svc #0\n" \ @@ -164,7 +164,7 @@ struct sys_stat_struct { register long _arg2 __asm__ ("r1") = (long)(arg2); \ register long _arg3 __asm__ ("r2") = (long)(arg3); \ register long _arg4 __asm__ ("r3") = (long)(arg4); \ - \ + \ __asm__ volatile ( \ _NOLIBC_THUMB_SET_R7 \ "svc #0\n" \ @@ -185,7 +185,7 @@ struct sys_stat_struct { register long _arg3 __asm__ ("r2") = (long)(arg3); \ register long _arg4 __asm__ ("r3") = (long)(arg4); \ register long _arg5 __asm__ ("r4") = (long)(arg5); \ - \ + \ __asm__ volatile ( \ _NOLIBC_THUMB_SET_R7 \ "svc #0\n" \ @@ -207,7 +207,7 @@ struct sys_stat_struct { register long _arg4 __asm__ ("r3") = (long)(arg4); \ register long _arg5 __asm__ ("r4") = (long)(arg5); \ register long _arg6 __asm__ ("r5") = (long)(arg6); \ - \ + \ __asm__ volatile ( \ _NOLIBC_THUMB_SET_R7 \ "svc #0\n" \ diff --git a/tools/include/nolibc/arch-i386.h b/tools/include/nolibc/arch-i386.h index 3d672d925e9e..c11a53acf159 100644 --- a/tools/include/nolibc/arch-i386.h +++ b/tools/include/nolibc/arch-i386.h @@ -57,7 +57,7 @@ struct sys_stat_struct { ({ \ long _ret; \ register long _num __asm__ ("eax") = (num); \ - \ + \ __asm__ volatile ( \ "int $0x80\n" \ : "=a" (_ret) \ @@ -72,7 +72,7 @@ struct sys_stat_struct { long _ret; \ register long _num __asm__ ("eax") = (num); \ register long _arg1 __asm__ ("ebx") = (long)(arg1); \ - \ + \ __asm__ volatile ( \ "int $0x80\n" \ : "=a" (_ret) \ @@ -89,7 +89,7 @@ struct sys_stat_struct { register long _num __asm__ ("eax") = (num); \ register long _arg1 __asm__ ("ebx") = (long)(arg1); \ register long _arg2 __asm__ ("ecx") = (long)(arg2); \ - \ + \ __asm__ volatile ( \ "int $0x80\n" \ : "=a" (_ret) \ @@ -107,7 +107,7 @@ struct sys_stat_struct { register long _arg1 __asm__ ("ebx") = (long)(arg1); \ register long _arg2 __asm__ ("ecx") = (long)(arg2); \ register long _arg3 __asm__ ("edx") = (long)(arg3); \ - \ + \ __asm__ volatile ( \ "int $0x80\n" \ : "=a" (_ret) \ @@ -126,7 +126,7 @@ struct sys_stat_struct { register long _arg2 __asm__ ("ecx") = (long)(arg2); \ register long _arg3 __asm__ ("edx") = (long)(arg3); \ register long _arg4 __asm__ ("esi") = (long)(arg4); \ - \ + \ __asm__ volatile ( \ "int $0x80\n" \ : "=a" (_ret) \ @@ -146,7 +146,7 @@ struct sys_stat_struct { register long _arg3 __asm__ ("edx") = (long)(arg3); \ register long _arg4 __asm__ ("esi") = (long)(arg4); \ register long _arg5 __asm__ ("edi") = (long)(arg5); \ - \ + \ __asm__ volatile ( \ "int $0x80\n" \ : "=a" (_ret) \ diff --git a/tools/include/nolibc/arch-mips.h b/tools/include/nolibc/arch-mips.h index db24e0837a39..55cd376a98e2 100644 --- a/tools/include/nolibc/arch-mips.h +++ b/tools/include/nolibc/arch-mips.h @@ -61,7 +61,7 @@ struct sys_stat_struct { ({ \ register long _num __asm__ ("v0") = (num); \ register long _arg4 __asm__ ("a3"); \ - \ + \ __asm__ volatile ( \ "addiu $sp, $sp, -32\n" \ "syscall\n" \ @@ -69,7 +69,7 @@ struct sys_stat_struct { : "=r"(_num), "=r"(_arg4) \ : "r"(_num) \ : "memory", "cc", "at", "v1", "hi", "lo", \ - "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9" \ + "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9" \ ); \ _arg4 ? -_num : _num; \ }) @@ -79,7 +79,7 @@ struct sys_stat_struct { register long _num __asm__ ("v0") = (num); \ register long _arg1 __asm__ ("a0") = (long)(arg1); \ register long _arg4 __asm__ ("a3"); \ - \ + \ __asm__ volatile ( \ "addiu $sp, $sp, -32\n" \ "syscall\n" \ @@ -88,7 +88,7 @@ struct sys_stat_struct { : "0"(_num), \ "r"(_arg1) \ : "memory", "cc", "at", "v1", "hi", "lo", \ - "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9" \ + "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9" \ ); \ _arg4 ? -_num : _num; \ }) @@ -99,7 +99,7 @@ struct sys_stat_struct { register long _arg1 __asm__ ("a0") = (long)(arg1); \ register long _arg2 __asm__ ("a1") = (long)(arg2); \ register long _arg4 __asm__ ("a3"); \ - \ + \ __asm__ volatile ( \ "addiu $sp, $sp, -32\n" \ "syscall\n" \ @@ -108,7 +108,7 @@ struct sys_stat_struct { : "0"(_num), \ "r"(_arg1), "r"(_arg2) \ : "memory", "cc", "at", "v1", "hi", "lo", \ - "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9" \ + "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9" \ ); \ _arg4 ? -_num : _num; \ }) @@ -120,7 +120,7 @@ struct sys_stat_struct { register long _arg2 __asm__ ("a1") = (long)(arg2); \ register long _arg3 __asm__ ("a2") = (long)(arg3); \ register long _arg4 __asm__ ("a3"); \ - \ + \ __asm__ volatile ( \ "addiu $sp, $sp, -32\n" \ "syscall\n" \ @@ -129,7 +129,7 @@ struct sys_stat_struct { : "0"(_num), \ "r"(_arg1), "r"(_arg2), "r"(_arg3) \ : "memory", "cc", "at", "v1", "hi", "lo", \ - "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9" \ + "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9" \ ); \ _arg4 ? -_num : _num; \ }) @@ -141,7 +141,7 @@ struct sys_stat_struct { register long _arg2 __asm__ ("a1") = (long)(arg2); \ register long _arg3 __asm__ ("a2") = (long)(arg3); \ register long _arg4 __asm__ ("a3") = (long)(arg4); \ - \ + \ __asm__ volatile ( \ "addiu $sp, $sp, -32\n" \ "syscall\n" \ @@ -150,7 +150,7 @@ struct sys_stat_struct { : "0"(_num), \ "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4) \ : "memory", "cc", "at", "v1", "hi", "lo", \ - "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9" \ + "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9" \ ); \ _arg4 ? -_num : _num; \ }) @@ -163,7 +163,7 @@ struct sys_stat_struct { register long _arg3 __asm__ ("a2") = (long)(arg3); \ register long _arg4 __asm__ ("a3") = (long)(arg4); \ register long _arg5 = (long)(arg5); \ - \ + \ __asm__ volatile ( \ "addiu $sp, $sp, -32\n" \ "sw %7, 16($sp)\n" \ @@ -173,7 +173,7 @@ struct sys_stat_struct { : "0"(_num), \ "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5) \ : "memory", "cc", "at", "v1", "hi", "lo", \ - "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9" \ + "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9" \ ); \ _arg4 ? -_num : _num; \ }) diff --git a/tools/include/nolibc/arch-x86_64.h b/tools/include/nolibc/arch-x86_64.h index 6fc4d8392742..1ae73d83aad1 100644 --- a/tools/include/nolibc/arch-x86_64.h +++ b/tools/include/nolibc/arch-x86_64.h @@ -59,7 +59,7 @@ struct sys_stat_struct { ({ \ long _ret; \ register long _num __asm__ ("rax") = (num); \ - \ + \ __asm__ volatile ( \ "syscall\n" \ : "=a"(_ret) \ @@ -74,7 +74,7 @@ struct sys_stat_struct { long _ret; \ register long _num __asm__ ("rax") = (num); \ register long _arg1 __asm__ ("rdi") = (long)(arg1); \ - \ + \ __asm__ volatile ( \ "syscall\n" \ : "=a"(_ret) \ @@ -91,7 +91,7 @@ struct sys_stat_struct { register long _num __asm__ ("rax") = (num); \ register long _arg1 __asm__ ("rdi") = (long)(arg1); \ register long _arg2 __asm__ ("rsi") = (long)(arg2); \ - \ + \ __asm__ volatile ( \ "syscall\n" \ : "=a"(_ret) \ @@ -109,7 +109,7 @@ struct sys_stat_struct { register long _arg1 __asm__ ("rdi") = (long)(arg1); \ register long _arg2 __asm__ ("rsi") = (long)(arg2); \ register long _arg3 __asm__ ("rdx") = (long)(arg3); \ - \ + \ __asm__ volatile ( \ "syscall\n" \ : "=a"(_ret) \ @@ -128,7 +128,7 @@ struct sys_stat_struct { register long _arg2 __asm__ ("rsi") = (long)(arg2); \ register long _arg3 __asm__ ("rdx") = (long)(arg3); \ register long _arg4 __asm__ ("r10") = (long)(arg4); \ - \ + \ __asm__ volatile ( \ "syscall\n" \ : "=a"(_ret) \ @@ -148,7 +148,7 @@ struct sys_stat_struct { register long _arg3 __asm__ ("rdx") = (long)(arg3); \ register long _arg4 __asm__ ("r10") = (long)(arg4); \ register long _arg5 __asm__ ("r8") = (long)(arg5); \ - \ + \ __asm__ volatile ( \ "syscall\n" \ : "=a"(_ret) \ @@ -169,7 +169,7 @@ struct sys_stat_struct { register long _arg4 __asm__ ("r10") = (long)(arg4); \ register long _arg5 __asm__ ("r8") = (long)(arg5); \ register long _arg6 __asm__ ("r9") = (long)(arg6); \ - \ + \ __asm__ volatile ( \ "syscall\n" \ : "=a"(_ret) \ From patchwork Fri Jul 7 14:52:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13304992 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E486EB64D9 for ; Fri, 7 Jul 2023 14:52:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229902AbjGGOwg (ORCPT ); Fri, 7 Jul 2023 10:52:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229586AbjGGOwg (ORCPT ); Fri, 7 Jul 2023 10:52:36 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F6371FF9; Fri, 7 Jul 2023 07:52:33 -0700 (PDT) X-QQ-mid: bizesmtp72t1688741537txgey93i Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 07 Jul 2023 22:52:16 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: znfcQSa1hKb1XUkvo8eX0HWlL+yR7wAWFiK0QzruRKVMnt7mEdtksu7tih+7X YjW6kbScnRE3aYMeztgoXEnJownNCDy+TOUpdsuMx2B5WbvP72jV8YlquZO5G5ckE8nLpKb pbiDLjDvXaK0KnYewnR2qSYRWKStTYtn14eRTY1wOr1tAuDfGyld8eXh43jc+4A3fonLD3b Mh9HWvnUCdV2YTCNwbUzhpKlI55c2XtHWmJtGcI0424F7ZhME40W8SiTFjAwdMfiQQhCUos kr84tjhRwzVvKSN5QO9bHUa9CMz1SW263f4GXppMnh3MrxUP9hOrf6QXZqcpuCtyxg8osyN XtNeF3nUuVYEP1dhu/SYI8NAVJqmnGX2gcjSUR56zrpje4Jeaz+/66yzWAGEg== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 4808279286737028793 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, david.laight@aculab.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, thomas@t-8ch.de Subject: [PATCH v6 02/15] toolc/nolibc: arch-*.h: clean up whitespaces after __asm__ Date: Fri, 7 Jul 2023 22:52:09 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org replace "__asm__ volatile" with "__asm__ volatile" and insert necessary whitespace before "\" to make sure the lines are aligned. $ sed -i -e 's/__asm__ volatile ( /__asm__ volatile ( /g' tools/include/nolibc/*.h Note, arch-s390.h uses post-tab instead of post-whitespaces, must avoid insert whitespace just before the tabs: $ sed -i -e 's/__asm__ volatile (\t/__asm__ volatile (\t/g' tools/include/nolibc/arch-*.h Signed-off-by: Zhangjin Wu --- tools/include/nolibc/arch-aarch64.h | 14 +++++++------- tools/include/nolibc/arch-arm.h | 14 +++++++------- tools/include/nolibc/arch-i386.h | 12 ++++++------ tools/include/nolibc/arch-loongarch.h | 14 +++++++------- tools/include/nolibc/arch-mips.h | 12 ++++++------ tools/include/nolibc/arch-riscv.h | 14 +++++++------- tools/include/nolibc/arch-s390.h | 14 +++++++------- tools/include/nolibc/arch-x86_64.h | 14 +++++++------- 8 files changed, 54 insertions(+), 54 deletions(-) diff --git a/tools/include/nolibc/arch-aarch64.h b/tools/include/nolibc/arch-aarch64.h index c911f61365d1..6227b77a4a09 100644 --- a/tools/include/nolibc/arch-aarch64.h +++ b/tools/include/nolibc/arch-aarch64.h @@ -57,7 +57,7 @@ struct sys_stat_struct { register long _num __asm__ ("x8") = (num); \ register long _arg1 __asm__ ("x0"); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "svc #0\n" \ : "=r"(_arg1) \ : "r"(_num) \ @@ -71,7 +71,7 @@ struct sys_stat_struct { register long _num __asm__ ("x8") = (num); \ register long _arg1 __asm__ ("x0") = (long)(arg1); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "svc #0\n" \ : "=r"(_arg1) \ : "r"(_arg1), \ @@ -87,7 +87,7 @@ struct sys_stat_struct { register long _arg1 __asm__ ("x0") = (long)(arg1); \ register long _arg2 __asm__ ("x1") = (long)(arg2); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "svc #0\n" \ : "=r"(_arg1) \ : "r"(_arg1), "r"(_arg2), \ @@ -104,7 +104,7 @@ struct sys_stat_struct { register long _arg2 __asm__ ("x1") = (long)(arg2); \ register long _arg3 __asm__ ("x2") = (long)(arg3); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "svc #0\n" \ : "=r"(_arg1) \ : "r"(_arg1), "r"(_arg2), "r"(_arg3), \ @@ -122,7 +122,7 @@ struct sys_stat_struct { register long _arg3 __asm__ ("x2") = (long)(arg3); \ register long _arg4 __asm__ ("x3") = (long)(arg4); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "svc #0\n" \ : "=r"(_arg1) \ : "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), \ @@ -141,7 +141,7 @@ struct sys_stat_struct { register long _arg4 __asm__ ("x3") = (long)(arg4); \ register long _arg5 __asm__ ("x4") = (long)(arg5); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "svc #0\n" \ : "=r" (_arg1) \ : "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5), \ @@ -161,7 +161,7 @@ struct sys_stat_struct { register long _arg5 __asm__ ("x4") = (long)(arg5); \ register long _arg6 __asm__ ("x5") = (long)(arg6); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "svc #0\n" \ : "=r" (_arg1) \ : "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5), \ diff --git a/tools/include/nolibc/arch-arm.h b/tools/include/nolibc/arch-arm.h index d5887fd9bc5f..4d4887a5f04b 100644 --- a/tools/include/nolibc/arch-arm.h +++ b/tools/include/nolibc/arch-arm.h @@ -91,7 +91,7 @@ struct sys_stat_struct { register long _num __asm__(_NOLIBC_SYSCALL_REG) = (num); \ register long _arg1 __asm__ ("r0"); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ _NOLIBC_THUMB_SET_R7 \ "svc #0\n" \ _NOLIBC_THUMB_RESTORE_R7 \ @@ -108,7 +108,7 @@ struct sys_stat_struct { register long _num __asm__(_NOLIBC_SYSCALL_REG) = (num); \ register long _arg1 __asm__ ("r0") = (long)(arg1); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ _NOLIBC_THUMB_SET_R7 \ "svc #0\n" \ _NOLIBC_THUMB_RESTORE_R7 \ @@ -126,7 +126,7 @@ struct sys_stat_struct { register long _arg1 __asm__ ("r0") = (long)(arg1); \ register long _arg2 __asm__ ("r1") = (long)(arg2); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ _NOLIBC_THUMB_SET_R7 \ "svc #0\n" \ _NOLIBC_THUMB_RESTORE_R7 \ @@ -145,7 +145,7 @@ struct sys_stat_struct { register long _arg2 __asm__ ("r1") = (long)(arg2); \ register long _arg3 __asm__ ("r2") = (long)(arg3); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ _NOLIBC_THUMB_SET_R7 \ "svc #0\n" \ _NOLIBC_THUMB_RESTORE_R7 \ @@ -165,7 +165,7 @@ struct sys_stat_struct { register long _arg3 __asm__ ("r2") = (long)(arg3); \ register long _arg4 __asm__ ("r3") = (long)(arg4); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ _NOLIBC_THUMB_SET_R7 \ "svc #0\n" \ _NOLIBC_THUMB_RESTORE_R7 \ @@ -186,7 +186,7 @@ struct sys_stat_struct { register long _arg4 __asm__ ("r3") = (long)(arg4); \ register long _arg5 __asm__ ("r4") = (long)(arg5); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ _NOLIBC_THUMB_SET_R7 \ "svc #0\n" \ _NOLIBC_THUMB_RESTORE_R7 \ @@ -208,7 +208,7 @@ struct sys_stat_struct { register long _arg5 __asm__ ("r4") = (long)(arg5); \ register long _arg6 __asm__ ("r5") = (long)(arg6); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ _NOLIBC_THUMB_SET_R7 \ "svc #0\n" \ _NOLIBC_THUMB_RESTORE_R7 \ diff --git a/tools/include/nolibc/arch-i386.h b/tools/include/nolibc/arch-i386.h index c11a53acf159..4c6b7c04e2e7 100644 --- a/tools/include/nolibc/arch-i386.h +++ b/tools/include/nolibc/arch-i386.h @@ -58,7 +58,7 @@ struct sys_stat_struct { long _ret; \ register long _num __asm__ ("eax") = (num); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "int $0x80\n" \ : "=a" (_ret) \ : "0"(_num) \ @@ -73,7 +73,7 @@ struct sys_stat_struct { register long _num __asm__ ("eax") = (num); \ register long _arg1 __asm__ ("ebx") = (long)(arg1); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "int $0x80\n" \ : "=a" (_ret) \ : "r"(_arg1), \ @@ -90,7 +90,7 @@ struct sys_stat_struct { register long _arg1 __asm__ ("ebx") = (long)(arg1); \ register long _arg2 __asm__ ("ecx") = (long)(arg2); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "int $0x80\n" \ : "=a" (_ret) \ : "r"(_arg1), "r"(_arg2), \ @@ -108,7 +108,7 @@ struct sys_stat_struct { register long _arg2 __asm__ ("ecx") = (long)(arg2); \ register long _arg3 __asm__ ("edx") = (long)(arg3); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "int $0x80\n" \ : "=a" (_ret) \ : "r"(_arg1), "r"(_arg2), "r"(_arg3), \ @@ -127,7 +127,7 @@ struct sys_stat_struct { register long _arg3 __asm__ ("edx") = (long)(arg3); \ register long _arg4 __asm__ ("esi") = (long)(arg4); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "int $0x80\n" \ : "=a" (_ret) \ : "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), \ @@ -147,7 +147,7 @@ struct sys_stat_struct { register long _arg4 __asm__ ("esi") = (long)(arg4); \ register long _arg5 __asm__ ("edi") = (long)(arg5); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "int $0x80\n" \ : "=a" (_ret) \ : "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5), \ diff --git a/tools/include/nolibc/arch-loongarch.h b/tools/include/nolibc/arch-loongarch.h index ad3f266e7093..8df42268e578 100644 --- a/tools/include/nolibc/arch-loongarch.h +++ b/tools/include/nolibc/arch-loongarch.h @@ -28,7 +28,7 @@ register long _num __asm__ ("a7") = (num); \ register long _arg1 __asm__ ("a0"); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "syscall 0\n" \ : "=r"(_arg1) \ : "r"(_num) \ @@ -43,7 +43,7 @@ register long _num __asm__ ("a7") = (num); \ register long _arg1 __asm__ ("a0") = (long)(arg1); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "syscall 0\n" \ : "+r"(_arg1) \ : "r"(_num) \ @@ -59,7 +59,7 @@ register long _arg1 __asm__ ("a0") = (long)(arg1); \ register long _arg2 __asm__ ("a1") = (long)(arg2); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "syscall 0\n" \ : "+r"(_arg1) \ : "r"(_arg2), \ @@ -77,7 +77,7 @@ register long _arg2 __asm__ ("a1") = (long)(arg2); \ register long _arg3 __asm__ ("a2") = (long)(arg3); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "syscall 0\n" \ : "+r"(_arg1) \ : "r"(_arg2), "r"(_arg3), \ @@ -96,7 +96,7 @@ register long _arg3 __asm__ ("a2") = (long)(arg3); \ register long _arg4 __asm__ ("a3") = (long)(arg4); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "syscall 0\n" \ : "+r"(_arg1) \ : "r"(_arg2), "r"(_arg3), "r"(_arg4), \ @@ -116,7 +116,7 @@ register long _arg4 __asm__ ("a3") = (long)(arg4); \ register long _arg5 __asm__ ("a4") = (long)(arg5); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "syscall 0\n" \ : "+r"(_arg1) \ : "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5), \ @@ -137,7 +137,7 @@ register long _arg5 __asm__ ("a4") = (long)(arg5); \ register long _arg6 __asm__ ("a5") = (long)(arg6); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "syscall 0\n" \ : "+r"(_arg1) \ : "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5), "r"(_arg6), \ diff --git a/tools/include/nolibc/arch-mips.h b/tools/include/nolibc/arch-mips.h index 55cd376a98e2..22aacc07b1fc 100644 --- a/tools/include/nolibc/arch-mips.h +++ b/tools/include/nolibc/arch-mips.h @@ -62,7 +62,7 @@ struct sys_stat_struct { register long _num __asm__ ("v0") = (num); \ register long _arg4 __asm__ ("a3"); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "addiu $sp, $sp, -32\n" \ "syscall\n" \ "addiu $sp, $sp, 32\n" \ @@ -80,7 +80,7 @@ struct sys_stat_struct { register long _arg1 __asm__ ("a0") = (long)(arg1); \ register long _arg4 __asm__ ("a3"); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "addiu $sp, $sp, -32\n" \ "syscall\n" \ "addiu $sp, $sp, 32\n" \ @@ -100,7 +100,7 @@ struct sys_stat_struct { register long _arg2 __asm__ ("a1") = (long)(arg2); \ register long _arg4 __asm__ ("a3"); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "addiu $sp, $sp, -32\n" \ "syscall\n" \ "addiu $sp, $sp, 32\n" \ @@ -121,7 +121,7 @@ struct sys_stat_struct { register long _arg3 __asm__ ("a2") = (long)(arg3); \ register long _arg4 __asm__ ("a3"); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "addiu $sp, $sp, -32\n" \ "syscall\n" \ "addiu $sp, $sp, 32\n" \ @@ -142,7 +142,7 @@ struct sys_stat_struct { register long _arg3 __asm__ ("a2") = (long)(arg3); \ register long _arg4 __asm__ ("a3") = (long)(arg4); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "addiu $sp, $sp, -32\n" \ "syscall\n" \ "addiu $sp, $sp, 32\n" \ @@ -164,7 +164,7 @@ struct sys_stat_struct { register long _arg4 __asm__ ("a3") = (long)(arg4); \ register long _arg5 = (long)(arg5); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "addiu $sp, $sp, -32\n" \ "sw %7, 16($sp)\n" \ "syscall\n " \ diff --git a/tools/include/nolibc/arch-riscv.h b/tools/include/nolibc/arch-riscv.h index a2e8564e66d6..cd958b2f4b1b 100644 --- a/tools/include/nolibc/arch-riscv.h +++ b/tools/include/nolibc/arch-riscv.h @@ -63,7 +63,7 @@ struct sys_stat_struct { register long _num __asm__ ("a7") = (num); \ register long _arg1 __asm__ ("a0"); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "ecall\n\t" \ : "=r"(_arg1) \ : "r"(_num) \ @@ -77,7 +77,7 @@ struct sys_stat_struct { register long _num __asm__ ("a7") = (num); \ register long _arg1 __asm__ ("a0") = (long)(arg1); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "ecall\n" \ : "+r"(_arg1) \ : "r"(_num) \ @@ -92,7 +92,7 @@ struct sys_stat_struct { register long _arg1 __asm__ ("a0") = (long)(arg1); \ register long _arg2 __asm__ ("a1") = (long)(arg2); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "ecall\n" \ : "+r"(_arg1) \ : "r"(_arg2), \ @@ -109,7 +109,7 @@ struct sys_stat_struct { register long _arg2 __asm__ ("a1") = (long)(arg2); \ register long _arg3 __asm__ ("a2") = (long)(arg3); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "ecall\n\t" \ : "+r"(_arg1) \ : "r"(_arg2), "r"(_arg3), \ @@ -127,7 +127,7 @@ struct sys_stat_struct { register long _arg3 __asm__ ("a2") = (long)(arg3); \ register long _arg4 __asm__ ("a3") = (long)(arg4); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "ecall\n" \ : "+r"(_arg1) \ : "r"(_arg2), "r"(_arg3), "r"(_arg4), \ @@ -146,7 +146,7 @@ struct sys_stat_struct { register long _arg4 __asm__ ("a3") = (long)(arg4); \ register long _arg5 __asm__ ("a4") = (long)(arg5); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "ecall\n" \ : "+r"(_arg1) \ : "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5), \ @@ -166,7 +166,7 @@ struct sys_stat_struct { register long _arg5 __asm__ ("a4") = (long)(arg5); \ register long _arg6 __asm__ ("a5") = (long)(arg6); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "ecall\n" \ : "+r"(_arg1) \ : "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5), "r"(_arg6), \ diff --git a/tools/include/nolibc/arch-s390.h b/tools/include/nolibc/arch-s390.h index 516dff5bff8b..a644ecd361c0 100644 --- a/tools/include/nolibc/arch-s390.h +++ b/tools/include/nolibc/arch-s390.h @@ -52,7 +52,7 @@ struct sys_stat_struct { register long _num __asm__ ("1") = (num); \ register long _rc __asm__ ("2"); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "svc 0\n" \ : "=d"(_rc) \ : "d"(_num) \ @@ -66,7 +66,7 @@ struct sys_stat_struct { register long _num __asm__ ("1") = (num); \ register long _arg1 __asm__ ("2") = (long)(arg1); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "svc 0\n" \ : "+d"(_arg1) \ : "d"(_num) \ @@ -81,7 +81,7 @@ struct sys_stat_struct { register long _arg1 __asm__ ("2") = (long)(arg1); \ register long _arg2 __asm__ ("3") = (long)(arg2); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "svc 0\n" \ : "+d"(_arg1) \ : "d"(_arg2), "d"(_num) \ @@ -97,7 +97,7 @@ struct sys_stat_struct { register long _arg2 __asm__ ("3") = (long)(arg2); \ register long _arg3 __asm__ ("4") = (long)(arg3); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "svc 0\n" \ : "+d"(_arg1) \ : "d"(_arg2), "d"(_arg3), "d"(_num) \ @@ -114,7 +114,7 @@ struct sys_stat_struct { register long _arg3 __asm__ ("4") = (long)(arg3); \ register long _arg4 __asm__ ("5") = (long)(arg4); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "svc 0\n" \ : "+d"(_arg1) \ : "d"(_arg2), "d"(_arg3), "d"(_arg4), "d"(_num) \ @@ -132,7 +132,7 @@ struct sys_stat_struct { register long _arg4 __asm__ ("5") = (long)(arg4); \ register long _arg5 __asm__ ("6") = (long)(arg5); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "svc 0\n" \ : "+d"(_arg1) \ : "d"(_arg2), "d"(_arg3), "d"(_arg4), "d"(_arg5), \ @@ -152,7 +152,7 @@ struct sys_stat_struct { register long _arg5 __asm__ ("6") = (long)(arg5); \ register long _arg6 __asm__ ("7") = (long)(arg6); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "svc 0\n" \ : "+d"(_arg1) \ : "d"(_arg2), "d"(_arg3), "d"(_arg4), "d"(_arg5), \ diff --git a/tools/include/nolibc/arch-x86_64.h b/tools/include/nolibc/arch-x86_64.h index 1ae73d83aad1..e69113742a99 100644 --- a/tools/include/nolibc/arch-x86_64.h +++ b/tools/include/nolibc/arch-x86_64.h @@ -60,7 +60,7 @@ struct sys_stat_struct { long _ret; \ register long _num __asm__ ("rax") = (num); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "syscall\n" \ : "=a"(_ret) \ : "0"(_num) \ @@ -75,7 +75,7 @@ struct sys_stat_struct { register long _num __asm__ ("rax") = (num); \ register long _arg1 __asm__ ("rdi") = (long)(arg1); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "syscall\n" \ : "=a"(_ret) \ : "r"(_arg1), \ @@ -92,7 +92,7 @@ struct sys_stat_struct { register long _arg1 __asm__ ("rdi") = (long)(arg1); \ register long _arg2 __asm__ ("rsi") = (long)(arg2); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "syscall\n" \ : "=a"(_ret) \ : "r"(_arg1), "r"(_arg2), \ @@ -110,7 +110,7 @@ struct sys_stat_struct { register long _arg2 __asm__ ("rsi") = (long)(arg2); \ register long _arg3 __asm__ ("rdx") = (long)(arg3); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "syscall\n" \ : "=a"(_ret) \ : "r"(_arg1), "r"(_arg2), "r"(_arg3), \ @@ -129,7 +129,7 @@ struct sys_stat_struct { register long _arg3 __asm__ ("rdx") = (long)(arg3); \ register long _arg4 __asm__ ("r10") = (long)(arg4); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "syscall\n" \ : "=a"(_ret) \ : "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), \ @@ -149,7 +149,7 @@ struct sys_stat_struct { register long _arg4 __asm__ ("r10") = (long)(arg4); \ register long _arg5 __asm__ ("r8") = (long)(arg5); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "syscall\n" \ : "=a"(_ret) \ : "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5), \ @@ -170,7 +170,7 @@ struct sys_stat_struct { register long _arg5 __asm__ ("r8") = (long)(arg5); \ register long _arg6 __asm__ ("r9") = (long)(arg6); \ \ - __asm__ volatile ( \ + __asm__ volatile ( \ "syscall\n" \ : "=a"(_ret) \ : "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5), \ From patchwork Fri Jul 7 14:53:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13304993 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8FB7EEB64D9 for ; Fri, 7 Jul 2023 14:53:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231799AbjGGOxj (ORCPT ); Fri, 7 Jul 2023 10:53:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229586AbjGGOxj (ORCPT ); Fri, 7 Jul 2023 10:53:39 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DE1C1FE1; Fri, 7 Jul 2023 07:53:37 -0700 (PDT) X-QQ-mid: bizesmtp62t1688741604t1m5yidp Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 07 Jul 2023 22:53:23 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: RumxddD8MdDoCupDu61PsFdnODRCtUmvZyeNJY1kEp4RpqJHc+ft0WnnMTIMl 8E1IBp9KiQV/4Avrm24T6ReRHju3wRp/EAlp6VfplODJn88CSPwt5Hj27c/7mENQXkqeWP/ P5icrX8GIU+X80kAmC05Iwm1qu+Z6czaDJClR1LN5Ie8oFBwT7Lens4Ftz0+Ytp+9vzlVAQ KIwE+Ifb3ea0bF5boi2yusAJRFWWF6WnNd9OyIiRggyyGkCuHWs7NtJ+SMwndFp0d3S331T 7v1LN26Z7mqjG+HQNvcfKOACHySIeoz8hoDN3eQm0XRw0/P/i0CL7LszpTsjEAUjpCve+DQ QHwzRV0Z0bXvNPGlE/id2smOyitCsXV1ACIAjTHRO9mlbvGaRh0YqDNpH7gTg== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 13151235364426953370 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, david.laight@aculab.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, thomas@t-8ch.de Subject: [PATCH v6 03/15] tools/nolibc: arch-loongarch.h: shrink with _NOLIBC_SYSCALL_CLOBBERLIST Date: Fri, 7 Jul 2023 22:53:20 +0800 Message-Id: <83b89f7e2935c0708d92dc473c8434d0d304c74b.1688739492.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org my_syscall share the same long clobber list, define a macro for them. Signed-off-by: Zhangjin Wu --- tools/include/nolibc/arch-loongarch.h | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/tools/include/nolibc/arch-loongarch.h b/tools/include/nolibc/arch-loongarch.h index 8df42268e578..8aa7724fe38e 100644 --- a/tools/include/nolibc/arch-loongarch.h +++ b/tools/include/nolibc/arch-loongarch.h @@ -22,6 +22,8 @@ * On LoongArch, select() is not implemented so we have to use pselect6(). */ #define __ARCH_WANT_SYS_PSELECT6 +#define _NOLIBC_SYSCALL_CLOBBERLIST \ + "memory", "$t0", "$t1", "$t2", "$t3", "$t4", "$t5", "$t6", "$t7", "$t8" #define my_syscall0(num) \ ({ \ @@ -32,8 +34,7 @@ "syscall 0\n" \ : "=r"(_arg1) \ : "r"(_num) \ - : "memory", "$t0", "$t1", "$t2", "$t3", \ - "$t4", "$t5", "$t6", "$t7", "$t8" \ + : _NOLIBC_SYSCALL_CLOBBERLIST \ ); \ _arg1; \ }) @@ -47,8 +48,7 @@ "syscall 0\n" \ : "+r"(_arg1) \ : "r"(_num) \ - : "memory", "$t0", "$t1", "$t2", "$t3", \ - "$t4", "$t5", "$t6", "$t7", "$t8" \ + : _NOLIBC_SYSCALL_CLOBBERLIST \ ); \ _arg1; \ }) @@ -64,8 +64,7 @@ : "+r"(_arg1) \ : "r"(_arg2), \ "r"(_num) \ - : "memory", "$t0", "$t1", "$t2", "$t3", \ - "$t4", "$t5", "$t6", "$t7", "$t8" \ + : _NOLIBC_SYSCALL_CLOBBERLIST \ ); \ _arg1; \ }) @@ -82,8 +81,7 @@ : "+r"(_arg1) \ : "r"(_arg2), "r"(_arg3), \ "r"(_num) \ - : "memory", "$t0", "$t1", "$t2", "$t3", \ - "$t4", "$t5", "$t6", "$t7", "$t8" \ + : _NOLIBC_SYSCALL_CLOBBERLIST \ ); \ _arg1; \ }) @@ -101,8 +99,7 @@ : "+r"(_arg1) \ : "r"(_arg2), "r"(_arg3), "r"(_arg4), \ "r"(_num) \ - : "memory", "$t0", "$t1", "$t2", "$t3", \ - "$t4", "$t5", "$t6", "$t7", "$t8" \ + : _NOLIBC_SYSCALL_CLOBBERLIST \ ); \ _arg1; \ }) @@ -121,8 +118,7 @@ : "+r"(_arg1) \ : "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5), \ "r"(_num) \ - : "memory", "$t0", "$t1", "$t2", "$t3", \ - "$t4", "$t5", "$t6", "$t7", "$t8" \ + : _NOLIBC_SYSCALL_CLOBBERLIST \ ); \ _arg1; \ }) @@ -142,8 +138,7 @@ : "+r"(_arg1) \ : "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5), "r"(_arg6), \ "r"(_num) \ - : "memory", "$t0", "$t1", "$t2", "$t3", \ - "$t4", "$t5", "$t6", "$t7", "$t8" \ + : _NOLIBC_SYSCALL_CLOBBERLIST \ ); \ _arg1; \ }) From patchwork Fri Jul 7 14:54:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13304994 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ECCACEB64D9 for ; Fri, 7 Jul 2023 14:54:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232406AbjGGOyu (ORCPT ); Fri, 7 Jul 2023 10:54:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231786AbjGGOyt (ORCPT ); Fri, 7 Jul 2023 10:54:49 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D343211C; Fri, 7 Jul 2023 07:54:46 -0700 (PDT) X-QQ-mid: bizesmtp74t1688741672t4vg896o Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 07 Jul 2023 22:54:31 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: Xz3VOcA7Mr3gnW13Mz7SkboIep4UxV/SucUK86192TK31+GR1/gFj4OOvj6fx +bH2BPikj/AX30RQHBZf3cNqBVb49OmRMvtvus7UF6BqrXLwg3xey2y9AhQKmAPFHVev69f ErK63Q3C9GNXsW+TbKtvYG0hKJt7oL6GhJxEHWf40w4lWMOFukWapJagciCTvd4/pYH0dxC Wqsqculf/+nBZkuztTci4N9bIlNAW/avjblu8lA7u9x7/RhXtc1btXTp+ayjqaWuQ0WOVqx kU7mioJpKsGBEFxYDurdJAHrZnDpDrUTGHGTwxcN9OSFLC7OxwYbgwXdezoymakZaCeP02Q Kj0T5ubFQuquSn4mPUVQ0t49LeHGYT4HETOnmh0nKKMen0bCqN1ugnDSRKjlg== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 4053769286691536026 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, david.laight@aculab.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, thomas@t-8ch.de Subject: [PATCH v6 04/15] tools/nolibc: arch-mips.h: shrink with _NOLIBC_SYSCALL_CLOBBERLIST Date: Fri, 7 Jul 2023 22:54:26 +0800 Message-Id: <3ba25ebd88fcef91a6a411472684b4b30e6018ef.1688739492.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org my_syscall share the same long clobber list, define a macro for them. Signed-off-by: Zhangjin Wu --- tools/include/nolibc/arch-mips.h | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/tools/include/nolibc/arch-mips.h b/tools/include/nolibc/arch-mips.h index 22aacc07b1fc..1848f57777c4 100644 --- a/tools/include/nolibc/arch-mips.h +++ b/tools/include/nolibc/arch-mips.h @@ -57,6 +57,10 @@ struct sys_stat_struct { * don't have to experience issues with register constraints. */ +#define _NOLIBC_SYSCALL_CLOBBERLIST \ + "memory", "cc", "at", "v1", "hi", "lo", \ + "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9" + #define my_syscall0(num) \ ({ \ register long _num __asm__ ("v0") = (num); \ @@ -68,8 +72,7 @@ struct sys_stat_struct { "addiu $sp, $sp, 32\n" \ : "=r"(_num), "=r"(_arg4) \ : "r"(_num) \ - : "memory", "cc", "at", "v1", "hi", "lo", \ - "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9" \ + : _NOLIBC_SYSCALL_CLOBBERLIST \ ); \ _arg4 ? -_num : _num; \ }) @@ -87,8 +90,7 @@ struct sys_stat_struct { : "=r"(_num), "=r"(_arg4) \ : "0"(_num), \ "r"(_arg1) \ - : "memory", "cc", "at", "v1", "hi", "lo", \ - "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9" \ + : _NOLIBC_SYSCALL_CLOBBERLIST \ ); \ _arg4 ? -_num : _num; \ }) @@ -107,8 +109,7 @@ struct sys_stat_struct { : "=r"(_num), "=r"(_arg4) \ : "0"(_num), \ "r"(_arg1), "r"(_arg2) \ - : "memory", "cc", "at", "v1", "hi", "lo", \ - "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9" \ + : _NOLIBC_SYSCALL_CLOBBERLIST \ ); \ _arg4 ? -_num : _num; \ }) @@ -128,8 +129,7 @@ struct sys_stat_struct { : "=r"(_num), "=r"(_arg4) \ : "0"(_num), \ "r"(_arg1), "r"(_arg2), "r"(_arg3) \ - : "memory", "cc", "at", "v1", "hi", "lo", \ - "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9" \ + : _NOLIBC_SYSCALL_CLOBBERLIST \ ); \ _arg4 ? -_num : _num; \ }) @@ -149,8 +149,7 @@ struct sys_stat_struct { : "=r" (_num), "=r"(_arg4) \ : "0"(_num), \ "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4) \ - : "memory", "cc", "at", "v1", "hi", "lo", \ - "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9" \ + : _NOLIBC_SYSCALL_CLOBBERLIST \ ); \ _arg4 ? -_num : _num; \ }) @@ -172,8 +171,7 @@ struct sys_stat_struct { : "=r" (_num), "=r"(_arg4) \ : "0"(_num), \ "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5) \ - : "memory", "cc", "at", "v1", "hi", "lo", \ - "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9" \ + : _NOLIBC_SYSCALL_CLOBBERLIST \ ); \ _arg4 ? -_num : _num; \ }) From patchwork Fri Jul 7 14:55:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13305002 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87835EB64D9 for ; Fri, 7 Jul 2023 14:56:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233153AbjGGO4U (ORCPT ); Fri, 7 Jul 2023 10:56:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233151AbjGGO4T (ORCPT ); Fri, 7 Jul 2023 10:56:19 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BAD4A2117; Fri, 7 Jul 2023 07:56:10 -0700 (PDT) X-QQ-mid: bizesmtp90t1688741756t4957kso Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 07 Jul 2023 22:55:54 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: ILHsT53NKPgT3vYb7mSqef6qq6ijJFi5yZN+5IyXvKcCNY/FIjIcEWS0O5O+d 2NGhVscVoSruYGQXUG1TyM4Xedj+I/qg+7nL+jSkOz5tn0vd+07XiMUqFJslNu8QBkHhpUT 0MtEI2n1qoAZP64wEYuleIEOyFT9uh9c1HTh0aSVkydPB8MzgzUkyVLD2FoKPyNMJTecK1R y8/UG3/PQNvw4I5GSsIMvazUH7UcFyNyWD0VmHh9aKiUcZ9t5PFVjbGpo/bLKCzqHxq2NMY u8rgA6n/NSDFQIjFKpQAFBV4nNGLkxZd3pehjtNaIJ27EX2lHZEqBpdXgouPeQOc2OYwhVe 2zZjcdcsqh/BgXe/5Va1Z/B03oHnY72gBId+uoUZIAuyabDfddtVo0xRQgnKg== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 8772950966564420236 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, david.laight@aculab.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, thomas@t-8ch.de Subject: [PATCH v6 05/15] tools/nolibc: add missing my_syscall6() for mips Date: Fri, 7 Jul 2023 22:55:35 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org It is able to pass the 6th argument like the 5th argument via the stack for mips, let's add a new my_syscall6() now, see [1] for details: The mips/o32 system call convention passes arguments 5 through 8 on the user stack. Both mmap() and pselect6() require my_syscall6(). [1]: https://man7.org/linux/man-pages/man2/syscall.2.html Signed-off-by: Zhangjin Wu --- tools/include/nolibc/arch-mips.h | 27 ++++++++++++++++++++++++++- tools/include/nolibc/nolibc.h | 9 ++++----- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/tools/include/nolibc/arch-mips.h b/tools/include/nolibc/arch-mips.h index 1848f57777c4..a2bfdf57b957 100644 --- a/tools/include/nolibc/arch-mips.h +++ b/tools/include/nolibc/arch-mips.h @@ -166,7 +166,7 @@ struct sys_stat_struct { __asm__ volatile ( \ "addiu $sp, $sp, -32\n" \ "sw %7, 16($sp)\n" \ - "syscall\n " \ + "syscall\n" \ "addiu $sp, $sp, 32\n" \ : "=r" (_num), "=r"(_arg4) \ : "0"(_num), \ @@ -176,6 +176,31 @@ struct sys_stat_struct { _arg4 ? -_num : _num; \ }) +#define my_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \ +({ \ + register long _num __asm__ ("v0") = (num); \ + register long _arg1 __asm__ ("a0") = (long)(arg1); \ + register long _arg2 __asm__ ("a1") = (long)(arg2); \ + register long _arg3 __asm__ ("a2") = (long)(arg3); \ + register long _arg4 __asm__ ("a3") = (long)(arg4); \ + register long _arg5 = (long)(arg5); \ + register long _arg6 = (long)(arg6); \ + \ + __asm__ volatile ( \ + "addiu $sp, $sp, -32\n" \ + "sw %7, 16($sp)\n" \ + "sw %8, 20($sp)\n" \ + "syscall\n" \ + "addiu $sp, $sp, 32\n" \ + : "=r" (_num), "=r"(_arg4) \ + : "0"(_num), \ + "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5), \ + "r"(_arg6) \ + : _NOLIBC_SYSCALL_CLOBBERLIST \ + ); \ + _arg4 ? -_num : _num; \ +}) + char **environ __attribute__((weak)); const unsigned long *_auxv __attribute__((weak)); diff --git a/tools/include/nolibc/nolibc.h b/tools/include/nolibc/nolibc.h index 05a228a6ee78..1f8d821000ac 100644 --- a/tools/include/nolibc/nolibc.h +++ b/tools/include/nolibc/nolibc.h @@ -13,11 +13,10 @@ * Syscalls are split into 3 levels: * - The lower level is the arch-specific syscall() definition, consisting in * assembly code in compound expressions. These are called my_syscall0() to - * my_syscall6() depending on the number of arguments. The MIPS - * implementation is limited to 5 arguments. All input arguments are cast - * to a long stored in a register. These expressions always return the - * syscall's return value as a signed long value which is often either a - * pointer or the negated errno value. + * my_syscall6() depending on the number of arguments. All input arguments + * are castto a long stored in a register. These expressions always return + * the syscall's return value as a signed long value which is often either + * a pointer or the negated errno value. * * - The second level is mostly architecture-independent. It is made of * static functions called sys_() which rely on my_syscallN() From patchwork Fri Jul 7 14:56:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13305003 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A16FEB64D9 for ; Fri, 7 Jul 2023 14:57:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231786AbjGGO5e (ORCPT ); Fri, 7 Jul 2023 10:57:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229586AbjGGO5d (ORCPT ); Fri, 7 Jul 2023 10:57:33 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2ACFA210A; Fri, 7 Jul 2023 07:57:31 -0700 (PDT) X-QQ-mid: bizesmtp65t1688741838t0f6f5rq Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 07 Jul 2023 22:57:17 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: 6/K5pWSRdGp5l3PoSnsEr+W6n/O4GVkW2LsupZpOaCCnabhC9drJ+DsHTHGGa rpPAydJpCLVE4Yu5xjNNf886fcd75eYPy4f1CJVneC7/0vFizOlY/8RavL9cQLH+5qlBKdY T26RBSYkIWrac+plKyZyFDAQHOazNAOnx1T7kOiVneWS5f/wr8Ez5VRxQvzZvQxdei7uftr G8bYJAdCFUoNytCFtmfyt9XZohqeJxoGQaPP3fHRTj28Ly8xD8BkFYsPULycHa/6IDvJuAN MqUK5SPN9/+jB5l4g/5XTC9L51uz2CBdxApWKXmcHXt6PfAwJmgYn/9kDGGQLO0EvowDYOC tj5RprGXjtRiusZgLAzassh26B9m6zPartP8HLPVFF77FEdqu/QC8BNCz0T6GLu2e8ZMYia X-QQ-GoodBg: 0 X-BIZMAIL-ID: 6279798532617974938 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, david.laight@aculab.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, thomas@t-8ch.de, David Laight Subject: [PATCH v6 06/15] tools/nolibc: __sysret: support syscalls who return a pointer Date: Fri, 7 Jul 2023 22:56:59 +0800 Message-Id: <11fd815773f7d202d329ac2c64cd6980b32e4fcf.1688739492.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org No official reference states the errno range, here aligns with musl and glibc and uses [-MAX_ERRNO, -1] instead of all negative ones. - musl: src/internal/syscall_ret.c - glibc: sysdeps/unix/sysv/linux/sysdep.h The MAX_ERRNO used by musl and glibc is 4095, just like the one nolibc defined in tools/include/nolibc/errno.h. Suggested-by: Willy Tarreau Link: https://lore.kernel.org/lkml/ZKKdD%2Fp4UkEavru6@1wt.eu/ Suggested-by: David Laight Link: https://lore.kernel.org/linux-riscv/94dd5170929f454fbc0a10a2eb3b108d@AcuMS.aculab.com/ Signed-off-by: Zhangjin Wu --- tools/include/nolibc/sys.h | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index 53bc3ad6593e..3479f54d7957 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -28,13 +28,20 @@ #include "errno.h" #include "types.h" -/* Syscall return helper, set errno as -ret when ret < 0 */ + +/* Syscall return helper for library routines, set errno as -ret when ret is in + * range of [-MAX_ERRNO, -1] + * + * Note, No official reference states the errno range here aligns with musl + * (src/internal/syscall_ret.c) and glibc (sysdeps/unix/sysv/linux/sysdep.h) + */ + static __inline__ __attribute__((unused, always_inline)) -long __sysret(long ret) +long __sysret(unsigned long ret) { - if (ret < 0) { - SET_ERRNO(-ret); - ret = -1; + if (ret >= (unsigned long)-MAX_ERRNO) { + SET_ERRNO(-(long)ret); + return -1; } return ret; } From patchwork Fri Jul 7 14:58:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13305004 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9B998EB64D9 for ; Fri, 7 Jul 2023 14:59:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233111AbjGGO7H (ORCPT ); Fri, 7 Jul 2023 10:59:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232308AbjGGO7G (ORCPT ); Fri, 7 Jul 2023 10:59:06 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B27E42102; Fri, 7 Jul 2023 07:59:03 -0700 (PDT) X-QQ-mid: bizesmtp66t1688741930t1u7j3pm Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 07 Jul 2023 22:58:49 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: FVl8EHhfVR7yQpfZTGK8C+9c2sldMS7g8O8sphi3aZ3lVOgDE6mUBVA4cCQad kO/IXo2DyBCrzayugYXvTg5txrwWjTP6N5r+UZweLv4IkFD30FHcdjIK1+jFUtIiMik2QUG HkOw6coYGLIO8BZwYXLEer8oY/wY2g/gx+OMutEGwfozZE01xyhidcc6kipNJivkA5mMy65 UnHb6lTgTTv4PYZwlBSpSFlUEZRRZUodLLdeG6EjdS+b7ZgBv7p0QsKptgKlaz4XVxN1lfe hqxBNYLi51fQB/4Dn+CFw55wcyWYxgLZI1J69Sfu59KNZ5n2roe4WNRY7A+Hh9E5VKKVYIX d8PyfxwRmSvJCcQjaXt45gwIFPDjpPhrRd5iCY9Cz3CJtT5N/Y1dOGPHqXeOgY+nAuBj+ds X-QQ-GoodBg: 0 X-BIZMAIL-ID: 12986911038597649536 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, david.laight@aculab.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, thomas@t-8ch.de Subject: [PATCH v6 07/15] tools/nolibc: clean up mmap() routine Date: Fri, 7 Jul 2023 22:58:20 +0800 Message-Id: <5817aa30c97be3b4db794a1d35272e0f379b80f1.1688739492.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Do several cleanups together: - Since all supported architectures have my_syscall6() now, remove the #ifdef check. - Move the mmap() related macros to tools/include/nolibc/types.h and reuse most of them from - Apply the new generic __sysret() to convert the calling of sys_map() to oneline code Note, since MAP_FAILED is -1 on Linux, so we can use the generic __sysret() which returns -1 upon error and still satisfy user land that checks for MAP_FAILED. Suggested-by: Willy Tarreau Link: https://lore.kernel.org/lkml/20230702192347.GJ16233@1wt.eu/ Signed-off-by: Zhangjin Wu --- tools/include/nolibc/sys.h | 29 ++++++----------------------- tools/include/nolibc/types.h | 6 ++++++ 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index 3479f54d7957..3d01a24e6f7a 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -636,26 +636,11 @@ int mknod(const char *path, mode_t mode, dev_t dev) return __sysret(sys_mknod(path, mode, dev)); } -#ifndef MAP_SHARED -#define MAP_SHARED 0x01 /* Share changes */ -#define MAP_PRIVATE 0x02 /* Changes are private */ -#define MAP_SHARED_VALIDATE 0x03 /* share + validate extension flags */ -#endif - -#ifndef MAP_FAILED -#define MAP_FAILED ((void *)-1) -#endif - #ifndef sys_mmap static __attribute__((unused)) void *sys_mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset) { -#ifndef my_syscall6 - /* Function not implemented. */ - return (void *)-ENOSYS; -#else - int n; #if defined(__NR_mmap2) @@ -666,20 +651,18 @@ void *sys_mmap(void *addr, size_t length, int prot, int flags, int fd, #endif return (void *)my_syscall6(n, addr, length, prot, flags, fd, offset); -#endif } #endif +/* Note that on Linux, MAP_FAILED is -1 so we can use the generic __sysret() + * which returns -1 upon error and still satisfy user land that checks for + * MAP_FAILED. + */ + static __attribute__((unused)) void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset) { - void *ret = sys_mmap(addr, length, prot, flags, fd, offset); - - if ((unsigned long)ret >= -4095UL) { - SET_ERRNO(-(long)ret); - ret = MAP_FAILED; - } - return ret; + return (void *)__sysret((unsigned long)sys_mmap(addr, length, prot, flags, fd, offset)); } static __attribute__((unused)) diff --git a/tools/include/nolibc/types.h b/tools/include/nolibc/types.h index f96e28bff4ba..5e1bac8509ec 100644 --- a/tools/include/nolibc/types.h +++ b/tools/include/nolibc/types.h @@ -8,6 +8,7 @@ #define _NOLIBC_TYPES_H #include "std.h" +#include #include #include @@ -81,6 +82,11 @@ #define MAXPATHLEN (PATH_MAX) #endif +/* flags for mmap */ +#ifndef MAP_FAILED +#define MAP_FAILED ((void *)-1) +#endif + /* whence values for lseek() */ #define SEEK_SET 0 #define SEEK_CUR 1 From patchwork Fri Jul 7 14:59:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13305005 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93369EB64DA for ; Fri, 7 Jul 2023 15:00:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233214AbjGGPA1 (ORCPT ); Fri, 7 Jul 2023 11:00:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232308AbjGGPA0 (ORCPT ); Fri, 7 Jul 2023 11:00:26 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F241A1FE2; Fri, 7 Jul 2023 08:00:21 -0700 (PDT) X-QQ-mid: bizesmtp66t1688742007tg949pqx Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 07 Jul 2023 23:00:06 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: F7g8sXqc8jKUXva1LOQuC3l6Huh4naBPWG4uwtnPE08/V+nzmxJAVIlC+NW4t GJBwcqaJMlH3AHBqAX6F0hXsEzGUuQj2+Q74Sxs9xvMGzhsPQ8eXADWbmJu7pt7Lky2X+Dn rwIOhzzB6DGVdZwiOfFl5lZJ08gjw668dZcOO+UMASsBHylhSt++/1YjHCR3vYaC3Dn2Tzb KDzd/Nd7hf6waMdwYz/zlrhe8E0wZckFp/hFTCcxBjqi0gereXhOL1hY0gYQCPPqH03bkBG Q2laSXI34883bzQwno94VwwwNoAaTo+M3fnMzBk7X4MVaLuXhsDJRMxTxE7tfjoMeI169XX 608IzYYMbWNlzFPOQYTjr4y2sxvNcIizzGf64Ldy+qNDqeSumMrewESt2diJw== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 1688201172120877824 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, david.laight@aculab.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, thomas@t-8ch.de Subject: [PATCH v6 08/15] tools/nolibc: clean up sbrk() routine Date: Fri, 7 Jul 2023 22:59:53 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Fix up the error reported by scripts/checkpatch.pl: ERROR: do not use assignment in if condition #95: FILE: tools/include/nolibc/sys.h:95: + if ((ret = sys_brk(0)) && (sys_brk(ret + inc) == ret + inc)) Apply the new generic __sysret() to merge the SET_ERRNO() and return lines. Signed-off-by: Zhangjin Wu --- tools/include/nolibc/sys.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index 3d01a24e6f7a..61a3204b00d7 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -89,14 +89,13 @@ int brk(void *addr) static __attribute__((unused)) void *sbrk(intptr_t inc) { - void *ret; - /* first call to find current end */ - if ((ret = sys_brk(0)) && (sys_brk(ret + inc) == ret + inc)) + void *ret = sys_brk(0); + + if (ret && sys_brk(ret + inc) == ret + inc) return ret + inc; - SET_ERRNO(ENOMEM); - return (void *)-1; + return (void *)__sysret(-ENOMEM); } From patchwork Fri Jul 7 15:01:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13305010 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ABB6DEB64D9 for ; Fri, 7 Jul 2023 15:01:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232308AbjGGPBa (ORCPT ); Fri, 7 Jul 2023 11:01:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232974AbjGGPB3 (ORCPT ); Fri, 7 Jul 2023 11:01:29 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 726DA1FE2; Fri, 7 Jul 2023 08:01:28 -0700 (PDT) X-QQ-mid: bizesmtp74t1688742074tg81aioz Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 07 Jul 2023 23:01:12 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: +bXiSo2NuBc1Cd2zooPSXRsbPXASdUhmi+9wjNyy/hjCxNCxO5qngS1ViteCu ns6FJkzManwTtWB7dHIZA8wXwP40Yky4g0FuLECXFu2Ndeaooo69kfrJoOWpX45uzyTGpAJ nPnUC0t4URkUa8//XlfzX4YGN4v3zUMSi9ZV8m6LygSdBTdSgSSjIFILqo/I6i5Wms9ANVE aV6qpvXLwzFzaQXY6srvtV54bxf/VqOAHBH4yJvqFIe0HX42Oago3jrel90v8a8ausjvOEk FMSau3FWLFNI4aFaEsG+uRScy9Trs8rFpplBRLluEWFJhrWXhZQ+mxR1ecuQeGowyBt7WKS 7k2Ek8ShyF8kd1sCBdBFi6khn2PoKnT3U+WLKIUxsFoTpGVmTx0RBsy60RaMcVWc+wIOZ5x X-QQ-GoodBg: 0 X-BIZMAIL-ID: 11414460270218283821 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, david.laight@aculab.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, thomas@t-8ch.de Subject: [PATCH v6 09/15] selftests/nolibc: export argv0 for some tests Date: Fri, 7 Jul 2023 23:01:09 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org argv0 is the path to nolibc-test program itself, which is a very good always existing readable file for some tests, let's export it. Note, the path may be absolute or relative, please make sure the tests work with both of them. If it is relative, we must make sure the current path is the one specified by the PWD environment variable. Suggested-by: Willy Tarreau Link: https://lore.kernel.org/lkml/ZKKbS3cwKcHgnGwu@1wt.eu/ Signed-off-by: Zhangjin Wu --- tools/testing/selftests/nolibc/nolibc-test.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 486334981e60..88b840f86f52 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -43,6 +43,9 @@ /* will be used by nolibc by getenv() */ char **environ; +/* will be used by some test cases as readable file, please don't write it */ +static const char *argv0; + /* definition of a series of tests */ struct test { const char *name; /* test name */ @@ -948,6 +951,7 @@ int main(int argc, char **argv, char **envp) int idx; char *test; + argv0 = argv[0]; environ = envp; /* when called as init, it's possible that no console was opened, for From patchwork Fri Jul 7 15:02:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13305011 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16AAEEB64D9 for ; Fri, 7 Jul 2023 15:02:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233237AbjGGPCt (ORCPT ); Fri, 7 Jul 2023 11:02:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233252AbjGGPCs (ORCPT ); Fri, 7 Jul 2023 11:02:48 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10F5F210A; Fri, 7 Jul 2023 08:02:37 -0700 (PDT) X-QQ-mid: bizesmtp63t1688742143tn8jl0ih Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 07 Jul 2023 23:02:22 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: hoArX50alxFmsJ0atZjqbzHeVuse8MtD4x3pgHfFnxe1hIjs3zsPJJljILwPP cZOCtJq2GFFmaWMlBnT7xIijoHajHOWxCVCyUgsrmQJI4aJwBx1j1G0/nT9v816H4crLevD b2wqhPOTx2jJXGPA0XEf1e4cXnpNe+Ho6HRdAYwOKiwGrv3+FsrXaYQXFnirspceOYnrj5d 2gD2Mwc5hrF7Tk82JzkwT9vRE8qLrIbfJAFlgLQxBAVjmuqj1HFPF+meU0LnlvFzYUHVQsU ALHr5zeDk8O8oofQT+qDeXFlCZuVx8tWjuBG0NsEHzSMmIGDxTHm1aGJR5nGRksKAQw62x2 856wxltVV+JT2VWIZNTh1T+Ecuwb/jyN6hRoodt577DibVw0p0ypooL8P7v34K9lg6uY0Ni X-QQ-GoodBg: 0 X-BIZMAIL-ID: 7535638931028319636 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, david.laight@aculab.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, thomas@t-8ch.de Subject: [PATCH v6 10/15] selftests/nolibc: prepare: create /dev/zero Date: Fri, 7 Jul 2023 23:02:16 +0800 Message-Id: <589b6a374e604b6289eb00890cd63e2b7d2ce86f.1688739492.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org /dev/zero is commonly used to allocate anonymous memory, it is a very good file for tests, let's prepare it. Suggested-by: Willy Tarreau Link: https://lore.kernel.org/lkml/20230702193306.GK16233@1wt.eu/ Signed-off-by: Zhangjin Wu --- tools/testing/selftests/nolibc/nolibc-test.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 88b840f86f52..b759fb25d375 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -894,11 +894,13 @@ int prepare(void) */ if (stat("/dev/.", &stat_buf) == 0 || mkdir("/dev", 0755) == 0) { if (stat("/dev/console", &stat_buf) != 0 || - stat("/dev/null", &stat_buf) != 0) { + stat("/dev/null", &stat_buf) != 0 || + stat("/dev/zero", &stat_buf) != 0) { /* try devtmpfs first, otherwise fall back to manual creation */ if (mount("/dev", "/dev", "devtmpfs", 0, 0) != 0) { mknod("/dev/console", 0600 | S_IFCHR, makedev(5, 1)); mknod("/dev/null", 0666 | S_IFCHR, makedev(1, 3)); + mknod("/dev/zero", 0666 | S_IFCHR, makedev(1, 5)); } } } From patchwork Fri Jul 7 15:03:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13305012 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9EFEEEB64D9 for ; Fri, 7 Jul 2023 15:03:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233116AbjGGPDw (ORCPT ); Fri, 7 Jul 2023 11:03:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233238AbjGGPDv (ORCPT ); Fri, 7 Jul 2023 11:03:51 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1022B1FE2; Fri, 7 Jul 2023 08:03:49 -0700 (PDT) X-QQ-mid: bizesmtp67t1688742215t9bcbq7j Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 07 Jul 2023 23:03:34 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: ttAhR/+4RmnN6nx3iljloJFFxC//J57L6V9h3PxADUXe0+b7w1eDps9vJaZOn mn9JnbeD3nNYt2VsoSba+gB6pGj899tAN6ryR8zpRDrkOTDVEHXgh0of9Yyv8BcQAfM97D2 g2fMfc3LDxLKjw9FJwWuCuMyMOe5AINO51aaVWYKTTeWgAXzNiyUr8HQJ+HRdU/kDuceTuW trYrBgn1FORbXZufjh6X3yYFmOZszVuJxwEYbpmV/DohrTADWUBJLFrfubtSoJ+YBzzvAum e5mSH8c0ZQi8JQKddt3LY5y3rSBJP0O7HRqRNpa2ATMPhfavAtpjt5bZCnHolzcLXkDKr2/ 7zcOjZezqMfR30WpbgqtGxf2RdnL963KDMLTEjNRrPPWoUWpLWENiWDlDdimm2JozmewsN2 X-QQ-GoodBg: 0 X-BIZMAIL-ID: 7898572542868346834 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, david.laight@aculab.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, thomas@t-8ch.de Subject: [PATCH v6 11/15] selftests/nolibc: add EXPECT_PTREQ, EXPECT_PTRNE and EXPECT_PTRER Date: Fri, 7 Jul 2023 23:03:26 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org The syscalls like sbrk() and mmap() return pointers, to test them, more pointer compare test macros are required, add them: - EXPECT_PTREQ() expects two equal pointers. - EXPECT_PTRNE() expects two non-equal pointers. - EXPECT_PTRER() expects failure with a specified errno. - EXPECT_PTRER2() expects failure with one of two specified errnos. Signed-off-by: Zhangjin Wu --- tools/testing/selftests/nolibc/nolibc-test.c | 58 ++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index b759fb25d375..8be675debf28 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -364,6 +364,64 @@ static int expect_ptrnz(const void *expr, int llen) return ret; } +#define EXPECT_PTREQ(cond, expr, cmp) \ + do { if (!cond) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_ptreq(expr, llen, cmp); } while (0) + +static int expect_ptreq(const void *expr, int llen, const void *cmp) +{ + int ret = 0; + + llen += printf(" = <%p> ", expr); + if (expr != cmp) { + ret = 1; + llen += pad_spc(llen, 64, "[FAIL]\n"); + } else { + llen += pad_spc(llen, 64, " [OK]\n"); + } + return ret; +} + +#define EXPECT_PTRNE(cond, expr, cmp) \ + do { if (!cond) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_ptrne(expr, llen, cmp); } while (0) + +static int expect_ptrne(const void *expr, int llen, const void *cmp) +{ + int ret = 0; + + llen += printf(" = <%p> ", expr); + if (expr == cmp) { + ret = 1; + llen += pad_spc(llen, 64, "[FAIL]\n"); + } else { + llen += pad_spc(llen, 64, " [OK]\n"); + } + return ret; +} + +#define EXPECT_PTRER2(cond, expr, expret, experr1, experr2) \ + do { if (!cond) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_ptrerr2(expr, expret, experr1, experr2, llen); } while (0) + +#define EXPECT_PTRER(cond, expr, expret, experr) \ + EXPECT_PTRER2(cond, expr, expret, experr, 0) + +static int expect_ptrerr2(const void *expr, const void *expret, int experr1, int experr2, int llen) +{ + int ret = 0; + int _errno = errno; + + llen += printf(" = <%p> %s ", expr, errorname(_errno)); + if (expr != expret || (_errno != experr1 && _errno != experr2)) { + ret = 1; + if (experr2 == 0) + llen += printf(" != (<%p> %s) ", expret, errorname(experr1)); + else + llen += printf(" != (<%p> %s %s) ", expret, errorname(experr1), errorname(experr2)); + llen += pad_spc(llen, 64, "[FAIL]\n"); + } else { + llen += pad_spc(llen, 64, " [OK]\n"); + } + return ret; +} #define EXPECT_STRZR(cond, expr) \ do { if (!cond) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_strzr(expr, llen); } while (0) From patchwork Fri Jul 7 15:04:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13305013 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0457FEB64D9 for ; Fri, 7 Jul 2023 15:05:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233293AbjGGPFC (ORCPT ); Fri, 7 Jul 2023 11:05:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232882AbjGGPFB (ORCPT ); Fri, 7 Jul 2023 11:05:01 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 151FBAF; Fri, 7 Jul 2023 08:04:59 -0700 (PDT) X-QQ-mid: bizesmtp86t1688742286tdi4pyen Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 07 Jul 2023 23:04:44 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: LE7C6P2vL8SOb2ot9Z4ClJPBG54oOkVEmnFkdgI7ol3U2CHkMdwXkXemITIbi djp+D/7qqCayMft9D4BLvUx1HdAK5PtsH0bKSsHvQQ+CQkH1NcscF1hU+hEdiActny/W++4 6yGiFU5Cz2UjoqfospzFK3ZAlb9V9Z8HNBWYr7kfNzFTOIq05OxVwEbh6Hb0+GXFC6NojBw 7Qtx8mUIxs/JUHjqS8OQABWAVMsbcFSCfrY0zgRT/BHTNmJuJF4kAf7bGtIxHkt0us2ClEh JFf+lGyIaYHHUbIp1aGNk98tQMfnK2RpSFzpwgXnA7ngEk22+dCmS++VBzsBk+5rHAQIBV4 M7h6K18S8y+59KAI10TvychS9ca23hf+ByN50OBU8CyYuCwK1OflvnlqOuJKA== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 4349370555613870298 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, david.laight@aculab.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, thomas@t-8ch.de Subject: [PATCH v6 12/15] selftests/nolibc: add sbrk_0 to test current brk getting Date: Fri, 7 Jul 2023 23:04:38 +0800 Message-Id: <1d45f48df9735f7c7cd52e2529712a7436c94355.1688739492.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org From musl 0.9.14 (to the latest version 1.2.3), both sbrk() and brk() have almost been disabled for they conflict with malloc, only sbrk(0) is still permitted as a way to get the current location of the program break, let's support such case. EXPECT_PTRNE() is used to expect sbrk() always successfully getting the current break. Signed-off-by: Zhangjin Wu --- tools/testing/selftests/nolibc/nolibc-test.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 8be675debf28..fde1b3c51a4a 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -633,6 +633,7 @@ int run_syscall(int min, int max) CASE_TEST(kill_0); EXPECT_SYSZR(1, kill(getpid(), 0)); break; CASE_TEST(kill_CONT); EXPECT_SYSZR(1, kill(getpid(), 0)); break; CASE_TEST(kill_BADPID); EXPECT_SYSER(1, kill(INT_MAX, 0), -1, ESRCH); break; + CASE_TEST(sbrk_0); EXPECT_PTRNE(1, sbrk(0), (void *)-1); break; CASE_TEST(sbrk); if ((p1 = p2 = sbrk(4096)) != (void *)-1) p2 = sbrk(-4096); EXPECT_SYSZR(1, (p2 == (void *)-1) || p2 == p1); break; CASE_TEST(brk); EXPECT_SYSZR(1, brk(sbrk(0))); break; CASE_TEST(chdir_root); EXPECT_SYSZR(1, chdir("/")); break; From patchwork Fri Jul 7 15:05:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13305019 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 218A1EB64D9 for ; Fri, 7 Jul 2023 15:06:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232277AbjGGPG1 (ORCPT ); Fri, 7 Jul 2023 11:06:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232151AbjGGPG0 (ORCPT ); Fri, 7 Jul 2023 11:06:26 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07F8BAA; Fri, 7 Jul 2023 08:06:24 -0700 (PDT) X-QQ-mid: bizesmtp72t1688742370t5qefwef Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 07 Jul 2023 23:06:09 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: 3M0okmaRx3hzmnpwX7/mep5Hi+aL1BsPnbLb2Ne734KOZ+87748VonTMKdRIp EFDKQ10JOaI9H1K/u2Yfwm8Ia6Dla25b2yBF2VOfTaGbJ/qyULz0sUU/SWH5h85TZzJwQ+a ztzbh/G5rkZFJYZ4liyhe7BpLWnr+cG4Cso4RfBaWwkjZAKRX31UJCpxkIJvbOU/LUOgxD5 Qgl3up7OJ42WsGe4o8iGLxOPxd9rbypRPLBrFdawoixcB5WOgHOgR4cSe7KnQuCPj8OcVdY +ZeJXUx7dr7R+2CsEhy7RZm+kHa23A8+dd3hyEJ1r0fouvYK1X4bs88rqWmwsePtF9ARtvj XfrFvCXbpGEVTpwnrQq6gBVuH6ZDkORFuY53Ge7nNia4nbM0CqdRjoa1eF15Q== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 12075169014602729724 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, david.laight@aculab.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, thomas@t-8ch.de Subject: [PATCH v6 13/15] selftests/nolibc: add mmap_bad test case Date: Fri, 7 Jul 2023 23:05:49 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org The length argument of mmap() must be greater than 0, passing a zero length argument expects failure with -EINVAL. Signed-off-by: Zhangjin Wu --- tools/testing/selftests/nolibc/nolibc-test.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index fde1b3c51a4a..4026772ed4c5 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -669,6 +669,7 @@ int run_syscall(int min, int max) CASE_TEST(lseek_m1); EXPECT_SYSER(1, lseek(-1, 0, SEEK_SET), -1, EBADF); break; CASE_TEST(lseek_0); EXPECT_SYSER(1, lseek(0, 0, SEEK_SET), -1, ESPIPE); break; CASE_TEST(mkdir_root); EXPECT_SYSER(1, mkdir("/", 0755), -1, EEXIST); break; + CASE_TEST(mmap_bad); EXPECT_PTRER(1, mmap(NULL, 0, PROT_READ, MAP_PRIVATE, 0, 0), MAP_FAILED, EINVAL); break; CASE_TEST(open_tty); EXPECT_SYSNE(1, tmp = open("/dev/null", 0), -1); if (tmp != -1) close(tmp); break; CASE_TEST(open_blah); EXPECT_SYSER(1, tmp = open("/proc/self/blah", 0), -1, ENOENT); if (tmp != -1) close(tmp); break; CASE_TEST(poll_null); EXPECT_SYSZR(1, poll(NULL, 0, 0)); break; From patchwork Fri Jul 7 15:07:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13305020 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37313C04A94 for ; Fri, 7 Jul 2023 15:07:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233013AbjGGPHf (ORCPT ); Fri, 7 Jul 2023 11:07:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233327AbjGGPHd (ORCPT ); Fri, 7 Jul 2023 11:07:33 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00092210A; Fri, 7 Jul 2023 08:07:31 -0700 (PDT) X-QQ-mid: bizesmtp90t1688742437tcr8anue Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 07 Jul 2023 23:07:15 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: mRz6/7wsmIg+4CzfesqpnlhD9XXjDu45isJCglf5hPCGD0jR5QLXdzjRlVIQ6 mmO6/WeU/h56+WwaqGBPYOWFEc03dMive8tkSFGo2uxhES+B9CjOOsEhcE2pm2tY4S7XXgx KPEaV+tS3ZY9PhO+3cnptxVVAUVvYyqXhMMkuyz2BhX5oVg9mGBm47uw9hyskv+N3FA+SBD uG4zoMJdLVJmaGMdPBTXDzLCa3Mkn26Y0pWBYeUUJRJXnc/gVcI12s9A9VxyEeanAfwO/qp zdHFwTe+Hz/74ftL/dLu1jF8T0e1MB9uPDRgfvzfwEgTYME2ad3zS6KJ5nSPzVOOAlyQFm1 P8Voz8E8sHZJbgQwFA0JqWED7G59t0HcpmvyivohPpIt1rnSgx7CB9PAtd31Q== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 7592088167357566417 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, david.laight@aculab.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, thomas@t-8ch.de Subject: [PATCH v6 14/15] selftests/nolibc: add munmap_bad test case Date: Fri, 7 Jul 2023 23:07:13 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org The addr argument of munmap() must be a multiple of the page size, passing invalid (void *)1 addr expects failure with -EINVAL. Signed-off-by: Zhangjin Wu --- tools/testing/selftests/nolibc/nolibc-test.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 4026772ed4c5..8644e415cb66 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -670,6 +670,7 @@ int run_syscall(int min, int max) CASE_TEST(lseek_0); EXPECT_SYSER(1, lseek(0, 0, SEEK_SET), -1, ESPIPE); break; CASE_TEST(mkdir_root); EXPECT_SYSER(1, mkdir("/", 0755), -1, EEXIST); break; CASE_TEST(mmap_bad); EXPECT_PTRER(1, mmap(NULL, 0, PROT_READ, MAP_PRIVATE, 0, 0), MAP_FAILED, EINVAL); break; + CASE_TEST(munmap_bad); EXPECT_SYSER(1, munmap((void *)1, 0), -1, EINVAL); break; CASE_TEST(open_tty); EXPECT_SYSNE(1, tmp = open("/dev/null", 0), -1); if (tmp != -1) close(tmp); break; CASE_TEST(open_blah); EXPECT_SYSER(1, tmp = open("/proc/self/blah", 0), -1, ENOENT); if (tmp != -1) close(tmp); break; CASE_TEST(poll_null); EXPECT_SYSZR(1, poll(NULL, 0, 0)); break; From patchwork Fri Jul 7 15:08:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13305021 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 17E51EB64D9 for ; Fri, 7 Jul 2023 15:09:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233054AbjGGPJE (ORCPT ); Fri, 7 Jul 2023 11:09:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233327AbjGGPIz (ORCPT ); Fri, 7 Jul 2023 11:08:55 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C157926B5; Fri, 7 Jul 2023 08:08:49 -0700 (PDT) X-QQ-mid: bizesmtp91t1688742515ti7jswgp Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 07 Jul 2023 23:08:34 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: D6RqbDSxuq6OBW3CsVdKIjFvpbHMW/wgNqC9K9ilhUQlZg0IgX7nDFBEM0M1Q Xro0AOa3zXB43uoPd20W0Y477EJFex9MLuooi5XD4l6HZh5jKuXPydugZugaq81/kFkWdzi 3NKHk+AalEIw0dPBy4h4W6KiwiEYiJPPyFG6rYQmY/1kCx+saPO3DCVGv3MJVWfYJsPD6KV IuJTjUO3zKXqGBxMOdDSSIuwIhoddepxd1W7qukyLJhlVo6ysR4binyQztDX5Ilg0LLohMa XYhps7gmzdcUzBnqBo8YRSzHFNKM1F6c/RShkpHyQHJCnFVnbO0EY/nmeOLelwc4WTsFgqO KwzB6ccg8NLuclWZ81+ujKcAIST6H1z9RVvh+O8xaKEeySAb/fX7v939M8dFY1sJi6Xp/fp /tU5uvp4U9o= X-QQ-GoodBg: 0 X-BIZMAIL-ID: 12299959330165944862 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, david.laight@aculab.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, thomas@t-8ch.de, =?utf-8?q?Thomas_Wei?= =?utf-8?q?=C3=9Fschuh?= Subject: [PATCH v6 15/15] selftests/nolibc: add mmap_munmap_good test case Date: Fri, 7 Jul 2023 23:08:20 +0800 Message-Id: <838f401801aea4476f54d7f5117dc90d8839a515.1688739493.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org mmap() a file with a good offset and then munmap() it. a non-zero offset is passed to test the 6th argument of my_syscall6(). Note, it is not easy to find a unique file for mmap() in different scenes, so, a file list is used to search the right one: - /dev/zero: is commonly used to allocate anonymous memory and is likely present and readable - /proc/1/exe: for 'run' and 'run-user' target, 'run-user' can not find '/proc/self/exe' - /proc/self/exe: for 'libc-test' target, normal program 'libc-test' has no permission to access '/proc/1/exe' - argv0: the path of the program itself, let it pass even with worst case scene: no procfs and no /dev/zero Suggested-by: Willy Tarreau Link: https://lore.kernel.org/lkml/20230702193306.GK16233@1wt.eu/ Suggested-by: Thomas Weißschuh Link: https://lore.kernel.org/lkml/bff82ea6-610b-4471-a28b-6c76c28604a6@t-8ch.de/ Signed-off-by: Zhangjin Wu --- tools/testing/selftests/nolibc/nolibc-test.c | 60 ++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 8644e415cb66..a7191b637b85 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -595,6 +595,65 @@ static int test_stat_timestamps(void) return 0; } +int test_mmap_munmap(void) +{ + int ret, fd, i; + void *mem; + size_t page_size, file_size, length; + off_t offset, pa_offset; + struct stat stat_buf; + const char * const files[] = { + "/dev/zero", + "/proc/1/exe", "/proc/self/exe", + argv0, + NULL + }; + + page_size = getpagesize(); + if (page_size < 0) + return -1; + + /* find a right file to mmap, existed and accessible */ + for (i = 0; files[i] != NULL; i++) { + ret = fd = open(files[i], O_RDONLY); + if (ret == -1) + continue; + else + break; + } + if (ret == -1) + return ret; + + ret = stat(files[i], &stat_buf); + if (ret == -1) + goto end; + + /* file size of the special /dev/zero is 0, let's assign one manually */ + if (i == 0) + file_size = 3*page_size; + else + file_size = stat_buf.st_size; + + offset = file_size - 1; + if (offset < 0) + offset = 0; + length = file_size - offset; + pa_offset = offset & ~(page_size - 1); + + mem = mmap(NULL, length + offset - pa_offset, PROT_READ, MAP_SHARED, fd, pa_offset); + if (mem == MAP_FAILED) { + ret = -1; + goto end; + } + + ret = munmap(mem, length + offset - pa_offset); + +end: + close(fd); + return ret; +} + + /* Run syscall tests between IDs and . * Return 0 on success, non-zero on failure. */ @@ -671,6 +730,7 @@ int run_syscall(int min, int max) CASE_TEST(mkdir_root); EXPECT_SYSER(1, mkdir("/", 0755), -1, EEXIST); break; CASE_TEST(mmap_bad); EXPECT_PTRER(1, mmap(NULL, 0, PROT_READ, MAP_PRIVATE, 0, 0), MAP_FAILED, EINVAL); break; CASE_TEST(munmap_bad); EXPECT_SYSER(1, munmap((void *)1, 0), -1, EINVAL); break; + CASE_TEST(mmap_munmap_good); EXPECT_SYSZR(1, test_mmap_munmap()); break; CASE_TEST(open_tty); EXPECT_SYSNE(1, tmp = open("/dev/null", 0), -1); if (tmp != -1) close(tmp); break; CASE_TEST(open_blah); EXPECT_SYSER(1, tmp = open("/proc/self/blah", 0), -1, ENOENT); if (tmp != -1) close(tmp); break; CASE_TEST(poll_null); EXPECT_SYSZR(1, poll(NULL, 0, 0)); break;