[compiler-rt] Make mmap-munmap interceptor fail earlier (PR #171295)
Thurston Dang via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 27 12:55:33 PST 2026
================
@@ -159,43 +192,90 @@ DECLARE_REAL_AND_INTERCEPTOR(void, free, void*)
template <class Mmap>
static void* mmap_interceptor(Mmap real_mmap, void* addr, SIZE_T length,
int prot, int flags, int fd, OFF64_T offset) {
+ if (length == 0)
+ return real_mmap(addr, length, prot, flags, fd, offset);
+
+# if SANITIZER_POSIX
+ uptr start = reinterpret_cast<uptr>(addr);
+ uptr end_excl;
+ if (UNLIKELY(__builtin_add_overflow(start, (uptr)length, &end_excl))) {
+ errno = errno_EINVAL;
+ return (void*)-1;
+ }
+
+ if (flags & map_fixed) {
+ if (__asan::IntersectsShadowOrGap(start, end_excl)) {
+ errno = errno_EINVAL;
+ return (void*)-1;
+ }
+ if (!AddrIsInMem(start) || !AddrIsInMem(end_excl - 1)) {
+ errno = errno_ENOMEM;
+ return (void*)-1;
+ }
+ } else {
+ if (addr && __asan::IntersectsShadowOrGap(start, start + 1))
+ addr = nullptr;
----------------
thurstond wrote:
cuda_test.cpp fails (https://github.com/llvm/llvm-project/actions/runs/21395345315/job/61605235935?pr=171295) when protect_shadow_gap=0
https://github.com/llvm/llvm-project/pull/171295
More information about the llvm-commits
mailing list