summaryrefslogtreecommitdiffstats
path: root/sys/sys/filedesc.h
diff options
context:
space:
mode:
authortedu <tedu@openbsd.org>2004-01-06 04:18:18 +0000
committertedu <tedu@openbsd.org>2004-01-06 04:18:18 +0000
commit3cfaffa960fe23fea5853d6bba25a8056585d020 (patch)
treeddcfac7a2c1f04199bbf4c6e86f1ab8f270051da /sys/sys/filedesc.h
parent2004 (diff)
downloadwireguard-openbsd-3cfaffa960fe23fea5853d6bba25a8056585d020.tar.xz
wireguard-openbsd-3cfaffa960fe23fea5853d6bba25a8056585d020.zip
lock filedesc before manipulating. avoids some rare races.
testing for quite some time by brad + otto
Diffstat (limited to 'sys/sys/filedesc.h')
-rw-r--r--sys/sys/filedesc.h9
1 files changed, 6 insertions, 3 deletions
diff --git a/sys/sys/filedesc.h b/sys/sys/filedesc.h
index 32fd3922538..d9471e74c56 100644
--- a/sys/sys/filedesc.h
+++ b/sys/sys/filedesc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: filedesc.h,v 1.16 2003/06/02 23:28:21 millert Exp $ */
+/* $OpenBSD: filedesc.h,v 1.17 2004/01/06 04:18:18 tedu Exp $ */
/* $NetBSD: filedesc.h,v 1.14 1996/04/09 20:55:28 cgd Exp $ */
/*
@@ -32,7 +32,7 @@
* @(#)filedesc.h 8.1 (Berkeley) 6/2/93
*/
-#include <sys/lock.h>
+#include <sys/rwlock.h>
/*
* This structure is used for the management of descriptors. It may be
* shared by multiple processes.
@@ -68,7 +68,7 @@ struct filedesc {
int fd_freefile; /* approx. next free file */
u_short fd_cmask; /* mask for file creation */
u_short fd_refcnt; /* reference count */
- struct lock fd_lock; /* lock for growing the structure */
+ struct rwlock fd_lock; /* lock for the file descs */
int fd_knlistsize; /* size of knlist */
struct klist *fd_knlist; /* list of attached knotes */
@@ -127,4 +127,7 @@ struct file *fd_getfile(struct filedesc *, int fd);
int closef(struct file *, struct proc *);
int getsock(struct filedesc *, int, struct file **);
+
+#define fdplock(fdp, p) rw_enter_write(&(fdp)->fd_lock, p)
+#define fdpunlock(fdp) rw_exit_write(&(fdp)->fd_lock)
#endif