2 (* Memory info command for virtual domains.
3 (C) Copyright 2008 Richard W.M. Jones, Red Hat Inc.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 module D = Libvirt.Domain
30 module Ksymmap = Map.Make (String)
32 type ksymmap = addr Ksymmap.t
35 dom : Libvirt.ro D.t option;
38 mem : ([`Wordsize], [`Endian], [`HasMapping]) Virt_mem_mmap.t;
46 kernel_release : string;
47 kernel_version : string;
53 ksyms : ksymmap option;
54 utsname : utsname option;
55 tasks : Virt_mem_mmap.addr option;
56 net_devices : Virt_mem_mmap.addr option;
59 exception ParseError of string * string * string
62 field_available : bool;
66 (* This is the maximum we can download in one go over the libvirt
69 * XXX Should have a 'D.max_peek' function.
71 let max_memory_peek = 65536
73 type load_memory_error =
77 exception LoadMemoryError of load_memory_error * string
79 let _load_memory mem dom start size =
80 let str = String.create size in
82 let remaining = size - i in
83 if remaining > 0 then (
84 let size = min remaining max_memory_peek in
85 D.memory_peek dom [D.Virtual] (start +^ Int64.of_int i) size str i;
91 Virt_mem_mmap.add_string mem str start
93 let load_static_memory ~dom ~domname ~arch ~wordsize ~endian
94 ~kernel_min ~kernel_max start size =
95 if start < kernel_min then
96 raise (LoadMemoryError (AddressOutOfRange,
97 "load_memory: start < kernel_min"))
98 else if start +^ Int64.of_int size > kernel_max then
99 raise (LoadMemoryError (AddressOutOfRange,
100 "load_memory: start+size > kernel_max"))
102 let mem = Virt_mem_mmap.create () in
103 let mem = Virt_mem_mmap.set_wordsize mem wordsize in
104 let mem = Virt_mem_mmap.set_endian mem endian in
106 let mem = _load_memory mem dom start size in
108 { dom = Some dom; domname = domname; mem = mem; arch = arch;
109 kernel_min = kernel_min; kernel_max = kernel_max }
112 let load_memory ({ dom = dom; mem = mem; kernel_min = kernel_min;
113 kernel_max = kernel_max } as image) start size =
114 if start < kernel_min then
115 raise (LoadMemoryError (AddressOutOfRange,
116 "load_memory: start < kernel_min"))
117 else if start +^ Int64.of_int size > kernel_max then
118 raise (LoadMemoryError (AddressOutOfRange,
119 "load_memory: start+size > kernel_max"))
120 else if Virt_mem_mmap.is_mapped_range mem start size then image
124 raise (LoadMemoryError (DomIsNull, "load_memory: dom = None"))
126 let mem = _load_memory mem dom start size in
127 { image with mem = mem }