Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
v5
  • Loading branch information
zhengyu123 committed Jul 11, 2025
commit b8615978ebda04c663720e5e07dc462db4d4d2c0
4 changes: 3 additions & 1 deletion ddprof-lib/src/main/cpp/codeCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ char *NativeFunc::create(const char *name, short lib_index) {
void NativeFunc::destroy(char *name) { free(from(name)); }

CodeCache::CodeCache(const char *name, short lib_index, bool imports_patchable,
const void *min_address, const void *max_address) {
const void *min_address, const void *max_address,
const char* image_base) {
_name = NativeFunc::create(name, -1);
_lib_index = lib_index;
_min_address = min_address;
_max_address = max_address;
_text_base = NULL;
_image_base = image_base;

_plt_offset = 0;
_plt_size = 0;
Expand Down
6 changes: 5 additions & 1 deletion ddprof-lib/src/main/cpp/codeCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class CodeCache {
const void *_min_address;
const void *_max_address;
const char *_text_base;
const char* _image_base;

unsigned int _plt_offset;
unsigned int _plt_size;
Expand All @@ -132,7 +133,8 @@ class CodeCache {
explicit CodeCache(const char *name, short lib_index = -1,
bool imports_patchable = false,
const void *min_address = NO_MIN_ADDRESS,
const void *max_address = NO_MAX_ADDRESS);
const void *max_address = NO_MAX_ADDRESS,
const char* image_base = NULL);
// Copy constructor
CodeCache(const CodeCache &other);
// Copy assignment operator
Expand All @@ -148,6 +150,8 @@ class CodeCache {

const void *maxAddress() const { return _max_address; }

const char* imageBase() const { return _image_base; }

bool contains(const void *address) const {
return address >= _min_address && address < _max_address;
}
Expand Down
12 changes: 10 additions & 2 deletions ddprof-lib/src/main/cpp/symbols_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ void Symbols::parseLibraries(CodeCacheArray *array, bool kernel_symbols) {
_parsed_inodes.insert(inode);

SharedLibrary& lib = it.second;
CodeCache* cc = new CodeCache(lib.file, array->count(), false, lib.map_start, lib.map_end);
CodeCache* cc = new CodeCache(lib.file, array->count(), false, lib.map_start, lib.map_end, lib.image_base);

// Strip " (deleted)" suffix so that removed library can be reopened
size_t len = strlen(lib.file);
Expand Down Expand Up @@ -681,8 +681,16 @@ static bool verifyBaseAddress(const CodeCache* cc, void* lib_handle) {
return cc->imageBase() == (const char*)dl_info.dli_fbase;
}

static bool isMainExecutable(const char* image_base, const void* map_end) {
return _main_phdr != NULL && _main_phdr >= image_base && _main_phdr < map_end;
}

static bool isLoader(const char* image_base) {
return _ld_base == image_base;
}

UnloadProtection::UnloadProtection(const CodeCache *cc) {
if (OS::isMusl() || isMainExecutable(cc->imageBase(), cc->maxAddress()) || isLoader(cc->imageBase())) {
if (MUSL || isMainExecutable(cc->imageBase(), cc->maxAddress()) || isLoader(cc->imageBase())) {
_lib_handle = NULL;
_valid = true;
return;
Expand Down