Skip to content

Commit

Permalink
更新 svuvm.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Dragon-Git authored Jul 1, 2024
1 parent fd853d1 commit 41e4394
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/pysvuvm/svuvm.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include <dlfcn.h>
#include <libgen.h>
#ifdef __APPLE__
#include <mach-o/dyld.h>
#endif
#include <pybind11/pybind11.h>
#include <pybind11/embed.h>
#include "svdpi.h"
Expand Down Expand Up @@ -58,10 +61,19 @@ void py_func(const char* mod_name, const char* func_name, const char* mod_paths)
}
}
#elif defined(__APPLE__)
uint32_t image_count = _dyld_image_count();
Dl_info dl_info;
if (dladdr((void*)py_func, &dl_info)) {
dir_path = dirname(const_cast<char*>(dl_info.dli_fname));
path.attr("append")(dir_path);

for(uint32_t i=0; i<image_count; i++) {
const char* image_name = _dyld_get_image_name(i);
const struct mach_header* header = _dyld_get_image_header(i);

if (dladdr(header, &dl_info) && info.dli_fbase == header) {
if ((intptr_t)py_func >= (intptr_t)header && (intptr_t)py_func < (intptr_t)header + _dyld_get_image_vmaddr_slide(i)) {
dir_path = dirname(const_cast<char*>(image_name));
path.attr("append")(dir_path);
}
}
}
#else
#error Platform not supported.
Expand Down

0 comments on commit 41e4394

Please sign in to comment.