From patchwork Mon Aug 5 21:54:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leandro Pereira X-Patchwork-Id: 1142486 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-104180-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=reject dis=none) header.from=microsoft.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="qY/qtYim"; dkim=pass (1024-bit key; unprotected) header.d=microsoft.com header.i=@microsoft.com header.b="Ae+cig6Z"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 462Wl24l1Xz9sNF for ; Tue, 6 Aug 2019 07:54:37 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:content-type :content-transfer-encoding:mime-version; q=dns; s=default; b=Og4 TFwPRKF/7KLz3FUd78s8iCiuwvKwUElxTIJPE0kfAJ80B5eh7ZMoYvjVWEEjXcC1 IWlf0Azl02Avg0Q8PgloGQ/qmsFt3oRSUhZLWyKQoKwF0DBuT1CoMPpQR72V3bsM 7qE6zZOaX4hoO/cJjPpSZXEcCmLD03oMxS6qMHsk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:content-type :content-transfer-encoding:mime-version; s=default; bh=v8+HH6dkO sAIsmi6jJy6GvHspRk=; b=qY/qtYimXmeN+jl2JYOSxQp7ol8U53FjYXpel7hcX CdH247wBWyzuXxcByQnkCfuHuIOBtW3WfyD0aB5hOX7/USYGBXKiJBjm4zV0liXw +5jUxceOaJZysI9Gqs6+rvpIGrMEgEMVX1yDHC6DIE+J00uLWGjmbVzzOucUcF9S d4= Received: (qmail 113136 invoked by alias); 5 Aug 2019 21:54:32 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 113116 invoked by uid 89); 5 Aug 2019 21:54:32 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: NAM01-BN3-obe.outbound.protection.outlook.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jYEvcZ+JiSCV2SfVKtstrvZ36ia2UOr9gY7Ko0s+qBt9lyvsvdAq8ej49tPXqPb3pzbPC/OS++N8y/+/V4GnjNFCu01f2xgDlUN9TL9MuOqUD0hJSukpp0BVle3fhyu8wDiI+Ea341iu6FVW7pGoOJzlcpxpV7rGCbtNgc6hvUqFBC5lXl88I4CIDBcW3l39MtNjyFjgylYnFBsg7b0+jFjnKqnqFW5F8dhyEoyHI5lwh7z9fY8kJLUyZkT9an8fKZIt+klZS9z13cz2ihnyub1TCJASnwTlqPbrX62qY9fG/VQi4afafh4xaKJ2dFJOebG6Vlfv2n6K7I8OnwSZSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=N0WPeRdd5EVx3dWk1MqVlP/Jl+ALvaqTOSyCuQUfkmE=; b=HprfTnD4UqWCGKQLaM50N+CQ/dPL7HW4sqciVxCWbViYAJzFudNAmzynyKcjikjnTMgqXsQ6GQNqPXRdFs/wkbSb0ZcFVxcXPikZJZofq0yZu9C6P5mF5B9U2wGXrlCJZw8RupNKui5iGgMukPVTmb+iZMcad+BRJLn6L6cZRZl7e0+yugMh4tLgiEKBh/CHQnhSz5CBrWCQXCoYvX9j8nf21oWJLgScXwcvvP3Jj7MzCeeybpNztemL+4H3y7iahkeoAnBslZY43dtRwrP7gfTAhGr0CTM5YmO2J2et6GJJxJMjSZocegcfxn6rJIHe9VKB5WGUBMS3K43B9BQPoA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=N0WPeRdd5EVx3dWk1MqVlP/Jl+ALvaqTOSyCuQUfkmE=; b=Ae+cig6ZvWCwOUO2ib4EpvVGK1mbIsLOJi8vyZGwBULkXfENMCm/b54ccLQcxOjZlS+dyPMvVTSMOfyxePeLBWaXW+rdZDQxjmbwhFAprNAboayEqv4fpAtfpvuW0CR5YdKRYLm1z0MK7sj56fv+GaJthGtOJBKj9WWY3sVPdDE= From: Leandro Pereira To: "libc-alpha@sourceware.org" Subject: [PATCH 1/2] Add nocancel version of pread64() Date: Mon, 5 Aug 2019 21:54:26 +0000 Message-ID: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Leandro.Pereira@microsoft.com; x-ms-exchange-purlcount: 1 x-ms-oob-tlc-oobclassifiers: OLM:8882; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-ms-exchange-transport-forked: True MIME-Version: 1.0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: NVjJgGt3XLyAWth/EK0hEUJEXcbNZeRRwkQxAnOY1GTGF55JSoTcD6IDMmcn05nUKchTM5ieBwX0SEXUNpmGPQ== This is in preparation for changes in the dynamic linker so that pread() is used instead of lseek()+read(). 2019-08-05 Leandro Pereira * sysdeps/generic/not-cancel.h: New macro. * sysdeps/unix/sysv/linux/not-cancel.h: New macro. * sysdeps/unix/sysv/linux/pread64_nocancel.c: Implement nocancel version of pread64. * sysdeps/unix/sysv/linux/Versions (GLIBC_PRIVATE): Add __pread64_nocancel. * sysdeps/unix/sysv/linux/Makefile: Reference pread64_nocancel.c. Reviewed-by: Carlos O'Donell --- sysdeps/generic/not-cancel.h | 2 ++ sysdeps/unix/sysv/linux/Makefile | 4 +-- sysdeps/unix/sysv/linux/Versions | 1 + sysdeps/unix/sysv/linux/not-cancel.h | 4 +++ sysdeps/unix/sysv/linux/pread64_nocancel.c | 32 ++++++++++++++++++++++ 5 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 sysdeps/unix/sysv/linux/pread64_nocancel.c diff --git a/sysdeps/generic/not-cancel.h b/sysdeps/generic/not-cancel.h index f3d862651e..724c3e5e71 100644 --- a/sysdeps/generic/not-cancel.h +++ b/sysdeps/generic/not-cancel.h @@ -41,6 +41,8 @@ (void) __close (fd) #define __read_nocancel(fd, buf, n) \ __read (fd, buf, n) +#define __pread64_nocancel(fd, buf, count, offset) \ + __pread64 (fd, buf, count, offset) #define __write_nocancel(fd, buf, n) \ __write (fd, buf, n) #define __writev_nocancel_nostatus(fd, iov, n) \ diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 1ab6bcbfc8..a7980a60f6 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -212,8 +212,8 @@ sysdep_routines += xstatconv internal_statvfs internal_statvfs64 \ close_nocancel fcntl_nocancel nanosleep_nocancel \ open_nocancel open64_nocancel \ openat_nocancel openat64_nocancel \ - pause_nocancel read_nocancel waitpid_nocancel \ - write_nocancel statx_cp + pause_nocancel read_nocancel pread64_nocancel \ + waitpid_nocancel write_nocancel statx_cp sysdep_headers += bits/fcntl-linux.h diff --git a/sysdeps/unix/sysv/linux/Versions b/sysdeps/unix/sysv/linux/Versions index 1ca102a9e2..d385085c61 100644 --- a/sysdeps/unix/sysv/linux/Versions +++ b/sysdeps/unix/sysv/linux/Versions @@ -182,6 +182,7 @@ libc { __syscall_rt_sigqueueinfo; __open_nocancel; __read_nocancel; + __pread64_nocancel; __close_nocancel; __sigtimedwait; # functions used by nscd diff --git a/sysdeps/unix/sysv/linux/not-cancel.h b/sysdeps/unix/sysv/linux/not-cancel.h index 16cc31cba5..bf7d80125a 100644 --- a/sysdeps/unix/sysv/linux/not-cancel.h +++ b/sysdeps/unix/sysv/linux/not-cancel.h @@ -43,6 +43,9 @@ __typeof (openat64) __openat64_nocancel; /* Non cancellable read syscall. */ __typeof (__read) __read_nocancel; +/* Non cancellable pread syscall (LFS version). */ +__typeof (__pread64) __pread64_nocancel; + /* Uncancelable write. */ __typeof (__write) __write_nocancel; @@ -84,6 +87,7 @@ hidden_proto (__open64_nocancel) hidden_proto (__openat_nocancel) hidden_proto (__openat64_nocancel) hidden_proto (__read_nocancel) +hidden_proto (__pread64_nocancel) hidden_proto (__write_nocancel) hidden_proto (__close_nocancel) hidden_proto (__waitpid_nocancel) diff --git a/sysdeps/unix/sysv/linux/pread64_nocancel.c b/sysdeps/unix/sysv/linux/pread64_nocancel.c new file mode 100644 index 0000000000..dab61260e5 --- /dev/null +++ b/sysdeps/unix/sysv/linux/pread64_nocancel.c @@ -0,0 +1,32 @@ +/* Linux pread64() syscall implementation -- non-cancellable. + Copyright (C) 2019 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include + +#ifndef __NR_pread64 +# define __NR_pread64 __NR_pread +#endif + +ssize_t +__pread64_nocancel (int fd, void *buf, size_t count, off64_t offset) +{ + return INLINE_SYSCALL_CALL (pread64, fd, buf, count, SYSCALL_LL64_PRW (offset)); +} +hidden_def (__pread64_nocancel) From patchwork Mon Aug 5 21:56:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leandro Pereira X-Patchwork-Id: 1142487 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-104181-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=reject dis=none) header.from=microsoft.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="vnuclC0F"; dkim=pass (1024-bit key; unprotected) header.d=microsoft.com header.i=@microsoft.com header.b="V1MWsELW"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 462Wmr51DQz9sN4 for ; Tue, 6 Aug 2019 07:56:12 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:content-type :content-transfer-encoding:mime-version; q=dns; s=default; b=uTo PSf0D6JtpDZC+PtZWcwLpyEswzyNKowhNx3PrWG2dbYl9JyMxCnXBvN64HBX7uZg dpqcufcf5O5dTXJlPzEZzXq0H7O4LZHb781Hc2wBH6IGRA5eaWLfLUndL0qsAnxa ElyyOauVgDGEoSZNyMQCvYd6uzWqvyYCaeRcn9pY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:content-type :content-transfer-encoding:mime-version; s=default; bh=QW8mrIbOF JQBJ+2yOvYhNz3hURI=; b=vnuclC0F42EdevZ3ru1346oyY22u0FQFrBvkWZ84r lfDLZtWQtpUfVYTOOkfDekKJajVXQTs4Qkih8iZckeFJdUBKq4rJtBsXUVe4pAck TZZF6Obh5ytg5LxiIS++FZlrOVaFp9dVo5aFU8em0Y3tfgpQsDkknHczjl4BWAVx u4= Received: (qmail 116178 invoked by alias); 5 Aug 2019 21:56:07 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 116170 invoked by uid 89); 5 Aug 2019 21:56:06 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: NAM03-CO1-obe.outbound.protection.outlook.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PB8XqFtIEnfz3IGxgEQplhQrmpWHtIWLBwWp9dl5ezSMEU2luKboWzF7Z8CX7L8XOk3fNrjJily1bKM+szL82ilzNegxY1JVN4vWdGVwXQTjTnCu4Vtth49pUEIVpXaayCSSZ7dCB49uGmEHma9cbYBQtqs6HBBR7BKf8Okn+eSrxvclB7ZZ81Ld1KeskrzrBME/VnGR73hKPAVUk8LzpzUZYfcUwOJ2TPxrAOVrHYp+YcmzpSzNqJurBfXAjb9TSMnxjTza33sjubenyARP/GO1e+P0kAdxC0ciBkhhRXg2E4IbE2pVU7FEz+lkqFiRN01xmwhFak8xJciKClV11w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=O22ROZjOWstbdLYaavw746AHHNmkFgkxnmdWlj5ha14=; b=FEZNK+c5PFsOTGooWKfrrr95gWdvLZXGQwKSWkvb2PWnFIsWMLqqrC/CAYbj9DCZFa+FjCPtpiTEdfCm3Zo22aV6JaG5lGv0gCyR1YphywTS3CbgQRsfNYjS9V2Y1U8Teso7FJP9vvWnAC7kBz9E8emgkk8aKkfCUZgf9JV+aqo5vlnK6KuykVyGaAbNFA0x7FCiVuixREvCeOUJw5wylB2XeApnex7ZnP6t8WHDETpfdIGDVewm2wgOIaCKKNek28XUsNCwYeHBVjgTrfAg72bYcaXyAXnZ+r97gQ9LObkxefKf18rrkfI+sf05C6nuAOHwgft4wp8subP89rzyug== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=O22ROZjOWstbdLYaavw746AHHNmkFgkxnmdWlj5ha14=; b=V1MWsELWzmvapcO6mfGdlu5KEd4ZizRwmIs++xIhOYyTlOiEa0xDCvL7aavQsEkrrE9q7kAGes6+j2vKUvyebqmO3BP5MULlgFZlJXWVkYxW9RiZ0Xx6p375jtlyWWqphZVveGaG5DCiiTg0S/nJabIlgelH2wcFFD4m3RLBWbY= From: Leandro Pereira To: "libc-alpha@sourceware.org" Subject: [PATCH 2/2] elf: Use nocancel pread64() instead of lseek()+read() Date: Mon, 5 Aug 2019 21:56:03 +0000 Message-ID: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Leandro.Pereira@microsoft.com; x-ms-oob-tlc-oobclassifiers: OLM:1443; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-ms-exchange-transport-forked: True MIME-Version: 1.0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: Emgg1wxuqW20iy/11si/edqDRb9TjAMPZ3tUmXZ1JITQI89E8f/7hBegPL3aYKRjxUwBho+Nfg490hIrfXA6YQ== Transforms this, when linking in a shared object: openat(AT_FDCWD, "/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 3 read(3, "\177ELF\2\1\1\3"..., 832) = 832 lseek(3, 792, SEEK_SET) = 792 read(3, "\4\0\0\0\24\0\0\0"..., 68) = 68 fstat(3, {st_mode=S_IFREG|0755, st_size=6699224, ...}) = 0 lseek(3, 792, SEEK_SET) = 792 read(3, "\4\0\0\0\24\0\0\0"..., 68) = 68 lseek(3, 864, SEEK_SET) = 864 read(3, "\4\0\0\0\20\0\0\0"..., 32) = 32 Into this: openat(AT_FDCWD, "/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 3 read(3, "\177ELF\2\1\1\3"..., 832) = 832 pread(3, "\4\0\0\0\24\0\0\0"..., 68, 792) = 68 fstat(3, {st_mode=S_IFREG|0755, st_size=6699224, ...}) = 0 pread(3, "\4\0\0\0\24\0\0\0"..., 68, 792) = 68 pread(3, "\4\0\0\0\20\0\0\0"..., 32, 864) = 32 2019-08-05 Leandro Pereira * elf/dl-load.c: Use __pread64_nocancel() instead of __lseek()+ __read_nocancel(). * sysdeps/x86/dl-prop.h: Likewise. Reviewed-by: Carlos O'Donell --- elf/dl-load.c | 9 +++------ sysdeps/x86/dl-prop.h | 3 +-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/elf/dl-load.c b/elf/dl-load.c index 5abeb867f1..462c425a13 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -1005,8 +1005,7 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd, else { phdr = alloca (maplength); - __lseek (fd, header->e_phoff, SEEK_SET); - if ((size_t) __read_nocancel (fd, (void *) phdr, maplength) != maplength) + if ((size_t) __pread64_nocancel (fd, (void *) phdr, maplength, header->e_phoff) != maplength) { errstring = N_("cannot read file data"); goto call_lose_errno; @@ -1659,8 +1658,7 @@ open_verify (const char *name, int fd, else { phdr = alloca (maplength); - __lseek (fd, ehdr->e_phoff, SEEK_SET); - if ((size_t) __read_nocancel (fd, (void *) phdr, maplength) + if ((size_t) __pread64_nocancel (fd, (void *) phdr, maplength, ehdr->e_phoff) != maplength) { read_error: @@ -1710,8 +1708,7 @@ open_verify (const char *name, int fd, abi_note = abi_note_malloced; } - __lseek (fd, ph->p_offset, SEEK_SET); - if (__read_nocancel (fd, (void *) abi_note, size) != size) + if (__pread64_nocancel (fd, (void *) abi_note, size, ph->p_offset) != size) { free (abi_note_malloced); goto read_error; diff --git a/sysdeps/x86/dl-prop.h b/sysdeps/x86/dl-prop.h index 1b335ccbb3..080d66a971 100644 --- a/sysdeps/x86/dl-prop.h +++ b/sysdeps/x86/dl-prop.h @@ -167,8 +167,7 @@ _dl_process_pt_note (struct link_map *l, const ElfW(Phdr) *ph, note_malloced = malloc (size); note = note_malloced; } - __lseek (fd, ph->p_offset, SEEK_SET); - if (__read_nocancel (fd, (void *) note, size) != size) + if (__pread64_nocancel (fd, (void *) note, size, ph->p_offset) != size) { if (note_malloced) free (note_malloced);