Branch: Tag:

1996-09-23

1996-09-23 13:19:43 by Fredrik Hübinette (Hubbe) <hubbe@hubbe.net>

mmap fix

Rev: src/interpret.c:1.2

48:   struct svalue *sp; /* Current position */   struct svalue *evaluator_stack; /* Start of stack */   int stack_size = EVALUATOR_STACK_SIZE; + int evaluator_stack_malloced = 0;      /* mark stack, used to store markers into the normal stack */   struct svalue **mark_sp; /* Current position */   struct svalue **mark_stack; /* Start of stack */ -  + int mark_stack_malloced = 0;      struct frame *fp; /* frame pointer */   
68:   #define MAP_PRIVATE 0   #endif    + #ifndef MAP_FAILED + #define MAP_FAILED -1 + #endif +    #ifdef MAP_ANONYMOUS    fd=-1;   #else
83:       if(fd != -1) close(fd);    -  if(!evaluator_stack || !mark_stack) fatal("Failed to mmap() stack space.\n"); - #else +  if((char *)MAP_FAILED == (char *)evaluator_stack) evaluator_stack=0; +  if((char *)MAP_FAILED == (char *)mark_stack) mark_stack=0; +  + #endif +  if(!evaluator_stack) +  {    evaluator_stack=(struct svalue *)malloc(stack_size*sizeof(struct svalue)); -  +  evaluator_stack_malloced=1; +  } +  +  if(!mark_stack) +  {    mark_stack=(struct svalue **)malloc(stack_size*sizeof(struct svalue *)); - #endif +  mark_stack_malloced=1; +  } +     sp=evaluator_stack;    mark_sp=mark_stack;   }
1553:    reset_evaluator();      #ifdef USE_MMAP_FOR_STACK +  if(!evaluator_stack_malloced) +  {    munmap((char *)evaluator_stack, stack_size*sizeof(struct svalue)); -  +  evaluator_stack=0; +  } +  if(!mark_stack_malloced) +  {    munmap((char *)mark_stack, stack_size*sizeof(struct svalue *)); - #else -  free((char *)evaluator_stack); -  free((char *)mark_stack); +  mark_stack=0; +  }   #endif    -  +  if(evaluator_stack) free((char *)evaluator_stack); +  if(mark_stack) free((char *)mark_stack); +  +  mark_stack=0; +  evaluator_stack=0; +  mark_stack_malloced=0; +  evaluator_stack_malloced=0;   }