summaryrefslogtreecommitdiff
path: root/rts/RtsAPI.c
diff options
context:
space:
mode:
authorAlexander Vershilov <alexander.vershilov@gmail.com>2016-12-02 14:32:48 -0500
committerBen Gamari <ben@smart-cactus.org>2016-12-02 15:29:15 -0500
commit895a131f6e56847d9ebca2e9bfe19a3189e49d72 (patch)
tree0b54a54e22104ccf5b790a02448f6fb6875812a2 /rts/RtsAPI.c
parentf46369b8a1bf90a3bdc30f2b566c3a7e03672518 (diff)
downloadhaskell-895a131f6e56847d9ebca2e9bfe19a3189e49d72.tar.gz
Install toplevel handler inside fork.
When rts is forked it doesn't update toplevel handler, so UserInterrupt exception is sent to Thread1 that doesn't exist in forked process. We install toplevel handler when fork so signal will be delivered to the new main thread. Fixes #12903 Reviewers: simonmar, austin, erikd, bgamari Reviewed By: bgamari Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2770 GHC Trac Issues: #12903
Diffstat (limited to 'rts/RtsAPI.c')
-rw-r--r--rts/RtsAPI.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/rts/RtsAPI.c b/rts/RtsAPI.c
index f009de7b64..2ca5dc437f 100644
--- a/rts/RtsAPI.c
+++ b/rts/RtsAPI.c
@@ -461,6 +461,35 @@ void rts_evalIO (/* inout */ Capability **cap,
}
/*
+ * rts_evalStableIOMain() is suitable for calling main Haskell thread
+ * stored in (StablePtr (IO a)) it calls rts_evalStableIO but wraps
+ * function in GHC.TopHandler.runMainIO that installs top_handlers.
+ * See Trac #12903.
+ */
+void rts_evalStableIOMain(/* inout */ Capability **cap,
+ /* in */ HsStablePtr s,
+ /* out */ HsStablePtr *ret)
+{
+ StgTSO* tso;
+ StgClosure *p, *r, *w;
+ SchedulerStatus stat;
+
+ p = (StgClosure *)deRefStablePtr(s);
+ w = rts_apply(*cap, &base_GHCziTopHandler_runMainIO_closure, p);
+ tso = createStrictIOThread(*cap, RtsFlags.GcFlags.initialStkSize, w);
+ // async exceptions are always blocked by default in the created
+ // thread. See #1048.
+ tso->flags |= TSO_BLOCKEX | TSO_INTERRUPTIBLE;
+ scheduleWaitThread(tso,&r,cap);
+ stat = rts_getSchedStatus(*cap);
+
+ if (stat == Success && ret != NULL) {
+ ASSERT(r != NULL);
+ *ret = getStablePtr((StgPtr)r);
+ }
+}
+
+/*
* rts_evalStableIO() is suitable for calling from Haskell. It
* evaluates a value of the form (StablePtr (IO a)), forcing the
* action's result to WHNF before returning. The result is returned