Skip to content

Commit 4403904

Browse files
committed
CHB: move functionality to global memory map
1 parent 93875f3 commit 4403904

26 files changed

+921
-161
lines changed

CodeHawk/CHB/bchanalyze/bCHFileIO.ml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,19 @@ let save_global_state () =
200200
file_output#saveFile filename doc#toPretty
201201
end
202202

203+
204+
let save_global_memory_map () =
205+
let filename = get_global_memory_map_filename () in
206+
let doc = xmlDocument () in
207+
let root = get_bch_root "global-locations" in
208+
let gNode = xmlElement "global-locations" in
209+
begin
210+
BCHGlobalMemoryMap.global_memory_map#write_xml gNode;
211+
doc#setNode root;
212+
root#appendChildren [gNode];
213+
file_output#saveFile filename doc#toPretty
214+
end
215+
203216
let save_system_info () =
204217
let filename = get_system_info_filename () in
205218
let doc = xmlDocument () in

CodeHawk/CHB/bchanalyze/bCHFileIO.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ val save_functions_list: unit -> unit
4343
val save_arm_functions_list: unit -> unit
4444

4545
val save_global_state: unit -> unit
46+
val save_global_memory_map: unit -> unit
4647
val save_system_info: unit -> unit
4748
val save_resultmetrics: xml_element_int -> unit
4849
val save_disassembly_status: unit -> unit

CodeHawk/CHB/bchcmdline/bCHXBinaryAnalyzer.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,8 @@ let main () =
602602
pr_timing [STR "system_info saved"];
603603
save_arm_dictionary ();
604604
pr_timing [STR "dictionary saved"];
605+
save_global_memory_map ();
606+
pr_timing [STR "global-locations saved"];
605607
save_interface_dictionary ();
606608
pr_timing [STR "interface dictionary saved"];
607609
save_bcdictionary ();
@@ -898,6 +900,8 @@ let main () =
898900
(* save_arm_assembly_instructions (); *)
899901
save_arm_dictionary ();
900902
pr_timing [STR "arm dictionary saved"];
903+
save_global_memory_map ();
904+
pr_timing [STR "global-locations saved"];
901905
save_bc_files ();
902906
pr_timing [STR "bc files saved"];
903907
save_interface_dictionary ();

CodeHawk/CHB/bchcmdline/bCHXInspectSummaries.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ open CHLogger
3838

3939
(* bchlib *)
4040
open BCHBasicTypes
41-
open BCHConstantDefinitions
4241
open BCHFunctionSummaryLibrary
4342
open BCHLibTypes
4443
open BCHSystemInfo
@@ -126,7 +125,7 @@ let print_statistics () =
126125
STR "Type definitions: "; NL; type_definitions#toPretty; NL;
127126
STR "IO action categories: "; INT (List.length pActions); NL;
128127
STR "Parameter roles : "; INT nParamRoles; NL;
129-
constant_statistics_to_pretty (); NL]
128+
BCHConstantDefinitions.constant_statistics_to_pretty (); NL]
130129
end
131130

132131
let main () =

CodeHawk/CHB/bchlib/bCHDoubleword.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,11 @@ let numerical_to_doubleword (num:numerical_t): doubleword_result =
488488
"numerical_to_doubleword"
489489

490490

491+
let numerical_mod_to_doubleword (num: numerical_t): doubleword_int =
492+
let num = num#modulo numerical_e32 in
493+
TR.tget_ok (numerical_to_doubleword num)
494+
495+
491496
let dw_index_to_int (index:dw_index_t) = index
492497

493498

CodeHawk/CHB/bchlib/bCHDoubleword.mli

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ val big_int_to_doubleword: big_int -> doubleword_result
109109
val string_to_doubleword: string -> doubleword_result
110110

111111

