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