From d73379a5a3b2d6381ccd578d843aae7ba36799cd Mon Sep 17 00:00:00 2001 From: Ben Gamari Date: Sun, 20 Oct 2019 15:51:08 -0400 Subject: Assert capability ownership --- rts/Capability.c | 4 ++++ rts/Capability.h | 2 ++ rts/ward.config | 5 ++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/rts/Capability.c b/rts/Capability.c index 7d44b0ec38..194184b101 100644 --- a/rts/Capability.c +++ b/rts/Capability.c @@ -494,6 +494,7 @@ void interruptAllCapabilities(void) #if defined(THREADED_RTS) WARD_NEED(capability_lock_held) +WARD_GRANT(TASK_OWNS_CAPABILITY(task, cap)) static void giveCapabilityToTask (Capability *cap USED_IF_DEBUG, Task *task) { @@ -777,6 +778,7 @@ static Capability * waitForWorkerCapability (Task *task) #if defined(THREADED_RTS) +WARD_GRANT(TASK_OWNS_CAPABILITY(task, *return)) static Capability * waitForReturnCapability (Task *task) { Capability *cap; @@ -882,6 +884,7 @@ static Capability * find_capability_for_task(const Task * task) * * ------------------------------------------------------------------------- */ +WARD_GRANT(TASK_OWNS_CAPABILITY(task, *cap)) void waitForCapability (Capability **pCap, Task *task) { #if !defined(THREADED_RTS) @@ -956,6 +959,7 @@ void waitForCapability (Capability **pCap, Task *task) /* See Note [GC livelock] in Schedule.c for why we have gcAllowed and return the bool */ +WARD_REVOKE(TASK_OWNS_CAPABILITY(task, *cap)) bool /* Did we GC? */ yieldCapability ( Capability** pCap // [in/out] Task's owned capability. Set to the diff --git a/rts/Capability.h b/rts/Capability.h index 78b7b6f083..ba19e3130d 100644 --- a/rts/Capability.h +++ b/rts/Capability.h @@ -386,6 +386,8 @@ void markCapabilities (evac_fn evac, void *user); void traverseSparkQueues (evac_fn evac, void *user); +#define TASK_OWNS_CAPABILITY(task, cap) task_owns_capability + WARD_GRANT(capability_lock_held) INLINE_HEADER void acquire_capability_lock(Capability *cap) { diff --git a/rts/ward.config b/rts/ward.config index cd34be6a1b..6585b1914e 100644 --- a/rts/ward.config +++ b/rts/ward.config @@ -14,7 +14,10 @@ gc_block_alloc_spin_held "gc_block_alloc_spin is held" stable_ptr_lock_held "the stable pointer lock is held"; -task_owns_capability "the current thread's Task owns the Capability"; +// N.B. Use the TASK_OWNS_CAPABILITY macro instead of this capability directly where +// possible to clarify which Capability and which Task we are talking about. +task_owns_capability "a Task owns the Capability"; + capability_lock_held "the Capability's lock is held"; .enforce "Storage.c"; -- cgit v1.2.1