From 87b691b8ab2428b8bccda70183085efaf8e3662e Mon Sep 17 00:00:00 2001 From: Adeel <3840695+am11@users.noreply.github.com> Date: Wed, 30 Nov 2022 02:58:37 +0200 Subject: [PATCH 1/2] Move AT_EXECFN to fallback for /proc/self/exe --- src/native/minipal/getexepath.h | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/native/minipal/getexepath.h b/src/native/minipal/getexepath.h index 0db1b73aa6f011..55a3266e283574 100644 --- a/src/native/minipal/getexepath.h +++ b/src/native/minipal/getexepath.h @@ -75,13 +75,6 @@ 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 @@ -89,7 +82,21 @@ static inline char* minipal_getexepath(void) #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) #endif // defined(__APPLE__) } From fb3617ff9f8cbc5d37b86e08949457d0bed511da Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <3840695+am11@users.noreply.github.com> Date: Wed, 30 Nov 2022 03:19:07 +0200 Subject: [PATCH 2/2] Update src/native/minipal/getexepath.h --- src/native/minipal/getexepath.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/native/minipal/getexepath.h b/src/native/minipal/getexepath.h index 55a3266e283574..af0f4042350131 100644 --- a/src/native/minipal/getexepath.h +++ b/src/native/minipal/getexepath.h @@ -97,6 +97,8 @@ static inline char* minipal_getexepath(void) return realpath(exePath, NULL); } #endif // HAVE_GETAUXVAL && defined(AT_EXECFN) + + return NULL; #endif // defined(__APPLE__) }