chenBright commented on code in PR #2890:
URL: https://github.com/apache/brpc/pull/2890#discussion_r2019890431


##########
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:
   此处应该传的是cur_meta吧:
   1. jump_stack之前,需要调__sanitizer_start_switch_fiber()保存fake stack到cur_meta中。
   2. 
cur_meta对应的bthread被重新调度后,调__sanitizer_finish_switch_fiber恢复cur_meta保存的fake 
stack。



##########
docs/cn/sanitizers.md:
##########
@@ -0,0 +1,32 @@
+# Sanitizers
+
+新版本的GCC/Clang支持[sanitizers](https://github.com/google/sanitizers),方便开发者排查代码中的bug。
 bRPC对sanitizers提供了一定的支持。
+
+## AddressSanitizer(ASan)
+
+ASan提供了[对协程的支持](https://reviews.llvm.org/D20913)。 
在bthread创建、切换、销毁时,让ASan知道当前bthread的栈信息,主要用于维护[fake 
stack](https://github.com/google/sanitizers/wiki/AddressSanitizerUseAfterReturn)。
+
+bRPC中启用ASan的方法:给config_brpc.sh增加`--with-glog`选项、给cmake增加`-DWITH_GLOG=ON`选项或者给bazel增加`--define
 with_asan=true`选项。

Review Comment:
   确实有误,我提个PR改一下。



##########
src/bthread/task_group.cpp:
##########
@@ -255,6 +297,15 @@ int TaskGroup::init(size_t runqueue_capacity) {
     return 0;
 }
 
+#ifdef BUTIL_USE_ASAN
+void TaskGroup::asan_task_runner(intptr_t) {
+    // This is a new thread, and it doesn't have the fake stack yet. ASan will
+    // create it lazily, for now just pass NULL.
+    internal::FinishSwitchFiber(NULL);

Review Comment:
   是要成对出现的。
   
   此处的场景是bthread挂起,jump_stack调度了一个没运行过的bthread。此处的finish对应的是挂起bthread 
jump_stack之前的start。



-- 
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

Reply via email to