提交 a7eb2d81 编写于 作者: O obdev 提交者: wangzelin.wzl

[CP] not jump to routine stack when use asan

上级 3942c226
......@@ -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<common::ObLocalStore*>(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<common::ObLocalStore*>(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()
......
......@@ -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());
......
......@@ -202,6 +202,7 @@ private:
CoRoutine();
static void __start(boost::context::detail::transfer_t from);
void start_without_jump();
private:
CoIdx idx_;
......
......@@ -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.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册