From 8d740d4b41b1132ec2511a375ebb9fee0059784f Mon Sep 17 00:00:00 2001 From: ZhangLiang Date: Mon, 24 Mar 2025 07:31:01 +0000 Subject: [PATCH] =?UTF-8?q?=E6=8A=93=E5=B8=A7=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ZhangLiang Change-Id: I62d94e02655ee9358e1828baf8d183d1272a7fdb --- loader/loader.c | 59 +++++++++++++++---- .../vk_bundle_mgr_helper.cpp | 15 +++++ .../bundle_mgr_helper/vk_bundle_mgr_helper.h | 2 +- 3 files changed, 63 insertions(+), 13 deletions(-) diff --git a/loader/loader.c b/loader/loader.c index ed30f9e0..d38a023c 100644 --- a/loader/loader.c +++ b/loader/loader.c @@ -2897,6 +2897,7 @@ VkResult add_data_files(const struct loader_instance *inst, char *search_path, s break; } } else { // Otherwise, treat it as a directory + dir_stream = loader_opendir(inst, cur_file); if (NULL == dir_stream) { continue; @@ -2932,6 +2933,7 @@ VkResult add_data_files(const struct loader_instance *inst, char *search_path, s } } + out: return vk_result; @@ -3024,24 +3026,41 @@ VkResult read_data_files_in_search_paths(const struct loader_instance *inst, enu #if defined(__OHOS__) char *debug_layer_name = loader_secure_getenv("debug.graphic.debug_layer", inst); // squid squidsubcapture char *debug_hap_name = loader_secure_getenv("debug.graphic.debug_hap", inst); + char *system_debug_hap_name = loader_secure_getenv("debug.graphic.system_layer_flag", inst); char *debug_layer_json_path = NULL; - + bool use_system_layer = false; + if (NULL != system_debug_hap_name && '\0' != system_debug_hap_name[0]) { + if (strcmp(system_debug_hap_name, "1") == 0) { + use_system_layer = true; + } + } bool currentProcessEnableDebugLayer = false; + bool debug_layer_use_heap = false; if (NULL != debug_layer_name && '\0' != debug_layer_name[0] && InitBundleInfo(debug_hap_name)) { currentProcessEnableDebugLayer = true; + const char default_json_path[] = "/data/storage/el2/base/haps/entry/files/"; + const char external_system_json_path[] = "/vendor/etc/vulkan/debuglayer/"; + const char json_suffix[] = ".json"; + size_t max_len = sizeof(default_json_path); + if (max_len < sizeof(external_system_json_path)) { + max_len = sizeof(external_system_json_path); + } + size_t debug_layer_json_path_len = max_len + sizeof(debug_layer_name) + sizeof(json_suffix) +1; debug_layer_json_path = loader_secure_getenv("debug.graphic.vklayer_json_path",inst); if (NULL == debug_layer_json_path || '\0' == debug_layer_json_path[0]){ - const char default_json_path[] = "/data/storage/el2/base/haps/entry/files/"; - const char json_suffix[] = ".json"; - size_t debug_layer_json_path_len = strlen(default_json_path) + sizeof(debug_layer_name) + sizeof(json_suffix) +1; debug_layer_json_path = loader_instance_heap_calloc(inst,debug_layer_json_path_len,VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); if(debug_layer_json_path == NULL){ vk_result = VK_ERROR_OUT_OF_HOST_MEMORY; goto out; + } + debug_layer_use_heap = true; + if (use_system_layer && CheckAppProvisionTypeIsDebug()) { + strncpy(debug_layer_json_path,external_system_json_path,debug_layer_json_path_len); + } else { + strncpy(debug_layer_json_path,default_json_path,debug_layer_json_path_len); } - strncpy(debug_layer_json_path,default_json_path,debug_layer_json_path_len); strncat(debug_layer_json_path,debug_layer_name,debug_layer_json_path_len); - strncat(debug_layer_json_path,json_suffix,debug_layer_json_path_len); + strncat(debug_layer_json_path,json_suffix,debug_layer_json_path_len); } loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "OHOS:: debug_layer_json_path: %s", debug_layer_json_path); } @@ -3341,7 +3360,11 @@ out: loader_instance_heap_free(inst, default_config_home); #elif defined(__OHOS__) if(currentProcessEnableDebugLayer){ - loader_free_getenv(debug_layer_json_path, inst); + if (debug_layer_use_heap) { + loader_instance_heap_free(inst, debug_layer_json_path); + } else { + loader_free_getenv(debug_layer_json_path, inst); + } } loader_free_getenv(debug_layer_name, inst); loader_free_getenv(debug_hap_name, inst); @@ -4166,14 +4189,25 @@ struct loader_instance *loader_get_instance(const VkInstance instance) { loader_platform_dl_handle loader_open_layer_file(const struct loader_instance *inst, struct loader_layer_properties *prop) { char* libPath = prop->lib_name; + loader_log(inst, VULKAN_LOADER_DEBUG_BIT | VULKAN_LOADER_LAYER_BIT, 0, "try to open json libPath: %s", libPath); + if ((prop->lib_handle = loader_platform_open_library(libPath)) == NULL) { + loader_log(inst, VULKAN_LOADER_ERROR_BIT | VULKAN_LOADER_LAYER_BIT, 0, "Loading layer library open_library %s is error", libPath); + loader_handle_load_library_error(inst, libPath, &prop->lib_status); + } else { + prop->lib_status = LOADER_LAYER_LIB_SUCCESS_LOADED; + return prop->lib_handle; + } + #if defined(__OHOS__) char *debug_layer_name = loader_secure_getenv("debug.graphic.debug_layer", inst); char *debug_hap_name = loader_secure_getenv("debug.graphic.debug_hap", inst); bool isDebugLayer = false; char* debugLayerLibPath = NULL; + if (NULL != debug_layer_name && '\0' != debug_layer_name[0] && InitBundleInfo(debug_hap_name)) { const char lib_prefix[] = "lib"; const char so_suffix[] = ".so"; + size_t totalLen = strlen(debug_layer_name) + strlen(lib_prefix) + strlen(so_suffix) + 1; char* layerSoName = loader_instance_heap_calloc(inst, totalLen, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); if (layerSoName == NULL) { @@ -4183,6 +4217,7 @@ loader_platform_dl_handle loader_open_layer_file(const struct loader_instance *i strncpy(layerSoName, lib_prefix, totalLen); strncat(layerSoName, debug_layer_name, totalLen); strncat(layerSoName, so_suffix, totalLen); + if (strcmp(layerSoName, libPath) == 0) { isDebugLayer = true; debugLayerLibPath = GetDebugLayerLibPath(inst, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); @@ -4212,20 +4247,20 @@ loader_platform_dl_handle loader_open_layer_file(const struct loader_instance *i mallocErr: loader_free_getenv(debug_layer_name, inst); loader_free_getenv(debug_hap_name, inst); -#endif - loader_log(inst, VULKAN_LOADER_DEBUG_BIT | VULKAN_LOADER_LAYER_BIT, 0, "try to open libPath: %s", libPath); + + loader_log(inst, VULKAN_LOADER_DEBUG_BIT | VULKAN_LOADER_LAYER_BIT, 0, "try to open hap libPath: %s", libPath); if ((prop->lib_handle = loader_platform_open_library(libPath)) == NULL) { - loader_handle_load_library_error(inst, prop->lib_name, &prop->lib_status); + loader_log(inst, VULKAN_LOADER_ERROR_BIT | VULKAN_LOADER_LAYER_BIT, 0, "Loading layer library open_library %s is error", libPath); + loader_handle_load_library_error(inst, libPath, &prop->lib_status); } else { prop->lib_status = LOADER_LAYER_LIB_SUCCESS_LOADED; - loader_log(inst, VULKAN_LOADER_DEBUG_BIT | VULKAN_LOADER_LAYER_BIT, 0, "Loading layer library %s", prop->lib_name); } -#if defined(__OHOS__) if (isDebugLayer) { loader_instance_heap_free(inst, debugLayerLibPath); loader_instance_heap_free(inst, libPath); } #endif + return prop->lib_handle; } diff --git a/openharmony/bundle_mgr_helper/vk_bundle_mgr_helper.cpp b/openharmony/bundle_mgr_helper/vk_bundle_mgr_helper.cpp index 6d2123a7..708027a2 100644 --- a/openharmony/bundle_mgr_helper/vk_bundle_mgr_helper.cpp +++ b/openharmony/bundle_mgr_helper/vk_bundle_mgr_helper.cpp @@ -54,6 +54,21 @@ bool InitBundleInfo(char* debugHapName) return false; } +bool CheckAppProvisionTypeIsDebug() +{ + auto vkBundleMgrHelper = OHOS::DelayedSingleton::GetInstance(); + if (vkBundleMgrHelper == nullptr) { + VKHILOGE("vkBundleMgrHelper is null!"); + return false; + } + VKHILOGD("this hap is %{public}s, the debug hap appProvisionType is %{public}s", + vkBundleMgrHelper->g_bundleInfo.name.c_str(), vkBundleMgrHelper->g_bundleInfo.applicationInfo.appProvisionType.c_str()); + if (vkBundleMgrHelper->g_bundleInfo.applicationInfo.appProvisionType == "release") { + return false; + } + return true; +} + char* GetDebugLayerLibPath(const struct loader_instance *inst, VkSystemAllocationScope allocation_sacope) { auto vkBundleMgrHelper = OHOS::DelayedSingleton::GetInstance(); diff --git a/openharmony/bundle_mgr_helper/vk_bundle_mgr_helper.h b/openharmony/bundle_mgr_helper/vk_bundle_mgr_helper.h index 20bb67e8..0147ea0d 100644 --- a/openharmony/bundle_mgr_helper/vk_bundle_mgr_helper.h +++ b/openharmony/bundle_mgr_helper/vk_bundle_mgr_helper.h @@ -25,7 +25,7 @@ extern "C" { bool InitBundleInfo(char* debugHapName); char* GetDebugLayerLibPath(const struct loader_instance *inst, VkSystemAllocationScope allocation_sacope); - +bool CheckAppProvisionTypeIsDebug(); #ifdef __cplusplus } namespace OHOS { -- Gitee