summaryrefslogtreecommitdiff
path: root/src/mongo/base
diff options
context:
space:
mode:
authorBilly Donahue <billy.donahue@mongodb.com>2022-03-15 02:35:13 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-03-16 01:41:26 +0000
commit4b4a334cf67eba2abaaca1854eac5a8a03bee3e7 (patch)
tree10e35337c0238e6ef410ebeaec548bb7592a234f /src/mongo/base
parent04d14e9675539103de563ffa250380538206ee93 (diff)
downloadmongo-4b4a334cf67eba2abaaca1854eac5a8a03bee3e7.tar.gz
SERVER-51770 add std::error_code functions to errno_util
Remove errnoWithPrefix, errnoAndDescription
Diffstat (limited to 'src/mongo/base')
-rw-r--r--src/mongo/base/secure_allocator.cpp35
1 files changed, 21 insertions, 14 deletions
diff --git a/src/mongo/base/secure_allocator.cpp b/src/mongo/base/secure_allocator.cpp
index 06a0187d695..47837cb5c7d 100644
--- a/src/mongo/base/secure_allocator.cpp
+++ b/src/mongo/base/secure_allocator.cpp
@@ -33,6 +33,7 @@
#include "mongo/base/secure_allocator.h"
+#include <fmt/format.h>
#include <memory>
#ifdef _WIN32
@@ -58,6 +59,11 @@ namespace mongo::secure_allocator_details {
namespace {
+std::string fmtError(StringData prefix) {
+ auto ec = lastSystemError();
+ return format(FMT_STRING("{}: {}"), prefix, errorMessage(ec));
+}
+
/**
* NOTE(jcarey): Why not new/delete?
*
@@ -74,7 +80,7 @@ namespace {
void EnablePrivilege(const wchar_t* name) {
LUID luid;
if (!LookupPrivilegeValueW(nullptr, name, &luid)) {
- auto str = errnoWithPrefix("Failed to LookupPrivilegeValue");
+ auto str = fmtError("Failed to LookupPrivilegeValue");
LOGV2_WARNING(23704, "{str}", "str"_attr = str);
return;
}
@@ -82,7 +88,7 @@ void EnablePrivilege(const wchar_t* name) {
// Get the access token for the current process.
HANDLE accessToken;
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &accessToken)) {
- auto str = errnoWithPrefix("Failed to OpenProcessToken");
+ auto str = fmtError("Failed to OpenProcessToken");
LOGV2_WARNING(23705, "{str}", "str"_attr = str);
return;
}
@@ -97,7 +103,7 @@ void EnablePrivilege(const wchar_t* name) {
if (!AdjustTokenPrivileges(
accessToken, false, &privileges, sizeof(privileges), nullptr, nullptr)) {
- auto str = errnoWithPrefix("Failed to AdjustTokenPrivileges");
+ auto str = fmtError("Failed to AdjustTokenPrivileges");
LOGV2_WARNING(23706, "{str}", "str"_attr = str);
}
@@ -133,7 +139,7 @@ void growWorkingSize(std::size_t bytes) {
stdx::lock_guard<stdx::mutex> lock(workingSizeMutex);
if (!GetProcessWorkingSetSize(GetCurrentProcess(), &minWorkingSetSize, &maxWorkingSetSize)) {
- auto str = errnoWithPrefix("Failed to GetProcessWorkingSetSize");
+ auto str = fmtError("Failed to GetProcessWorkingSetSize");
LOGV2_FATAL(40285, "{str}", "str"_attr = str);
}
@@ -147,7 +153,7 @@ void growWorkingSize(std::size_t bytes) {
maxWorkingSetSize,
QUOTA_LIMITS_HARDWS_MIN_ENABLE |
QUOTA_LIMITS_HARDWS_MAX_DISABLE)) {
- auto str = errnoWithPrefix("Failed to SetProcessWorkingSetSizeEx");
+ auto str = fmtError("Failed to SetProcessWorkingSetSizeEx");
LOGV2_FATAL(40286, "{str}", "str"_attr = str);
}
}
@@ -166,7 +172,7 @@ void* systemAllocate(std::size_t bytes) {
auto ptr = VirtualAlloc(nullptr, bytes, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
if (!ptr) {
- auto str = errnoWithPrefix("Failed to VirtualAlloc");
+ auto str = fmtError("Failed to VirtualAlloc");
LOGV2_FATAL(28835, "{str}", "str"_attr = str);
}
@@ -182,7 +188,7 @@ void* systemAllocate(std::size_t bytes) {
}
}
- auto str = errnoWithPrefix("Failed to VirtualLock");
+ auto str = fmtError("Failed to VirtualLock");
LOGV2_FATAL(28828, "{str}", "str"_attr = str);
}
@@ -191,14 +197,14 @@ void* systemAllocate(std::size_t bytes) {
void systemDeallocate(void* ptr, std::size_t bytes) {
if (VirtualUnlock(ptr, bytes) == 0) {
- auto str = errnoWithPrefix("Failed to VirtualUnlock");
+ auto str = fmtError("Failed to VirtualUnlock");
LOGV2_FATAL(28829, "{str}", "str"_attr = str);
}
// VirtualFree needs to take 0 as the size parameter for MEM_RELEASE
// (that's how the api works).
if (VirtualFree(ptr, 0, MEM_RELEASE) == 0) {
- auto str = errnoWithPrefix("Failed to VirtualFree");
+ auto str = fmtError("Failed to VirtualFree");
LOGV2_FATAL(28830, "{str}", "str"_attr = str);
}
}
@@ -237,14 +243,14 @@ void* systemAllocate(std::size_t bytes) {
mmap(nullptr, bytes, PROT_READ | PROT_WRITE, MAP_PRIVATE | MONGO_MAP_ANONYMOUS, -1, 0);
if (!ptr) {
- auto str = errnoWithPrefix("Failed to mmap");
+ auto str = fmtError("Failed to mmap");
LOGV2_FATAL(23714, "{str}", "str"_attr = str);
fassertFailed(28831);
}
if (mlock(ptr, bytes) != 0) {
const int err = errno;
- auto str = errnoWithPrefix(
+ auto str = fmtError(
"Failed to mlock: Cannot allocate locked memory. For more details see: "
"https://dochub.mongodb.org/core/cannot-allocate-locked-memory");
LOGV2_FATAL(23715, "{str}", "str"_attr = str, "errno"_attr = err);
@@ -267,16 +273,17 @@ void systemDeallocate(void* ptr, std::size_t bytes) {
#endif
if (munlock(ptr, bytes) != 0) {
+ auto str = fmtError("Failed to munlock");
LOGV2_FATAL(28833,
"{errnoWithPrefix_Failed_to_munlock}",
- "errnoWithPrefix_Failed_to_munlock"_attr =
- errnoWithPrefix("Failed to munlock"));
+ "errnoWithPrefix_Failed_to_munlock"_attr = str);
}
if (munmap(ptr, bytes) != 0) {
+ auto str = fmtError("Failed to munmap");
LOGV2_FATAL(28834,
"{errnoWithPrefix_Failed_to_munmap}",
- "errnoWithPrefix_Failed_to_munmap"_attr = errnoWithPrefix("Failed to munmap"));
+ "errnoWithPrefix_Failed_to_munmap"_attr = str);
}
}