diff options
author | mvel <mvel@yandex-team.ru> | 2022-02-10 16:45:41 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:41 +0300 |
commit | 43f5a35593ebc9f6bcea619bb170394ea7ae468e (patch) | |
tree | e98df59de24d2ef7c77baed9f41e4875a2fef972 /util/system/protect.cpp | |
parent | bd30392c4cc92487950adc375c07adf52da1d592 (diff) | |
download | ydb-43f5a35593ebc9f6bcea619bb170394ea7ae468e.tar.gz |
Restoring authorship annotation for <mvel@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/system/protect.cpp')
-rw-r--r-- | util/system/protect.cpp | 94 |
1 files changed, 47 insertions, 47 deletions
diff --git a/util/system/protect.cpp b/util/system/protect.cpp index 615a8231bbe..bbb8d410dfb 100644 --- a/util/system/protect.cpp +++ b/util/system/protect.cpp @@ -1,66 +1,66 @@ -#include "protect.h" - -#include <util/generic/yexception.h> +#include "protect.h" + +#include <util/generic/yexception.h> #include <util/generic/string.h> -#include <util/stream/output.h> - -#include "yassert.h" - +#include <util/stream/output.h> + +#include "yassert.h" + #if defined(_unix_) || defined(_darwin_) #include <sys/mman.h> -#endif - -#ifdef _win_ +#endif + +#ifdef _win_ #include <Windows.h> -#endif - +#endif + static TString ModeToString(const EProtectMemory mode) { TString strMode; if (mode == PM_NONE) { - return "PM_NONE"; + return "PM_NONE"; } - + if (mode & PM_READ) { - strMode += "PM_READ|"; + strMode += "PM_READ|"; } if (mode & PM_WRITE) { - strMode += "PM_WRITE|"; + strMode += "PM_WRITE|"; } if (mode & PM_EXEC) { - strMode += "PM_EXEC|"; + strMode += "PM_EXEC|"; } return strMode.substr(0, strMode.size() - 1); -} - +} + void ProtectMemory(void* addr, const size_t length, const EProtectMemory mode) { Y_VERIFY(!(mode & ~(PM_READ | PM_WRITE | PM_EXEC)), "Invalid memory protection flag combination. "); - -#if defined(_unix_) || defined(_darwin_) - int mpMode = PROT_NONE; + +#if defined(_unix_) || defined(_darwin_) + int mpMode = PROT_NONE; if (mode & PM_READ) { - mpMode |= PROT_READ; + mpMode |= PROT_READ; } if (mode & PM_WRITE) { - mpMode |= PROT_WRITE; + mpMode |= PROT_WRITE; } if (mode & PM_EXEC) { - mpMode |= PROT_EXEC; + mpMode |= PROT_EXEC; } - // some old manpages for mprotect say 'const void* addr', but that's wrong + // some old manpages for mprotect say 'const void* addr', but that's wrong if (mprotect(addr, length, mpMode) == -1) { - ythrow TSystemError() << "Memory protection failed for mode " << ModeToString(mode) << ". "; + ythrow TSystemError() << "Memory protection failed for mode " << ModeToString(mode) << ". "; } -#endif - -#ifdef _win_ - DWORD mpMode = PAGE_NOACCESS; +#endif + +#ifdef _win_ + DWORD mpMode = PAGE_NOACCESS; // windows developers are not aware of bit flags :( - - /* - * It's unclear that we should NOT fail on Windows that does not support write-only - * memory protection. As we don't know, what behavior is more correct, we choose - * one of them. A discussion was here: REVIEW: 39725 - */ + + /* + * It's unclear that we should NOT fail on Windows that does not support write-only + * memory protection. As we don't know, what behavior is more correct, we choose + * one of them. A discussion was here: REVIEW: 39725 + */ switch (mode.ToBaseType()) { case PM_READ: mpMode = PAGE_READONLY; @@ -68,8 +68,8 @@ void ProtectMemory(void* addr, const size_t length, const EProtectMemory mode) { case PM_WRITE: mpMode = PAGE_READWRITE; break; // BUG: no write-only support - /*case PM_WRITE: - ythrow TSystemError() << "Write-only protection mode is not supported under Windows. ";*/ + /*case PM_WRITE: + ythrow TSystemError() << "Write-only protection mode is not supported under Windows. ";*/ case PM_READ | PM_WRITE: mpMode = PAGE_READWRITE; break; @@ -82,14 +82,14 @@ void ProtectMemory(void* addr, const size_t length, const EProtectMemory mode) { case PM_WRITE | PM_EXEC: mpMode = PAGE_EXECUTE_READWRITE; break; // BUG: no write-only support - /*case PM_WRITE | PM_EXEC: - ythrow TSystemError() << "Write-execute-only protection mode is not supported under Windows. ";*/ + /*case PM_WRITE | PM_EXEC: + ythrow TSystemError() << "Write-execute-only protection mode is not supported under Windows. ";*/ case PM_READ | PM_WRITE | PM_EXEC: mpMode = PAGE_EXECUTE_READWRITE; break; - } - DWORD oldMode = 0; - if (!VirtualProtect(addr, length, mpMode, &oldMode)) - ythrow TSystemError() << "Memory protection failed for mode " << ModeToString(mode) << ". "; -#endif -} + } + DWORD oldMode = 0; + if (!VirtualProtect(addr, length, mpMode, &oldMode)) + ythrow TSystemError() << "Memory protection failed for mode " << ModeToString(mode) << ". "; +#endif +} |