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-25 10:20:05 -0400
commite09afbf2a998beea7783e3de5dce5dd3c6ff23db (patch)
tree126afde30070ef8a13cee9a558eb1f5192b5c1ea /rts/StgMiscClosures.cmm
parent41cf758b3f50554e0aa5240a5898b693758d9670 (diff)
downloadhaskell-e09afbf2a998beea7783e3de5dce5dd3c6ff23db.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 e9186e3500..c2e4071ddf 100644
--- a/rts/StgMiscClosures.cmm
+++ b/rts/StgMiscClosures.cmm
@@ -409,6 +409,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
------------------------------------------------------------------------- */