diff mbox series

[hurd,commited] hurd: make close a cancellation point

Message ID 20200628164859.665385-1-samuel.thibault@ens-lyon.org
State New
Headers show
Series [hurd,commited] hurd: make close a cancellation point | expand

Commit Message

Samuel Thibault June 28, 2020, 4:48 p.m. UTC
and add _nocancel variant.

* sysdeps/mach/hurd/Makefile [io] (sysdep_routines): Add close_nocancel.
* sysdeps/mach/hurd/Versions (libc.GLIBC_PRIVATE, ld.GLIBC_PRIVATE): Add
__close_nocancel.
* sysdeps/mach/hurd/i386/localplt.data (__close_nocancel): Allow PLT.
* sysdeps/mach/hurd/close.c: Include <sysdep-cancel.h>
(__libc_close): Surround _hurd_fd_close with enabling async cancel.
* sysdeps/mach/hurd/close_nocancel.c: New file.
* sysdeps/mach/hurd/not-cancel.h (__close_nocancel): Replace macro with
declaration with hidden proto.
---
 sysdeps/mach/hurd/Makefile           |  2 +-
 sysdeps/mach/hurd/Versions           |  2 ++
 sysdeps/mach/hurd/close.c            |  4 ++++
 sysdeps/mach/hurd/close_nocancel.c   | 34 ++++++++++++++++++++++++++++
 sysdeps/mach/hurd/dl-sysdep.c        |  2 ++
 sysdeps/mach/hurd/i386/localplt.data |  3 ++-
 sysdeps/mach/hurd/not-cancel.h       |  9 ++++----
 7 files changed, 50 insertions(+), 6 deletions(-)
 create mode 100644 sysdeps/mach/hurd/close_nocancel.c
diff mbox series

Patch

diff --git a/sysdeps/mach/hurd/Makefile b/sysdeps/mach/hurd/Makefile
index a58e8c1c3d..4bfd290c09 100644
--- a/sysdeps/mach/hurd/Makefile
+++ b/sysdeps/mach/hurd/Makefile
@@ -196,7 +196,7 @@  sysdep_routines += cthreads
 endif
 
 ifeq (io, $(subdir))
-sysdep_routines += f_setlk close_nocancel_nostatus \
+sysdep_routines += f_setlk close_nocancel close_nocancel_nostatus \
 		   open_nocancel openat_nocancel read_nocancel \
 		   pread64_nocancel write_nocancel pwrite64_nocancel
 endif
