From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from forward101o.mail.yandex.net (forward101o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::601]) by sourceware.org (Postfix) with ESMTPS id 409E63850220 for ; Sat, 18 Mar 2023 16:51:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 409E63850220 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=yandex.ru Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=yandex.ru Received: from myt6-1289f562e823.qloud-c.yandex.net (myt6-1289f562e823.qloud-c.yandex.net [IPv6:2a02:6b8:c12:259d:0:640:1289:f562]) by forward101o.mail.yandex.net (Yandex) with ESMTP id 09184369C4AC for ; Sat, 18 Mar 2023 19:51:52 +0300 (MSK) Received: by myt6-1289f562e823.qloud-c.yandex.net (smtp/Yandex) with ESMTPSA id cpp3fcrbC8c1-AFoVFqGf; Sat, 18 Mar 2023 19:51:51 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1679158311; bh=I3lil+P8BERQZAw+AWZTS8jwax51srh5PnbNToh9PcE=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=jzXLMM7RgVeYDUXzLI7u3kBGl8xhXAGZoz4y8RrC5t1WR385NEEAs3LpyfHktUSOB aYuCwdgVYOd3LzGxRRL3DlIEU/05vbNSwY5Sx9EnbN7GnXXHRBU0tgYVAj3qzsSS3N H49A4BUuq8NcKXAFQuulm5IfNxAj672IGnZupFqg= Authentication-Results: myt6-1289f562e823.qloud-c.yandex.net; dkim=pass header.i=@yandex.ru From: Stas Sergeev To: libc-alpha@sourceware.org Cc: Stas Sergeev Subject: [PATCH 07/13] elf: convert pread64 to callback in do_open_verify() Date: Sat, 18 Mar 2023 21:51:04 +0500 Message-Id: <20230318165110.3672749-8-stsp2@yandex.ru> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230318165110.3672749-1-stsp2@yandex.ru> References: <20230318165110.3672749-1-stsp2@yandex.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.6 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 List-Id: 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); -- 2.37.2