Message ID | 20230110072434.3863-21-w@1wt.eu |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2602747wrt; Mon, 9 Jan 2023 23:28:07 -0800 (PST) X-Google-Smtp-Source: AMrXdXsGnRZTZLU9/7nO9uH77ahTYdGk9cEOaMFfTuX7RgkBcKtvumAJIhfPfA1xLtHP7S9iFrqh X-Received: by 2002:a17:90a:35a:b0:228:cd5d:aa8 with SMTP id 26-20020a17090a035a00b00228cd5d0aa8mr1605771pjf.30.1673335686500; Mon, 09 Jan 2023 23:28:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673335686; cv=none; d=google.com; s=arc-20160816; b=DFj0d0UqQqaCGXuUTCF85i1a2TBowdcCfjWQipfwNxqZz3EZtEdB7g+yOEX+VAwq8d g5O/qgT0dy/VjpJAeTHNn+1jg22Qy2jlw4ME74BZDsYaoUdKVZ9o1LUYc/8mg9aiYJLG 5VtAMSaZZVuMb12UjVJ4jAPC/uEcSASngv0Q9Qqq/pyVnT5puz1DWKCjPfWHclRnxEy4 qKS7xMCPPYwHXPSkRB02Eg3zmV+PYY1gkkhJufpOVUPs/wiWRrfc7++Ls8xf7KtHClvQ 3DSk8Xaz7INpTdWE7V3NQTW6q9NZyO9olgEyEldHT44wtyOGC4fpuGqDF+MSrQMfqy7K LPAQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id in17-20020a17090b439100b002233c2053c8si10424412pjb.78.2023.01.09.23.27.54; Mon, 09 Jan 2023 23:28:06 -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 <rfc822;syz17693488234@gmail.com> + 99 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 <rfc822;linux-kernel@vger.kernel.org>); 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 <linux-kernel@vger.kernel.org>; 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 <w@1wt.eu> To: "Paul E. McKenney" <paulmck@kernel.org> Cc: linux-kernel@vger.kernel.org, Ammar Faizi <ammarfaizi2@gnuweeb.org>, Willy Tarreau <w@1wt.eu> 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754619640522458090?= X-GMAIL-MSGID: =?utf-8?q?1754619640522458090?= |
Series |
nolibc: usability improvements (errno, environ, auxv)
|
|
Commit Message
Willy Tarreau
Jan. 10, 2023, 7:24 a.m. UTC
From: Ammar Faizi <ammarfaizi2@gnuweeb.org> 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 <ammarfaizi2@gnuweeb.org> Signed-off-by: Willy Tarreau <w@1wt.eu> --- 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 <linux/auxvec.h> 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) {