From a7eb2d81c535683e3019f94978303e8af98bf120 Mon Sep 17 00:00:00 2001 From: obdev Date: Fri, 22 Apr 2022 16:48:55 +0800 Subject: [PATCH] [CP] not jump to routine stack when use asan --- deps/oblib/src/common/ob_common_utility.cpp | 11 ++++++++++ deps/oblib/src/lib/coro/co_routine.cpp | 23 ++++++++++++++++++++- deps/oblib/src/lib/coro/co_routine.h | 1 + deps/oblib/src/lib/coro/routine.h | 4 ++++ 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/deps/oblib/src/common/ob_common_utility.cpp b/deps/oblib/src/common/ob_common_utility.cpp index 21069098d8..6ecd8bbd42 100644 --- a/deps/oblib/src/common/ob_common_utility.cpp +++ b/deps/oblib/src/common/ob_common_utility.cpp @@ -118,6 +118,7 @@ int check_stack_overflow(bool& is_overflow, int64_t reserved_size /* default equ int get_stackattr(void*& stackaddr, size_t& stacksize) { int ret = OB_SUCCESS; +#ifndef OB_USE_ASAN if (OB_LIKELY(CO_IS_ENABLED())) { auto cls = reinterpret_cast(CO_CURRENT().get_context().get_local_store()); stackaddr = cls->stack_addr_; @@ -125,6 +126,11 @@ int get_stackattr(void*& stackaddr, size_t& stacksize) } else if (OB_LIKELY(g_stackaddr != nullptr)) { stackaddr = g_stackaddr; stacksize = g_stacksize; +#else + if (OB_LIKELY(g_stackaddr != nullptr)) { + stackaddr = g_stackaddr; + stacksize = g_stacksize; +#endif } else { pthread_attr_t attr; if (OB_UNLIKELY(0 != pthread_getattr_np(pthread_self(), &attr))) { @@ -147,6 +153,7 @@ int get_stackattr(void*& stackaddr, size_t& stacksize) void set_stackattr(void* stackaddr, size_t stacksize) { +#ifndef OB_USE_ASAN if (CO_IS_ENABLED()) { auto cls = reinterpret_cast(CO_CURRENT().get_context().get_local_store()); cls->stack_addr_ = stackaddr; @@ -155,6 +162,10 @@ void set_stackattr(void* stackaddr, size_t stacksize) g_stackaddr = (char*)stackaddr; g_stacksize = stacksize; } +#else + g_stackaddr = (char *)stackaddr; + g_stacksize = stacksize; +#endif } ObFatalErrExtraInfoGuard::ObFatalErrExtraInfoGuard() diff --git a/deps/oblib/src/lib/coro/co_routine.cpp b/deps/oblib/src/lib/coro/co_routine.cpp index 9949793d21..053c58f261 100644 --- a/deps/oblib/src/lib/coro/co_routine.cpp +++ b/deps/oblib/src/lib/coro/co_routine.cpp @@ -71,9 +71,12 @@ int CoRoutine::resume(CoRoutine& current) running_tsc_ = co_rdtscp(); assert(cc_.get_ctx()); +#ifndef OB_USE_ASAN transfer_t transfer = jump_fcontext(cc_.get_ctx(), this); cc_.get_ctx() = transfer.fctx; - +#else + start_without_jump(); +#endif return ret; } @@ -142,6 +145,24 @@ void CoRoutine::__start(transfer_t from) OB_ASSERT(0); } +void CoRoutine::start_without_jump() +{ + int ret = OB_SUCCESS; + CoRoutine &routine = *this; + routine.idx_ = alloc_coidx(); + routine.set_run_status(RunStatus::RUNNING); + routine.at_create(); + MemoryContext *mem_context = GET_TSI0(MemoryContext); + assert(mem_context != nullptr && *mem_context != nullptr); + WITH_CONTEXT(*mem_context) + { + routine.run(); + } + routine.at_exit(); + free_coidx(routine.idx_); + routine.set_run_status(RunStatus::FINISHED); +} + int CoRoutine::at_create() { CVC.at_routine_create(get_crls_buffer()); diff --git a/deps/oblib/src/lib/coro/co_routine.h b/deps/oblib/src/lib/coro/co_routine.h index c77c4a9a00..5c840f30ab 100644 --- a/deps/oblib/src/lib/coro/co_routine.h +++ b/deps/oblib/src/lib/coro/co_routine.h @@ -202,6 +202,7 @@ private: CoRoutine(); static void __start(boost::context::detail::transfer_t from); + void start_without_jump(); private: CoIdx idx_; diff --git a/deps/oblib/src/lib/coro/routine.h b/deps/oblib/src/lib/coro/routine.h index 169ef05353..030c8a555c 100644 --- a/deps/oblib/src/lib/coro/routine.h +++ b/deps/oblib/src/lib/coro/routine.h @@ -56,11 +56,15 @@ namespace this_routine { /// their execution. OB_INLINE void usleep(uint32_t usec) { +#ifndef OB_USE_ASAN if (!this_thread::is_monopoly() && coro::is_enabled()) { coro::current().usleep(usec); } else { ::usleep(usec); } +#else + ::usleep(usec); +#endif } /// \brief Yield to other routines. -- GitLab