[Midnightbsd-cvs] src [9943] trunk/sys/kern: sync with freebsd 10-stable
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Fri May 25 16:40:00 EDT 2018
Revision: 9943
http://svnweb.midnightbsd.org/src/?rev=9943
Author: laffer1
Date: 2018-05-25 16:39:59 -0400 (Fri, 25 May 2018)
Log Message:
-----------
sync with freebsd 10-stable
Modified Paths:
--------------
trunk/sys/kern/Makefile
trunk/sys/kern/capabilities.conf
trunk/sys/kern/imgact_aout.c
trunk/sys/kern/imgact_gzip.c
trunk/sys/kern/imgact_shell.c
trunk/sys/kern/inflate.c
trunk/sys/kern/init_main.c
trunk/sys/kern/init_sysent.c
trunk/sys/kern/kern_acct.c
trunk/sys/kern/kern_alq.c
trunk/sys/kern/kern_clock.c
trunk/sys/kern/kern_clocksource.c
trunk/sys/kern/kern_condvar.c
trunk/sys/kern/kern_conf.c
Property Changed:
----------------
trunk/sys/kern/capabilities.conf
Modified: trunk/sys/kern/Makefile
===================================================================
--- trunk/sys/kern/Makefile 2018-05-25 20:34:19 UTC (rev 9942)
+++ trunk/sys/kern/Makefile 2018-05-25 20:39:59 UTC (rev 9943)
@@ -1,5 +1,6 @@
+# $MidnightBSD$
# @(#)Makefile 8.2 (Berkeley) 3/21/94
-# $MidnightBSD$
+# $FreeBSD: stable/10/sys/kern/Makefile 315063 2017-03-11 08:40:59Z dchagin $
# Makefile for init_sysent
@@ -12,10 +13,4 @@
init_sysent.c syscalls.c systrace_args.c ../sys/syscall.h \
../sys/syscall.mk ../sys/sysproto.h: makesyscalls.sh syscalls.master \
capabilities.conf
- -mv -f init_sysent.c init_sysent.c.bak
- -mv -f syscalls.c syscalls.c.bak
- -mv -f systrace_args.c systrace_args.c.bak
- -mv -f ../sys/syscall.h ../sys/syscall.h.bak
- -mv -f ../sys/syscall.mk ../sys/syscall.mk.bak
- -mv -f ../sys/sysproto.h ../sys/sysproto.h.bak
sh makesyscalls.sh syscalls.master
Modified: trunk/sys/kern/capabilities.conf
===================================================================
--- trunk/sys/kern/capabilities.conf 2018-05-25 20:34:19 UTC (rev 9942)
+++ trunk/sys/kern/capabilities.conf 2018-05-25 20:39:59 UTC (rev 9943)
@@ -32,8 +32,8 @@
## - sys_exit(2), abort2(2) and close(2) are very important.
## - Sorted alphabetically, please keep it that way.
##
-## $FreeBSD$
-##
+## $FreeBSD: stable/10/sys/kern/capabilities.conf 305518 2016-09-07 04:06:25Z emaste $
+## $MidnightBSD$
##
## Allow ACL and MAC label operations by file descriptor, subject to
@@ -78,6 +78,7 @@
## relies on existing bindings on a socket, subject to capability rights.
##
accept
+accept4
##
## Allow AIO operations by file descriptor, subject to capability rights.
@@ -100,25 +101,27 @@
#audit
##
-## Disllow bind(2) for now, even though we support CAP_BIND.
+## Allow bindat(2).
##
-## XXXRW: Revisit this.
-##
-#bind
+bindat
##
## Allow capability mode and capability system calls.
##
cap_enter
+cap_fcntls_get
+cap_fcntls_limit
cap_getmode
-cap_getrights
-cap_new
+cap_ioctls_get
+cap_ioctls_limit
+__cap_rights_get
+cap_rights_limit
##
## Allow read-only clock operations.
##
+clock_getres
clock_gettime
-clock_getres
##
## Always allow file descriptor close(2).
@@ -127,11 +130,9 @@
closefrom
##
-## Disallow connect(2) for now, despite CAP_CONNECT.
+## Allow connectat(2).
##
-## XXXRW: Revisit this.
-##
-#connect
+connectat
##
## cpuset(2) and related calls require scoping by process, but should
@@ -219,8 +220,9 @@
ftruncate
##
-## Allow futimes(2), subject to capability rights.
+## Allow futimens(2) and futimes(2), subject to capability rights.
##
+futimens
futimes
##
@@ -239,7 +241,7 @@
## Allow directory I/O on a file descriptor, subject to capability rights.
## Originally we had separate capabilities for directory-specific read
## operations, but on BSD we allow reading the raw directory data, so we just
-## rely on CAP_READ and CAP_SEEK now.
+## rely on CAP_READ now.
##
getdents
getdirentries
@@ -248,6 +250,7 @@
## Allow querying certain trivial global state.
##
getdomainname
+getdtablesize
##
## Allow querying current process credential state.
@@ -317,13 +320,10 @@
getuid
##
-## Disallow ioctl(2) for now, as frequently ioctl(2) operations have global
-## scope, but this is a tricky one as it is also required for tty control.
-## We do have a capability right for this operation.
+## Allow ioctl(2), which hopefully will be limited by applications only to
+## required commands with cap_ioctls_limit(2) syscall.
##
-## XXXRW: This needs to be revisited.
-##
-#ioctl
+ioctl
##
## Allow querying current process credential state.
@@ -337,6 +337,11 @@
kevent
##
+## Allow kill(2), as we allow the process to send signals only to himself.
+##
+kill
+
+##
## Allow message queue operations on file descriptors, subject to capability
## rights.
##
@@ -383,13 +388,6 @@
lseek
##
-## Allow MAC label operations by file descriptor, subject to capability
-## rights.
-##
-mac_get_fd
-mac_set_fd
-
-##
## Allow simple VM operations on the current process.
##
madvise
@@ -442,16 +440,22 @@
##
## Operations relative to directory capabilities.
##
+chflagsat
faccessat
+fchmodat
+fchownat
fstatat
-fchmodat
futimesat
+linkat
mkdirat
-rmdirat
mkfifoat
mknodat
openat
+readlinkat
renameat
+symlinkat
+unlinkat
+utimensat
##
## Allow entry into open(2). This system call will fail, since access to the
@@ -481,6 +485,7 @@
## Allow pipe(2).
##
pipe
+pipe2
##
## Allow poll(2), which will be scoped by capability rights.
@@ -543,7 +548,7 @@
##
sched_getparam
sched_getscheduler
-sched_rr_getinterval
+sched_rr_get_interval
sched_setparam
sched_setscheduler
sched_yield
@@ -557,10 +562,11 @@
sctp_peeloff
##
-## Allow select(2), which will be scoped by capability rights.
+## Allow pselect(2) and select(2), which will be scoped by capability rights.
##
## XXXRW: But is it?
##
+pselect
select
##
@@ -664,6 +670,7 @@
sigtimedwait
sigvec
sigwaitinfo
+sigwait
##
## Allow creating new socket pairs with socket(2) and socketpair(2).
Property changes on: trunk/sys/kern/capabilities.conf
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/sys/kern/imgact_aout.c
===================================================================
--- trunk/sys/kern/imgact_aout.c 2018-05-25 20:34:19 UTC (rev 9942)
+++ trunk/sys/kern/imgact_aout.c 2018-05-25 20:39:59 UTC (rev 9943)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1993, David Greenman
* All rights reserved.
@@ -25,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/kern/imgact_aout.c 294136 2016-01-16 07:56:49Z dchagin $");
#include <sys/param.h>
#include <sys/exec.h>
@@ -99,6 +100,8 @@
.sv_fetch_syscall_args = cpu_fetch_syscall_args,
.sv_syscallnames = syscallnames,
.sv_schedtail = NULL,
+ .sv_thread_detach = NULL,
+ .sv_trap = NULL,
};
#elif defined(__amd64__)
@@ -175,9 +178,9 @@
* 0x64 for Linux, 0x86 for *BSD, 0x00 for BSDI.
* NetBSD is in network byte order.. ugh.
*/
- if (((a_out->a_magic >> 16) & 0xff) != 0x86 &&
- ((a_out->a_magic >> 16) & 0xff) != 0 &&
- ((((int)ntohl(a_out->a_magic)) >> 16) & 0xff) != 0x86)
+ if (((a_out->a_midmag >> 16) & 0xff) != 0x86 &&
+ ((a_out->a_midmag >> 16) & 0xff) != 0 &&
+ ((((int)ntohl(a_out->a_midmag)) >> 16) & 0xff) != 0x86)
return -1;
/*
@@ -185,7 +188,7 @@
* We do two cases: host byte order and network byte order
* (for NetBSD compatibility)
*/
- switch ((int)(a_out->a_magic & 0xffff)) {
+ switch ((int)(a_out->a_midmag & 0xffff)) {
case ZMAGIC:
virtual_offset = 0;
if (a_out->a_text) {
@@ -204,7 +207,7 @@
break;
default:
/* NetBSD compatibility */
- switch ((int)(ntohl(a_out->a_magic) & 0xffff)) {
+ switch ((int)(ntohl(a_out->a_midmag) & 0xffff)) {
case ZMAGIC:
case QMAGIC:
virtual_offset = PAGE_SIZE;
Modified: trunk/sys/kern/imgact_gzip.c
===================================================================
--- trunk/sys/kern/imgact_gzip.c 2018-05-25 20:34:19 UTC (rev 9942)
+++ trunk/sys/kern/imgact_gzip.c 2018-05-25 20:39:59 UTC (rev 9943)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
@@ -18,11 +19,11 @@
* inflate isn't quite reentrant yet...
* error-handling is a mess...
* so is the rest...
- * tidy up unnecesary includes
+ * tidy up unnecessary includes
*/
#include <sys/cdefs.h>
-__FBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/kern/imgact_gzip.c 255426 2013-09-09 18:11:59Z jhb $");
#include <sys/param.h>
#include <sys/exec.h>
@@ -137,7 +138,7 @@
}
if (igz.inbuf)
- kmem_free_wakeup(exec_map, (vm_offset_t)igz.inbuf, PAGE_SIZE);
+ kmap_free_wakeup(exec_map, (vm_offset_t)igz.inbuf, PAGE_SIZE);
if (igz.error || error) {
printf("Output=%lu ", igz.output);
printf("Inflate_error=%d igz.error=%d where=%d\n",
@@ -161,7 +162,7 @@
* Set file/virtual offset based on a.out variant. We do two cases:
* host byte order and network byte order (for NetBSD compatibility)
*/
- switch ((int) (gz->a_out.a_magic & 0xffff)) {
+ switch ((int) (gz->a_out.a_midmag & 0xffff)) {
case ZMAGIC:
gz->virtual_offset = 0;
if (gz->a_out.a_text) {
@@ -177,7 +178,7 @@
break;
default:
/* NetBSD compatibility */
- switch ((int) (ntohl(gz->a_out.a_magic) & 0xffff)) {
+ switch ((int) (ntohl(gz->a_out.a_midmag) & 0xffff)) {
case ZMAGIC:
case QMAGIC:
gz->virtual_offset = PAGE_SIZE;
@@ -269,12 +270,9 @@
*/
vmaddr = gz->virtual_offset + gz->a_out.a_text +
gz->a_out.a_data;
- error = vm_map_find(&vmspace->vm_map,
- NULL,
- 0,
- &vmaddr,
- gz->bss_size,
- FALSE, VM_PROT_ALL, VM_PROT_ALL, 0);
+ error = vm_map_find(&vmspace->vm_map, NULL, 0, &vmaddr,
+ gz->bss_size, 0, VMFS_NO_SPACE, VM_PROT_ALL, VM_PROT_ALL,
+ 0);
if (error) {
gz->where = __LINE__;
return (error);
@@ -310,7 +308,7 @@
return igz->inbuf[(igz->idx++) - igz->offset];
}
if (igz->inbuf)
- kmem_free_wakeup(exec_map, (vm_offset_t)igz->inbuf, PAGE_SIZE);
+ kmap_free_wakeup(exec_map, (vm_offset_t)igz->inbuf, PAGE_SIZE);
igz->offset = igz->idx & ~PAGE_MASK;
error = vm_mmap(exec_map, /* map */
Modified: trunk/sys/kern/imgact_shell.c
===================================================================
--- trunk/sys/kern/imgact_shell.c 2018-05-25 20:34:19 UTC (rev 9942)
+++ trunk/sys/kern/imgact_shell.c 2018-05-25 20:39:59 UTC (rev 9943)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1993, David Greenman
* All rights reserved.
@@ -25,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/kern/imgact_shell.c 325514 2017-11-07 14:28:10Z pfg $");
#include <sys/param.h>
#include <sys/vnode.h>
@@ -97,8 +98,7 @@
* 6.x branch on May 28, 2005 (matching __FreeBSD_version 600029).
*/
int
-exec_shell_imgact(imgp)
- struct image_params *imgp;
+exec_shell_imgact(struct image_params *imgp)
{
const char *image_header = imgp->image_header;
const char *ihp, *interpb, *interpe, *maxp, *optb, *opte, *fname;
@@ -115,10 +115,10 @@
* Don't allow a shell script to be the shell for a shell
* script. :-)
*/
- if (imgp->interpreted)
+ if (imgp->interpreted & IMGACT_SHELL)
return (ENOEXEC);
- imgp->interpreted = 1;
+ imgp->interpreted |= IMGACT_SHELL;
/*
* At this point we have the first page of the file mapped.
@@ -125,7 +125,7 @@
* However, we don't know how far into the page the contents are
* valid -- the actual file might be much shorter than the page.
* So find out the file size.
- */
+ */
error = VOP_GETATTR(imgp->vp, &vattr, imgp->proc->p_ucred);
if (error)
return (error);
Modified: trunk/sys/kern/inflate.c
===================================================================
--- trunk/sys/kern/inflate.c 2018-05-25 20:34:19 UTC (rev 9942)
+++ trunk/sys/kern/inflate.c 2018-05-25 20:39:59 UTC (rev 9943)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*
* Most parts of this file are not covered by:
* ----------------------------------------------------------------------------
@@ -9,7 +10,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/kern/inflate.c 302234 2016-06-27 21:50:30Z bdrewery $");
#include <sys/param.h>
#include <sys/inflate.h>
@@ -206,7 +207,7 @@
end-of-block. Note however that the static length tree defines
288 codes just to fill out the Huffman codes. Codes 286 and 287
cannot be used though, since there is no length base or extra bits
- defined for them. Similarily, there are up to 30 distance codes.
+ defined for them. Similarly, there are up to 30 distance codes.
However, static trees define 32 codes (all 5 bits) to fill out the
Huffman codes, but the last two had better not show up in the data.
7. Unzip can check dynamic Huffman blocks for complete code sets.
@@ -335,7 +336,7 @@
where NEEDBITS makes sure that b has at least j bits in it, and
DUMPBITS removes the bits from b. The macros use the variable k
for the number of bits in b. Normally, b and k are register
- variables for speed, and are initialized at the begining of a
+ variables for speed, and are initialized at the beginning of a
routine that uses these macros from a global bit buffer and count.
In order to not ask for more bits than there are in the compressed
Modified: trunk/sys/kern/init_main.c
===================================================================
--- trunk/sys/kern/init_main.c 2018-05-25 20:34:19 UTC (rev 9942)
+++ trunk/sys/kern/init_main.c 2018-05-25 20:39:59 UTC (rev 9943)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1995 Terrence R. Lambert
* All rights reserved.
@@ -42,7 +43,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/kern/init_main.c 314667 2017-03-04 13:03:31Z avg $");
#include "opt_ddb.h"
#include "opt_init_path.h"
@@ -101,13 +102,24 @@
struct vmspace vmspace0;
struct proc *initproc;
-int boothowto = 0; /* initialized so that it can be patched */
+#ifndef BOOTHOWTO
+#define BOOTHOWTO 0
+#endif
+int boothowto = BOOTHOWTO; /* initialized so that it can be patched */
SYSCTL_INT(_debug, OID_AUTO, boothowto, CTLFLAG_RD, &boothowto, 0,
"Boot control flags, passed from loader");
-int bootverbose;
+
+#ifndef BOOTVERBOSE
+#define BOOTVERBOSE 0
+#endif
+int bootverbose = BOOTVERBOSE;
SYSCTL_INT(_debug, OID_AUTO, bootverbose, CTLFLAG_RW, &bootverbose, 0,
"Control the output of verbose kernel messages");
+#ifdef INVARIANTS
+FEATURE(invariants, "Kernel compiled with INVARIANTS, may affect performance");
+#endif
+
/*
* This ensures that there is at least one entry so that the sysinit_set
* symbol is not undefined. A sybsystem ID of SI_SUB_DUMMY is never
@@ -236,9 +248,6 @@
/*
* Traverse the (now) ordered list of system initialization tasks.
* Perform each task, and continue on to the next task.
- *
- * The last item on the list is expected to be the scheduler,
- * which will not return.
*/
for (sipp = sysinit; sipp < sysinit_end; sipp++) {
@@ -296,7 +305,13 @@
}
}
- panic("Shouldn't get here!");
+ mtx_assert(&Giant, MA_OWNED | MA_NOTRECURSED);
+ mtx_unlock(&Giant);
+
+ /*
+ * Now hand over this thread to swapper.
+ */
+ swapper();
/* NOTREACHED*/
}
@@ -339,7 +354,7 @@
"WARNING: WITNESS option enabled, expect reduced performance.\n";
SYSINIT(witwarn, SI_SUB_COPYRIGHT, SI_ORDER_THIRD + 1,
print_caddr_t, wit_warn);
-SYSINIT(witwarn2, SI_SUB_RUN_SCHEDULER, SI_ORDER_THIRD + 1,
+SYSINIT(witwarn2, SI_SUB_LAST, SI_ORDER_THIRD + 1,
print_caddr_t, wit_warn);
#endif
@@ -348,7 +363,7 @@
"WARNING: DIAGNOSTIC option enabled, expect reduced performance.\n";
SYSINIT(diagwarn, SI_SUB_COPYRIGHT, SI_ORDER_THIRD + 2,
print_caddr_t, diag_warn);
-SYSINIT(diagwarn2, SI_SUB_RUN_SCHEDULER, SI_ORDER_THIRD + 2,
+SYSINIT(diagwarn2, SI_SUB_LAST, SI_ORDER_THIRD + 2,
print_caddr_t, diag_warn);
#endif
@@ -400,6 +415,8 @@
.sv_fetch_syscall_args = null_fetch_syscall_args,
.sv_syscallnames = NULL,
.sv_schedtail = NULL,
+ .sv_thread_detach = NULL,
+ .sv_trap = NULL,
};
/*
@@ -421,6 +438,7 @@
{
struct proc *p;
struct thread *td;
+ struct ucred *newcred;
vm_paddr_t pageablemem;
int i;
@@ -445,17 +463,8 @@
* Add scheduler specific parts to proc, thread as needed.
*/
schedinit(); /* scheduler gets its house in order */
- /*
- * Initialize sleep queue hash table
- */
- sleepinit();
/*
- * additional VM structures
- */
- vm_init2();
-
- /*
* Create process 0 (the swapper).
*/
LIST_INSERT_HEAD(&allproc, p, p_list);
@@ -472,7 +481,8 @@
session0.s_leader = p;
p->p_sysent = &null_sysvec;
- p->p_flag = P_SYSTEM | P_INMEM;
+ p->p_flag = P_SYSTEM | P_INMEM | P_KTHREAD;
+ p->p_flag2 = 0;
p->p_state = PRS_NORMAL;
knlist_init_mtx(&p->p_klist, &p->p_mtx);
STAILQ_INIT(&p->p_ktr);
@@ -488,34 +498,37 @@
td->td_priority = PVM;
td->td_base_pri = PVM;
td->td_oncpu = 0;
- td->td_flags = TDF_INMEM|TDP_KTHREAD;
+ td->td_flags = TDF_INMEM;
+ td->td_pflags = TDP_KTHREAD;
td->td_cpuset = cpuset_thread0();
- prison0.pr_cpuset = cpuset_ref(td->td_cpuset);
+ prison0_init();
p->p_peers = 0;
p->p_leader = p;
+ p->p_reaper = p;
+ LIST_INIT(&p->p_reaplist);
-
strncpy(p->p_comm, "kernel", sizeof (p->p_comm));
strncpy(td->td_name, "swapper", sizeof (td->td_name));
callout_init_mtx(&p->p_itcallout, &p->p_mtx, 0);
callout_init_mtx(&p->p_limco, &p->p_mtx, 0);
- callout_init(&td->td_slpcallout, CALLOUT_MPSAFE);
+ callout_init(&td->td_slpcallout, 1);
/* Create credentials. */
- p->p_ucred = crget();
- p->p_ucred->cr_ngroups = 1; /* group 0 */
- p->p_ucred->cr_uidinfo = uifind(0);
- p->p_ucred->cr_ruidinfo = uifind(0);
- p->p_ucred->cr_prison = &prison0;
- p->p_ucred->cr_loginclass = loginclass_find("default");
+ newcred = crget();
+ newcred->cr_ngroups = 1; /* group 0 */
+ newcred->cr_uidinfo = uifind(0);
+ newcred->cr_ruidinfo = uifind(0);
+ newcred->cr_prison = &prison0;
+ newcred->cr_loginclass = loginclass_find("default");
+ proc_set_cred_init(p, newcred);
#ifdef AUDIT
- audit_cred_kproc0(p->p_ucred);
+ audit_cred_kproc0(newcred);
#endif
#ifdef MAC
- mac_cred_create_swapper(p->p_ucred);
+ mac_cred_create_swapper(newcred);
#endif
- td->td_ucred = crhold(p->p_ucred);
+ td->td_ucred = crhold(newcred);
/* Create sigacts. */
p->p_sigacts = sigacts_alloc();
@@ -600,9 +613,9 @@
sx_slock(&allproc_lock);
FOREACH_PROC_IN_SYSTEM(p) {
microuptime(&p->p_stats->p_start);
- PROC_SLOCK(p);
+ PROC_STATLOCK(p);
rufetch(p, &ru); /* Clears thread stats */
- PROC_SUNLOCK(p);
+ PROC_STATUNLOCK(p);
p->p_rux.rux_runtime = 0;
p->p_rux.rux_uticks = 0;
p->p_rux.rux_sticks = 0;
@@ -662,7 +675,7 @@
#ifdef INIT_PATH
__XSTRING(INIT_PATH);
#else
- "/sbin/init:/sbin/oinit:/sbin/init.bak:/rescue/init:/stand/sysinstall";
+ "/sbin/init:/sbin/oinit:/sbin/init.bak:/rescue/init";
#endif
SYSCTL_STRING(_kern, OID_AUTO, init_path, CTLFLAG_RD, init_path, 0,
"Path used to search the init process");
@@ -703,12 +716,15 @@
vfs_mountroot();
+ /* Wipe GELI passphrase from the environment. */
+ unsetenv("kern.geom.eli.passphrase");
+
/*
* Need just enough stack to hold the faked-up "execve()" arguments.
*/
addr = p->p_sysent->sv_usrstack - PAGE_SIZE;
- if (vm_map_find(&p->p_vmspace->vm_map, NULL, 0, &addr, PAGE_SIZE,
- FALSE, VM_PROT_ALL, VM_PROT_ALL, 0) != 0)
+ if (vm_map_find(&p->p_vmspace->vm_map, NULL, 0, &addr, PAGE_SIZE, 0,
+ VMFS_NO_SPACE, VM_PROT_ALL, VM_PROT_ALL, 0) != 0)
panic("init: couldn't allocate argument space");
p->p_vmspace->vm_maxsaddr = (caddr_t)addr;
p->p_vmspace->vm_ssize = 1;
@@ -818,8 +834,11 @@
KASSERT(initproc->p_pid == 1, ("create_init: initproc->p_pid != 1"));
/* divorce init's credentials from the kernel's */
newcred = crget();
+ sx_xlock(&proctree_lock);
PROC_LOCK(initproc);
initproc->p_flag |= P_SYSTEM | P_INMEM;
+ initproc->p_treeflag |= P_TREE_REAPER;
+ LIST_INSERT_HEAD(&initproc->p_reaplist, &proc0, p_reapsibling);
oldcred = initproc->p_ucred;
crcopy(newcred, oldcred);
#ifdef MAC
@@ -828,8 +847,9 @@
#ifdef AUDIT
audit_cred_proc1(newcred);
#endif
- initproc->p_ucred = newcred;
+ proc_set_cred(initproc, newcred);
PROC_UNLOCK(initproc);
+ sx_xunlock(&proctree_lock);
crfree(oldcred);
cred_update_thread(FIRST_THREAD_IN_PROC(initproc));
cpu_set_fork_handler(FIRST_THREAD_IN_PROC(initproc), start_init, NULL);
Modified: trunk/sys/kern/init_sysent.c
===================================================================
--- trunk/sys/kern/init_sysent.c 2018-05-25 20:34:19 UTC (rev 9942)
+++ trunk/sys/kern/init_sysent.c 2018-05-25 20:39:59 UTC (rev 9943)
@@ -1,9 +1,9 @@
+/* $MidnightBSD$ */
/*
* System call switch table.
*
* DO NOT EDIT-- this file is automatically generated.
- * $MidnightBSD$
- * created from MidnightBSD
+ * $FreeBSD: stable/10/sys/kern/init_sysent.c 321018 2017-07-15 17:00:43Z dchagin $
*/
#include "opt_compat.h"
@@ -71,7 +71,7 @@
{ AS(chflags_args), (sy_call_t *)sys_chflags, AUE_CHFLAGS, NULL, 0, 0, 0, SY_THR_STATIC }, /* 34 = chflags */
{ AS(fchflags_args), (sy_call_t *)sys_fchflags, AUE_FCHFLAGS, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 35 = fchflags */
{ 0, (sy_call_t *)sys_sync, AUE_SYNC, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 36 = sync */
- { AS(kill_args), (sy_call_t *)sys_kill, AUE_KILL, NULL, 0, 0, 0, SY_THR_STATIC }, /* 37 = kill */
+ { AS(kill_args), (sy_call_t *)sys_kill, AUE_KILL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 37 = kill */
{ compat(AS(ostat_args),stat), AUE_STAT, NULL, 0, 0, 0, SY_THR_STATIC }, /* 38 = old stat */
{ 0, (sy_call_t *)sys_getppid, AUE_GETPPID, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 39 = getppid */
{ compat(AS(olstat_args),lstat), AUE_LSTAT, NULL, 0, 0, 0, SY_THR_STATIC }, /* 40 = old lstat */
@@ -88,7 +88,7 @@
{ AS(acct_args), (sy_call_t *)sys_acct, AUE_ACCT, NULL, 0, 0, 0, SY_THR_STATIC }, /* 51 = acct */
{ compat(0,sigpending), AUE_SIGPENDING, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 52 = old sigpending */
{ AS(sigaltstack_args), (sy_call_t *)sys_sigaltstack, AUE_SIGALTSTACK, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 53 = sigaltstack */
- { AS(ioctl_args), (sy_call_t *)sys_ioctl, AUE_IOCTL, NULL, 0, 0, 0, SY_THR_STATIC }, /* 54 = ioctl */
+ { AS(ioctl_args), (sy_call_t *)sys_ioctl, AUE_IOCTL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 54 = ioctl */
{ AS(reboot_args), (sy_call_t *)sys_reboot, AUE_REBOOT, NULL, 0, 0, 0, SY_THR_STATIC }, /* 55 = reboot */
{ AS(revoke_args), (sy_call_t *)sys_revoke, AUE_REVOKE, NULL, 0, 0, 0, SY_THR_STATIC }, /* 56 = revoke */
{ AS(symlink_args), (sy_call_t *)sys_symlink, AUE_SYMLINK, NULL, 0, 0, 0, SY_THR_STATIC }, /* 57 = symlink */
@@ -123,7 +123,7 @@
{ AS(getitimer_args), (sy_call_t *)sys_getitimer, AUE_GETITIMER, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 86 = getitimer */
{ compat(AS(gethostname_args),gethostname), AUE_SYSCTL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 87 = old gethostname */
{ compat(AS(sethostname_args),sethostname), AUE_SYSCTL, NULL, 0, 0, 0, SY_THR_STATIC }, /* 88 = old sethostname */
- { 0, (sy_call_t *)sys_getdtablesize, AUE_GETDTABLESIZE, NULL, 0, 0, 0, SY_THR_STATIC }, /* 89 = getdtablesize */
+ { 0, (sy_call_t *)sys_getdtablesize, AUE_GETDTABLESIZE, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 89 = getdtablesize */
{ AS(dup2_args), (sy_call_t *)sys_dup2, AUE_DUP2, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 90 = dup2 */
{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 91 = getdopt */
{ AS(fcntl_args), (sy_call_t *)sys_fcntl, AUE_FCNTL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 92 = fcntl */
@@ -275,13 +275,13 @@
{ AS(ktimer_gettime_args), (sy_call_t *)sys_ktimer_gettime, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 238 = ktimer_gettime */
{ AS(ktimer_getoverrun_args), (sy_call_t *)sys_ktimer_getoverrun, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 239 = ktimer_getoverrun */
{ AS(nanosleep_args), (sy_call_t *)sys_nanosleep, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 240 = nanosleep */
- { 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 241 = nosys */
- { 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 242 = nosys */
- { 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 243 = nosys */
+ { AS(ffclock_getcounter_args), (sy_call_t *)sys_ffclock_getcounter, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC }, /* 241 = ffclock_getcounter */
+ { AS(ffclock_setestimate_args), (sy_call_t *)sys_ffclock_setestimate, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC }, /* 242 = ffclock_setestimate */
+ { AS(ffclock_getestimate_args), (sy_call_t *)sys_ffclock_getestimate, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC }, /* 243 = ffclock_getestimate */
{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 244 = nosys */
{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 245 = nosys */
{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 246 = nosys */
- { 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 247 = nosys */
+ { AS(clock_getcpuclockid2_args), (sy_call_t *)sys_clock_getcpuclockid2, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC }, /* 247 = clock_getcpuclockid2 */
{ AS(ntp_gettime_args), (sy_call_t *)sys_ntp_gettime, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 248 = ntp_gettime */
{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 249 = nosys */
{ AS(minherit_args), (sy_call_t *)sys_minherit, AUE_MINHERIT, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 250 = minherit */
@@ -289,9 +289,9 @@
{ AS(openbsd_poll_args), (sy_call_t *)sys_openbsd_poll, AUE_POLL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 252 = openbsd_poll */
{ 0, (sy_call_t *)sys_issetugid, AUE_ISSETUGID, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 253 = issetugid */
{ AS(lchown_args), (sy_call_t *)sys_lchown, AUE_LCHOWN, NULL, 0, 0, 0, SY_THR_STATIC }, /* 254 = lchown */
- { AS(aio_read_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 255 = aio_read */
- { AS(aio_write_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 256 = aio_write */
- { AS(lio_listio_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 257 = lio_listio */
+ { AS(aio_read_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_ABSENT }, /* 255 = aio_read */
+ { AS(aio_write_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_ABSENT }, /* 256 = aio_write */
+ { AS(lio_listio_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_ABSENT }, /* 257 = lio_listio */
{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 258 = nosys */
{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 259 = nosys */
{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 260 = nosys */
@@ -348,13 +348,13 @@
{ AS(setresuid_args), (sy_call_t *)sys_setresuid, AUE_SETRESUID, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 311 = setresuid */
{ AS(setresgid_args), (sy_call_t *)sys_setresgid, AUE_SETRESGID, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 312 = setresgid */
{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 313 = obsolete signanosleep */
- { AS(aio_return_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 314 = aio_return */
- { AS(aio_suspend_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 315 = aio_suspend */
- { AS(aio_cancel_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 316 = aio_cancel */
- { AS(aio_error_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 317 = aio_error */
- { AS(oaio_read_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 318 = oaio_read */
- { AS(oaio_write_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 319 = oaio_write */
- { AS(olio_listio_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 320 = olio_listio */
+ { AS(aio_return_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_ABSENT }, /* 314 = aio_return */
+ { AS(aio_suspend_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_ABSENT }, /* 315 = aio_suspend */
+ { AS(aio_cancel_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_ABSENT }, /* 316 = aio_cancel */
+ { AS(aio_error_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_ABSENT }, /* 317 = aio_error */
+ { AS(oaio_read_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_ABSENT }, /* 318 = oaio_read */
+ { AS(oaio_write_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_ABSENT }, /* 319 = oaio_write */
+ { AS(olio_listio_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_ABSENT }, /* 320 = olio_listio */
{ 0, (sy_call_t *)sys_yield, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 321 = yield */
{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 322 = obsolete thr_sleep */
{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 323 = obsolete thr_wakeup */
@@ -368,7 +368,7 @@
{ 0, (sy_call_t *)sys_sched_yield, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 331 = sched_yield */
{ AS(sched_get_priority_max_args), (sy_call_t *)sys_sched_get_priority_max, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 332 = sched_get_priority_max */
{ AS(sched_get_priority_min_args), (sy_call_t *)sys_sched_get_priority_min, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 333 = sched_get_priority_min */
- { AS(sched_rr_get_interval_args), (sy_call_t *)sys_sched_rr_get_interval, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC }, /* 334 = sched_rr_get_interval */
+ { AS(sched_rr_get_interval_args), (sy_call_t *)sys_sched_rr_get_interval, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 334 = sched_rr_get_interval */
{ AS(utrace_args), (sy_call_t *)sys_utrace, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 335 = utrace */
{ compat4(AS(freebsd4_sendfile_args),sendfile), AUE_SENDFILE, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 336 = freebsd4 sendfile */
{ AS(kldsym_args), (sy_call_t *)sys_kldsym, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC }, /* 337 = kldsym */
@@ -393,7 +393,7 @@
{ AS(extattr_set_file_args), (sy_call_t *)sys_extattr_set_file, AUE_EXTATTR_SET_FILE, NULL, 0, 0, 0, SY_THR_STATIC }, /* 356 = extattr_set_file */
{ AS(extattr_get_file_args), (sy_call_t *)sys_extattr_get_file, AUE_EXTATTR_GET_FILE, NULL, 0, 0, 0, SY_THR_STATIC }, /* 357 = extattr_get_file */
{ AS(extattr_delete_file_args), (sy_call_t *)sys_extattr_delete_file, AUE_EXTATTR_DELETE_FILE, NULL, 0, 0, 0, SY_THR_STATIC }, /* 358 = extattr_delete_file */
- { AS(aio_waitcomplete_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 359 = aio_waitcomplete */
+ { AS(aio_waitcomplete_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_ABSENT }, /* 359 = aio_waitcomplete */
{ AS(getresuid_args), (sy_call_t *)sys_getresuid, AUE_GETRESUID, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 360 = getresuid */
{ AS(getresgid_args), (sy_call_t *)sys_getresgid, AUE_GETRESGID, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 361 = getresgid */
{ 0, (sy_call_t *)sys_kqueue, AUE_KQUEUE, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 362 = kqueue */
@@ -463,7 +463,7 @@
{ AS(__acl_set_link_args), (sy_call_t *)sys___acl_set_link, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC }, /* 426 = __acl_set_link */
{ AS(__acl_delete_link_args), (sy_call_t *)sys___acl_delete_link, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC }, /* 427 = __acl_delete_link */
{ AS(__acl_aclcheck_link_args), (sy_call_t *)sys___acl_aclcheck_link, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC }, /* 428 = __acl_aclcheck_link */
- { AS(sigwait_args), (sy_call_t *)sys_sigwait, AUE_SIGWAIT, NULL, 0, 0, 0, SY_THR_STATIC }, /* 429 = sigwait */
+ { AS(sigwait_args), (sy_call_t *)sys_sigwait, AUE_SIGWAIT, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 429 = sigwait */
{ AS(thr_create_args), (sy_call_t *)sys_thr_create, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 430 = thr_create */
{ AS(thr_exit_args), (sy_call_t *)sys_thr_exit, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 431 = thr_exit */
{ AS(thr_self_args), (sy_call_t *)sys_thr_self, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 432 = thr_self */
@@ -492,23 +492,23 @@
{ AS(thr_new_args), (sy_call_t *)sys_thr_new, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 455 = thr_new */
{ AS(sigqueue_args), (sy_call_t *)sys_sigqueue, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 456 = sigqueue */
{ AS(kmq_open_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 457 = kmq_open */
- { AS(kmq_setattr_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 458 = kmq_setattr */
- { AS(kmq_timedreceive_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 459 = kmq_timedreceive */
- { AS(kmq_timedsend_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 460 = kmq_timedsend */
- { AS(kmq_notify_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 461 = kmq_notify */
+ { AS(kmq_setattr_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_ABSENT }, /* 458 = kmq_setattr */
+ { AS(kmq_timedreceive_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_ABSENT }, /* 459 = kmq_timedreceive */
+ { AS(kmq_timedsend_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_ABSENT }, /* 460 = kmq_timedsend */
+ { AS(kmq_notify_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_ABSENT }, /* 461 = kmq_notify */
{ AS(kmq_unlink_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 462 = kmq_unlink */
{ AS(abort2_args), (sy_call_t *)sys_abort2, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 463 = abort2 */
{ AS(thr_set_name_args), (sy_call_t *)sys_thr_set_name, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 464 = thr_set_name */
- { AS(aio_fsync_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 465 = aio_fsync */
+ { AS(aio_fsync_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_ABSENT }, /* 465 = aio_fsync */
{ AS(rtprio_thread_args), (sy_call_t *)sys_rtprio_thread, AUE_RTPRIO, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 466 = rtprio_thread */
{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 467 = nosys */
{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 468 = nosys */
{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 469 = __getpath_fromfd */
{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 470 = __getpath_fromaddr */
- { AS(sctp_peeloff_args), (sy_call_t *)sys_sctp_peeloff, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 471 = sctp_peeloff */
- { AS(sctp_generic_sendmsg_args), (sy_call_t *)sys_sctp_generic_sendmsg, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 472 = sctp_generic_sendmsg */
- { AS(sctp_generic_sendmsg_iov_args), (sy_call_t *)sys_sctp_generic_sendmsg_iov, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 473 = sctp_generic_sendmsg_iov */
- { AS(sctp_generic_recvmsg_args), (sy_call_t *)sys_sctp_generic_recvmsg, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 474 = sctp_generic_recvmsg */
+ { AS(sctp_peeloff_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_ABSENT }, /* 471 = sctp_peeloff */
+ { AS(sctp_generic_sendmsg_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_ABSENT }, /* 472 = sctp_generic_sendmsg */
+ { AS(sctp_generic_sendmsg_iov_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_ABSENT }, /* 473 = sctp_generic_sendmsg_iov */
+ { AS(sctp_generic_recvmsg_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_ABSENT }, /* 474 = sctp_generic_recvmsg */
{ AS(pread_args), (sy_call_t *)sys_pread, AUE_PREAD, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 475 = pread */
{ AS(pwrite_args), (sy_call_t *)sys_pwrite, AUE_PWRITE, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 476 = pwrite */
{ AS(mmap_args), (sy_call_t *)sys_mmap, AUE_MMAP, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 477 = mmap */
@@ -525,19 +525,19 @@
{ AS(cpuset_setaffinity_args), (sy_call_t *)sys_cpuset_setaffinity, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC }, /* 488 = cpuset_setaffinity */
{ AS(faccessat_args), (sy_call_t *)sys_faccessat, AUE_FACCESSAT, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 489 = faccessat */
{ AS(fchmodat_args), (sy_call_t *)sys_fchmodat, AUE_FCHMODAT, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 490 = fchmodat */
- { AS(fchownat_args), (sy_call_t *)sys_fchownat, AUE_FCHOWNAT, NULL, 0, 0, 0, SY_THR_STATIC }, /* 491 = fchownat */
+ { AS(fchownat_args), (sy_call_t *)sys_fchownat, AUE_FCHOWNAT, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 491 = fchownat */
{ AS(fexecve_args), (sy_call_t *)sys_fexecve, AUE_FEXECVE, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 492 = fexecve */
{ AS(fstatat_args), (sy_call_t *)sys_fstatat, AUE_FSTATAT, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 493 = fstatat */
{ AS(futimesat_args), (sy_call_t *)sys_futimesat, AUE_FUTIMESAT, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 494 = futimesat */
- { AS(linkat_args), (sy_call_t *)sys_linkat, AUE_LINKAT, NULL, 0, 0, 0, SY_THR_STATIC }, /* 495 = linkat */
+ { AS(linkat_args), (sy_call_t *)sys_linkat, AUE_LINKAT, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 495 = linkat */
{ AS(mkdirat_args), (sy_call_t *)sys_mkdirat, AUE_MKDIRAT, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 496 = mkdirat */
{ AS(mkfifoat_args), (sy_call_t *)sys_mkfifoat, AUE_MKFIFOAT, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 497 = mkfifoat */
{ AS(mknodat_args), (sy_call_t *)sys_mknodat, AUE_MKNODAT, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 498 = mknodat */
{ AS(openat_args), (sy_call_t *)sys_openat, AUE_OPENAT_RWTC, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 499 = openat */
- { AS(readlinkat_args), (sy_call_t *)sys_readlinkat, AUE_READLINKAT, NULL, 0, 0, 0, SY_THR_STATIC }, /* 500 = readlinkat */
+ { AS(readlinkat_args), (sy_call_t *)sys_readlinkat, AUE_READLINKAT, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 500 = readlinkat */
{ AS(renameat_args), (sy_call_t *)sys_renameat, AUE_RENAMEAT, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 501 = renameat */
- { AS(symlinkat_args), (sy_call_t *)sys_symlinkat, AUE_SYMLINKAT, NULL, 0, 0, 0, SY_THR_STATIC }, /* 502 = symlinkat */
- { AS(unlinkat_args), (sy_call_t *)sys_unlinkat, AUE_UNLINKAT, NULL, 0, 0, 0, SY_THR_STATIC }, /* 503 = unlinkat */
+ { AS(symlinkat_args), (sy_call_t *)sys_symlinkat, AUE_SYMLINKAT, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 502 = symlinkat */
+ { AS(unlinkat_args), (sy_call_t *)sys_unlinkat, AUE_UNLINKAT, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 503 = unlinkat */
{ AS(posix_openpt_args), (sy_call_t *)sys_posix_openpt, AUE_POSIX_OPENPT, NULL, 0, 0, 0, SY_THR_STATIC }, /* 504 = posix_openpt */
{ AS(gssd_syscall_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 505 = gssd_syscall */
{ AS(jail_get_args), (sy_call_t *)sys_jail_get, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC }, /* 506 = jail_get */
@@ -548,8 +548,8 @@
{ AS(msgctl_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 511 = msgctl */
{ AS(shmctl_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 512 = shmctl */
{ AS(lpathconf_args), (sy_call_t *)sys_lpathconf, AUE_LPATHCONF, NULL, 0, 0, 0, SY_THR_STATIC }, /* 513 = lpathconf */
- { AS(cap_new_args), (sy_call_t *)sys_cap_new, AUE_CAP_NEW, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 514 = cap_new */
- { AS(cap_getrights_args), (sy_call_t *)sys_cap_getrights, AUE_CAP_GETRIGHTS, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 515 = cap_getrights */
+ { 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 514 = obsolete cap_new */
+ { AS(__cap_rights_get_args), (sy_call_t *)sys___cap_rights_get, AUE_CAP_RIGHTS_GET, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 515 = __cap_rights_get */
{ 0, (sy_call_t *)sys_cap_enter, AUE_CAP_ENTER, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 516 = cap_enter */
{ AS(cap_getmode_args), (sy_call_t *)sys_cap_getmode, AUE_CAP_GETMODE, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 517 = cap_getmode */
{ AS(pdfork_args), (sy_call_t *)sys_pdfork, AUE_PDFORK, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 518 = pdfork */
@@ -556,7 +556,7 @@
{ AS(pdkill_args), (sy_call_t *)sys_pdkill, AUE_PDKILL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 519 = pdkill */
{ AS(pdgetpid_args), (sy_call_t *)sys_pdgetpid, AUE_PDGETPID, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 520 = pdgetpid */
{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 521 = pdwait4 */
- { AS(pselect_args), (sy_call_t *)sys_pselect, AUE_SELECT, NULL, 0, 0, 0, SY_THR_STATIC }, /* 522 = pselect */
+ { AS(pselect_args), (sy_call_t *)sys_pselect, AUE_SELECT, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 522 = pselect */
{ AS(getloginclass_args), (sy_call_t *)sys_getloginclass, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC }, /* 523 = getloginclass */
{ AS(setloginclass_args), (sy_call_t *)sys_setloginclass, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC }, /* 524 = setloginclass */
{ AS(rctl_get_racct_args), (sy_call_t *)sys_rctl_get_racct, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC }, /* 525 = rctl_get_racct */
@@ -567,4 +567,19 @@
{ AS(posix_fallocate_args), (sy_call_t *)sys_posix_fallocate, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC }, /* 530 = posix_fallocate */
{ AS(posix_fadvise_args), (sy_call_t *)sys_posix_fadvise, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC }, /* 531 = posix_fadvise */
{ AS(wait6_args), (sy_call_t *)sys_wait6, AUE_WAIT6, NULL, 0, 0, 0, SY_THR_STATIC }, /* 532 = wait6 */
+ { AS(cap_rights_limit_args), (sy_call_t *)sys_cap_rights_limit, AUE_CAP_RIGHTS_LIMIT, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 533 = cap_rights_limit */
+ { AS(cap_ioctls_limit_args), (sy_call_t *)sys_cap_ioctls_limit, AUE_CAP_IOCTLS_LIMIT, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 534 = cap_ioctls_limit */
+ { AS(cap_ioctls_get_args), (sy_call_t *)sys_cap_ioctls_get, AUE_CAP_IOCTLS_GET, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 535 = cap_ioctls_get */
+ { AS(cap_fcntls_limit_args), (sy_call_t *)sys_cap_fcntls_limit, AUE_CAP_FCNTLS_LIMIT, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 536 = cap_fcntls_limit */
+ { AS(cap_fcntls_get_args), (sy_call_t *)sys_cap_fcntls_get, AUE_CAP_FCNTLS_GET, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 537 = cap_fcntls_get */
+ { AS(bindat_args), (sy_call_t *)sys_bindat, AUE_BINDAT, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 538 = bindat */
+ { AS(connectat_args), (sy_call_t *)sys_connectat, AUE_CONNECTAT, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 539 = connectat */
+ { AS(chflagsat_args), (sy_call_t *)sys_chflagsat, AUE_CHFLAGSAT, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 540 = chflagsat */
+ { AS(accept4_args), (sy_call_t *)sys_accept4, AUE_ACCEPT, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 541 = accept4 */
+ { AS(pipe2_args), (sy_call_t *)sys_pipe2, AUE_PIPE, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 542 = pipe2 */
+ { AS(aio_mlock_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT }, /* 543 = aio_mlock */
+ { AS(procctl_args), (sy_call_t *)sys_procctl, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC }, /* 544 = procctl */
+ { AS(ppoll_args), (sy_call_t *)sys_ppoll, AUE_POLL, NULL, 0, 0, 0, SY_THR_STATIC }, /* 545 = ppoll */
+ { AS(futimens_args), (sy_call_t *)sys_futimens, AUE_FUTIMES, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 546 = futimens */
+ { AS(utimensat_args), (sy_call_t *)sys_utimensat, AUE_FUTIMESAT, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC }, /* 547 = utimensat */
};
Modified: trunk/sys/kern/kern_acct.c
===================================================================
--- trunk/sys/kern/kern_acct.c 2018-05-25 20:34:19 UTC (rev 9942)
+++ trunk/sys/kern/kern_acct.c 2018-05-25 20:39:59 UTC (rev 9943)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1982, 1986, 1989, 1993
* The Regents of the University of California. All rights reserved.
@@ -68,7 +69,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/kern/kern_acct.c 252422 2013-06-30 19:08:06Z mjg $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -133,6 +134,7 @@
static int acct_suspended;
static struct vnode *acct_vp;
static struct ucred *acct_cred;
+static struct plimit *acct_limit;
static int acct_flags;
static struct sx acct_sx;
@@ -196,7 +198,7 @@
sys_acct(struct thread *td, struct acct_args *uap)
{
struct nameidata nd;
- int error, flags, vfslocked, replacing;
+ int error, flags, i, replacing;
error = priv_check(td, PRIV_ACCT);
if (error)
@@ -207,13 +209,12 @@
* appending and make sure it's a 'normal'.
*/
if (uap->path != NULL) {
- NDINIT(&nd, LOOKUP, NOFOLLOW | MPSAFE | AUDITVNODE1,
+ NDINIT(&nd, LOOKUP, NOFOLLOW | AUDITVNODE1,
UIO_USERSPACE, uap->path, td);
flags = FWRITE | O_APPEND;
error = vn_open(&nd, &flags, 0, NULL);
if (error)
return (error);
- vfslocked = NDHASGIANT(&nd);
NDFREE(&nd, NDF_ONLY_PNBUF);
#ifdef MAC
error = mac_system_check_acct(td->td_ucred, nd.ni_vp);
@@ -220,7 +221,6 @@
if (error) {
VOP_UNLOCK(nd.ni_vp, 0);
vn_close(nd.ni_vp, flags, td->td_ucred, td);
- VFS_UNLOCK_GIANT(vfslocked);
return (error);
}
#endif
@@ -227,10 +227,8 @@
VOP_UNLOCK(nd.ni_vp, 0);
if (nd.ni_vp->v_type != VREG) {
vn_close(nd.ni_vp, flags, td->td_ucred, td);
- VFS_UNLOCK_GIANT(vfslocked);
return (EACCES);
}
- VFS_UNLOCK_GIANT(vfslocked);
#ifdef MAC
} else {
error = mac_system_check_acct(td->td_ucred, NULL);
@@ -259,11 +257,8 @@
* enabled.
*/
acct_suspended = 0;
- if (acct_vp != NULL) {
- vfslocked = VFS_LOCK_GIANT(acct_vp->v_mount);
+ if (acct_vp != NULL)
error = acct_disable(td, !replacing);
- VFS_UNLOCK_GIANT(vfslocked);
- }
if (uap->path == NULL) {
if (acct_state & ACCT_RUNNING) {
acct_state |= ACCT_EXITREQ;
@@ -274,6 +269,15 @@
}
/*
+ * Create our own plimit object without limits. It will be assigned
+ * to exiting processes.
+ */
+ acct_limit = lim_alloc();
+ for (i = 0; i < RLIM_NLIMITS; i++)
+ acct_limit->pl_rlimit[i].rlim_cur =
+ acct_limit->pl_rlimit[i].rlim_max = RLIM_INFINITY;
+
+ /*
* Save the new accounting file vnode, and schedule the new
* free space watcher.
*/
@@ -291,14 +295,7 @@
error = kproc_create(acct_thread, NULL, NULL, 0, 0,
"accounting");
if (error) {
- vfslocked = VFS_LOCK_GIANT(acct_vp->v_mount);
- (void) vn_close(acct_vp, acct_flags, acct_cred, td);
- VFS_UNLOCK_GIANT(vfslocked);
- crfree(acct_cred);
- acct_configured = 0;
- acct_vp = NULL;
- acct_cred = NULL;
- acct_flags = 0;
+ (void) acct_disable(td, 0);
sx_xunlock(&acct_sx);
log(LOG_NOTICE, "Unable to start accounting thread\n");
return (error);
@@ -323,6 +320,7 @@
sx_assert(&acct_sx, SX_XLOCKED);
error = vn_close(acct_vp, acct_flags, acct_cred, td);
crfree(acct_cred);
+ lim_free(acct_limit);
acct_configured = 0;
acct_vp = NULL;
acct_cred = NULL;
@@ -343,10 +341,10 @@
{
struct acctv2 acct;
struct timeval ut, st, tmp;
- struct plimit *newlim, *oldlim;
+ struct plimit *oldlim;
struct proc *p;
struct rusage ru;
- int t, ret, vfslocked;
+ int t, ret;
/*
* Lockless check of accounting condition before doing the hard
@@ -419,7 +417,6 @@
/* (8) The boolean flags that tell how the process terminated, etc. */
acct.ac_flagx = p->p_acflag;
- PROC_UNLOCK(p);
/* Setup ancillary structure fields. */
acct.ac_flagx |= ANVER;
@@ -428,14 +425,10 @@
acct.ac_len = acct.ac_len2 = sizeof(acct);
/*
- * Eliminate any file size rlimit.
+ * Eliminate rlimits (file size limit in particular).
*/
- newlim = lim_alloc();
- PROC_LOCK(p);
oldlim = p->p_limit;
- lim_copy(newlim, oldlim);
- newlim->pl_rlimit[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
- p->p_limit = newlim;
+ p->p_limit = lim_hold(acct_limit);
PROC_UNLOCK(p);
lim_free(oldlim);
@@ -442,11 +435,9 @@
/*
* Write the accounting information to the file.
*/
- vfslocked = VFS_LOCK_GIANT(acct_vp->v_mount);
ret = vn_rdwr(UIO_WRITE, acct_vp, (caddr_t)&acct, sizeof (acct),
(off_t)0, UIO_SYSSPACE, IO_APPEND|IO_UNIT, acct_cred, NOCRED,
NULL, td);
- VFS_UNLOCK_GIANT(vfslocked);
sx_sunlock(&acct_sx);
return (ret);
}
@@ -563,7 +554,6 @@
acctwatch(void)
{
struct statfs sb;
- int vfslocked;
sx_assert(&acct_sx, SX_XLOCKED);
@@ -581,10 +571,8 @@
* If our vnode is no longer valid, tear it down and signal the
* accounting thread to die.
*/
- vfslocked = VFS_LOCK_GIANT(acct_vp->v_mount);
if (acct_vp->v_type == VBAD) {
(void) acct_disable(NULL, 1);
- VFS_UNLOCK_GIANT(vfslocked);
acct_state |= ACCT_EXITREQ;
return;
}
@@ -593,11 +581,8 @@
* Stopping here is better than continuing, maybe it will be VBAD
* next time around.
*/
- if (VFS_STATFS(acct_vp->v_mount, &sb) < 0) {
- VFS_UNLOCK_GIANT(vfslocked);
+ if (VFS_STATFS(acct_vp->v_mount, &sb) < 0)
return;
- }
- VFS_UNLOCK_GIANT(vfslocked);
if (acct_suspended) {
if (sb.f_bavail > (int64_t)(acctresume * sb.f_blocks /
100)) {
Modified: trunk/sys/kern/kern_alq.c
===================================================================
--- trunk/sys/kern/kern_alq.c 2018-05-25 20:34:19 UTC (rev 9942)
+++ trunk/sys/kern/kern_alq.c 2018-05-25 20:39:59 UTC (rev 9943)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2002, Jeffrey Roberson <jeff at freebsd.org>
* Copyright (c) 2008-2009, Lawrence Stewart <lstewart at freebsd.org>
@@ -31,7 +32,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/kern/kern_alq.c 264366 2014-04-12 06:50:11Z dchagin $");
#include "opt_mac.h"
@@ -99,6 +100,7 @@
static int ald_shutingdown = 0;
struct thread *ald_thread;
static struct proc *ald_proc;
+static eventhandler_tag alq_eventhandler_tag = NULL;
#define ALD_LOCK() mtx_lock(&ald_mtx)
#define ALD_UNLOCK() mtx_unlock(&ald_mtx)
@@ -194,8 +196,8 @@
ald_thread = FIRST_THREAD_IN_PROC(ald_proc);
- EVENTHANDLER_REGISTER(shutdown_pre_sync, ald_shutdown, NULL,
- SHUTDOWN_PRI_FIRST);
+ alq_eventhandler_tag = EVENTHANDLER_REGISTER(shutdown_pre_sync,
+ ald_shutdown, NULL, SHUTDOWN_PRI_FIRST);
ALD_LOCK();
@@ -313,7 +315,6 @@
struct iovec aiov[2];
int totlen;
int iov;
- int vfslocked;
int wrapearly;
KASSERT((HAS_PENDING_DATA(alq)), ("%s: queue empty!", __func__));
@@ -365,7 +366,6 @@
/*
* Do all of the junk required to write now.
*/
- vfslocked = VFS_LOCK_GIANT(vp->v_mount);
vn_start_write(vp, &mp, V_WAIT);
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
/*
@@ -377,7 +377,6 @@
VOP_WRITE(vp, &auio, IO_UNIT | IO_APPEND, alq->aq_cred);
VOP_UNLOCK(vp, 0);
vn_finished_write(mp);
- VFS_UNLOCK_GIANT(vfslocked);
ALQ_LOCK(alq);
alq->aq_flags &= ~AQ_FLUSHING;
@@ -438,7 +437,6 @@
struct alq *alq;
int oflags;
int error;
- int vfslocked;
KASSERT((size > 0), ("%s: size <= 0", __func__));
@@ -445,7 +443,7 @@
*alqp = NULL;
td = curthread;
- NDINIT(&nd, LOOKUP, NOFOLLOW | MPSAFE, UIO_SYSSPACE, file, td);
+ NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_SYSSPACE, file, td);
oflags = FWRITE | O_NOFOLLOW | O_CREAT;
error = vn_open_cred(&nd, &oflags, cmode, 0, cred, NULL);
@@ -452,11 +450,9 @@
if (error)
return (error);
- vfslocked = NDHASGIANT(&nd);
NDFREE(&nd, NDF_ONLY_PNBUF);
/* We just unlock so we hold a reference */
VOP_UNLOCK(nd.ni_vp, 0);
- VFS_UNLOCK_GIANT(vfslocked);
alq = malloc(sizeof(*alq), M_ALD, M_WAITOK|M_ZERO);
alq->aq_vp = nd.ni_vp;
@@ -493,10 +489,12 @@
KASSERT((count >= 0), ("%s: count < 0", __func__));
if (count > 0) {
- ret = alq_open_flags(alqp, file, cred, cmode, size*count, 0);
- (*alqp)->aq_flags |= AQ_LEGACY;
- (*alqp)->aq_entmax = count;
- (*alqp)->aq_entlen = size;
+ if ((ret = alq_open_flags(alqp, file, cred, cmode,
+ size*count, 0)) == 0) {
+ (*alqp)->aq_flags |= AQ_LEGACY;
+ (*alqp)->aq_entmax = count;
+ (*alqp)->aq_entlen = size;
+ }
} else
ret = alq_open_flags(alqp, file, cred, cmode, size, 0);
@@ -941,6 +939,8 @@
if (LIST_FIRST(&ald_queues) == NULL) {
ald_shutingdown = 1;
ALD_UNLOCK();
+ EVENTHANDLER_DEREGISTER(shutdown_pre_sync,
+ alq_eventhandler_tag);
ald_shutdown(NULL, 0);
mtx_destroy(&ald_mtx);
} else {
Modified: trunk/sys/kern/kern_clock.c
===================================================================
--- trunk/sys/kern/kern_clock.c 2018-05-25 20:34:19 UTC (rev 9942)
+++ trunk/sys/kern/kern_clock.c 2018-05-25 20:39:59 UTC (rev 9943)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1982, 1986, 1991, 1993
* The Regents of the University of California. All rights reserved.
@@ -35,7 +36,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/kern/kern_clock.c 293473 2016-01-09 14:08:10Z dchagin $");
#include "opt_kdb.h"
#include "opt_device_polling.h"
@@ -93,7 +94,7 @@
static struct mtx time_lock;
SDT_PROVIDER_DECLARE(sched);
-SDT_PROBE_DEFINE2(sched, , , tick, tick, "struct thread *", "struct proc *");
+SDT_PROBE_DEFINE2(sched, , , tick, "struct thread *", "struct proc *");
static int
sysctl_kern_cp_time(SYSCTL_HANDLER_ARGS)
@@ -216,13 +217,8 @@
}
FOREACH_THREAD_IN_PROC(p, td) {
- /*
- * Once a thread is found in "interesting"
- * state a possible ticks wrap-up needs to be
- * checked.
- */
thread_lock(td);
- if (TD_ON_LOCK(td) && ticks < td->td_blktick) {
+ if (TD_ON_LOCK(td)) {
/*
* The thread should be blocked on a
@@ -247,8 +243,7 @@
__func__, td, tticks);
}
} else if (TD_IS_SLEEPING(td) &&
- TD_ON_SLEEPQ(td) &&
- ticks < td->td_blktick) {
+ TD_ON_SLEEPQ(td)) {
/*
* Check if the thread is sleeping on a
@@ -439,16 +434,16 @@
flags = 0;
if (usermode &&
timevalisset(&pstats->p_timer[ITIMER_VIRTUAL].it_value)) {
- PROC_SLOCK(p);
+ PROC_ITIMLOCK(p);
if (itimerdecr(&pstats->p_timer[ITIMER_VIRTUAL], tick) == 0)
flags |= TDF_ALRMPEND | TDF_ASTPENDING;
- PROC_SUNLOCK(p);
+ PROC_ITIMUNLOCK(p);
}
if (timevalisset(&pstats->p_timer[ITIMER_PROF].it_value)) {
- PROC_SLOCK(p);
+ PROC_ITIMLOCK(p);
if (itimerdecr(&pstats->p_timer[ITIMER_PROF], tick) == 0)
flags |= TDF_PROFPEND | TDF_ASTPENDING;
- PROC_SUNLOCK(p);
+ PROC_ITIMUNLOCK(p);
}
thread_lock(td);
sched_tick(1);
@@ -461,7 +456,7 @@
if (td->td_intr_frame != NULL)
PMC_SOFT_CALL_TF( , , clock, hard, td->td_intr_frame);
#endif
- callout_tick();
+ callout_process(sbinuptime());
}
/*
@@ -527,18 +522,18 @@
flags = 0;
if (usermode &&
timevalisset(&pstats->p_timer[ITIMER_VIRTUAL].it_value)) {
- PROC_SLOCK(p);
+ PROC_ITIMLOCK(p);
if (itimerdecr(&pstats->p_timer[ITIMER_VIRTUAL],
tick * cnt) == 0)
flags |= TDF_ALRMPEND | TDF_ASTPENDING;
- PROC_SUNLOCK(p);
+ PROC_ITIMUNLOCK(p);
}
if (timevalisset(&pstats->p_timer[ITIMER_PROF].it_value)) {
- PROC_SLOCK(p);
+ PROC_ITIMLOCK(p);
if (itimerdecr(&pstats->p_timer[ITIMER_PROF],
tick * cnt) == 0)
flags |= TDF_PROFPEND | TDF_ASTPENDING;
- PROC_SUNLOCK(p);
+ PROC_ITIMUNLOCK(p);
}
thread_lock(td);
sched_tick(cnt);
@@ -551,7 +546,6 @@
if (td->td_intr_frame != NULL)
PMC_SOFT_CALL_TF( , , clock, hard, td->td_intr_frame);
#endif
- callout_tick();
/* We are in charge to handle this tick duty. */
if (newticks > 0) {
/* Dangerous and no need to call these things concurrently. */
@@ -676,11 +670,11 @@
PROC_LOCK_ASSERT(p, MA_OWNED);
if (p->p_flag & P_PROFIL) {
if (p->p_profthreads != 0) {
- p->p_flag |= P_STOPPROF;
- while (p->p_profthreads != 0)
+ while (p->p_profthreads != 0) {
+ p->p_flag |= P_STOPPROF;
msleep(&p->p_profthreads, &p->p_mtx, PPAUSE,
"stopprof", 0);
- p->p_flag &= ~P_STOPPROF;
+ }
}
if ((p->p_flag & P_PROFIL) == 0)
return;
Modified: trunk/sys/kern/kern_clocksource.c
===================================================================
--- trunk/sys/kern/kern_clocksource.c 2018-05-25 20:34:19 UTC (rev 9942)
+++ trunk/sys/kern/kern_clocksource.c 2018-05-25 20:39:59 UTC (rev 9943)
@@ -1,5 +1,6 @@
+/* $MidnightBSD$ */
/*-
- * Copyright (c) 2010-2012 Alexander Motin <mav at FreeBSD.org>
+ * Copyright (c) 2010-2013 Alexander Motin <mav at FreeBSD.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -25,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: release/9.2.0/sys/kern/kern_clocksource.c 250600 2013-05-13 15:18:36Z fabient $");
+__FBSDID("$FreeBSD: stable/10/sys/kern/kern_clocksource.c 315255 2017-03-14 15:37:29Z hselasky $");
/*
* Common routines to manage event timers hardware.
@@ -37,6 +38,7 @@
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/bus.h>
+#include <sys/limits.h>
#include <sys/lock.h>
#include <sys/kdb.h>
#include <sys/ktr.h>
@@ -54,26 +56,19 @@
#include <machine/cpu.h>
#include <machine/smp.h>
-#ifdef KDTRACE_HOOKS
-#include <sys/dtrace_bsd.h>
-cyclic_clock_func_t cyclic_clock_func = NULL;
-#endif
+int cpu_deepest_sleep = 0; /* Deepest Cx state available. */
+int cpu_disable_c2_sleep = 0; /* Timer dies in C2. */
+int cpu_disable_c3_sleep = 0; /* Timer dies in C3. */
-int cpu_can_deep_sleep = 0; /* C3 state is available. */
-int cpu_disable_deep_sleep = 0; /* Timer dies in C3. */
-
static void setuptimer(void);
-static void loadtimer(struct bintime *now, int first);
+static void loadtimer(sbintime_t now, int first);
static int doconfigtimer(void);
static void configtimer(int start);
static int round_freq(struct eventtimer *et, int freq);
-static void getnextcpuevent(struct bintime *event, int idle);
-static void getnextevent(struct bintime *event);
-static int handleevents(struct bintime *now, int fake);
-#ifdef SMP
-static void cpu_new_callout(int cpu, int ticks);
-#endif
+static sbintime_t getnextcpuevent(int idle);
+static sbintime_t getnextevent(void);
+static int handleevents(sbintime_t now, int fake);
static struct mtx et_hw_mtx;
@@ -94,13 +89,11 @@
}
static struct eventtimer *timer = NULL;
-static struct bintime timerperiod; /* Timer period for periodic mode. */
-static struct bintime hardperiod; /* hardclock() events period. */
-static struct bintime statperiod; /* statclock() events period. */
-static struct bintime profperiod; /* profclock() events period. */
-static struct bintime nexttick; /* Next global timer tick time. */
-static struct bintime nexthard; /* Next global hardlock() event. */
-static u_int busy = 0; /* Reconfiguration is in progress. */
+static sbintime_t timerperiod; /* Timer period for periodic mode. */
+static sbintime_t statperiod; /* statclock() events period. */
+static sbintime_t profperiod; /* profclock() events period. */
+static sbintime_t nexttick; /* Next global timer tick time. */
+static u_int busy = 1; /* Reconfiguration is in progress. */
static int profiling = 0; /* Profiling events enabled. */
static char timername[32]; /* Wanted timer. */
@@ -116,11 +109,6 @@
SYSCTL_UINT(_kern_eventtimer, OID_AUTO, idletick, CTLFLAG_RW, &idletick,
0, "Run periodic events when idle");
-static u_int activetick = 1; /* Run all periodic events when active. */
-TUNABLE_INT("kern.eventtimer.activetick", &activetick);
-SYSCTL_UINT(_kern_eventtimer, OID_AUTO, activetick, CTLFLAG_RW, &activetick,
- 0, "Run all periodic events when active");
-
static int periodic = 0; /* Periodic or one-shot mode. */
static int want_periodic = 0; /* What mode to prefer. */
TUNABLE_INT("kern.eventtimer.periodic", &want_periodic);
@@ -129,30 +117,21 @@
struct mtx et_hw_mtx; /* Per-CPU timer mutex. */
u_int action; /* Reconfiguration requests. */
u_int handle; /* Immediate handle resuests. */
- struct bintime now; /* Last tick time. */
- struct bintime nextevent; /* Next scheduled event on this CPU. */
- struct bintime nexttick; /* Next timer tick time. */
- struct bintime nexthard; /* Next hardlock() event. */
- struct bintime nextstat; /* Next statclock() event. */
- struct bintime nextprof; /* Next profclock() event. */
-#ifdef KDTRACE_HOOKS
- struct bintime nextcyc; /* Next OpenSolaris cyclics event. */
-#endif
+ sbintime_t now; /* Last tick time. */
+ sbintime_t nextevent; /* Next scheduled event on this CPU. */
+ sbintime_t nexttick; /* Next timer tick time. */
+ sbintime_t nexthard; /* Next hardlock() event. */
+ sbintime_t nextstat; /* Next statclock() event. */
+ sbintime_t nextprof; /* Next profclock() event. */
+ sbintime_t nextcall; /* Next callout event. */
+ sbintime_t nextcallopt; /* Next optional callout event. */
int ipi; /* This CPU needs IPI. */
int idle; /* This CPU is in idle mode. */
};
static DPCPU_DEFINE(struct pcpu_state, timerstate);
+DPCPU_DEFINE(sbintime_t, hardclocktime);
-#define FREQ2BT(freq, bt) \
-{ \
- (bt)->sec = 0; \
- (bt)->frac = ((uint64_t)0x8000000000000000 / (freq)) << 1; \
-}
-#define BT2FREQ(bt) \
- (((uint64_t)0x8000000000000000 + ((bt)->frac >> 2)) / \
- ((bt)->frac >> 1))
-
/*
* Timer broadcast IPI handler.
*/
@@ -159,7 +138,7 @@
int
hardclockintr(void)
{
- struct bintime now;
+ sbintime_t now;
struct pcpu_state *state;
int done;
@@ -167,10 +146,9 @@
return (FILTER_HANDLED);
state = DPCPU_PTR(timerstate);
now = state->now;
- CTR4(KTR_SPARE2, "ipi at %d: now %d.%08x%08x",
- curcpu, now.sec, (unsigned int)(now.frac >> 32),
- (unsigned int)(now.frac & 0xffffffff));
- done = handleevents(&now, 0);
+ CTR3(KTR_SPARE2, "ipi at %d: now %d.%08x",
+ curcpu, (int)(now >> 32), (u_int)(now & 0xffffffff));
+ done = handleevents(now, 0);
return (done ? FILTER_HANDLED : FILTER_STRAY);
}
@@ -178,46 +156,43 @@
* Handle all events for specified time on this CPU
*/
static int
-handleevents(struct bintime *now, int fake)
+handleevents(sbintime_t now, int fake)
{
- struct bintime t;
+ sbintime_t t, *hct;
struct trapframe *frame;
struct pcpu_state *state;
- uintfptr_t pc;
int usermode;
int done, runs;
- CTR4(KTR_SPARE2, "handle at %d: now %d.%08x%08x",
- curcpu, now->sec, (unsigned int)(now->frac >> 32),
- (unsigned int)(now->frac & 0xffffffff));
+ CTR3(KTR_SPARE2, "handle at %d: now %d.%08x",
+ curcpu, (int)(now >> 32), (u_int)(now & 0xffffffff));
done = 0;
if (fake) {
frame = NULL;
usermode = 0;
- pc = 0;
} else {
frame = curthread->td_intr_frame;
usermode = TRAPF_USERMODE(frame);
- pc = TRAPF_PC(frame);
}
state = DPCPU_PTR(timerstate);
runs = 0;
- while (bintime_cmp(now, &state->nexthard, >=)) {
- bintime_add(&state->nexthard, &hardperiod);
+ while (now >= state->nexthard) {
+ state->nexthard += tick_sbt;
runs++;
}
- if ((timer->et_flags & ET_FLAGS_PERCPU) == 0 &&
- bintime_cmp(&state->nexthard, &nexthard, >))
- nexthard = state->nexthard;
- if (runs && fake < 2) {
- hardclock_cnt(runs, usermode);
- done = 1;
+ if (runs) {
+ hct = DPCPU_PTR(hardclocktime);
+ *hct = state->nexthard - tick_sbt;
+ if (fake < 2) {
+ hardclock_cnt(runs, usermode);
+ done = 1;
+ }
}
runs = 0;
- while (bintime_cmp(now, &state->nextstat, >=)) {
- bintime_add(&state->nextstat, &statperiod);
+ while (now >= state->nextstat) {
+ state->nextstat += statperiod;
runs++;
}
if (runs && fake < 2) {
@@ -226,36 +201,28 @@
}
if (profiling) {
runs = 0;
- while (bintime_cmp(now, &state->nextprof, >=)) {
- bintime_add(&state->nextprof, &profperiod);
+ while (now >= state->nextprof) {
+ state->nextprof += profperiod;
runs++;
}
if (runs && !fake) {
- profclock_cnt(runs, usermode, pc);
+ profclock_cnt(runs, usermode, TRAPF_PC(frame));
done = 1;
}
} else
state->nextprof = state->nextstat;
-
-#ifdef KDTRACE_HOOKS
- if (fake == 0 && cyclic_clock_func != NULL &&
- state->nextcyc.sec != -1 &&
- bintime_cmp(now, &state->nextcyc, >=)) {
- state->nextcyc.sec = -1;
- (*cyclic_clock_func)(frame);
+ if (now >= state->nextcallopt || now >= state->nextcall) {
+ state->nextcall = state->nextcallopt = SBT_MAX;
+ callout_process(now);
}
-#endif
- getnextcpuevent(&t, 0);
- if (fake == 2) {
- state->nextevent = t;
- return (done);
- }
+ t = getnextcpuevent(0);
ET_HW_LOCK(state);
if (!busy) {
state->idle = 0;
state->nextevent = t;
- loadtimer(now, 0);
+ loadtimer(now, (fake == 2) &&
+ (timer->et_flags & ET_FLAGS_PERCPU));
}
ET_HW_UNLOCK(state);
return (done);
@@ -264,74 +231,69 @@
/*
* Schedule binuptime of the next event on current CPU.
*/
-static void
-getnextcpuevent(struct bintime *event, int idle)
+static sbintime_t
+getnextcpuevent(int idle)
{
- struct bintime tmp;
+ sbintime_t event;
struct pcpu_state *state;
- int skip;
+ u_int hardfreq;
state = DPCPU_PTR(timerstate);
- /* Handle hardclock() events. */
- *event = state->nexthard;
- if (idle || (!activetick && !profiling &&
- (timer->et_flags & ET_FLAGS_PERCPU) == 0)) {
- skip = idle ? 4 : (stathz / 2);
- if (curcpu == CPU_FIRST() && tc_min_ticktock_freq > skip)
- skip = tc_min_ticktock_freq;
- skip = callout_tickstofirst(hz / skip) - 1;
- CTR2(KTR_SPARE2, "skip at %d: %d", curcpu, skip);
- tmp = hardperiod;
- bintime_mul(&tmp, skip);
- bintime_add(event, &tmp);
+ /* Handle hardclock() events, skipping some if CPU is idle. */
+ event = state->nexthard;
+ if (idle) {
+ hardfreq = (u_int)hz / 2;
+ if (tc_min_ticktock_freq > 2
+#ifdef SMP
+ && curcpu == CPU_FIRST()
+#endif
+ )
+ hardfreq = hz / tc_min_ticktock_freq;
+ if (hardfreq > 1)
+ event += tick_sbt * (hardfreq - 1);
}
+ /* Handle callout events. */
+ if (event > state->nextcall)
+ event = state->nextcall;
if (!idle) { /* If CPU is active - handle other types of events. */
- if (bintime_cmp(event, &state->nextstat, >))
- *event = state->nextstat;
- if (profiling && bintime_cmp(event, &state->nextprof, >))
- *event = state->nextprof;
+ if (event > state->nextstat)
+ event = state->nextstat;
+ if (profiling && event > state->nextprof)
+ event = state->nextprof;
}
-#ifdef KDTRACE_HOOKS
- if (state->nextcyc.sec != -1 && bintime_cmp(event, &state->nextcyc, >))
- *event = state->nextcyc;
-#endif
+ return (event);
}
/*
* Schedule binuptime of the next event on all CPUs.
*/
-static void
-getnextevent(struct bintime *event)
+static sbintime_t
+getnextevent(void)
{
struct pcpu_state *state;
+ sbintime_t event;
#ifdef SMP
int cpu;
#endif
- int c, nonidle;
+ int c;
state = DPCPU_PTR(timerstate);
- *event = state->nextevent;
- c = curcpu;
- nonidle = !state->idle;
+ event = state->nextevent;
+ c = -1;
+#ifdef SMP
if ((timer->et_flags & ET_FLAGS_PERCPU) == 0) {
-#ifdef SMP
CPU_FOREACH(cpu) {
- if (curcpu == cpu)
- continue;
state = DPCPU_ID_PTR(cpu, timerstate);
- nonidle += !state->idle;
- if (bintime_cmp(event, &state->nextevent, >)) {
- *event = state->nextevent;
+ if (event > state->nextevent) {
+ event = state->nextevent;
c = cpu;
}
}
+ }
#endif
- if (nonidle != 0 && bintime_cmp(event, &nexthard, >))
- *event = nexthard;
- }
- CTR5(KTR_SPARE2, "next at %d: next %d.%08x%08x by %d",
- curcpu, event->sec, (unsigned int)(event->frac >> 32),
- (unsigned int)(event->frac & 0xffffffff), c);
+ CTR4(KTR_SPARE2, "next at %d: next %d.%08x by %d",
+ curcpu, (int)(event >> 32), (u_int)(event & 0xffffffff), c);
+ return (event);
}
/* Hardware timer callback function. */
@@ -338,8 +300,8 @@
static void
timercb(struct eventtimer *et, void *arg)
{
- struct bintime now;
- struct bintime *next;
+ sbintime_t now;
+ sbintime_t *next;
struct pcpu_state *state;
#ifdef SMP
int cpu, bcast;
@@ -354,17 +316,14 @@
next = &state->nexttick;
} else
next = &nexttick;
- if (periodic) {
- now = *next; /* Ex-next tick time becomes present time. */
- bintime_add(next, &timerperiod); /* Next tick in 1 period. */
- } else {
- binuptime(&now); /* Get present time from hardware. */
- next->sec = -1; /* Next tick is not scheduled yet. */
- }
+ now = sbinuptime();
+ if (periodic)
+ *next = now + timerperiod;
+ else
+ *next = -1; /* Next tick is not scheduled yet. */
state->now = now;
- CTR4(KTR_SPARE2, "intr at %d: now %d.%08x%08x",
- curcpu, now.sec, (unsigned int)(now.frac >> 32),
- (unsigned int)(now.frac & 0xffffffff));
+ CTR3(KTR_SPARE2, "intr at %d: now %d.%08x",
+ curcpu, (int)(now >> 32), (u_int)(now & 0xffffffff));
#ifdef SMP
/* Prepare broadcasting to other CPUs for non-per-CPU timers. */
@@ -374,8 +333,8 @@
state = DPCPU_ID_PTR(cpu, timerstate);
ET_HW_LOCK(state);
state->now = now;
- if (bintime_cmp(&now, &state->nextevent, >=)) {
- state->nextevent.sec++;
+ if (now >= state->nextevent) {
+ state->nextevent += SBT_1S;
if (curcpu != cpu) {
state->ipi = 1;
bcast = 1;
@@ -387,7 +346,7 @@
#endif
/* Handle events for this time on this CPU. */
- handleevents(&now, 0);
+ handleevents(now, 0);
#ifdef SMP
/* Broadcast interrupt to other CPUs for non-per-CPU timers. */
@@ -409,11 +368,11 @@
* Load new value into hardware timer.
*/
static void
-loadtimer(struct bintime *now, int start)
+loadtimer(sbintime_t now, int start)
{
struct pcpu_state *state;
- struct bintime new;
- struct bintime *next;
+ sbintime_t new;
+ sbintime_t *next;
uint64_t tmp;
int eq;
@@ -428,30 +387,24 @@
* Try to start all periodic timers aligned
* to period to make events synchronous.
*/
- tmp = ((uint64_t)now->sec << 36) + (now->frac >> 28);
- tmp = (tmp % (timerperiod.frac >> 28)) << 28;
- new.sec = 0;
- new.frac = timerperiod.frac - tmp;
- if (new.frac < tmp) /* Left less then passed. */
- bintime_add(&new, &timerperiod);
+ tmp = now % timerperiod;
+ new = timerperiod - tmp;
+ if (new < tmp) /* Left less then passed. */
+ new += timerperiod;
CTR5(KTR_SPARE2, "load p at %d: now %d.%08x first in %d.%08x",
- curcpu, now->sec, (unsigned int)(now->frac >> 32),
- new.sec, (unsigned int)(new.frac >> 32));
- *next = new;
- bintime_add(next, now);
- et_start(timer, &new, &timerperiod);
+ curcpu, (int)(now >> 32), (u_int)(now & 0xffffffff),
+ (int)(new >> 32), (u_int)(new & 0xffffffff));
+ *next = new + now;
+ et_start(timer, new, timerperiod);
}
} else {
- getnextevent(&new);
- eq = bintime_cmp(&new, next, ==);
- CTR5(KTR_SPARE2, "load at %d: next %d.%08x%08x eq %d",
- curcpu, new.sec, (unsigned int)(new.frac >> 32),
- (unsigned int)(new.frac & 0xffffffff),
- eq);
+ new = getnextevent();
+ eq = (new == *next);
+ CTR4(KTR_SPARE2, "load at %d: next %d.%08x eq %d",
+ curcpu, (int)(new >> 32), (u_int)(new & 0xffffffff), eq);
if (!eq) {
*next = new;
- bintime_sub(&new, now);
- et_start(timer, &new, NULL);
+ et_start(timer, new - now, 0);
}
}
}
@@ -473,7 +426,7 @@
while (freq < (profiling ? profhz : stathz))
freq += hz;
freq = round_freq(timer, freq);
- FREQ2BT(freq, &timerperiod);
+ timerperiod = SBT_1S / freq;
}
/*
@@ -482,15 +435,15 @@
static int
doconfigtimer(void)
{
- struct bintime now;
+ sbintime_t now;
struct pcpu_state *state;
state = DPCPU_PTR(timerstate);
switch (atomic_load_acq_int(&state->action)) {
case 1:
- binuptime(&now);
+ now = sbinuptime();
ET_HW_LOCK(state);
- loadtimer(&now, 1);
+ loadtimer(now, 1);
ET_HW_UNLOCK(state);
state->handle = 0;
atomic_store_rel_int(&state->action, 0);
@@ -504,8 +457,8 @@
return (1);
}
if (atomic_readandclear_int(&state->handle) && !busy) {
- binuptime(&now);
- handleevents(&now, 0);
+ now = sbinuptime();
+ handleevents(now, 0);
return (1);
}
return (0);
@@ -518,40 +471,45 @@
static void
configtimer(int start)
{
- struct bintime now, next;
+ sbintime_t now, next;
struct pcpu_state *state;
int cpu;
if (start) {
setuptimer();
- binuptime(&now);
- }
+ now = sbinuptime();
+ } else
+ now = 0;
critical_enter();
ET_HW_LOCK(DPCPU_PTR(timerstate));
if (start) {
/* Initialize time machine parameters. */
- next = now;
- bintime_add(&next, &timerperiod);
+ next = now + timerperiod;
if (periodic)
nexttick = next;
else
- nexttick.sec = -1;
+ nexttick = -1;
CPU_FOREACH(cpu) {
state = DPCPU_ID_PTR(cpu, timerstate);
state->now = now;
- state->nextevent = next;
+ if (!smp_started && cpu != CPU_FIRST())
+ state->nextevent = SBT_MAX;
+ else
+ state->nextevent = next;
if (periodic)
state->nexttick = next;
else
- state->nexttick.sec = -1;
+ state->nexttick = -1;
state->nexthard = next;
state->nextstat = next;
state->nextprof = next;
+ state->nextcall = next;
+ state->nextcallopt = next;
hardclock_sync(cpu);
}
busy = 0;
/* Start global timer or per-CPU timer of this CPU. */
- loadtimer(&now, 1);
+ loadtimer(now, 1);
} else {
busy = 1;
/* Stop global timer or per-CPU timer of this CPU. */
@@ -600,12 +558,13 @@
div = 1 << (flsl(div + div / 2) - 1);
freq = (et->et_frequency + div / 2) / div;
}
- if (et->et_min_period.sec > 0)
- freq = 0;
- else if (et->et_min_period.frac != 0)
- freq = min(freq, BT2FREQ(&et->et_min_period));
- if (et->et_max_period.sec == 0 && et->et_max_period.frac != 0)
- freq = max(freq, BT2FREQ(&et->et_max_period));
+ if (et->et_min_period > SBT_1S)
+ panic("Event timer \"%s\" doesn't support sub-second periods!",
+ et->et_name);
+ else if (et->et_min_period != 0)
+ freq = min(freq, SBT2FREQ(et->et_min_period));
+ if (et->et_max_period < SBT_1S && et->et_max_period != 0)
+ freq = max(freq, SBT2FREQ(et->et_max_period));
return (freq);
}
@@ -622,13 +581,9 @@
CPU_FOREACH(cpu) {
state = DPCPU_ID_PTR(cpu, timerstate);
mtx_init(&state->et_hw_mtx, "et_hw_mtx", NULL, MTX_SPIN);
-#ifdef KDTRACE_HOOKS
- state->nextcyc.sec = -1;
-#endif
+ state->nextcall = SBT_MAX;
+ state->nextcallopt = SBT_MAX;
}
-#ifdef SMP
- callout_new_inserted = cpu_new_callout;
-#endif
periodic = want_periodic;
/* Grab requested timer or the best of present. */
if (timername[0])
@@ -655,7 +610,7 @@
else if (!periodic && (timer->et_flags & ET_FLAGS_ONESHOT) == 0)
periodic = 1;
if (timer->et_flags & ET_FLAGS_C3STOP)
- cpu_disable_deep_sleep++;
+ cpu_disable_c3_sleep++;
/*
* We honor the requested 'hz' value.
@@ -692,9 +647,10 @@
profhz = round_freq(timer, stathz * 64);
}
tick = 1000000 / hz;
- FREQ2BT(hz, &hardperiod);
- FREQ2BT(stathz, &statperiod);
- FREQ2BT(profhz, &profperiod);
+ tick_sbt = SBT_1S / hz;
+ tick_bt = sbttobt(tick_sbt);
+ statperiod = SBT_1S / stathz;
+ profperiod = SBT_1S / profhz;
ET_LOCK();
configtimer(1);
ET_UNLOCK();
@@ -706,22 +662,22 @@
void
cpu_initclocks_ap(void)
{
- struct bintime now;
+ sbintime_t now;
struct pcpu_state *state;
+ struct thread *td;
state = DPCPU_PTR(timerstate);
- binuptime(&now);
+ now = sbinuptime();
ET_HW_LOCK(state);
- if ((timer->et_flags & ET_FLAGS_PERCPU) == 0 && periodic) {
- state->now = nexttick;
- bintime_sub(&state->now, &timerperiod);
- } else
- state->now = now;
+ state->now = now;
hardclock_sync(curcpu);
- handleevents(&state->now, 2);
- if (timer->et_flags & ET_FLAGS_PERCPU)
- loadtimer(&now, 1);
+ spinlock_enter();
ET_HW_UNLOCK(state);
+ td = curthread;
+ td->td_intr_nesting_level++;
+ handleevents(state->now, 2);
+ td->td_intr_nesting_level--;
+ spinlock_exit();
}
/*
@@ -767,10 +723,10 @@
/*
* Switch to idle mode (all ticks handled).
*/
-void
+sbintime_t
cpu_idleclock(void)
{
- struct bintime now, t;
+ sbintime_t now, t;
struct pcpu_state *state;
if (idletick || busy ||
@@ -779,22 +735,22 @@
|| curcpu == CPU_FIRST()
#endif
)
- return;
+ return (-1);
state = DPCPU_PTR(timerstate);
if (periodic)
now = state->now;
else
- binuptime(&now);
- CTR4(KTR_SPARE2, "idle at %d: now %d.%08x%08x",
- curcpu, now.sec, (unsigned int)(now.frac >> 32),
- (unsigned int)(now.frac & 0xffffffff));
- getnextcpuevent(&t, 1);
+ now = sbinuptime();
+ CTR3(KTR_SPARE2, "idle at %d: now %d.%08x",
+ curcpu, (int)(now >> 32), (u_int)(now & 0xffffffff));
+ t = getnextcpuevent(1);
ET_HW_LOCK(state);
state->idle = 1;
state->nextevent = t;
if (!periodic)
- loadtimer(&now, 0);
+ loadtimer(now, 0);
ET_HW_UNLOCK(state);
+ return (MAX(t - now, 0));
}
/*
@@ -803,7 +759,7 @@
void
cpu_activeclock(void)
{
- struct bintime now;
+ sbintime_t now;
struct pcpu_state *state;
struct thread *td;
@@ -813,101 +769,82 @@
if (periodic)
now = state->now;
else
- binuptime(&now);
- CTR4(KTR_SPARE2, "active at %d: now %d.%08x%08x",
- curcpu, now.sec, (unsigned int)(now.frac >> 32),
- (unsigned int)(now.frac & 0xffffffff));
+ now = sbinuptime();
+ CTR3(KTR_SPARE2, "active at %d: now %d.%08x",
+ curcpu, (int)(now >> 32), (u_int)(now & 0xffffffff));
spinlock_enter();
td = curthread;
td->td_intr_nesting_level++;
- handleevents(&now, 1);
+ handleevents(now, 1);
td->td_intr_nesting_level--;
spinlock_exit();
}
-#ifdef KDTRACE_HOOKS
+/*
+ * Change the frequency of the given timer. This changes et->et_frequency and
+ * if et is the active timer it reconfigures the timer on all CPUs. This is
+ * intended to be a private interface for the use of et_change_frequency() only.
+ */
void
-clocksource_cyc_set(const struct bintime *t)
+cpu_et_frequency(struct eventtimer *et, uint64_t newfreq)
{
- struct bintime now;
- struct pcpu_state *state;
- state = DPCPU_PTR(timerstate);
- if (periodic)
- now = state->now;
- else
- binuptime(&now);
-
- CTR4(KTR_SPARE2, "set_cyc at %d: now %d.%08x%08x",
- curcpu, now.sec, (unsigned int)(now.frac >> 32),
- (unsigned int)(now.frac & 0xffffffff));
- CTR4(KTR_SPARE2, "set_cyc at %d: t %d.%08x%08x",
- curcpu, t->sec, (unsigned int)(t->frac >> 32),
- (unsigned int)(t->frac & 0xffffffff));
-
- ET_HW_LOCK(state);
- if (bintime_cmp(t, &state->nextcyc, ==)) {
- ET_HW_UNLOCK(state);
- return;
- }
- state->nextcyc = *t;
- if (bintime_cmp(&state->nextcyc, &state->nextevent, >=)) {
- ET_HW_UNLOCK(state);
- return;
- }
- state->nextevent = state->nextcyc;
- if (!periodic)
- loadtimer(&now, 0);
- ET_HW_UNLOCK(state);
+ ET_LOCK();
+ if (et == timer) {
+ configtimer(0);
+ et->et_frequency = newfreq;
+ configtimer(1);
+ } else
+ et->et_frequency = newfreq;
+ ET_UNLOCK();
}
-#endif
-#ifdef SMP
-static void
-cpu_new_callout(int cpu, int ticks)
+void
+cpu_new_callout(int cpu, sbintime_t bt, sbintime_t bt_opt)
{
- struct bintime tmp;
struct pcpu_state *state;
- CTR3(KTR_SPARE2, "new co at %d: on %d in %d",
- curcpu, cpu, ticks);
+ /* Do not touch anything if somebody reconfiguring timers. */
+ if (busy)
+ return;
+ CTR6(KTR_SPARE2, "new co at %d: on %d at %d.%08x - %d.%08x",
+ curcpu, cpu, (int)(bt_opt >> 32), (u_int)(bt_opt & 0xffffffff),
+ (int)(bt >> 32), (u_int)(bt & 0xffffffff));
state = DPCPU_ID_PTR(cpu, timerstate);
ET_HW_LOCK(state);
- if (state->idle == 0 || busy) {
+
+ /*
+ * If there is callout time already set earlier -- do nothing.
+ * This check may appear redundant because we check already in
+ * callout_process() but this double check guarantees we're safe
+ * with respect to race conditions between interrupts execution
+ * and scheduling.
+ */
+ state->nextcallopt = bt_opt;
+ if (bt >= state->nextcall)
+ goto done;
+ state->nextcall = bt;
+ /* If there is some other event set earlier -- do nothing. */
+ if (bt >= state->nextevent)
+ goto done;
+ state->nextevent = bt;
+ /* If timer is periodic -- there is nothing to reprogram. */
+ if (periodic)
+ goto done;
+ /* If timer is global or of the current CPU -- reprogram it. */
+ if ((timer->et_flags & ET_FLAGS_PERCPU) == 0 || cpu == curcpu) {
+ loadtimer(sbinuptime(), 0);
+done:
ET_HW_UNLOCK(state);
return;
}
- /*
- * If timer is periodic - just update next event time for target CPU.
- * If timer is global - there is chance it is already programmed.
- */
- if (periodic || (timer->et_flags & ET_FLAGS_PERCPU) == 0) {
- tmp = hardperiod;
- bintime_mul(&tmp, ticks - 1);
- bintime_add(&tmp, &state->nexthard);
- if (bintime_cmp(&tmp, &state->nextevent, <))
- state->nextevent = tmp;
- if (periodic ||
- bintime_cmp(&state->nextevent, &nexttick, >=)) {
- ET_HW_UNLOCK(state);
- return;
- }
- }
- /*
- * Otherwise we have to wake that CPU up, as we can't get present
- * bintime to reprogram global timer from here. If timer is per-CPU,
- * we by definition can't do it from here.
- */
+ /* Otherwise make other CPU to reprogram it. */
+ state->handle = 1;
ET_HW_UNLOCK(state);
- if (timer->et_flags & ET_FLAGS_PERCPU) {
- state->handle = 1;
- ipi_cpu(cpu, IPI_HARDCLOCK);
- } else {
- if (!cpu_idle_wakeup(cpu))
- ipi_cpu(cpu, IPI_AST);
- }
+#ifdef SMP
+ ipi_cpu(cpu, IPI_HARDCLOCK);
+#endif
}
-#endif
/*
* Report or change the active event timers hardware.
@@ -939,9 +876,9 @@
configtimer(0);
et_free(timer);
if (et->et_flags & ET_FLAGS_C3STOP)
- cpu_disable_deep_sleep++;
+ cpu_disable_c3_sleep++;
if (timer->et_flags & ET_FLAGS_C3STOP)
- cpu_disable_deep_sleep--;
+ cpu_disable_c3_sleep--;
periodic = want_periodic;
timer = et;
et_init(timer, timercb, NULL, NULL);
@@ -975,3 +912,42 @@
SYSCTL_PROC(_kern_eventtimer, OID_AUTO, periodic,
CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
0, 0, sysctl_kern_eventtimer_periodic, "I", "Enable event timer periodic mode");
+
+#include "opt_ddb.h"
+
+#ifdef DDB
+#include <ddb/ddb.h>
+
+DB_SHOW_COMMAND(clocksource, db_show_clocksource)
+{
+ struct pcpu_state *st;
+ int c;
+
+ CPU_FOREACH(c) {
+ st = DPCPU_ID_PTR(c, timerstate);
+ db_printf(
+ "CPU %2d: action %d handle %d ipi %d idle %d\n"
+ " now %#jx nevent %#jx (%jd)\n"
+ " ntick %#jx (%jd) nhard %#jx (%jd)\n"
+ " nstat %#jx (%jd) nprof %#jx (%jd)\n"
+ " ncall %#jx (%jd) ncallopt %#jx (%jd)\n",
+ c, st->action, st->handle, st->ipi, st->idle,
+ (uintmax_t)st->now,
+ (uintmax_t)st->nextevent,
+ (uintmax_t)(st->nextevent - st->now) / tick_sbt,
+ (uintmax_t)st->nexttick,
+ (uintmax_t)(st->nexttick - st->now) / tick_sbt,
+ (uintmax_t)st->nexthard,
+ (uintmax_t)(st->nexthard - st->now) / tick_sbt,
+ (uintmax_t)st->nextstat,
+ (uintmax_t)(st->nextstat - st->now) / tick_sbt,
+ (uintmax_t)st->nextprof,
+ (uintmax_t)(st->nextprof - st->now) / tick_sbt,
+ (uintmax_t)st->nextcall,
+ (uintmax_t)(st->nextcall - st->now) / tick_sbt,
+ (uintmax_t)st->nextcallopt,
+ (uintmax_t)(st->nextcallopt - st->now) / tick_sbt);
+ }
+}
+
+#endif
Modified: trunk/sys/kern/kern_condvar.c
===================================================================
--- trunk/sys/kern/kern_condvar.c 2018-05-25 20:34:19 UTC (rev 9942)
+++ trunk/sys/kern/kern_condvar.c 2018-05-25 20:39:59 UTC (rev 9943)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2000 Jake Burkholder <jake at freebsd.org>.
* All rights reserved.
@@ -25,12 +26,13 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/kern/kern_condvar.c 302234 2016-06-27 21:50:30Z bdrewery $");
#include "opt_ktrace.h"
#include <sys/param.h>
#include <sys/systm.h>
+#include <sys/limits.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/proc.h>
@@ -47,6 +49,17 @@
#endif
/*
+ * A bound below which cv_waiters is valid. Once cv_waiters reaches this bound,
+ * cv_signal must manually check the wait queue for threads.
+ */
+#define CV_WAITERS_BOUND INT_MAX
+
+#define CV_WAITERS_INC(cvp) do { \
+ if ((cvp)->cv_waiters < CV_WAITERS_BOUND) \
+ (cvp)->cv_waiters++; \
+} while (0)
+
+/*
* Common sanity checks for cv_wait* functions.
*/
#define CV_ASSERT(cvp, lock, td) do { \
@@ -97,7 +110,7 @@
WITNESS_SAVE_DECL(lock_witness);
struct lock_class *class;
struct thread *td;
- int lock_state;
+ uintptr_t lock_state;
td = curthread;
lock_state = 0;
@@ -122,7 +135,7 @@
sleepq_lock(cvp);
- cvp->cv_waiters++;
+ CV_WAITERS_INC(cvp);
if (lock == &Giant.lock_object)
mtx_assert(&Giant, MA_OWNED);
DROP_GIANT();
@@ -151,7 +164,7 @@
/*
* Wait on a condition variable. This function differs from cv_wait by
- * not aquiring the mutex after condition variable was signaled.
+ * not acquiring the mutex after condition variable was signaled.
*/
void
_cv_wait_unlock(struct cv *cvp, struct lock_object *lock)
@@ -184,7 +197,7 @@
sleepq_lock(cvp);
- cvp->cv_waiters++;
+ CV_WAITERS_INC(cvp);
DROP_GIANT();
sleepq_add(cvp, lock, cvp->cv_description, SLEEPQ_CONDVAR, 0);
@@ -214,7 +227,8 @@
WITNESS_SAVE_DECL(lock_witness);
struct lock_class *class;
struct thread *td;
- int lock_state, rval;
+ uintptr_t lock_state;
+ int rval;
td = curthread;
lock_state = 0;
@@ -239,7 +253,7 @@
sleepq_lock(cvp);
- cvp->cv_waiters++;
+ CV_WAITERS_INC(cvp);
if (lock == &Giant.lock_object)
mtx_assert(&Giant, MA_OWNED);
DROP_GIANT();
@@ -270,12 +284,13 @@
}
/*
- * Wait on a condition variable for at most timo/hz seconds. Returns 0 if the
- * process was resumed by cv_signal or cv_broadcast, EWOULDBLOCK if the timeout
- * expires.
+ * Wait on a condition variable for (at most) the value specified in sbt
+ * argument. Returns 0 if the process was resumed by cv_signal or cv_broadcast,
+ * EWOULDBLOCK if the timeout expires.
*/
int
-_cv_timedwait(struct cv *cvp, struct lock_object *lock, int timo)
+_cv_timedwait_sbt(struct cv *cvp, struct lock_object *lock, sbintime_t sbt,
+ sbintime_t pr, int flags)
{
WITNESS_SAVE_DECL(lock_witness);
struct lock_class *class;
@@ -305,13 +320,13 @@
sleepq_lock(cvp);
- cvp->cv_waiters++;
+ CV_WAITERS_INC(cvp);
if (lock == &Giant.lock_object)
mtx_assert(&Giant, MA_OWNED);
DROP_GIANT();
sleepq_add(cvp, lock, cvp->cv_description, SLEEPQ_CONDVAR, 0);
- sleepq_set_timeout(cvp, timo);
+ sleepq_set_timeout_sbt(cvp, sbt, pr, flags);
if (lock != &Giant.lock_object) {
if (class->lc_flags & LC_SLEEPABLE)
sleepq_release(cvp);
@@ -336,13 +351,15 @@
}
/*
- * Wait on a condition variable for at most timo/hz seconds, allowing
- * interruption by signals. Returns 0 if the thread was resumed by cv_signal
- * or cv_broadcast, EWOULDBLOCK if the timeout expires, and EINTR or ERESTART if
- * a signal was caught.
+ * Wait on a condition variable for (at most) the value specified in sbt
+ * argument, allowing interruption by signals.
+ * Returns 0 if the thread was resumed by cv_signal or cv_broadcast,
+ * EWOULDBLOCK if the timeout expires, and EINTR or ERESTART if a signal
+ * was caught.
*/
int
-_cv_timedwait_sig(struct cv *cvp, struct lock_object *lock, int timo)
+_cv_timedwait_sig_sbt(struct cv *cvp, struct lock_object *lock,
+ sbintime_t sbt, sbintime_t pr, int flags)
{
WITNESS_SAVE_DECL(lock_witness);
struct lock_class *class;
@@ -372,7 +389,7 @@
sleepq_lock(cvp);
- cvp->cv_waiters++;
+ CV_WAITERS_INC(cvp);
if (lock == &Giant.lock_object)
mtx_assert(&Giant, MA_OWNED);
DROP_GIANT();
@@ -379,7 +396,7 @@
sleepq_add(cvp, lock, cvp->cv_description, SLEEPQ_CONDVAR |
SLEEPQ_INTERRUPTIBLE, 0);
- sleepq_set_timeout(cvp, timo);
+ sleepq_set_timeout_sbt(cvp, sbt, pr, flags);
if (lock != &Giant.lock_object) {
if (class->lc_flags & LC_SLEEPABLE)
sleepq_release(cvp);
@@ -418,8 +435,15 @@
wakeup_swapper = 0;
sleepq_lock(cvp);
if (cvp->cv_waiters > 0) {
- cvp->cv_waiters--;
- wakeup_swapper = sleepq_signal(cvp, SLEEPQ_CONDVAR, 0, 0);
+ if (cvp->cv_waiters == CV_WAITERS_BOUND &&
+ sleepq_lookup(cvp) == NULL) {
+ cvp->cv_waiters = 0;
+ } else {
+ if (cvp->cv_waiters < CV_WAITERS_BOUND)
+ cvp->cv_waiters--;
+ wakeup_swapper = sleepq_signal(cvp, SLEEPQ_CONDVAR, 0,
+ 0);
+ }
}
sleepq_release(cvp);
if (wakeup_swapper)
Modified: trunk/sys/kern/kern_conf.c
===================================================================
--- trunk/sys/kern/kern_conf.c 2018-05-25 20:34:19 UTC (rev 9942)
+++ trunk/sys/kern/kern_conf.c 2018-05-25 20:39:59 UTC (rev 9943)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1999-2002 Poul-Henning Kamp
* All rights reserved.
@@ -25,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/kern/kern_conf.c 294976 2016-01-28 09:18:12Z kib $");
#include <sys/param.h>
#include <sys/kernel.h>
@@ -55,6 +56,7 @@
static void destroy_devl(struct cdev *dev);
static int destroy_dev_sched_cbl(struct cdev *dev,
void (*cb)(void *), void *arg);
+static void destroy_dev_tq(void *ctx, int pending);
static int make_dev_credv(int flags, struct cdev **dres, struct cdevsw *devsw,
int unit, struct ucred *cr, uid_t uid, gid_t gid, int mode, const char *fmt,
va_list ap);
@@ -194,7 +196,7 @@
if (csw != NULL) {
cdp = cdev2priv(dev);
if ((cdp->cdp_flags & CDP_SCHED_DTR) == 0)
- dev->si_threadcount++;
+ atomic_add_long(&dev->si_threadcount, 1);
else
csw = NULL;
}
@@ -235,7 +237,7 @@
if ((cdp->cdp_flags & CDP_SCHED_DTR) == 0) {
csw = dev->si_devsw;
if (csw != NULL)
- dev->si_threadcount++;
+ atomic_add_long(&dev->si_threadcount, 1);
}
dev_unlock();
if (csw != NULL) {
@@ -252,11 +254,9 @@
mtx_assert(&devmtx, MA_NOTOWNED);
if (!ref)
return;
- dev_lock();
KASSERT(dev->si_threadcount > 0,
("%s threadcount is wrong", dev->si_name));
- dev->si_threadcount--;
- dev_unlock();
+ atomic_subtract_rel_long(&dev->si_threadcount, 1);
}
int
@@ -567,22 +567,26 @@
}
static struct cdev *
-newdev(struct cdevsw *csw, int unit, struct cdev *si)
+newdev(struct make_dev_args *args, struct cdev *si)
{
struct cdev *si2;
+ struct cdevsw *csw;
mtx_assert(&devmtx, MA_OWNED);
+ csw = args->mda_devsw;
if (csw->d_flags & D_NEEDMINOR) {
/* We may want to return an existing device */
LIST_FOREACH(si2, &csw->d_devs, si_list) {
- if (dev2unit(si2) == unit) {
+ if (dev2unit(si2) == args->mda_unit) {
dev_free_devlocked(si);
return (si2);
}
}
}
- si->si_drv0 = unit;
+ si->si_drv0 = args->mda_unit;
si->si_devsw = csw;
+ si->si_drv1 = args->mda_si_drv1;
+ si->si_drv2 = args->mda_si_drv2;
LIST_INSERT_HEAD(&csw->d_devs, si, si_list);
return (si);
}
@@ -690,16 +694,22 @@
mtx_assert(&devmtx, MA_OWNED);
- len = vsnrprintf(dev->__si_namebuf, sizeof(dev->__si_namebuf), 32,
- fmt, ap);
- if (len > sizeof(dev->__si_namebuf) - 1)
+ len = vsnrprintf(dev->si_name, sizeof(dev->si_name), 32, fmt, ap);
+ if (len > sizeof(dev->si_name) - 1)
return (ENAMETOOLONG);
/* Strip leading slashes. */
- for (from = dev->__si_namebuf; *from == '/'; from++)
+ for (from = dev->si_name; *from == '/'; from++)
;
- for (to = dev->__si_namebuf; *from != '\0'; from++, to++) {
+ for (to = dev->si_name; *from != '\0'; from++, to++) {
+ /*
+ * Spaces and double quotation marks cause
+ * problems for the devctl(4) protocol.
+ * Reject names containing those characters.
+ */
+ if (isspace(*from) || *from == '"')
+ return (EINVAL);
/* Treat multiple sequential slashes as single. */
while (from[0] == '/' && from[1] == '/')
from++;
@@ -710,11 +720,11 @@
}
*to = '\0';
- if (dev->__si_namebuf[0] == '\0')
+ if (dev->si_name[0] == '\0')
return (EINVAL);
/* Disallow "." and ".." components. */
- for (s = dev->__si_namebuf;;) {
+ for (s = dev->si_name;;) {
for (q = s; *q != '/' && *q != '\0'; q++)
;
if (q - s == 1 && s[0] == '.')
@@ -726,39 +736,52 @@
s = q + 1;
}
- if (devfs_dev_exists(dev->__si_namebuf) != 0)
+ if (devfs_dev_exists(dev->si_name) != 0)
return (EEXIST);
return (0);
}
+void
+make_dev_args_init_impl(struct make_dev_args *args, size_t sz)
+{
+
+ bzero(args, sz);
+ args->mda_size = sz;
+}
+
static int
-make_dev_credv(int flags, struct cdev **dres, struct cdevsw *devsw, int unit,
- struct ucred *cr, uid_t uid, gid_t gid, int mode, const char *fmt,
- va_list ap)
+make_dev_sv(struct make_dev_args *args1, struct cdev **dres,
+ const char *fmt, va_list ap)
{
struct cdev *dev, *dev_new;
+ struct make_dev_args args;
int res;
- KASSERT((flags & MAKEDEV_WAITOK) == 0 || (flags & MAKEDEV_NOWAIT) == 0,
- ("make_dev_credv: both WAITOK and NOWAIT specified"));
- dev_new = devfs_alloc(flags);
+ bzero(&args, sizeof(args));
+ if (sizeof(args) < args1->mda_size)
+ return (EINVAL);
+ bcopy(args1, &args, args1->mda_size);
+ KASSERT((args.mda_flags & MAKEDEV_WAITOK) == 0 ||
+ (args.mda_flags & MAKEDEV_NOWAIT) == 0,
+ ("make_dev_sv: both WAITOK and NOWAIT specified"));
+ dev_new = devfs_alloc(args.mda_flags);
if (dev_new == NULL)
return (ENOMEM);
dev_lock();
- res = prep_cdevsw(devsw, flags);
+ res = prep_cdevsw(args.mda_devsw, args.mda_flags);
if (res != 0) {
dev_unlock();
devfs_free(dev_new);
return (res);
}
- dev = newdev(devsw, unit, dev_new);
+ dev = newdev(&args, dev_new);
if ((dev->si_flags & SI_NAMED) == 0) {
res = prep_devname(dev, fmt, ap);
if (res != 0) {
- if ((flags & MAKEDEV_CHECKNAME) == 0) {
+ if ((args.mda_flags & MAKEDEV_CHECKNAME) == 0) {
panic(
- "make_dev_credv: bad si_name (error=%d, si_name=%s)",
+ "make_dev_sv: bad si_name (error=%d, si_name=%s)",
res, dev->si_name);
}
if (dev == dev_new) {
@@ -770,9 +793,9 @@
return (res);
}
}
- if (flags & MAKEDEV_REF)
+ if ((args.mda_flags & MAKEDEV_REF) != 0)
dev_refl(dev);
- if (flags & MAKEDEV_ETERNAL)
+ if ((args.mda_flags & MAKEDEV_ETERNAL) != 0)
dev->si_flags |= SI_ETERNAL;
if (dev->si_flags & SI_CHEAPCLONE &&
dev->si_flags & SI_NAMED) {
@@ -787,24 +810,55 @@
}
KASSERT(!(dev->si_flags & SI_NAMED),
("make_dev() by driver %s on pre-existing device (min=%x, name=%s)",
- devsw->d_name, dev2unit(dev), devtoname(dev)));
+ args.mda_devsw->d_name, dev2unit(dev), devtoname(dev)));
dev->si_flags |= SI_NAMED;
- if (cr != NULL)
- dev->si_cred = crhold(cr);
- dev->si_uid = uid;
- dev->si_gid = gid;
- dev->si_mode = mode;
+ if (args.mda_cr != NULL)
+ dev->si_cred = crhold(args.mda_cr);
+ dev->si_uid = args.mda_uid;
+ dev->si_gid = args.mda_gid;
+ dev->si_mode = args.mda_mode;
devfs_create(dev);
clean_unrhdrl(devfs_inos);
dev_unlock_and_free();
- notify_create(dev, flags);
+ notify_create(dev, args.mda_flags);
*dres = dev;
return (0);
}
+int
+make_dev_s(struct make_dev_args *args, struct cdev **dres,
+ const char *fmt, ...)
+{
+ va_list ap;
+ int res;
+
+ va_start(ap, fmt);
+ res = make_dev_sv(args, dres, fmt, ap);
+ va_end(ap);
+ return (res);
+}
+
+static int
+make_dev_credv(int flags, struct cdev **dres, struct cdevsw *devsw, int unit,
+ struct ucred *cr, uid_t uid, gid_t gid, int mode, const char *fmt,
+ va_list ap)
+{
+ struct make_dev_args args;
+
+ make_dev_args_init(&args);
+ args.mda_flags = flags;
+ args.mda_devsw = devsw;
+ args.mda_cr = cr;
+ args.mda_uid = uid;
+ args.mda_gid = gid;
+ args.mda_mode = mode;
+ args.mda_unit = unit;
+ return (make_dev_sv(&args, dres, fmt, ap));
+}
+
struct cdev *
make_dev(struct cdevsw *devsw, int unit, uid_t uid, gid_t gid, int mode,
const char *fmt, ...)
@@ -1242,6 +1296,7 @@
{
struct clonedevs *cd;
struct cdev *dev, *ndev, *dl, *de;
+ struct make_dev_args args;
int unit, low, u;
KASSERT(*cdp != NULL,
@@ -1293,7 +1348,10 @@
}
if (unit == -1)
unit = low & CLONE_UNITMASK;
- dev = newdev(csw, unit | extra, ndev);
+ make_dev_args_init(&args);
+ args.mda_unit = unit | extra;
+ args.mda_devsw = csw;
+ dev = newdev(&args, ndev);
if (dev->si_flags & SI_CLONELIST) {
printf("dev %p (%s) is on clonelist\n", dev, dev->si_name);
printf("unit=%d, low=%d, extra=0x%x\n", unit, low, extra);
@@ -1352,7 +1410,7 @@
static TAILQ_HEAD(, cdev_priv) dev_ddtr =
TAILQ_HEAD_INITIALIZER(dev_ddtr);
-static struct task dev_dtr_task;
+static struct task dev_dtr_task = TASK_INITIALIZER(0, destroy_dev_tq, NULL);
static void
destroy_dev_tq(void *ctx, int pending)
@@ -1440,15 +1498,6 @@
sx_xunlock(&clone_drain_lock);
}
-static void
-devdtr_init(void *dummy __unused)
-{
-
- TASK_INIT(&dev_dtr_task, 0, destroy_dev_tq, NULL);
-}
-
-SYSINIT(devdtr, SI_SUB_DEVFS, SI_ORDER_SECOND, devdtr_init, NULL);
-
#include "opt_ddb.h"
#ifdef DDB
#include <sys/kernel.h>
@@ -1494,10 +1543,7 @@
SI_FLAG(SI_NAMED);
SI_FLAG(SI_CHEAPCLONE);
SI_FLAG(SI_CHILD);
- SI_FLAG(SI_DEVOPEN);
- SI_FLAG(SI_CONSOPEN);
SI_FLAG(SI_DUMPDEV);
- SI_FLAG(SI_CANDELETE);
SI_FLAG(SI_CLONELIST);
db_printf("si_flags %s\n", buf);
More information about the Midnightbsd-cvs
mailing list