提交 bc55a310 编写于 作者: M MapleStory

Add musl.dl.debug.dlclose param for debugging use-after-dlclose issues

If musl.dl.debug.dlclose is enabled, the sections of dlclosed library will not be unmapped.
Instead the mmap area will be set to PROT_NONE. If the program run into the dlclosed library
the crash log would contain the library info rather than a unmapped pc.
The param can be set by following cmdline:
param set musl.dl.debug.dlclose enable

Issue: I69Y3Z
Test: backtrace_local_test
Signed-off-by: NMapleStory <zengzhi5@huawei.com>
上级 f1936b48
......@@ -1199,12 +1199,21 @@ static void unmap_library(struct dso *dso)
for (i=0; i<dso->loadmap->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);
}
}
}
......
......@@ -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 <fcntl.h>
......@@ -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;
}
......@@ -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__); \
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册