1995-08-09 08:06:35 -07:00
|
|
|
/***********************************************************************/
|
|
|
|
/* */
|
2011-07-27 07:17:02 -07:00
|
|
|
/* OCaml */
|
1995-08-09 08:06:35 -07:00
|
|
|
/* */
|
|
|
|
/* Xavier Leroy and Damien Doligez, INRIA Rocquencourt */
|
|
|
|
/* */
|
1996-04-30 07:53:58 -07:00
|
|
|
/* Copyright 1996 Institut National de Recherche en Informatique et */
|
1999-11-17 10:59:06 -08:00
|
|
|
/* en Automatique. All rights reserved. This file is distributed */
|
2001-12-07 05:41:02 -08:00
|
|
|
/* under the terms of the GNU Library General Public License, with */
|
|
|
|
/* the special exception on linking described in file ../LICENSE. */
|
1995-08-09 08:06:35 -07:00
|
|
|
/* */
|
|
|
|
/***********************************************************************/
|
|
|
|
|
1995-07-10 02:48:27 -07:00
|
|
|
/* Start-up code */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2014-12-27 06:41:49 -08:00
|
|
|
#include "caml/callback.h"
|
|
|
|
#include "caml/backtrace.h"
|
|
|
|
#include "caml/custom.h"
|
|
|
|
#include "caml/debugger.h"
|
|
|
|
#include "caml/fail.h"
|
|
|
|
#include "caml/freelist.h"
|
|
|
|
#include "caml/gc.h"
|
|
|
|
#include "caml/gc_ctrl.h"
|
|
|
|
#include "caml/intext.h"
|
|
|
|
#include "caml/memory.h"
|
|
|
|
#include "caml/misc.h"
|
|
|
|
#include "caml/mlvalues.h"
|
|
|
|
#include "caml/osdeps.h"
|
|
|
|
#include "caml/printexc.h"
|
2010-04-27 00:55:08 -07:00
|
|
|
#include "stack.h"
|
2015-05-04 08:44:40 -07:00
|
|
|
#include "caml/startup_aux.h"
|
2014-12-27 06:41:49 -08:00
|
|
|
#include "caml/sys.h"
|
1996-11-07 05:12:16 -08:00
|
|
|
#ifdef HAS_UI
|
2014-12-27 06:41:49 -08:00
|
|
|
#include "caml/ui.h"
|
1996-11-07 05:12:16 -08:00
|
|
|
#endif
|
1995-07-10 02:48:27 -07:00
|
|
|
|
2004-01-01 08:42:43 -08:00
|
|
|
extern int caml_parser_trace;
|
2007-11-06 07:16:56 -08:00
|
|
|
CAMLexport header_t caml_atom_table[256];
|
2004-01-02 11:23:29 -08:00
|
|
|
char * caml_code_area_start, * caml_code_area_end;
|
1995-07-10 02:48:27 -07:00
|
|
|
|
1997-07-02 11:16:15 -07:00
|
|
|
/* Initialize the atom table and the static data and code area limits. */
|
1996-11-07 02:55:49 -08:00
|
|
|
|
1997-07-02 11:16:15 -07:00
|
|
|
struct segment { char * begin; char * end; };
|
|
|
|
|
2015-05-04 08:44:40 -07:00
|
|
|
static void init_static(void)
|
1995-07-10 02:48:27 -07:00
|
|
|
{
|
1997-07-02 11:16:15 -07:00
|
|
|
extern struct segment caml_data_segments[], caml_code_segments[];
|
2008-01-03 01:37:10 -08:00
|
|
|
int i;
|
2012-03-13 07:50:41 -07:00
|
|
|
struct code_fragment * cf;
|
1996-02-20 02:59:35 -08:00
|
|
|
|
2015-05-04 08:44:40 -07:00
|
|
|
caml_init_atom_table ();
|
2008-01-03 01:37:10 -08:00
|
|
|
|
|
|
|
for (i = 0; caml_data_segments[i].begin != 0; i++) {
|
2012-02-18 08:56:29 -08:00
|
|
|
/* PR#5509: we must include the zero word at end of data segment,
|
|
|
|
because pointers equal to caml_data_segments[i].end are static data. */
|
2008-12-03 10:09:09 -08:00
|
|
|
if (caml_page_table_add(In_static_data,
|
2008-01-03 01:37:10 -08:00
|
|
|
caml_data_segments[i].begin,
|
2012-02-18 08:56:29 -08:00
|
|
|
caml_data_segments[i].end + sizeof(value)) != 0)
|
2013-03-09 14:38:52 -08:00
|
|
|
caml_fatal_error("Fatal error: not enough memory for initial page table");
|
2008-01-03 01:37:10 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
caml_code_area_start = caml_code_segments[0].begin;
|
|
|
|
caml_code_area_end = caml_code_segments[0].end;
|
|
|
|
for (i = 1; caml_code_segments[i].begin != 0; i++) {
|
|
|
|
if (caml_code_segments[i].begin < caml_code_area_start)
|
|
|
|
caml_code_area_start = caml_code_segments[i].begin;
|
|
|
|
if (caml_code_segments[i].end > caml_code_area_end)
|
|
|
|
caml_code_area_end = caml_code_segments[i].end;
|
|
|
|
}
|
2012-03-13 07:50:41 -07:00
|
|
|
/* Register the code in the table of code fragments */
|
|
|
|
cf = caml_stat_alloc(sizeof(struct code_fragment));
|
|
|
|
cf->code_start = caml_code_area_start;
|
|
|
|
cf->code_end = caml_code_area_end;
|
|
|
|
cf->digest_computed = 0;
|
|
|
|
caml_ext_table_init(&caml_code_fragments_table, 8);
|
|
|
|
caml_ext_table_add(&caml_code_fragments_table, cf);
|
1995-07-10 02:48:27 -07:00
|
|
|
}
|
|
|
|
|
2003-06-16 05:31:14 -07:00
|
|
|
/* These are termination hooks used by the systhreads library */
|
|
|
|
struct longjmp_buffer caml_termination_jmpbuf;
|
|
|
|
void (*caml_termination_hook)(void *) = NULL;
|
|
|
|
|
1999-02-14 08:48:25 -08:00
|
|
|
extern value caml_start_program (void);
|
2004-01-02 11:23:29 -08:00
|
|
|
extern void caml_init_ieee_floats (void);
|
2004-01-01 08:42:43 -08:00
|
|
|
extern void caml_init_signals (void);
|
1996-11-07 02:55:49 -08:00
|
|
|
|
2013-01-17 01:04:53 -08:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
|
|
|
|
/* PR 4887: avoid crash box of windows runtime on some system calls */
|
|
|
|
extern void caml_install_invalid_parameter_handler();
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
void caml_main(char **argv)
|
1996-11-07 02:55:49 -08:00
|
|
|
{
|
2002-02-11 05:51:40 -08:00
|
|
|
char * exe_name;
|
|
|
|
static char proc_self_exe[256];
|
1999-02-14 08:48:25 -08:00
|
|
|
value res;
|
2010-04-27 00:55:08 -07:00
|
|
|
char tos;
|
1999-02-14 08:48:25 -08:00
|
|
|
|
2015-07-26 12:01:47 -07:00
|
|
|
caml_init_frame_descriptors();
|
2004-01-02 11:23:29 -08:00
|
|
|
caml_init_ieee_floats();
|
2013-01-17 01:04:53 -08:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
caml_install_invalid_parameter_handler();
|
|
|
|
#endif
|
2004-01-01 08:42:43 -08:00
|
|
|
caml_init_custom_operations();
|
1996-11-07 02:55:49 -08:00
|
|
|
#ifdef DEBUG
|
2003-12-29 14:15:02 -08:00
|
|
|
caml_verb_gc = 63;
|
1996-11-07 02:55:49 -08:00
|
|
|
#endif
|
2010-04-27 00:55:08 -07:00
|
|
|
caml_top_of_stack = &tos;
|
2015-05-04 08:44:40 -07:00
|
|
|
caml_parse_ocamlrunparam();
|
|
|
|
caml_init_gc (caml_init_minor_heap_wsz, caml_init_heap_wsz,
|
|
|
|
caml_init_heap_chunk_sz, caml_init_percent_free,
|
|
|
|
caml_init_max_percent_free);
|
|
|
|
init_static();
|
2004-01-01 08:42:43 -08:00
|
|
|
caml_init_signals();
|
2010-04-22 08:41:16 -07:00
|
|
|
caml_debugger_init (); /* force debugger.o stub to be linked */
|
2002-02-11 05:51:40 -08:00
|
|
|
exe_name = argv[0];
|
2005-03-24 09:20:54 -08:00
|
|
|
if (exe_name == NULL) exe_name = "";
|
2004-01-01 10:32:36 -08:00
|
|
|
if (caml_executable_name(proc_self_exe, sizeof(proc_self_exe)) == 0)
|
2002-02-11 05:51:40 -08:00
|
|
|
exe_name = proc_self_exe;
|
2005-03-24 09:20:54 -08:00
|
|
|
else
|
|
|
|
exe_name = caml_search_exe_in_path(exe_name);
|
2003-12-16 10:09:44 -08:00
|
|
|
caml_sys_init(exe_name, argv);
|
2003-06-16 05:31:14 -07:00
|
|
|
if (sigsetjmp(caml_termination_jmpbuf.buf, 0)) {
|
|
|
|
if (caml_termination_hook != NULL) caml_termination_hook(NULL);
|
|
|
|
return;
|
|
|
|
}
|
1999-02-14 08:48:25 -08:00
|
|
|
res = caml_start_program();
|
|
|
|
if (Is_exception_result(res))
|
2004-01-01 08:42:43 -08:00
|
|
|
caml_fatal_uncaught_exception(Extract_exception(res));
|
1995-07-10 02:48:27 -07:00
|
|
|
}
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
void caml_startup(char **argv)
|
1996-11-07 02:55:49 -08:00
|
|
|
{
|
|
|
|
caml_main(argv);
|
|
|
|
}
|