| Attached Files | ocaml-4.00.1-data-marsh.tgz [^] (2,649 bytes) 2013-03-11 23:29
ocaml-4.00.1-data-marsh.diff [^] (9,866 bytes) 2013-03-11 23:57 [Show Content] [Hide Content]diff -Naur ocaml-4.00.1/asmrun/natdynlink.c ocaml-4.00.1-data-marsh/asmrun/natdynlink.c
--- ocaml-4.00.1/asmrun/natdynlink.c 2013-03-11 22:23:41.000000000 +0100
+++ ocaml-4.00.1-data-marsh/asmrun/natdynlink.c 2013-03-11 22:24:09.000000000 +0100
@@ -75,7 +75,7 @@
CAMLparam1 (symbol);
CAMLlocal1 (result);
void *sym,*sym2;
- struct code_fragment * cf;
+ struct code_fragment * cf = NULL;
#define optsym(n) getsym(handle,unit,n)
char *unit;
@@ -89,11 +89,6 @@
sym = optsym("");
if (NULL != sym) caml_register_dyn_global(sym);
- sym = optsym("__data_begin");
- sym2 = optsym("__data_end");
- if (NULL != sym && NULL != sym2)
- caml_page_table_add(In_static_data, sym, sym2);
-
sym = optsym("__code_begin");
sym2 = optsym("__code_end");
if (NULL != sym && NULL != sym2) {
@@ -101,10 +96,23 @@
cf = caml_stat_alloc(sizeof(struct code_fragment));
cf->code_start = (char *) sym;
cf->code_end = (char *) sym2;
+ cf->data_start = NULL;
+ cf->data_end = NULL;
cf->digest_computed = 0;
- caml_ext_table_add(&caml_code_fragments_table, cf);
}
+ sym = optsym("__data_begin");
+ sym2 = optsym("__data_end");
+ if (NULL != sym && NULL != sym2) {
+ caml_page_table_add(In_static_data, sym, sym2);
+ if (cf != NULL) {
+ cf->data_start = (char *) sym;
+ cf->data_end = (char *) sym2;
+ }
+ }
+
+ if (cf != NULL) caml_ext_table_add(&caml_code_fragments_table, cf);
+
entrypoint = optsym("__entry");
if (NULL != entrypoint) result = caml_callback((value)(&entrypoint), 0);
else result = Val_unit;
diff -Naur ocaml-4.00.1/asmrun/startup.c ocaml-4.00.1-data-marsh/asmrun/startup.c
--- ocaml-4.00.1/asmrun/startup.c 2013-03-11 22:23:41.000000000 +0100
+++ ocaml-4.00.1-data-marsh/asmrun/startup.c 2013-03-11 22:24:09.000000000 +0100
@@ -59,6 +59,22 @@
caml_atom_table, caml_atom_table + 256) != 0)
caml_fatal_error("Fatal error: not enough memory for the initial page table");
+ /* Register the data in the table of code fragments */
+ cf = caml_stat_alloc(sizeof(struct code_fragment));
+ if (caml_data_segments[0].begin != 0) {
+ cf->data_start = caml_data_segments[0].begin;
+ cf->data_end = caml_data_segments[0].end;
+ for (i = 1 ; caml_data_segments[i].begin != 0; i ++) {
+ if (caml_data_segments[i].begin < cf->data_start)
+ cf->data_start = caml_data_segments[i].begin;
+ if (caml_data_segments[i].end > cf->data_end)
+ cf->data_end = caml_data_segments[i].end;
+ }
+ } else {
+ cf->data_start = NULL;
+ cf->data_end = NULL;
+ }
+
for (i = 0; caml_data_segments[i].begin != 0; i++) {
/* 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. */
@@ -66,6 +82,7 @@
caml_data_segments[i].begin,
caml_data_segments[i].end + sizeof(value)) != 0)
caml_fatal_error("Fatal error: not enough memory for the initial page table");
+
}
caml_code_area_start = caml_code_segments[0].begin;
@@ -76,8 +93,8 @@
if (caml_code_segments[i].end > caml_code_area_end)
caml_code_area_end = caml_code_segments[i].end;
}
+
/* 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;
diff -Naur ocaml-4.00.1/byterun/extern.c ocaml-4.00.1-data-marsh/byterun/extern.c
--- ocaml-4.00.1/byterun/extern.c 2013-03-11 22:23:36.000000000 +0100
+++ ocaml-4.00.1-data-marsh/byterun/extern.c 2013-03-11 22:24:09.000000000 +0100
@@ -24,7 +24,6 @@
#include "gc.h"
#include "intext.h"
#include "io.h"
-#include "md5.h"
#include "memory.h"
#include "misc.h"
#include "mlvalues.h"
@@ -815,10 +814,7 @@
int i;
for (i = caml_code_fragments_table.size - 1; i >= 0; i--) {
struct code_fragment * cf = caml_code_fragments_table.contents[i];
- if (! cf->digest_computed) {
- caml_md5_block(cf->digest, cf->code_start, cf->code_end - cf->code_start);
- cf->digest_computed = 1;
- }
+ if (!cf->digest_computed) caml_update_code_fragment_digest(cf);
if (cf->code_start <= addr && addr < cf->code_end) return cf;
}
return NULL;
diff -Naur ocaml-4.00.1/byterun/fix_code.c ocaml-4.00.1-data-marsh/byterun/fix_code.c
--- ocaml-4.00.1/byterun/fix_code.c 2013-03-11 22:23:36.000000000 +0100
+++ ocaml-4.00.1-data-marsh/byterun/fix_code.c 2013-03-11 22:24:09.000000000 +0100
@@ -25,12 +25,13 @@
#include "fix_code.h"
#include "instruct.h"
#include "intext.h"
-#include "md5.h"
#include "memory.h"
#include "misc.h"
#include "mlvalues.h"
#include "reverse.h"
+char *caml_data;
+asize_t caml_data_size;
code_t caml_start_code;
asize_t caml_code_size;
unsigned char * caml_saved_code;
@@ -44,7 +45,9 @@
cf = caml_stat_alloc(sizeof(struct code_fragment));
cf->code_start = (char *) caml_start_code;
cf->code_end = (char *) caml_start_code + caml_code_size;
- caml_md5_block(cf->digest, caml_start_code, caml_code_size);
+ cf->data_start = (char *) caml_data;
+ cf->data_end = (char *) caml_data + caml_data_size;
+ caml_update_code_fragment_digest(cf);
cf->digest_computed = 1;
caml_ext_table_init(&caml_code_fragments_table, 8);
caml_ext_table_add(&caml_code_fragments_table, cf);
diff -Naur ocaml-4.00.1/byterun/fix_code.h ocaml-4.00.1-data-marsh/byterun/fix_code.h
--- ocaml-4.00.1/byterun/fix_code.h 2013-03-11 22:23:36.000000000 +0100
+++ ocaml-4.00.1-data-marsh/byterun/fix_code.h 2013-03-11 22:24:09.000000000 +0100
@@ -23,6 +23,8 @@
#include "misc.h"
#include "mlvalues.h"
+extern char *caml_data;
+extern asize_t caml_data_size;
extern code_t caml_start_code;
extern asize_t caml_code_size;
extern unsigned char * caml_saved_code;
diff -Naur ocaml-4.00.1/byterun/intern.c ocaml-4.00.1-data-marsh/byterun/intern.c
--- ocaml-4.00.1/byterun/intern.c 2013-03-11 22:23:36.000000000 +0100
+++ ocaml-4.00.1-data-marsh/byterun/intern.c 2013-03-11 22:24:09.000000000 +0100
@@ -26,7 +26,6 @@
#include "gc.h"
#include "intext.h"
#include "io.h"
-#include "md5.h"
#include "memory.h"
#include "mlvalues.h"
#include "misc.h"
@@ -738,10 +737,7 @@
int i;
for (i = caml_code_fragments_table.size - 1; i >= 0; i--) {
struct code_fragment * cf = caml_code_fragments_table.contents[i];
- if (! cf->digest_computed) {
- caml_md5_block(cf->digest, cf->code_start, cf->code_end - cf->code_start);
- cf->digest_computed = 1;
- }
+ if (!cf->digest_computed) caml_update_code_fragment_digest(cf);
if (memcmp(digest, cf->digest, 16) == 0) {
if (cf->code_start + offset < cf->code_end)
return cf->code_start + offset;
diff -Naur ocaml-4.00.1/byterun/intext.h ocaml-4.00.1-data-marsh/byterun/intext.h
--- ocaml-4.00.1/byterun/intext.h 2013-03-11 22:23:36.000000000 +0100
+++ ocaml-4.00.1-data-marsh/byterun/intext.h 2013-03-11 22:24:09.000000000 +0100
@@ -155,12 +155,18 @@
struct code_fragment {
char * code_start;
char * code_end;
+ char * data_start;
+ char * data_end;
unsigned char digest[16];
char digest_computed;
};
struct ext_table caml_code_fragments_table;
+/* Defined in misc.c */
+
+extern void caml_update_code_fragment_digest(struct code_fragment *cf);
+
/* </private> */
#ifdef __cplusplus
diff -Naur ocaml-4.00.1/byterun/meta.c ocaml-4.00.1-data-marsh/byterun/meta.c
--- ocaml-4.00.1/byterun/meta.c 2013-03-11 22:23:36.000000000 +0100
+++ ocaml-4.00.1-data-marsh/byterun/meta.c 2013-03-11 22:24:09.000000000 +0100
@@ -67,6 +67,8 @@
struct code_fragment * cf = caml_stat_alloc(sizeof(struct code_fragment));
cf->code_start = (char *) prog;
cf->code_end = (char *) prog + Long_val(len);
+ cf->data_start = NULL;
+ cf->data_end = NULL;
memcpy(cf->digest, String_val(digest), 16);
cf->digest_computed = 1;
caml_ext_table_add(&caml_code_fragments_table, cf);
diff -Naur ocaml-4.00.1/byterun/misc.c ocaml-4.00.1-data-marsh/byterun/misc.c
--- ocaml-4.00.1/byterun/misc.c 2013-03-11 22:23:36.000000000 +0100
+++ ocaml-4.00.1-data-marsh/byterun/misc.c 2013-03-11 22:24:09.000000000 +0100
@@ -16,7 +16,9 @@
#include <stdio.h>
#include "config.h"
#include "misc.h"
+#include "intext.h"
#include "memory.h"
+#include "md5.h"
#ifdef DEBUG
@@ -123,3 +125,13 @@
for (i = 0; i < tbl->size; i++) caml_stat_free(tbl->contents[i]);
caml_stat_free(tbl->contents);
}
+
+void caml_update_code_fragment_digest(struct code_fragment *cf) {
+ int i;
+ unsigned char code_digest[16];
+ unsigned char data_digest[16];
+ caml_md5_block(code_digest, cf->code_start, cf->code_end - cf->code_start);
+ caml_md5_block(data_digest, cf->data_start, cf->data_end - cf->data_start);
+ for (i = 0 ; i < 16 ; i ++)
+ cf->digest[i] = code_digest[i] ^ data_digest[i];
+}
diff -Naur ocaml-4.00.1/byterun/startup.c ocaml-4.00.1-data-marsh/byterun/startup.c
--- ocaml-4.00.1/byterun/startup.c 2013-03-11 22:23:36.000000000 +0100
+++ ocaml-4.00.1-data-marsh/byterun/startup.c 2013-03-11 22:24:09.000000000 +0100
@@ -391,8 +391,11 @@
/* Initialize the debugger, if needed */
caml_debugger_init();
/* Load the code */
+ caml_data_size = caml_seek_section(fd, &trail, "DATA");
+ caml_data = read_section(fd, &trail, "DATA");
caml_code_size = caml_seek_section(fd, &trail, "CODE");
caml_load_code(fd, caml_code_size);
+ caml_stat_free(caml_data);
/* Build the table of primitives */
shared_lib_path = read_section(fd, &trail, "DLPT");
shared_libs = read_section(fd, &trail, "DLLS");
@@ -477,6 +480,8 @@
/* Load the code */
caml_start_code = code;
caml_code_size = code_size;
+ caml_data = data;
+ caml_data_size = data_size;
caml_init_code_fragments();
if (caml_debugger_in_use) {
int len, i;
|