You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit e63621a
Browse filesBrowse the repository at this point in the historyBrowse files
AddressSanitizer (ASan) is an algorithm that can help developers identify memory safety issues in their C and C++ programs. Developers can use the /fsanitize=address flag to add ASan instrumentation to their native programs. At runtime, the ASan runtime replaces common allocation and memory manipulation functions with instrumented versions. Together, the instrumentation and ASan runtime enable developers to gather useful information about any memory safety issues that are encountered during execution.
12
12
13
+
14
+
## Custom allocators and ASan
15
+
16
+
ASan provides interceptors for common allocator interfaces, malloc/free, new/delete, HeapAlloc/HeapFree (via RtlAllocateHeap/RtlFreeHeap). Many programs make use of custom allocators for one reason or another. An example would be any program using dlmalloc or a solution using the std::allocator interface and VirtualAlloc. ASan instrumentation does not automatically enlighten these allocators, so it falls to the programmer to 'enlighten' them when using ASan.
17
+
18
+
### Manual ASan poisoning interface
19
+
20
+
The interface for enlightening is simple but it imposes alignment restrictions on the user. The interface function prototypes:
These functions are not needed when ASan is disabled, the interface header provides wrapper macros that will check whether ASan is enabled during compilation and omit the functions when ASan instrumentation is not enabled. These macros should be used rather than using the above functions directly:
25
+
`#define ASAN_POISON_MEMORY_REGION(addr, size)`
26
+
`#define ASAN_UNPOISON_MEMORY_REGION(addr, size)`
27
+
28
+
### Manual ASan poisoning and alignment
29
+
30
+
ASan poisoning has alignment requirements: the user must add padding such that the padding ends on a byte boundary in the shadow memory. Since each bit in the ASan shadow memory encodes the state of a byte in real memory, this means that **the size + padding for each allocation must align on a 8 byte boundary.** If this requirement is not satisfied it can lead to incorrect bug reporting, including missed and false-positive reports.
31
+
32
+
See the included examples for a little background. One is a small program to show what can go wrong with manual shadow memory poisoning. The second is an example implementation of manual poising using the `std::allocator` interface.
0 commit comments