Skip to content

Commit

Permalink
get_method_module_path
Browse files Browse the repository at this point in the history
  • Loading branch information
VSadov committed May 15, 2020
1 parent ba0e584 commit f71f944
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/installer/corehost/cli/fxr/hostfxr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ namespace
if (startup_info.dotnet_root.empty())
{
pal::string_t mod_path;
if (!pal::get_own_module_path(&mod_path))
if (!pal::get_method_module_path(&mod_path, (void*)&hostfxr_set_error_writer))
return StatusCode::CoreHostCurHostFindFailure;

startup_info.dotnet_root = get_dotnet_root_from_fxr_path(mod_path);
Expand Down
1 change: 1 addition & 0 deletions src/installer/corehost/cli/hostmisc/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ namespace pal

bool get_own_executable_path(string_t* recv);
bool get_own_module_path(string_t* recv);
bool get_method_module_path(string_t* recv, void* method);
bool get_module_path(dll_t mod, string_t* recv);
bool get_current_module(dll_t *mod);
bool getenv(const char_t* name, string_t* recv);
Expand Down
10 changes: 10 additions & 0 deletions src/installer/corehost/cli/hostmisc/pal.unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,16 @@ bool pal::get_own_module_path(string_t* recv)
return true;
}

bool pal::get_method_module_path(string_t* recv, void* method)
{
Dl_info info;
if (dladdr(method, &info) == 0)
return false;

recv->assign(info.dli_fname);
return true;
}

bool pal::get_module_path(dll_t module, string_t* recv)
{
return false;
Expand Down
10 changes: 10 additions & 0 deletions src/installer/corehost/cli/hostmisc/pal.windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,16 @@ bool pal::get_own_module_path(string_t* recv)
return GetModuleFileNameWrapper(hmod, recv);
}

bool pal::get_method_module_path(string_t* recv, void* method)
{
HMODULE hmod;
if (!GetModuleHandleFromAddress(method, &hmod))
return false;

return GetModuleFileNameWrapper(hmod, recv);
}


bool pal::get_module_path(dll_t mod, string_t* recv)
{
return GetModuleFileNameWrapper(mod, recv);
Expand Down

0 comments on commit f71f944

Please sign in to comment.