From a28c9372caa834691e8ca49be6f0f6a262247cb5 Mon Sep 17 00:00:00 2001 From: Ben Gamari Date: Sun, 20 Oct 2019 12:10:32 -0400 Subject: Assert capability ownership --- rts/Capability.c | 2 ++ rts/Capability.h | 24 ++++++++++++++++++++++++ rts/ward.config | 7 +++++++ 3 files changed, 33 insertions(+) diff --git a/rts/Capability.c b/rts/Capability.c index c3571f6d64..d1354d9231 100644 --- a/rts/Capability.c +++ b/rts/Capability.c @@ -493,6 +493,7 @@ void interruptAllCapabilities(void) * ------------------------------------------------------------------------- */ #if defined(THREADED_RTS) +WARD_NEED(capability_lock_held) static void giveCapabilityToTask (Capability *cap USED_IF_DEBUG, Task *task) { @@ -625,6 +626,7 @@ releaseAndWakeupCapability (Capability* cap USED_IF_THREADS) RELEASE_LOCK(&cap->lock); } +WARD_NEED(capability_lock_held) static void enqueueWorker (Capability* cap USED_IF_THREADS) { diff --git a/rts/Capability.h b/rts/Capability.h index 73e564a628..78b7b6f083 100644 --- a/rts/Capability.h +++ b/rts/Capability.h @@ -386,6 +386,30 @@ void markCapabilities (evac_fn evac, void *user); void traverseSparkQueues (evac_fn evac, void *user); +WARD_GRANT(capability_lock_held) +INLINE_HEADER void +acquire_capability_lock(Capability *cap) { + ACQUIRE_MUTEX(&cap->lock); +} + +WARD_NEED(capability_lock_held) +WARD_REVOKE(capability_lock_held) +INLINE_HEADER void +release_capability_lock(Capability *cap) { + RELEASE_MUTEX(&cap->lock); +} + +WARD_NEED(capability_lock_held) +INLINE_HEADER Task * +get_running_task(Capability *cap) { + return capability->running_task; +} +WARD_NEED(capability_lock_held) +INLINE_HEADER void +set_running_task(Capability *cap, const Task *task) { + capability->running_task = task; +} + /* ----------------------------------------------------------------------------- NUMA -------------------------------------------------------------------------- */ diff --git a/rts/ward.config b/rts/ward.config index 91aead362d..beb37e271d 100644 --- a/rts/ward.config +++ b/rts/ward.config @@ -14,6 +14,9 @@ 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"; +capability_lock_held "the Capability's lock is held"; + .enforce "Storage.c"; .enforce "GC.c"; .enforce "MarkWeak.c"; @@ -25,3 +28,7 @@ stable_ptr_lock_held "the stable pointer lock is held"; .enforce "Schedule.c"; .enforce "RaiseAsync.c"; .enforce "StablePtr.c"; +.enforce "Sparks.c"; +.enforce "LdvProfile.c"; +.enforce "Capability.c"; +.enforce "*.c"; -- cgit v1.2.1