Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp7410640rwl; Mon, 9 Jan 2023 23:57:13 -0800 (PST) X-Google-Smtp-Source: AMrXdXsUFxdYELy7sJ1f2QCD+zEGO9yInOD28m2X6YJ7SL1W6sBuhXFN7LppqJ+TYDvctm+V1pSl X-Received: by 2002:a05:6a21:3a94:b0:9d:efbe:52c3 with SMTP id zv20-20020a056a213a9400b0009defbe52c3mr16026523pzb.51.1673337433318; Mon, 09 Jan 2023 23:57:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673337433; cv=none; d=google.com; s=arc-20160816; b=vFhj+Kc3+AwEEuyAVU1REyDFLg7G6zIOckqL7DPmdHEfhLlvaJIRxw6f2g6+g5VCjl UGoI9p7GZR/Vi9A2vGB9WD38/zF1/bDe1v7vxt67eSNWWsRK6FZmPYHaKTYRBHUNhRUF sEe8z3VwvADT3Jyu1PmxDVExM0PjbDlc3ONcGVp9QQVV7OiFSuVWC9+PMjyypgQsWTEj Md39i3uOe5PxM/lE7k2eyYKbBuBe0NlR8DYb7o/I74CqBq+vqDs0ffNWQkbUZNywm1Pl S3Ytj36LPXKH8NAxqAs23XS6cIT9mwMRsmpgvmDc93FvXHBU46pudfJjgGwDAS5hNDno /Kog== 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=7QZ5h6OZxJsl3IigKp8/LdcR1xHLu5WK9TSS+yyc86Y=; b=PCAE8Vtczlo3grCHrAGmnke2gGFRsyxfbAObn0Ir+6L7QQWQi4LIfl/EOR7WmbECTK Mv2pNMHuN7++Y3xEgyPRb7EI1ixTxE91PXTBxHC/YdxMWHPAFWsYJQpYuh65+bLHoWSN /H5KxyAajz3y0Fhk0qwWpFY4Z2ziVsalsossj+yZbizj4vpVIWjphRiv6mHhY0wj/Syj k3SYOhMbGQ74PGStNUv3hjyVGxMTVW0cm0tDYmVoxEYXzceSx3WHwjc7P73k8kFvocqL qygTg9PQYfG8+L/IIaWlrnVTGsUIQDZCA74OyS0egqoVohpsXvfZPFJVyhib79oKsAG+ J6SA== 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 n64-20020a632743000000b00478e26efc95si10857256pgn.34.2023.01.09.23.57.06; Mon, 09 Jan 2023 23:57:13 -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 S235654AbjAJH11 (ORCPT + 53 others); Tue, 10 Jan 2023 02:27:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237634AbjAJH1E (ORCPT ); Tue, 10 Jan 2023 02:27:04 -0500 Received: from 1wt.eu (wtarreau.pck.nerim.net [62.212.114.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9CADC1C4 for ; Mon, 9 Jan 2023 23:25:50 -0800 (PST) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 30A7OeHA003947; Tue, 10 Jan 2023 08:24:40 +0100 From: Willy Tarreau To: "Paul E. McKenney" Cc: linux-kernel@vger.kernel.org, Ammar Faizi , Willy Tarreau Subject: [PATCH v2 20/22] nolibc/stdlib: Implement `getauxval(3)` function Date: Tue, 10 Jan 2023 08:24:32 +0100 Message-Id: <20230110072434.3863-21-w@1wt.eu> X-Mailer: git-send-email 2.17.5 In-Reply-To: <20230110072434.3863-1-w@1wt.eu> References: <20230110072434.3863-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 Signed-off-by: Willy Tarreau --- 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