Revert "[sanitizer-coverage] remove stale code" at it breaks Windows bot.
This reverts commit r282994. llvm-svn: 283183
This commit is contained in:
		
							parent
							
								
									1a8d52d1ae
								
							
						
					
					
						commit
						bf1bc21157
					
				| 
						 | 
				
			
			@ -113,6 +113,8 @@ class CoverageData {
 | 
			
		|||
  uptr *data();
 | 
			
		||||
  uptr size() const;
 | 
			
		||||
 | 
			
		||||
  void SetPcBuffer(uptr* data, uptr length);
 | 
			
		||||
 | 
			
		||||
 private:
 | 
			
		||||
  struct NamedPcRange {
 | 
			
		||||
    const char *copied_module_name;
 | 
			
		||||
| 
						 | 
				
			
			@ -143,6 +145,9 @@ class CoverageData {
 | 
			
		|||
  // Descriptor of the file mapped pc array.
 | 
			
		||||
  fd_t pc_fd;
 | 
			
		||||
 | 
			
		||||
  uptr *pc_buffer;
 | 
			
		||||
  uptr pc_buffer_len;
 | 
			
		||||
 | 
			
		||||
  // Vector of coverage guard arrays, protected by mu.
 | 
			
		||||
  InternalMmapVectorNoCtor<s32*> guard_array_vec;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -214,6 +219,9 @@ void CoverageData::Enable() {
 | 
			
		|||
    atomic_store(&pc_array_size, kPcArrayMaxSize, memory_order_relaxed);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  pc_buffer = nullptr;
 | 
			
		||||
  pc_buffer_len = 0;
 | 
			
		||||
 | 
			
		||||
  cc_array = reinterpret_cast<uptr **>(MmapNoReserveOrDie(
 | 
			
		||||
      sizeof(uptr *) * kCcArrayMaxSize, "CovInit::cc_array"));
 | 
			
		||||
  atomic_store(&cc_array_size, kCcArrayMaxSize, memory_order_relaxed);
 | 
			
		||||
| 
						 | 
				
			
			@ -419,6 +427,7 @@ void CoverageData::Add(uptr pc, u32 *guard) {
 | 
			
		|||
           atomic_load(&pc_array_size, memory_order_acquire));
 | 
			
		||||
  uptr counter = atomic_fetch_add(&coverage_counter, 1, memory_order_relaxed);
 | 
			
		||||
  pc_array[idx] = BundlePcAndCounter(pc, counter);
 | 
			
		||||
  if (pc_buffer && counter < pc_buffer_len) pc_buffer[counter] = pc;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Registers a pair caller=>callee.
 | 
			
		||||
| 
						 | 
				
			
			@ -872,6 +881,11 @@ void CoverageData::DumpAll() {
 | 
			
		|||
  DumpCallerCalleePairs();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void CoverageData::SetPcBuffer(uptr* data, uptr length) {
 | 
			
		||||
  pc_buffer = data;
 | 
			
		||||
  pc_buffer_len = length;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void CovPrepareForSandboxing(__sanitizer_sandbox_arguments *args) {
 | 
			
		||||
  if (!args) return;
 | 
			
		||||
  if (!coverage_enabled) return;
 | 
			
		||||
| 
						 | 
				
			
			@ -1006,6 +1020,16 @@ uptr __sanitizer_get_coverage_guards(uptr **data) {
 | 
			
		|||
  return coverage_data.size();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
SANITIZER_INTERFACE_ATTRIBUTE
 | 
			
		||||
void __sanitizer_set_coverage_pc_buffer(uptr *data, uptr length) {
 | 
			
		||||
  coverage_data.SetPcBuffer(data, length);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
SANITIZER_INTERFACE_ATTRIBUTE
 | 
			
		||||
uptr __sanitizer_get_coverage_pc_buffer_pos() {
 | 
			
		||||
  return __sanitizer_get_total_unique_coverage();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
SANITIZER_INTERFACE_ATTRIBUTE
 | 
			
		||||
uptr __sanitizer_get_number_of_counters() {
 | 
			
		||||
  return coverage_data.GetNumberOf8bitCounters();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,49 @@
 | 
			
		|||
// Test __sanitizer_coverage_pc_buffer().
 | 
			
		||||
 | 
			
		||||
// RUN: %clangxx_asan -fsanitize-coverage=edge %stdcxx11 %s -O3 -o %t && %run %t
 | 
			
		||||
 | 
			
		||||
// UNSUPPORTED: android
 | 
			
		||||
 | 
			
		||||
#include <assert.h>
 | 
			
		||||
#include <memory>
 | 
			
		||||
#include <sanitizer/coverage_interface.h>
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
 | 
			
		||||
static volatile int sink;
 | 
			
		||||
__attribute__((noinline)) void foo() { sink = 1; }
 | 
			
		||||
 | 
			
		||||
void assertNotZeroPcs(uintptr_t *buf, uintptr_t size) {
 | 
			
		||||
  assert(buf);
 | 
			
		||||
  for (uintptr_t i = 0; i < size; ++i)
 | 
			
		||||
    assert(buf[i]);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int main() {
 | 
			
		||||
  uintptr_t buf_size = 1 << 20;
 | 
			
		||||
  std::unique_ptr<uintptr_t[]> buf(new uintptr_t[buf_size]);
 | 
			
		||||
  __sanitizer_set_coverage_pc_buffer(buf.get(), buf_size);
 | 
			
		||||
 | 
			
		||||
  {
 | 
			
		||||
    uintptr_t sz = __sanitizer_get_coverage_pc_buffer_pos();
 | 
			
		||||
    assertNotZeroPcs(buf.get(), sz);
 | 
			
		||||
    assert(sz);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  {
 | 
			
		||||
    uintptr_t sz = __sanitizer_get_coverage_pc_buffer_pos();
 | 
			
		||||
    foo();
 | 
			
		||||
    uintptr_t sz1 = __sanitizer_get_coverage_pc_buffer_pos();
 | 
			
		||||
    assertNotZeroPcs(buf.get(), sz1);
 | 
			
		||||
    assert(sz1 > sz);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  {
 | 
			
		||||
    uintptr_t sz = __sanitizer_get_coverage_pc_buffer_pos();
 | 
			
		||||
    // reset coverage to 0.
 | 
			
		||||
    __sanitizer_reset_coverage();
 | 
			
		||||
    uintptr_t sz1 = __sanitizer_get_coverage_pc_buffer_pos();
 | 
			
		||||
    assertNotZeroPcs(buf.get(), sz1);
 | 
			
		||||
    assert(sz1 < sz);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue