Guest User

Untitled

a guest
Feb 16th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.63 KB | None | 0 0
  1. diff -Naur ocaml-4.00.1/asmrun/natdynlink.c ocaml-4.00.1-data-marsh/asmrun/natdynlink.c
  2. --- ocaml-4.00.1/asmrun/natdynlink.c 2013-03-11 22:23:41.000000000 +0100
  3. +++ ocaml-4.00.1-data-marsh/asmrun/natdynlink.c 2013-03-11 22:24:09.000000000 +0100
  4. @@ -75,7 +75,7 @@
  5. CAMLparam1 (symbol);
  6. CAMLlocal1 (result);
  7. void *sym,*sym2;
  8. - struct code_fragment * cf;
  9. + struct code_fragment * cf = NULL;
  10.  
  11. #define optsym(n) getsym(handle,unit,n)
  12. char *unit;
  13. @@ -89,11 +89,6 @@
  14. sym = optsym("");
  15. if (NULL != sym) caml_register_dyn_global(sym);
  16.  
  17. - sym = optsym("__data_begin");
  18. - sym2 = optsym("__data_end");
  19. - if (NULL != sym && NULL != sym2)
  20. - caml_page_table_add(In_static_data, sym, sym2);
  21. -
  22. sym = optsym("__code_begin");
  23. sym2 = optsym("__code_end");
  24. if (NULL != sym && NULL != sym2) {
  25. @@ -101,10 +96,23 @@
  26. cf = caml_stat_alloc(sizeof(struct code_fragment));
  27. cf->code_start = (char *) sym;
  28. cf->code_end = (char *) sym2;
  29. + cf->data_start = NULL;
  30. + cf->data_end = NULL;
  31. cf->digest_computed = 0;
  32. - caml_ext_table_add(&caml_code_fragments_table, cf);
  33. }
  34.  
  35. + sym = optsym("__data_begin");
  36. + sym2 = optsym("__data_end");
  37. + if (NULL != sym && NULL != sym2) {
  38. + caml_page_table_add(In_static_data, sym, sym2);
  39. + if (cf != NULL) {
  40. + cf->data_start = (char *) sym;
  41. + cf->data_end = (char *) sym2;
  42. + }
  43. + }
  44. +
  45. + if (cf != NULL) caml_ext_table_add(&caml_code_fragments_table, cf);
  46. +
  47. entrypoint = optsym("__entry");
  48. if (NULL != entrypoint) result = caml_callback((value)(&entrypoint), 0);
  49. else result = Val_unit;
  50. diff -Naur ocaml-4.00.1/asmrun/startup.c ocaml-4.00.1-data-marsh/asmrun/startup.c
  51. --- ocaml-4.00.1/asmrun/startup.c 2013-03-11 22:23:41.000000000 +0100
  52. +++ ocaml-4.00.1-data-marsh/asmrun/startup.c 2013-03-11 22:24:09.000000000 +0100
  53. @@ -59,6 +59,22 @@
  54. caml_atom_table, caml_atom_table + 256) != 0)
  55. caml_fatal_error("Fatal error: not enough memory for the initial page table");
  56.  
  57. + /* Register the data in the table of code fragments */
  58. + cf = caml_stat_alloc(sizeof(struct code_fragment));
  59. + if (caml_data_segments[0].begin != 0) {
  60. + cf->data_start = caml_data_segments[0].begin;
  61. + cf->data_end = caml_data_segments[0].end;
  62. + for (i = 1 ; caml_data_segments[i].begin != 0; i ++) {
  63. + if (caml_data_segments[i].begin < cf->data_start)
  64. + cf->data_start = caml_data_segments[i].begin;
  65. + if (caml_data_segments[i].end > cf->data_end)
  66. + cf->data_end = caml_data_segments[i].end;
  67. + }
  68. + } else {
  69. + cf->data_start = NULL;
  70. + cf->data_end = NULL;
  71. + }
  72. +
  73. for (i = 0; caml_data_segments[i].begin != 0; i++) {
  74. /* PR#5509: we must include the zero word at end of data segment,
  75. because pointers equal to caml_data_segments[i].end are static data. */
  76. @@ -66,6 +82,7 @@
  77. caml_data_segments[i].begin,
  78. caml_data_segments[i].end + sizeof(value)) != 0)
  79. caml_fatal_error("Fatal error: not enough memory for the initial page table");
  80. +
  81. }
  82.  
  83. caml_code_area_start = caml_code_segments[0].begin;
  84. @@ -76,8 +93,8 @@
  85. if (caml_code_segments[i].end > caml_code_area_end)
  86. caml_code_area_end = caml_code_segments[i].end;
  87. }
  88. +
  89. /* Register the code in the table of code fragments */
  90. - cf = caml_stat_alloc(sizeof(struct code_fragment));
  91. cf->code_start = caml_code_area_start;
  92. cf->code_end = caml_code_area_end;
  93. cf->digest_computed = 0;
  94. diff -Naur ocaml-4.00.1/byterun/extern.c ocaml-4.00.1-data-marsh/byterun/extern.c
  95. --- ocaml-4.00.1/byterun/extern.c 2013-03-11 22:23:36.000000000 +0100
  96. +++ ocaml-4.00.1-data-marsh/byterun/extern.c 2013-03-11 22:24:09.000000000 +0100
  97. @@ -24,7 +24,6 @@
  98. #include "gc.h"
  99. #include "intext.h"
  100. #include "io.h"
  101. -#include "md5.h"
  102. #include "memory.h"
  103. #include "misc.h"
  104. #include "mlvalues.h"
  105. @@ -815,10 +814,7 @@
  106. int i;
  107. for (i = caml_code_fragments_table.size - 1; i >= 0; i--) {
  108. struct code_fragment * cf = caml_code_fragments_table.contents[i];
  109. - if (! cf->digest_computed) {
  110. - caml_md5_block(cf->digest, cf->code_start, cf->code_end - cf->code_start);
  111. - cf->digest_computed = 1;
  112. - }
  113. + if (!cf->digest_computed) caml_update_code_fragment_digest(cf);
  114. if (cf->code_start <= addr && addr < cf->code_end) return cf;
  115. }
  116. return NULL;
  117. diff -Naur ocaml-4.00.1/byterun/fix_code.c ocaml-4.00.1-data-marsh/byterun/fix_code.c
  118. --- ocaml-4.00.1/byterun/fix_code.c 2013-03-11 22:23:36.000000000 +0100
  119. +++ ocaml-4.00.1-data-marsh/byterun/fix_code.c 2013-03-11 22:24:09.000000000 +0100
  120. @@ -25,12 +25,13 @@
  121. #include "fix_code.h"
  122. #include "instruct.h"
  123. #include "intext.h"
  124. -#include "md5.h"
  125. #include "memory.h"
  126. #include "misc.h"
  127. #include "mlvalues.h"
  128. #include "reverse.h"
  129.  
  130. +char *caml_data;
  131. +asize_t caml_data_size;
  132. code_t caml_start_code;
  133. asize_t caml_code_size;
  134. unsigned char * caml_saved_code;
  135. @@ -44,7 +45,9 @@
  136. cf = caml_stat_alloc(sizeof(struct code_fragment));
  137. cf->code_start = (char *) caml_start_code;
  138. cf->code_end = (char *) caml_start_code + caml_code_size;
  139. - caml_md5_block(cf->digest, caml_start_code, caml_code_size);
  140. + cf->data_start = (char *) caml_data;
  141. + cf->data_end = (char *) caml_data + caml_data_size;
  142. + caml_update_code_fragment_digest(cf);
  143. cf->digest_computed = 1;
  144. caml_ext_table_init(&caml_code_fragments_table, 8);
  145. caml_ext_table_add(&caml_code_fragments_table, cf);
  146. diff -Naur ocaml-4.00.1/byterun/fix_code.h ocaml-4.00.1-data-marsh/byterun/fix_code.h
  147. --- ocaml-4.00.1/byterun/fix_code.h 2013-03-11 22:23:36.000000000 +0100
  148. +++ ocaml-4.00.1-data-marsh/byterun/fix_code.h 2013-03-11 22:24:09.000000000 +0100
  149. @@ -23,6 +23,8 @@
  150. #include "misc.h"
  151. #include "mlvalues.h"
  152.  
  153. +extern char *caml_data;
  154. +extern asize_t caml_data_size;
  155. extern code_t caml_start_code;
  156. extern asize_t caml_code_size;
  157. extern unsigned char * caml_saved_code;
  158. diff -Naur ocaml-4.00.1/byterun/intern.c ocaml-4.00.1-data-marsh/byterun/intern.c
  159. --- ocaml-4.00.1/byterun/intern.c 2013-03-11 22:23:36.000000000 +0100
  160. +++ ocaml-4.00.1-data-marsh/byterun/intern.c 2013-03-11 22:24:09.000000000 +0100
  161. @@ -26,7 +26,6 @@
  162. #include "gc.h"
  163. #include "intext.h"
  164. #include "io.h"
  165. -#include "md5.h"
  166. #include "memory.h"
  167. #include "mlvalues.h"
  168. #include "misc.h"
  169. @@ -738,10 +737,7 @@
  170. int i;
  171. for (i = caml_code_fragments_table.size - 1; i >= 0; i--) {
  172. struct code_fragment * cf = caml_code_fragments_table.contents[i];
  173. - if (! cf->digest_computed) {
  174. - caml_md5_block(cf->digest, cf->code_start, cf->code_end - cf->code_start);
  175. - cf->digest_computed = 1;
  176. - }
  177. + if (!cf->digest_computed) caml_update_code_fragment_digest(cf);
  178. if (memcmp(digest, cf->digest, 16) == 0) {
  179. if (cf->code_start + offset < cf->code_end)
  180. return cf->code_start + offset;
  181. diff -Naur ocaml-4.00.1/byterun/intext.h ocaml-4.00.1-data-marsh/byterun/intext.h
  182. --- ocaml-4.00.1/byterun/intext.h 2013-03-11 22:23:36.000000000 +0100
  183. +++ ocaml-4.00.1-data-marsh/byterun/intext.h 2013-03-11 22:24:09.000000000 +0100
  184. @@ -155,12 +155,18 @@
  185. struct code_fragment {
  186. char * code_start;
  187. char * code_end;
  188. + char * data_start;
  189. + char * data_end;
  190. unsigned char digest[16];
  191. char digest_computed;
  192. };
  193.  
  194. struct ext_table caml_code_fragments_table;
  195.  
  196. +/* Defined in misc.c */
  197. +
  198. +extern void caml_update_code_fragment_digest(struct code_fragment *cf);
  199. +
  200. /* </private> */
  201.  
  202. #ifdef __cplusplus
  203. diff -Naur ocaml-4.00.1/byterun/meta.c ocaml-4.00.1-data-marsh/byterun/meta.c
  204. --- ocaml-4.00.1/byterun/meta.c 2013-03-11 22:23:36.000000000 +0100
  205. +++ ocaml-4.00.1-data-marsh/byterun/meta.c 2013-03-11 22:24:09.000000000 +0100
  206. @@ -67,6 +67,8 @@
  207. struct code_fragment * cf = caml_stat_alloc(sizeof(struct code_fragment));
  208. cf->code_start = (char *) prog;
  209. cf->code_end = (char *) prog + Long_val(len);
  210. + cf->data_start = NULL;
  211. + cf->data_end = NULL;
  212. memcpy(cf->digest, String_val(digest), 16);
  213. cf->digest_computed = 1;
  214. caml_ext_table_add(&caml_code_fragments_table, cf);
  215. diff -Naur ocaml-4.00.1/byterun/misc.c ocaml-4.00.1-data-marsh/byterun/misc.c
  216. --- ocaml-4.00.1/byterun/misc.c 2013-03-11 22:23:36.000000000 +0100
  217. +++ ocaml-4.00.1-data-marsh/byterun/misc.c 2013-03-11 22:24:09.000000000 +0100
  218. @@ -16,7 +16,9 @@
  219. #include <stdio.h>
  220. #include "config.h"
  221. #include "misc.h"
  222. +#include "intext.h"
  223. #include "memory.h"
  224. +#include "md5.h"
  225.  
  226. #ifdef DEBUG
  227.  
  228. @@ -123,3 +125,13 @@
  229. for (i = 0; i < tbl->size; i++) caml_stat_free(tbl->contents[i]);
  230. caml_stat_free(tbl->contents);
  231. }
  232. +
  233. +void caml_update_code_fragment_digest(struct code_fragment *cf) {
  234. + int i;
  235. + unsigned char code_digest[16];
  236. + unsigned char data_digest[16];
  237. + caml_md5_block(code_digest, cf->code_start, cf->code_end - cf->code_start);
  238. + caml_md5_block(data_digest, cf->data_start, cf->data_end - cf->data_start);
  239. + for (i = 0 ; i < 16 ; i ++)
  240. + cf->digest[i] = code_digest[i] ^ data_digest[i];
  241. +}
  242. diff -Naur ocaml-4.00.1/byterun/startup.c ocaml-4.00.1-data-marsh/byterun/startup.c
  243. --- ocaml-4.00.1/byterun/startup.c 2013-03-11 22:23:36.000000000 +0100
  244. +++ ocaml-4.00.1-data-marsh/byterun/startup.c 2013-03-11 22:24:09.000000000 +0100
  245. @@ -391,8 +391,11 @@
  246. /* Initialize the debugger, if needed */
  247. caml_debugger_init();
  248. /* Load the code */
  249. + caml_data_size = caml_seek_section(fd, &trail, "DATA");
  250. + caml_data = read_section(fd, &trail, "DATA");
  251. caml_code_size = caml_seek_section(fd, &trail, "CODE");
  252. caml_load_code(fd, caml_code_size);
  253. + caml_stat_free(caml_data);
  254. /* Build the table of primitives */
  255. shared_lib_path = read_section(fd, &trail, "DLPT");
  256. shared_libs = read_section(fd, &trail, "DLLS");
  257. @@ -477,6 +480,8 @@
  258. /* Load the code */
  259. caml_start_code = code;
  260. caml_code_size = code_size;
  261. + caml_data = data;
  262. + caml_data_size = data_size;
  263. caml_init_code_fragments();
  264. if (caml_debugger_in_use) {
  265. int len, i;
Add Comment
Please, Sign In to add comment