From 0003d1b74eae06004bae525f65e1ed11f36f00c0 Mon Sep 17 00:00:00 2001 From: Jeff Roberson Date: Sun, 25 May 2003 18:18:32 +0000 Subject: [PATCH] - Create a new lock, umtx_lock, for use instead of the proc lock for protecting the umtx queues. We can't use the proc lock because we need to hold the lock across calls to casuptr, which can fault. Approved by: re --- sys/kern/kern_umtx.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/sys/kern/kern_umtx.c b/sys/kern/kern_umtx.c index 8c01669b7c59..bd0f524f452e 100644 --- a/sys/kern/kern_umtx.c +++ b/sys/kern/kern_umtx.c @@ -39,6 +39,13 @@ #include #include +#define UMTX_LOCK() mtx_lock(&umtx_lock); +#define UMTX_UNLOCK() mtx_unlock(&umtx_lock); + +struct mtx umtx_lock; + +MTX_SYSINIT(umtx, &umtx_lock, "User-land mutex lock", MTX_DEF); + int _umtx_lock(struct thread *td, struct _umtx_lock_args *uap) /* struct umtx *umtx */ @@ -57,7 +64,7 @@ _umtx_lock(struct thread *td, struct _umtx_lock_args *uap) */ umtx = uap->umtx; - PROC_LOCK(td->td_proc); + UMTX_LOCK(); for (;;) { /* @@ -103,7 +110,7 @@ _umtx_lock(struct thread *td, struct _umtx_lock_args *uap) } /* - * We are now protected from further races via the proc lock. + * We are now protected from further races via umtx_lock. * If userland messes with their mutex without using cmpset * they will deadlock themselves but they will still be * killable via signals. @@ -146,7 +153,7 @@ _umtx_lock(struct thread *td, struct _umtx_lock_args *uap) * used to maintain proper ordering. */ - error = msleep(&td->td_umtx, &td->td_proc->p_mtx, + error = msleep(&td->td_umtx, &umtx_lock, td->td_priority | PCATCH, "umtx", 0); /* @@ -171,7 +178,7 @@ _umtx_lock(struct thread *td, struct _umtx_lock_args *uap) } out: - PROC_UNLOCK(td->td_proc); + UMTX_UNLOCK(); return (error); } @@ -190,7 +197,7 @@ _umtx_unlock(struct thread *td, struct _umtx_unlock_args *uap) error = 0; umtx = uap->umtx; - PROC_LOCK(td->td_proc); + UMTX_LOCK(); /* * Make sure we own this mtx. @@ -300,7 +307,7 @@ _umtx_unlock(struct thread *td, struct _umtx_unlock_args *uap) wakeup(&td0->td_umtx); out: - PROC_UNLOCK(td->td_proc); + UMTX_UNLOCK(); return (error); }