diff --git a/src/mono/CMakeLists.txt b/src/mono/CMakeLists.txt index 823926370dd4ad..7a9e8c552ae25b 100644 --- a/src/mono/CMakeLists.txt +++ b/src/mono/CMakeLists.txt @@ -6,6 +6,8 @@ endif() project(mono) +include(../../eng/native/configurepaths.cmake) + set(CMAKE_C_FLAGS_CHECKED "") set(CMAKE_CXX_FLAGS_CHECKED "") set(CMAKE_EXE_LINKER_FLAGS_CHECKED "") @@ -586,7 +588,7 @@ endif() ###################################### # ICU CHECKS ###################################### -set(ICU_SHIM_PATH "../../../libraries/Native/Unix/System.Globalization.Native") +set(ICU_SHIM_PATH "${CLR_SRC_LIBS_NATIVE_DIR}/Unix/System.Globalization.Native") if(MONO_CROSS_COMPILE) elseif(HOST_OSX AND NOT HOST_MACCAT) include(FindPkgConfig) @@ -809,6 +811,7 @@ if (TARGET_BROWSER) endif() ### End of OS specific checks +include_directories("${CLR_SRC_NATIVE_DIR}/common") add_subdirectory(mono) if (ENABLE_MSCORDBI AND NOT TARGET_ARCH STREQUAL "arm64" AND NOT CMAKE_CROSSCOMPILING AND NOT TARGET_IOS AND NOT TARGET_ANDROID AND NOT TARGET_BROWSER AND NOT HOST_MACCAT) add_subdirectory(dlls/mscordbi) diff --git a/src/mono/cmake/config.h.in b/src/mono/cmake/config.h.in index 136a22bbe1dd5f..48a82ec6db8c4c 100644 --- a/src/mono/cmake/config.h.in +++ b/src/mono/cmake/config.h.in @@ -595,6 +595,8 @@ /* Define to 1 if you have the `pthread_jit_write_protect_np' function. */ #cmakedefine HAVE_PTHREAD_JIT_WRITE_PROTECT_NP 1 +#cmakedefine01 HAVE_GETAUXVAL + /* Define to 1 if you have the declaration of `pthread_mutexattr_setprotocol', and to 0 if you don't. */ #cmakedefine HAVE_DECL_PTHREAD_MUTEXATTR_SETPROTOCOL 1 diff --git a/src/mono/cmake/configure.cmake b/src/mono/cmake/configure.cmake index 5bad48a719b856..7bee1c6b98553a 100644 --- a/src/mono/cmake/configure.cmake +++ b/src/mono/cmake/configure.cmake @@ -103,6 +103,7 @@ check_symbol_exists(CLOCK_MONOTONIC "time.h" HAVE_CLOCK_MONOTONIC) check_symbol_exists(CLOCK_MONOTONIC_COARSE "time.h" HAVE_CLOCK_MONOTONIC_COARSE) check_symbol_exists(sys_signame "signal.h" HAVE_SYSSIGNAME) check_symbol_exists(pthread_jit_write_protect_np "pthread.h" HAVE_PTHREAD_JIT_WRITE_PROTECT_NP) +check_symbol_exists(getauxval sys/auxv.h HAVE_GETAUXVAL) ac_check_type("struct sockaddr_in6" sockaddr_in6 "netinet/in.h") ac_check_type("struct timeval" timeval "sys/time.h;sys/types.h;utime.h") diff --git a/src/mono/dlls/dbgshim/CMakeLists.txt b/src/mono/dlls/dbgshim/CMakeLists.txt index 40c36fc1af196f..f19ff0e7dc51ef 100644 --- a/src/mono/dlls/dbgshim/CMakeLists.txt +++ b/src/mono/dlls/dbgshim/CMakeLists.txt @@ -27,11 +27,7 @@ if(HOST_WIN32) endif() endif() -include(${PROJECT_SOURCE_DIR}/../../../../eng/native/configuretools.cmake) -include(${PROJECT_SOURCE_DIR}/../../../../eng/native/configurepaths.cmake) -include(${PROJECT_SOURCE_DIR}/../../../../eng/native/configureplatform.cmake) -include(${PROJECT_SOURCE_DIR}/../../../../eng/native/configurecompiler.cmake) - +include(${CLR_ENG_NATIVE_DIR}/configurecompiler.cmake) add_definitions(-D_WIN32_WINNT=0x0602) diff --git a/src/mono/dlls/mscordbi/CMakeLists.txt b/src/mono/dlls/mscordbi/CMakeLists.txt index ea667c3e2b2f6c..2f8ba379561e14 100644 --- a/src/mono/dlls/mscordbi/CMakeLists.txt +++ b/src/mono/dlls/mscordbi/CMakeLists.txt @@ -94,10 +94,7 @@ endif() add_subdirectory(${PROJECT_SOURCE_DIR}/socket-dbi) -include(${PROJECT_SOURCE_DIR}/../../../../eng/native/configuretools.cmake) -include(${PROJECT_SOURCE_DIR}/../../../../eng/native/configurepaths.cmake) -include(${PROJECT_SOURCE_DIR}/../../../../eng/native/configureplatform.cmake) -include(${PROJECT_SOURCE_DIR}/../../../../eng/native/configurecompiler.cmake) +include(${CLR_ENG_NATIVE_DIR}/configurecompiler.cmake) if (CLR_CMAKE_HOST_UNIX) # Add custom targets that the pal build expects. diff --git a/src/mono/mono/metadata/assembly.c b/src/mono/mono/metadata/assembly.c index 6f14674683a86d..58215064cc864c 100644 --- a/src/mono/mono/metadata/assembly.c +++ b/src/mono/mono/metadata/assembly.c @@ -46,6 +46,7 @@ #include #include #include +#include #ifndef HOST_WIN32 #include @@ -524,37 +525,18 @@ set_dirs (char *exe) void mono_set_rootdir (void) { -#if defined(HOST_WIN32) || (defined(HOST_DARWIN) && !defined(TARGET_ARM)) - gchar *bindir, *installdir, *root, *name, *resolvedname, *config; - -#ifdef HOST_WIN32 - name = mono_get_module_file_name ((HMODULE) &__ImageBase); -#else - { - /* - * _NSGetExecutablePath may return -1 to indicate buf is not large - * enough, but we ignore that case to avoid having to do extra dynamic - * allocation for the path and hope that 4096 is enough - this is - * ok in the Linux/Solaris case below at least... - */ - - gchar buf[4096]; - guint buf_size = sizeof (buf); - - name = NULL; - if (_NSGetExecutablePath (buf, &buf_size) == 0) - name = g_strdup (buf); - - if (name == NULL) { - fallback (); - return; - } - } + char *path = getexepath(); + if (path == NULL) { +#ifndef HOST_WIN32 + fallback (); #endif + return; + } - resolvedname = mono_path_resolve_symlinks (name); +#if defined(HOST_WIN32) || (defined(HOST_DARWIN) && !defined(TARGET_ARM)) + gchar *bindir, *installdir, *root, *config; - bindir = g_path_get_dirname (resolvedname); + bindir = g_path_get_dirname (path); installdir = g_path_get_dirname (bindir); root = g_build_path (G_DIR_SEPARATOR_S, installdir, "lib", (const char*)NULL); @@ -572,44 +554,12 @@ mono_set_rootdir (void) g_free (root); g_free (installdir); g_free (bindir); - g_free (name); - g_free (resolvedname); + g_free (path); #elif defined(DISABLE_MONO_AUTODETECTION) fallback (); #else - char buf [4096]; - int s; - char *str; - -#if defined(HAVE_READLINK) - /* Linux style */ - s = readlink ("/proc/self/exe", buf, sizeof (buf)-1); -#else - s = -1; -#endif - - if (s != -1){ - buf [s] = 0; - set_dirs (buf); - return; - } - - /* Solaris 10 style */ - str = g_strdup_printf ("/proc/%d/path/a.out", mono_process_current_pid ()); - -#if defined(HAVE_READLINK) - s = readlink (str, buf, sizeof (buf)-1); -#else - s = -1; -#endif - - g_free (str); - if (s != -1){ - buf [s] = 0; - set_dirs (buf); - return; - } - fallback (); + set_dirs (path); + return; #endif } diff --git a/src/mono/mono/utils/mono-dl-darwin.c b/src/mono/mono/utils/mono-dl-darwin.c index 1242b1981b4f0a..217125542cee0c 100644 --- a/src/mono/mono/utils/mono-dl-darwin.c +++ b/src/mono/mono/utils/mono-dl-darwin.c @@ -43,15 +43,6 @@ mono_dl_get_so_suffixes (void) return suffixes; } -int -mono_dl_get_executable_path (char *buf, int buflen) -{ - uint32_t bsize = buflen; - if (_NSGetExecutablePath (buf, &bsize) == 0) - return strlen (buf); - return -1; -} - const char* mono_dl_get_system_dir (void) { diff --git a/src/mono/mono/utils/mono-dl-posix.c b/src/mono/mono/utils/mono-dl-posix.c index b716b83bce1f13..01775d17d221c2 100644 --- a/src/mono/mono/utils/mono-dl-posix.c +++ b/src/mono/mono/utils/mono-dl-posix.c @@ -65,16 +65,6 @@ mono_dl_get_so_suffixes (void) return suffixes; } -int -mono_dl_get_executable_path (char *buf, int buflen) -{ -#if defined(HAVE_READLINK) - return readlink ("/proc/self/exe", buf, buflen - 1); -#else - return -1; -#endif -} - const char* mono_dl_get_system_dir (void) { diff --git a/src/mono/mono/utils/mono-dl-wasm.c b/src/mono/mono/utils/mono-dl-wasm.c index df7d60756965c2..3ef2436a08f976 100644 --- a/src/mono/mono/utils/mono-dl-wasm.c +++ b/src/mono/mono/utils/mono-dl-wasm.c @@ -30,13 +30,6 @@ mono_dl_get_so_suffixes (void) return suffixes; } -int -mono_dl_get_executable_path (char *buf, int buflen) -{ - strncpy (buf, "/managed", buflen); //This is a packaging convertion that our tooling should enforce - return 0; -} - const char* mono_dl_get_system_dir (void) { diff --git a/src/mono/mono/utils/mono-dl-windows.c b/src/mono/mono/utils/mono-dl-windows.c index 487fe83188da0a..e2c6d2dfc64cad 100644 --- a/src/mono/mono/utils/mono-dl-windows.c +++ b/src/mono/mono/utils/mono-dl-windows.c @@ -220,12 +220,6 @@ mono_dl_current_error_string (void) } #endif /* HAVE_API_SUPPORT_WIN32_FORMAT_MESSAGE */ -int -mono_dl_get_executable_path (char *buf, int buflen) -{ - return -1; //TODO -} - const char* mono_dl_get_system_dir (void) { diff --git a/src/mono/mono/utils/mono-dl.c b/src/mono/mono/utils/mono-dl.c index 166cd5d602a8fb..0947c3bd0d4132 100644 --- a/src/mono/mono/utils/mono-dl.c +++ b/src/mono/mono/utils/mono-dl.c @@ -21,6 +21,7 @@ #include #include #include +#include #if defined(TARGET_ANDROID) && !defined(WIN32) #include @@ -613,18 +614,14 @@ MonoDl* mono_dl_open_runtime_lib (const char* lib_name, int flags, char **error_msg) { MonoDl *runtime_lib = NULL; - char buf [4096]; - int binl; *error_msg = NULL; - binl = mono_dl_get_executable_path (buf, sizeof (buf)); + char *resolvedname = getexepath(); - if (binl != -1) { + if (!resolvedname) { char *base; - char *resolvedname, *name; + char *name; char *baseparent = NULL; - buf [binl] = 0; - resolvedname = mono_path_resolve_symlinks (buf); base = g_path_get_dirname (resolvedname); name = g_strdup_printf ("%s/.libs", base); runtime_lib = try_load (lib_name, name, flags, error_msg); diff --git a/src/mono/mono/utils/mono-dl.h b/src/mono/mono/utils/mono-dl.h index 5a810f8c295dac..a0a2c4ec7e4c29 100644 --- a/src/mono/mono/utils/mono-dl.h +++ b/src/mono/mono/utils/mono-dl.h @@ -55,7 +55,6 @@ void mono_dl_close_handle (MonoDl *module); void* mono_dl_lookup_symbol (MonoDl *module, const char *name); int mono_dl_convert_flags (int mono_flags, int native_flags); char* mono_dl_current_error_string (void); -int mono_dl_get_executable_path (char *buf, int buflen); const char* mono_dl_get_system_dir (void); #endif /* __MONO_UTILS_DL_H__ */ diff --git a/src/native/common/getexepath.h b/src/native/common/getexepath.h index e918dadcb8e55e..5621f728c85ce1 100644 --- a/src/native/common/getexepath.h +++ b/src/native/common/getexepath.h @@ -15,6 +15,8 @@ #include #include #include +#elif defined(_WIN32) +#include #endif #ifdef __cplusplus @@ -23,7 +25,7 @@ extern "C" { // Returns the full path to the executable for the current process, resolving symbolic links. // The caller is responsible for releasing the buffer. Returns null on error. -extern inline char* getexepath(void) +static inline char* getexepath(void) { #if defined(__APPLE__) uint32_t path_length = 0; @@ -59,6 +61,17 @@ extern inline char* getexepath(void) } return realpath(path, NULL); +#elif defined(_WIN32) + char path[MAX_PATH]; + if (GetModuleFileNameA(NULL, path, MAX_PATH) == 0) + { + return NULL; + } + + return strdup(path); +#elif defined(TARGET_WASM) + // 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);