[project @ 2006-01-03 12:56:10 by simonmar]
[ghc-hetmet.git] / ghc / rts / Exception.cmm
index f35a9c7..9d8d9d6 100644 (file)
@@ -55,10 +55,10 @@ INFO_TABLE_RET( stg_unblockAsyncExceptionszh_ret,
     // Not true: see comments above
     // ASSERT(StgTSO_blocked_exceptions(CurrentTSO) != NULL);
 #if defined(GRAN) || defined(PAR)
-    foreign "C" awakenBlockedQueue(StgTSO_blocked_exceptions(CurrentTSO) "ptr", 
+    foreign "C" awakenBlockedQueue(MyCapability() "ptr", StgTSO_blocked_exceptions(CurrentTSO) "ptr", 
                                   NULL "ptr"); 
 #else
-    foreign "C" awakenBlockedQueue(StgTSO_blocked_exceptions(CurrentTSO) "ptr");
+    foreign "C" awakenBlockedQueue(MyCapability() "ptr", StgTSO_blocked_exceptions(CurrentTSO) "ptr");
 #endif
     StgTSO_blocked_exceptions(CurrentTSO) = NULL;
 #ifdef REG_R1
@@ -115,10 +115,10 @@ unblockAsyncExceptionszh_fast
 
     if (StgTSO_blocked_exceptions(CurrentTSO) != NULL) {
 #if defined(GRAN) || defined(PAR)
-      foreign "C" awakenBlockedQueue(StgTSO_blocked_exceptions(CurrentTSO) "ptr", 
+      foreign "C" awakenBlockedQueue(MyCapability() "ptr", StgTSO_blocked_exceptions(CurrentTSO) "ptr", 
                                     StgTSO_block_info(CurrentTSO) "ptr");
 #else
-      foreign "C" awakenBlockedQueue(StgTSO_blocked_exceptions(CurrentTSO) "ptr");
+      foreign "C" awakenBlockedQueue(MyCapability() "ptr", StgTSO_blocked_exceptions(CurrentTSO) "ptr");
 #endif
       StgTSO_blocked_exceptions(CurrentTSO) = NULL;
 
@@ -191,7 +191,7 @@ killThreadzh_fast
    */
   if (R1 == CurrentTSO) {
        SAVE_THREAD_STATE();
-       foreign "C" raiseAsyncWithLock(R1 "ptr", R2 "ptr");
+       foreign "C" raiseAsync(MyCapability() "ptr", R1 "ptr", R2 "ptr");
        if (StgTSO_what_next(CurrentTSO) == ThreadKilled::I16) {
                R1 = ThreadFinished;
                jump StgReturn;
@@ -201,7 +201,7 @@ killThreadzh_fast
                jump %ENTRY_CODE(Sp(0));
        }
   } else {
-       foreign "C" raiseAsyncWithLock(R1 "ptr", R2 "ptr");
+       foreign "C" raiseAsync(MyCapability() "ptr", R1 "ptr", R2 "ptr");
   }
 
   jump %ENTRY_CODE(Sp(0));
@@ -323,7 +323,7 @@ catchzh_fast
  * It is used in raisezh_fast to update thunks on the update list
  * -------------------------------------------------------------------------- */
 
-INFO_TABLE(stg_raise,1,0,THUNK,"raise","raise")
+INFO_TABLE(stg_raise,1,0,THUNK_1_0,"raise","raise")
 {
   R1 = StgThunk_payload(R1,0);
   jump raisezh_fast;
@@ -350,7 +350,7 @@ raisezh_fast
 
 retry_pop_stack:
     StgTSO_sp(CurrentTSO) = Sp;
-    frame_type = foreign "C" raiseExceptionHelper(CurrentTSO "ptr", R1 "ptr");
+    frame_type = foreign "C" raiseExceptionHelper(BaseReg "ptr", CurrentTSO "ptr", R1 "ptr");
     Sp = StgTSO_sp(CurrentTSO);
     if (frame_type == ATOMICALLY_FRAME) {
       /* The exception has reached the edge of a memory transaction.  Check that 
@@ -360,7 +360,7 @@ retry_pop_stack:
       W_ r;
       trec = StgTSO_trec(CurrentTSO);
       r = foreign "C" stmValidateNestOfTransactions(trec "ptr");
-      foreign "C" stmAbortTransaction(trec "ptr");
+      foreign "C" stmAbortTransaction(MyCapability() "ptr", trec "ptr");
       StgTSO_trec(CurrentTSO) = NO_TREC;
       if (r) {
         // Transaction was valid: continue searching for a catch frame
@@ -369,7 +369,7 @@ retry_pop_stack:
       } else {
         // Transaction was not valid: we retry the exception (otherwise continue
         // with a further call to raiseExceptionHelper)
-        "ptr" trec = foreign "C" stmStartTransaction(BaseReg "ptr", NO_TREC "ptr");
+        "ptr" trec = foreign "C" stmStartTransaction(MyCapability() "ptr", NO_TREC "ptr");
         StgTSO_trec(CurrentTSO) = trec;
         R1 = StgAtomicallyFrame_code(Sp);
         Sp_adj(-1);
@@ -378,13 +378,22 @@ retry_pop_stack:
     }
 
     if (frame_type == STOP_FRAME) {
-       /* We've stripped the entire stack, the thread is now dead. */
-       Sp = CurrentTSO + OFFSET_StgTSO_stack 
-               + WDS(StgTSO_stack_size(CurrentTSO)) - WDS(1);
-       Sp(0) = R1;             /* save the exception */
+       /*
+        * We've stripped the entire stack, the thread is now dead.
+        * We will leave the stack in a GC'able state, see the stg_stop_thread
+        * entry code in StgStartup.cmm.
+        */
+       Sp = CurrentTSO + TSO_OFFSET_StgTSO_stack 
+               + WDS(StgTSO_stack_size(CurrentTSO)) - WDS(2);
+       Sp(1) = R1;             /* save the exception */
+       Sp(0) = stg_enter_info; /* so that GC can traverse this stack */
        StgTSO_what_next(CurrentTSO) = ThreadKilled::I16;
        SAVE_THREAD_STATE();    /* inline! */
-       R1 = ThreadFinished;
+
+       /* The return code goes in BaseReg->rRet, and BaseReg is returned in R1 */
+       StgRegTable_rRet(BaseReg) = ThreadFinished;
+       R1 = BaseReg;
+
        jump StgReturn;
     }