Skip to content

[NFC][asan] Extract out RecordPoison helper function#195672

Merged
vitalybuka merged 4 commits into
mainfrom
users/vitalybuka/spr/nfcasan-extract-out-recordpoison-helper-function
May 4, 2026
Merged

[NFC][asan] Extract out RecordPoison helper function#195672
vitalybuka merged 4 commits into
mainfrom
users/vitalybuka/spr/nfcasan-extract-out-recordpoison-helper-function

Conversation

@vitalybuka
Copy link
Copy Markdown
Contributor

No description provided.

vitalybuka added 2 commits May 4, 2026 08:21
Created using spr 1.3.7
@llvmorg-github-actions
Copy link
Copy Markdown

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Vitaly Buka (vitalybuka)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/195672.diff

1 Files Affected:

  • (modified) compiler-rt/lib/asan/asan_poisoning.cpp (+17-13)
diff --git a/compiler-rt/lib/asan/asan_poisoning.cpp b/compiler-rt/lib/asan/asan_poisoning.cpp
index 79457dda1e7c5..fffb3b4ac08f1 100644
--- a/compiler-rt/lib/asan/asan_poisoning.cpp
+++ b/compiler-rt/lib/asan/asan_poisoning.cpp
@@ -138,6 +138,22 @@ void AsanPoisonOrUnpoisonIntraObjectRedzone(uptr ptr, uptr size, bool poison) {
 // ---------------------- Interface ---------------- {{{1
 using namespace __asan;
 
+static void RecordPoison(uptr beg_addr, uptr end_addr) {
+  if (LIKELY(beg_addr >= end_addr || flags()->poison_history_size == 0))
+    return;
+  GET_STACK_TRACE(/*max_size=*/16, /*fast=*/false);
+  u32 current_tid = GetCurrentTidOrInvalid();
+
+  u32 stack_id = StackDepotPut(stack);
+
+  PoisonRecord record;
+  record.stack_id = stack_id;
+  record.thread_id = current_tid;
+  record.begin = beg_addr;
+  record.end = end_addr;
+  AddPoisonRecord(record);
+}
+
 // Current implementation of __asan_(un)poison_memory_region doesn't check
 // that user program (un)poisons the memory it owns. It poisons memory
 // conservatively, and unpoisons progressively to make sure asan shadow
@@ -155,19 +171,7 @@ void __asan_poison_memory_region(void const volatile *addr, uptr size) {
   VPrintf(3, "Trying to poison memory region [%p, %p)\n", (void *)beg_addr,
           (void *)end_addr);
 
-  if (flags()->poison_history_size > 0) {
-    GET_STACK_TRACE(/*max_size=*/16, /*fast=*/false);
-    u32 current_tid = GetCurrentTidOrInvalid();
-
-    u32 stack_id = StackDepotPut(stack);
-
-    PoisonRecord record;
-    record.stack_id = stack_id;
-    record.thread_id = current_tid;
-    record.begin = beg_addr;
-    record.end = end_addr;
-    AddPoisonRecord(record);
-  }
+  RecordPoison(beg_addr, end_addr);
 
   ShadowSegmentEndpoint beg(beg_addr);
   ShadowSegmentEndpoint end(end_addr);

@vitalybuka vitalybuka requested a review from thurstond May 4, 2026 16:30
kusmour and others added 2 commits May 4, 2026 11:30
Created using spr 1.3.7

[skip ci]
Created using spr 1.3.7
@vitalybuka vitalybuka changed the base branch from users/vitalybuka/spr/main.nfcasan-extract-out-recordpoison-helper-function to main May 4, 2026 18:30
@vitalybuka vitalybuka enabled auto-merge (squash) May 4, 2026 18:31
@vitalybuka vitalybuka merged commit 98419d2 into main May 4, 2026
12 of 17 checks passed
@vitalybuka vitalybuka deleted the users/vitalybuka/spr/nfcasan-extract-out-recordpoison-helper-function branch May 4, 2026 18:48
moar55 pushed a commit to moar55/llvm-project that referenced this pull request May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants