From patchwork Thu Oct 3 02:26:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Aaron Merey X-Patchwork-Id: 98300 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 82CFC385DDDD for ; Thu, 3 Oct 2024 02:27:10 +0000 (GMT) X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 2DDC5385840A for ; Thu, 3 Oct 2024 02:26:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2DDC5385840A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2DDC5385840A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727922402; cv=none; b=Lm/GdjTc021CHPYG+noSkbOBzvecCZtzDi/ajYn3v/bA0AddkGJ3hdp+e1DSNTh3in5+dGGxdrDGHqcemcrF6Aa0X/NfcEOMiSBSOp5g/ip99v1qgpylFZAfIJQrJQaETNgWU2k51IKSe8WL7AI/F7bvETjSyIUAax7YrE2WSQg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727922402; c=relaxed/simple; bh=x4vt0jeHSBjWr201YtDA98sYBPkoi+QaS49mHS3kWns=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=mvowt6Y3GgC7QpSPzrta207GuCd7pDj98Ri2NKI7nmfAUE17SP0377CjvX3IZ+HGGOkq+TOEanCgRGmLyfHmmx/f5JjhghvtbZ7qW7cm+TFRxzKLGnCwd/7N84l2ANkmG3rXWDqihwBlVH7wA8HL0066kNoF+CMatWmja57cEc4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727922390; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=g1wUsO0yd9ohP/m8nxDoJIpEhtPNYO2e4mIhn07bRq8=; b=R9bPPtbIAcsUj4nNBGphG7ytilSOB0hv+/wrug7tiyLebvXTM7VQ+xCl7BWzWXeMZ/ZmDP qeN+timUVpBfy0DMmXnhelSU0JL+6YHrgYKizpSQ4M++nhbcjB4GN8y40+hBYOl5T/mIYv mF5bXkTa6lBOZWtxBgijKd0MncDLYcg= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-122-KH-aJ0WvMmWXosTp13EQww-1; Wed, 02 Oct 2024 22:26:29 -0400 X-MC-Unique: KH-aJ0WvMmWXosTp13EQww-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5865219560AE for ; Thu, 3 Oct 2024 02:26:26 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.64.12]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5B75219560A3; Thu, 3 Oct 2024 02:26:24 +0000 (UTC) From: Aaron Merey To: elfutils-devel@sourceware.org Cc: Aaron Merey Subject: [PATCH 2/9 v2] doc: Add elf32_fsize.3 and elf64_fsize.3 Date: Wed, 2 Oct 2024 22:26:03 -0400 Message-ID: <20241003022610.129834-2-amerey@redhat.com> In-Reply-To: <20241003022610.129834-1-amerey@redhat.com> References: <20241003022610.129834-1-amerey@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: elfutils-devel-bounces~patchwork=sourceware.org@sourceware.org Signed-off-by: Aaron Merey --- v2 changes: Reword description. State EV_CURRENT is the only valid version. Mention possibility of integer overflow. On Tue, Aug 27, 2024 at 12:32 PM Mark Wielaard wrote: > > Maybe give at least some examples of Elf_Type and which data structure > they represent? ELF_T_ADDR (32 bit address), ELF_T_EHDR (Elf32_Ehdr), > etc. > > And mention that elf_getdata will set the Elf_Data d_type to the > Elf_Type of the section? I added "See libelf(3) for more information regarding Elf_Type" to the description. This man page doesn't exist yet but I will add it and include a list of the different Elf_Type and its relationship to Elf_Data. doc/elf32_fsize.3 | 78 +++++++++++++++++++++++++++++++++++++++++++++++ doc/elf64_fsize.3 | 1 + 2 files changed, 79 insertions(+) create mode 100644 doc/elf32_fsize.3 create mode 100644 doc/elf64_fsize.3 diff --git a/doc/elf32_fsize.3 b/doc/elf32_fsize.3 new file mode 100644 index 00000000..a0aac70e --- /dev/null +++ b/doc/elf32_fsize.3 @@ -0,0 +1,78 @@ +.TH ELF32_FSIZE 3 2024-08-14 "Libelf" "Libelf Programmer's Manual" + +.SH NAME +elf32_fsize, elf64_fsize \- calculate the file size of an ELF data structure + +.SH SYNOPSIS +.nf +.B #include + +.BI "size_t elf32_fsize(Elf_Type " type ", size_t " count ", unsigned int " version ");" +.BI "size_t elf64_fsize(Elf_Type " type ", size_t " count ", unsigned int " version ");" + +.SH DESCRIPTION +Given an +.B Elf_Type +representation of a core ELF structure as well as the number of items, return +the number of bytes needed for the on-disk representation in a 32-bit or 64-bit +ELF file. The on-disk and in-memory representations of +.B Elf_Type +are assumed to be the same. See +.BR libelf (3) +for more information regarding +.BR Elf_Type . + +.SH PARAMETERS +.TP +.I type +The ELF data structure type for which the file size is to be calculated. + +.TP +.I count +The number of elements of the specified type. + +.TP +.I version +The ELF version. This should be set to +.BR EV_CURRENT , +which is the only valid value. + +.SH RETURN VALUE +The size in bytes of the specified count and type of data structure. +If version is not set to +.B EV_CURRENT +or +.I type +is not a valid +.BR Elf_Type , +return 0 and set a libelf error code. Integer overflow can occur if +the size of +.I type +multiplied by +.I count +is greater than +.BR SIZE_MAX . + +.SH SEE ALSO +.BR elf_errno (3), +.BR libelf (3), +.BR elf (5) + +.SH ATTRIBUTES +For an explanation of the terms used in this section, see +.BR attributes (7). +.TS +allbox; +lbx lb lb +l l l. +Interface Attribute Value +T{ +.na +.nh +.BR elf32_fsize (), +.BR elf64_fsize () +T} Thread safety MT-Safe +.TE + +.SH REPORTING BUGS +Report bugs to or https://sourceware.org/bugzilla/. diff --git a/doc/elf64_fsize.3 b/doc/elf64_fsize.3 new file mode 100644 index 00000000..178152ec --- /dev/null +++ b/doc/elf64_fsize.3 @@ -0,0 +1 @@ +.so man3/elf32_fsize.3