Skip to content

Commit b1cb268

Browse files
committed
CHB: add support for global variable as memory base
1 parent a1ebec4 commit b1cb268

File tree

1 file changed

+61
-45
lines changed

1 file changed

+61
-45
lines changed

CodeHawk/CHB/bchlib/bCHFloc.ml

Lines changed: 61 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,61 +1284,77 @@ object (self)
12841284
else if self#env#is_memory_variable v then
12851285
let memref_r = self#env#get_memory_reference v in
12861286
let memoff_r = self#env#get_memvar_offset v in
1287-
let basevar_r =
1288-
TR.tbind
1289-
~msg:(__FILE__ ^ ":" ^ (string_of_int __LINE__))
1290-
(fun memref ->
1291-
match memref#get_base with
1292-
| BaseVar v -> Ok v
1293-
| b ->
1294-
Error [__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ": "
1295-
^ "memory-base: " ^ (p2s (memory_base_to_pretty b))])
1296-
memref_r in
1297-
let basevar_type_r =
1298-
TR.tbind
1299-
~msg:(__FILE__ ^ ":" ^ (string_of_int __LINE__))
1300-
self#get_variable_type
1301-
basevar_r in
13021287
TR.tbind
13031288
~msg:(__FILE__ ^ ":" ^ (string_of_int __LINE__))
1304-
(fun basevartype ->
1305-
TR.tbind
1306-
(fun memoff ->
1307-
match memoff with
1308-
| NoOffset when is_pointer basevartype ->
1309-
Ok (ptr_deref basevartype)
1310-
| ConstantOffset (n, NoOffset) when is_pointer basevartype ->
1311-
let symmemoff_r =
1312-
address_memory_offset
1313-
(ptr_deref basevartype) (num_constant_expr n) in
1289+
(fun memref ->
1290+
match memref#get_base with
1291+
| BGlobal ->
1292+
(match memoff_r with
1293+
| Ok (ConstantOffset (num, NoOffset)) ->
1294+
let gvaddr = numerical_mod_to_doubleword num in
1295+
if memmap#has_location gvaddr then
1296+
let gloc = memmap#get_location gvaddr in
1297+
Ok (gloc#btype)
1298+
else
1299+
Error [__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ": "
1300+
^ "no global location found for address "
1301+
^ gvaddr#to_hex_string]
1302+
| _ ->
1303+
Error [__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ": "
1304+
^ "not a constant offset"])
1305+
| _ ->
1306+
let basevar_r =
1307+
match memref#get_base with
1308+
| BaseVar v -> Ok v
1309+
| b ->
1310+
Error [__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ": "
1311+
^ "memory-base: " ^ (p2s (memory_base_to_pretty b))] in
1312+
let basevar_type_r =
1313+
TR.tbind
1314+
~msg:(__FILE__ ^ ":" ^ (string_of_int __LINE__))
1315+
self#get_variable_type
1316+
basevar_r in
1317+
TR.tbind
1318+
~msg:(__FILE__ ^ ":" ^ (string_of_int __LINE__))
1319+
(fun basevartype ->
13141320
TR.tbind
1315-
~msg:(__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ": "
1316-
^ "basevar type: " ^ (btype_to_string basevartype)
1317-
^ "; offset: " ^ n#toString)
1318-
(fun off ->
1319-
match off with
1321+
(fun memoff ->
1322+
match memoff with
1323+
| NoOffset when is_pointer basevartype ->
1324+
Ok (ptr_deref basevartype)
1325+
| ConstantOffset (n, NoOffset) when is_pointer basevartype ->
1326+
let symmemoff_r =
1327+
address_memory_offset
1328+
(ptr_deref basevartype) (num_constant_expr n) in
1329+
TR.tbind
1330+
~msg:(__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ": "
1331+
^ "basevar type: " ^ (btype_to_string basevartype)
1332+
^ "; offset: " ^ n#toString)
1333+
(fun off ->
1334+
match off with
1335+
| FieldOffset ((fname, ckey), NoOffset) ->
1336+
let cinfo = get_compinfo_by_key ckey in
1337+
let finfo = get_compinfo_field cinfo fname in
1338+
Ok finfo.bftype
1339+
| _ ->
1340+
Error [__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ": "
1341+
^ "symbolic offset: "
1342+
^ (memory_offset_to_string off)
1343+
^ " with basevar type: "
1344+
^ (btype_to_string basevartype)
1345+
^ " not yet handled"])
1346+
symmemoff_r
13201347
| FieldOffset ((fname, ckey), NoOffset) ->
13211348
let cinfo = get_compinfo_by_key ckey in
13221349
let finfo = get_compinfo_field cinfo fname in
13231350
Ok finfo.bftype
13241351
| _ ->
13251352
Error [__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ": "
1326-
^ "symbolic offset: "
1327-
^ (memory_offset_to_string off)
1328-
^ " with basevar type: "
1329-
^ (btype_to_string basevartype)
1353+
^ "memoff: " ^ (memory_offset_to_string memoff)
13301354
^ " not yet handled"])
1331-
symmemoff_r
1332-
| FieldOffset ((fname, ckey), NoOffset) ->
1333-
let cinfo = get_compinfo_by_key ckey in
1334-
let finfo = get_compinfo_field cinfo fname in
1335-
Ok finfo.bftype
1336-
| _ ->
1337-
Error [__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ": "
1338-
^ "memoff: " ^ (memory_offset_to_string memoff)
1339-
^ " not yet handled"])
1340-
memoff_r)
1341-
basevar_type_r
1355+
memoff_r)
1356+
basevar_type_r)
1357+
memref_r
13421358
else if self#f#env#is_return_value v then
13431359
let callsite_r = self#f#env#get_call_site v in
13441360
TR.tbind

0 commit comments

Comments
 (0)