/* Save the current image to disk. We don't throw any exceptions here because if the 'then-die' argument is t it is not safe to do so. Instead we signal failure by returning false. */ bool factor_vm::save_image(const vm_char* saving_filename, const vm_char* filename) { image_header h; h.magic = image_magic; h.version = image_version; h.data_relocation_base = data->tenured->start; h.data_size = data->tenured->occupied_space(); h.code_relocation_base = code->allocator->start; h.code_size = code->allocator->occupied_space(); for (cell i = 0; i < special_object_count; i++) h.special_objects[i] = (save_special_p(i) ? special_objects[i] : false_object); FILE* file = OPEN_WRITE(saving_filename); if (file == NULL) return false; if (safe_fwrite(&h, sizeof(image_header), 1, file) != 1) return false; if (safe_fwrite((void*)data->tenured->start, h.data_size, 1, file) != 1) return false; if (safe_fwrite((void*)code->allocator->start, h.code_size, 1, file) != 1) return false; if (raw_fclose(file) == -1) return false; if (!move_file(saving_filename, filename)) return false; return true; }
/* Save the current image to disk */ bool save_image(const F_CHAR *filename) { FILE* file; F_HEADER h; FPRINTF(stderr,"*** Saving %s...\n",filename); file = OPEN_WRITE(filename); if(file == NULL) { fprintf(stderr,"Cannot open image file: %s\n",strerror(errno)); return false; } F_ZONE *tenured = &data_heap->generations[TENURED]; h.magic = IMAGE_MAGIC; h.version = IMAGE_VERSION; h.data_relocation_base = tenured->start; h.data_size = tenured->here - tenured->start; h.code_relocation_base = code_heap.segment->start; h.code_size = heap_size(&code_heap); h.t = T; h.bignum_zero = bignum_zero; h.bignum_pos_one = bignum_pos_one; h.bignum_neg_one = bignum_neg_one; CELL i; for(i = 0; i < USER_ENV; i++) { if(i < FIRST_SAVE_ENV) h.userenv[i] = F; else h.userenv[i] = userenv[i]; } fwrite(&h,sizeof(F_HEADER),1,file); if(fwrite((void*)tenured->start,h.data_size,1,file) != 1) { fprintf(stderr,"Save data heap failed: %s\n",strerror(errno)); return false; } if(fwrite(first_block(&code_heap),h.code_size,1,file) != 1) { fprintf(stderr,"Save code heap failed: %s\n",strerror(errno)); return false; } if(fclose(file)) { fprintf(stderr,"Failed to close image file: %s\n",strerror(errno)); return false; } return true; }
/* Save the current image to disk */ bool save_image(const vm_char *filename) { FILE* file; image_header h; file = OPEN_WRITE(filename); if(file == NULL) { print_string("Cannot open image file: "); print_native_string(filename); nl(); print_string(strerror(errno)); nl(); return false; } zone *tenured = &data->generations[data->tenured()]; h.magic = image_magic; h.version = image_version; h.data_relocation_base = tenured->start; h.data_size = tenured->here - tenured->start; h.code_relocation_base = code.seg->start; h.code_size = heap_size(&code); h.t = T; h.bignum_zero = bignum_zero; h.bignum_pos_one = bignum_pos_one; h.bignum_neg_one = bignum_neg_one; for(cell i = 0; i < USER_ENV; i++) h.userenv[i] = (save_env_p(i) ? userenv[i] : F); bool ok = true; if(fwrite(&h,sizeof(image_header),1,file) != 1) ok = false; if(fwrite((void*)tenured->start,h.data_size,1,file) != 1) ok = false; if(fwrite(first_block(&code),h.code_size,1,file) != 1) ok = false; if(fclose(file)) ok = false; if(!ok) { print_string("save-image failed: "); print_string(strerror(errno)); nl(); } return ok; }
/* Save the current image to disk */ bool factor_vm::save_image(const vm_char *saving_filename, const vm_char *filename) { FILE* file; image_header h; file = OPEN_WRITE(saving_filename); if(file == NULL) { std::cout << "Cannot open image file: " << saving_filename << std::endl; std::cout << strerror(errno) << std::endl; return false; } h.magic = image_magic; h.version = image_version; h.data_relocation_base = data->tenured->start; h.data_size = data->tenured->occupied_space(); h.code_relocation_base = code->seg->start; h.code_size = code->allocator->occupied_space(); h.true_object = true_object; h.bignum_zero = bignum_zero; h.bignum_pos_one = bignum_pos_one; h.bignum_neg_one = bignum_neg_one; for(cell i = 0; i < special_object_count; i++) h.special_objects[i] = (save_special_p(i) ? special_objects[i] : false_object); bool ok = true; if(safe_fwrite(&h,sizeof(image_header),1,file) != 1) ok = false; if(safe_fwrite((void*)data->tenured->start,h.data_size,1,file) != 1) ok = false; if(safe_fwrite(code->allocator->first_block(),h.code_size,1,file) != 1) ok = false; safe_fclose(file); if(!ok) std::cout << "save-image failed: " << strerror(errno) << std::endl; else move_file(saving_filename,filename); return ok; }
/* return size of dump file */ static off_t dump(const char *s) { /* Build the big list */ at *ans = NIL, **where = &ans; /* 1 - the modules */ at *p = module_list(); at *q = p; while (CONSP(q)) { *where = new_cons(Car(q), NIL); where = &Cdr(*where); q = Cdr(q); } /* 2- the globals */ *where = global_defs(); /* Header */ at *atf = OPEN_WRITE(s,"dump"); FILE *f = Gptr(atf); write32(f, DUMPMAGIC); write32(f, DUMPVERSION); /* The macro character map */ errno = 0; fwrite(char_map,1,256,f); test_file_error(f, errno); /* Write the big list */ bool oldready = error_doc.ready_to_an_error; error_doc.ready_to_an_error = false; bwrite(ans, f, true); error_doc.ready_to_an_error = oldready; lush_delete(atf); /* close file */ /* get file size */ struct stat buf; if (stat(s, &buf)>=0) if (S_ISREG(buf.st_mode)) return buf.st_size; return (off_t)0; }