diff options
author | kinan-sarmini <kinan-sarmini@yandex-team.ru> | 2022-02-10 16:51:47 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:51:47 +0300 |
commit | 3ceb84696d5141dce2da03d35b8040d6d932bb0c (patch) | |
tree | 0211c83d3394f9f5e194efe20114f7e8847b3f64 /util | |
parent | 0831cac87ab5748ed91187b7d1832aeebb854fc6 (diff) | |
download | ydb-3ceb84696d5141dce2da03d35b8040d6d932bb0c.tar.gz |
Restoring authorship annotation for <kinan-sarmini@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util')
-rw-r--r-- | util/system/filemap.cpp | 54 | ||||
-rw-r--r-- | util/system/filemap.h | 2 | ||||
-rw-r--r-- | util/system/filemap_ut.cpp | 20 |
3 files changed, 38 insertions, 38 deletions
diff --git a/util/system/filemap.cpp b/util/system/filemap.cpp index 7454a4cb94..100cef7389 100644 --- a/util/system/filemap.cpp +++ b/util/system/filemap.cpp @@ -19,7 +19,7 @@ #endif #define MAP_POPULATE 0 #endif - + #if !defined(_freebsd_) #ifdef MAP_NOCORE #error unlisted platform supporting MAP_NOCORE @@ -79,29 +79,29 @@ static inline i64 DownToGranularity(i64 offset) noexcept { return offset & ~((i64)(GRANULARITY - 1)); } -#if defined(_unix_) -static int ModeToMmapFlags(TMemoryMapCommon::EOpenMode mode) { - int flags = MAP_NOCORE; - if ((mode & TMemoryMapCommon::oAccessMask) == TMemoryMapCommon::oCopyOnWr) { - flags |= MAP_PRIVATE; - } else { - flags |= MAP_SHARED; - } - if (mode & TMemoryMapCommon::oPopulate) { - flags |= MAP_POPULATE; - } - return flags; -} - -static int ModeToMmapProt(TMemoryMapCommon::EOpenMode mode) { - int prot = PROT_READ; - if ((mode & TMemoryMapCommon::oAccessMask) != TMemoryMapCommon::oRdOnly) { - prot |= PROT_WRITE; - } - return prot; -} -#endif - +#if defined(_unix_) +static int ModeToMmapFlags(TMemoryMapCommon::EOpenMode mode) { + int flags = MAP_NOCORE; + if ((mode & TMemoryMapCommon::oAccessMask) == TMemoryMapCommon::oCopyOnWr) { + flags |= MAP_PRIVATE; + } else { + flags |= MAP_SHARED; + } + if (mode & TMemoryMapCommon::oPopulate) { + flags |= MAP_POPULATE; + } + return flags; +} + +static int ModeToMmapProt(TMemoryMapCommon::EOpenMode mode) { + int prot = PROT_READ; + if ((mode & TMemoryMapCommon::oAccessMask) != TMemoryMapCommon::oRdOnly) { + prot |= PROT_WRITE; + } + return prot; +} +#endif + // maybe we should move this function to another .cpp file to avoid unwanted optimization? void NPrivate::Precharge(const void* data, size_t dataSize, size_t off, size_t size) { if (off > dataSize) { @@ -141,8 +141,8 @@ public: } #elif defined(_unix_) if (!(Mode_ & oNotGreedy)) { - PtrStart_ = mmap((caddr_t) nullptr, Length_, ModeToMmapProt(Mode_), ModeToMmapFlags(Mode_), File_.GetHandle(), 0); - + PtrStart_ = mmap((caddr_t) nullptr, Length_, ModeToMmapProt(Mode_), ModeToMmapFlags(Mode_), File_.GetHandle(), 0); + if ((MAP_FAILED == PtrStart_) && Length_) { ythrow yexception() << "Can't map " << (unsigned long)Length_ << " bytes of file '" << DbgName_ << "' at offset 0: " << LastSystemErrorText(); } @@ -244,7 +244,7 @@ public: #if defined(_unix_) if (Mode_ & oNotGreedy) { #endif - result.Ptr = mmap((caddr_t) nullptr, size, ModeToMmapProt(Mode_), ModeToMmapFlags(Mode_), File_.GetHandle(), base); + result.Ptr = mmap((caddr_t) nullptr, size, ModeToMmapProt(Mode_), ModeToMmapFlags(Mode_), File_.GetHandle(), base); if (result.Ptr == (char*)(-1)) { result.Ptr = nullptr; diff --git a/util/system/filemap.h b/util/system/filemap.h index 11be64bff4..6b820824b2 100644 --- a/util/system/filemap.h +++ b/util/system/filemap.h @@ -56,7 +56,7 @@ struct TMemoryMapCommon { oAccessMask = 7, oNotGreedy = 8, oPrecharge = 16, - oPopulate = 32, // Populate page table entries (see mmap's MAP_POPULATE) + oPopulate = 32, // Populate page table entries (see mmap's MAP_POPULATE) }; Y_DECLARE_FLAGS(EOpenMode, EOpenModeFlag) diff --git a/util/system/filemap_ut.cpp b/util/system/filemap_ut.cpp index 73f109dc88..a42af17fb9 100644 --- a/util/system/filemap_ut.cpp +++ b/util/system/filemap_ut.cpp @@ -14,7 +14,7 @@ Y_UNIT_TEST_SUITE(TFileMapTest) { static const char* FileName_("./mappped_file"); - void BasicTest(TMemoryMapCommon::EOpenMode mode) { + void BasicTest(TMemoryMapCommon::EOpenMode mode) { char data[] = "abcdefgh"; TFile file(FileName_, CreateAlways | WrOnly); @@ -22,7 +22,7 @@ Y_UNIT_TEST_SUITE(TFileMapTest) { file.Close(); { - TFileMap mappedFile(FileName_, mode); + TFileMap mappedFile(FileName_, mode); mappedFile.Map(0, mappedFile.Length()); UNIT_ASSERT(mappedFile.MappedSize() == sizeof(data) && mappedFile.Length() == sizeof(data)); UNIT_ASSERT(mappedFile.IsOpen()); @@ -51,14 +51,14 @@ Y_UNIT_TEST_SUITE(TFileMapTest) { NFs::Remove(FileName_); } - Y_UNIT_TEST(TestFileMap) { - BasicTest(TMemoryMapCommon::oRdWr); - } - - Y_UNIT_TEST(TestFileMapPopulate) { - BasicTest(TMemoryMapCommon::oRdWr | TMemoryMapCommon::oPopulate); - } - + Y_UNIT_TEST(TestFileMap) { + BasicTest(TMemoryMapCommon::oRdWr); + } + + Y_UNIT_TEST(TestFileMapPopulate) { + BasicTest(TMemoryMapCommon::oRdWr | TMemoryMapCommon::oPopulate); + } + Y_UNIT_TEST(TestFileRemap) { const char data1[] = "01234"; const char data2[] = "abcdefg"; |