[compiler-rt] [scudo] Add specific die functions for linux specific failures. (PR #68650)

Christopher Ferris via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 10 20:13:39 PDT 2023


https://github.com/cferris1000 updated https://github.com/llvm/llvm-project/pull/68650

>From 1019e8c2fa00e215bd66fb2a16daf6184050676b Mon Sep 17 00:00:00 2001
From: Christopher Ferris <cferris at google.com>
Date: Mon, 9 Oct 2023 17:36:26 -0700
Subject: [PATCH 1/2] [scudo] Add specific die functions for linux specific
 failures.

While running into failures on unmap calls, it becomes difficult
to figure out what's wrong. Break the dieOnMapUnmapError into
specific versions for map, unmap, and then one for mprotect.

Also, put these in a common linux space so that all linux derived
code can reuse this code.
---
 .../lib/scudo/standalone/CMakeLists.txt       |  1 +
 compiler-rt/lib/scudo/standalone/common.cpp   | 14 ----
 compiler-rt/lib/scudo/standalone/common.h     |  4 --
 compiler-rt/lib/scudo/standalone/linux.cpp    |  9 ++-
 .../lib/scudo/standalone/linux_common.cpp     | 65 +++++++++++++++++++
 .../lib/scudo/standalone/linux_common.h       | 34 ++++++++++
 .../lib/scudo/standalone/mem_map_linux.cpp    | 11 ++--
 compiler-rt/lib/scudo/standalone/trusty.cpp   |  7 +-
 8 files changed, 113 insertions(+), 32 deletions(-)
 create mode 100644 compiler-rt/lib/scudo/standalone/linux_common.cpp
 create mode 100644 compiler-rt/lib/scudo/standalone/linux_common.h

diff --git a/compiler-rt/lib/scudo/standalone/CMakeLists.txt b/compiler-rt/lib/scudo/standalone/CMakeLists.txt
index c4d3ea1e4f05ba8..9738fb17d7f1241 100644
--- a/compiler-rt/lib/scudo/standalone/CMakeLists.txt
+++ b/compiler-rt/lib/scudo/standalone/CMakeLists.txt
@@ -108,6 +108,7 @@ set(SCUDO_SOURCES
   flags.cpp
   fuchsia.cpp
   linux.cpp
+  linux_common.cpp
   mem_map.cpp
   mem_map_fuchsia.cpp
   mem_map_linux.cpp
diff --git a/compiler-rt/lib/scudo/standalone/common.cpp b/compiler-rt/lib/scudo/standalone/common.cpp
index 666f95400c7e7aa..06e930638f6f971 100644
--- a/compiler-rt/lib/scudo/standalone/common.cpp
+++ b/compiler-rt/lib/scudo/standalone/common.cpp
@@ -21,18 +21,4 @@ uptr getPageSizeSlow() {
   return PageSizeCached;
 }
 
-// Fatal internal map() or unmap() error (potentially OOM related).
-void NORETURN dieOnMapUnmapError(uptr SizeIfOOM) {
-  char Error[128] = "Scudo ERROR: internal map or unmap failure\n";
-  if (SizeIfOOM) {
-    formatString(
-        Error, sizeof(Error),
-        "Scudo ERROR: internal map failure (NO MEMORY) requesting %zuKB\n",
-        SizeIfOOM >> 10);
-  }
-  outputRaw(Error);
-  setAbortMessage(Error);
-  die();
-}
-
 } // namespace scudo
diff --git a/compiler-rt/lib/scudo/standalone/common.h b/compiler-rt/lib/scudo/standalone/common.h
index d0f429cfcb7a08e..3581c946d1608fc 100644
--- a/compiler-rt/lib/scudo/standalone/common.h
+++ b/compiler-rt/lib/scudo/standalone/common.h
@@ -175,10 +175,6 @@ void setMemoryPermission(uptr Addr, uptr Size, uptr Flags,
 void releasePagesToOS(uptr BaseAddress, uptr Offset, uptr Size,
                       MapPlatformData *Data = nullptr);
 
-// Internal map & unmap fatal error. This must not call map(). SizeIfOOM shall
-// hold the requested size on an out-of-memory error, 0 otherwise.
-void NORETURN dieOnMapUnmapError(uptr SizeIfOOM = 0);
-
 // Logging related functions.
 
 void setAbortMessage(const char *Message);
diff --git a/compiler-rt/lib/scudo/standalone/linux.cpp b/compiler-rt/lib/scudo/standalone/linux.cpp
index c31c3d2483a97ad..3e3b2147b3c77c1 100644
--- a/compiler-rt/lib/scudo/standalone/linux.cpp
+++ b/compiler-rt/lib/scudo/standalone/linux.cpp
@@ -13,6 +13,7 @@
 #include "common.h"
 #include "internal_defs.h"
 #include "linux.h"
+#include "linux_common.h"
 #include "mutex.h"
 #include "string_utils.h"
 
@@ -41,8 +42,6 @@ namespace scudo {
 
 uptr getPageSize() { return static_cast<uptr>(sysconf(_SC_PAGESIZE)); }
 
-void NORETURN die() { abort(); }
-
 // TODO: Will be deprecated. Use the interfaces in MemMapLinux instead.
 void *map(void *Addr, uptr Size, UNUSED const char *Name, uptr Flags,
           UNUSED MapPlatformData *Data) {
@@ -66,7 +65,7 @@ void *map(void *Addr, uptr Size, UNUSED const char *Name, uptr Flags,
   void *P = mmap(Addr, Size, MmapProt, MmapFlags, -1, 0);
   if (P == MAP_FAILED) {
     if (!(Flags & MAP_ALLOWNOMEM) || errno != ENOMEM)
-      dieOnMapUnmapError(errno == ENOMEM ? Size : 0);
+      dieOnMapError(errno == ENOMEM ? Size : 0);
     return nullptr;
   }
 #if SCUDO_ANDROID
@@ -80,7 +79,7 @@ void *map(void *Addr, uptr Size, UNUSED const char *Name, uptr Flags,
 void unmap(void *Addr, uptr Size, UNUSED uptr Flags,
            UNUSED MapPlatformData *Data) {
   if (munmap(Addr, Size) != 0)
-    dieOnMapUnmapError();
+    dieOnUnmapError(reinterpret_cast<uptr>(Addr), Size);
 }
 
 // TODO: Will be deprecated. Use the interfaces in MemMapLinux instead.
@@ -88,7 +87,7 @@ void setMemoryPermission(uptr Addr, uptr Size, uptr Flags,
                          UNUSED MapPlatformData *Data) {
   int Prot = (Flags & MAP_NOACCESS) ? PROT_NONE : (PROT_READ | PROT_WRITE);
   if (mprotect(reinterpret_cast<void *>(Addr), Size, Prot) != 0)
-    dieOnMapUnmapError();
+    dieOnProtectError(Addr, Size, Prot);
 }
 
 // TODO: Will be deprecated. Use the interfaces in MemMapLinux instead.
diff --git a/compiler-rt/lib/scudo/standalone/linux_common.cpp b/compiler-rt/lib/scudo/standalone/linux_common.cpp
new file mode 100644
index 000000000000000..d0e39fb0ced87e3
--- /dev/null
+++ b/compiler-rt/lib/scudo/standalone/linux_common.cpp
@@ -0,0 +1,65 @@
+//===-- linux_common.cpp ----------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "platform.h"
+
+#if SCUDO_LINUX
+
+#include "common.h"
+#include "internal_defs.h"
+#include "linux_common.h"
+#include "string_utils.h"
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+namespace scudo {
+
+void NORETURN die() { abort(); }
+
+// Fatal internal map() error (potentially OOM related).
+void NORETURN dieOnMapError(uptr SizeIfOOM) {
+  char Error[128] = "Scudo ERROR: internal map failure\n";
+  if (SizeIfOOM) {
+    formatString(
+        Error, sizeof(Error),
+        "Scudo ERROR: internal map failure (NO MEMORY) requesting %zuKB\n",
+        SizeIfOOM >> 10);
+  }
+  outputRaw(Error);
+  setAbortMessage(Error);
+  die();
+}
+
+void NORETURN dieOnUnmapError(uptr Addr, uptr Size) {
+  char Error[128];
+  formatString(Error, sizeof(Error),
+               "Scudo ERROR: internal unmap failure (error desc=%s) Addr 0x%zx "
+               "Size %zu\n",
+               strerror(errno), Addr, Size);
+  outputRaw(Error);
+  setAbortMessage(Error);
+  die();
+}
+
+void NORETURN dieOnProtectError(uptr Addr, uptr Size, int Prot) {
+  char Error[128];
+  formatString(
+      Error, sizeof(Error),
+      "Scudo ERROR: internal protect failure (error desc=%s) Addr 0x%zx "
+      "Size %zu Prot %x\n",
+      strerror(errno), Addr, Size, Prot);
+  outputRaw(Error);
+  setAbortMessage(Error);
+  die();
+}
+
+} // namespace scudo
+
+#endif // SCUDO_LINUX
diff --git a/compiler-rt/lib/scudo/standalone/linux_common.h b/compiler-rt/lib/scudo/standalone/linux_common.h
new file mode 100644
index 000000000000000..6a5c528a040168b
--- /dev/null
+++ b/compiler-rt/lib/scudo/standalone/linux_common.h
@@ -0,0 +1,34 @@
+//===-- linux_common.h ------------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef SCUDO_LINUX_COMMON_H_
+#define SCUDO_LINUX_COMMON_H_
+
+#include "platform.h"
+
+#if SCUDO_LINUX
+
+#include "internal_defs.h"
+
+namespace scudo {
+
+// Internal map fatal error. This must not call map(). SizeIfOOM shall
+// hold the requested size on an out-of-memory error, 0 otherwise.
+void NORETURN dieOnMapError(uptr SizeIfOOM = 0);
+
+// Internal unmap fatal error. This must not call map().
+void NORETURN dieOnUnmapError(uptr Addr, uptr Size);
+
+// Internal protect fatal error. This must not call map().
+void NORETURN dieOnProtectError(uptr Addr, uptr Size, int Prot);
+
+} // namespace scudo
+
+#endif // SCUDO_LINUX
+
+#endif // SCUDO_LINUX_COMMON_H_
diff --git a/compiler-rt/lib/scudo/standalone/mem_map_linux.cpp b/compiler-rt/lib/scudo/standalone/mem_map_linux.cpp
index f377d105894db7d..8e55599398b956b 100644
--- a/compiler-rt/lib/scudo/standalone/mem_map_linux.cpp
+++ b/compiler-rt/lib/scudo/standalone/mem_map_linux.cpp
@@ -15,6 +15,7 @@
 #include "common.h"
 #include "internal_defs.h"
 #include "linux.h"
+#include "linux_common.h"
 #include "mutex.h"
 #include "string_utils.h"
 
@@ -64,7 +65,7 @@ static void *mmapWrapper(uptr Addr, uptr Size, const char *Name, uptr Flags) {
       mmap(reinterpret_cast<void *>(Addr), Size, MmapProt, MmapFlags, -1, 0);
   if (P == MAP_FAILED) {
     if (!(Flags & MAP_ALLOWNOMEM) || errno != ENOMEM)
-      dieOnMapUnmapError(errno == ENOMEM ? Size : 0);
+      dieOnMapError(errno == ENOMEM ? Size : 0);
     return nullptr;
   }
 #if SCUDO_ANDROID
@@ -101,21 +102,21 @@ void MemMapLinux::unmapImpl(uptr Addr, uptr Size) {
   }
 
   if (munmap(reinterpret_cast<void *>(Addr), Size) != 0)
-    dieOnMapUnmapError();
+    dieOnUnmapError(Addr, Size);
 }
 
 bool MemMapLinux::remapImpl(uptr Addr, uptr Size, const char *Name,
                             uptr Flags) {
   void *P = mmapWrapper(Addr, Size, Name, Flags);
   if (reinterpret_cast<uptr>(P) != Addr)
-    dieOnMapUnmapError();
+    dieOnMapError();
   return true;
 }
 
 void MemMapLinux::setMemoryPermissionImpl(uptr Addr, uptr Size, uptr Flags) {
   int Prot = (Flags & MAP_NOACCESS) ? PROT_NONE : (PROT_READ | PROT_WRITE);
   if (mprotect(reinterpret_cast<void *>(Addr), Size, Prot) != 0)
-    dieOnMapUnmapError();
+    dieOnProtectError(Addr, Size, Prot);
 }
 
 void MemMapLinux::releaseAndZeroPagesToOSImpl(uptr From, uptr Size) {
@@ -139,7 +140,7 @@ bool ReservedMemoryLinux::createImpl(uptr Addr, uptr Size, const char *Name,
 
 void ReservedMemoryLinux::releaseImpl() {
   if (munmap(reinterpret_cast<void *>(getBase()), getCapacity()) != 0)
-    dieOnMapUnmapError();
+    dieOnUnmapError(getBase(), getCapacity());
 }
 
 ReservedMemoryLinux::MemMapT ReservedMemoryLinux::dispatchImpl(uptr Addr,
diff --git a/compiler-rt/lib/scudo/standalone/trusty.cpp b/compiler-rt/lib/scudo/standalone/trusty.cpp
index 5f72b1cb3e54b05..daa72ba0c4bf3b1 100644
--- a/compiler-rt/lib/scudo/standalone/trusty.cpp
+++ b/compiler-rt/lib/scudo/standalone/trusty.cpp
@@ -11,6 +11,7 @@
 #if SCUDO_TRUSTY
 
 #include "common.h"
+#include "linux_common.h"
 #include "mutex.h"
 #include "trusty.h"
 
@@ -28,8 +29,6 @@ namespace scudo {
 
 uptr getPageSize() { return getauxval(AT_PAGESZ); }
 
-void NORETURN die() { abort(); }
-
 void *map(void *Addr, uptr Size, const char *Name, uptr Flags,
           UNUSED MapPlatformData *Data) {
   uint32_t MmapFlags =
@@ -51,7 +50,7 @@ void *map(void *Addr, uptr Size, const char *Name, uptr Flags,
   if (IS_ERR(P)) {
     errno = lk_err_to_errno(PTR_ERR(P));
     if (!(Flags & MAP_ALLOWNOMEM) || errno != ENOMEM)
-      dieOnMapUnmapError(Size);
+      dieOnMapError(Size);
     return nullptr;
   }
 
@@ -61,7 +60,7 @@ void *map(void *Addr, uptr Size, const char *Name, uptr Flags,
 void unmap(UNUSED void *Addr, UNUSED uptr Size, UNUSED uptr Flags,
            UNUSED MapPlatformData *Data) {
   if (_trusty_munmap(Addr, Size) != 0)
-    dieOnMapUnmapError();
+    dieOnUnmapError(Addr, Size);
 }
 
 void setMemoryPermission(UNUSED uptr Addr, UNUSED uptr Size, UNUSED uptr Flags,

>From 44cbb066b757e8511bdba8a6549afd08c40dd710 Mon Sep 17 00:00:00 2001
From: Christopher Ferris <cferris at google.com>
Date: Tue, 10 Oct 2023 19:18:54 -0700
Subject: [PATCH 2/2] Update for comments.

Move the dieOnXXX routines to reportXXX. Mv linux_common to report_linux.

Add a new reportRawError function that doesn't use ScopedString.
---
 .../lib/scudo/standalone/CMakeLists.txt       |  2 +-
 compiler-rt/lib/scudo/standalone/linux.cpp    | 10 ++++----
 .../lib/scudo/standalone/mem_map_linux.cpp    | 12 +++++-----
 compiler-rt/lib/scudo/standalone/report.cpp   | 11 ++++++---
 compiler-rt/lib/scudo/standalone/report.h     |  5 +++-
 .../{linux_common.cpp => report_linux.cpp}    | 23 +++++++------------
 .../{linux_common.h => report_linux.h}        | 18 +++++++--------
 compiler-rt/lib/scudo/standalone/trusty.cpp   |  8 ++++---
 8 files changed, 47 insertions(+), 42 deletions(-)
 rename compiler-rt/lib/scudo/standalone/{linux_common.cpp => report_linux.cpp} (77%)
 rename compiler-rt/lib/scudo/standalone/{linux_common.h => report_linux.h} (56%)

diff --git a/compiler-rt/lib/scudo/standalone/CMakeLists.txt b/compiler-rt/lib/scudo/standalone/CMakeLists.txt
index 9738fb17d7f1241..723b3b472d1fb06 100644
--- a/compiler-rt/lib/scudo/standalone/CMakeLists.txt
+++ b/compiler-rt/lib/scudo/standalone/CMakeLists.txt
@@ -108,12 +108,12 @@ set(SCUDO_SOURCES
   flags.cpp
   fuchsia.cpp
   linux.cpp
-  linux_common.cpp
   mem_map.cpp
   mem_map_fuchsia.cpp
   mem_map_linux.cpp
   release.cpp
   report.cpp
+  report_linux.cpp
   string_utils.cpp
   timing.cpp
   )
diff --git a/compiler-rt/lib/scudo/standalone/linux.cpp b/compiler-rt/lib/scudo/standalone/linux.cpp
index 3e3b2147b3c77c1..c73020dba429fa1 100644
--- a/compiler-rt/lib/scudo/standalone/linux.cpp
+++ b/compiler-rt/lib/scudo/standalone/linux.cpp
@@ -13,8 +13,8 @@
 #include "common.h"
 #include "internal_defs.h"
 #include "linux.h"
-#include "linux_common.h"
 #include "mutex.h"
+#include "report_linux.h"
 #include "string_utils.h"
 
 #include <errno.h>
@@ -40,6 +40,8 @@
 
 namespace scudo {
 
+void NORETURN die() { abort(); }
+
 uptr getPageSize() { return static_cast<uptr>(sysconf(_SC_PAGESIZE)); }
 
 // TODO: Will be deprecated. Use the interfaces in MemMapLinux instead.
@@ -65,7 +67,7 @@ void *map(void *Addr, uptr Size, UNUSED const char *Name, uptr Flags,
   void *P = mmap(Addr, Size, MmapProt, MmapFlags, -1, 0);
   if (P == MAP_FAILED) {
     if (!(Flags & MAP_ALLOWNOMEM) || errno != ENOMEM)
-      dieOnMapError(errno == ENOMEM ? Size : 0);
+      reportMapError(errno == ENOMEM ? Size : 0);
     return nullptr;
   }
 #if SCUDO_ANDROID
@@ -79,7 +81,7 @@ void *map(void *Addr, uptr Size, UNUSED const char *Name, uptr Flags,
 void unmap(void *Addr, uptr Size, UNUSED uptr Flags,
            UNUSED MapPlatformData *Data) {
   if (munmap(Addr, Size) != 0)
-    dieOnUnmapError(reinterpret_cast<uptr>(Addr), Size);
+    reportUnmapError(reinterpret_cast<uptr>(Addr), Size);
 }
 
 // TODO: Will be deprecated. Use the interfaces in MemMapLinux instead.
@@ -87,7 +89,7 @@ void setMemoryPermission(uptr Addr, uptr Size, uptr Flags,
                          UNUSED MapPlatformData *Data) {
   int Prot = (Flags & MAP_NOACCESS) ? PROT_NONE : (PROT_READ | PROT_WRITE);
   if (mprotect(reinterpret_cast<void *>(Addr), Size, Prot) != 0)
-    dieOnProtectError(Addr, Size, Prot);
+    reportProtectError(Addr, Size, Prot);
 }
 
 // TODO: Will be deprecated. Use the interfaces in MemMapLinux instead.
diff --git a/compiler-rt/lib/scudo/standalone/mem_map_linux.cpp b/compiler-rt/lib/scudo/standalone/mem_map_linux.cpp
index 8e55599398b956b..783c4f0d9ab0f0d 100644
--- a/compiler-rt/lib/scudo/standalone/mem_map_linux.cpp
+++ b/compiler-rt/lib/scudo/standalone/mem_map_linux.cpp
@@ -15,8 +15,8 @@
 #include "common.h"
 #include "internal_defs.h"
 #include "linux.h"
-#include "linux_common.h"
 #include "mutex.h"
+#include "report_linux.h"
 #include "string_utils.h"
 
 #include <errno.h>
@@ -65,7 +65,7 @@ static void *mmapWrapper(uptr Addr, uptr Size, const char *Name, uptr Flags) {
       mmap(reinterpret_cast<void *>(Addr), Size, MmapProt, MmapFlags, -1, 0);
   if (P == MAP_FAILED) {
     if (!(Flags & MAP_ALLOWNOMEM) || errno != ENOMEM)
-      dieOnMapError(errno == ENOMEM ? Size : 0);
+      reportMapError(errno == ENOMEM ? Size : 0);
     return nullptr;
   }
 #if SCUDO_ANDROID
@@ -102,21 +102,21 @@ void MemMapLinux::unmapImpl(uptr Addr, uptr Size) {
   }
 
   if (munmap(reinterpret_cast<void *>(Addr), Size) != 0)
-    dieOnUnmapError(Addr, Size);
+    reportUnmapError(Addr, Size);
 }
 
 bool MemMapLinux::remapImpl(uptr Addr, uptr Size, const char *Name,
                             uptr Flags) {
   void *P = mmapWrapper(Addr, Size, Name, Flags);
   if (reinterpret_cast<uptr>(P) != Addr)
-    dieOnMapError();
+    reportMapError();
   return true;
 }
 
 void MemMapLinux::setMemoryPermissionImpl(uptr Addr, uptr Size, uptr Flags) {
   int Prot = (Flags & MAP_NOACCESS) ? PROT_NONE : (PROT_READ | PROT_WRITE);
   if (mprotect(reinterpret_cast<void *>(Addr), Size, Prot) != 0)
-    dieOnProtectError(Addr, Size, Prot);
+    reportProtectError(Addr, Size, Prot);
 }
 
 void MemMapLinux::releaseAndZeroPagesToOSImpl(uptr From, uptr Size) {
@@ -140,7 +140,7 @@ bool ReservedMemoryLinux::createImpl(uptr Addr, uptr Size, const char *Name,
 
 void ReservedMemoryLinux::releaseImpl() {
   if (munmap(reinterpret_cast<void *>(getBase()), getCapacity()) != 0)
-    dieOnUnmapError(getBase(), getCapacity());
+    reportUnmapError(getBase(), getCapacity());
 }
 
 ReservedMemoryLinux::MemMapT ReservedMemoryLinux::dispatchImpl(uptr Addr,
diff --git a/compiler-rt/lib/scudo/standalone/report.cpp b/compiler-rt/lib/scudo/standalone/report.cpp
index c033949a85f4b5a..34db3e7be3b08de 100644
--- a/compiler-rt/lib/scudo/standalone/report.cpp
+++ b/compiler-rt/lib/scudo/standalone/report.cpp
@@ -25,9 +25,7 @@ class ScopedErrorReport {
     va_end(Args);
   }
   NORETURN ~ScopedErrorReport() {
-    outputRaw(Message.data());
-    setAbortMessage(Message.data());
-    die();
+    reportRawError(Message.data());
   }
 
 private:
@@ -55,6 +53,13 @@ void NORETURN reportError(const char *Message) {
   Report.append("%s\n", Message);
 }
 
+// Generic fatal error message without ScopedString.
+void NORETURN reportRawError(const char *Message) {
+  outputRaw(Message);
+  setAbortMessage(Message);
+  die();
+}
+
 void NORETURN reportInvalidFlag(const char *FlagType, const char *Value) {
   ScopedErrorReport Report;
   Report.append("invalid value for %s option: '%s'\n", FlagType, Value);
diff --git a/compiler-rt/lib/scudo/standalone/report.h b/compiler-rt/lib/scudo/standalone/report.h
index d8c2dea994c1623..a510fdaebb6de54 100644
--- a/compiler-rt/lib/scudo/standalone/report.h
+++ b/compiler-rt/lib/scudo/standalone/report.h
@@ -15,9 +15,12 @@ namespace scudo {
 
 // Reports are *fatal* unless stated otherwise.
 
-// Generic error.
+// Generic error, adds newline to end of message.
 void NORETURN reportError(const char *Message);
 
+// Generic error, but the message is not modified.
+void NORETURN reportRawError(const char *Message);
+
 // Flags related errors.
 void NORETURN reportInvalidFlag(const char *FlagType, const char *Value);
 
diff --git a/compiler-rt/lib/scudo/standalone/linux_common.cpp b/compiler-rt/lib/scudo/standalone/report_linux.cpp
similarity index 77%
rename from compiler-rt/lib/scudo/standalone/linux_common.cpp
rename to compiler-rt/lib/scudo/standalone/report_linux.cpp
index d0e39fb0ced87e3..e76d68a3fd1bdcb 100644
--- a/compiler-rt/lib/scudo/standalone/linux_common.cpp
+++ b/compiler-rt/lib/scudo/standalone/report_linux.cpp
@@ -12,7 +12,8 @@
 
 #include "common.h"
 #include "internal_defs.h"
-#include "linux_common.h"
+#include "report.h"
+#include "report_linux.h"
 #include "string_utils.h"
 
 #include <errno.h>
@@ -21,10 +22,8 @@
 
 namespace scudo {
 
-void NORETURN die() { abort(); }
-
 // Fatal internal map() error (potentially OOM related).
-void NORETURN dieOnMapError(uptr SizeIfOOM) {
+void NORETURN reportMapError(uptr SizeIfOOM) {
   char Error[128] = "Scudo ERROR: internal map failure\n";
   if (SizeIfOOM) {
     formatString(
@@ -32,32 +31,26 @@ void NORETURN dieOnMapError(uptr SizeIfOOM) {
         "Scudo ERROR: internal map failure (NO MEMORY) requesting %zuKB\n",
         SizeIfOOM >> 10);
   }
-  outputRaw(Error);
-  setAbortMessage(Error);
-  die();
+  reportRawError(Error);
 }
 
-void NORETURN dieOnUnmapError(uptr Addr, uptr Size) {
+void NORETURN reportUnmapError(uptr Addr, uptr Size) {
   char Error[128];
   formatString(Error, sizeof(Error),
                "Scudo ERROR: internal unmap failure (error desc=%s) Addr 0x%zx "
                "Size %zu\n",
                strerror(errno), Addr, Size);
-  outputRaw(Error);
-  setAbortMessage(Error);
-  die();
+  reportRawError(Error);
 }
 
-void NORETURN dieOnProtectError(uptr Addr, uptr Size, int Prot) {
+void NORETURN reportProtectError(uptr Addr, uptr Size, int Prot) {
   char Error[128];
   formatString(
       Error, sizeof(Error),
       "Scudo ERROR: internal protect failure (error desc=%s) Addr 0x%zx "
       "Size %zu Prot %x\n",
       strerror(errno), Addr, Size, Prot);
-  outputRaw(Error);
-  setAbortMessage(Error);
-  die();
+  reportRawError(Error);
 }
 
 } // namespace scudo
diff --git a/compiler-rt/lib/scudo/standalone/linux_common.h b/compiler-rt/lib/scudo/standalone/report_linux.h
similarity index 56%
rename from compiler-rt/lib/scudo/standalone/linux_common.h
rename to compiler-rt/lib/scudo/standalone/report_linux.h
index 6a5c528a040168b..1ce725899f13040 100644
--- a/compiler-rt/lib/scudo/standalone/linux_common.h
+++ b/compiler-rt/lib/scudo/standalone/report_linux.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef SCUDO_LINUX_COMMON_H_
-#define SCUDO_LINUX_COMMON_H_
+#ifndef SCUDO_REPORT_LINUX_H_
+#define SCUDO_REPORT_LINUX_H_
 
 #include "platform.h"
 
@@ -17,18 +17,18 @@
 
 namespace scudo {
 
-// Internal map fatal error. This must not call map(). SizeIfOOM shall
+// Report a fatal error when a map call fails. SizeIfOOM shall
 // hold the requested size on an out-of-memory error, 0 otherwise.
-void NORETURN dieOnMapError(uptr SizeIfOOM = 0);
+void NORETURN reportMapError(uptr SizeIfOOM = 0);
 
-// Internal unmap fatal error. This must not call map().
-void NORETURN dieOnUnmapError(uptr Addr, uptr Size);
+// Report a fatal error when an unmap call fails.
+void NORETURN reportUnmapError(uptr Addr, uptr Size);
 
-// Internal protect fatal error. This must not call map().
-void NORETURN dieOnProtectError(uptr Addr, uptr Size, int Prot);
+// Report a fatal error when a mprotect call fails.
+void NORETURN reportProtectError(uptr Addr, uptr Size, int Prot);
 
 } // namespace scudo
 
 #endif // SCUDO_LINUX
 
-#endif // SCUDO_LINUX_COMMON_H_
+#endif // SCUDO_REPORT_LINUX_H_
diff --git a/compiler-rt/lib/scudo/standalone/trusty.cpp b/compiler-rt/lib/scudo/standalone/trusty.cpp
index daa72ba0c4bf3b1..e446074e8667c8f 100644
--- a/compiler-rt/lib/scudo/standalone/trusty.cpp
+++ b/compiler-rt/lib/scudo/standalone/trusty.cpp
@@ -11,8 +11,8 @@
 #if SCUDO_TRUSTY
 
 #include "common.h"
-#include "linux_common.h"
 #include "mutex.h"
+#include "report_linux.h"
 #include "trusty.h"
 
 #include <errno.h>           // for errno
@@ -27,6 +27,8 @@
 
 namespace scudo {
 
+void NORETURN die() { abort(); }
+
 uptr getPageSize() { return getauxval(AT_PAGESZ); }
 
 void *map(void *Addr, uptr Size, const char *Name, uptr Flags,
@@ -50,7 +52,7 @@ void *map(void *Addr, uptr Size, const char *Name, uptr Flags,
   if (IS_ERR(P)) {
     errno = lk_err_to_errno(PTR_ERR(P));
     if (!(Flags & MAP_ALLOWNOMEM) || errno != ENOMEM)
-      dieOnMapError(Size);
+      reportMapError(Size);
     return nullptr;
   }
 
@@ -60,7 +62,7 @@ void *map(void *Addr, uptr Size, const char *Name, uptr Flags,
 void unmap(UNUSED void *Addr, UNUSED uptr Size, UNUSED uptr Flags,
            UNUSED MapPlatformData *Data) {
   if (_trusty_munmap(Addr, Size) != 0)
-    dieOnUnmapError(Addr, Size);
+    reportUnmapError(Addr, Size);
 }
 
 void setMemoryPermission(UNUSED uptr Addr, UNUSED uptr Size, UNUSED uptr Flags,



More information about the llvm-commits mailing list