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 | |
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')
-rw-r--r-- | util/system/compiler.h | 2 | ||||
-rw-r--r-- | util/system/datetime.h | 16 | ||||
-rw-r--r-- | util/system/direct_io_ut.cpp | 14 | ||||
-rw-r--r-- | util/system/env.cpp | 26 | ||||
-rw-r--r-- | util/system/env.h | 6 | ||||
-rw-r--r-- | util/system/env_ut.cpp | 6 | ||||
-rw-r--r-- | util/system/execpath.h | 2 | ||||
-rw-r--r-- | util/system/file_lock.cpp | 24 | ||||
-rw-r--r-- | util/system/file_lock.h | 14 | ||||
-rw-r--r-- | util/system/filemap.cpp | 2 | ||||
-rw-r--r-- | util/system/filemap.h | 86 | ||||
-rw-r--r-- | util/system/filemap_ut.cpp | 96 | ||||
-rw-r--r-- | util/system/flock.h | 6 | ||||
-rw-r--r-- | util/system/flock_ut.cpp | 14 | ||||
-rw-r--r-- | util/system/fstat.cpp | 28 | ||||
-rw-r--r-- | util/system/fstat.h | 14 | ||||
-rw-r--r-- | util/system/info.cpp | 6 | ||||
-rw-r--r-- | util/system/platform.h | 192 | ||||
-rw-r--r-- | util/system/protect.cpp | 94 | ||||
-rw-r--r-- | util/system/protect.h | 30 | ||||
-rw-r--r-- | util/system/shellcommand.cpp | 12 | ||||
-rw-r--r-- | util/system/shellcommand.h | 10 | ||||
-rw-r--r-- | util/system/shellcommand_ut.cpp | 4 |
23 files changed, 352 insertions, 352 deletions
diff --git a/util/system/compiler.h b/util/system/compiler.h index 95a67945d7..b373edcc46 100644 --- a/util/system/compiler.h +++ b/util/system/compiler.h @@ -287,7 +287,7 @@ _YandexAbort(); #endif #else - + #if defined(thread_sanitizer_enabled) || defined(__SANITIZE_THREAD__) #define _tsan_enabled_ #endif diff --git a/util/system/datetime.h b/util/system/datetime.h index d3982a047c..aa009974e0 100644 --- a/util/system/datetime.h +++ b/util/system/datetime.h @@ -17,14 +17,14 @@ /// Current time in microseconds since epoch ui64 MicroSeconds() noexcept; -/// Current time in milliseconds since epoch -inline ui64 MilliSeconds() { - return MicroSeconds() / ui64(1000); -} -/// Current time in milliseconds since epoch (deprecated, use MilliSeconds instead) -inline ui64 millisec() { - return MilliSeconds(); -} +/// Current time in milliseconds since epoch +inline ui64 MilliSeconds() { + return MicroSeconds() / ui64(1000); +} +/// Current time in milliseconds since epoch (deprecated, use MilliSeconds instead) +inline ui64 millisec() { + return MilliSeconds(); +} /// Current time in seconds since epoch ui32 Seconds() noexcept; ///Current thread time in microseconds diff --git a/util/system/direct_io_ut.cpp b/util/system/direct_io_ut.cpp index a3c56fbd96..839c3de7ca 100644 --- a/util/system/direct_io_ut.cpp +++ b/util/system/direct_io_ut.cpp @@ -23,19 +23,19 @@ Y_UNIT_TEST_SUITE(TDirectIoTestSuite) { writePos += writeCount; size_t readPos = RandomNumber(writePos); size_t readCount = RandomNumber(writePos - readPos); - UNIT_ASSERT_VALUES_EQUAL( + UNIT_ASSERT_VALUES_EQUAL( file.Pread(&readResult[0], readCount * sizeof(ui64), readPos * sizeof(ui64)), readCount * sizeof(ui64)); - for (size_t i = 0; i < readCount; ++i) { + for (size_t i = 0; i < readCount; ++i) { UNIT_ASSERT_VALUES_EQUAL(readResult[i], data[i + readPos]); - } + } } file.Finish(); TDirectIOBufferedFile fileNew(FileName_, RdOnly | Direct | Seq | OpenAlways, 1 << 15); for (int i = 0; i < 1000; ++i) { size_t readPos = RandomNumber(data.size()); size_t readCount = RandomNumber(data.size() - readPos); - UNIT_ASSERT_VALUES_EQUAL( + UNIT_ASSERT_VALUES_EQUAL( fileNew.Pread(&readResult[0], readCount * sizeof(ui64), readPos * sizeof(ui64)), readCount * sizeof(ui64)); for (size_t j = 0; j < readCount; ++j) { @@ -43,12 +43,12 @@ Y_UNIT_TEST_SUITE(TDirectIoTestSuite) { } } size_t readCount = data.size(); - UNIT_ASSERT_VALUES_EQUAL( + UNIT_ASSERT_VALUES_EQUAL( fileNew.Pread(&readResult[0], readCount * sizeof(ui64), 0), readCount * sizeof(ui64)); - for (size_t i = 0; i < readCount; ++i) { + for (size_t i = 0; i < readCount; ++i) { UNIT_ASSERT_VALUES_EQUAL(readResult[i], data[i]); - } + } NFs::Remove(FileName_); } diff --git a/util/system/env.cpp b/util/system/env.cpp index edc539a702..ead9b566a5 100644 --- a/util/system/env.cpp +++ b/util/system/env.cpp @@ -1,8 +1,8 @@ -#include "env.h" - +#include "env.h" + #include <util/generic/string.h> #include <util/generic/yexception.h> - + #ifdef _win_ #include <util/generic/vector.h> #include "winint.h" @@ -10,7 +10,7 @@ #include <cerrno> #include <cstdlib> #endif - + /** * On Windows there may be many copies of enviroment variables, there at least two known, one is * manipulated by Win32 API, another by C runtime, so we must be consistent in the choice of @@ -22,7 +22,7 @@ */ TString GetEnv(const TString& key, const TString& def) { -#ifdef _win_ +#ifdef _win_ size_t len = GetEnvironmentVariableA(key.data(), nullptr, 0); if (len == 0) { @@ -43,25 +43,25 @@ TString GetEnv(const TString& key, const TString& def) { } while (len > bufferSize); return TString(buffer.data(), len); -#else +#else const char* env = getenv(key.data()); return env ? TString(env) : def; -#endif -} - +#endif +} + void SetEnv(const TString& key, const TString& value) { bool isOk = false; int errorCode = 0; -#ifdef _win_ +#ifdef _win_ isOk = SetEnvironmentVariable(key.data(), value.data()); if (!isOk) { errorCode = GetLastError(); } -#else +#else isOk = (0 == setenv(key.data(), value.data(), true /*replace*/)); if (!isOk) { errorCode = errno; } -#endif +#endif Y_ENSURE_EX(isOk, TSystemError() << "failed to SetEnv with error-code " << errorCode); -} +} diff --git a/util/system/env.h b/util/system/env.h index 6af09425be..e2ccdd1e95 100644 --- a/util/system/env.h +++ b/util/system/env.h @@ -1,7 +1,7 @@ -#pragma once - +#pragma once + #include <util/generic/string.h> - + /** * Search the environment list provided by the host environment for associated variable. * diff --git a/util/system/env_ut.cpp b/util/system/env_ut.cpp index 32e3a39956..e03cc01658 100644 --- a/util/system/env_ut.cpp +++ b/util/system/env_ut.cpp @@ -1,8 +1,8 @@ #include <library/cpp/testing/unittest/registar.h> - + #include <util/generic/string.h> #include "env.h" - + Y_UNIT_TEST_SUITE(EnvTest) { Y_UNIT_TEST(GetSetEnvTest) { TString key = "util_GETENV_TestVar"; @@ -28,4 +28,4 @@ Y_UNIT_TEST_SUITE(EnvTest) { SetEnv(longKey, TString()); UNIT_ASSERT_VALUES_EQUAL(GetEnv(longKey), TString()); } -} +} diff --git a/util/system/execpath.h b/util/system/execpath.h index 5c476042c7..4b914b8e85 100644 --- a/util/system/execpath.h +++ b/util/system/execpath.h @@ -2,7 +2,7 @@ #include <util/generic/fwd.h> -// NOTE: This function has rare sporadic failures (throws exceptions) on FreeBSD. See REVIEW:54297 +// NOTE: This function has rare sporadic failures (throws exceptions) on FreeBSD. See REVIEW:54297 const TString& GetExecPath(); /** diff --git a/util/system/file_lock.cpp b/util/system/file_lock.cpp index 55160d287f..45d91282c5 100644 --- a/util/system/file_lock.cpp +++ b/util/system/file_lock.cpp @@ -1,8 +1,8 @@ -#include "file_lock.h" +#include "file_lock.h" #include "flock.h" - + #include <util/generic/yexception.h> - + #include <cerrno> namespace { @@ -22,13 +22,13 @@ namespace { TFileLock::TFileLock(const TString& filename, const EFileLockType type) : TFile(filename, OpenAlways | RdOnly) , Type(type) -{ -} - -void TFileLock::Acquire() { +{ +} + +void TFileLock::Acquire() { Flock(GetMode(Type)); -} - +} + bool TFileLock::TryAcquire() { try { Flock(GetMode(Type) | LOCK_NB); @@ -41,6 +41,6 @@ bool TFileLock::TryAcquire() { } } -void TFileLock::Release() { - Flock(LOCK_UN); -} +void TFileLock::Release() { + Flock(LOCK_UN); +} diff --git a/util/system/file_lock.h b/util/system/file_lock.h index ac3f95306f..b2aaff5baf 100644 --- a/util/system/file_lock.h +++ b/util/system/file_lock.h @@ -1,9 +1,9 @@ -#pragma once - +#pragma once + #include <util/generic/fwd.h> -#include <util/generic/noncopyable.h> +#include <util/generic/noncopyable.h> #include <util/system/file.h> - + enum class EFileLockType { Exclusive, Shared @@ -13,9 +13,9 @@ class TFileLock: public TFile { public: TFileLock(const TString& filename, const EFileLockType type = EFileLockType::Exclusive); - void Acquire(); + void Acquire(); bool TryAcquire(); - void Release(); + void Release(); inline void lock() { Acquire(); @@ -31,4 +31,4 @@ public: private: EFileLockType Type; -}; +}; diff --git a/util/system/filemap.cpp b/util/system/filemap.cpp index cfab1b6aca..7454a4cb94 100644 --- a/util/system/filemap.cpp +++ b/util/system/filemap.cpp @@ -74,7 +74,7 @@ namespace { TString TMemoryMapCommon::UnknownFileName() { return "Unknown_file_name"; } - + static inline i64 DownToGranularity(i64 offset) noexcept { return offset & ~((i64)(GRANULARITY - 1)); } diff --git a/util/system/filemap.h b/util/system/filemap.h index a6e97dabaf..11be64bff4 100644 --- a/util/system/filemap.h +++ b/util/system/filemap.h @@ -59,8 +59,8 @@ struct TMemoryMapCommon { oPopulate = 32, // Populate page table entries (see mmap's MAP_POPULATE) }; Y_DECLARE_FLAGS(EOpenMode, EOpenModeFlag) - - /** + + /** * Name that will be printed in exceptions if not specified. * Overridden by name obtained from `TFile` if it's not empty. */ @@ -184,16 +184,16 @@ private: }; template <class T> -class TFileMappedArray { -private: - const T* Ptr_; - const T* End_; +class TFileMappedArray { +private: + const T* Ptr_; + const T* End_; size_t Size_; char DummyData_[sizeof(T) + PLATFORM_DATA_ALIGN]; mutable THolder<T, TDestructor> Dummy_; - THolder<TFileMap> DataHolder_; + THolder<TFileMap> DataHolder_; -public: +public: TFileMappedArray() : Ptr_(nullptr) , End_(nullptr) @@ -204,34 +204,34 @@ public: Ptr_ = nullptr; End_ = nullptr; } - void Init(const char* name) { - DataHolder_.Reset(new TFileMap(name)); - DoInit(name); + void Init(const char* name) { + DataHolder_.Reset(new TFileMap(name)); + DoInit(name); + } + void Init(const TFileMap& fileMap) { + DataHolder_.Reset(new TFileMap(fileMap)); + DoInit(fileMap.GetFile().GetName()); } - void Init(const TFileMap& fileMap) { - DataHolder_.Reset(new TFileMap(fileMap)); - DoInit(fileMap.GetFile().GetName()); - } - void Term() { - DataHolder_.Destroy(); + void Term() { + DataHolder_.Destroy(); Ptr_ = nullptr; Size_ = 0; End_ = nullptr; } - void Precharge() { - DataHolder_->Precharge(); - } + void Precharge() { + DataHolder_->Precharge(); + } const T& operator[](size_t pos) const { Y_ASSERT(pos < size()); return Ptr_[pos]; } - /// for STL compatibility only, Size() usage is recommended + /// for STL compatibility only, Size() usage is recommended size_t size() const { return Size_; } - size_t Size() const { - return Size_; - } + size_t Size() const { + return Size_; + } const T& GetAt(size_t pos) const { if (pos < Size_) return Ptr_[pos]; @@ -251,40 +251,40 @@ public: return *Dummy_; } - /// for STL compatibility only, Empty() usage is recommended + /// for STL compatibility only, Empty() usage is recommended Y_PURE_FUNCTION bool empty() const noexcept { - return Empty(); - } + return Empty(); + } Y_PURE_FUNCTION bool Empty() const noexcept { return 0 == Size_; } - /// for STL compatibility only, Begin() usage is recommended + /// for STL compatibility only, Begin() usage is recommended const T* begin() const noexcept { - return Begin(); - } + return Begin(); + } const T* Begin() const noexcept { return Ptr_; } - /// for STL compatibility only, End() usage is recommended + /// for STL compatibility only, End() usage is recommended const T* end() const noexcept { return End_; } const T* End() const noexcept { - return End_; - } + return End_; + } -private: +private: void DoInit(const TString& fileName) { - DataHolder_->Map(0, DataHolder_->Length()); - if (DataHolder_->Length() % sizeof(T)) { - Term(); - ythrow yexception() << "Incorrect size of file " << fileName.Quote(); - } - Ptr_ = (const T*)DataHolder_->Ptr(); - Size_ = DataHolder_->Length() / sizeof(T); - End_ = Ptr_ + Size_; - } + DataHolder_->Map(0, DataHolder_->Length()); + if (DataHolder_->Length() % sizeof(T)) { + Term(); + ythrow yexception() << "Incorrect size of file " << fileName.Quote(); + } + Ptr_ = (const T*)DataHolder_->Ptr(); + Size_ = DataHolder_->Length() / sizeof(T); + End_ = Ptr_ + Size_; + } }; class TMappedAllocation: TMoveOnly { diff --git a/util/system/filemap_ut.cpp b/util/system/filemap_ut.cpp index 62755f7547..73f109dc88 100644 --- a/util/system/filemap_ut.cpp +++ b/util/system/filemap_ut.cpp @@ -12,7 +12,7 @@ #include <cstdio> Y_UNIT_TEST_SUITE(TFileMapTest) { - static const char* FileName_("./mappped_file"); + static const char* FileName_("./mappped_file"); void BasicTest(TMemoryMapCommon::EOpenMode mode) { char data[] = "abcdefgh"; @@ -132,7 +132,7 @@ Y_UNIT_TEST_SUITE(TFileMapTest) { //cygwin is not real unix :( #else Y_UNIT_TEST(TestNotGreedy) { - unsigned page[4096 / sizeof(unsigned)]; + unsigned page[4096 / sizeof(unsigned)]; #if defined(_unix_) // Temporary limit allowed virtual memory size to 1Gb @@ -221,49 +221,49 @@ Y_UNIT_TEST_SUITE(TFileMapTest) { file.Write(static_cast<void*>(data), sizeof(data)); file.Close(); - mappedArray.Init(FileName_); - // actual test begin - UNIT_ASSERT(mappedArray.Size() == sz); + mappedArray.Init(FileName_); + // actual test begin + UNIT_ASSERT(mappedArray.Size() == sz); for (size_t i = 0; i < sz; ++i) { UNIT_ASSERT(mappedArray[i] == data[i]); } - - UNIT_ASSERT(mappedArray.GetAt(mappedArray.Size()) == 0); - UNIT_ASSERT(*mappedArray.Begin() == data[0]); - UNIT_ASSERT(size_t(mappedArray.End() - mappedArray.Begin()) == sz); - UNIT_ASSERT(!mappedArray.Empty()); - // actual test end - mappedArray.Term(); - - // Init array via file mapping - TFileMap fileMap(FileName_); - fileMap.Map(0, fileMap.Length()); - mappedArray.Init(fileMap); - - // actual test begin - UNIT_ASSERT(mappedArray.Size() == sz); + + UNIT_ASSERT(mappedArray.GetAt(mappedArray.Size()) == 0); + UNIT_ASSERT(*mappedArray.Begin() == data[0]); + UNIT_ASSERT(size_t(mappedArray.End() - mappedArray.Begin()) == sz); + UNIT_ASSERT(!mappedArray.Empty()); + // actual test end + mappedArray.Term(); + + // Init array via file mapping + TFileMap fileMap(FileName_); + fileMap.Map(0, fileMap.Length()); + mappedArray.Init(fileMap); + + // actual test begin + UNIT_ASSERT(mappedArray.Size() == sz); for (size_t i = 0; i < sz; ++i) { - UNIT_ASSERT(mappedArray[i] == data[i]); + UNIT_ASSERT(mappedArray[i] == data[i]); } - - UNIT_ASSERT(mappedArray.GetAt(mappedArray.Size()) == 0); - UNIT_ASSERT(*mappedArray.Begin() == data[0]); - UNIT_ASSERT(size_t(mappedArray.End() - mappedArray.Begin()) == sz); - UNIT_ASSERT(!mappedArray.Empty()); - // actual test end - + + UNIT_ASSERT(mappedArray.GetAt(mappedArray.Size()) == 0); + UNIT_ASSERT(*mappedArray.Begin() == data[0]); + UNIT_ASSERT(size_t(mappedArray.End() - mappedArray.Begin()) == sz); + UNIT_ASSERT(!mappedArray.Empty()); + // actual test end + file = TFile(FileName_, WrOnly); file.Seek(0, sEnd); file.Write("x", 1); file.Close(); - bool caught = false; + bool caught = false; try { - mappedArray.Init(FileName_); + mappedArray.Init(FileName_); } catch (const yexception&) { - caught = true; + caught = true; } - UNIT_ASSERT(caught); + UNIT_ASSERT(caught); } NFs::Remove(FileName_); } @@ -291,32 +291,32 @@ Y_UNIT_TEST_SUITE(TFileMapTest) { } Y_UNIT_TEST(TestMemoryMap) { - TFile file(FileName_, CreateAlways | WrOnly); - file.Close(); - - FILE* f = fopen(FileName_, "rb"); + TFile file(FileName_, CreateAlways | WrOnly); + file.Close(); + + FILE* f = fopen(FileName_, "rb"); UNIT_ASSERT(f != nullptr); - try { - TMemoryMap mappedMem(f); - mappedMem.Map(mappedMem.Length() / 2, mappedMem.Length() + 100); // overflow + try { + TMemoryMap mappedMem(f); + mappedMem.Map(mappedMem.Length() / 2, mappedMem.Length() + 100); // overflow UNIT_ASSERT(0); // should not go here } catch (yexception& exc) { TString text = exc.what(); // exception should contain failed file name UNIT_ASSERT(text.find(TMemoryMapCommon::UnknownFileName()) != TString::npos); - fclose(f); - } - - TFile fileForMap(FileName_, OpenExisting); - try { - TMemoryMap mappedMem(fileForMap); - mappedMem.Map(mappedMem.Length() / 2, mappedMem.Length() + 100); // overflow + fclose(f); + } + + TFile fileForMap(FileName_, OpenExisting); + try { + TMemoryMap mappedMem(fileForMap); + mappedMem.Map(mappedMem.Length() / 2, mappedMem.Length() + 100); // overflow UNIT_ASSERT(0); // should not go here } catch (yexception& exc) { TString text = exc.what(); // exception should contain failed file name UNIT_ASSERT(text.find(FileName_) != TString::npos); - } + } NFs::Remove(FileName_); - } + } Y_UNIT_TEST(TestMemoryMapIsWritable) { TFile file(FileName_, CreateAlways | WrOnly); diff --git a/util/system/flock.h b/util/system/flock.h index 210e834825..797b1970a1 100644 --- a/util/system/flock.h +++ b/util/system/flock.h @@ -2,7 +2,7 @@ #include "error.h" #include "defaults.h" -#include "file.h" +#include "file.h" #if defined(_unix_) @@ -13,7 +13,7 @@ static inline int Flock(int fd, int op) { return flock(fd, op); } -#else // not _unix_ +#else // not _unix_ #ifdef __cplusplus extern "C" { @@ -32,4 +32,4 @@ extern "C" { } #endif -#endif // not _unix_ +#endif // not _unix_ diff --git a/util/system/flock_ut.cpp b/util/system/flock_ut.cpp index 2bb705944c..b5f6cb5328 100644 --- a/util/system/flock_ut.cpp +++ b/util/system/flock_ut.cpp @@ -1,6 +1,6 @@ #include "flock.h" -#include "file_lock.h" -#include "guard.h" +#include "file_lock.h" +#include "guard.h" #include "tempfile.h" #include <library/cpp/testing/unittest/registar.h> @@ -14,15 +14,15 @@ Y_UNIT_TEST_SUITE(TFileLockTest) { } Y_UNIT_TEST(TestFileLocker) { - TTempFileHandle tmp("./file.locker"); + TTempFileHandle tmp("./file.locker"); TFileLock fileLockExclusive1("./file.locker"); TFileLock fileLockExclusive2("./file.locker"); TFileLock fileLockShared1("./file.locker", EFileLockType::Shared); TFileLock fileLockShared2("./file.locker", EFileLockType::Shared); TFileLock fileLockShared3("./file.locker", EFileLockType::Shared); - { + { TGuard<TFileLock> guard(fileLockExclusive1); - } + } { TTryGuard<TFileLock> tryGuard(fileLockExclusive1); UNIT_ASSERT(tryGuard.WasAcquired()); @@ -53,5 +53,5 @@ Y_UNIT_TEST_SUITE(TFileLockTest) { UNIT_ASSERT(!guard2.WasAcquired()); UNIT_ASSERT(guard3.WasAcquired()); } - } -} + } +} diff --git a/util/system/fstat.cpp b/util/system/fstat.cpp index 27f0de682b..81e98cbc6b 100644 --- a/util/system/fstat.cpp +++ b/util/system/fstat.cpp @@ -3,7 +3,7 @@ #include <sys/stat.h> -#include <util/folder/path.h> +#include <util/folder/path.h> #include <cerrno> @@ -82,7 +82,7 @@ static bool GetStatByHandle(TSystemFStat& fs, FHANDLE f) { #endif } -static bool GetStatByName(TSystemFStat& fs, const char* fileName, bool nofollow) { +static bool GetStatByName(TSystemFStat& fs, const char* fileName, bool nofollow) { #ifdef _win_ TFileHandle h = NFsPrivate::CreateFileWithUtf8Name(fileName, FILE_READ_ATTRIBUTES | FILE_READ_EA, FILE_SHARE_READ | FILE_SHARE_WRITE, OPEN_EXISTING, @@ -92,7 +92,7 @@ static bool GetStatByName(TSystemFStat& fs, const char* fileName, bool nofollow) } return GetStatByHandle(fs, h); #else - return !(nofollow ? lstat : stat)(fileName, &fs); + return !(nofollow ? lstat : stat)(fileName, &fs); #endif } @@ -111,27 +111,27 @@ TFileStat::TFileStat(FHANDLE f) { } } -void TFileStat::MakeFromFileName(const char* fileName, bool nofollow) { +void TFileStat::MakeFromFileName(const char* fileName, bool nofollow) { TSystemFStat st; - if (GetStatByName(st, fileName, nofollow)) { + if (GetStatByName(st, fileName, nofollow)) { MakeStat(*this, st); } else { *this = TFileStat(); } } -TFileStat::TFileStat(const TFsPath& fileName, bool nofollow) { +TFileStat::TFileStat(const TFsPath& fileName, bool nofollow) { MakeFromFileName(fileName.GetPath().data(), nofollow); -} - +} + TFileStat::TFileStat(const TString& fileName, bool nofollow) { MakeFromFileName(fileName.data(), nofollow); -} - -TFileStat::TFileStat(const char* fileName, bool nofollow) { - MakeFromFileName(fileName, nofollow); -} - +} + +TFileStat::TFileStat(const char* fileName, bool nofollow) { + MakeFromFileName(fileName, nofollow); +} + bool TFileStat::IsNull() const noexcept { return *this == TFileStat(); } diff --git a/util/system/fstat.h b/util/system/fstat.h index b9ef3f3987..64e79e1b55 100644 --- a/util/system/fstat.h +++ b/util/system/fstat.h @@ -4,7 +4,7 @@ #include <util/system/fhandle.h> class TFile; -class TFsPath; +class TFsPath; struct TFileStat { ui32 Mode = 0; /* protection */ @@ -29,17 +29,17 @@ public: bool IsDir() const noexcept; bool IsSymlink() const noexcept; - explicit TFileStat(const TFile& f); - explicit TFileStat(FHANDLE f); - TFileStat(const TFsPath& fileName, bool nofollow = false); + explicit TFileStat(const TFile& f); + explicit TFileStat(FHANDLE f); + TFileStat(const TFsPath& fileName, bool nofollow = false); TFileStat(const TString& fileName, bool nofollow = false); - TFileStat(const char* fileName, bool nofollow = false); + TFileStat(const char* fileName, bool nofollow = false); friend bool operator==(const TFileStat& l, const TFileStat& r) noexcept; friend bool operator!=(const TFileStat& l, const TFileStat& r) noexcept; -private: - void MakeFromFileName(const char* fileName, bool nofollow); +private: + void MakeFromFileName(const char* fileName, bool nofollow); }; i64 GetFileLength(FHANDLE fd); diff --git a/util/system/info.cpp b/util/system/info.cpp index 0d4ac42885..cf6681e89a 100644 --- a/util/system/info.cpp +++ b/util/system/info.cpp @@ -148,9 +148,9 @@ size_t NSystemInfo::LoadAverage(double* la, size_t len) { #if defined(_win_) || defined(_musl_) || defined(_bionic_) int ret = -1; #else - for (size_t i = 0; i < len; ++i) { - la[i] = 0; - } + for (size_t i = 0; i < len; ++i) { + la[i] = 0; + } int ret = getloadavg(la, len); #endif diff --git a/util/system/platform.h b/util/system/platform.h index c3b2dd33b2..58f310ab34 100644 --- a/util/system/platform.h +++ b/util/system/platform.h @@ -1,84 +1,84 @@ #pragma once -// ya style breaks indentation in ifdef's and code becomes unreadable -// clang-format off - +// ya style breaks indentation in ifdef's and code becomes unreadable +// clang-format off + // What OS ? // our definition has the form _{osname}_ #if defined(_WIN64) - #define _win64_ - #define _win32_ + #define _win64_ + #define _win32_ #elif defined(__WIN32__) || defined(_WIN32) // _WIN32 is also defined by the 64-bit compiler for backward compatibility - #define _win32_ + #define _win32_ #else - #define _unix_ - - #if defined(__sun__) || defined(sun) || defined(sparc) || defined(__sparc) - #define _sun_ - #endif - - #if defined(__hpux__) - #define _hpux_ - #endif - - #if defined(__linux__) - // Stands for "Linux" in the means of Linux kernel (i. e. Android is included) - #define _linux_ - #endif - - #if defined(__FreeBSD__) - #define _freebsd_ - #endif - - #if defined(__CYGWIN__) - #define _cygwin_ - #endif - - #if defined(__APPLE__) - #define _darwin_ - #endif - - #if defined(__ANDROID__) - #define _android_ - #endif + #define _unix_ + + #if defined(__sun__) || defined(sun) || defined(sparc) || defined(__sparc) + #define _sun_ + #endif + + #if defined(__hpux__) + #define _hpux_ + #endif + + #if defined(__linux__) + // Stands for "Linux" in the means of Linux kernel (i. e. Android is included) + #define _linux_ + #endif + + #if defined(__FreeBSD__) + #define _freebsd_ + #endif + + #if defined(__CYGWIN__) + #define _cygwin_ + #endif + + #if defined(__APPLE__) + #define _darwin_ + #endif + + #if defined(__ANDROID__) + #define _android_ + #endif #endif #if defined(__IOS__) - #define _ios_ + #define _ios_ #endif #if defined(_linux_) - #if defined(_musl_) - // nothing to do - #elif defined(_android_) - // Please do not mix with android-based systems. - // This definition describes Standard Library (libc) type. - #define _bionic_ - #else - #define _glibc_ - #endif + #if defined(_musl_) + // nothing to do + #elif defined(_android_) + // Please do not mix with android-based systems. + // This definition describes Standard Library (libc) type. + #define _bionic_ + #else + #define _glibc_ + #endif #endif #if defined(_darwin_) - #define unix - #define __unix__ + #define unix + #define __unix__ #endif #if defined(_win32_) || defined(_win64_) - #define _win_ + #define _win_ #endif #if defined(__arm__) || defined(__ARM__) || defined(__ARM_NEON) || defined(__aarch64__) || defined(_M_ARM) - #if defined(__arm64) || defined(__arm64__) || defined(__aarch64__) - #define _arm64_ - #else - #define _arm32_ - #endif + #if defined(__arm64) || defined(__arm64__) || defined(__aarch64__) + #define _arm64_ + #else + #define _arm32_ + #endif #endif #if defined(_arm64_) || defined(_arm32_) - #define _arm_ + #define _arm_ #endif /* __ia64__ and __x86_64__ - defined by GNU C. @@ -88,105 +88,105 @@ * or _M_X64 (starting in Visual Studio 8). */ #if defined(__x86_64__) || defined(_M_X64) || defined(_M_AMD64) - #define _x86_64_ + #define _x86_64_ #endif #if defined(__i386__) || defined(_M_IX86) - #define _i386_ + #define _i386_ #endif #if defined(__ia64__) || defined(_M_IA64) - #define _ia64_ + #define _ia64_ #endif #if defined(__powerpc__) - #define _ppc_ + #define _ppc_ #endif #if defined(__powerpc64__) - #define _ppc64_ + #define _ppc64_ #endif #if !defined(sparc) && !defined(__sparc) && !defined(__hpux__) && !defined(__alpha__) && !defined(_ia64_) && !defined(_x86_64_) && !defined(_arm_) && !defined(_i386_) && !defined(_ppc_) && !defined(_ppc64_) - #error "platform not defined, please, define one" + #error "platform not defined, please, define one" #endif #if defined(_x86_64_) || defined(_i386_) - #define _x86_ + #define _x86_ #endif #if defined(__MIC__) - #define _mic_ - #define _k1om_ + #define _mic_ + #define _k1om_ #endif // stdio or MessageBox #if defined(__CONSOLE__) || defined(_CONSOLE) - #define _console_ + #define _console_ #endif #if (defined(_win_) && !defined(_console_)) - #define _windows_ + #define _windows_ #elif !defined(_console_) - #define _console_ + #define _console_ #endif #if defined(__SSE__) || defined(SSE_ENABLED) - #define _sse_ + #define _sse_ #endif #if defined(__SSE2__) || defined(SSE2_ENABLED) - #define _sse2_ + #define _sse2_ #endif #if defined(__SSE3__) || defined(SSE3_ENABLED) - #define _sse3_ + #define _sse3_ #endif #if defined(__SSSE3__) || defined(SSSE3_ENABLED) - #define _ssse3_ + #define _ssse3_ #endif #if defined(__SSE4_1__) || defined(SSE41_ENABLED) - #define _sse4_1_ + #define _sse4_1_ #endif #if defined(__SSE4_2__) || defined(SSE42_ENABLED) - #define _sse4_2_ + #define _sse4_2_ #endif #if defined(__POPCNT__) || defined(POPCNT_ENABLED) - #define _popcnt_ + #define _popcnt_ #endif #if defined(__PCLMUL__) || defined(PCLMUL_ENABLED) - #define _pclmul_ + #define _pclmul_ #endif #if defined(__AES__) || defined(AES_ENABLED) - #define _aes_ + #define _aes_ #endif #if defined(__AVX__) || defined(AVX_ENABLED) - #define _avx_ + #define _avx_ #endif #if defined(__AVX2__) || defined(AVX2_ENABLED) - #define _avx2_ + #define _avx2_ #endif #if defined(__FMA__) || defined(FMA_ENABLED) - #define _fma_ + #define _fma_ #endif #if defined(__DLL__) || defined(_DLL) - #define _dll_ + #define _dll_ #endif // 16, 32 or 64 #if defined(__sparc_v9__) || defined(_x86_64_) || defined(_ia64_) || defined(_arm64_) || defined(_ppc64_) - #define _64_ + #define _64_ #else - #define _32_ + #define _32_ #endif /* All modern 64-bit Unix systems use scheme LP64 (long, pointers are 64-bit). @@ -202,15 +202,15 @@ */ #if defined(_32_) - #define SIZEOF_PTR 4 + #define SIZEOF_PTR 4 #elif defined(_64_) - #define SIZEOF_PTR 8 + #define SIZEOF_PTR 8 #endif #define PLATFORM_DATA_ALIGN SIZEOF_PTR #if !defined(SIZEOF_PTR) - #error todo + #error todo #endif #define SIZEOF_CHAR 1 @@ -221,20 +221,20 @@ #define SIZEOF_UNSIGNED_INT 4 #if defined(_32_) - #define SIZEOF_LONG 4 - #define SIZEOF_UNSIGNED_LONG 4 + #define SIZEOF_LONG 4 + #define SIZEOF_UNSIGNED_LONG 4 #elif defined(_64_) - #if defined(_win_) - #define SIZEOF_LONG 4 - #define SIZEOF_UNSIGNED_LONG 4 - #else - #define SIZEOF_LONG 8 - #define SIZEOF_UNSIGNED_LONG 8 - #endif // _win_ + #if defined(_win_) + #define SIZEOF_LONG 4 + #define SIZEOF_UNSIGNED_LONG 4 + #else + #define SIZEOF_LONG 8 + #define SIZEOF_UNSIGNED_LONG 8 + #endif // _win_ #endif // _32_ #if !defined(SIZEOF_LONG) - #error todo + #error todo #endif #define SIZEOF_LONG_LONG 8 @@ -243,4 +243,4 @@ #undef SIZEOF_SIZE_T // in case we include <Python.h> which defines it, too #define SIZEOF_SIZE_T SIZEOF_PTR -// clang-format on +// clang-format on diff --git a/util/system/protect.cpp b/util/system/protect.cpp index 615a8231bb..bbb8d410df 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 +} diff --git a/util/system/protect.h b/util/system/protect.h index da024548de..26714f3e92 100644 --- a/util/system/protect.h +++ b/util/system/protect.h @@ -1,25 +1,25 @@ -#pragma once - +#pragma once + #include "defaults.h" - + #include <util/generic/flags.h> -enum EProtectMemoryMode { +enum EProtectMemoryMode { PM_NONE = 0x00, // no access allowed PM_READ = 0x01, // read access allowed - PM_WRITE = 0x02, // write access allowed + PM_WRITE = 0x02, // write access allowed PM_EXEC = 0x04 // execute access allowed -}; - +}; + Y_DECLARE_FLAGS(EProtectMemory, EProtectMemoryMode) Y_DECLARE_OPERATORS_FOR_FLAGS(EProtectMemory) -/** - * Set protection mode on memory block - * @param addr Block address to be protected - * @param length Block size in bytes - * @param mode A bitwise combination of @c EProtectMemoryMode flags - * @note On Windows there is no write-only protection mode, - * so PM_WRITE will be translated to (PM_READ | PM_WRITE) on Windows. - **/ +/** + * Set protection mode on memory block + * @param addr Block address to be protected + * @param length Block size in bytes + * @param mode A bitwise combination of @c EProtectMemoryMode flags + * @note On Windows there is no write-only protection mode, + * so PM_WRITE will be translated to (PM_READ | PM_WRITE) on Windows. + **/ void ProtectMemory(void* addr, const size_t length, const EProtectMemory mode); diff --git a/util/system/shellcommand.cpp b/util/system/shellcommand.cpp index 45588154ad..b1989b5c8c 100644 --- a/util/system/shellcommand.cpp +++ b/util/system/shellcommand.cpp @@ -508,8 +508,8 @@ public: } return nullptr; } - - TString GetQuotedCommand() const; + + TString GetQuotedCommand() const; }; #if defined(_win_) @@ -1194,7 +1194,7 @@ TShellCommand& TShellCommand::CloseInput() { Impl->CloseInput(); return *this; } - -TString TShellCommand::GetQuotedCommand() const { - return Impl->GetQuotedCommand(); -} + +TString TShellCommand::GetQuotedCommand() const { + return Impl->GetQuotedCommand(); +} diff --git a/util/system/shellcommand.h b/util/system/shellcommand.h index 0e2a232538..8730627fe5 100644 --- a/util/system/shellcommand.h +++ b/util/system/shellcommand.h @@ -464,11 +464,11 @@ public: */ TShellCommand& CloseInput(); - /** - * @brief Get quoted command (for debug/view purposes only!) - **/ - TString GetQuotedCommand() const; - + /** + * @brief Get quoted command (for debug/view purposes only!) + **/ + TString GetQuotedCommand() const; + private: class TImpl; using TImplRef = TSimpleIntrusivePtr<TImpl>; diff --git a/util/system/shellcommand_ut.cpp b/util/system/shellcommand_ut.cpp index 412ba161e6..9d849279d2 100644 --- a/util/system/shellcommand_ut.cpp +++ b/util/system/shellcommand_ut.cpp @@ -80,8 +80,8 @@ Y_UNIT_TEST_SUITE(TShellCommandTest) { UNIT_ASSERT_VALUES_EQUAL(cmd.GetOutput(), "hello" NL); UNIT_ASSERT(TShellCommand::SHELL_FINISHED == cmd.GetStatus()); UNIT_ASSERT(cmd.GetExitCode().Defined() && 0 == cmd.GetExitCode()); - - UNIT_ASSERT_VALUES_EQUAL(cmd.GetQuotedCommand(), "echo hello"); + + UNIT_ASSERT_VALUES_EQUAL(cmd.GetQuotedCommand(), "echo hello"); } Y_UNIT_TEST(TestOnlyNecessaryQuotes) { |