From c696cae3ff895204fdc481abe8b497cbeda72c78 Mon Sep 17 00:00:00 2001 From: Aaron Bockover Date: Mon, 11 Jan 2010 06:04:09 +0000 Subject: [PATCH] 2010-01-10 Aaron Bockover * assembly.c (mono_set_rootdir): Support finding the mono paths on OS X at runtime in the same way as on Windows, which yields a relocatable Mono. Uses dyld's _NSGetExecutablePath and realpath to resolve the path of the running mono process. On TARGET_ARM, fallback () will always be executed. svn path=/trunk/mono/; revision=149298 --- mono/metadata/ChangeLog | 9 +++++++++ mono/metadata/assembly.c | 31 ++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/mono/metadata/ChangeLog b/mono/metadata/ChangeLog index 73648899152..445c4acedf4 100644 --- a/mono/metadata/ChangeLog +++ b/mono/metadata/ChangeLog @@ -1,3 +1,12 @@ +2010-01-10 Aaron Bockover + + * assembly.c (mono_set_rootdir): Support finding the mono paths on OS X + at runtime in the same way as on Windows, which yields a relocatable + Mono. Uses dyld's _NSGetExecutablePath and realpath to resolve the path + of the running mono process. + + On TARGET_ARM, fallback () will always be executed. + 2010-01-08 Rodrigo Kumpera * icall.c (ves_icall_Type_GetInterfaceMapData): This function is generics variance aware. diff --git a/mono/metadata/assembly.c b/mono/metadata/assembly.c index 65d769a9cf4..4e1cd840e4b 100644 --- a/mono/metadata/assembly.c +++ b/mono/metadata/assembly.c @@ -38,6 +38,10 @@ #include #endif +#ifdef PLATFORM_MACOSX +#include +#endif + /* AssemblyVersionMap: an assembly name and the assembly version set on which it is based */ typedef struct { const char* assembly_name; @@ -550,10 +554,35 @@ set_dirs (char *exe) void mono_set_rootdir (void) { -#ifdef HOST_WIN32 +#if defined(HOST_WIN32) || (defined(PLATFORM_MACOSX) && !defined(TARGET_ARM)) gchar *bindir, *installdir, *root, *name, *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 = realpath (buf, NULL); + } + + if (name == NULL) { + fallback (); + return; + } + } +#endif + bindir = g_path_get_dirname (name); installdir = g_path_get_dirname (bindir); root = g_build_path (G_DIR_SEPARATOR_S, installdir, "lib", NULL); -- 2.25.1