add_definitions(-DFEATURE_EVENTSOURCE_XPLAT=1)
endif (CLR_CMAKE_PLATFORM_LINUX)
+if (CLR_CMAKE_PLATFORM_UNIX)
+ add_definitions(-DPLATFORM_UNIX=1)
+
+ if(CLR_CMAKE_PLATFORM_LINUX)
+ add_definitions(-D__LINUX__=1)
+ if(CLR_CMAKE_PLATFORM_UNIX_TARGET_AMD64)
+ message("Detected Linux x86_64")
+ add_definitions(-DLINUX64)
+ elseif(CLR_CMAKE_PLATFORM_ARCH_ARM)
+ message("Detected Linux ARM")
+ add_definitions(-DLINUX32)
+ elseif(CLR_CMAKE_PLATFORM_ARCH_ARM64)
+ message("Detected Linux ARM64")
+ add_definitions(-DLINUX64)
+ else()
+ clr_unknown_arch()
+ endif()
+
+ endif(CLR_CMAKE_PLATFORM_LINUX)
+
+ if(CLR_CMAKE_PLATFORM_FREEBSD)
+ message("Detected FreeBSD amd64")
+ endif(CLR_CMAKE_PLATFORM_FREEBSD)
+
+endif(CLR_CMAKE_PLATFORM_UNIX)
+
if(CLR_CMAKE_PLATFORM_UNIX)
add_subdirectory(src/ToolBox/SOS/lldbplugin)
add_subdirectory(src/pal)
- add_subdirectory(src/coreclr/hosts/unixcorerun)
add_subdirectory(src/corefx)
+ add_subdirectory(src/coreclr/hosts/unixcorerun)
add_subdirectory(src/coreclr/hosts/unixcoreconsole)
endif(CLR_CMAKE_PLATFORM_UNIX)
add_subdirectory(src/coreclr/hosts/osxbundlerun)
endif(CLR_CMAKE_PLATFORM_DARWIN)
-
# Add this subdir. We install the headers for the jit.
add_subdirectory(src/pal/prebuilt/inc)
if (CLR_CMAKE_PLATFORM_UNIX)
- add_definitions(-DPLATFORM_UNIX=1)
add_definitions(-DFEATURE_PAL_SXS)
add_definitions(-DFEATURE_COREFX_GLOBALIZATION)
+ add_definitions(-DFEATURE_PAL)
if(IS_64BIT_BUILD)
add_definitions(-DBIT64=1)
endif(IS_64BIT_BUILD)
-
- add_definitions(-DFEATURE_PAL)
-
- if(CLR_CMAKE_PLATFORM_LINUX)
- add_definitions(-D__LINUX__=1)
- if(CLR_CMAKE_PLATFORM_UNIX_TARGET_AMD64)
- message("Detected Linux x86_64")
- add_definitions(-DLINUX64)
- elseif(CLR_CMAKE_PLATFORM_ARCH_ARM)
- message("Detected Linux ARM")
- add_definitions(-DLINUX32)
- elseif(CLR_CMAKE_PLATFORM_ARCH_ARM64)
- message("Detected Linux ARM64")
- add_definitions(-DLINUX64)
- else()
- clr_unknown_arch()
- endif()
-
- endif(CLR_CMAKE_PLATFORM_LINUX)
+
if(CLR_CMAKE_PLATFORM_DARWIN)
message("Detected OSX x86_64")
add_definitions(-D_XOPEN_SOURCE)
endif(CLR_CMAKE_PLATFORM_DARWIN)
- if(CLR_CMAKE_PLATFORM_FREEBSD)
- message("Detected FreeBSD amd64")
- endif(CLR_CMAKE_PLATFORM_FREEBSD)
+
endif(CLR_CMAKE_PLATFORM_UNIX)
{
// Make sure we have a full path for argv[0].
std::string argv0AbsolutePath;
- if (!GetAbsolutePath(argv[0], argv0AbsolutePath))
+ std::string entryPointExecutablePath;
+
+ if (!GetEntrypointExecutableAbsolutePath(entryPointExecutablePath))
{
perror("Could not get full path to current executable");
return -1;
}
+ if (!GetAbsolutePath(entryPointExecutablePath.c_str(), argv0AbsolutePath))
+ {
+ perror("Could not normalize full path to current executable");
+ return -1;
+ }
+
// We will try to load the managed assembly with the same name as this executable
// but with the .dll extension.
std::string programPath(argv0AbsolutePath);
#include <string.h>
#include <sys/stat.h>
-// The name of the CoreCLR native runtime DLL
#if defined(__APPLE__)
+#include <mach-o/dyld.h>
static const char * const coreClrDll = "libcoreclr.dylib";
#else
static const char * const coreClrDll = "libcoreclr.so";
const char* managedAssemblyPath,
unsigned int* exitCode);
+#if defined(__LINUX__)
+#define symlinkEntrypointExecutable "/proc/self/exe"
+#elif !defined(__APPLE__)
+#define symlinkEntrypointExecutable "/proc/curproc/exe"
+#endif
+
+bool GetEntrypointExecutableAbsolutePath(std::string& entrypointExecutable)
+{
+ bool result = false;
+
+ entrypointExecutable.clear();
+
+ // Get path to the executable for the current process using
+ // platform specific means.
+#if defined(__LINUX__) || !defined(__APPLE__)
+
+ // On non-Mac OS, return the symlink that will be resolved by GetAbsolutePath
+ // to fetch the entrypoint EXE absolute path, inclusive of filename.
+ entrypointExecutable.assign(symlinkEntrypointExecutable);
+ result = true;
+#elif defined(__APPLE__)
+
+ // On Mac, we ask the OS for the absolute path to the entrypoint executable
+ uint32_t lenActualPath = 0;
+ if (_NSGetExecutablePath(nullptr, &lenActualPath) == -1)
+ {
+ // OSX has placed the actual path length in lenActualPath,
+ // so re-attempt the operation
+ std::string resizedPath(lenActualPath, '\0');
+ char *pResizedPath = const_cast<char *>(resizedPath.c_str());
+ if (_NSGetExecutablePath(pResizedPath, &lenActualPath) == 0)
+ {
+ entrypointExecutable.assign(pResizedPath);
+ result = true;
+ }
+ }
+ #endif
+
+ return result;
+}
+
bool GetAbsolutePath(const char* path, std::string& absolutePath)
{
bool result = false;