Skip to content

Commit 0458405

Browse files
committed
[sanitizer] Add diagnostics for munmap failure
We are seeing CHECK is triggered there, but it's unclear why.
1 parent c598828 commit 0458405

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_common.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,26 @@ void NORETURN ReportMmapFailureAndDie(uptr size, const char *mem_type,
6161
UNREACHABLE("unable to mmap");
6262
}
6363

64+
void NORETURN ReportMunmapFailureAndDie(void *addr, uptr size, error_t err,
65+
bool raw_report) {
66+
static int recursion_count;
67+
if (raw_report || recursion_count) {
68+
// If raw report is requested or we went into recursion just die. The
69+
// Report() and CHECK calls below may call mmap recursively and fail.
70+
RawWrite("ERROR: Failed to mmap\n");
71+
Die();
72+
}
73+
recursion_count++;
74+
Report(
75+
"ERROR: %s failed to deallocate 0x%zx (%zd) bytes at address %p (error "
76+
"code: %d)\n",
77+
SanitizerToolName, size, size, addr, err);
78+
#if !SANITIZER_GO
79+
DumpProcessMap();
80+
#endif
81+
UNREACHABLE("unable to unmmap");
82+
}
83+
6484
typedef bool UptrComparisonFunction(const uptr &a, const uptr &b);
6585
typedef bool U32ComparisonFunction(const u32 &a, const u32 &b);
6686

compiler-rt/lib/sanitizer_common/sanitizer_common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,8 @@ CheckFailed(const char *file, int line, const char *cond, u64 v1, u64 v2);
315315
void NORETURN ReportMmapFailureAndDie(uptr size, const char *mem_type,
316316
const char *mmap_type, error_t err,
317317
bool raw_report = false);
318+
void NORETURN ReportMunmapFailureAndDie(void *ptr, uptr size, error_t err,
319+
bool raw_report = false);
318320

319321
// Returns true if the platform-specific error reported is an OOM error.
320322
bool ErrorIsOOM(error_t err);

compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,9 @@ void *MmapOrDie(uptr size, const char *mem_type, bool raw_report) {
5757
void UnmapOrDie(void *addr, uptr size) {
5858
if (!addr || !size) return;
5959
uptr res = internal_munmap(addr, size);
60-
if (UNLIKELY(internal_iserror(res))) {
61-
Report("ERROR: %s failed to deallocate 0x%zx (%zd) bytes at address %p\n",
62-
SanitizerToolName, size, size, addr);
63-
CHECK("unable to unmap" && 0);
64-
}
60+
int reserrno;
61+
if (UNLIKELY(internal_iserror(res, &reserrno)))
62+
ReportMunmapFailureAndDie(addr, size, reserrno);
6563
DecreaseTotalMmap(size);
6664
}
6765

0 commit comments

Comments
 (0)