From patchwork Tue Oct 27 09:42:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 40884 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8BD70386EC2D; Tue, 27 Oct 2020 09:43:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8BD70386EC2D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1603791782; bh=3Va6Y9CL0CSsQYUa2okeGBdYfAHu9giHPva49T7H5vY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=oXmWOoApEj8bECKgIsOcTzLogi193nUkOgNs+KDtAvkWNyopQ3rC+Uax7yRZrg6il IpXoHS9/YZKLta+vhWgy7mgwzRAHr9DXZKJPjFWBPmcz/hMh72o7JkNOl8R29Sl0Gw 0lvQ2twuLYzUkMHL7kzLnZLPMAf0uhuWaAD0BCss= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 802003858D37 for ; Tue, 27 Oct 2020 09:42:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 802003858D37 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-463-ACrJpWp8Oj61yDprh2GxGA-1; Tue, 27 Oct 2020 05:42:57 -0400 X-MC-Unique: ACrJpWp8Oj61yDprh2GxGA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id ADE301882FB3 for ; Tue, 27 Oct 2020 09:42:56 +0000 (UTC) Received: from oldenburg2.str.redhat.com (ovpn-113-60.ams2.redhat.com [10.36.113.60]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2BE265C1C2 for ; Tue, 27 Oct 2020 09:42:56 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH] misc: Add internal __getauxval2 function Date: Tue, 27 Oct 2020 10:42:54 +0100 Message-ID: <87imaw80o1.fsf@oldenburg2.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" The explicit error return value (without in-band signaling) avoids complicated steps to detect errors based on whether errno has been updated. Tested on x86_64-linux-gnu. Reviewed-by: Alistair Francis --- include/sys/auxv.h | 5 +++++ misc/getauxval.c | 33 +++++++++++++++++++++++++++------ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/include/sys/auxv.h b/include/sys/auxv.h index 3bab6d05d4..dd0602b08d 100644 --- a/include/sys/auxv.h +++ b/include/sys/auxv.h @@ -5,4 +5,9 @@ extern __typeof (getauxval) __getauxval; libc_hidden_proto (__getauxval) +/* Like getauxval, but writes the value to *RESULT and returns true if + found, or returns false. Does not set errno. */ +_Bool __getauxval2 (unsigned long int type, unsigned long int *result); +libc_hidden_proto (__getauxval2) + #endif /* !_ISOMAC */ diff --git a/misc/getauxval.c b/misc/getauxval.c index d7f9f957d0..e96d4dfa20 100644 --- a/misc/getauxval.c +++ b/misc/getauxval.c @@ -18,26 +18,47 @@ #include #include #include +#include - -unsigned long int -__getauxval (unsigned long int type) +bool +__getauxval2 (unsigned long int type, unsigned long int *result) { #ifdef HAVE_AUX_VECTOR ElfW(auxv_t) *p; #endif if (type == AT_HWCAP) - return GLRO(dl_hwcap); + { + *result = GLRO(dl_hwcap); + return true; + } else if (type == AT_HWCAP2) - return GLRO(dl_hwcap2); + { + *result = GLRO(dl_hwcap2); + return true; + } #ifdef HAVE_AUX_VECTOR for (p = GLRO(dl_auxv); p->a_type != AT_NULL; p++) if (p->a_type == type) - return p->a_un.a_val; + { + *result = p->a_un.a_val; + return true; + } #endif + return false; +} +libc_hidden_def (__getauxval2) + +unsigned long int +__getauxval (unsigned long int type) +{ + unsigned long int result; + + if (__getauxval2 (type, &result)) + return result; + __set_errno (ENOENT); return 0; }