From 16fcaf7099ca8e3d4bf1fc48fdd7dd8640959bfc Mon Sep 17 00:00:00 2001 From: openharmony_ci <120357966@qq.com> Date: Mon, 30 Jan 2023 01:11:32 +0000 Subject: [PATCH] =?UTF-8?q?!787=20=E5=A2=9E=E5=8A=A0dlclose=20debug?= =?UTF-8?q?=E5=BC=80=E5=85=B3=20Merge=20pull=20request=20!787=20from=20Map?= =?UTF-8?q?lestory=5Fzeng/master?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- porting/linux/user/ldso/dynlink.c | 15 ++++++++++++--- porting/linux/user/ldso/ld_log.c | 16 ++++++++++++++++ porting/linux/user/ldso/ld_log.h | 2 ++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/porting/linux/user/ldso/dynlink.c b/porting/linux/user/ldso/dynlink.c index 95516fb0..99fad6b7 100644 --- a/porting/linux/user/ldso/dynlink.c +++ b/porting/linux/user/ldso/dynlink.c @@ -1229,12 +1229,21 @@ static void unmap_library(struct dso *dso) for (i=0; iloadmap->nsegs; i++) { if (!dso->loadmap->segs[i].p_memsz) continue; - munmap((void *)dso->loadmap->segs[i].addr, - dso->loadmap->segs[i].p_memsz); + if (!is_dlclose_debug_enable()) { + munmap((void *)dso->loadmap->segs[i].addr, + dso->loadmap->segs[i].p_memsz); + } else { + (void)mprotect((void *)dso->loadmap->segs[i].addr, + dso->loadmap->segs[i].p_memsz, PROT_NONE); + } } internal_free(dso->loadmap); } else if (dso->map && dso->map_len) { - munmap(dso->map, dso->map_len); + if (!is_dlclose_debug_enable()) { + munmap(dso->map, dso->map_len); + } else { + mprotect(dso->map, dso->map_len, PROT_NONE); + } } } diff --git a/porting/linux/user/ldso/ld_log.c b/porting/linux/user/ldso/ld_log.c index bd1c5492..26d9d934 100644 --- a/porting/linux/user/ldso/ld_log.c +++ b/porting/linux/user/ldso/ld_log.c @@ -16,6 +16,7 @@ #include "ld_log.h" static bool ld_log_enable = false; +static bool ld_dlclose_debug = false; #ifdef OHOS_ENABLE_PARAMETER #include @@ -73,11 +74,21 @@ static bool get_ld_log_value() } return (get_bool_sysparam(app_param_handle) || get_bool_sysparam(all_param_handle)); } + +static bool get_ld_debug_dlclose_value() +{ + static CachedHandle param_handle = NULL; + if (param_handle == NULL) { + param_handle = CachedParameterCreate("musl.ld.debug.dlclose", "false"); + } + return get_bool_sysparam(param_handle); +} #endif void ld_log_reset() { #if (defined(OHOS_ENABLE_PARAMETER)) + ld_dlclose_debug = get_ld_debug_dlclose_value(); if (!is_musl_log_enable()) { ld_log_enable = false; return; @@ -92,3 +103,8 @@ bool get_ld_log_enable() { return ld_log_enable; } + +bool is_dlclose_debug_enable() +{ + return ld_dlclose_debug; +} diff --git a/porting/linux/user/ldso/ld_log.h b/porting/linux/user/ldso/ld_log.h index 9c51975c..697a01a0 100644 --- a/porting/linux/user/ldso/ld_log.h +++ b/porting/linux/user/ldso/ld_log.h @@ -34,6 +34,8 @@ extern "C" { hidden bool get_ld_log_enable(); hidden void ld_log_reset(); +hidden bool is_dlclose_debug_enable(); + #if ((LD_LOG_LEVEL & LD_LOG_ERROR) && (defined(OHOS_ENABLE_PARAMETER) || defined(ENABLE_MUSL_LOG))) #define LD_LOGE(...) if (get_ld_log_enable()) { \ (void)HiLogAdapterPrint(MUSL_LOG_TYPE, LOG_ERROR, MUSL_LOG_DOMAIN, LD_LOG_TAG, __VA_ARGS__); \ -- GitLab