Skip to content

Commit 5af717e

Browse files
authored
Merge pull request #610 from szadam/sanitizers
Fix asan bug
2 parents 6f74530 + 14c5198 commit 5af717e

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

.github/workflows/sanitizers.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ jobs:
7272
working-directory: ${{env.BUILD_DIR}}
7373
run: >
7474
${{ matrix.compiler.cxx == 'icpx' && '. /opt/intel/oneapi/setvars.sh &&' || ''}}
75-
GTEST_FILTER="-*umfProviderTest.alloc_page64_align_0*" ctest --output-on-failure
76-
# TO DO: fix umf-provider_os_memory test for sanitizers
77-
# issue 581: https://github.com/oneapi-src/unified-memory-framework/issues/581
75+
ctest --output-on-failure
7876
7977
windows-build:
8078
name: cl and clang-cl on Windows

src/base_alloc/base_alloc_global.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,12 @@ void umf_ba_global_free(void *ptr) {
195195

196196
int ac_index = size_to_idx(total_size);
197197
if (ac_index >= NUM_ALLOCATION_CLASSES) {
198-
utils_annotate_memory_inaccessible(ptr, total_size);
199198
ba_os_free(ptr, total_size);
200199
return;
201200
}
202201

203202
if (!BASE_ALLOC.ac[ac_index]) {
204203
// if creating ac failed, memory must have been allocated by os
205-
utils_annotate_memory_inaccessible(ptr, total_size);
206204
ba_os_free(ptr, total_size);
207205
return;
208206
}

src/base_alloc/base_alloc_linux.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,13 @@ static UTIL_ONCE_FLAG Page_size_is_initialized = UTIL_ONCE_FLAG_INIT;
1919
static size_t Page_size;
2020

2121
void *ba_os_alloc(size_t size) {
22-
return mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS,
23-
-1, 0);
22+
void *ptr = mmap(NULL, size, PROT_READ | PROT_WRITE,
23+
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
24+
// this should be unnecessary but pairs of mmap/munmap do not reset
25+
// asan's user-poisoning flags, leading to invalid error reports
26+
// Bug 81619: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81619
27+
utils_annotate_memory_defined(ptr, size);
28+
return ptr;
2429
}
2530

2631
void ba_os_free(void *ptr, size_t size) {

src/provider/provider_os_memory_posix.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "provider_os_memory_internal.h"
1818
#include "utils_log.h"
19+
#include "utils_sanitizers.h"
1920

2021
// maximum value of the off_t type
2122
#define OFF_T_MAX \
@@ -74,11 +75,20 @@ void *os_mmap(void *hint_addr, size_t length, int prot, int flag, int fd,
7475
if (ptr == MAP_FAILED) {
7576
return NULL;
7677
}
77-
78+
// this should be unnecessary but pairs of mmap/munmap do not reset
79+
// asan's user-poisoning flags, leading to invalid error reports
80+
// Bug 81619: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81619
81+
utils_annotate_memory_defined(ptr, length);
7882
return ptr;
7983
}
8084

81-
int os_munmap(void *addr, size_t length) { return munmap(addr, length); }
85+
int os_munmap(void *addr, size_t length) {
86+
// this should be unnecessary but pairs of mmap/munmap do not reset
87+
// asan's user-poisoning flags, leading to invalid error reports
88+
// Bug 81619: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81619
89+
utils_annotate_memory_defined(addr, length);
90+
return munmap(addr, length);
91+
}
8292

8393
size_t os_get_page_size(void) { return sysconf(_SC_PAGE_SIZE); }
8494

0 commit comments

Comments
 (0)