hurd: make open and openat cancellation points

and add _nocancel variants.

* sysdeps/mach/hurd/Makefile [io] (sysdep_routines): Add open_nocancel
openat_nocancel.
* sysdeps/mach/hurd/Versions (libc.GLIBC_PRIVATE, ld.GLIBC_PRIVATE): Add
__open_nocancel.
* sysdeps/mach/hurd/dl-sysdep.c (__open_nocancel): Add alias, check it
is not hidden.
* sysdeps/mach/hurd/i386/localplt.data (__open_nocancel): Allow PLT.
* sysdeps/mach/hurd/not-cancel.h (__open_nocancel, __openat_nocancel:
Replace macros with declarations with hidden proto.
(__open64_nocancel, __openat64_nocancel): Call __open_nocancel and
__openat_nocancel instead of __open64 and __openat64.
* sysdeps/mach/hurd/open.c: Include <sysdep-cancel.h>
(__libc_open): Surround __file_name_lookup with enabling async cancel.
* sysdeps/mach/hurd/openat.c: Likewise.
* sysdeps/mach/hurd/open_nocancel.c,
sysdeps/mach/hurd/openat_nocancel.c: New files.
This commit is contained in:
Samuel Thibault 2020-06-28 14:27:36 +00:00
parent 67a78072e2
commit 4cafcd839f
9 changed files with 138 additions and 10 deletions

View file

@ -196,7 +196,8 @@ sysdep_routines += cthreads
endif
ifeq (io, $(subdir))
sysdep_routines += f_setlk close_nocancel_nostatus read_nocancel \
sysdep_routines += f_setlk close_nocancel_nostatus \
open_nocancel openat_nocancel read_nocancel \
pread64_nocancel write_nocancel pwrite64_nocancel
endif

View file

@ -13,6 +13,7 @@ libc {
GLIBC_PRIVATE {
# Functions shared with the dynamic linker
__access; __access_noerrno; __libc_read; __libc_write; __libc_lseek64;
__open_nocancel;
__read_nocancel; __pread64_nocancel;
__write_nocancel;
__libc_lock_self0; __getcwd;
@ -54,6 +55,7 @@ ld {
# functions that must be shared with libc
__access; __access_noerrno; __libc_read; __libc_write; __libc_lseek64;
__open_nocancel;
__read_nocancel; __pread64_nocancel;
__write_nocancel;
__libc_lock_self0; __getcwd;

View file

@ -338,6 +338,7 @@ open_file (const char *file_name, int flags,
check_no_hidden(__open);
check_no_hidden (__open64);
check_no_hidden (__open_nocancel);
int weak_function
__open (const char *file_name, int mode, ...)
{
@ -349,6 +350,7 @@ __open (const char *file_name, int mode, ...)
return (int)port;
}
weak_alias (__open, __open64)
weak_alias (__open, __open_nocancel)
check_no_hidden(__close);
int weak_function

View file

@ -17,7 +17,8 @@ ld.so: _dl_catch_exception + REL R_386_GLOB_DAT
# The dynamic linker has its own versions of basic functions for initial loading
# of shared libraries. These need to be overriden by libc once loaded.
ld.so: __open ?
ld.so: __open64
ld.so: __open64 ?
ld.so: __open_nocancel
ld.so: __close
ld.so: __read ?
ld.so: __read_nocancel

View file

@ -29,19 +29,23 @@
#include <hurd/fd.h>
/* For now we have none. Map the name to the normal functions. */
#define __open_nocancel(...) \
__open (__VA_ARGS__)
#define __open64_nocancel(...) \
__open64 (__VA_ARGS__)
#define __openat_nocancel(...) \
__openat (__VA_ARGS__)
#define __openat64_nocancel(...) \
__openat64 (__VA_ARGS__)
#define __close_nocancel(fd) \
__close (fd)
void __close_nocancel_nostatus (int fd);
/* Non cancellable open syscall. */
__typeof (__open) __open_nocancel;
/* open64 is just the same as open for us. */
#define __open64_nocancel(...) \
__open_nocancel (__VA_ARGS__)
/* Non cancellable openat syscall. */
__typeof (__openat) __openat_nocancel;
/* open64 is just the same as open for us. */
#define __openat64_nocancel(...) \
__openat_nocancel (__VA_ARGS__)
/* Non cancellable read syscall. */
__typeof (__read) __read_nocancel;
@ -66,6 +70,8 @@ void __writev_nocancel_nostatus (int fd, const struct iovec *vector, int count);
__fcntl64 (fd, cmd, __VA_ARGS__)
#if IS_IN (libc)
hidden_proto (__open_nocancel)
hidden_proto (__openat_nocancel)
hidden_proto (__read_nocancel)
hidden_proto (__pread64_nocancel)
hidden_proto (__write_nocancel)

View file

@ -21,6 +21,7 @@
#include <stdio.h>
#include <hurd.h>
#include <hurd/fd.h>
#include <sysdep-cancel.h>
/* Open FILE with access OFLAG. If O_CREAT or O_TMPFILE is in OFLAG,
a third argument is the file protection. */
@ -29,6 +30,7 @@ __libc_open (const char *file, int oflag, ...)
{
mode_t mode;
io_t port;
int cancel_oldtype;
if (__OPEN_NEEDS_MODE (oflag))
{
@ -40,7 +42,10 @@ __libc_open (const char *file, int oflag, ...)
else
mode = 0;
cancel_oldtype = LIBC_CANCEL_ASYNC();
port = __file_name_lookup (file, oflag, mode);
LIBC_CANCEL_RESET (cancel_oldtype);
if (port == MACH_PORT_NULL)
return -1;

View file

@ -0,0 +1,51 @@
/* Copyright (C) 1992-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 <fcntl.h>
#include <stdarg.h>
#include <stdio.h>
#include <hurd.h>
#include <hurd/fd.h>
#include <not-cancel.h>
/* Open FILE with access OFLAG. If O_CREAT or O_TMPFILE is in OFLAG,
a third argument is the file protection. */
int
__open_nocancel (const char *file, int oflag, ...)
{
mode_t mode;
io_t port;
if (__OPEN_NEEDS_MODE (oflag))
{
va_list arg;
va_start (arg, oflag);
mode = va_arg (arg, mode_t);
va_end (arg);
}
else
mode = 0;
port = __file_name_lookup (file, oflag, mode);
if (port == MACH_PORT_NULL)
return -1;
return _hurd_intern_fd (port, oflag, 1);
}
libc_hidden_def (__open_nocancel)

View file

@ -24,6 +24,7 @@
#include <sys/stat.h>
#include <hurd.h>
#include <hurd/fd.h>
#include <sysdep-cancel.h>
/* Open FILE with access OFLAG. Interpret relative paths relative to
the directory associated with FD. If O_CREAT or O_TMPFILE is in OFLAG, a
@ -33,6 +34,7 @@ __openat (int fd, const char *file, int oflag, ...)
{
mode_t mode;
io_t port;
int cancel_oldtype;
if (__OPEN_NEEDS_MODE (oflag))
{
@ -44,7 +46,10 @@ __openat (int fd, const char *file, int oflag, ...)
else
mode = 0;
cancel_oldtype = LIBC_CANCEL_ASYNC();
port = __file_name_lookup_at (fd, 0, file, oflag, mode);
LIBC_CANCEL_RESET (cancel_oldtype);
if (port == MACH_PORT_NULL)
return -1;

View file

@ -0,0 +1,55 @@
/* openat -- Open a file named relative to an open directory. Hurd version.
Copyright (C) 2006-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 <fcntl.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <sys/stat.h>
#include <hurd.h>
#include <hurd/fd.h>
#include <not-cancel.h>
/* Open FILE with access OFLAG. Interpret relative paths relative to
the directory associated with FD. If O_CREAT or O_TMPFILE is in OFLAG, a
third argument is the file protection. */
int
__openat_nocancel (int fd, const char *file, int oflag, ...)
{
mode_t mode;
io_t port;
if (__OPEN_NEEDS_MODE (oflag))
{
va_list arg;
va_start (arg, oflag);
mode = va_arg (arg, mode_t);
va_end (arg);
}
else
mode = 0;
port = __file_name_lookup_at (fd, 0, file, oflag, mode);
if (port == MACH_PORT_NULL)
return -1;
return _hurd_intern_fd (port, oflag, 1);
}
libc_hidden_def (__openat_nocancel)