1 (* Memory info command for virtual domains.
2 (C) Copyright 2008 Richard W.M. Jones, Red Hat Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 (* This code will work provided list_head always contains just a
21 * 'next' and 'prev' pointer. If it changes, then we'll have to
22 * import the struct list_head from the kernel version, just like
23 * every other structure. (XXX)
32 image (* Kernel image. *)
33 * int64 (* Pointer to start of head struct. *)
36 let create_base image head offset =
37 let offset = Int64.of_int offset in
40 let create image head offset =
41 let offset = Int64.of_int offset in
42 let head = head -^ offset in
45 let get_next_ptr image addr offset =
46 let addr = addr +^ offset in
47 let addr = Virt_mem_mmap.follow_pointer image.mem addr in
48 let addr = addr -^ offset in
51 let load (image, head, offset) f =
52 let rec loop image addr =
53 if addr <> head then (
54 let image = f image addr in
55 let addr = get_next_ptr image addr offset in
60 let image = loop image (get_next_ptr image head offset) in
61 image, (image, head, offset)
65 let mapped = Virt_mem_mmap.is_mapped_range image.mem addr size in
67 if not mapped then Virt_mem_types.load_memory image addr size
73 let fold (image, head, offset) b f =
75 if addr <> head then (
77 let addr = get_next_ptr image addr offset in
82 loop b (get_next_ptr image head offset)
84 (* Iter and map can be implemented in terms of fold. *)
86 fold t () (fun () addr -> let () = f addr in ())
89 List.rev (fold t [] (fun xs addr -> let x = f addr in x :: xs))