open Virt_mem_utils
open Virt_mem_types
+open Kernel_task_struct
let run debug (image, ksymmap, utsname) =
try
raise Exit
| Some { kernel_release = v } -> v in
- if not (Kernel_task_struct.known kernel_version) then (
+ if not (task_struct_known kernel_version) then (
eprintf (f_"%s: %s: unknown kernel version
Try a newer version of virt-mem, or if the guest is not from a
supported Linux distribution, see this page about adding support:
raise Exit
);
- let task_struct_size = Kernel_task_struct.size kernel_version in
+ let task_struct_size = task_struct_size kernel_version in
let init_task, init_task_addr =
let init_task_addr =
with Not_found ->
eprintf (f_"%s: could not find init_task in kernel image\n") domname;
raise Exit in
- let addr =
- (Virt_mem_mmap.unsafe_typed_addr_of_addr init_task_addr :
- [ `task_struct ] Virt_mem_mmap.typed_addr) in
- let init_task = Kernel_task_struct.get kernel_version image.mem addr in
+ let init_task =
+ get_task_struct kernel_version image.mem init_task_addr in
init_task, init_task_addr in
(* Starting at init_task, navigate through the linked list of
*)
let tasks, image =
let rec loop image acc task =
- let next = task.Kernel_task_struct.tasks'next in
- let next_addr = Virt_mem_mmap.unsafe_addr_of_typed_addr next in
- if next_addr <> init_task_addr then (
+ let next = task.task_struct_tasks'next in
+ if next <> init_task_addr then (
let mapped =
- Virt_mem_mmap.is_mapped_range image.mem
- next_addr task_struct_size in
+ Virt_mem_mmap.is_mapped_range image.mem next task_struct_size in
let image =
- if not mapped then load_memory image next_addr task_struct_size
+ if not mapped then load_memory image next task_struct_size
else image in
- let task = Kernel_task_struct.get kernel_version image.mem next in
+ let task = get_task_struct kernel_version image.mem next in
+ let task = {
+ task with
+ task_struct_comm = truncate_c_string task.task_struct_comm
+ } in
let acc = task :: acc in
loop image acc task
) else
in
loop image [] init_task in
+ (* Sort tasks by PID. *)
+ let cmp { task_struct_pid = p1 } { task_struct_pid = p2 } = compare p1 p2 in
+ let tasks = List.sort cmp tasks in
+
+ printf " PID STAT COMMAND\n";
+
List.iter (
fun task ->
- printf "%S\n" task.Kernel_task_struct.comm
+ printf "%5Ld %s\n" task.task_struct_pid task.task_struct_comm
) tasks
- with
- | Exit -> ()
+ with Exit -> ()
let summary = s_"list processes in virtual machine"
let description = s_"\