X-Git-Url: http://git.annexia.org/?p=virt-mem.git;a=blobdiff_plain;f=lib%2Fvirt_mem_mmap.ml;h=98dc84a933a9ab22adcb793e652c2e3d04885837;hp=87741e489f8c47173d128c0db25301d5c9ea74f5;hb=e4a9a58795f30b85fd965e6584ca73d7b0a812f8;hpb=8e753ba58844f0188306fd0a468fab899bd4308d diff --git a/lib/virt_mem_mmap.ml b/lib/virt_mem_mmap.ml index 87741e4..98dc84a 100644 --- a/lib/virt_mem_mmap.ml +++ b/lib/virt_mem_mmap.ml @@ -78,6 +78,25 @@ let of_file fd addr = let t = create () in add_file t fd addr +let add_string ({ mappings = mappings } as t) str addr = + if addr &^ 7L <> 0L then + invalid_arg "add_file: mapping address must be aligned to 8 bytes"; + let size = String.length str in + (* Use Bigarray.Array1. XXX We should just use the string. *) + let arr = Array1.create char c_layout size in + for i = 0 to size-1 do + Array1.set arr i (String.unsafe_get str i) + done; + (* Create the mapping entry and keep the mappings sorted by start addr. *) + let mappings = + { start = addr; size = Int64.of_int size; arr = arr } :: mappings in + let mappings = sort_mappings mappings in + { t with mappings = mappings } + +let of_string str addr = + let t = create () in + add_string t str addr + (* Find in mappings and return first predicate match. *) let _find_map { mappings = mappings } pred = let rec loop = function