123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990(**************************************************************************)(* *)(* This file is part of Frama-C. *)(* *)(* Copyright (C) 2007-2025 *)(* 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). *)(* *)(**************************************************************************)openMt_memory.Typestypeid_type=IdThread|IdMutex|IdQueueletto_string=function|IdThread->"thread"|IdMutex->"mutex"|IdQueue->"queue"typeraw_id=id_type*intletpretty_raw_idfmt(idt,offset)=Format.fprintffmt"%s_%d"(to_stringidt)offset(* YYY cache this per project *)letarray_threads=Mt_cil.mthread_global_var"__fc_mthread_threads"letarray_mutexes=Mt_cil.mthread_global_var"__fc_mthread_mutexes"letarray_queues=Mt_cil.mthread_global_var"__fc_mthread_queues"letarray_of_idt=function|IdThread->array_threads()|IdMutex->array_mutexes()|IdQueue->array_queues()letpointer_of_id((idt,offset):raw_id):pointer=assert(offset>0);letarray=array_of_idtidtandoffset=(offset-1)*(Machine.sizeof_int())(* Let us not lose the first cell of the array *)inarray,offsetletread_id_statestateraw_id=letp=pointer_of_idraw_idinMt_memory.read_int_pointerpstateletread_id_state_enumeratecardstateraw_id:_Mt_lib.conversion=letvalue=read_id_statestateraw_idinletfailurefmt=Format.fprintffmt"Id %a contains garbled state %a"pretty_raw_idraw_idCvalue.V.prettyvalueintrymatchLocations.Location_Bytes.fold_i(funbil->(b,i)::l)value[]with|[Base.Null,i]->begintryignore(Ival.cardinal_less_thanicard);`Success(Ival.fold_int(funil->Abstract_interp.Int.to_int_exni::l)i[])withAbstract_interp.Not_less_than->`Failurefailureend|_->`FailurefailurewithNot_found->`Failurefailureletwrite_id_statestateraw_idv=letp=pointer_of_idraw_idinMt_memory.write_int_pointerpvstateletreplace_id_valuestateraw_id~before~after=letp=pointer_of_idraw_idinMt_memory.replace_value_at_int_pointerp~before~afterstateletof_threadth=IdThread,Thread.idthletof_mutexm=IdMutex,Mutex.idmletof_queueq=IdQueue,Mqueue.idq