@@ -67,45 +67,6 @@ void TracePC::HandleInline8bitCountersInit(uint8_t *Start, uint8_t *Stop) {
6767 NumInline8bitCounters += M.Size ();
6868}
6969
70- // Mark all full page counter regions as PROT_NONE and set Enabled=false.
71- // The first time the instrumented code hits such a protected/disabled
72- // counter region we should catch a SEGV and call UnprotectLazyCounters,
73- // which will mark the page as PROT_READ|PROT_WRITE and set Enabled=true.
74- //
75- // Whenever other functions iterate over the counters they should ignore
76- // regions with Enabled=false.
77- void TracePC::ProtectLazyCounters () {
78- size_t NumPagesProtected = 0 ;
79- IterateCounterRegions ([&](Module::Region &R) {
80- if (!R.OneFullPage ) return ;
81- if (Mprotect (R.Start , R.Stop - R.Start , false )) {
82- R.Enabled = false ;
83- NumPagesProtected++;
84- }
85- });
86- if (NumPagesProtected)
87- Printf (" INFO: %zd pages of counters where protected;"
88- " libFuzzer's SEGV handler must be installed\n " ,
89- NumPagesProtected);
90- }
91-
92- bool TracePC::UnprotectLazyCounters (void *CounterPtr) {
93- // Printf("UnprotectLazyCounters: %p\n", CounterPtr);
94- if (!CounterPtr)
95- return false ;
96- bool Done = false ;
97- uint8_t *Addr = reinterpret_cast <uint8_t *>(CounterPtr);
98- IterateCounterRegions ([&](Module::Region &R) {
99- if (!R.OneFullPage || R.Enabled || Done) return ;
100- if (Addr >= R.Start && Addr < R.Stop )
101- if (Mprotect (R.Start , R.Stop - R.Start , true )) {
102- R.Enabled = true ;
103- Done = true ;
104- }
105- });
106- return Done;
107- }
108-
10970void TracePC::HandlePCsInit (const uintptr_t *Start, const uintptr_t *Stop) {
11071 const PCTableEntry *B = reinterpret_cast <const PCTableEntry *>(Start);
11172 const PCTableEntry *E = reinterpret_cast <const PCTableEntry *>(Stop);
0 commit comments