Skip to content
Merged
Changes from all commits
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
25 changes: 17 additions & 8 deletions src/native/minipal/getexepath.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,30 @@ static inline char* minipal_getexepath(void)
// This is a packaging convention that our tooling should enforce.
return strdup("/managed");
#else
#if HAVE_GETAUXVAL && defined(AT_EXECFN)
const char* path = (const char *)(getauxval(AT_EXECFN));
if (path && !errno)
{
return realpath(path, NULL);
}
#endif // HAVE_GETAUXVAL && defined(AT_EXECFN)
#ifdef __linux__
const char* symlinkEntrypointExecutable = "/proc/self/exe";
#else
const char* symlinkEntrypointExecutable = "/proc/curproc/exe";
#endif

// Resolve the symlink to the executable from /proc
return realpath(symlinkEntrypointExecutable, NULL);
char* path = realpath(symlinkEntrypointExecutable, NULL);
if (path)
{
return path;
}

#if HAVE_GETAUXVAL && defined(AT_EXECFN)
// fallback to AT_EXECFN, which does not work properly in rare cases
// when .NET process is set as interpreter (shebang).
const char* exePath = (const char *)(getauxval(AT_EXECFN));
if (exePath && !errno)
{
return realpath(exePath, NULL);
}
#endif // HAVE_GETAUXVAL && defined(AT_EXECFN)

return NULL;
#endif // defined(__APPLE__)
}

Expand Down