|
1 | 1 | /*
|
2 | 2 | *
|
3 |
| - * Copyright (C) 2023 Intel Corporation |
| 3 | + * Copyright (C) 2023-2024 Intel Corporation |
4 | 4 | *
|
5 | 5 | * Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
|
6 | 6 | * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
24 | 24 | #include <tbb/scalable_allocator.h>
|
25 | 25 |
|
26 | 26 | #include "utils_common.h"
|
| 27 | +#include "utils_sanitizers.h" |
27 | 28 |
|
28 | 29 | typedef void *(*raw_alloc_tbb_type)(intptr_t, size_t *);
|
29 | 30 | typedef void (*raw_free_tbb_type)(intptr_t, void *, size_t);
|
@@ -191,6 +192,13 @@ static void *tbb_calloc(void *pool, size_t num, size_t size) {
|
191 | 192 | return NULL;
|
192 | 193 | }
|
193 | 194 |
|
| 195 | + // synchronizes with release in tbb_free: |
| 196 | + // if another thread modified memory allocated from tbb and called free |
| 197 | + // and we end up getting this memory from tbb_malloc above we need to |
| 198 | + // tell asan that the memset below does not conflict with any preceeding |
| 199 | + // stores |
| 200 | + utils_annotate_acquire(ptr); |
| 201 | + |
194 | 202 | memset(ptr, 0, csize);
|
195 | 203 | return ptr;
|
196 | 204 | }
|
@@ -229,6 +237,9 @@ static umf_result_t tbb_free(void *pool, void *ptr) {
|
229 | 237 |
|
230 | 238 | TLS_last_free_error = UMF_RESULT_SUCCESS;
|
231 | 239 |
|
| 240 | + // synchronizes (happens-before) with acquire in tbb_calloc |
| 241 | + utils_annotate_release(ptr); |
| 242 | + |
232 | 243 | struct tbb_memory_pool *pool_data = (struct tbb_memory_pool *)pool;
|
233 | 244 | if (g_tbb_ops.pool_free(pool_data->tbb_pool, ptr)) {
|
234 | 245 | return UMF_RESULT_SUCCESS;
|
|
0 commit comments