From 3050e13f1182301fe080f9b84b1285bc5ac10178 Mon Sep 17 00:00:00 2001 From: liuyifei Date: Thu, 27 Mar 2025 03:38:00 +0000 Subject: [PATCH 1/6] =?UTF-8?q?=E5=BC=80=E5=90=AFCFI=E4=BD=BF=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liuyifei --- frameworks/hilog_ndk/BUILD.gn | 1 + frameworks/libhilog/BUILD.gn | 1 + interfaces/js/kits/napi/BUILD.gn | 2 ++ interfaces/native/innerkits/BUILD.gn | 2 ++ services/hilogd/BUILD.gn | 1 + services/hilogtool/BUILD.gn | 1 + 6 files changed, 8 insertions(+) diff --git a/frameworks/hilog_ndk/BUILD.gn b/frameworks/hilog_ndk/BUILD.gn index ff22b32..d69f53f 100644 --- a/frameworks/hilog_ndk/BUILD.gn +++ b/frameworks/hilog_ndk/BUILD.gn @@ -14,6 +14,7 @@ import("//build/ohos.gni") ohos_shared_library("hilog_ndk") { + branch_protector_ret = "pac_ret" sanitize = { cfi = true cfi_cross_dso = true diff --git a/frameworks/libhilog/BUILD.gn b/frameworks/libhilog/BUILD.gn index c8bbd92..e489ff2 100644 --- a/frameworks/libhilog/BUILD.gn +++ b/frameworks/libhilog/BUILD.gn @@ -41,6 +41,7 @@ config("libhilog_config") { template("libhilog_source") { forward_variables_from(invoker, "*") ohos_source_set(target_name) { + branch_protector_ret = "pac_ret" if (platform != "windows" && platform != "mac" && platform != "linux") { param_sources = [ "$param_root/properties.cpp" ] ioctl_sources = [ "$ioctl_root/log_ioctl.cpp" ] diff --git a/interfaces/js/kits/napi/BUILD.gn b/interfaces/js/kits/napi/BUILD.gn index 198c340..01fc374 100644 --- a/interfaces/js/kits/napi/BUILD.gn +++ b/interfaces/js/kits/napi/BUILD.gn @@ -15,6 +15,7 @@ import("//base/hiviewdfx/hilog/hilog.gni") import("//build/ohos.gni") ohos_source_set("libhilognapi_src") { + branch_protector_ret = "pac_ret" defines = [] include_dirs = [ "//base/hiviewdfx/hilog/frameworks/libhilog/param/include", @@ -65,6 +66,7 @@ config("libhilog_js_cfg") { } ohos_shared_library("libhilognapi") { + branch_protector_ret = "pac_ret" sanitize = { cfi = true cfi_cross_dso = true diff --git a/interfaces/native/innerkits/BUILD.gn b/interfaces/native/innerkits/BUILD.gn index 26c638b..6c147f1 100644 --- a/interfaces/native/innerkits/BUILD.gn +++ b/interfaces/native/innerkits/BUILD.gn @@ -25,6 +25,7 @@ config("libhilog_pub_config") { } if (is_mingw || is_mac || is_linux || is_ohos) { ohos_shared_library("libhilog") { + branch_protector_ret = "pac_ret" public_configs = [ ":libhilog_pub_config" ] if (is_ohos) { deps = [ "../../../frameworks/libhilog:libhilog_source_ohos" ] @@ -65,6 +66,7 @@ template("libhilog") { forward_variables_from(invoker, "*") if (current_os == "android" || current_os == "ios") { ohos_static_library(target_name) { + branch_protector_ret = "pac_ret" public_configs = [ ":libhilog_pub_config" ] deps = [ "../../../platform:libhilog_platform_source_$platform" ] diff --git a/services/hilogd/BUILD.gn b/services/hilogd/BUILD.gn index 9a5bbed..b1275b0 100644 --- a/services/hilogd/BUILD.gn +++ b/services/hilogd/BUILD.gn @@ -20,6 +20,7 @@ config("hilogd_config") { } ohos_executable("hilogd") { + branch_protector_ret = "pac_ret" sources = [ "cmd_executor.cpp", "flow_control.cpp", diff --git a/services/hilogtool/BUILD.gn b/services/hilogtool/BUILD.gn index aa7ea15..09998f6 100644 --- a/services/hilogtool/BUILD.gn +++ b/services/hilogtool/BUILD.gn @@ -20,6 +20,7 @@ config("hilog_config") { } ohos_executable("hilog") { + branch_protector_ret = "pac_ret" sources = [ "log_display.cpp", "main.cpp", -- Gitee From 5580e1ed962a5513eb992d721b23e8b49e6c455f Mon Sep 17 00:00:00 2001 From: liuyifei Date: Thu, 27 Mar 2025 09:43:00 +0000 Subject: [PATCH 2/6] update interfaces/native/innerkits/BUILD.gn. Signed-off-by: liuyifei --- interfaces/native/innerkits/BUILD.gn | 1 - 1 file changed, 1 deletion(-) diff --git a/interfaces/native/innerkits/BUILD.gn b/interfaces/native/innerkits/BUILD.gn index 6c147f1..05e096a 100644 --- a/interfaces/native/innerkits/BUILD.gn +++ b/interfaces/native/innerkits/BUILD.gn @@ -66,7 +66,6 @@ template("libhilog") { forward_variables_from(invoker, "*") if (current_os == "android" || current_os == "ios") { ohos_static_library(target_name) { - branch_protector_ret = "pac_ret" public_configs = [ ":libhilog_pub_config" ] deps = [ "../../../platform:libhilog_platform_source_$platform" ] -- Gitee From 55eac0137abc504368b9a868faeeee91eacd8029 Mon Sep 17 00:00:00 2001 From: liuyifei Date: Thu, 27 Mar 2025 11:54:11 +0000 Subject: [PATCH 3/6] update frameworks/libhilog/BUILD.gn. Signed-off-by: liuyifei --- frameworks/libhilog/BUILD.gn | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/frameworks/libhilog/BUILD.gn b/frameworks/libhilog/BUILD.gn index e489ff2..e201517 100644 --- a/frameworks/libhilog/BUILD.gn +++ b/frameworks/libhilog/BUILD.gn @@ -42,6 +42,11 @@ template("libhilog_source") { forward_variables_from(invoker, "*") ohos_source_set(target_name) { branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } if (platform != "windows" && platform != "mac" && platform != "linux") { param_sources = [ "$param_root/properties.cpp" ] ioctl_sources = [ "$ioctl_root/log_ioctl.cpp" ] -- Gitee From 2788d40baf614721bd8f904cfdd473b058795c06 Mon Sep 17 00:00:00 2001 From: buzhenwang Date: Sat, 19 Apr 2025 10:40:16 +0800 Subject: [PATCH 4/6] add support for printing ts object Signed-off-by: liuyifei --- .../js/kits/napi/src/common/napi/n_val.cpp | 48 ++++++++++++++++++- .../js/kits/napi/src/common/napi/n_val.h | 6 +++ .../js/kits/napi/src/common/napi/uni_header.h | 4 -- .../napi/src/hilog/src/hilog_napi_base.cpp | 9 ++-- 4 files changed, 59 insertions(+), 8 deletions(-) diff --git a/interfaces/js/kits/napi/src/common/napi/n_val.cpp b/interfaces/js/kits/napi/src/common/napi/n_val.cpp index e97f317..4a982d2 100644 --- a/interfaces/js/kits/napi/src/common/napi/n_val.cpp +++ b/interfaces/js/kits/napi/src/common/napi/n_val.cpp @@ -30,13 +30,18 @@ NVal::operator bool() const } bool NVal::TypeIs(napi_valuetype expType) const +{ + return ValueTypeIs(val_, expType); +} + +bool NVal::ValueTypeIs(napi_value value, napi_valuetype expType) const { if (!*this) { return false; } napi_valuetype valueType; - napi_typeof(env_, val_, &valueType); + napi_typeof(env_, value, &valueType); if (expType != valueType) { return false; @@ -173,6 +178,47 @@ tuple NVal::ToTypedArrayInfo return make_tuple(status == napi_ok, data, length, byte_offset, type); } +string NVal::GetPrintString(napi_value value) const +{ + string str; + if (!ValueTypeIs(value, napi_string)) { + napi_value strValue = nullptr; + if (napi_coerce_to_string(env_, value, &strValue) != napi_ok) { + return str; + } + value = strValue; + } + napi_get_print_string(env_, value, str); + return str; +} + +tuple NVal::GetValObjectAsStr() const +{ + napi_value globalValue = nullptr; + auto fail = make_tuple(false, ""); + napi_status status = napi_get_global(env_, &globalValue); + if (status != napi_ok) { + return fail; + } + napi_value jsonValue = nullptr; + status = napi_get_named_property(env_, globalValue, "JSON", &jsonValue); + if (status != napi_ok) { + return fail; + } + napi_value stringifyValue = nullptr; + status = napi_get_named_property(env_, jsonValue, "stringify", &stringifyValue); + if (status != napi_ok) { + return fail; + } + napi_value transValue = nullptr; + status = napi_call_function(env_, jsonValue, stringifyValue, 1, &val_, &transValue); + if (status != napi_ok || transValue == nullptr) { + return fail; + } + string content = GetPrintString(transValue); + return make_tuple(true, content); +} + bool NVal::HasProp(string propName) const { bool res = false; diff --git a/interfaces/js/kits/napi/src/common/napi/n_val.h b/interfaces/js/kits/napi/src/common/napi/n_val.h index e2ed44d..2a0e1ab 100644 --- a/interfaces/js/kits/napi/src/common/napi/n_val.h +++ b/interfaces/js/kits/napi/src/common/napi/n_val.h @@ -41,6 +41,8 @@ public: bool TypeIs(napi_valuetype expType) const; + bool ValueTypeIs(napi_value value, napi_valuetype expType) const; + /* SHOULD ONLY BE USED FOR EXPECTED TYPE */ std::tuple, size_t> ToUTF8String() const; @@ -68,6 +70,8 @@ public: std::tuple ToTypedArrayInfo() const; + std::tuple GetValObjectAsStr() const; + /* Static helpers to create js objects */ static NVal CreateUndefined(napi_env env); @@ -109,6 +113,8 @@ public: static inline napi_property_descriptor DeclareNapiGetterSetter(const char *name, napi_callback getter, napi_callback setter); +private: + std::string GetPrintString(napi_value value) const; }; } // namespace HiviewDFX } // namespace OHOS diff --git a/interfaces/js/kits/napi/src/common/napi/uni_header.h b/interfaces/js/kits/napi/src/common/napi/uni_header.h index d000d78..5de61d6 100644 --- a/interfaces/js/kits/napi/src/common/napi/uni_header.h +++ b/interfaces/js/kits/napi/src/common/napi/uni_header.h @@ -15,10 +15,6 @@ #ifndef INTERFACES_JS_KITS_NAPI_SRC_COMMON_NAPI_UNI_HEADER_H #define INTERFACES_JS_KITS_NAPI_SRC_COMMON_NAPI_UNI_HEADER_H -#pragma once - -#include -#else #include "napi/native_api.h" #include "napi/native_node_api.h" diff --git a/interfaces/js/kits/napi/src/hilog/src/hilog_napi_base.cpp b/interfaces/js/kits/napi/src/hilog/src/hilog_napi_base.cpp index 4e5ca26..4de4ba4 100644 --- a/interfaces/js/kits/napi/src/hilog/src/hilog_napi_base.cpp +++ b/interfaces/js/kits/napi/src/hilog/src/hilog_napi_base.cpp @@ -95,7 +95,8 @@ void ParseLogContent(string& formatStr, vector& params, string& logCo break; case 'O': case 'o': - if (params[count].type == napi_object) { + if (params[count].type == napi_object || params[count].type == napi_function || + params[count].type == napi_undefined || params[count].type == napi_null) { ret += (priv && showPriv) ? PRIV_STR : params[count].val; } count++; @@ -223,8 +224,8 @@ napi_value HilogNapiBase::parseNapiValue(napi_env env, napi_callback_info info, if (typeStatus != napi_ok) { return nullptr; } - if (type == napi_number || type == napi_bigint || type == napi_object || - type == napi_undefined || type == napi_boolean || type == napi_null) { + if (type == napi_number || type == napi_bigint || type == napi_undefined || + type == napi_boolean || type == napi_null) { napi_value elmString; napi_status objectStatus = napi_coerce_to_string(env, element, &elmString); if (objectStatus != napi_ok) { @@ -234,6 +235,8 @@ napi_value HilogNapiBase::parseNapiValue(napi_env env, napi_callback_info info, if (!succ) { return nullptr; } + } else if (type == napi_object || type == napi_function) { + tie(succ, res.val) = NVal(env, element).GetValObjectAsStr(); } else if (type == napi_string) { tie(succ, name, ignore) = NVal(env, element).ToUTF8String(); if (!succ) { -- Gitee From 63ad14c457409d0e9fcecdbea50adf4ba82feb07 Mon Sep 17 00:00:00 2001 From: liuyifei Date: Tue, 6 May 2025 01:48:11 +0000 Subject: [PATCH 5/6] update interfaces/native/innerkits/BUILD.gn. Signed-off-by: liuyifei --- interfaces/native/innerkits/BUILD.gn | 1 - 1 file changed, 1 deletion(-) diff --git a/interfaces/native/innerkits/BUILD.gn b/interfaces/native/innerkits/BUILD.gn index 540b9f8..8c43d64 100644 --- a/interfaces/native/innerkits/BUILD.gn +++ b/interfaces/native/innerkits/BUILD.gn @@ -25,7 +25,6 @@ config("libhilog_pub_config") { } if (is_mingw || is_mac || is_linux || is_ohos) { ohos_shared_library("libhilog") { - branch_protector_ret = "pac_ret" public_configs = [ ":libhilog_pub_config" ] if (is_ohos) { deps = [ "../../../frameworks/libhilog:libhilog_source_ohos" ] -- Gitee From 61366c239902f48736f31c16ea7e021bbea395d1 Mon Sep 17 00:00:00 2001 From: liuyifei Date: Tue, 6 May 2025 01:48:45 +0000 Subject: [PATCH 6/6] update interfaces/js/kits/napi/BUILD.gn. Signed-off-by: liuyifei --- interfaces/js/kits/napi/BUILD.gn | 2 -- 1 file changed, 2 deletions(-) diff --git a/interfaces/js/kits/napi/BUILD.gn b/interfaces/js/kits/napi/BUILD.gn index 01fc374..198c340 100644 --- a/interfaces/js/kits/napi/BUILD.gn +++ b/interfaces/js/kits/napi/BUILD.gn @@ -15,7 +15,6 @@ import("//base/hiviewdfx/hilog/hilog.gni") import("//build/ohos.gni") ohos_source_set("libhilognapi_src") { - branch_protector_ret = "pac_ret" defines = [] include_dirs = [ "//base/hiviewdfx/hilog/frameworks/libhilog/param/include", @@ -66,7 +65,6 @@ config("libhilog_js_cfg") { } ohos_shared_library("libhilognapi") { - branch_protector_ret = "pac_ret" sanitize = { cfi = true cfi_cross_dso = true -- Gitee