(* Registration function used by the tools. *)
let register ?(external_cmd = true) ?(extra_args = [])
- ?argcheck ?beforeksyms ?run
+ ?argcheck ?beforeksyms ?beforeutsname ?run
name summary description =
tools :=
(name, (name, summary, description, external_cmd, extra_args,
- argcheck, beforeksyms, run))
+ argcheck, beforeksyms, beforeutsname, run))
:: !tools
(* Main program, called from mem/virt_mem_main.ml when all the
match tool with
| None -> (* Generic usage message. *)
let tools = List.map (
- fun (name, (_, summary, _, external_cmd, _, _, _, _)) ->
+ fun (name, (_, summary, _, external_cmd, _, _, _, _, _)) ->
if external_cmd then "virt-"^name, summary
else "virt-mem "^name, summary
) tools in
Options:") tools
(* Tool-specific usage message. *)
- | Some (name, summary, description, external_cmd, _, _, _, _) ->
+ | Some (name, summary, description, external_cmd, _, _, _, _, _) ->
let cmd =
if external_cmd then "virt-" ^ name else "virt-mem " ^ name in
let argspec =
let extra_args = match tool with
| None -> []
- | Some (_, _, _, _, extra_args, _, _, _) -> extra_args in
+ | Some (_, _, _, _, extra_args, _, _, _, _) -> extra_args in
let argspec = [
"-A", Arg.String set_architecture,
"arch " ^ s_"Set kernel architecture, endianness and word size";
* or the user didn't give us a valid tool (eg. "virt-mem foobar").
* Detect that final case now and give an error.
*)
- let name, _, _, _, _, argcheck, beforeksyms, run =
+ let name, _, _, _, _, argcheck, beforeksyms, beforeutsname, run =
match tool with
| Some t -> t
| None ->
| Some beforeksyms -> beforeksyms debug images
);
- (* If there is no run function, then there is no point continuing
- * with the rest of the program (kernel symbol analysis) ...
+ (* If there are no more callback functions, then there is no point
+ * continuing with the rest of the program (kernel symbol analysis) ...
*)
- if run = None then exit 0;
+ if beforeutsname = None && run = None then exit 0;
(* Do the kernel symbol analysis. *)
let images =
List.map (
fun image ->
-
(* Look for ordinary kernel symbols: *)
let image = Virt_mem_ksyms.find_kernel_symbols debug image in
(* Look for kallsyms: *)
image
) images in
+ (* Before utsname analysis. *)
+ (match beforeutsname with
+ | None -> ()
+ | Some beforeutsname -> List.iter (beforeutsname debug) images
+ );
+
+ (* If there are no more callback functions, then there is no point
+ * continuing with the rest of the program (kernel version analysis) ...
+ *)
+ if run = None then exit 0;
+
+ (* Get the kernel version (utsname analysis). *)
+ let images = List.map (Virt_mem_utsname.find_utsname debug) images in
+
(* Run the tool's main function. *)
(match run with
| None -> ()
- | Some run ->
- run debug images
+ | Some run -> List.iter (run debug) images
)