diff options
author | Christopher Ferris <cferris1000@users.noreply.github.com> | 2024-04-05 14:25:39 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2024-04-05 14:32:06 -0700 |
commit | 4de720a30d7cd35d15d2802b8ed20374e7b50230 (patch) | |
tree | c41778deb4e1cadba4cf47ff6a0a266c67a25aa3 | |
parent | 9e8419f58721f02bdc7db58ca98b2e7c17880f8d (diff) | |
download | scudo-4de720a30d7cd35d15d2802b8ed20374e7b50230.tar.gz |
[scudo] Add errno description to mmap failure. (#87713)
Added unit tests for all of the linux report error functions.
GitOrigin-RevId: 0a39f1a7e5c7fd00b37231964ec81dae938948e7
Change-Id: Ieea9cecbe6dcf6aff9d65392b220583a1a2504e4
-rw-r--r-- | standalone/report_linux.cpp | 8 | ||||
-rw-r--r-- | standalone/tests/report_test.cpp | 25 |
2 files changed, 29 insertions, 4 deletions
diff --git a/standalone/report_linux.cpp b/standalone/report_linux.cpp index dfddef3324b..432f6a01696 100644 --- a/standalone/report_linux.cpp +++ b/standalone/report_linux.cpp @@ -25,10 +25,10 @@ namespace scudo { // Fatal internal map() error (potentially OOM related). void NORETURN reportMapError(uptr SizeIfOOM) { ScopedString Error; - Error.append("Scudo ERROR: internal map failure"); - if (SizeIfOOM) { - Error.append(" (NO MEMORY) requesting %zuKB", SizeIfOOM >> 10); - } + Error.append("Scudo ERROR: internal map failure (error desc=%s)", + strerror(errno)); + if (SizeIfOOM) + Error.append(" requesting %zuKB", SizeIfOOM >> 10); Error.append("\n"); reportRawError(Error.data()); } diff --git a/standalone/tests/report_test.cpp b/standalone/tests/report_test.cpp index 92f1ee81303..2c790247a2f 100644 --- a/standalone/tests/report_test.cpp +++ b/standalone/tests/report_test.cpp @@ -53,3 +53,28 @@ TEST(ScudoReportDeathTest, CSpecific) { EXPECT_DEATH(scudo::reportInvalidAlignedAllocAlignment(123, 456), "Scudo ERROR.*123.*456"); } + +#if SCUDO_LINUX || SCUDO_TRUSTY || SCUDO_ANDROID +#include "report_linux.h" + +#include <errno.h> +#include <sys/mman.h> + +TEST(ScudoReportDeathTest, Linux) { + errno = ENOMEM; + EXPECT_DEATH(scudo::reportMapError(), + "Scudo ERROR:.*internal map failure \\(error desc=.*\\)\\s*$"); + errno = ENOMEM; + EXPECT_DEATH(scudo::reportMapError(1024U), + "Scudo ERROR:.*internal map failure \\(error desc=.*\\) " + "requesting 1KB\\s*$"); + errno = ENOMEM; + EXPECT_DEATH(scudo::reportUnmapError(0x1000U, 100U), + "Scudo ERROR:.*internal unmap failure \\(error desc=.*\\) Addr " + "0x1000 Size 100\\s*$"); + errno = ENOMEM; + EXPECT_DEATH(scudo::reportProtectError(0x1000U, 100U, PROT_READ), + "Scudo ERROR:.*internal protect failure \\(error desc=.*\\) " + "Addr 0x1000 Size 100 Prot 1\\s*$"); +} +#endif |