Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions CodeHawk/CHB/bchlib/bCHFloc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,7 @@ object (self)
__FILE__ __LINE__
["addrvalue: " ^ (x2s addrvalue);
"btype: " ^ (btype_to_string btype);
"size: " ^ (if Option.is_some size then (string_of_int (Option.get size)) else "?")] in
"size: " ^ (opti2s size)] in

match self#normalize_addrvalue addrvalue with
| XOp ((Xf "addressofvar"), [XVar v]) when self#env#is_global_variable v ->
Expand Down Expand Up @@ -1341,7 +1341,8 @@ object (self)
(TR.tmap
~msg:(__FILE__ ^ ":" ^ (string_of_int __LINE__))
(fun offset -> self#f#env#mk_gloc_variable gloc offset)
(gloc#address_memory_offset ~tgtsize:size ~tgtbtype:btype self#l addrvalue))
(gloc#address_memory_offset
~tgtsize:size ~tgtbtype:btype self#l addrvalue))
| _ ->
let (memref_r, memoff_r) = self#decompose_memaddr addrvalue in
TR.tmap2
Expand Down Expand Up @@ -2362,15 +2363,7 @@ object (self)
| XConst (IntConst n) when n#gt CHNumerical.numerical_zero ->
let dw = numerical_mod_to_doubleword n in
if memmap#has_location dw then
TR.tfold
~ok:(fun gv -> XOp ((Xf "addressofvar"), [XVar gv]))
~error:(fun e ->
begin
log_result
~tag:"assign global variable address" __FILE__ __LINE__ e;
rhs
end)
(self#f#env#mk_global_variable self#l n)
TR.tvalue (self#f#env#mk_global_variable_address dw) ~default:rhs
else
rhs
| _ -> rhs in
Expand Down
20 changes: 16 additions & 4 deletions CodeHawk/CHB/bchlib/bCHFunctionInfo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,22 @@ object (self)
end
end

method mk_global_variable_address (dw: doubleword_int): xpr_t traceresult =
match memmap#containing_location dw with
| Some gloc when dw#equal gloc#address ->
let gvar =
self#mk_variable (self#varmgr#make_global_variable dw#to_numerical) in
let ivar = self#mk_variable (varmgr#make_initial_memory_value gvar) in
begin
self#set_variable_name gvar gloc#name;
self#set_variable_name ivar (gloc#name ^ "_in");
Ok (XOp ((Xf "addressofvar"), [XVar gvar]))
end
| _ ->
Error [__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ": "
^ dw#to_hex_string
^ " is not the address of a known global variable"]

method mk_global_variable
?(size=4)
?(btype=t_unknown)
Expand All @@ -848,10 +864,6 @@ object (self)
let dw = numerical_mod_to_doubleword base in
match memmap#containing_location dw with
| Some gloc ->
let gvar =
self#mk_variable
(self#varmgr#make_global_variable gloc#address#to_numerical) in
let _ivar = self#mk_variable (varmgr#make_initial_memory_value gvar) in
tmap
~msg:(__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ": memref:global")
(fun offset ->
Expand Down
7 changes: 5 additions & 2 deletions CodeHawk/CHB/bchlib/bCHGlobalMemoryMap.ml
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,8 @@ object (self)
~msg:(p2s loc#toPretty)
~tag:"mmap:address-offset-memory-offset"
__FILE__ __LINE__
["xoffset: " ^ (x2s xoffset)
["gloc: " ^ self#address#to_hex_string
^ "; xoffset: " ^ (x2s xoffset)
^ "; tgtsize: " ^ (opti2s tgtsize)
^ "; tgtbtype: " ^ (ty2s tgtbtype)] in
match xoffset with
Expand Down Expand Up @@ -517,7 +518,9 @@ object (self)
else
Error [__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ":"
^ (btype_to_string self#btype)
^ " is not known to be a struct or array"]
^ " is not known to be a struct or array";
"gloc_address: " ^ self#address#to_hex_string;
"xoffset: " ^ (x2s xoffset)]

method address_memory_offset
?(tgtsize=None)
Expand Down
2 changes: 2 additions & 0 deletions CodeHawk/CHB/bchlib/bCHLibTypes.mli
Original file line number Diff line number Diff line change
Expand Up @@ -4778,6 +4778,8 @@ class type function_environment_int =

(** {2 Memory variables} *)

method mk_global_variable_address: doubleword_int -> xpr_t traceresult

(** [mk_global_variable offset] attempts to find a containing global
location for [offset]. If successful a memory offset will be computed
for that offset relative to the address of the containing location
Expand Down