Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file callsites_main.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114openCore_kernelopenBap.StdincludeSelf()openOption.Monad_infixletcall_of_jmpjmp=matchJmp.kindjmpwith|Ret_|Int_|Goto_->None|Callcall->Somecallletcalleecallprog=matchCall.targetcallwith|Indirect_->None|Directtid->Term.findsub_tprogtidletrequirex=Option.some_ifx()letdef_of_argarg=letd=Def.create(Arg.lhsarg)(Arg.rhsarg)inSome(Term.with_attrsd(Term.attrsarg))letintent_matchesxy=matchArg.intentxwith|None->true|Somex->matchx,ywith|In,In|Out,Out->true|Both,_|_,Both->true|_->falselettransfer_attrattrt1t2=matchTerm.get_attrt1attrwith|None->t2|Somev->Term.set_attrt2attrvlettransfer_attrst1t2=lett2=Term.set_attrt2Term.synthetic()inTerm.set_attrt2Term.origin(Term.tidt1)|>transfer_attrDisasm.insnt1|>transfer_attraddresst1letis_out=function|Out->true|_->falseletadd_defintentblkdef=ifis_outintentthenTerm.prependdef_tblkdefelseTerm.appenddef_tblkdefletdefs_of_argscallintentargs=List.filter_mapargs~f:(funarg->require(intent_matchesargintent)>>=fun()->def_of_argarg>>|transfer_attrscall)lettargetintentsubblkcall=ifis_outintentthenCall.returncall>>=function|Directtid->Term.findblk_tsubtid|_->NoneelseSomeblk(* Note, that output arguments will be inserted in the reverse order, so
we sort all of them in a natural way to get the following order: In Both Out *)letenum_argst=letcomparexy=Option.comparecompare_intent(Arg.intentx)(Arg.intenty)inTerm.enumarg_tt|>Seq.to_list|>List.stable_sort~compareletinsert_defsprogsub=letblk_with_defintentblkjmpsub:blktermoption=call_of_jmpjmp>>=funcaller->calleecallerprog>>=funcallee->targetintentsubblkcaller>>|funblk->enum_argscallee|>defs_of_argsjmpintent|>List.fold~init:blk~f:(add_defintent)inletinsertintentblkjmpsub=Option.value_map(blk_with_defintentblkjmpsub)~default:sub~f:(Term.updateblk_tsub)inList.fold[In;Out]~init:sub~f:(funsubintent->Term.enumblk_tsub|>Seq.fold~init:sub~f:(funsubblk->Term.enumjmp_tblk|>Seq.fold~init:sub~f:(funsubjmp->insertintentblkjmpsub)))letfill_callsprogram=Term.mapsub_tprogram~f:(insert_defsprogram)letmainproj=letprog=Project.programprojinProject.with_programproj(fill_callsprog)let()=Config.manpage[`S"DESCRIPTION";`P"This pass will inject artificial definitions of a subroutine
arguments at call sites. Consider function $(b,malloc) that has
the following declaration in BIR:";`Pre"
sub malloc(malloc_size, malloc_result)
malloc_size :: in u32 = R0
malloc_result :: out u32 = R0";`P"This plugin will add two definitions, one just before the call
to the malloc:";`Pre"
...
000001c3: malloc_size := R0
0000015b: call @malloc with return %0000015c";`P"And prepend another to the block to which malloc will return:";`Pre"
0000015c:
000001c4: R0 := malloc_result
...";`S"SEE ALSO";`P"$(b,bap-plugin-api)(1)"];Config.when_ready(fun_->Project.register_pass~deps:["abi"]main)