#include <sys/mman.h>
int main(int argc, char **argv) {
- int size = 4096;
- int tag = 74;
- int val = 42;
+ const int kSize = 4096;
+ const int kTag = 74;
// Get any mmaped pointer.
void *r =
- mmap(0, size, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
+ mmap(0, kSize, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
if (r == MAP_FAILED) {
fprintf(stderr, "Failed to mmap.\n");
abort();
}
// Manually tag the pointer and the memory.
- __hwasan_tag_memory(r, tag, size);
- int *p1 = __hwasan_tag_pointer(r, tag);
+ __hwasan_tag_memory(r, kTag, kSize);
+ int *p1 = __hwasan_tag_pointer(r, kTag);
// Check that the pointer and the tag match.
- if (__hwasan_test_shadow(p1, size) != -1) {
+ if (__hwasan_test_shadow(p1, kSize) != -1) {
fprintf(stderr, "Failed to tag.\n");
return 1;
}
// First munmmap and then mmap the same pointer using MAP_FIXED.
- munmap(r, size);
- if (__hwasan_test_shadow(r, size) != -1) {
+ munmap(r, kSize);
+ if (__hwasan_test_shadow(r, kSize) != -1) {
fprintf(stderr, "Shadow memory was not cleaned by munmap.\n");
return 1;
}
- __hwasan_tag_memory(r, tag, size);
- int *p2 = (int *)mmap(r, size, PROT_READ | PROT_WRITE,
+ __hwasan_tag_memory(r, kTag, kSize);
+ int *p2 = (int *)mmap(r, kSize, PROT_READ | PROT_WRITE,
MAP_FIXED | MAP_ANON | MAP_PRIVATE, -1, 0);
// Check that the pointer has no tag in it.
}
// Make sure we can access the shadow with an untagged pointer.
- if (__hwasan_test_shadow(p2, size) != -1 ) {
+ if (__hwasan_test_shadow(p2, kSize) != -1) {
fprintf(stderr, "Shadow memory was not cleaned by mmap.\n");
return 1;
}