From patchwork Fri Mar 17 06:32:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: stsp X-Patchwork-Id: 1758091 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=qyyi9Pq4; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PdDsq2jdlz1yWp for ; Fri, 17 Mar 2023 17:35:59 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4A180385084C for ; Fri, 17 Mar 2023 06:35:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4A180385084C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1679034957; bh=I3lil+P8BERQZAw+AWZTS8jwax51srh5PnbNToh9PcE=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=qyyi9Pq4o2sFC/dEAmnJEbVYwoHj2un2X7oClXTdGZq9Bv8y3uQl5D/5zLDdXIGck EN7c2HU4AH6P9mOpUtE6KMHM7CrSts/3U714Ri8fQUhFglTleMQ+gFEQCGnfA1yXHS oqj4MGXZP2mtkw0uJoyAyLuuRO38bMo0aKbe6Slo= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from forward107p.mail.yandex.net (forward107p.mail.yandex.net [77.88.28.115]) by sourceware.org (Postfix) with ESMTPS id EA72B3848432 for ; Fri, 17 Mar 2023 06:34:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EA72B3848432 Received: from sas9-2d24a7e69f58.qloud-c.yandex.net (sas9-2d24a7e69f58.qloud-c.yandex.net [IPv6:2a02:6b8:c11:2298:0:640:2d24:a7e6]) by forward107p.mail.yandex.net (Yandex) with ESMTP id 909505574FE5 for ; Fri, 17 Mar 2023 09:32:34 +0300 (MSK) Received: by sas9-2d24a7e69f58.qloud-c.yandex.net (smtp/Yandex) with ESMTPSA id QWeJF9abi0U1-jdLVZ07v; Fri, 17 Mar 2023 09:32:34 +0300 X-Yandex-Fwd: 1 To: libc-alpha@sourceware.org Cc: Stas Sergeev Subject: [PATCH 07/11] elf: convert pread64 to callback in do_open_verify() Date: Fri, 17 Mar 2023 11:32:06 +0500 Message-Id: <20230317063210.4118076-8-stsp2@yandex.ru> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230317063210.4118076-1-stsp2@yandex.ru> References: <20230317063210.4118076-1-stsp2@yandex.ru> MIME-Version: 1.0 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, 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: 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: Stas Sergeev via Libc-alpha From: stsp Reply-To: Stas Sergeev Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" This unbinds do_open_verify() from fd. The test-suite was run on x86_64/64 and showed no regressions. Signed-off-by: Stas Sergeev --- elf/dl-load.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/elf/dl-load.c b/elf/dl-load.c index 45656d8fa5..67e4933735 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -1613,10 +1613,18 @@ print_search_path (struct r_search_path_elem **list, _dl_debug_printf_c ("\t\t(%s)\n", what); } +static ssize_t +do_pread (void *arg, void *buf, size_t count, off_t offset) +{ + int fd = *(const int *) arg; + return __pread64_nocancel (fd, buf, count, offset); +} + static int -do_open_verify (const char *name, int fd, +do_open_verify (const char *name, void *fd, struct filebuf *fbp, struct link_map *loader, - bool *found_other_class, bool free_name) + bool *found_other_class, bool free_name, + __typeof (do_pread) *pread_cb) { /* This is the expected ELF header. */ #define ELF32_CLASS ELFCLASS32 @@ -1652,7 +1660,7 @@ do_open_verify (const char *name, int fd, we can use. */ __set_errno (0); /* Read in the header. */ - if (__pread64_nocancel (fd, &_ehdr, sizeof(_ehdr), 0) != sizeof(_ehdr)) + if (pread_cb (fd, &_ehdr, sizeof(_ehdr), 0) != sizeof(_ehdr)) { errval = errno; errstring = (errval == 0 @@ -1754,7 +1762,7 @@ do_open_verify (const char *name, int fd, maplength = ehdr->e_phnum * sizeof (ElfW(Phdr)); filebuf_ensure (fbp, maplength + ehdr->e_phoff); - if ((size_t) __pread64_nocancel (fd, fbp->buf, maplength + + if ((size_t) pread_cb (fd, fbp->buf, maplength + ehdr->e_phoff, 0) != maplength + ehdr->e_phoff) { @@ -1815,9 +1823,9 @@ open_verify (const char *name, int fd, if (fd != -1) { - int err = do_open_verify (name, fd, fbp, loader, + int err = do_open_verify (name, &fd, fbp, loader, found_other_class, - free_name); + free_name, do_pread); if (err) { __close_nocancel (fd);