aboutsummaryrefslogtreecommitdiffstats
path: root/util/system/protect.cpp
diff options
context:
space:
mode:
authorAnton Samokhvalov <pg83@yandex.ru>2022-02-10 16:45:15 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:15 +0300
commit72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch)
treeda2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /util/system/protect.cpp
parent778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff)
downloadydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'util/system/protect.cpp')
-rw-r--r--util/system/protect.cpp80
1 files changed, 40 insertions, 40 deletions
diff --git a/util/system/protect.cpp b/util/system/protect.cpp
index bbb8d410df..1d4ce2b614 100644
--- a/util/system/protect.cpp
+++ b/util/system/protect.cpp
@@ -6,29 +6,29 @@
#include "yassert.h"
-#if defined(_unix_) || defined(_darwin_)
- #include <sys/mman.h>
+#if defined(_unix_) || defined(_darwin_)
+ #include <sys/mman.h>
#endif
#ifdef _win_
- #include <Windows.h>
+ #include <Windows.h>
#endif
static TString ModeToString(const EProtectMemory mode) {
TString strMode;
- if (mode == PM_NONE) {
+ if (mode == PM_NONE) {
return "PM_NONE";
- }
+ }
- if (mode & PM_READ) {
+ if (mode & PM_READ) {
strMode += "PM_READ|";
- }
- if (mode & PM_WRITE) {
+ }
+ if (mode & PM_WRITE) {
strMode += "PM_WRITE|";
- }
- if (mode & PM_EXEC) {
+ }
+ if (mode & PM_EXEC) {
strMode += "PM_EXEC|";
- }
+ }
return strMode.substr(0, strMode.size() - 1);
}
@@ -37,19 +37,19 @@ void ProtectMemory(void* addr, const size_t length, const EProtectMemory mode) {
#if defined(_unix_) || defined(_darwin_)
int mpMode = PROT_NONE;
- if (mode & PM_READ) {
+ if (mode & PM_READ) {
mpMode |= PROT_READ;
- }
- if (mode & PM_WRITE) {
+ }
+ if (mode & PM_WRITE) {
mpMode |= PROT_WRITE;
- }
- if (mode & PM_EXEC) {
+ }
+ if (mode & PM_EXEC) {
mpMode |= PROT_EXEC;
- }
+ }
// some old manpages for mprotect say 'const void* addr', but that's wrong
- if (mprotect(addr, length, mpMode) == -1) {
+ if (mprotect(addr, length, mpMode) == -1) {
ythrow TSystemError() << "Memory protection failed for mode " << ModeToString(mode) << ". ";
- }
+ }
#endif
#ifdef _win_
@@ -62,31 +62,31 @@ void ProtectMemory(void* addr, const size_t length, const EProtectMemory mode) {
* one of them. A discussion was here: REVIEW: 39725
*/
switch (mode.ToBaseType()) {
- case PM_READ:
- mpMode = PAGE_READONLY;
- break;
- case PM_WRITE:
- mpMode = PAGE_READWRITE;
- break; // BUG: no write-only support
+ case PM_READ:
+ mpMode = PAGE_READONLY;
+ break;
+ 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_READ | PM_WRITE:
- mpMode = PAGE_READWRITE;
- break;
- case PM_EXEC:
- mpMode = PAGE_EXECUTE;
- break;
- case PM_READ | PM_EXEC:
- mpMode = PAGE_EXECUTE_READ;
- break;
- case PM_WRITE | PM_EXEC:
- mpMode = PAGE_EXECUTE_READWRITE;
- break; // BUG: no write-only support
+ case PM_READ | PM_WRITE:
+ mpMode = PAGE_READWRITE;
+ break;
+ case PM_EXEC:
+ mpMode = PAGE_EXECUTE;
+ break;
+ case PM_READ | PM_EXEC:
+ mpMode = PAGE_EXECUTE_READ;
+ break;
+ 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_READ | PM_WRITE | PM_EXEC:
- mpMode = PAGE_EXECUTE_READWRITE;
- break;
+ case PM_READ | PM_WRITE | PM_EXEC:
+ mpMode = PAGE_EXECUTE_READWRITE;
+ break;
}
DWORD oldMode = 0;
if (!VirtualProtect(addr, length, mpMode, &oldMode))