From 9161df6d9d16e21440fd8f08982f2418a6b331d5 Mon Sep 17 00:00:00 2001 From: JustinYT Date: Wed, 4 Jun 2025 10:58:47 +0800 Subject: [PATCH] adjsut gn build for smartperf_host Signed-off-by: JustinYT --- common/dfxutil/dfx_util.cpp | 4 ++ common/dfxutil/string_view_util.h | 45 +++++++++++++++++++ interfaces/common/byte_order.h | 2 +- .../unwinder/include/dfx_elf_define.h | 2 +- .../unwinder/include/dfx_elf_parser.h | 2 +- .../innerkits/unwinder/src/elf/dfx_elf.cpp | 2 +- .../unwinder/src/elf/elf_factory.cpp | 12 +++++ 7 files changed, 65 insertions(+), 4 deletions(-) diff --git a/common/dfxutil/dfx_util.cpp b/common/dfxutil/dfx_util.cpp index a90f4303c..9429fd431 100644 --- a/common/dfxutil/dfx_util.cpp +++ b/common/dfxutil/dfx_util.cpp @@ -229,7 +229,11 @@ bool ReadFdToString(int fd, std::string& content) void CloseFd(int &fd) { if (fd > 0) { +#if is_ohos fdsan_close_with_tag(fd, fdsan_create_owner_tag(FDSAN_OWNER_TYPE_FILE, LOG_DOMAIN)); +#else + close(fd); +#endif fd = -1; } } diff --git a/common/dfxutil/string_view_util.h b/common/dfxutil/string_view_util.h index b44a59ea7..7dbd3568d 100644 --- a/common/dfxutil/string_view_util.h +++ b/common/dfxutil/string_view_util.h @@ -24,6 +24,24 @@ namespace OHOS { namespace HiviewDFX { +#ifdef is_mac +class SpinLock { +public: + void lock() + { + while (locked_.test_and_set(std::memory_order_acquire)) { + ; + } + } + void unlock() + { + locked_.clear(std::memory_order_release); + } + +private: + std::atomic_flag locked_ = ATOMIC_FLAG_INIT; +}; +#endif class StringViewHold { public: static StringViewHold &Get() @@ -34,50 +52,77 @@ public: const char* Hold(STRING_VIEW view) { +#ifndef is_mac pthread_spin_lock(&spin_lock_); +#else + std::lock_guard lockGurand(spinlock_); +#endif if (view.size() == 0) { +#ifndef is_mac pthread_spin_unlock(&spin_lock_); +#endif return ""; } char *p = new (std::nothrow) char[view.size() + 1]; if (p == nullptr) { +#ifndef is_mac pthread_spin_unlock(&spin_lock_); +#endif return ""; } if (memset_s(p, view.size() + 1, '\0', view.size() + 1) != 0) { +#ifndef is_mac pthread_spin_unlock(&spin_lock_); +#endif return ""; } std::copy(view.data(), view.data() + view.size(), p); views_.emplace_back(p); +#ifndef is_mac pthread_spin_unlock(&spin_lock_); +#endif return p; } // only use in UT void Clean() { +#ifndef is_mac pthread_spin_lock(&spin_lock_); +#else + std::lock_guard lockGurand(spinlock_); +#endif for (auto &p : views_) { delete[] p; } views_.clear(); +#ifndef is_mac pthread_spin_unlock(&spin_lock_); +#endif } + private: +#ifndef is_mac StringViewHold() { pthread_spin_init(&spin_lock_, PTHREAD_PROCESS_PRIVATE); } +#endif ~StringViewHold() { Clean(); +#ifndef is_mac pthread_spin_destroy(&spin_lock_); +#endif } std::vector views_; +#ifndef is_mac pthread_spinlock_t spin_lock_; +#else + SpinLock spinlock_; +#endif }; } // namespace HiviewDFX } // namespace OHOS diff --git a/interfaces/common/byte_order.h b/interfaces/common/byte_order.h index 3c40993ec..a55d9db07 100644 --- a/interfaces/common/byte_order.h +++ b/interfaces/common/byte_order.h @@ -16,7 +16,7 @@ #ifndef BYTE_ORDER_H #define BYTE_ORDER_H -#if is_mingw +#if is_mingw || is_mac #define UNWIND_LITTLE_ENDIAN 1234 #define UNWIND_BIG_ENDIAN 4321 #define UNWIND_BYTE_ORDER -1 // Unknown diff --git a/interfaces/innerkits/unwinder/include/dfx_elf_define.h b/interfaces/innerkits/unwinder/include/dfx_elf_define.h index 6bc939491..a71d76b56 100644 --- a/interfaces/innerkits/unwinder/include/dfx_elf_define.h +++ b/interfaces/innerkits/unwinder/include/dfx_elf_define.h @@ -17,7 +17,7 @@ #include #include -#if !is_mingw +#if !is_mingw && !is_mac #include #include #endif diff --git a/interfaces/innerkits/unwinder/include/dfx_elf_parser.h b/interfaces/innerkits/unwinder/include/dfx_elf_parser.h index b4c844377..86a4bdd19 100644 --- a/interfaces/innerkits/unwinder/include/dfx_elf_parser.h +++ b/interfaces/innerkits/unwinder/include/dfx_elf_parser.h @@ -16,7 +16,7 @@ #define DFX_ELF_PARSER_H #include -#if is_mingw +#if is_mingw || is_mac #include "dfx_nonlinux_define.h" #else #include diff --git a/interfaces/innerkits/unwinder/src/elf/dfx_elf.cpp b/interfaces/innerkits/unwinder/src/elf/dfx_elf.cpp index 9398e59ac..d071f2b93 100644 --- a/interfaces/innerkits/unwinder/src/elf/dfx_elf.cpp +++ b/interfaces/innerkits/unwinder/src/elf/dfx_elf.cpp @@ -20,7 +20,7 @@ #include #include #include -#if is_mingw +#if is_mingw || is_mac #include "dfx_nonlinux_define.h" #else #include diff --git a/interfaces/innerkits/unwinder/src/elf/elf_factory.cpp b/interfaces/innerkits/unwinder/src/elf/elf_factory.cpp index cbe670628..52ced5315 100644 --- a/interfaces/innerkits/unwinder/src/elf/elf_factory.cpp +++ b/interfaces/innerkits/unwinder/src/elf/elf_factory.cpp @@ -151,8 +151,10 @@ std::shared_ptr RegularElfFactory::Create() DFXLOGE("Failed to open file: %{public}s, errno(%{public}d)", filePath_.c_str(), errno); return regularElf; } +#if is_ohos uint64_t ownerTag = fdsan_create_owner_tag(FDSAN_OWNER_TYPE_FILE, LOG_DOMAIN); fdsan_exchange_owner_tag(fd, 0, ownerTag); +#endif do { auto size = static_cast(GetFileSize(fd)); auto mMap = std::make_shared(); @@ -162,7 +164,11 @@ std::shared_ptr RegularElfFactory::Create() } regularElf->SetMmap(mMap); } while (false); +#if is_ohos fdsan_close_with_tag(fd, ownerTag); +#else + close(fd); +#endif return regularElf; } @@ -215,8 +221,10 @@ std::shared_ptr CompressHapElfFactory::Create() DFXLOGE("Failed to open hap file, errno(%{public}d)", errno); return nullptr; } +#if is_ohos uint64_t ownerTag = fdsan_create_owner_tag(FDSAN_OWNER_TYPE_FILE, LOG_DOMAIN); fdsan_exchange_owner_tag(fd, 0, ownerTag); +#endif std::shared_ptr compressHapElf = nullptr; do { size_t elfSize = 0; @@ -237,7 +245,11 @@ std::shared_ptr CompressHapElfFactory::Create() break; } } while (false); +#if is_ohos fdsan_close_with_tag(fd, ownerTag); +#else + close(fd); +#endif return compressHapElf; } -- Gitee