From patchwork Sun Jan 8 13:58:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ammar Faizi X-Patchwork-Id: 13092498 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 F3B6FC54EBD for ; Sun, 8 Jan 2023 13:58:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233007AbjAHN60 (ORCPT ); Sun, 8 Jan 2023 08:58:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232939AbjAHN6Z (ORCPT ); Sun, 8 Jan 2023 08:58:25 -0500 Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5935D2FF; Sun, 8 Jan 2023 05:58:24 -0800 (PST) Received: from localhost.localdomain (unknown [182.253.183.184]) by gnuweeb.org (Postfix) with ESMTPSA id AF84E7E6D5; Sun, 8 Jan 2023 13:58:21 +0000 (UTC) X-GW-Data: lPqxHiMPbJw1wb7CM9QUryAGzr0yq5atzVDdxTR0iA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1673186304; bh=wcpOgJmHUqHilg+MA55c94wnAlyf9zHTIyYePnjiqNM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EFXZkn/3XD4yXC9/kl1H5fo6KHZ5WXwvEzPwVJRY+oy6THg+LUcgqGZqjedoPNQVP TPFcc8x8q2Om7FZ24wCiusqC9yie+y+0U8H9vZ/vsup2nKBvP1DG7gaAwnM7/K8vXO ij5BA5kXIugK5sfb40wRTi6DImcbv+1WPBXy2QtfItgEH+JVpnl8xHqYpUay7jldol AiTfAO63d2oM311mt9jRi3n9kqlvtGJTMC5s7p5KZBYtgw6HbN6MEMg+LG8V9Ot9jV qmyuorbPFE/2C+bFOJz84vybWBitXC3OjpMOwi2TQgx7RHWePH0HxxXEmG/m6BQbQS 5zs909NZv8c8w== From: Ammar Faizi To: Willy Tarreau Cc: Ammar Faizi , Shuah Khan , "Paul E. McKenney" , Sven Schnelle , Alviro Iskandar Setiawan , GNU/Weeb Mailing List , Linux Kernel Mailing List , Linux Kselftest Mailing List Subject: [RESEND PATCH v1 2/3] nolibc/sys: Implement `getpagesize(2)` function Date: Sun, 8 Jan 2023 20:58:08 +0700 Message-Id: <20230108135809.850210-3-ammar.faizi@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230108135809.850210-1-ammar.faizi@intel.com> References: <20230108135809.850210-1-ammar.faizi@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org From: Ammar Faizi This function returns the page size used by the running kernel. The page size value is taken from the auxiliary vector at 'AT_PAGESZ' key. 'getpagesize(2)' is assumed as a syscall becuase the manpage placement of this function is in entry 2 ('man 2 getpagesize') despite there is no real 'getpagesize(2)' syscall in the Linux syscall table. Define this function in 'sys.h'. Signed-off-by: Ammar Faizi --- Side note: This function calls 'getauxval(3)' function that's defined in 'stdlib.h', but since most functions in 'stdlib.h' needs 'sys.h', the 'sys.h' is always included first. Therefore, we need a forward declaration of 'getauxval(3)' in sys.h. tools/include/nolibc/sys.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index 3db1dd8c74ee..acf7cf438010 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -18,6 +18,7 @@ #include #include #include +#include #include "arch.h" #include "errno.h" @@ -498,6 +499,26 @@ pid_t gettid(void) return sys_gettid(); } +static unsigned long getauxval(unsigned long key); + +/* + * long getpagesize(void); + */ + +static __attribute__((unused)) +long getpagesize(void) +{ + long ret; + + ret = getauxval(AT_PAGESZ); + if (!ret) { + SET_ERRNO(ENOENT); + return -1; + } + + return ret; +} + /* * int gettimeofday(struct timeval *tv, struct timezone *tz);