]> sourceware.org Git - glibc.git/commitdiff
hurd: make open and openat cancellation points
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Sun, 28 Jun 2020 14:27:36 +0000 (14:27 +0000)
committerSamuel Thibault <samuel.thibault@ens-lyon.org>
Sun, 28 Jun 2020 15:11:23 +0000 (15:11 +0000)
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.

sysdeps/mach/hurd/Makefile
sysdeps/mach/hurd/Versions
sysdeps/mach/hurd/dl-sysdep.c
sysdeps/mach/hurd/i386/localplt.data
sysdeps/mach/hurd/not-cancel.h
sysdeps/mach/hurd/open.c
sysdeps/mach/hurd/open_nocancel.c [new file with mode: 0644]
sysdeps/mach/hurd/openat.c
sysdeps/mach/hurd/openat_nocancel.c [new file with mode: 0644]

index edab284d119d8c2c67d956dff0064258bf8ce177..a58e8c1c3d53ee15be63393879d7e43e6224e4a0 100644 (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
 
index e8b4aba7763cfd587dd586d6ccbdddad70401bbd..67594d8c085441a32ef62b2d4b0a842a6d5b3e08 100644 (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;
index a4eab4c08efce8e04bae33a7f64e9ffa0c847769..8a87b9b0f2b047e6d166d1e7333321504debba79 100644 (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
index 66478dee7ac44a11930b753edb1e003696e8864a..66e9c4f253a7be6e212d6f48d92769f7187ab23e 100644 (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
index 202dca8792b2222c48787e3a94af0017c215f99d..c627ec7bde2e3555fa4e5d7745c0e6594ef5deb0 100644 (file)
 #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)
index ec74a83b0fd8584e18ad040820edc5e041f5bbf1..c2c4e284c2293f44a468fbd314a0e72643d7a239 100644 (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;
 
diff --git a/sysdeps/mach/hurd/open_nocancel.c b/sysdeps/mach/hurd/open_nocancel.c
new file mode 100644 (file)
index 0000000..e180c25
--- /dev/null
@@ -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)
index 7e241cd36fe9716951cd47177593ff4fa080501a..5842da05d7f9b013fbea6d69f226fa221bab8f6f 100644 (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;
 
diff --git a/sysdeps/mach/hurd/openat_nocancel.c b/sysdeps/mach/hurd/openat_nocancel.c
new file mode 100644 (file)
index 0000000..b6af799
--- /dev/null
@@ -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)
This page took 0.058618 seconds and 5 git commands to generate.