value caml_startup_common(char_os **argv, int pooling) { char_os * exe_name, * proc_self_exe; char tos; CAML_INIT_DOMAIN_STATE; /* Determine options */ caml_parse_ocamlrunparam(); #ifdef DEBUG caml_gc_message (-1, "### OCaml runtime: debug mode ###\n"); #endif if (caml_params->cleanup_on_exit) pooling = 1; if (!caml_startup_aux(pooling)) return Val_unit; #ifdef WITH_SPACETIME caml_spacetime_initialize(); #endif caml_init_ieee_floats(); #if defined(_MSC_VER) && __STDC_SECURE_LIB__ >= 200411L caml_install_invalid_parameter_handler(); #endif caml_init_custom_operations(); caml_init_gc (); if (caml_params->backtrace_enabled_init) caml_record_backtrace(Val_int(1)); /* Capture 16-byte aligned (ceil) system_stack_high */ Caml_state->system_stack_high = (char*)((((uintnat)&tos + 16) >> 4) << 4); init_segments(); caml_init_signals(); #ifdef _WIN32 caml_win32_overflow_detection(); #endif caml_debugger_init (); /* force debugger.o stub to be linked */ exe_name = argv[0]; if (exe_name == NULL) exe_name = _T(""); proc_self_exe = caml_executable_name(); if (proc_self_exe != NULL) exe_name = proc_self_exe; else exe_name = caml_search_exe_in_path(exe_name); caml_init_argv(exe_name, argv); if (sigsetjmp(caml_termination_jmpbuf.buf, 0)) { if (caml_termination_hook != NULL) caml_termination_hook(NULL); return Val_unit; } caml_init_main_stack(); return caml_start_program(Caml_state->young_ptr); }
/* must be run on the domain's thread */ static void create_domain(uintnat initial_minor_heap_size, int is_main) { int i; dom_internal* d = 0; Assert (domain_self == 0); caml_plat_lock(&all_domains_lock); for (i = 0; i < Max_domains; i++) { if (!all_domains[i].running) { d = &all_domains[i]; break; } } if (d) { d->running = 1; d->state.is_main = is_main; d->state.vm_inited = 0; d->state.internals = d; /* FIXME: shutdown RPC? */ atomic_store_rel(&d->rpc_request, RPC_IDLE); domain_self = d; caml_domain_state = (void*)(d->tls_area); caml_plat_lock(&d->roots_lock); if (!d->interrupt_word_address) { caml_mem_commit((void*)d->tls_area, (d->tls_area_end - d->tls_area)); atomic_uintnat* young_limit = (atomic_uintnat*)&caml_domain_state->young_limit; d->interrupt_word_address = young_limit; atomic_store_rel(young_limit, d->minor_heap_area); } caml_domain_state->young_start = caml_domain_state->young_end = caml_domain_state->young_ptr = 0; d->state.shared_heap = caml_init_shared_heap(); caml_init_major_gc(); caml_reallocate_minor_heap(initial_minor_heap_size); caml_init_main_stack(); d->state.remembered_set = &caml_remembered_set; d->state.local_roots = &caml_local_roots; #ifdef NATIVE_CODE /* FIXME */ #else d->state.current_stack = &caml_current_stack; #endif d->state.state = caml_domain_state; d->state.mark_stack = &caml_mark_stack; d->state.mark_stack_count = &caml_mark_stack_count; d->state.vm_inited = 1; } caml_plat_unlock(&all_domains_lock); }