1 //===- FuzzerExtraCountersWindows.cpp - Extra coverage counters for Win32 -===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
8 // Extra coverage counters defined by user code for Windows.
9 //===----------------------------------------------------------------------===//
11 #include "FuzzerPlatform.h"
20 // The __start___libfuzzer_extra_counters variable is align 16, size 16 to
21 // ensure the padding between it and the next variable in this section (either
22 // __libfuzzer_extra_counters or __stop___libfuzzer_extra_counters) will be
23 // located at (__start___libfuzzer_extra_counters +
24 // sizeof(__start___libfuzzer_extra_counters)). Otherwise, the calculation of
25 // (stop - (start + sizeof(start))) might be skewed.
27 // The section name, __libfuzzer_extra_countaaa ends with "aaa", so it sorts
28 // before __libfuzzer_extra_counters alphabetically. We want the start symbol to
29 // be placed in the section just before the user supplied counters (if present).
31 #pragma section(".data$__libfuzzer_extra_countaaa")
33 __declspec(allocate(".data$__libfuzzer_extra_countaaa")) uint8_t
34 __start___libfuzzer_extra_counters
[16] = {0};
37 // Example of what the user-supplied counters should look like. First, the
38 // pragma to create the section name. It will fall alphabetically between
39 // ".data$__libfuzzer_extra_countaaa" and ".data$__libfuzzer_extra_countzzz".
40 // Next, the declspec to allocate the variable inside the specified section.
41 // Finally, some array, struct, whatever that is used to track the counter data.
42 // The size of this variable is computed at runtime by finding the difference of
43 // __stop___libfuzzer_extra_counters and __start___libfuzzer_extra_counters +
44 // sizeof(__start___libfuzzer_extra_counters).
48 // #pragma section(".data$__libfuzzer_extra_counters")
49 // __declspec(allocate(".data$__libfuzzer_extra_counters"))
50 // uint8_t any_name_variable[64 * 1024];
54 // Here, the section name, __libfuzzer_extra_countzzz ends with "zzz", so it
55 // sorts after __libfuzzer_extra_counters alphabetically. We want the stop
56 // symbol to be placed in the section just after the user supplied counters (if
57 // present). Align to 1 so there isn't any padding placed between this and the
60 #pragma section(".data$__libfuzzer_extra_countzzz")
62 __declspec(allocate(".data$__libfuzzer_extra_countzzz")) uint8_t
63 __stop___libfuzzer_extra_counters
= 0;
65 uint8_t *ExtraCountersBegin() {
66 return __start___libfuzzer_extra_counters
+
67 sizeof(__start___libfuzzer_extra_counters
);
70 uint8_t *ExtraCountersEnd() { return &__stop___libfuzzer_extra_counters
; }
72 ATTRIBUTE_NO_SANITIZE_ALL
73 void ClearExtraCounters() {
74 uint8_t *Beg
= ExtraCountersBegin();
75 SecureZeroMemory(Beg
, ExtraCountersEnd() - Beg
);