123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174(**************************************************************************)(* This file is part of BINSEC. *)(* *)(* Copyright (C) 2016-2026 *)(* CEA (Commissariat à l'énergie atomique et aux énergies *)(* alternatives) *)(* *)(* you can redistribute it and/or modify it under the terms of the GNU *)(* Lesser General Public License as published by the Free Software *)(* Foundation, version 2.1. *)(* *)(* It is distributed in the hope that it will be useful, *)(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *)(* GNU Lesser General Public License for more details. *)(* *)(* See the GNU Lesser General Public License version 2.1 *)(* for more details (enclosed in the file licenses/LGPLv2.1). *)(* *)(**************************************************************************)typeinstruction_kinds=Dba.Instr.tlisttypewidening_delay=intmoduleBoundThreshold=structtypet={los:intarray;his:intarray}letdefault={los=[||];his=[||]}letmk_from_list(los:intlist)(his:intlist):t={los=Array.of_listlos;his=Array.of_listhis}letis_unspecifiedbthreshold=Array.lengthbthreshold.los=0&&Array.lengthbthreshold.his=0endmoduleWideningThreshold=structtypet={signed:BoundThreshold.t;unsigned:BoundThreshold.t}letmksignedunsigned={signed;unsigned}letdefault={signed=BoundThreshold.default;unsigned=BoundThreshold.default}letis_unspecified(wthreshold:t)=BoundThreshold.is_unspecifiedwthreshold.signed&&BoundThreshold.is_unspecifiedwthreshold.unsigned(* Translation function to legacy structure *)letflatten_to_arrays_tuplewthreshold=letopenBoundThresholdin(wthreshold.signed.his,wthreshold.signed.los,wthreshold.unsigned.his,wthreshold.unsigned.los)endletdefault_global_widening_thresholds=WideningThreshold.defaultanddefault_global_widening_delay=0typet={entry_points:Virtual_address.Set.t;jumps:Dba.addressesDba_types.Caddress.Map.t;allowed_jumpzones:(Dba.address*Dba.address)list;stops:Dba_types.Caddress.Set.t;prepend_stubs:instruction_kindsDba_types.Caddress.Map.t;substitute_stubs:Dba_types.instruction_sequenceDba_types.Caddress.Map.t;linear_addresses:(Virtual_address.t*Virtual_address.t)list;global_widening:WideningThreshold.t*widening_delay;local_widening_thresholds:WideningThreshold.tDba_types.Caddress.Map.t;local_widening_delays:widening_delayDba_types.Caddress.Map.t;}letdefault={entry_points=Virtual_address.Set.empty;jumps=Dba_types.Caddress.Map.empty;allowed_jumpzones=[];stops=Dba_types.Caddress.Set.empty;substitute_stubs=Dba_types.Caddress.Map.empty;prepend_stubs=Dba_types.Caddress.Map.empty;linear_addresses=[];global_widening=(default_global_widening_thresholds,default_global_widening_delay);local_widening_thresholds=Dba_types.Caddress.Map.empty;local_widening_delays=Dba_types.Caddress.Map.empty;}letempty=defaultlethas_entry_pointsp=not(Virtual_address.Set.is_emptyp.entry_points)lethas_stopsp=not(Dba_types.Caddress.Set.is_emptyp.stops)lethas_jumpsp=not(Dba_types.Caddress.Map.is_emptyp.jumps)lethas_allowed_jumpzonesp=p.allowed_jumpzones<>[]lethas_prepend_stubsp=not(Dba_types.Caddress.Map.is_emptyp.prepend_stubs)lethas_substitute_stubsp=not(Dba_types.Caddress.Map.is_emptyp.substitute_stubs)lethas_linear_addressesp=p.linear_addresses<>[](* FIXME: in the next 2 functions
* If those values are set to default values in the parameter file, the user
* will be allowed to make another declaration in the same file *)lethas_global_widening_delayp=sndp.global_widening<>default_global_widening_delaylethas_global_widening_thresholdsp=not(WideningThreshold.is_unspecified(fstp.global_widening))let_has_local_widening_thresholdsp=not(Dba_types.Caddress.Map.is_emptyp.local_widening_thresholds)let_has_local_widening_delaysp=not(Dba_types.Caddress.Map.is_emptyp.local_widening_delays)letset_if_noterr_perr_msgdo_actionparameters=iferr_pparametersthenfailwitherr_msgelsedo_actionparametersletset_entry_pointsaddrsparameters=Kernel_options.Logger.debug"@[Setting %d entry points...@]"(Virtual_address.Set.cardinaladdrs);set_if_nothas_entry_points"Entry points already set"(funp->{pwithentry_points=addrs})parametersletset_jumpsaddr_mapparameters=set_if_nothas_jumps"Jumps already set"(funp->{pwithjumps=addr_map})parametersletset_stopsaddressesparameters=set_if_nothas_stops"Stops already set"(funp->{pwithstops=addresses})parametersletset_prepend_stubsaddr_mapparameters=set_if_nothas_prepend_stubs"Prepend stubs already set"(funp->{pwithprepend_stubs=addr_map})parametersletset_substitute_stubsaddr_mapparameters=set_if_nothas_substitute_stubs"Susbstitute stubs already set"(funp->{pwithsubstitute_stubs=addr_map})parametersletset_allowed_jumpzonesaddrsparameters=set_if_nothas_allowed_jumpzones"Allowed jumps areas already set"(funp->{pwithallowed_jumpzones=addrs})parametersletset_linear_addressesaddr_intervalsparameters=letlinear_addresses=List.map(fun(start,_end)->letopenDba_types.Caddressin(to_virtual_addressstart,to_virtual_address_end))addr_intervalsinset_if_nothas_linear_addresses"Linear addresses already set"(funp->{pwithlinear_addresses})parametersletset_global_widening_delaywidening_delayparameters=set_if_nothas_global_widening_delay"Global widening delay already set"(funp->{pwithglobal_widening=(fstp.global_widening,widening_delay)})parametersletset_global_widening_thresholdswidening_thresholdsparameters=set_if_nothas_global_widening_thresholds"Global widening thresholds already set"(funp->{pwithglobal_widening=(widening_thresholds,sndp.global_widening)})parameters