hurd: Make write and pwrite64 cancellation points

and add _nocancel variants.

* sysdeps/mach/hurd/write.c (__libc_write): Call __write_nocancel
surrounded by enabling async cancel, to replace implementation moved
to...
* sysdeps/mach/hurd/write_nocancel.c (__write_nocancel): ... here.
* sysdeps/mach/hurd/pwrite64.c (__libc_pwrite64): Call
__pwrite64_nocancel surrounded by enabling async cancel, to replace
implementation moved to...
* sysdeps/mach/hurd/pwrite64_nocancel.c (__pwrite64_nocancel): ... here.
* sysdeps/mach/hurd/Makefile (sysdep_routines): Add write_nocancel and
pwrite64_nocancel.
* sysdeps/mach/hurd/not-cancel.h (__write_nocancel,
__pwrite64_nocancel): Replace macros with prototypes with a hidden proto on
libc.

* sysdeps/mach/hurd/dl-sysdep.c (__write_nocancel): New alias, check
that it is not hidden.
* sysdeps/mach/hurd/Versions (libc.GLIBC_PRIVATE): Add __write_nocancel.
(ld.GLIBC_PRIVATE): Add __write_nocancel.
* sysdeps/mach/hurd/i386/localplt.data (__write_nocancel): Add
reference.
This commit is contained in:
Samuel Thibault 2020-06-14 15:50:44 +00:00
parent 76fe4ef4be
commit 662de0889a
9 changed files with 94 additions and 19 deletions

View file

@ -197,7 +197,7 @@ endif
ifeq (io, $(subdir))
sysdep_routines += f_setlk close_nocancel_nostatus read_nocancel \
pread64_nocancel
pread64_nocancel write_nocancel pwrite64_nocancel
endif
ifeq ($(subdir),sunrpc)

View file

@ -11,6 +11,7 @@ libc {
# Functions shared with the dynamic linker
__access; __access_noerrno; __libc_read; __libc_write; __libc_lseek64;
__read_nocancel; __pread64_nocancel;
__write_nocancel;
__libc_lock_self0; __getcwd;
_dl_init_first;
@ -51,6 +52,7 @@ ld {
# functions that must be shared with libc
__access; __access_noerrno; __libc_read; __libc_write; __libc_lseek64;
__read_nocancel; __pread64_nocancel;
__write_nocancel;
__libc_lock_self0; __getcwd;
}
}

View file

@ -396,6 +396,7 @@ libc_hidden_weak (__read)
weak_alias (__read, __read_nocancel)
check_no_hidden(__write);
check_no_hidden(__write_nocancel);
__ssize_t weak_function
__write (int fd, const void *buf, size_t nbytes)
{
@ -411,6 +412,7 @@ __write (int fd, const void *buf, size_t nbytes)
return nwrote;
}
libc_hidden_weak (__write)
weak_alias (__write, __write_nocancel)
/* This is only used for printing messages (see dl-misc.c). */
check_no_hidden(__writev);

View file

@ -23,7 +23,8 @@ ld.so: __read ?
ld.so: __read_nocancel
ld.so: __pread64
ld.so: __pread64_nocancel
ld.so: __write
ld.so: __write ?
ld.so: __write_nocancel
ld.so: __writev
ld.so: __libc_lseek64
ld.so: __mmap

View file

@ -48,8 +48,12 @@ __typeof (__read) __read_nocancel;
/* Non cancellable pread syscall (LFS version). */
__typeof (__pread64) __pread64_nocancel;
#define __write_nocancel(fd, buf, n) \
__write (fd, buf, n)
/* Non cancellable write syscall. */
__typeof (__write) __write_nocancel;
/* Non cancellable pwrite syscall (LFS version). */
__typeof (__pwrite64) __pwrite64_nocancel;
#define __writev_nocancel_nostatus(fd, iov, n) \
(void) __writev (fd, iov, n)
# define __waitpid_nocancel(pid, stat_loc, options) \
@ -60,6 +64,8 @@ __typeof (__pread64) __pread64_nocancel;
#if IS_IN (libc)
hidden_proto (__read_nocancel)
hidden_proto (__pread64_nocancel)
hidden_proto (__write_nocancel)
hidden_proto (__pwrite64_nocancel)
hidden_proto (__close_nocancel_nostatus)
#endif

View file

@ -17,19 +17,17 @@
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
#include <errno.h>
#include <unistd.h>
#include <hurd/fd.h>
#include <sysdep-cancel.h>
#include <not-cancel.h>
ssize_t
__libc_pwrite64 (int fd, const void *buf, size_t nbytes, off64_t offset)
{
error_t err;
if (offset < 0)
err = EINVAL;
else
err = HURD_FD_USE (fd, _hurd_fd_write (descriptor, buf, &nbytes, offset));
return err ? __hurd_dfail (fd, err) : nbytes;
ssize_t ret;
int cancel_oldtype = LIBC_CANCEL_ASYNC();
ret = __pwrite64_nocancel (fd, buf, nbytes, offset);
LIBC_CANCEL_RESET (cancel_oldtype);
return ret;
}
#ifndef __libc_pwrite64

View file

@ -0,0 +1,35 @@
/* Write block to given position in file without changing file pointer.
Hurd version.
Copyright (C) 2001-2020 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
<https://www.gnu.org/licenses/>. */
#include <errno.h>
#include <unistd.h>
#include <hurd/fd.h>
#include <not-cancel.h>
ssize_t
__pwrite64_nocancel (int fd, const void *buf, size_t nbytes, off64_t offset)
{
error_t err;
if (offset < 0)
err = EINVAL;
else
err = HURD_FD_USE (fd, _hurd_fd_write (descriptor, buf, &nbytes, offset));
return err ? __hurd_dfail (fd, err) : nbytes;
}
libc_hidden_weak (__pwrite64_nocancel)

View file

@ -15,16 +15,17 @@
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
#include <errno.h>
#include <unistd.h>
#include <hurd/fd.h>
#include <sysdep-cancel.h>
#include <not-cancel.h>
ssize_t
__libc_write (int fd, const void *buf, size_t nbytes)
{
error_t err = HURD_FD_USE (fd, _hurd_fd_write (descriptor,
buf, &nbytes, -1));
return err ? __hurd_dfail (fd, err) : nbytes;
ssize_t ret;
int cancel_oldtype = LIBC_CANCEL_ASYNC();
ret = __write_nocancel (fd, buf, nbytes);
LIBC_CANCEL_RESET (cancel_oldtype);
return ret;
}
libc_hidden_def (__libc_write)
weak_alias (__libc_write, __write)

View file

@ -0,0 +1,30 @@
/* Copyright (C) 1991-2020 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
<https://www.gnu.org/licenses/>. */
#include <errno.h>
#include <unistd.h>
#include <hurd/fd.h>
#include <not-cancel.h>
ssize_t
__write_nocancel (int fd, const void *buf, size_t nbytes)
{
error_t err = HURD_FD_USE (fd, _hurd_fd_write (descriptor,
buf, &nbytes, -1));
return err ? __hurd_dfail (fd, err) : nbytes;
}
libc_hidden_weak (__write_nocancel)