Add support for finding/parsing kallsyms.
[virt-mem.git] / lib / virt_mem_mmap.ml
index 7401e17..f6edee8 100644 (file)
@@ -205,7 +205,7 @@ let get_byte { mappings = mappings } addr =
   let rec loop = function
     | [] -> invalid_arg "get_byte"
     | { start = start; size = size; arr = arr } :: _
-       when start <= addr && addr < size ->
+       when start <= addr && addr < start +^ size ->
        let offset = Int64.to_int (addr -^ start) in
        Char.code (Array1.get arr offset)
     | _ :: ms -> loop ms
@@ -303,6 +303,15 @@ let is_C_identifier t addr =
   with
     Invalid_argument _ -> false
 
+let is_mapped { mappings = mappings } addr =
+  let rec loop = function
+    | [] -> false
+    | { start = start; size = size; arr = arr } :: _
+       when start <= addr && addr < start +^ size -> true
+    | _ :: ms -> loop ms
+  in
+  loop mappings
+
 let follow_pointer t addr =
   let ws = get_wordsize t in
   let e = get_endian t in
@@ -320,3 +329,8 @@ let succ_long t addr =
 let pred_long t addr =
   let ws = get_wordsize t in
   addr -^ Int64.of_int (bytes_of_wordsize ws)
+
+let align t addr =
+  let ws = get_wordsize t in
+  let mask = Int64.of_int (bytes_of_wordsize ws - 1) in
+  (addr +^ mask) &^ (Int64.lognot mask)