Create a zero initialized coverage array on the heap (note: we do this instead of directly initializing the value [0; _], to avoid excess stack usage in debug mode).
()
| 115 | /// Create a zero initialized coverage array on the heap (note: we do this instead of directly |
| 116 | /// initializing the value [0; _], to avoid excess stack usage in debug mode). |
| 117 | fn init_coverage_array() -> Box<[u64; MAP_SIZE / 8]> { |
| 118 | let layout = std::alloc::Layout::new::<[u64; MAP_SIZE / 8]>(); |
| 119 | // Safety: `layout` has a non-zero size and `[u64; _]` is valid when zero initializated. |
| 120 | unsafe { |
| 121 | let ptr: *mut [u64; MAP_SIZE / 8] = std::alloc::alloc_zeroed(layout).cast(); |
| 122 | if ptr.is_null() { |
| 123 | panic!("failed to allocate {} bytes for coverage array.", layout.size()) |
| 124 | } |
| 125 | Box::from_raw(ptr) |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | type EdgeCountSnapshot = Vec<u8>; |
| 130 |