signature MLTON_WORLD =
sig
datatype status = Clone | Original
val load: string -> 'a
val save: string -> status
val saveThread: string * Thread.Runnable.t -> unit
end
-
datatype statusspecifies whether a world is original or restarted (a clone).
-
load floads the saved computation from file
f. -
save fsaves the entire state of the computation to the file
f. The computation can then be restarted at a later time usingWorld.loador theload-worldruntime option. The call tosavein the original computation returnsOriginaland the call in the restarted world returnsClone. -
saveThread (f, rt)saves the entire state of the computation to the file
fthat will resume with threadrtupon restart.
Notes
Executables that save and load worlds are incompatible with address space layout randomization (ASLR) of the executable (though, not of shared libraries). The state of a computation includes addresses into the code and data segments of the executable (e.g., static runtime-system data, return addresses); such addresses are invalid when interpreted by the executable loaded at a different base address.
Executables that save and load worlds should be compiled with an option to suppress the generation of position-independent executables.
-
Darwin 11 (Mac OS X Lion) and higher :
-link-opt -fno-PIE
Example
Suppose that save-world.sml contains the following.
open MLton.World
val _ =
case save "world" of
Original => print "I am the original\n"
| Clone => print "I am the clone\n"
Then, if we compile save-world.sml and run it, the Original
branch will execute, and a file named world will be created.
% mlton save-world.sml % ./save-world I am the original
We can then load world using the load-world
run time option.
% ./save-world @MLton load-world world -- I am the clone