@@ -163,10 +163,11 @@ static cl::opt<bool> ClDebugNonzeroLabels(
163
163
cl::Hidden);
164
164
165
165
// Experimental feature that inserts callbacks for certain data events.
166
- // Currently callbacks are only inserted for stores.
166
+ // Currently callbacks are only inserted for loads and stores.
167
167
//
168
168
// If this flag is set to true, the user must provide definitions for the
169
169
// following callback functions:
170
+ // void __dfsan_load_callback(dfsan_label Label);
170
171
// void __dfsan_store_callback(dfsan_label Label);
171
172
static cl::opt<bool > ClEventCallbacks (
172
173
" dfsan-event-callbacks" ,
@@ -356,14 +357,15 @@ class DataFlowSanitizer : public ModulePass {
356
357
FunctionType *DFSanSetLabelFnTy;
357
358
FunctionType *DFSanNonzeroLabelFnTy;
358
359
FunctionType *DFSanVarargWrapperFnTy;
359
- FunctionType *DFSanStoreCallbackFnTy ;
360
+ FunctionType *DFSanLoadStoreCallbackFnTy ;
360
361
FunctionCallee DFSanUnionFn;
361
362
FunctionCallee DFSanCheckedUnionFn;
362
363
FunctionCallee DFSanUnionLoadFn;
363
364
FunctionCallee DFSanUnimplementedFn;
364
365
FunctionCallee DFSanSetLabelFn;
365
366
FunctionCallee DFSanNonzeroLabelFn;
366
367
FunctionCallee DFSanVarargWrapperFn;
368
+ FunctionCallee DFSanLoadCallbackFn;
367
369
FunctionCallee DFSanStoreCallbackFn;
368
370
MDNode *ColdCallWeights;
369
371
DFSanABIList ABIList;
@@ -596,7 +598,7 @@ bool DataFlowSanitizer::doInitialization(Module &M) {
596
598
Type::getVoidTy (*Ctx), None, /* isVarArg=*/ false );
597
599
DFSanVarargWrapperFnTy = FunctionType::get (
598
600
Type::getVoidTy (*Ctx), Type::getInt8PtrTy (*Ctx), /* isVarArg=*/ false );
599
- DFSanStoreCallbackFnTy =
601
+ DFSanLoadStoreCallbackFnTy =
600
602
FunctionType::get (Type::getVoidTy (*Ctx), ShadowTy, /* isVarArg=*/ false );
601
603
602
604
if (GetArgTLSPtr) {
@@ -798,8 +800,10 @@ bool DataFlowSanitizer::runOnModule(Module &M) {
798
800
DFSanVarargWrapperFn = Mod->getOrInsertFunction (" __dfsan_vararg_wrapper" ,
799
801
DFSanVarargWrapperFnTy);
800
802
803
+ DFSanLoadCallbackFn = Mod->getOrInsertFunction (" __dfsan_load_callback" ,
804
+ DFSanLoadStoreCallbackFnTy);
801
805
DFSanStoreCallbackFn = Mod->getOrInsertFunction (" __dfsan_store_callback" ,
802
- DFSanStoreCallbackFnTy );
806
+ DFSanLoadStoreCallbackFnTy );
803
807
804
808
std::vector<Function *> FnsToInstrument;
805
809
SmallPtrSet<Function *, 2 > FnsWithNativeABI;
@@ -812,6 +816,7 @@ bool DataFlowSanitizer::runOnModule(Module &M) {
812
816
&i != DFSanSetLabelFn.getCallee ()->stripPointerCasts () &&
813
817
&i != DFSanNonzeroLabelFn.getCallee ()->stripPointerCasts () &&
814
818
&i != DFSanVarargWrapperFn.getCallee ()->stripPointerCasts () &&
819
+ &i != DFSanLoadCallbackFn.getCallee ()->stripPointerCasts () &&
815
820
&i != DFSanStoreCallbackFn.getCallee ()->stripPointerCasts ())
816
821
FnsToInstrument.push_back (&i);
817
822
}
@@ -1344,6 +1349,10 @@ void DFSanVisitor::visitLoadInst(LoadInst &LI) {
1344
1349
DFSF.NonZeroChecks .push_back (Shadow);
1345
1350
1346
1351
DFSF.setShadow (&LI, Shadow);
1352
+ if (ClEventCallbacks) {
1353
+ IRBuilder<> IRB (&LI);
1354
+ IRB.CreateCall (DFSF.DFS .DFSanLoadCallbackFn , Shadow);
1355
+ }
1347
1356
}
1348
1357
1349
1358
void DFSanFunction::storeShadow (Value *Addr, uint64_t Size, Align Alignment,
0 commit comments