Date: Tue, 14 Apr 2020 18:07:42 +0000 (UTC) From: Kyle Evans <kevans@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r359930 - in head: lib/libc/include lib/libc/sys sys/compat/freebsd32 sys/kern tools/build Message-ID: <202004141807.03EI7gh4076312@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kevans Date: Tue Apr 14 18:07:42 2020 New Revision: 359930 URL: https://svnweb.freebsd.org/changeset/base/359930 Log: Mark closefrom(2) COMPAT12, reimplement in libc to wrap close_range Include a temporarily compatibility shim as well for kernels predating close_range, since closefrom is used in some critical areas. Reviewed by: markj (previous version), kib Differential Revision: https://reviews.freebsd.org/D24399 Added: head/lib/libc/sys/closefrom.c (contents, props changed) Modified: head/lib/libc/include/libc_private.h head/lib/libc/sys/Makefile.inc head/lib/libc/sys/Symbol.map head/sys/compat/freebsd32/syscalls.master head/sys/kern/kern_descrip.c head/sys/kern/syscalls.master head/tools/build/depend-cleanup.sh Modified: head/lib/libc/include/libc_private.h ============================================================================== --- head/lib/libc/include/libc_private.h Tue Apr 14 16:56:57 2020 (r359929) +++ head/lib/libc/include/libc_private.h Tue Apr 14 18:07:42 2020 (r359930) @@ -331,6 +331,7 @@ int __sys_clock_gettime(__clockid_t, struct timespec int __sys_clock_nanosleep(__clockid_t, int, const struct timespec *, struct timespec *); int __sys_close(int); +int __sys_close_range(unsigned, unsigned, int); int __sys_connect(int, const struct sockaddr *, __socklen_t); int __sys_fcntl(int, int, ...); int __sys_fdatasync(int); Modified: head/lib/libc/sys/Makefile.inc ============================================================================== --- head/lib/libc/sys/Makefile.inc Tue Apr 14 16:56:57 2020 (r359929) +++ head/lib/libc/sys/Makefile.inc Tue Apr 14 18:07:42 2020 (r359930) @@ -45,6 +45,7 @@ NOASM+= getdirentries.o PSEUDO+= _getdirentries.o SRCS+= brk.c +SRCS+= closefrom.c SRCS+= pipe.c SRCS+= shm_open.c SRCS+= vadvise.c Modified: head/lib/libc/sys/Symbol.map ============================================================================== --- head/lib/libc/sys/Symbol.map Tue Apr 14 16:56:57 2020 (r359929) +++ head/lib/libc/sys/Symbol.map Tue Apr 14 18:07:42 2020 (r359930) @@ -520,8 +520,6 @@ FBSDprivate_1.0 { __sys_clock_settime; _close; __sys_close; - _closefrom; - __sys_closefrom; _connect; __sys_connect; _cpuset; Added: head/lib/libc/sys/closefrom.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/lib/libc/sys/closefrom.c Tue Apr 14 18:07:42 2020 (r359930) @@ -0,0 +1,47 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2020 Kyle Evans <kevans@FreeBSD.org> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <sys/syscall.h> +#include <unistd.h> + +#include "libc_private.h" + +#define CLOSE_RANGE_OSREL 1300091 + +void +closefrom(int lowfd) +{ + + if (__getosreldate() >= CLOSE_RANGE_OSREL) + __sys_close_range(lowfd, ~0U, 0); + else + /* Fallback to closefrom(2) on older kernels. */ + syscall(SYS_freebsd12_closefrom, lowfd); +} Modified: head/sys/compat/freebsd32/syscalls.master ============================================================================== --- head/sys/compat/freebsd32/syscalls.master Tue Apr 14 16:56:57 2020 (r359929) +++ head/sys/compat/freebsd32/syscalls.master Tue Apr 14 18:07:42 2020 (r359930) @@ -980,7 +980,7 @@ 507 AUE_JAIL_SET STD { int freebsd32_jail_set(struct iovec32 *iovp, \ unsigned int iovcnt, int flags); } 508 AUE_JAIL_REMOVE NOPROTO { int jail_remove(int jid); } -509 AUE_CLOSEFROM NOPROTO { int closefrom(int lowfd); } +509 AUE_CLOSEFROM COMPAT12|NOPROTO { int closefrom(int lowfd); } 510 AUE_SEMCTL NOSTD { int freebsd32_semctl(int semid, int semnum, \ int cmd, union semun32 *arg); } 511 AUE_MSGCTL NOSTD { int freebsd32_msgctl(int msqid, int cmd, \ Modified: head/sys/kern/kern_descrip.c ============================================================================== --- head/sys/kern/kern_descrip.c Tue Apr 14 16:56:57 2020 (r359929) +++ head/sys/kern/kern_descrip.c Tue Apr 14 18:07:42 2020 (r359930) @@ -1372,17 +1372,18 @@ sys_close_range(struct thread *td, struct close_range_ return (kern_close_range(td, uap->lowfd, uap->highfd)); } +#ifdef COMPAT_FREEBSD12 /* * Close open file descriptors. */ #ifndef _SYS_SYSPROTO_H_ -struct closefrom_args { +struct freebsd12_closefrom_args { int lowfd; }; #endif /* ARGSUSED */ int -sys_closefrom(struct thread *td, struct closefrom_args *uap) +freebsd12_closefrom(struct thread *td, struct freebsd12_closefrom_args *uap) { u_int lowfd; @@ -1395,6 +1396,7 @@ sys_closefrom(struct thread *td, struct closefrom_args lowfd = MAX(0, uap->lowfd); return (kern_close_range(td, lowfd, ~0U)); } +#endif /* COMPAT_FREEBSD12 */ #if defined(COMPAT_43) /* Modified: head/sys/kern/syscalls.master ============================================================================== --- head/sys/kern/syscalls.master Tue Apr 14 16:56:57 2020 (r359929) +++ head/sys/kern/syscalls.master Tue Apr 14 18:07:42 2020 (r359930) @@ -2776,7 +2776,7 @@ int jid ); } -509 AUE_CLOSEFROM STD { +509 AUE_CLOSEFROM COMPAT12 { int closefrom( int lowfd ); Modified: head/tools/build/depend-cleanup.sh ============================================================================== --- head/tools/build/depend-cleanup.sh Tue Apr 14 16:56:57 2020 (r359929) +++ head/tools/build/depend-cleanup.sh Tue Apr 14 18:07:42 2020 (r359930) @@ -36,3 +36,5 @@ clean_dep() clean_dep lib/libc shm_open S # 20200310 r358851 rename of openmp's ittnotify_static.c to .cpp clean_dep lib/libomp ittnotify_static c +# 20200414 r359930 closefrom +clean_dep lib/libc closefrom S
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202004141807.03EI7gh4076312>