diff --git a/sysdeps/mach/hurd/Versions b/sysdeps/mach/hurd/Versions
index 67594d8c08..c456f472c4 100644
--- a/sysdeps/mach/hurd/Versions
+++ b/sysdeps/mach/hurd/Versions
@@ -13,6 +13,7 @@  libc {
   GLIBC_PRIVATE {
     # Functions shared with the dynamic linker
     __access; __access_noerrno; __libc_read; __libc_write; __libc_lseek64;
+    __close_nocancel;
     __open_nocancel;
     __read_nocancel; __pread64_nocancel;
     __write_nocancel;
@@ -55,6 +56,7 @@  ld {
 
     # functions that must be shared with libc
     __access; __access_noerrno; __libc_read; __libc_write; __libc_lseek64;
+    __close_nocancel;
     __open_nocancel;
     __read_nocancel; __pread64_nocancel;
     __write_nocancel;
diff --git a/sysdeps/mach/hurd/close.c b/sysdeps/mach/hurd/close.c
index 4b1e203084..b461087447 100644
--- a/sysdeps/mach/hurd/close.c
+++ b/sysdeps/mach/hurd/close.c
@@ -19,14 +19,18 @@ 
 #include <unistd.h>
 #include <hurd.h>
 #include <hurd/fd.h>
+#include <sysdep-cancel.h>
 
 /* Close the file descriptor FD.  */
 int
 __close (int fd)
 {
   error_t err;
+  int cancel_oldtype;
 
+  cancel_oldtype = LIBC_CANCEL_ASYNC();
   err = HURD_FD_USE (fd, _hurd_fd_close (descriptor));
+  LIBC_CANCEL_RESET (cancel_oldtype);
 
   return err ? __hurd_fail (err) : 0;
 }
diff --git a/sysdeps/mach/hurd/close_nocancel.c b/sysdeps/mach/hurd/close_nocancel.c
new file mode 100644
index 0000000000..3411e321ab
--- /dev/null
+++ b/sysdeps/mach/hurd/close_nocancel.c
@@ -0,0 +1,34 @@ 
+/* 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.h>
+#include <hurd/fd.h>
+#include <not-cancel.h>
+
+/* Close the file descriptor FD.  */
+int
+__close_nocancel (int fd)
+{
+  error_t err;
+
+  err = HURD_FD_USE (fd, _hurd_fd_close (descriptor));
+
+  return err ? __hurd_fail (err) : 0;
+}
+libc_hidden_def (__close_nocancel)
diff --git a/sysdeps/mach/hurd/dl-sysdep.c b/sysdeps/mach/hurd/dl-sysdep.c
index 8a87b9b0f2..2a9a6d12bc 100644
--- a/sysdeps/mach/hurd/dl-sysdep.c
+++ b/sysdeps/mach/hurd/dl-sysdep.c
@@ -353,6 +353,7 @@  weak_alias (__open, __open64)
 weak_alias (__open, __open_nocancel)
 
 check_no_hidden(__close);
+check_no_hidden(__close_nocancel);
 int weak_function
 __close (int fd)
 {
@@ -360,6 +361,7 @@  __close (int fd)
     __mach_port_deallocate (__mach_task_self (), (mach_port_t) fd);
   return 0;
 }
+weak_alias (__close, __close_nocancel)
 
 check_no_hidden(__pread64);
 check_no_hidden(__pread64_nocancel);
diff --git a/sysdeps/mach/hurd/i386/localplt.data b/sysdeps/mach/hurd/i386/localplt.data
index 66e9c4f253..b199e14e7f 100644
--- a/sysdeps/mach/hurd/i386/localplt.data
+++ b/sysdeps/mach/hurd/i386/localplt.data
@@ -19,7 +19,8 @@  ld.so: _dl_catch_exception + REL R_386_GLOB_DAT
 ld.so: __open ?
 ld.so: __open64 ?
 ld.so: __open_nocancel
-ld.so: __close
+ld.so: __close ?
+ld.so: __close_nocancel
 ld.so: __read ?
 ld.so: __read_nocancel
 ld.so: __pread64
diff --git a/sysdeps/mach/hurd/not-cancel.h b/sysdeps/mach/hurd/not-cancel.h
index c627ec7bde..7e824c5f11 100644
--- a/sysdeps/mach/hurd/not-cancel.h
+++ b/sysdeps/mach/hurd/not-cancel.h
@@ -28,9 +28,8 @@ 
 #include <hurd.h>
 #include <hurd/fd.h>
 
-/* For now we have none.  Map the name to the normal functions.  */
-#define __close_nocancel(fd) \
-  __close (fd)
+/* Non cancellable close syscall.  */
+__typeof (__close) __close_nocancel;
 
 void __close_nocancel_nostatus (int fd);
 
@@ -64,12 +63,15 @@  __typeof (__writev) __writev_nocancel;
 /* Non cancellable writev syscall with no status.  */
 void __writev_nocancel_nostatus (int fd, const struct iovec *vector, int count);
 
+/* For now we have none.  Map the name to the normal functions.  */
 # define __waitpid_nocancel(pid, stat_loc, options) \
   __waitpid (pid, stat_loc, options)
 #define __fcntl64_nocancel(fd, cmd, ...) \
   __fcntl64 (fd, cmd, __VA_ARGS__)
 
 #if IS_IN (libc)
+hidden_proto (__close_nocancel)
+hidden_proto (__close_nocancel_nostatus)
 hidden_proto (__open_nocancel)
 hidden_proto (__openat_nocancel)
 hidden_proto (__read_nocancel)
@@ -78,7 +80,6 @@  hidden_proto (__write_nocancel)
 hidden_proto (__pwrite64_nocancel)
 hidden_proto (__writev_nocancel)
 hidden_proto (__writev_nocancel_nostatus)
-hidden_proto (__close_nocancel_nostatus)
 #endif
 
 #endif /* NOT_CANCEL_H  */