"Fossies" - the Fresh Open Source Software Archive

Member "virt-dmesg-0.3.0/src/search.ml" (25 May 2011, 2332 Bytes) of package /linux/privat/old/virt-dmesg-0.3.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Objective Caml source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 (* virt-dmesg
    2  * (C) Copyright 2008-2011 Red Hat Inc.
    3  *
    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.
    8  *
    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.
   13  *
   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.
   17  *)
   18 
   19 module D = Libvirt.Domain
   20 
   21 open Printf
   22 
   23 open Utils
   24 
   25 let search_at ?(dump = false) dom base_addr =
   26   debug "search_at %Lx" base_addr;
   27 
   28   (* Load the kernel into memory. *)
   29   let max_peek = D.max_peek dom in
   30   let k = Kernel.create base_addr (
   31     fun addr ->
   32       let buffer = String.create max_peek in
   33       D.memory_peek dom [D.Virtual] addr max_peek buffer 0;
   34       buffer
   35   ) in
   36 
   37   (* Dump mode?  Bypass symbol table lookups and just dump the kernel
   38    * memory to stdout.
   39    *)
   40   if dump then (
   41     print_string k.Kernel.data;
   42     k, StringMap.empty
   43   ) else (
   44     (* Search for the ordinary symbol table. *)
   45     let ksyms = Ksyms.search_ksyms k in
   46 
   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
   50 
   51     (* Search for kallsyms (optional -- don't worry if it fails). *)
   52     let kallsyms = try Kallsyms.search_kallsyms k map with Not_found -> [] in
   53 
   54     (* Extend the map with kallsyms. *)
   55     let map = List.fold_left add map kallsyms in
   56 
   57     k, map
   58   )
   59 
   60 let search ?dump dom =
   61   (* XXX In future be smarter about what addresses to search. *)
   62   let addrs = [
   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 *)
   66   ] in
   67   let rec loop = function
   68     | [] -> raise Not_found
   69     | addr :: addrs ->
   70         try search_at ?dump dom addr
   71         with Not_found -> loop addrs
   72   in
   73   loop addrs