2 * (C) Copyright 2008-2011 Red Hat Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 module D = Libvirt.Domain
25 let search_at ?(dump = false) dom base_addr =
26 debug "search_at %Lx" base_addr;
28 (* Load the kernel into memory. *)
29 let max_peek = D.max_peek dom in
30 let k = Kernel.create base_addr (
32 let buffer = String.create max_peek in
33 D.memory_peek dom [D.Virtual] addr max_peek buffer 0;
37 (* Dump mode? Bypass symbol table lookups and just dump the kernel
41 print_string k.Kernel.data;
44 (* Search for the ordinary symbol table. *)
45 let ksyms = Ksyms.search_ksyms k in
47 (* Construct a map containing all symbols. *)
48 let add map (symbol, value) = StringMap.add symbol value map in
49 let map = List.fold_left add StringMap.empty ksyms in
51 (* Search for kallsyms (optional -- don't worry if it fails). *)
52 let kallsyms = try Kallsyms.search_kallsyms k map with Not_found -> [] in
54 (* Extend the map with kallsyms. *)
55 let map = List.fold_left add map kallsyms in
60 let search ?dump dom =
61 (* XXX In future be smarter about what addresses to search. *)
63 0xc010_0000_L; (* 32 bit since the dawn of time *)
64 0xffffffff_81000000_L; (* Fedora 14, 64 bit *)
65 0xffffffff_80000000_L; (* RHEL 3, 4, 5, 64 bit *)
67 let rec loop = function
68 | [] -> raise Not_found
70 try search_at ?dump dom addr
71 with Not_found -> loop addrs