diff options
author | AlexSm <alex@ydb.tech> | 2024-03-05 10:40:59 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-05 12:40:59 +0300 |
commit | 1ac13c847b5358faba44dbb638a828e24369467b (patch) | |
tree | 07672b4dd3604ad3dee540a02c6494cb7d10dc3d /util/system | |
parent | ffcca3e7f7958ddc6487b91d3df8c01054bd0638 (diff) | |
download | ydb-1ac13c847b5358faba44dbb638a828e24369467b.tar.gz |
Library import 16 (#2433)
Co-authored-by: robot-piglet <robot-piglet@yandex-team.com>
Co-authored-by: deshevoy <deshevoy@yandex-team.com>
Co-authored-by: robot-contrib <robot-contrib@yandex-team.com>
Co-authored-by: thegeorg <thegeorg@yandex-team.com>
Co-authored-by: robot-ya-builder <robot-ya-builder@yandex-team.com>
Co-authored-by: svidyuk <svidyuk@yandex-team.com>
Co-authored-by: shadchin <shadchin@yandex-team.com>
Co-authored-by: robot-ratatosk <robot-ratatosk@yandex-team.com>
Co-authored-by: innokentii <innokentii@yandex-team.com>
Co-authored-by: arkady-e1ppa <arkady-e1ppa@yandex-team.com>
Co-authored-by: snermolaev <snermolaev@yandex-team.com>
Co-authored-by: dimdim11 <dimdim11@yandex-team.com>
Co-authored-by: kickbutt <kickbutt@yandex-team.com>
Co-authored-by: abdullinsaid <abdullinsaid@yandex-team.com>
Co-authored-by: korsunandrei <korsunandrei@yandex-team.com>
Co-authored-by: petrk <petrk@yandex-team.com>
Co-authored-by: miroslav2 <miroslav2@yandex-team.com>
Co-authored-by: serjflint <serjflint@yandex-team.com>
Co-authored-by: akhropov <akhropov@yandex-team.com>
Co-authored-by: prettyboy <prettyboy@yandex-team.com>
Co-authored-by: ilikepugs <ilikepugs@yandex-team.com>
Co-authored-by: hiddenpath <hiddenpath@yandex-team.com>
Co-authored-by: mikhnenko <mikhnenko@yandex-team.com>
Co-authored-by: spreis <spreis@yandex-team.com>
Co-authored-by: andreyshspb <andreyshspb@yandex-team.com>
Co-authored-by: dimaandreev <dimaandreev@yandex-team.com>
Co-authored-by: rashid <rashid@yandex-team.com>
Co-authored-by: robot-ydb-importer <robot-ydb-importer@yandex-team.com>
Co-authored-by: r-vetrov <r-vetrov@yandex-team.com>
Co-authored-by: ypodlesov <ypodlesov@yandex-team.com>
Co-authored-by: zaverden <zaverden@yandex-team.com>
Co-authored-by: vpozdyayev <vpozdyayev@yandex-team.com>
Co-authored-by: robot-cozmo <robot-cozmo@yandex-team.com>
Co-authored-by: v-korovin <v-korovin@yandex-team.com>
Co-authored-by: arikon <arikon@yandex-team.com>
Co-authored-by: khoden <khoden@yandex-team.com>
Co-authored-by: psydmm <psydmm@yandex-team.com>
Co-authored-by: robot-javacom <robot-javacom@yandex-team.com>
Co-authored-by: dtorilov <dtorilov@yandex-team.com>
Co-authored-by: sennikovmv <sennikovmv@yandex-team.com>
Co-authored-by: hcpp <hcpp@ydb.tech>
Diffstat (limited to 'util/system')
-rw-r--r-- | util/system/context.cpp | 13 | ||||
-rw-r--r-- | util/system/context.h | 25 | ||||
-rw-r--r-- | util/system/fs.cpp | 23 | ||||
-rw-r--r-- | util/system/fs.h | 7 | ||||
-rw-r--r-- | util/system/sanitizers.cpp | 83 | ||||
-rw-r--r-- | util/system/sanitizers.h | 44 |
6 files changed, 98 insertions, 97 deletions
diff --git a/util/system/context.cpp b/util/system/context.cpp index ad99309088..3a67593813 100644 --- a/util/system/context.cpp +++ b/util/system/context.cpp @@ -134,6 +134,8 @@ namespace { #endif } + #if defined(USE_SANITIZER_CONTEXT) + TContMachineContext::TSan::TSan() noexcept : TL(nullptr) { @@ -148,11 +150,12 @@ TContMachineContext::TSan::TSan(const TContClosure& c) noexcept void TContMachineContext::TSan::DoRunNaked() { AfterSwitch(); TL->DoRunNaked(); - BeforeFinish(); } + #endif + TContMachineContext::TContMachineContext(const TContClosure& c) - #if defined(_asan_enabled_) || defined(_tsan_enabled_) + #if defined(USE_SANITIZER_CONTEXT) : San_(c) #endif { @@ -162,7 +165,7 @@ TContMachineContext::TContMachineContext(const TContClosure& c) * arg, and align data */ - #if defined(_asan_enabled_) + #if defined(USE_SANITIZER_CONTEXT) auto trampoline = &San_; #else auto trampoline = c.TrampoLine; @@ -196,12 +199,12 @@ TContMachineContext::TContMachineContext(const TContClosure& c) void TContMachineContext::SwitchTo(TContMachineContext* next) noexcept { if (Y_LIKELY(__mysetjmp(Buf_) == 0)) { - #if defined(_asan_enabled_) || defined(_tsan_enabled_) + #if defined(USE_SANITIZER_CONTEXT) next->San_.BeforeSwitch(&San_); #endif __mylongjmp(next->Buf_, 1); } else { - #if defined(_asan_enabled_) + #if defined(USE_SANITIZER_CONTEXT) San_.AfterSwitch(); #endif } diff --git a/util/system/context.h b/util/system/context.h index c04a462365..1b690bd57c 100644 --- a/util/system/context.h +++ b/util/system/context.h @@ -3,7 +3,6 @@ #include "align.h" #include "defaults.h" #include "compiler.h" -#include "sanitizers.h" #include <util/generic/array_ref.h> #include <util/generic/utility.h> @@ -17,17 +16,21 @@ #error todo #endif +#if defined(__clang_major__) && (__clang_major__ >= 9) && (defined(_asan_enabled_) || defined(_tsan_enabled_)) + #include "sanitizers.h" + #define USE_SANITIZER_CONTEXT +#endif + /* * switch method */ -#if defined(thread_sanitizer_enabled) - #define USE_UCONTEXT_CONT - #if defined(_darwin_) - #define _XOPEN_SOURCE 700 - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wdeprecated-declarations" - #endif -#elif defined(_bionic_) || defined(__IOS__) +#if defined(thread_sanitizer_enabled) && defined(_darwin_) + #define _XOPEN_SOURCE 700 + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wdeprecated-declarations" +#endif + +#if defined(_bionic_) || defined(__IOS__) #define USE_GENERIC_CONT #elif defined(_cygwin_) #define USE_UCONTEXT_CONT @@ -145,6 +148,8 @@ public: private: __myjmp_buf Buf_; + #if defined(USE_SANITIZER_CONTEXT) + struct TSan: public ITrampoLine, public ::NSan::TFiberContext { TSan() noexcept; TSan(const TContClosure& c) noexcept; @@ -154,7 +159,6 @@ private: ITrampoLine* TL; }; - #if defined(_asan_enabled_) || defined(_tsan_enabled_) TSan San_; #endif }; @@ -168,6 +172,7 @@ static inline size_t MachineContextSize() noexcept { * be polite */ #if !defined(FROM_CONTEXT_IMPL) + #undef USE_SANITIZER_CONTEXT #undef USE_JUMP_CONT #undef USE_FIBER_CONT #undef USE_GENERIC_CONT diff --git a/util/system/fs.cpp b/util/system/fs.cpp index b848abac8a..808bc0b7b6 100644 --- a/util/system/fs.cpp +++ b/util/system/fs.cpp @@ -8,12 +8,13 @@ #include <errno.h> #endif +#include <util/folder/iterator.h> +#include <util/folder/path.h> #include <util/generic/yexception.h> #include <util/memory/tempbuf.h> #include <util/stream/file.h> -#include <util/folder/iterator.h> #include <util/system/fstat.h> -#include <util/folder/path.h> +#include <util/system/sysstat.h> bool NFs::Remove(const TString& path) { #if defined(_win_) @@ -23,6 +24,24 @@ bool NFs::Remove(const TString& path) { #endif } +bool NFs::SetExecutable(const TString& path, bool exec) { +#ifdef _unix_ + TFileStat stat(path); + ui32 mode = stat.Mode; + if (exec) { + mode |= S_IXUSR | S_IXGRP | S_IXOTH; + } else { + mode &= ~(S_IXUSR | S_IXGRP | S_IXOTH); + } + if (stat.Mode != 0 && mode != stat.Mode) { + return !Chmod(path.c_str(), mode); + } +#endif + Y_UNUSED(exec); + Y_UNUSED(path); + return true; +} + void NFs::RemoveRecursive(const TString& path) { static const TStringBuf errStr = "error while removing "; diff --git a/util/system/fs.h b/util/system/fs.h index a28a6d84fb..f4ab746aa3 100644 --- a/util/system/fs.h +++ b/util/system/fs.h @@ -23,6 +23,13 @@ namespace NFs { Y_DECLARE_FLAGS(EFilePermissions, EFilePermission); + /// Add executable bit + /// + /// @param[in] path Path to mark as executable + /// @param[in] exec New value of execution bit + /// @returns true if bit has changed or false otherwise + bool SetExecutable(const TString& path, bool exec); + /// Remove a file or empty directory /// /// @param[in] path Path to file or directory diff --git a/util/system/sanitizers.cpp b/util/system/sanitizers.cpp index bb799a9e2e..3e710b39c7 100644 --- a/util/system/sanitizers.cpp +++ b/util/system/sanitizers.cpp @@ -1,42 +1,29 @@ #include "sanitizers.h" #include "thread.h" -#if defined(_asan_enabled_) -extern "C" { - void __sanitizer_start_switch_fiber(void** fake_stack_save, const void* bottom, size_t size); - void __sanitizer_finish_switch_fiber(void* fake_stack_save, const void** old_bottom, size_t* old_size); -} -#endif +using namespace NSan; #if defined(_tsan_enabled_) #if defined(__clang_major__) && (__clang_major__ >= 9) -extern "C" { - void* __tsan_get_current_fiber(void); +extern "C" { // sanitizers API + + #if defined(_tsan_enabled_) void* __tsan_create_fiber(unsigned flags); - void __tsan_destroy_fiber(void* fiber); - void __tsan_switch_to_fiber(void* fiber, unsigned flags); void __tsan_set_fiber_name(void* fiber, const char* name); -} + #endif + +} // sanitizers API #else namespace { - void* __tsan_get_current_fiber(void) { - return nullptr; - } void* __tsan_create_fiber(unsigned) { return nullptr; } - void __tsan_destroy_fiber(void*) { - } - void __tsan_switch_to_fiber(void*, unsigned) { - } void __tsan_set_fiber_name(void*, const char*) { } } #endif #endif -using namespace NSan; - TFiberContext::TFiberContext() noexcept : Token_(nullptr) , IsMainFiber_(true) @@ -45,7 +32,7 @@ TFiberContext::TFiberContext() noexcept #endif { TCurrentThreadLimits sl; - + (void)Token_; Stack_ = sl.StackBegin; Len_ = sl.StackLength; @@ -70,60 +57,6 @@ TFiberContext::TFiberContext(const void* stack, size_t len, const char* contName #endif } -TFiberContext::~TFiberContext() noexcept { - if (!IsMainFiber_) { -#if defined(_asan_enabled_) - if (Token_) { - // destroy saved FakeStack - void* activeFakeStack = nullptr; - const void* activeStack = nullptr; - size_t activeStackSize = 0; - __sanitizer_start_switch_fiber(&activeFakeStack, (char*)Stack_, Len_); - __sanitizer_finish_switch_fiber(Token_, &activeStack, &activeStackSize); - __sanitizer_start_switch_fiber(nullptr, activeStack, activeStackSize); - __sanitizer_finish_switch_fiber(activeFakeStack, nullptr, nullptr); - } -#endif -#if defined(_tsan_enabled_) - __tsan_destroy_fiber(CurrentTSanFiberContext_); -#endif - } -} - -void TFiberContext::BeforeFinish() noexcept { -#if defined(_asan_enabled_) - __sanitizer_start_switch_fiber(nullptr, nullptr, 0); -#else - (void)Token_; - (void)Stack_; - (void)Len_; -#endif -} - -void TFiberContext::BeforeSwitch(TFiberContext* old) noexcept { -#if defined(_asan_enabled_) - __sanitizer_start_switch_fiber(old ? &old->Token_ : nullptr, (char*)Stack_, Len_); -#else - (void)old; -#endif - -#if defined(_tsan_enabled_) - __tsan_switch_to_fiber(CurrentTSanFiberContext_, /*flags =*/0); -#endif -} - -void TFiberContext::AfterSwitch() noexcept { -#if defined(_asan_enabled_) - __sanitizer_finish_switch_fiber(Token_, nullptr, nullptr); -#endif -} - -void TFiberContext::AfterStart() noexcept { -#if defined(_asan_enabled_) - __sanitizer_finish_switch_fiber(nullptr, nullptr, nullptr); -#endif -} - #if defined(_tsan_enabled_) extern "C" { // This function should not be directly exposed in headers diff --git a/util/system/sanitizers.h b/util/system/sanitizers.h index f0d3124496..516256ea1d 100644 --- a/util/system/sanitizers.h +++ b/util/system/sanitizers.h @@ -6,6 +6,8 @@ extern "C" { // sanitizers API #if defined(_asan_enabled_) void __lsan_ignore_object(const void* p); + void __sanitizer_start_switch_fiber(void** fake_stack_save, const void* bottom, size_t size); + void __sanitizer_finish_switch_fiber(void* fake_stack_save, const void** old_bottom, size_t* old_size); #endif #if defined(_msan_enabled_) @@ -17,6 +19,9 @@ extern "C" { // sanitizers API #if defined(_tsan_enabled_) void __tsan_acquire(void* a); void __tsan_release(void* a); + void* __tsan_get_current_fiber(void); + void __tsan_destroy_fiber(void* fiber); + void __tsan_switch_to_fiber(void* fiber, unsigned flags); #endif } // sanitizers API @@ -27,13 +32,42 @@ namespace NSan { TFiberContext() noexcept; TFiberContext(const void* stack, size_t len, const char* contName) noexcept; - ~TFiberContext() noexcept; + ~TFiberContext() noexcept { + if (!IsMainFiber_) { +#if defined(_asan_enabled_) + if (Token_) { + // destroy saved FakeStack + void* activeFakeStack = nullptr; + const void* activeStack = nullptr; + size_t activeStackSize = 0; + __sanitizer_start_switch_fiber(&activeFakeStack, (char*)Stack_, Len_); + __sanitizer_finish_switch_fiber(Token_, &activeStack, &activeStackSize); + __sanitizer_start_switch_fiber(nullptr, activeStack, activeStackSize); + __sanitizer_finish_switch_fiber(activeFakeStack, nullptr, nullptr); + } +#endif +#if defined(_tsan_enabled_) + __tsan_destroy_fiber(CurrentTSanFiberContext_); +#endif + } + } - void BeforeFinish() noexcept; - void BeforeSwitch(TFiberContext* old) noexcept; - void AfterSwitch() noexcept; + Y_FORCE_INLINE void BeforeSwitch(TFiberContext* old) noexcept { +#if defined(_asan_enabled_) + __sanitizer_start_switch_fiber(old ? &old->Token_ : nullptr, (char*)Stack_, Len_); +#else + (void)old; +#endif - static void AfterStart() noexcept; +#if defined(_tsan_enabled_) + __tsan_switch_to_fiber(CurrentTSanFiberContext_, /*flags =*/0); +#endif + } + void AfterSwitch() noexcept { +#if defined(_asan_enabled_) + __sanitizer_finish_switch_fiber(Token_, nullptr, nullptr); +#endif + } private: void* Token_; |