Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp5880564rwl; Mon, 9 Jan 2023 00:45:24 -0800 (PST) X-Google-Smtp-Source: AMrXdXt6epMLdQHo4zcJzjxHWdmgQkerRLj+Tpc5kambWKvYuXRIHHAdXhd5UxQVtylWxL4ypLyw X-Received: by 2002:a17:906:2801:b0:7c1:639:6b46 with SMTP id r1-20020a170906280100b007c106396b46mr48856666ejc.9.1673253924690; Mon, 09 Jan 2023 00:45:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673253924; cv=none; d=google.com; s=arc-20160816; b=P8E1S5CZ338Cw5aVYEpAONOz9PuEIS2duBp4cXT/xPwcSDfSBVmZ+IQer55MwX1187 yBljiI9qG2pk2YgMeNnS6ONxsslVpSdAV0UaoT9DY4cLbRnTTZTD8SHG42M0XmxXY17A eIUoHAXwocVJXY2Mr/VBfAitOIYTl3RspJ+odD4CG/OdBPSWQbskSNGTCrMLUapJWypm z6BfLXeeJEelaw4mSE1O6UM6l++v28UXIl+hK6UUZp2jRZ9KMCWgG/Nb9bTeXKcrPRx8 jyrd/CwHs8rlfQPACYd1v2H8IA6u3VaHiWPCM1CyRsQ1pM3AZ2zLEjDm70/t2YsMbYmp YofQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=uhG7DTtl9/Pj7zRozgAVktjHp64C0Fcc0EMks0MvQvk=; b=ERGW4bXqIUsV0gGaibUf16FGk+IxLVNcUq4jS3QSmlx5XBenhEFMrqsj74cV00qGQq iNg10tqVzo0K91//XODb8Z8ja4/WA9SK5m+kBNZslcPRJeWGFlMRyeJJOPooT3Zc5Naw erusYhwwPtUgFARB8TiK58yThX5KtPfQJNv4MN8bnQNINC+hNWXUbpdcQFyW3k6Nj8a2 +3lwZyXVZW51vK7u+IZZqrCKRXLThI/MYuZyZge2pD06xeQPOfiyNil728SRB/HjWSX7 x0wle0pERn6DmMypElc7j/1N4UDxuexCRRAcGKCBjpq63eqqtWY/UuDxBxh7qOILMLmW g7Xw== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id un2-20020a170907cb8200b007adadfc97c7si6956841ejc.918.2023.01.09.00.45.10; Mon, 09 Jan 2023 00:45:24 -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; 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 S236874AbjAIInO (ORCPT + 54 others); Mon, 9 Jan 2023 03:43:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236844AbjAIImX (ORCPT ); Mon, 9 Jan 2023 03:42:23 -0500 Received: from 1wt.eu (wtarreau.pck.nerim.net [62.212.114.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8045012D2D for ; Mon, 9 Jan 2023 00:42:22 -0800 (PST) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 3098gFRG027439; Mon, 9 Jan 2023 09:42:15 +0100 From: Willy Tarreau To: "Paul E. McKenney" Cc: linux-kernel@vger.kernel.org, Ammar Faizi Subject: [PATCH 20/22] nolibc/stdlib: Implement `getauxval(3)` function Date: Mon, 9 Jan 2023 09:42:06 +0100 Message-Id: <20230109084208.27355-21-w@1wt.eu> X-Mailer: git-send-email 2.17.5 In-Reply-To: <20230109084208.27355-1-w@1wt.eu> References: <20230109084208.27355-1-w@1wt.eu> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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 a24000d1e822..894c955d027e 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) { -- 2.17.5