home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / emerald / emrldsys.lha / Kernel / Checkpoint / recover.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-17  |  5.0 KB  |  175 lines

  1. /*
  2.  * recover.c - Emerald Checkpoint operation recovery routines
  3.  *
  4.  * Copyright 1986 Eric Jul and Norm Hutchinson.
  5.  * Copyright 1988 Clinton Jeffery
  6.  * May not be used for any purpose without written permission from the authors.
  7.  * The Emerald kernel for the Emerald programming language.
  8.  *
  9.  * This code was inspired by portions of mobility.c and locate.c
  10.  */
  11. #include <sys/file.h>
  12. #include <stdio.h>
  13. #include "Kernel/h/system.h"
  14. #include "Kernel/h/assert.h"
  15. #include "Kernel/h/macros.h"
  16. #include "Kernel/h/errMsgs.h"
  17. #include "Kernel/h/mmCodes.h"
  18. #include "Kernel/h/emTypes.h"
  19. #include "Kernel/h/timerTypes.h"
  20. #include "Kernel/h/kmdTypes.h"
  21. #include "Kernel/h/kEvents.h"
  22. #include "Kernel/h/emCodes.h"
  23. #include "Kernel/h/mmMsgTypes.h"
  24. #include "Kernel/h/lmTypes.h"
  25. #include "Kernel/h/emkDefs.h"
  26. #include "Kernel/h/lmCodes.h"
  27. #include "Kernel/h/hotsTypes.h"
  28. #include "Kernel/h/map.h"
  29. #include "Kernel/h/set.h"
  30. #include "Kernel/h/consts.h"
  31. #include "Kernel/h/utils.h"
  32. #include "Kernel/h/cPLog.h"
  33. #include "Kernel/h/replicant.h"
  34.  
  35. extern void     UnblockInitially();
  36. extern char    *BrandNames[];
  37. extern Boolean  LoadRequest();
  38. extern ODP      OTLookup();
  39.  
  40.  
  41. /* forwards */
  42. HResult  RecoverItemHandler();
  43. HResult  RecoverCallBack();
  44.  
  45. typedef struct TRec {
  46.     OID                 theOID;
  47.     Offset              theOffset;
  48. } TRec, *TRecPtr;
  49.  
  50. /*
  51.  * RecoverItemHandler
  52.  */
  53. HResult RecoverItemHandler(fHandlePtr, theOldODP)
  54. replicantPtr fHandlePtr;       /* this is just a magic cookie */
  55. ODP theOldODP;
  56. {
  57.   MoveItem item;            /* this is a struct { ItemHdr hdr; ODP oldODP; } */
  58.   extern void TriggerCallBacks();
  59.  
  60.   item.oldODP = theOldODP;
  61.   theOldODP   = NULL;       /* this variable is used later in another context*/
  62.   KMDTrace("Recover", 3, "RecoverItemHandler\n");
  63.  
  64.   TriggerCallBacks((LMHandle *)fHandlePtr, &item, 1);
  65. }
  66.  
  67. /*
  68.  * RecoverCallBack
  69.  */
  70. HResult RecoverCallBack(fReq, fOID)
  71. GenericReqPtr           fReq;
  72. OID                     fOID;
  73. {
  74.   register IncomingMoveReqPtr req;
  75.   extern void DoTranslate(), StartProcessAtAddr();
  76.   req = (IncomingMoveReqPtr) fReq;
  77.   KMDTrace("Recover", 4, "RecoverCallBack; OID %s status %s\n", PPOID(fOID),
  78.        req->status == IMLoadingCode ? "Loading Code" :
  79.        req->status == IMCodeLoadDone? "Code load done" :
  80.        "BAD STATUS");
  81.  
  82.   switch (req->status) {
  83.     
  84.   case IMLoadingCode: {
  85.     ODP     oldODP;
  86.     CodeODP newODP;
  87.     
  88.     /* Requested code has arrived */
  89.     oldODP  = (ODP) Map_Lookup(req->neededMap, (int) fOID);
  90.  
  91.     if (IsNIL(oldODP)) {
  92.       ErrMsg("RecoverCallBack %s -- ignored\n");
  93.       return;
  94.     }
  95.     Map_Delete(req->neededMap, (int) fOID);
  96.  
  97.     newODP          = (CodeODP) OTLookup(fOID);
  98.     assert(NonNULL(newODP));
  99.  
  100.     /* (Note, m uses the pointer to the code area.) */
  101.     KMDTrace("CPTT", 5, "CPTT Map_Insert: (0x%06x -> 0x%06x) for code %s\n",
  102.          oldODP, newODP->dataPtr, PPCodePtr(newODP->dataPtr));
  103.     Map_Insert(req->m, (int) oldODP, (int) newODP->dataPtr);
  104.  
  105.     if (Map_Count(req->neededMap) == 0) {
  106.       KMDTrace("Recover", 4, "All needed code loaded\n");
  107.       req->status = IMCodeLoadDone;
  108.       RecoverCallBack((GenericReqPtr) req, (OID) NULL);
  109.     }
  110.     break;
  111.   }
  112.  
  113.   case IMCodeLoadDone: {
  114.  
  115.     /* All needed code has been loaded, now translate */
  116.     DoTranslate(req->newSet, req->m, 1);    /*1 is a recovery flag*/
  117.  
  118.     /* All done now, cleanup */
  119.     Map_Destroy(req->m);
  120.     Map_Destroy(req->neededMap);
  121.     Set_Destroy(req->newSet);
  122.  
  123. #if 1
  124.     /* Gee, where should the recovery process start up?  Lets try here */
  125.     /* this code rehashed from MakeObject in kOps.c */
  126.     {
  127.       CodePtr  cType;
  128.       register GODP             x;
  129.       SSPtr p;
  130.       extern SSPtr NewProcess();
  131.       
  132.       /* figure out how to fill the parameters */
  133.       x = ((GODP)(req->travellerODP));
  134.       assert(x != (GODP) NULL);
  135.       if( ((x->dataPtr) != (struct GOData *)NULL) &&
  136.      ((cType = (CodePtr)(x->dataPtr->myCodePtr))!= (CodePtr)NULL)) {
  137.     /* Now make a global call of the object's recovery section, if any */
  138.     if (cType->recovery.offset) {
  139.       KMDTrace("Recover",4, "Recovery code for object 0x%04x starts\n",x);
  140.       x->tag.setUpDone        = FALSE;
  141.       x->tag.frozen           = TRUE;
  142.       x->tag.isResident       = TRUE;
  143.       x->tag.xref             = TRUE;    /* support for local gc */
  144.       x->dataPtr->tag.setUpDone = FALSE;
  145.       x->dataPtr->tag.frozen    = TRUE;
  146.       x->dataPtr->tag.isResident= TRUE;
  147.       x->dataPtr->tag.xref      = TRUE;    /* support for local gc */
  148.       p = NewProcess();
  149.       StartProcessAtAddr(p, x, x->dataPtr,
  150.                  (CodeAddr) addOffset(cType, cType->recovery.offset));
  151.  
  152.     } else { /* No recovery */
  153.       x->tag.setUpDone        = TRUE;
  154.       x->tag.frozen           = FALSE;
  155.       x->tag.isResident       = TRUE;
  156.       x->tag.xref             = TRUE;    /* support for local gc */
  157.       x->dataPtr->tag.setUpDone = TRUE;
  158.       x->dataPtr->tag.frozen    = FALSE;
  159.       x->dataPtr->tag.isResident= TRUE;
  160.       x->dataPtr->tag.xref      = TRUE;    /* support for local gc */
  161.       UnblockInitially(x);
  162.     }
  163.       }
  164.     }
  165. #endif
  166.  
  167.     FreeRequest((GenericReqPtr) req);
  168.     break;
  169.   }
  170.   default:
  171.     ErrMsg("Bad move status %d in RecoverCallBack\n", req->status);
  172.     (void) abort();
  173.   }
  174. }
  175.