From patchwork Sat Mar 18 16:51:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: stsp X-Patchwork-Id: 66571 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 ECDDE383F42D for ; Sat, 18 Mar 2023 16:53:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ECDDE383F42D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1679158436; 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=PNzsjqWAdtQqV8sXKFqXFd62pLn5NNbirO8H2UjsvgjarTlp86pCUzTEL9pTxKasg 3IiHjhLBtRjL9paNkcwnZn7EDY4MPaU6qimncPNNiBRJe16vk7ANHzV+s0nHMCm6kD 14v4sJDIdgOD7lXZEtpi3pb5TDipbqzvjhFdXxKg= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org 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 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 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 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 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+patchwork=sourceware.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);