+open Virt_mem_utils
+open Virt_mem_mmap
+
+let run debug images =
+ (* Print new_utsname structure from bitstring. *)
+ let print_new_utsname name bs =
+ (* Truncate an OCaml string at the first ASCII NUL character, ie. as
+ * if it were a C string.
+ *)
+ let truncate str =
+ try
+ let i = String.index str '\000' in
+ String.sub str 0 i
+ with
+ Not_found -> str
+ in
+ (* Expect the first (sysname) field to always be "Linux", which is
+ * also a good way to tell if we're synchronized to the right bit of
+ * memory.
+ *)
+ bitmatch bs with
+ | { "Linux\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" : 65*8 : string;
+ nodename : 65*8 : string;
+ release : 65*8 : string;
+ version : 65*8 : string;
+ machine : 65*8 : string;
+ domainname : 65*8 : string } ->
+ printf "%s: Linux %s %s %s %s %s\n"
+ name
+ (truncate nodename) (truncate release)
+ (truncate version) (truncate machine) (truncate domainname)
+ | { _ } ->
+ eprintf (f_"%s: unexpected system_utsname in kernel image\n")
+ name
+ in
+
+ List.iter (
+ fun (_, name, arch, mem, lookup_ksym) ->
+ (* In Linux 2.6.25, the symbol is init_uts_ns.
+ * http://lxr.linux.no/linux/init/version.c
+ *)
+ try
+ let addr = lookup_ksym "init_uts_ns" in