[Sanitizer] Use ReportMmapFailureAndDie() in all applicable mmap variants on Posix.

llvm-svn: 252121
This commit is contained in:
Alexey Samsonov
2015-11-05 01:16:48 +00:00
parent 18e9625edb
commit 96c6ecc842
4 changed files with 12 additions and 16 deletions

View File

@@ -164,7 +164,7 @@ void NORETURN CheckFailed(const char *file, int line, const char *cond,
}
void NORETURN ReportMmapFailureAndDie(uptr size, const char *mem_type,
error_t err) {
const char *mmap_type, error_t err) {
static int recursion_count;
if (recursion_count) {
// The Report() and CHECK calls below may call mmap recursively and fail.
@@ -174,8 +174,8 @@ void NORETURN ReportMmapFailureAndDie(uptr size, const char *mem_type,
}
recursion_count++;
Report("ERROR: %s failed to "
"allocate 0x%zx (%zd) bytes of %s (error code: %d)\n",
SanitizerToolName, size, size, mem_type, err);
"%s 0x%zx (%zd) bytes of %s (error code: %d)\n",
SanitizerToolName, mmap_type, size, size, mem_type, err);
DumpProcessMap();
UNREACHABLE("unable to mmap");
}

View File

@@ -309,7 +309,7 @@ void NORETURN Die();
void NORETURN
CheckFailed(const char *file, int line, const char *cond, u64 v1, u64 v2);
void NORETURN ReportMmapFailureAndDie(uptr size, const char *mem_type,
error_t err);
const char *mmap_type, error_t err);
// Set the name of the current thread to 'name', return true on succees.
// The name may be truncated to a system-dependent limit.

View File

@@ -119,7 +119,7 @@ void *MmapOrDie(uptr size, const char *mem_type) {
MAP_PRIVATE | MAP_ANON, -1, 0);
int reserrno;
if (internal_iserror(res, &reserrno))
ReportMmapFailureAndDie(size, mem_type, reserrno);
ReportMmapFailureAndDie(size, mem_type, "allocate", reserrno);
IncreaseTotalMmap(size);
return (void *)res;
}
@@ -143,12 +143,8 @@ void *MmapNoReserveOrDie(uptr size, const char *mem_type) {
MAP_PRIVATE | MAP_ANON | MAP_NORESERVE,
-1, 0);
int reserrno;
if (internal_iserror(p, &reserrno)) {
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);
}
if (internal_iserror(p, &reserrno))
ReportMmapFailureAndDie(size, mem_type, "allocate noreserve", reserrno);
IncreaseTotalMmap(size);
return (void *)p;
}
@@ -162,10 +158,10 @@ 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 %zx (errno: %d)\n",
SanitizerToolName, size, size, fixed_addr, reserrno);
CHECK("unable to mmap" && 0);
char mem_type[30];
internal_snprintf(mem_type, sizeof(mem_type), "memory at address 0x%zx",
fixed_addr);
ReportMmapFailureAndDie(size, mem_type, "allocate", reserrno);
}
IncreaseTotalMmap(size);
return (void *)p;

View File

@@ -86,7 +86,7 @@ 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)
ReportMmapFailureAndDie(size, mem_type, GetLastError());
ReportMmapFailureAndDie(size, mem_type, "allocate", GetLastError());
return rv;
}