From acc877b3a7ec0e409247e8d8a39872285ec46469 Mon Sep 17 00:00:00 2001 From: Feoramund <161657516+Feoramund@users.noreply.github.com> Date: Fri, 9 May 2025 17:34:33 -0400 Subject: [PATCH] Don't free virtual memory when ThreadSanitizer is active This is a workaround for a lack of an ability to tell TSan that it should clear any state it has about certain memory ranges to prevent false positives. --- base/runtime/virtual_memory.odin | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/base/runtime/virtual_memory.odin b/base/runtime/virtual_memory.odin index e8f676350..e4116d260 100644 --- a/base/runtime/virtual_memory.odin +++ b/base/runtime/virtual_memory.odin @@ -65,7 +65,19 @@ allocate_virtual_memory_aligned :: proc "contextless" (size: int, alignment: int Free virtual memory allocated by any of the `allocate_*` procs. */ free_virtual_memory :: proc "contextless" (ptr: rawptr, size: int) { - _free_virtual_memory(ptr, size) + // TODO: There is currently no good way to tell ThreadSanitizer that we're + // done with a region of memory and to clear any information it has about + // it, so that when it's enabled, we simply do not release any memory back + // to the operating system. + // + // This prevents all false positive warnings when one thread inevitably + // gives up some of its memory that is then re-assigned to a different + // thread by the operating system. + // + // This is a workaround for the time being. + when .Thread not_in ODIN_SANITIZER_FLAGS { + _free_virtual_memory(ptr, size) + } } /*