/* This function also initializes the data and code heaps */ void factor_vm::load_image(vm_parameters* p) { FILE* file = open_image(p); if (file == NULL) { std::cout << "Cannot open image file: " << p->image_path << std::endl; char *msg = threadsafe_strerror(errno); std::cout << "strerror:2: " << msg << std::endl; free(msg); exit(1); } image_header h; if (raw_fread(&h, sizeof(image_header), 1, file) != 1) fatal_error("Cannot read image header", 0); if (h.magic != image_magic) fatal_error("Bad image: magic number check failed", h.magic); if (h.version != image_version) fatal_error("Bad image: version number check failed", h.version); load_data_heap(file, &h, p); load_code_heap(file, &h, p); raw_fclose(file); /* Certain special objects in the image are known to the runtime */ memcpy(special_objects, h.special_objects, sizeof(special_objects)); cell data_offset = data->tenured->start - h.data_relocation_base; cell code_offset = code->allocator->start - h.code_relocation_base; fixup_heaps(data_offset, code_offset); /* Store image path name */ special_objects[OBJ_IMAGE] = allot_alien(false_object, (cell)p->image_path); }
FILE* factor_vm::open_image(vm_parameters* p) { if (p->embedded_image) { FILE* file = OPEN_READ(p->executable_path); if (file == NULL) { std::cout << "Cannot open embedded image" << std::endl; char *msg = threadsafe_strerror(errno); std::cout << "strerror:1: " << msg << std::endl; free(msg); exit(1); } embedded_image_footer footer; if (!read_embedded_image_footer(file, &footer)) { std::cout << "No embedded image" << std::endl; exit(1); } safe_fseek(file, (off_t)footer.image_offset, SEEK_SET); return file; } else return OPEN_READ(p->image_path); }
// Read an image file from disk, only done once during startup // This function also initializes the data and code heaps void factor_vm::load_image(vm_parameters* p) { FILE* file = OPEN_READ(p->image_path); if (file == NULL) { std::cout << "Cannot open image file: " << p->image_path << std::endl; char *msg = threadsafe_strerror(errno); std::cout << "strerror:2: " << msg << std::endl; free(msg); exit(1); } if (p->embedded_image) { embedded_image_footer footer; if (!read_embedded_image_footer(file, &footer)) { std::cout << "No embedded image" << std::endl; exit(1); } safe_fseek(file, (off_t)footer.image_offset, SEEK_SET); } image_header h; if (raw_fread(&h, sizeof(image_header), 1, file) != 1) fatal_error("Cannot read image header", 0); if (h.magic != image_magic) fatal_error("Bad image: magic number check failed", h.magic); if (h.version != image_version) fatal_error("Bad image: version number check failed", h.version); load_data_heap(file, &h, p); load_code_heap(file, &h, p); raw_fclose(file); // Certain special objects in the image are known to the runtime memcpy(special_objects, h.special_objects, sizeof(special_objects)); cell data_offset = data->tenured->start - h.data_relocation_base; cell code_offset = code->allocator->start - h.code_relocation_base; fixup_heaps(data_offset, code_offset); }