From 729fcfd7625a38939cc595faddcf1262529337ab Mon Sep 17 00:00:00 2001 From: Coldwings Date: Tue, 5 Aug 2025 15:34:01 +0800 Subject: [PATCH 1/3] Fix X86 linux asan start call --- thread/thread.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/thread/thread.cpp b/thread/thread.cpp index d71d422c..3b8e2fc1 100644 --- a/thread/thread.cpp +++ b/thread/thread.cpp @@ -763,6 +763,7 @@ R"( DEF_ASM_FUNC(_photon_thread_stub) R"( + call _asan_start mov 0x40(%rbp), %rdi movq $0, 0x40(%rbp) call *0x48(%rbp) From 66ae7b011636f1d80975b957db5f74b1e3a3a38e Mon Sep 17 00:00:00 2001 From: PhotonLibOS <140932936+photonlibos@users.noreply.github.com> Date: Fri, 8 Aug 2025 11:00:40 +0800 Subject: [PATCH 2/3] Fix autopr (#933) (#934) Co-authored-by: Coldwings --- .github/workflows/auto-pr-precise.yml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/auto-pr-precise.yml b/.github/workflows/auto-pr-precise.yml index f590dcaf..f55faa27 100644 --- a/.github/workflows/auto-pr-precise.yml +++ b/.github/workflows/auto-pr-precise.yml @@ -57,11 +57,17 @@ jobs: set -x git checkout ${{steps.branch_info.outputs.NEXT_BRANCH}} git checkout -b ${{steps.create_branch.outputs.PRBRANCH}} - TITLE=$(git log --format="| %s" ${{ github.event.commits[0].id }}~..${{ github.event.after }} | xargs -0) - echo "TITLE=$TITLE" >> $GITHUB_OUTPUT - echo "MESSAGE<<__EOF" >> $GITHUB_OUTPUT + echo "TITLE<<__AUTOPR_EOF" >> $GITHUB_OUTPUT + git log --format="| %s" ${{ github.event.commits[0].id }}~..${{ github.event.after }} | tr '\n' ' ' >> $GITHUB_OUTPUT + echo "__AUTOPR_EOF" >> $GITHUB_OUTPUT + echo "MESSAGE<<__AUTOPR_EOF" >> $GITHUB_OUTPUT git log --format="> %B" ${{ github.event.commits[0].id }}~..${{ github.event.after }} >> $GITHUB_OUTPUT +<<<<<<< HEAD echo "__EOF" >> $GITHUB_OUTPUT +======= + echo "__AUTOPR_EOF" >> $GITHUB_OUTPUT + cat $GITHUB_OUTPUT +>>>>>>> 79228b2 (Fix autopr (#933) (#934)) REVS=$(git rev-list --reverse ${{ github.event.commits[0].id }}~..${{ github.event.after }} ) for rev in "$REVS"; do if ! git cherry-pick ${rev} ; then @@ -84,4 +90,3 @@ jobs: base: `${{steps.branch_info.outputs.NEXT_BRANCH}}`, body: `${{steps.merge-changes.outputs.MESSAGE}}\nGenerated by Auto PR, by cherry-pick related commits`, }); - From ccaf356d24beac1c48830d1a7e4ada1c6a228e78 Mon Sep 17 00:00:00 2001 From: Coldwings Date: Tue, 12 Aug 2025 11:33:02 +0800 Subject: [PATCH 3/3] Fix PHOTON_BUILD_WITH_ASAN --- CMakeLists.txt | 1 + thread/thread.cpp | 90 +++++++++++++++++++++++------------------------ 2 files changed, 46 insertions(+), 45 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f5efb3cb..4e44c533 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,6 +73,7 @@ if (PHOTON_BUILD_WITH_ASAN) if ((NOT CMAKE_BUILD_TYPE STREQUAL "Debug") OR (NOT CMAKE_SYSTEM_NAME STREQUAL "Linux")) message(FATAL_ERROR "Wrong environment") endif () + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -static-libasan") add_link_options(-fsanitize=address -static-libasan) endif () diff --git a/thread/thread.cpp b/thread/thread.cpp index 3b8e2fc1..52fd07e4 100644 --- a/thread/thread.cpp +++ b/thread/thread.cpp @@ -169,51 +169,6 @@ namespace photon void* _ptr; }; - #if defined(__has_feature) - # if __has_feature(address_sanitizer) // for clang - # define __SANITIZE_ADDRESS__ // GCC already sets this - # endif - #endif - - #ifdef __SANITIZE_ADDRESS__ - extern "C" { - // Check out sanitizer/asan-interface.h in compiler-rt for documentation. - 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** bottom_old, size_t* size_old); - } - - static void asan_start(void** save, thread* to) { - void* bottom = to->buf ? to->buf : to->stackful_alloc_top; - __sanitizer_start_switch_fiber(save, bottom, - to->stack_size); - } - - static void asan_finish(void* save) { - __sanitizer_finish_switch_fiber(save, nullptr, nullptr); - } - -#define ASAN_START() asan_finish((void*)nullptr); - -#define ASAN_SWITCH(to) \ - void* __save; \ - asan_start(&__save, to); \ - DEFER({ asan_finish(__save); }); - -#define ASAN_DIE_SWITCH(to) \ - asan_start(nullptr, to); - -#else -#define ASAN_START(ptr) -#define ASAN_SWITCH(to) -#define ASAN_DIE_SWITCH(to) -#endif - - static void _asan_start() asm("_asan_start"); - - __attribute__((used)) static void _asan_start() { ASAN_START(); } - struct thread_list; struct thread : public intrusive_list_node { volatile vcpu_t* vcpu; @@ -338,6 +293,51 @@ namespace photon } }; +#if defined(__has_feature) +# if __has_feature(address_sanitizer) // for clang +# define __SANITIZE_ADDRESS__ // GCC already sets this +# endif +#endif + +#ifdef __SANITIZE_ADDRESS__ + extern "C" { + // Check out sanitizer/asan-interface.h in compiler-rt for documentation. + 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** bottom_old, size_t* size_old); + } + + static void asan_start(void** save, thread* to) { + void* bottom = to->buf ? to->buf : to->stackful_alloc_top; + __sanitizer_start_switch_fiber(save, bottom, + to->stack_size); + } + + static void asan_finish(void* save) { + __sanitizer_finish_switch_fiber(save, nullptr, nullptr); + } + +#define ASAN_START() asan_finish((void*)nullptr); + +#define ASAN_SWITCH(to) \ + void* __save; \ + asan_start(&__save, to); \ + DEFER({ asan_finish(__save); }); + +#define ASAN_DIE_SWITCH(to) \ + asan_start(nullptr, to); + +#else +#define ASAN_START(ptr) +#define ASAN_SWITCH(to) +#define ASAN_DIE_SWITCH(to) +#endif + + static void _asan_start() asm("_asan_start"); + + __attribute__((used)) static void _asan_start() { ASAN_START(); } + #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Winvalid-offsetof" static_assert(offsetof(thread, vcpu) == offsetof(partial_thread, vcpu), "...");