From patchwork Wed Jun 28 13:41: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: 113934 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8965562vqr; Wed, 28 Jun 2023 07:23:19 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5x2HeQSIV21qOxPV0XGaFCRBlyGIAPaFq1g/hKBNByk6cEAPSsmySik32Shf/0Vzy8pEGE X-Received: by 2002:a17:902:ea0d:b0:1b7:c666:dc5e with SMTP id s13-20020a170902ea0d00b001b7c666dc5emr17094294plg.8.1687962199398; Wed, 28 Jun 2023 07:23:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687962199; cv=none; d=google.com; s=arc-20160816; b=qB0zyX0ubXsfNx2B4suutov4NFOnYB153nTZEG1Q3woYm05J0ySWXZ8GBA8deQQV9b thnhuntkH5Tj0rFn33Is2fl9l1qN4NK7TeU3053LPRNWnYtOF9Y4SOR4YUW76O3Mky/J 5V2SpP7NssvAnuxf5Xs+keEv5dct9qDleILeQzlfiFDLsgksNo5nAgTXWuJKlkS6Fv7t Y7l75qGSOB1oK7dHAg8pX9Jx/shMK7Cq823JVMojZ/F+g7k3pxooUJZBNkT3F52GWx37 vmStkJi3NYFPnVZSXE6zEY4bO5NgBNVet/Voq3iB3cnoGxSY3g0WzerrNsB4zTWVaapy OMTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=w5qpZsYx3idnX+Nj4vLkPb2JPJlA0/PmXaPlbQfjnD0=; fh=CABfkMhKo5yB9DuGBIJJBQ5z8vnCCyGNX8ln70ySW7c=; b=A/sPOf63xF7pZTBS7eZTkcnjnrV7dd7UDqbED3W1jdKSs0Q1dQtfW8psB6AoAuerAh PNJWa65INCkWQGH6vfNnbE3sAd91Qw8B9vYjj1tsOFlRSGoqh+5rx0j94wrqpDbfCeXT ZKffQGX7YVv0+D2oknUIAfL4c91y8jE4dDv44PkP5JtMXKK4QnoEVLiH/Aq7riBN0qdD XZktwo8SV/QgWtgsVRSVco9Z9sNRvYmq2TBU8hZz7LOi5cs/t3N8uOM2mGDS0qZ+1DzJ 4RWLCYXsFO7ecrKWuVq1KzhblwGn5tfRdE264jAjTGFaiITAjzTCOfslGLqHiQYXhcVW 4jbQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q15-20020a170902eb8f00b001b3d27c4f48si2484503plg.57.2023.06.28.07.23.04; Wed, 28 Jun 2023 07:23:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231903AbjF1NoO (ORCPT + 99 others); Wed, 28 Jun 2023 09:44:14 -0400 Received: from bg4.exmail.qq.com ([43.155.65.254]:10251 "EHLO bg4.exmail.qq.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231210AbjF1NoJ (ORCPT ); Wed, 28 Jun 2023 09:44:09 -0400 X-QQ-mid: bizesmtp71t1687959834tnnavfbr Received: from linux-lab-host.localdomain ( [116.30.129.193]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 28 Jun 2023 21:43:53 +0800 (CST) X-QQ-SSF: 01200000000000D0V000000A0000000 X-QQ-FEAT: Y6Kc/cQg3lZMtgn2kxiU6zmEGNcj28TJS0EgbFpP4twIX+T9y2B6p0bOn3MWv kwvUR4P1W5/nG5q1ysHmSUWyO41+7CgGe/G/5Cr9uT7VV9/dHhRkxOPPx8eQM51V/NExjV5 NnAojSJ9NLly/nYfbygC8y0tCztiSKCNMJjl2tyv6UelKR7tTEonhyqEbq5SY9F/isScf+J CVkN9WiXJ7yUkVDmYOdChCbet5bOziyBbcdV46eQkF+gQF230AShRQ//qpPP/8+FrE3HBc/ mlOEG2WWVXjDZZyYRWG4u/NjvjF3ZNtMw1lVdF+2tC8WkonX/j1Ou8lbp3JZSN6w1SZ/N1F UT+xC1U6JoBtLl8IkZcz//WavDz3ZKXZZWvncWZbo14gwTYVbmwEqrTyZWtdg== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 10849030665645760256 From: Zhangjin Wu To: thomas@t-8ch.de, 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 Subject: [PATCH v5 11/14] tools/nolibc: clean up mmap() support Date: Wed, 28 Jun 2023 21:41: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:qybglogicsvrsz:qybglogicsvrsz3a-3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769956651170515988?= X-GMAIL-MSGID: =?utf-8?q?1769956651170515988?= 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 __sysret() to convert the calling of sys_map() to oneline code Signed-off-by: Zhangjin Wu --- tools/include/nolibc/sys.h | 24 +----------------------- tools/include/nolibc/types.h | 6 ++++++ 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index b6125e600dc2..e0ac95a4bfa1 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -632,26 +632,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) @@ -662,20 +647,13 @@ 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 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..bed62da7877c 100644 --- a/tools/include/nolibc/types.h +++ b/tools/include/nolibc/types.h @@ -10,6 +10,7 @@ #include "std.h" #include #include +#include /* Only the generic macros and types may be defined here. The arch-specific @@ -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