Page MenuHomeFreeBSD

D24399.id70508.diff
No OneTemporary

D24399.id70508.diff

Index: Makefile.inc1
===================================================================
--- Makefile.inc1
+++ Makefile.inc1
@@ -957,7 +957,8 @@
.endif
.endfor
# 20190916 r352703 shm_open
-.for f in shm_open
+# 2020041X rXXXXXX closefrom
+.for f in shm_open closefrom
@if [ -e "${OBJTOP}/lib/libc/.depend.${f}.o" ] && \
egrep -qw '${f}\.[sS]' ${OBJTOP}/lib/libc/.depend.${f}.o; then \
echo "Removing stale dependencies for ${f} syscall wrappers"; \
Index: lib/libc/include/libc_private.h
===================================================================
--- lib/libc/include/libc_private.h
+++ lib/libc/include/libc_private.h
@@ -331,6 +331,7 @@
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);
Index: lib/libc/sys/Makefile.inc
===================================================================
--- lib/libc/sys/Makefile.inc
+++ lib/libc/sys/Makefile.inc
@@ -45,6 +45,7 @@
PSEUDO+= _getdirentries.o
SRCS+= brk.c
+SRCS+= closefrom.c
SRCS+= pipe.c
SRCS+= shm_open.c
SRCS+= vadvise.c
Index: lib/libc/sys/closefrom.c
===================================================================
--- /dev/null
+++ lib/libc/sys/closefrom.c
@@ -0,0 +1,50 @@
+/*
+ * 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"
+
+__weak_reference(closefrom, _closefrom);
+__weak_reference(closefrom, __sys_closefrom);
+
+#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);
+}
Index: sys/compat/freebsd32/syscalls.master
===================================================================
--- sys/compat/freebsd32/syscalls.master
+++ sys/compat/freebsd32/syscalls.master
@@ -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, \
Index: sys/kern/kern_descrip.c
===================================================================
--- sys/kern/kern_descrip.c
+++ sys/kern/kern_descrip.c
@@ -1372,17 +1372,18 @@
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 @@
lowfd = MAX(0, uap->lowfd);
return (kern_close_range(td, lowfd, ~0U));
}
+#endif /* COMPAT_FREEBSD12 */
#if defined(COMPAT_43)
/*
Index: sys/kern/syscalls.master
===================================================================
--- sys/kern/syscalls.master
+++ sys/kern/syscalls.master
@@ -2776,7 +2776,7 @@
int jid
);
}
-509 AUE_CLOSEFROM STD {
+509 AUE_CLOSEFROM COMPAT12 {
int closefrom(
int lowfd
);

File Metadata

Mime Type
text/plain
Expires
Wed, Jan 21, 10:15 PM (14 h, 47 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
27822020
Default Alt Text
D24399.id70508.diff (4 KB)

Event Timeline