summaryrefslogtreecommitdiffstats
path: root/sys/sys/filedesc.h
diff options
context:
space:
mode:
authorguenther <guenther@openbsd.org>2012-02-15 04:26:27 +0000
committerguenther <guenther@openbsd.org>2012-02-15 04:26:27 +0000
commit638f0017823ed0e106d01f08deef215e05f1e560 (patch)
treecba8201347fdd0e19f16ceee4f173da6d23b9754 /sys/sys/filedesc.h
parent82571/82572 do not properly set byte enables 2 and 3 on MSI (diff)
downloadwireguard-openbsd-638f0017823ed0e106d01f08deef215e05f1e560.tar.xz
wireguard-openbsd-638f0017823ed0e106d01f08deef215e05f1e560.zip
Hold struct filedesc's fd_lock when writing to the fd_ofiles, fd_ofileflags,
or fd_{lo,hi}maps members, or when doing a read for a write. Fixes hangs when an rthreaded processes sleeps while copying the fd table for fork() and catches another thread with the lock. ok jsing@ tedu@
Diffstat (limited to 'sys/sys/filedesc.h')
-rw-r--r--sys/sys/filedesc.h7
1 files changed, 5 insertions, 2 deletions
diff --git a/sys/sys/filedesc.h b/sys/sys/filedesc.h
index 792129b1cb8..876b3bb6b14 100644
--- a/sys/sys/filedesc.h
+++ b/sys/sys/filedesc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: filedesc.h,v 1.20 2008/09/19 12:24:55 art Exp $ */
+/* $OpenBSD: filedesc.h,v 1.21 2012/02/15 04:26:27 guenther Exp $ */
/* $NetBSD: filedesc.h,v 1.14 1996/04/09 20:55:28 cgd Exp $ */
/*
@@ -68,7 +68,9 @@ struct filedesc {
int fd_freefile; /* approx. next free file */
u_short fd_cmask; /* mask for file creation */
u_short fd_refcnt; /* reference count */
- struct rwlock fd_lock; /* lock for the file descs */
+ struct rwlock fd_lock; /* lock for the file descs; must be */
+ /* held when writing to fd_ofiles, */
+ /* fd_ofileflags, or fd_{hi,lo}map */
int fd_knlistsize; /* size of knlist */
struct klist *fd_knlist; /* list of attached knotes */
@@ -137,4 +139,5 @@ int getsock(struct filedesc *, int, struct file **);
#define fdplock(fdp) rw_enter_write(&(fdp)->fd_lock)
#define fdpunlock(fdp) rw_exit_write(&(fdp)->fd_lock)
+#define fdpassertlocked(fdp) rw_assert_wrlock(&(fdp)->fd_lock)
#endif