[Git][ghc/ghc][wip/T25377] rts: Add assertions surrounding tracking of StgAsyncIOResult

Ben Gamari (@bgamari) gitlab at gitlab.haskell.org
Wed Oct 16 16:04:44 UTC 2024



Ben Gamari pushed to branch wip/T25377 at Glasgow Haskell Compiler / GHC


Commits:
a540601c by Ben Gamari at 2024-10-16T12:04:32-04:00
rts: Add assertions surrounding tracking of StgAsyncIOResult

We were previously pretty cavalier in handling StgAsyncIOResults which
has proven in #25377 to be problematic. We now initialize the
AsyncResult field of the `stg_block_async_void` frame to NULL when
pushing, assert that it is NULL in `awaitRequest` and that it is not
NULL in `stg_block_async_void`.

- - - - -


2 changed files:

- rts/HeapStackCheck.cmm
- rts/win32/AsyncMIO.c


Changes:

=====================================
rts/HeapStackCheck.cmm
=====================================
@@ -730,6 +730,7 @@ stg_block_async
 INFO_TABLE_RET ( stg_block_async_void, RET_SMALL, W_ info_ptr, W_ ares )
     return ()
 {
+    ASSERT(ares != 0);
     ccall free(ares "ptr");
     return ();
 }
@@ -738,6 +739,7 @@ stg_block_async_void
 {
     Sp_adj(-2);
     Sp(0) = stg_block_async_void_info;
+    Sp(1) = 0;  // this is the StgAsyncIOResult, which will be filled in by awaitRequests.
     BLOCK_GENERIC;
 }
 


=====================================
rts/win32/AsyncMIO.c
=====================================
@@ -203,6 +203,22 @@ shutdownAsyncIO(bool wait_threads)
     OS_CLOSE_LOCK(&queue_lock);
 }
 
+static void
+assertValidAsyncFrame(StgPtr sp) {
+#if defined(DEBUG)
+    StgPtr info = sp[0];
+    if (info != (StgWord) &stg_block_async_void_info &&
+        info != (StgWord) &stg_block_async_info) {
+        barf("assertValidAsyncFrame: invalid frame type");
+    }
+    if (sp[1] != 0) {
+        barf("assertValidAsyncFrame: non-null StgAsyncIOResult");
+    }
+#else
+    (void) sp;
+#endif
+}
+
 /*
  * Function: awaitRequests(wait)
  *
@@ -326,6 +342,7 @@ start:
                         // stg_block_async_info stack frame, because
                         // the block_info field will be overwritten by
                         // pushOnRunQueue().
+                        assertValidBlockAsyncFrame(tso->stackobj->sp);
                         tso->stackobj->sp[1] = (W_)tso->block_info.async_result;
                         pushOnRunQueue(&MainCapability, tso);
                         break;



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/a540601c3d3722c003b26f4e3671ed74724da1cd

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/a540601c3d3722c003b26f4e3671ed74724da1cd
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20241016/b4739152/attachment-0001.html>


More information about the ghc-commits mailing list