diff options
Diffstat (limited to 'winsup')
-rw-r--r-- | winsup/cygwin/cygwin.din | 1 | ||||
-rw-r--r-- | winsup/cygwin/include/cygwin/version.h | 3 | ||||
-rw-r--r-- | winsup/cygwin/release/3.5.0 | 2 | ||||
-rw-r--r-- | winsup/cygwin/syscalls.cc | 42 | ||||
-rw-r--r-- | winsup/doc/new-features.xml | 4 | ||||
-rw-r--r-- | winsup/doc/posix.xml | 5 |
6 files changed, 56 insertions, 1 deletions
diff --git a/winsup/cygwin/cygwin.din b/winsup/cygwin/cygwin.din index 9b76ce6..9e354ac 100644 --- a/winsup/cygwin/cygwin.din +++ b/winsup/cygwin/cygwin.din @@ -347,6 +347,7 @@ clog10l NOSIGFE clogf NOSIGFE clogl NOSIGFE close SIGFE +close_range SIGFE closedir SIGFE closelog SIGFE cnd_broadcast SIGFE diff --git a/winsup/cygwin/include/cygwin/version.h b/winsup/cygwin/include/cygwin/version.h index c8177c2..3036878 100644 --- a/winsup/cygwin/include/cygwin/version.h +++ b/winsup/cygwin/include/cygwin/version.h @@ -484,12 +484,13 @@ details. */ 347: Add c16rtomb, c32rtomb, mbrtoc16, mbrtoc32. 348: Add c8rtomb, mbrtoc. 349: Add fallocate. + 350: Add close_range. Note that we forgot to bump the api for ualarm, strtoll, strtoull, sigaltstack, sethostname. */ #define CYGWIN_VERSION_API_MAJOR 0 -#define CYGWIN_VERSION_API_MINOR 349 +#define CYGWIN_VERSION_API_MINOR 350 /* There is also a compatibity version number associated with the shared memory regions. It is incremented when incompatible changes are made to the shared diff --git a/winsup/cygwin/release/3.5.0 b/winsup/cygwin/release/3.5.0 index d0a6c2f..6209064 100644 --- a/winsup/cygwin/release/3.5.0 +++ b/winsup/cygwin/release/3.5.0 @@ -43,6 +43,8 @@ What's new: - New API calls: c8rtomb, c16rtomb, c32rtomb, mbrtoc8, mbrtoc16, mbrtoc32. +- New API call: close_range (available on FreeBSD and Linux). + - New API call: fallocate (Linux-specific). - Implement OSS-based sound mixer device (/dev/mixer). diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index 486db1d..9d88b60 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -85,6 +85,48 @@ close_all_files (bool norelease) cygheap->fdtab.unlock (); } +/* Close or set the close-on-exec flag for all open file descriptors + from firstfd to lastfd. CLOSE_RANGE_UNSHARE is not supported. + Available on FreeBSD since 13 and Linux since 5.9 */ +extern "C" int +close_range (unsigned int firstfd, unsigned int lastfd, int flags) +{ + pthread_testcancel (); + + if (!(firstfd <= lastfd && !(flags & ~CLOSE_RANGE_CLOEXEC))) + { + set_errno (EINVAL); + return -1; + } + + cygheap->fdtab.lock (); + + unsigned int size = (lastfd < cygheap->fdtab.size ? lastfd + 1 : + cygheap->fdtab.size); + + for (unsigned int i = firstfd; i < size; i++) + { + cygheap_fdget cfd ((int) i, false, false); + if (cfd < 0) + continue; + + if (flags & CLOSE_RANGE_CLOEXEC) + { + syscall_printf ("set FD_CLOEXEC on fd %u", i); + cfd->fcntl (F_SETFD, FD_CLOEXEC); + } + else + { + syscall_printf ("closing fd %u", i); + cfd->close_with_arch (); + cfd.release (); + } + } + + cygheap->fdtab.unlock (); + return 0; +} + extern "C" int dup (int fd) { diff --git a/winsup/doc/new-features.xml b/winsup/doc/new-features.xml index 6ae4200..0abe1c4 100644 --- a/winsup/doc/new-features.xml +++ b/winsup/doc/new-features.xml @@ -75,6 +75,10 @@ New API calls: c8rtomb, c16rtomb, c32rtomb, mbrtoc8, mbrtoc16, mbrtoc32. </para></listitem> <listitem><para> +New API call: close_range (available on FreeBSD and Linux). +</para></listitem> + +<listitem><para> New API call: fallocate (Linux-specific). </para></listitem> diff --git a/winsup/doc/posix.xml b/winsup/doc/posix.xml index 1a4eee1..8905691 100644 --- a/winsup/doc/posix.xml +++ b/winsup/doc/posix.xml @@ -1143,6 +1143,7 @@ also IEEE Std 1003.1-2017 (POSIX.1-2017).</para> cfmakeraw cfsetspeed clearerr_unlocked + close_range daemon dn_comp dn_expand @@ -1297,6 +1298,7 @@ also IEEE Std 1003.1-2017 (POSIX.1-2017).</para> clog10 clog10f clog10l + close_range (see <xref linkend="std-notes">chapter "Implementation Notes"</xref>) crypt_r (available in external "crypt" library) dladdr (see <xref linkend="std-notes">chapter "Implementation Notes"</xref>) dremf @@ -1656,6 +1658,9 @@ CLOCK_REALTIME and CLOCK_MONOTONIC. <function>clock_setres</function>, <function>clock_settime</function>, and <function>timer_create</function> currently support only CLOCK_REALTIME.</para> +<para><function>close_range</function> does not support the Linux-specific +flag CLOSE_RANGE_UNSHARE.</para> + <para>POSIX file locks via <function>fcntl</function> or <function>lockf</function>, as well as BSD <function>flock</function> locks are advisory locks. They don't interact with Windows mandatory locks, nor |