// This fun is called (only) from:
//
//     src/c/main/runtime-main.c
//
void   load_and_run_heap_image (
    // =======================
    //
    const char*	    heap_image_to_run_filename,
    Heapcleaner_Args*   heap_parameters
) {
    // Load a heap image from a file and resume execution.
    //
    // The arguments
    //
    //     agegroup0_buffer_bytesize
    //     active_agegroups
    //     oldest_agegroup_keeping_idle_fromspace_buffers
    //
    // possible command-line overrides of the heap parameters
    // specified in the image being imported.
    //
    // (Non-negative values signify override.)
    //
    // This function is called in only one place, in
    //     src/c/main/runtime-main.c

    Task* task = import_heap_image( heap_image_to_run_filename, heap_parameters );


    set_up_fault_handlers ();

#ifdef SIZES_C_64_MYTHRYL_32
    // Patch the 32-bit addresses:
    //
    patch_static_heapchunk_32_bit_addresses ();
#endif

    run_mythryl_task_and_runtime_eventloop( task );								// run_mythryl_task_and_runtime_eventloop		def in   src/c/main/run-mythryl-code-and-runtime-eventloop.c
}
예제 #2
0
void   load_compiled_files__may_heapclean   (
    // ==================================
    //
    const char*         compiled_files_to_load_filename,
    Heapcleaner_Args*   heap_parameters,				// See   struct cleaner_args   in   src/c/h/heap.h
    Roots*              extra_roots
){
    // Load into the runtime heap all the .compiled files
    // listed one per line in given compiled_files_to_load file:
    //
    // This function is called from exactly one spot, in
    //
    //     src/c/main/runtime-main.c

    int    max_boot_path_len;
    char*  filename_buf;

    int    seen_runtime_package_picklehash = FALSE;			// FALSE until we see the picklehash naming our runtime.

    open_logfile();

    Task* task
	=
	make_task(							// make_task					def in   src/c/main/runtime-state.c
	    TRUE,							// is_boot
	    heap_parameters
	);


    // Set up handlers for ^C, divide-by-zero,
    // integer overflow etc:
    //
    set_up_fault_handlers ();						// set_up_fault_handlers			def in   src/c/machine-dependent/posix-arithmetic-trap-handlers.c
									// set_up_fault_handlers			def in   src/c/machine-dependent/win32-fault.c
									// set_up_fault_handlers			def in   src/c/machine-dependent/cygwin-fault.c	

    // Set up RunVec in CStruct in
    //
    //     runtime_package__global.
    //
    // This constitutes an ersatz exports list implementing
    //
    //     src/lib/core/init/runtime.api
    // 
    // which we will later substitute for the (useless) code from
    //
    //     src/lib/core/init/runtime.pkg
    //
    // thus providing access to critical assembly fns including
    //
    //     find_cfun
    //
    // implemented in one of
    //
    //     src/c/machine-dependent/prim.sparc32.asm
    //     src/c/machine-dependent/prim.pwrpc32.asm
    //     src/c/machine-dependent/prim.intel32.asm
    //     src/c/machine-dependent/prim.intel32.masm
    //
    construct_runtime_package__global( task );				// construct_runtime_package__global	def in   src/c/main/construct-runtime-package.c

    // Construct the list of files to be loaded:
    //
    Val compiled_file_list
	=
	read_in_compiled_file_list__may_heapclean (
	    task,
            compiled_files_to_load_filename,
            &max_boot_path_len,
	    extra_roots
	);

    Roots roots1 = { &compiled_file_list, extra_roots };

    // This space is ultimately wasted:           XXX BUGGO FIXME
    //
    if (! (filename_buf = MALLOC( max_boot_path_len ))) {
	//
	die ("unable to allocate space for boot file names");
    }

    // Load all requested compiled_files into the heap:
    //
    while (compiled_file_list != LIST_NIL) {
	//
        char* filename =  filename_buf;

        // Need to make a copy of the filename because
        // load_compiled_file__may_heapclean is going to scribble into it:
        //
	strcpy( filename_buf, HEAP_STRING_AS_C_STRING( LIST_HEAD( compiled_file_list )));
       
	compiled_file_list = LIST_TAIL( compiled_file_list );		// Remove above filename from list of files to process.

	// If 'filename' does not begin with "RUNTIME_PACKAGE_PICKLEHASH=" ...
	//
	if (strstr(filename,"RUNTIME_PACKAGE_PICKLEHASH=") != filename) {
	    //
	    // ... then we can load it normally:
	    //
	    load_compiled_file__may_heapclean( task, filename, &roots1 );

	} else {

	    // We're processing the
            //
            //     RUNTIME_PACKAGE_PICKLEHASH=...
            //
            // set up for us by
            //
            //     src/app/makelib/mythryl-compiler-compiler/find-set-of-compiledfiles-for-executable.pkg

	    while (*filename++ != '=');   		// Step over "RUNTIME_PACKAGE_PICKLEHASH=" prefix.

	    if (seen_runtime_package_picklehash) {
		//
                if (log_fd) fclose( log_fd );

		die ("Runtime system picklehash registered more than once!\n");
		exit(1);								// Just for gcc's sake -- cannot exectute.

	    }

	    // Most parts of the Mythryl implementation treat the C-coded
	    // runtime functions as being just like library functions
	    // coded in Mythryl -- to avoid special cases, we go to great
	    // lengths to hide the differences.
	    //
	    // But this is one of the places where the charade breaks
	    // down -- there isn't actually any (useful) .compiled file
	    // corresponding to the runtime picklehash:  Instead, we
	    // must link runtime calls directly down into our C code.
	    //
	    // For more info, see the comments in
	    //     src/lib/core/init/runtime.pkg
	    //
	    // So here we implement some of that special handling:

	    // Register the runtime system under the given picklehash:
	    //
	    Picklehash picklehash;

	    int  l = strlen( filename );

	    for (int i = 0;   i < PICKLEHASH_BYTES;   i++) {
	        //
		int i2 = 2 * i;
		if (i2 + 1 < l) {
		    int c1 = filename[i2+0];
		    int c2 = filename[i2+1];
		    picklehash.bytes[i] = (hex(c1) << 4) + hex(c2);
		}
	    }
	    fprintf(
		log_fd ? log_fd : stderr,
		"\n                    load-compiledfiles.c:   Runtime system picklehash is      %s\n\n",
		filename
	    );

	    register_compiled_file_exports__may_heapclean( task, &picklehash, runtime_package__global, &roots1 );

	    seen_runtime_package_picklehash = TRUE;							// Make sure that we register the runtime system picklehash only once.
	}
    }

    if (log_fd)   fclose( log_fd );
}													// load_compiled_files__may_heapclean