From 75dd862f41569df1f9f512ea3d9414fe3ea423f1 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Thu, 1 Jan 1970 00:00:00 +0000 Subject: [PATCH] Finish static approach in favour of a simpler, more dynamic version. --- extract/codegen/code_generation.ml | 8 +++----- extract/codegen/compile_kerneldb.ml | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/extract/codegen/code_generation.ml b/extract/codegen/code_generation.ml index c5e735f..d76aa4a 100644 --- a/extract/codegen/code_generation.ml +++ b/extract/codegen/code_generation.ml @@ -587,7 +587,7 @@ let generate_followers xs = >> in strs @ [ str ] in - (* Finally a publicly exposed follower function. *) + (* Finally a publicly exposed follower function for each structure. *) let strs = let fs = List.map ( @@ -597,9 +597,7 @@ let generate_followers xs = let body = tuple_generate_extract follower_tuple struct_name <:patt< f >> <:expr< followers >> - <:expr< - f load followers AddrMap.empty addr - >> in + <:expr< f load followers AddrMap.empty addr >> in <:str_item< let $lid:fname$ kernel_version load addr = @@ -622,7 +620,7 @@ let generate_followers xs = (string -> Virt_mem_mmap.addr -> int -> Bitstring.bitstring) -> Virt_mem_mmap.addr -> (string * int) AddrMap.t - >> + >> ) xs in concat_str_items strs, concat_sig_items sigs diff --git a/extract/codegen/compile_kerneldb.ml b/extract/codegen/compile_kerneldb.ml index 4ad221f..b9d3306 100644 --- a/extract/codegen/compile_kerneldb.ml +++ b/extract/codegen/compile_kerneldb.ml @@ -92,6 +92,35 @@ let good_structs = [ }; ] +(*---------------------------------------------------------------------- + * These are the code fragments which run over kernel structures. + *----------------------------------------------------------------------*) + +let fragments = [ + <:str_item< + let get_net_devices net_device = + let rec loop dev acc = + let ipv4 = net_device.ip_ptr.ifa_list in + let ipv4_addresses = + let rec loop2 ipv4 acc = + let addr = ipv4.ifa_address :: acc in + let ipv4 = ipv4.ifa_next in + loop2 ipv4 + in + loop ipv4 [] in + let acc = ipv4_addresses :: acc in + let next = get_net_devices net_device.dev_list'next in + if next <> net_device then loop next + else acc + >>; + + <:str_item< + let get_net_devices_from_init_net net = + get_net_devices net.dev_base_head'next + >>; + +] + let debug = false open Camlp4.PreCast -- 1.8.3.1