Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp4937442rwl; Sun, 8 Jan 2023 06:00:01 -0800 (PST) X-Google-Smtp-Source: AMrXdXs47jq4jD69h50JXGOpuZwx5YZYQzws1wySpAB691KMfMlCqUFTY4ZXZ6dkQU14CRjcIXG0 X-Received: by 2002:a17:90a:62c1:b0:226:d7e8:e11f with SMTP id k1-20020a17090a62c100b00226d7e8e11fmr10754811pjs.12.1673186400833; Sun, 08 Jan 2023 06:00:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673186400; cv=none; d=google.com; s=arc-20160816; b=zf7V2b3bcbCNCr5UG0+CaVuhVVWzou2FwHil4difktcx01s5Kt9nF0/Rai/+Lxa7Bi sGJcDk04QVrV/pXkZQp2cd+hTetFDTpy3zguqId9fu9999C3fZ/8VMg5v/JxuBJRG43s H0+jfIah9nJMOvabkBppWAHKd7+Ij55G6CRana2bYUDFvhUBJXHRTC0BKXUqxsUb9+NQ mFbu2PgTQU+EKPtQvkpHldIwzVnJRQ2WsAUDMumuhybnt14wvcG02E+Quhyrpu5PcOlt Uh6G2JdD0cdwzevhvj6p54bdNaVmptqxq29MRLmYDTy3zt6LU+rez7JSr+zTrWaPTqV7 eJkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=m/2mdc30Gp8/Q1PygMPSfenfDGkA0e5iobglBLdbUHU=; b=LXsNVMBcF76I0w7NIZ1FuXUm9xVbRldJm5v/lwNmy2IbNTwAiRHuJ4x3ATCQ8JiGej TvzPanNLLVxMkrtrvlBxseAV0R9qnJmUgO9f6ung7I+vHeMCah9t3mAeon6hfLALzxQg 52UK/jJcG8z4/56Gk61jXqLz/fvA6dYLSC5rhejKOdIXYpi8lVGQXrkOPnKJ58s00LyJ iX8HWKPG0BIX5zzieeS4i6pIj+jgHfnOhIm/xtdL+FIVvK02kk6WPkpQ4RaaJCrJ4zOT 0VPuogPz3zO7cEXovqVdgmBCID8bsA+O8zO0BfZ9n0QACTf+No0srJ/IvDe+/JGHmA78 C7AA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gnuweeb.org header.s=default header.b=tAlpPOYo; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnuweeb.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h16-20020a17090aea9000b002263901539asi6631034pjz.2.2023.01.08.05.59.54; Sun, 08 Jan 2023 06:00:00 -0800 (PST) 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; dkim=pass header.i=@gnuweeb.org header.s=default header.b=tAlpPOYo; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnuweeb.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231255AbjAHN60 (ORCPT + 52 others); Sun, 8 Jan 2023 08:58:26 -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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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) { -- Ammar Faizi