summaryrefslogtreecommitdiff
path: root/rts/StgMiscClosures.cmm
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2022-04-04 21:43:27 -0400
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-04-29 13:06:20 -0400
commit5630dde68185f96da026a4e0c722fe6631633299 (patch)
tree973de628f322377ce523fcfb09a2ae25bd74f295 /rts/StgMiscClosures.cmm
parent724d0dc04645b21865bcd1877b7cc77e9a3fe9b2 (diff)
downloadhaskell-5630dde68185f96da026a4e0c722fe6631633299.tar.gz
rts: Refactor handling of dead threads' stacks
This fixes a bug that @JunmingZhao42 and I noticed while working on her MMTK port. Specifically, in stg_stop_thread we used stg_enter_info as a sentinel at the tail of a stack after a thread has completed. However, stg_enter_info expects to have a two-field payload, which we do not push. Consequently, if the GC ends up somehow the stack it will attempt to interpret data past the end of the stack as the frame's fields, resulting in unsound behavior. To fix this I eliminate this hacky use of `stg_stop_thread` and instead introduce a new stack frame type, `stg_dead_thread_info`. Not only does this eliminate the potential for the previously mentioned memory unsoundness but it also more clearly captures the intended structure of the dead threads' stacks.
Diffstat (limited to 'rts/StgMiscClosures.cmm')
-rw-r--r--rts/StgMiscClosures.cmm10
1 files changed, 10 insertions, 0 deletions
diff --git a/rts/StgMiscClosures.cmm b/rts/StgMiscClosures.cmm
index b9aee516d0..dbdd2d71fa 100644
--- a/rts/StgMiscClosures.cmm
+++ b/rts/StgMiscClosures.cmm
@@ -414,6 +414,16 @@ INFO_TABLE_RET( stg_apply_interp, RET_BCO )
jump stg_yield_to_interpreter [];
}
+/*
+ * Dummy info table pushed on the top of the stack when the stack's
+ * owning thread has finished.
+ */
+INFO_TABLE_RET( stg_dead_thread, RET_SMALL,
+ W_ info_ptr,
+ PROF_HDR_FIELDS(W_,p1,p2)
+ P_ result )
+{ foreign "C" barf("stg_dead_thread entered!") never returns; }
+
/* ----------------------------------------------------------------------------
Entry code for a BCO
------------------------------------------------------------------------- */