BusyJay commented on code in PR #2890: URL: https://github.com/apache/brpc/pull/2890#discussion_r2020463256
########## src/bthread/task_group.cpp: ########## @@ -657,7 +715,11 @@ void TaskGroup::sched_to(TaskGroup** pg, TaskMeta* next_meta) { g->_control->_task_tracer.set_status(TASK_STATUS_JUMPING, cur_meta); g->_control->_task_tracer.set_status(TASK_STATUS_JUMPING, next_meta); #endif // BRPC_BTHREAD_TRACER - jump_stack(cur_meta->stack, next_meta->stack); + { + BTHREAD_SCOPED_ASAN_FIBER_SWITCHER( + cur_meta->stack->storage, cur_ending); Review Comment: 调用链是:`BTHREAD_SCOPED_ASAN_FIBER_SWITCHER(cur_meta_storage)` -> `ScopedASanFiberSwitcher(cur_meta_storage)` -> `StartSwitchFiber(&fake_stack, cur_meta_storage)` -> `BUTIL_ASAN_START_SWITCH_FIBER(&fake_stack, cur_meta_storage.real_bottom, cur_meta_storage.stacksize)` -> `__sanitizer_start_switch_fiber(&fake_stack, cur_meta_storage.real_bottom, cur_meta_storage.stacksize)`. 文档里说后两个参数是要跳转到的栈 meta,所以应该是 next_meta: > Before switching to a different stack, you must call <c>__sanitizer_start_switch_fiber()</c> with a pointer to the bottom of the destination stack and with its size. > jump_stack之前,需要调__sanitizer_start_switch_fiber()保存fake stack到cur_meta中。 不对,fake_stack 是由 asan 自己根据记录的栈信息进行维护的,并且最终保留在上述 API 传入的第一个参数里。比如从协程 A 跳转协程 B 时调用 start_switch_fiber(&fake_stack_a),asan 记录的线程栈底和目前的长度会保留在 A 的 `fake_stack_a`。当从别的协程跳回 A 时,A 再调用 finish_switch_fiber(fake_stack_a),把之前记录的栈底和长度重新恢复到 asan 内部。 fake_stack 不是必须的,可以直接传 nullptr,只要做校验的时候把 detect_stack_use_after_return 设置成 0 即可(gcc13 以前默认就是关闭的)。 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org For additional commands, e-mail: dev-h...@brpc.apache.org