⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 checkpoint.c

📁 一个用在mips体系结构中的操作系统
💻 C
📖 第 1 页 / 共 3 页
字号:
{   fclose(group->stream);   group->stream = 0;}/* Functions to save and restore values */boolParseInteger(char *str, cptlong *val){   /* Must do hex before int, or else sscanf will see 0x... and scan the 0 */   if (sscanf(str, HEX_FORMAT, val) == 1) return TRUE;   if (sscanf(str, INT_FORMAT, val) == 1) return TRUE;   return FALSE;}boolParseBlock(char *str, cptlong *ptr, cptlong *val){   return (sscanf(str, BLOCK_FORMAT, ptr, val) == 2);}boolParseString(char *str, char *val){   return (sscanf(str, STRING_FORMAT, val) == 1);}CptEntry *FindEntry(CptGroup *group, char *name, int i1, int i2){   /* We check the file first, then the group list, because there could be      and optional parameter in the group list which is overridden in the file.      This could be inefficient once we actually have optional parameters,       because the whole file will be read as soon as the first optional value      is accessed. */   CptEntry *entry = FindEntryInFile(group, name, i1, i2);   if (entry != NULL)      return entry;   entry = FindEntryInList(group, name, i1, i2);   if (entry != NULL)      return entry;   CPUWarning("CPT: Could not find entry %s [%d,%d] in %s checkpoint file\n",               name, i1, i2, group->tag);   return NULL;}static int64ReadInteger(CptGroup *group, char *name, int i1, int i2){   CptEntry *entry = FindEntry(group, name, i1, i2);   int64 val;   if (entry == NULL) {      group->failure = TRUE;      return 0;   }   if (entry->type != CPT_INTEGER) {      CPUWarning("CPT: Could not parse value for entry %s [%d,%d] as an integer\n",                  name, i1, i2);       group->failure = TRUE;      return 0;   }   val = entry->intval;   FreeEntry(entry);   return val;}static int64ReadBlock(CptGroup *group, char *name, int i1, int i2, int *size){   CptEntry *entry = FindEntry(group, name, i1, i2);   int64 ptr;   if (entry == NULL) {      group->failure = TRUE;      return 0;   }   if (entry->type != CPT_BLOCK) {      CPUWarning("CPT: Could not parse value for entry [%d,%d] as a binary block\n",                  i1, i2);       group->failure = TRUE;      return 0;   }   ptr = entry->ptrval;   *size = entry->intval;   FreeEntry(entry);   return ptr;}char *ReadString(CptGroup *group, char *name, int i1, int i2){   CptEntry *entry = FindEntry(group, name, i1, i2);   char *ptr;   if (entry == NULL) {      group->failure = TRUE;      return 0;   }   if (entry->type != CPT_STRING) {      CPUWarning("CPT: Could not parse value for entry %s [%d,%d] as a string\n",                  name, i1, i2);       group->failure = TRUE;      return 0;   }   ptr = UINT64_TO_PTR(entry->ptrval);   FreeEntry(entry);   return ptr;}voidWriteInteger(CptGroup *group, char *name, int i1, int i2, int64 val){   char valstr[MAX_LENGTH];   sprintf(valstr, INT_FORMAT, (cptlong)val);   SaveLine(group, name, i1, i2, valstr);}voidWriteHexInteger(CptGroup *group, char *name, int i1, int i2, int64 val){   char valstr[MAX_LENGTH];   sprintf(valstr, HEX_FORMAT, (cptlong)val);   SaveLine(group, name, i1, i2, valstr);}voidWriteString(CptGroup *group, char *name, int i1, int i2, char *val){   char valstr[MAX_LENGTH];   sprintf(valstr, STRING_FORMAT, val);   SaveLine(group, name, i1, i2, valstr);}voidWriteBlock(CptGroup *group, char *name, int i1, int i2,            int64 pos, int64 val){   char valstr[MAX_LENGTH];   sprintf(valstr, BLOCK_FORMAT,(cptlong) pos, (cptlong)val);   SaveLine(group, name, i1, i2, valstr);}intSimcpt_CptInt(CptDescriptor *cptd, char *name, int i1, int i2, int *val){   if (cptd->mode == CPT_SAVE)      WriteInteger(cptd->group, name, i1, i2, (int64) *val);   else      *val = (int) ReadInteger(cptd->group, name, i1, i2);   return 0;}intSimcpt_CptUint(CptDescriptor *cptd, char *name, int i1, int i2, uint *val){   if (cptd->mode == CPT_SAVE)      WriteInteger(cptd->group, name, i1, i2, (int64) *val);   else      *val = (uint) ReadInteger(cptd->group, name, i1, i2);   return 0;}intSimcpt_CptHex(CptDescriptor *cptd, char *name, int i1, int i2, uint *val){   if (cptd->mode == CPT_SAVE)      WriteHexInteger(cptd->group, name, i1, i2, (int64) *val);   else      *val = (uint) ReadInteger(cptd->group, name, i1, i2);   return 0;}intSimcpt_CptChar(CptDescriptor *cptd, char *name, int i1, int i2, char *val){   if (cptd->mode == CPT_SAVE)      WriteInteger(cptd->group, name, i1, i2, (int64) *val);   else      *val = (char) ReadInteger(cptd->group, name, i1, i2);   return 0;}intSimcpt_CptUchar(CptDescriptor *cptd, char *name, int i1, int i2, unsigned char *val){   if (cptd->mode == CPT_SAVE)      WriteHexInteger(cptd->group, name, i1, i2, (int64) *val);   else      *val = (unsigned char) ReadInteger(cptd->group, name, i1, i2);   return 0;}intSimcpt_CptLong(CptDescriptor *cptd, char *name, int i1, int i2, long *val){   if (cptd->mode == CPT_SAVE)      WriteInteger(cptd->group, name, i1, i2, (int64) *val);   else      *val = (long) ReadInteger(cptd->group, name, i1, i2);   return 0;}intSimcpt_CptUlong(CptDescriptor *cptd, char *name, int i1, int i2, unsigned long *val){   if (cptd->mode == CPT_SAVE)      WriteInteger(cptd->group, name, i1, i2, (int64) *val);   else      *val = (long) ReadInteger(cptd->group, name, i1, i2);   return 0;}intSimcpt_CptULL(CptDescriptor *cptd, char *name, int i1, int i2, uint64 *val){   if (cptd->mode == CPT_SAVE)      WriteInteger(cptd->group, name, i1, i2, (int64) *val);   else      *val = (uint64) ReadInteger(cptd->group, name, i1, i2);   return 0;}int Simcpt_CptParamInt(CptDescriptor *cptd, char *name, int i1, int i2,                   int *paramAddr){   if (cptd->mode == CPT_SAVE)      WriteInteger(cptd->group, name, i1, i2, (int64) *paramAddr);   else       *paramAddr = (int) ReadInteger(cptd->group, name, i1, i2);   return 0;}  intSimcpt_CptString(CptDescriptor *cptd, char *name, int i1, int i2, char **val){   if (cptd->mode == CPT_SAVE)      WriteString(cptd->group, name, i1, i2, *val);   else {      char *ptr = ReadString(cptd->group, name, i1, i2);      if (ptr == NULL) return 1;      if (*val == NULL)         *val = SaveString(ptr);      else         strcpy(*val, ptr);   }   return 0;}intSimcpt_CptBlock(CptDescriptor *cptd, char *name, int i1, int i2, void *val,                 int size, int outputFDesc){   if (cptd->mode == CPT_SAVE) {      WriteBlock(cptd->group, name, i1, i2, (int64) cptd->group->binpos,                  size);      SaveBlock(cptd->group, (caddr_t) val, size);   } else {      int64 pos;      int bsize;      pos = ReadBlock(cptd->group, name, i1, i2, &bsize);      if (size != bsize) {         CPUWarning("CPT: Binary data size difference in %s:\n"                    "CPT:   SimOS expected a data block of %d bytes\n"                    "CPT:   Checkpoint file provided %d bytes\n",                    cptd->group->tag, size, bsize);      }      outputFD = outputFDesc;      RestoreBlock(cptd->group, (caddr_t) val, pos, bsize);      outputFD = -1;   }   return 0;}int Simcpt_Comment(CptDescriptor *cptd, char *comment){   if (cptd->mode == CPT_SAVE) {      fprintf(cptd->group->stream, "# %s\n", comment);   }   return 0;}/* Calls to provide optional parameters */intSimcpt_OptionalInteger(CptDescriptor *cptd, char *name, int i1, int i2, int64 val){   CptGroup *group = cptd->group;   CptEntry *entry = NewEntry(name, i1, i2, CPT_INTEGER);   if (entry == NULL) return -1;   entry->optional = TRUE;   entry->type = CPT_INTEGER;   entry->intval = val;   AddEntry(group, entry);   return 0;}intSimcpt_OptionalString(CptDescriptor *cptd, char *name, int i1, int i2, char *val){   char valstring[MAX_LENGTH];   CptGroup *group = cptd->group;   CptEntry *entry = NewEntry(name, i1, i2, CPT_STRING);   if (entry == NULL) return -1;   entry->optional = TRUE;   entry->ptrval = (int64)PTR_TO_UINT64(SaveString(valstring));   AddEntry(group, entry);   return 0;}boolSimcpt_IsRemote(void){   return cptRemote;}intSimcpt_GetMemoryCptFile(void){  char filename[MAX_PATH_LENGTH];  char pathname[MAX_PATH_LENGTH];  int memfd;  CptGroup *group = FindGroup("memory");  CptCompression compress;  if (group == NULL) {     CPUWarning("CPT: Couldn't open memory checkpoint file for mmap\n");     return -1;  }  if (cptRemote) {     CPUWarning("CPT: Cannot mmap memory checkpoint file on rmtaccess server\n");     return -1;  }    sprintf(filename, "%s.%s.bin", cptName, group->tag);  compress = GetCompression(filename, pathname);  if (compress != NO_COMPRESSION) {     if (compress != NUM_COMPRESS_TYPES)       CPUWarning("CPT: Cannot mmap file %s -- it is compressed.\n", pathname);     else        CPUWarning("CPT: Cannot find file %s for mmap.\n", filename);     return -1;  }  memfd = open(pathname, O_RDONLY);  if (memfd < 0)    CPUWarning("CPT: Cannot open file %s for mmap.\n", pathname);  return memfd;}intSimcpt_CanMmapMemoryCheckpoint( void ){   if (cptRemote) {      return FALSE;   } else {      CptGroup *group = FindGroup("memory");      char filename[MAX_PATH_LENGTH];      char pathname[MAX_PATH_LENGTH];      ASSERT(group != NULL);            sprintf(filename, "%s.%s.bin", cptName, group->tag);      return (GetCompression(filename, pathname) == NO_COMPRESSION);   }}voidSimcpt_Preread_Numcells(void){   CptGroup *group;   if (cptVersion.ver == 3) {      group = NewGroup("firewall");      OpenCptFile(CPT_RESTORE, group);      NUM_CELLS(0) = ReadInteger(group, "NumCells", NO_INDEX, NO_INDEX);      CloseCptFile(group);      group->tag = "HOHA";   }}voidSimcpt_Preread_Numether(void){   CptGroup *group;   if (cptVersion.ver == 3) {      group = NewGroup("ether");      OpenCptFile(CPT_RESTORE, group);      NUM_ETHER_CONTROLLERS(0) = ReadInteger(group, "NumControllers",                                             NO_INDEX, NO_INDEX);      CloseCptFile(group);      group->tag = "HOHA";   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -