From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NO_DNS_FOR_FROM autolearn=no autolearn_force=no version=3.4.6 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) 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 Content-Transfer-Encoding: 8bit List-Id: 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) { -- Ammar Faizi