From 82f9d9ca7a7c9b2521389a7c6bb9994275560d44 Mon Sep 17 00:00:00 2001 From: Timur Iskhodzhanov Date: Wed, 19 Mar 2014 08:23:00 +0000 Subject: [PATCH] [ASan] Print mmap errno/GetLastError in a readable and consistent way Reviewed at http://llvm-reviews.chandlerc.com/D3107 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@204218 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/sanitizer_common/sanitizer_posix.cc | 15 ++++++++------- lib/sanitizer_common/sanitizer_win.cc | 15 +++++++++------ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/lib/sanitizer_common/sanitizer_posix.cc b/lib/sanitizer_common/sanitizer_posix.cc index 65ff16566..a9b9d77f7 100644 --- a/lib/sanitizer_common/sanitizer_posix.cc +++ b/lib/sanitizer_common/sanitizer_posix.cc @@ -64,7 +64,8 @@ void *MmapOrDie(uptr size, const char *mem_type) { Die(); } recursion_count++; - Report("ERROR: %s failed to allocate 0x%zx (%zd) bytes of %s: %d\n", + Report("ERROR: %s failed to " + "allocate 0x%zx (%zd) bytes of %s (errno: %d)\n", SanitizerToolName, size, size, mem_type, reserrno); DumpProcessMap(); CHECK("unable to mmap" && 0); @@ -91,8 +92,8 @@ void *MmapNoReserveOrDie(uptr size, const char *mem_type) { -1, 0); int reserrno; if (internal_iserror(p, &reserrno)) { - Report("ERROR: " - "%s failed to allocate noreserve 0x%zx (%zd) bytes for '%s' (%d)\n", + Report("ERROR: %s failed to " + "allocate noreserve 0x%zx (%zd) bytes for '%s' (errno: %d)\n", SanitizerToolName, size, size, mem_type, reserrno); CHECK("unable to mmap" && 0); } @@ -108,8 +109,8 @@ void *MmapFixedNoReserve(uptr fixed_addr, uptr size) { -1, 0); int reserrno; if (internal_iserror(p, &reserrno)) - Report("ERROR: " - "%s failed to allocate 0x%zx (%zd) bytes at address %zu (%d)\n", + Report("ERROR: %s failed to " + "allocate 0x%zx (%zd) bytes at address %zu (errno: %d)\n", SanitizerToolName, size, size, fixed_addr, reserrno); return (void *)p; } @@ -123,8 +124,8 @@ void *MmapFixedOrDie(uptr fixed_addr, uptr size) { -1, 0); int reserrno; if (internal_iserror(p, &reserrno)) { - Report("ERROR:" - " %s failed to allocate 0x%zx (%zd) bytes at address %zu (%d)\n", + Report("ERROR: %s failed to " + "allocate 0x%zx (%zd) bytes at address %zu (errno: %d)\n", SanitizerToolName, size, size, fixed_addr, reserrno); CHECK("unable to mmap" && 0); } diff --git a/lib/sanitizer_common/sanitizer_win.cc b/lib/sanitizer_common/sanitizer_win.cc index 21f92b3b6..d7d1c36ea 100644 --- a/lib/sanitizer_common/sanitizer_win.cc +++ b/lib/sanitizer_common/sanitizer_win.cc @@ -80,8 +80,9 @@ void GetThreadStackTopAndBottom(bool at_initialization, uptr *stack_top, void *MmapOrDie(uptr size, const char *mem_type) { void *rv = VirtualAlloc(0, size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); if (rv == 0) { - Report("ERROR: Failed to allocate 0x%zx (%zd) bytes of %s\n", - size, size, mem_type); + Report("ERROR: %s failed to " + "allocate 0x%zx (%zd) bytes of %s (error code: %d)\n", + SanitizerToolName, size, size, mem_type, GetLastError()); CHECK("unable to mmap" && 0); } return rv; @@ -89,8 +90,9 @@ void *MmapOrDie(uptr size, const char *mem_type) { void UnmapOrDie(void *addr, uptr size) { if (VirtualFree(addr, size, MEM_DECOMMIT) == 0) { - Report("ERROR: Failed to deallocate 0x%zx (%zd) bytes at address %p\n", - size, size, addr); + Report("ERROR: %s failed to " + "deallocate 0x%zx (%zd) bytes at address %p (error code: %d)\n", + SanitizerToolName, size, size, addr, GetLastError()); CHECK("unable to unmap" && 0); } } @@ -101,8 +103,9 @@ void *MmapFixedNoReserve(uptr fixed_addr, uptr size) { void *p = VirtualAlloc((LPVOID)fixed_addr, size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); if (p == 0) - Report("ERROR: Failed to allocate 0x%zx (%zd) bytes at %p (%d)\n", - size, size, fixed_addr, GetLastError()); + Report("ERROR: %s failed to " + "allocate %p (%zd) bytes at %p (error code: %d)\n", + SanitizerToolName, size, size, fixed_addr, GetLastError()); return p; } -- 2.11.4.GIT