Code:
PAGESIZE 4096
DATASTART (char *)&etext;
typedef struct dlist {
struct dlist *flink;
struct dlist *blink;
char *addr;
char *stop;
unsigned long size;
} *Dlist;
Dlist curptr, endptr; ( Dlist is a structure to create a link list)
int no_chunks=0, pn;
long size;
caddr_t stop, addr;
if(incremental){ /*-- variable used to check if incremental checkpointing on? --*/
endptr = inc_list->main->flink;
/*-- for each included chunk of the heap --*/
for(curptr = inc_list->main->blink->blink;
curptr != endptr; curptr = curptr->blink){
/*-- write out the last page in the included chunk --*/
stop = curptr->addr;
pn = ((long)curptr->stop - (long)DATASTART) / PAGESIZE;
if(isdirty(pn)){ /* function to check if the segment has been modified*/
addr = (caddr_t)max((long)curptr->addr,
(long)((pn * PAGESIZE) + DATASTART));
size = (long)curptr->stop - (long)addr;
debug(stderr, "DEBUG: Writing heap from 0x%x to 0x%x, pn = %d\n",
addr, addr+size, pn);
if(write_chunk(addr, size, map_fd, data_fd) == -1){ /* function to write a chunk to a file */
return -1;
}
no_chunks++;
}
/*-- write out all the whole pages in the middle of the chunk --*/
for(pn--; pn * PAGESIZE + DATASTART >= stop; pn--){
if(isdirty(pn)){
addr = (caddr_t)((pn * PAGESIZE) + DATASTART);
debug(stderr, "DEBUG: Writing heap from 0x%x to 0x%x, pn = %d\n",
addr, addr+PAGESIZE, pn);
if(write_chunk(addr, PAGESIZE, map_fd, data_fd) == -1){
return -1;
}
}
no_chunks++;
}
}
/*-- write out the first page in the included chunk --*/
addr = curptr->addr;
size = ((pn+1) * PAGESIZE + DATASTART) - addr;
if(size > 0 && (isdirty(pn))){
debug(stderr, "DEBUG: Writing heap from 0x%x to 0x%x\n", addr, addr+size);
if(write_chunk(addr, size, map_fd, data_fd) == -1){
return -1;
}
}
no_chunks++;
}
}
}
else{ /*-- incremental checkpointing off! --*/
endptr = inc_list->main->blink;
/*-- for each included chunk of the heap --*/
for(curptr = inc_list->main->flink->flink;
curptr != endptr; curptr = curptr->flink){
debug(stderr, "DEBUG: saving memory from 0x%x to 0x%x\n",
curptr->addr, curptr->addr+curptr->size);
if(write_chunk(curptr->addr, curptr->size, map_fd, data_fd) == -1){
return -1;
}
}
no_chunks++;
}
}
return no_chunks;