summaryrefslogtreecommitdiff
path: root/sys/kern
diff options
context:
space:
mode:
authorMark Johnston <markj@FreeBSD.org>2020-12-09 14:05:08 +0000
committerMark Johnston <markj@FreeBSD.org>2020-12-09 14:05:08 +0000
commit3309fa7403f691da45592bf9147d0f9892e01644 (patch)
tree578f4cbce2c78cbe7f8c9e1b09040dc7345ae1ee /sys/kern
parent4c1c90ea955be45fcbabd9b76d85b8fb18b79f45 (diff)
Notes
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/kern_descrip.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c
index bf556eddb43f..7e0d0bca7fb4 100644
--- a/sys/kern/kern_descrip.c
+++ b/sys/kern/kern_descrip.c
@@ -2463,6 +2463,13 @@ fdescfree_fds(struct thread *td, struct filedesc *fdp, bool needclose)
struct file *fp;
int i, lastfile;
+ KASSERT(refcount_load(&fdp->fd_refcnt) == 0,
+ ("%s: fd table %p carries references", __func__, fdp));
+
+ /* Serialize with threads iterating over the table. */
+ FILEDESC_XLOCK(fdp);
+ FILEDESC_XUNLOCK(fdp);
+
lastfile = fdlastfile_single(fdp);
for (i = 0; i <= lastfile; i++) {
fde = &fdp->fd_ofiles[i];
@@ -2536,6 +2543,11 @@ pdescfree(struct thread *td)
void
fdescfree_remapped(struct filedesc *fdp)
{
+#ifdef INVARIANTS
+ /* fdescfree_fds() asserts that fd_refcnt == 0. */
+ if (!refcount_release(&fdp->fd_refcnt))
+ panic("%s: fd table %p has extra references", __func__, fdp);
+#endif
fdescfree_fds(curthread, fdp, 0);
}