112-
(**[numerical_to_doubleword num] converts num to a doubleword.
112+
(**[numerical_to_doubleword num] converts [num] to a doubleword.
113113
114114
[num] must be less than [2^32] and greater than or equal [-2^31].
115115
Negative numbers are represented by their two's complement
@@ -118,6 +118,11 @@ val string_to_doubleword: string -> doubleword_result
118118
val numerical_to_doubleword: numerical_t -> doubleword_result
119119

120120

121+
(** [numerical_mod_to_doubleword num] converts [num] to a a doubleword.
122+
[num] will be forced within the range [0..2^32-1] using wraparound.*)
123+
val numerical_mod_to_doubleword: numerical_t -> doubleword_int
124+
125+
121126
(** [numerical_to_hex_string num] converts num to a hexadecimal string
122127
representation via a doubleword representation.
123128

CodeHawk/CHB/bchlib/bCHFloc.ml

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -599,22 +599,10 @@ object (self)
599599
let fintf = ctinfo#get_function_interface in
600600
let stackpars = get_stack_parameters fintf in
601601
let regpars = get_register_parameters fintf in
602-
let _ =
603-
chlog#add
604-
"floc:get_call_arguments"
605-
(LBLOCK [
606-
self#l#toPretty;
607-
STR " ";
608-
STR ctinfo#get_name;
609-
STR ": ";
610-
INT (List.length stackpars);
611-
STR " stackparameters; ";
612-
INT (List.length regpars);
613-
STR " register parameters"]) in
614-
615602
List.concat [(get_regargs regpars); (get_stackargs stackpars)]
616603

617604
method get_call_args =
605+
(* used in x86 only *)
618606
let ctinfo = self#get_call_target in
619607
if ctinfo#is_wrapped_app_call then
620608
self#get_wrapped_call_args

CodeHawk/CHB/bchlib/bCHFunctionInfo.ml

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ module DoublewordCollections = CHCollections.Make
109109

110110
let id = BCHInterfaceDictionary.interface_dictionary
111111

112+
let memmap = BCHGlobalMemoryMap.global_memory_map
113+
112114

113115
type po_anchor_t = (* proof obligation anchor *)
114116
| DirectAccess
@@ -850,7 +852,23 @@ object (self)
850852
?(size=4)
851853
?(offset=NoOffset)
852854
(base: numerical_t): variable_t traceresult =
853-
let base = base#modulo (mkNumerical BCHDoubleword.e32) in
855+
let dwbase =
856+
fail_tfold
857+
(trerror_record
858+
(LBLOCK [
859+
STR "Converting ";
860+
base#toPretty;
861+
STR " in finfo.mk_global_variable in function ";
862+
faddr#toPretty]))
863+
(fun b -> b)
864+
(numerical_to_doubleword (base#modulo (mkNumerical BCHDoubleword.e32))) in
865+
let default (gloc: global_location_int) =
866+
let var =
867+
self#mk_variable (varmgr#make_global_variable ~size ~offset base) in
868+
let _ = self#set_variable_name var gloc#name in
869+
Ok var in
870+
871+
(*
854872
match numerical_to_doubleword base with
855873
| Error e -> Error ("finfo.mk_global_variable" :: e)
856874
| Ok addr ->
@@ -880,6 +898,29 @@ object (self)
880898
| _ -> ());
881899
Ok var
882900
end in
901+
*)
902+
match memmap#containing_location dwbase with
903+
| Some gloc ->
904+
tfold
905+
~ok:(fun memoffset ->
906+
let var =
907+
self#mk_variable
908+
(varmgr#make_global_variable
909+
~offset:memoffset gloc#address#to_numerical) in
910+
let _ = self#set_variable_name var gloc#name in
911+
Ok var)
912+
~error:(fun sl ->
913+
begin
914+
chlog#add
915+
"fenv#mk_global_variable: Error"
916+
(LBLOCK [faddr#toPretty; STR ": "; STR (String.concat "; " sl)]);
917+
default gloc
918+
end)
919+
(gloc#address_memory_offset dwbase)
920+
| _ ->
921+
Ok (self#mk_variable (varmgr#make_global_variable ~size ~offset base))
922+
(*
923+
|
883924
884925
if is_in_global_structvar addr then
885926
(match get_structvar_base_offset addr with
@@ -951,6 +992,7 @@ object (self)
951992
default ())
952993
else
953994
default ()
995+
*)
954996

955997
method mk_global_memory_address
956998
?(optname = None) ?(opttype=None) (n: numerical_t) =
@@ -2010,7 +2052,13 @@ object (self)
20102052
method set_bc_summary (fs: function_summary_int) =
20112053
begin
20122054
appsummary <- fs;
2013-
env#set_argument_names fs#get_function_interface
2055+
env#set_argument_names fs#get_function_interface;
2056+
chlog#add
2057+
"set-bc-summary"
2058+
(LBLOCK [
2059+
function_interface_to_pretty fs#get_function_interface;
2060+
STR " with function signature ";
2061+
STR (btype_to_string fs#get_function_interface.fintf_type_signature.fts_returntype)])
20142062
end
20152063

20162064
method read_xml_user_summary (node:xml_element_int) =

CodeHawk/CHB/bchlib/bCHFunctionSummaryLibrary.ml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ open CHXmlDocument
4040
(* bchlib *)
4141
open BCHBasicTypes
4242
open BCHBCFiles
43-
open BCHConstantDefinitions
4443
open BCHBCTypeXml
4544
open BCHDemangler
4645
open BCHFunctionSummary
@@ -342,10 +341,10 @@ object (self)
342341
let root = doc#getRoot in
343342
if root#hasOneTaggedChild "symbolic-constants" then
344343
let node = root#getTaggedChild "symbolic-constants" in
345-
read_xml_symbolic_constants node
344+
BCHConstantDefinitions.read_xml_symbolic_constants node
346345
else if root#hasOneTaggedChild "symbolic-flags" then
347346
let node = root#getTaggedChild "symbolic-flags" in
348-
read_xml_symbolic_flags node
347+
BCHConstantDefinitions.read_xml_symbolic_flags node
349348
else
350349
raise
351350
(BCH_failure

0 commit comments

Comments
 (0)