From patchwork Sun Jan 8 13:58:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ammar Faizi X-Patchwork-Id: 13092497 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 A7D87C54EBD for ; Sun, 8 Jan 2023 13:58:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230498AbjAHN6Y (ORCPT ); Sun, 8 Jan 2023 08:58:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229482AbjAHN6W (ORCPT ); Sun, 8 Jan 2023 08:58:22 -0500 Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65E49D2FE; Sun, 8 Jan 2023 05:58:21 -0800 (PST) Received: from localhost.localdomain (unknown [182.253.183.184]) by gnuweeb.org (Postfix) with ESMTPSA id 4E6717E6D0; Sun, 8 Jan 2023 13:58:18 +0000 (UTC) X-GW-Data: lPqxHiMPbJw1wb7CM9QUryAGzr0yq5atzVDdxTR0iA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1673186301; bh=BkTOpKaeNmCPtwR5gdbSfSfyuS5UVBZalGi2xnE4O5s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tAlpPOYoyNS07iwYSbr6NMlh3VacCe9dxJ1Kx8fm9C2wzb2FnYGDA3QUVNmH7BbtR 8VwmBFiui5bP7pVX21V8oleWO1KXGsfzhKObTNVxrfsPpnJmLCjLK3VMAGIqqKUXlT YvjIByFKXxIbtQB8lmwb9PeXHYGCOFoT3mgNu5zwoepue9YukyCs8sEPLRb86daKuZ WaowmigasH6Rz1WCNxvUjCIsMoO6iT2lVvPWcG5xu/EdV1Qn5OrjBvWF9+ODP1/CT5 oPt2N46aqGW4aqPqQN8LbvXhxSKDnsyamGF9hG+Cw/QqrK2P9967ah1OZsyNKmdT5P gyjVvrEFpHuMA== 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 1/3] nolibc/stdlib: Implement `getauxval(3)` function Date: Sun, 8 Jan 2023 20:58:07 +0700 Message-Id: <20230108135809.850210-2-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 Previous commits save the address of the auxiliary vector into a global variable @_auxv. This commit creates a new function 'getauxval()' as a helper function to get the auxv value based on the given key. The behavior of this function is identic with the function documented in 'man 3 getauxval'. This function is also needed to implement 'getpagesize()' function that we will wire up in the next patches. Signed-off-by: Ammar Faizi --- tools/include/nolibc/stdlib.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tools/include/nolibc/stdlib.h b/tools/include/nolibc/stdlib.h index 92378c4b9660..cdca557c4013 100644 --- a/tools/include/nolibc/stdlib.h +++ b/tools/include/nolibc/stdlib.h @@ -12,6 +12,7 @@ #include "types.h" #include "sys.h" #include "string.h" +#include struct nolibc_heap { size_t len; @@ -108,6 +109,32 @@ char *getenv(const char *name) return _getenv(name, environ); } +static __attribute__((unused)) +unsigned long getauxval(unsigned long type) +{ + const unsigned long *auxv = _auxv; + unsigned long ret; + + if (!auxv) + return 0; + + while (1) { + if (!auxv[0] && !auxv[1]) { + ret = 0; + break; + } + + if (auxv[0] == type) { + ret = auxv[1]; + break; + } + + auxv += 2; + } + + return ret; +} + static __attribute__((unused)) void *malloc(size_t len) {