diff --git a/eng/native/configurecompiler.cmake b/eng/native/configurecompiler.cmake index 2937916ced91b..735f77b028217 100644 --- a/eng/native/configurecompiler.cmake +++ b/eng/native/configurecompiler.cmake @@ -183,10 +183,10 @@ elseif(CLR_CMAKE_HOST_FREEBSD) add_compile_options($<$:-Wa,--noexecstack>) add_link_options(LINKER:--build-id=sha1) elseif(CLR_CMAKE_HOST_SUNOS) - set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} /opt/local/include) - set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} /opt/local/lib) + add_compile_options($<$:-Wa,--noexecstack>) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector") + add_definitions(-D__EXTENSIONS__) endif() #------------------------------------ @@ -367,17 +367,13 @@ if(CLR_CMAKE_TARGET_UNIX) add_definitions(-DDISABLE_CONTRACTS) if(CLR_CMAKE_TARGET_OSX) add_definitions(-DTARGET_OSX) - endif(CLR_CMAKE_TARGET_OSX) - if(CLR_CMAKE_TARGET_FREEBSD) + elseif(CLR_CMAKE_TARGET_FREEBSD) add_definitions(-DTARGET_FREEBSD) - endif(CLR_CMAKE_TARGET_FREEBSD) - if(CLR_CMAKE_TARGET_LINUX) + elseif(CLR_CMAKE_TARGET_LINUX) add_definitions(-DTARGET_LINUX) - endif(CLR_CMAKE_TARGET_LINUX) - if(CLR_CMAKE_TARGET_NETBSD) + elseif(CLR_CMAKE_TARGET_NETBSD) add_definitions(-DTARGET_NETBSD) - endif(CLR_CMAKE_TARGET_NETBSD) - if(CLR_CMAKE_TARGET_ANDROID) + elseif(CLR_CMAKE_TARGET_ANDROID) add_definitions(-DTARGET_ANDROID) endif() else(CLR_CMAKE_TARGET_UNIX) diff --git a/src/coreclr/src/debug/daccess/CMakeLists.txt b/src/coreclr/src/debug/daccess/CMakeLists.txt index b56c37c623e87..6d18ad64fded8 100644 --- a/src/coreclr/src/debug/daccess/CMakeLists.txt +++ b/src/coreclr/src/debug/daccess/CMakeLists.txt @@ -41,7 +41,7 @@ target_precompile_header(TARGET daccess HEADER stdafx.h) add_dependencies(daccess eventing_headers) -if(CLR_CMAKE_HOST_OSX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD) +if(CLR_CMAKE_HOST_OSX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS) add_definitions(-DUSE_DAC_TABLE_RVA) add_custom_command( @@ -63,4 +63,4 @@ if(CLR_CMAKE_HOST_OSX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD) ) add_dependencies(daccess dactablerva_header) -endif(CLR_CMAKE_HOST_OSX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD) +endif(CLR_CMAKE_HOST_OSX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS) diff --git a/src/coreclr/src/dlls/dbgshim/CMakeLists.txt b/src/coreclr/src/dlls/dbgshim/CMakeLists.txt index b3b326f0bf49d..8f3ef4a3330c1 100644 --- a/src/coreclr/src/dlls/dbgshim/CMakeLists.txt +++ b/src/coreclr/src/dlls/dbgshim/CMakeLists.txt @@ -40,6 +40,11 @@ if(CLR_CMAKE_HOST_OSX) set(EXPORTS_LINKER_OPTION -Wl,-exported_symbols_list,${EXPORTS_FILE}) endif(CLR_CMAKE_HOST_OSX) +if(CLR_CMAKE_HOST_SUNOS) + # Add linker exports file option + set(EXPORTS_LINKER_OPTION -Wl,-M,${EXPORTS_FILE}) +endif(CLR_CMAKE_HOST_SUNOS) + add_library_clr(dbgshim SHARED ${DBGSHIM_SOURCES}) if(CLR_CMAKE_HOST_UNIX) diff --git a/src/coreclr/src/dlls/mscordac/CMakeLists.txt b/src/coreclr/src/dlls/mscordac/CMakeLists.txt index 3e2a6bdb24231..d005acc8c5a74 100644 --- a/src/coreclr/src/dlls/mscordac/CMakeLists.txt +++ b/src/coreclr/src/dlls/mscordac/CMakeLists.txt @@ -31,9 +31,9 @@ else(CLR_CMAKE_HOST_WIN32) # Add dependency on export file add_custom_target(mscordaccore_exports DEPENDS ${EXPORTS_FILE}) - if(CLR_CMAKE_HOST_OSX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD) + if(CLR_CMAKE_HOST_OSX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS) generate_exports_file(${DEF_SOURCES} ${EXPORTS_FILE}) - endif(CLR_CMAKE_HOST_OSX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD) + endif(CLR_CMAKE_HOST_OSX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS) if(CLR_CMAKE_HOST_LINUX) @@ -96,6 +96,11 @@ if(CLR_CMAKE_HOST_OSX) set(EXPORTS_LINKER_OPTION -Wl,-exported_symbols_list,${EXPORTS_FILE}) endif(CLR_CMAKE_HOST_OSX) +if(CLR_CMAKE_HOST_SUNOS) + # Add linker exports file option + set(EXPORTS_LINKER_OPTION -Wl,-M,${EXPORTS_FILE}) +endif(CLR_CMAKE_HOST_SUNOS) + # Create object library to enable creation of proper dependency of mscordaccore.exp on mscordac.obj and # mscordaccore on both the mscordaccore.exp and mscordac.obj. _add_library(mscordacobj OBJECT mscordac.cpp) diff --git a/src/coreclr/src/dlls/mscordbi/CMakeLists.txt b/src/coreclr/src/dlls/mscordbi/CMakeLists.txt index d3a695cee4af2..6a54e77733246 100644 --- a/src/coreclr/src/dlls/mscordbi/CMakeLists.txt +++ b/src/coreclr/src/dlls/mscordbi/CMakeLists.txt @@ -55,6 +55,11 @@ if(CLR_CMAKE_HOST_OSX) set(EXPORTS_LINKER_OPTION -Wl,-exported_symbols_list,${EXPORTS_FILE}) endif(CLR_CMAKE_HOST_OSX) +if(CLR_CMAKE_HOST_SUNOS) + # Add linker exports file option + set(EXPORTS_LINKER_OPTION -Wl,-M,${EXPORTS_FILE}) +endif(CLR_CMAKE_HOST_SUNOS) + add_library_clr(mscordbi SHARED ${MSCORDBI_SOURCES}) target_precompile_header(TARGET mscordbi HEADER stdafx.h) diff --git a/src/coreclr/src/dlls/mscoree/coreclr/CMakeLists.txt b/src/coreclr/src/dlls/mscoree/coreclr/CMakeLists.txt index 52ec65fa73ba5..4358d79669b45 100644 --- a/src/coreclr/src/dlls/mscoree/coreclr/CMakeLists.txt +++ b/src/coreclr/src/dlls/mscoree/coreclr/CMakeLists.txt @@ -59,7 +59,12 @@ else(CLR_CMAKE_HOST_WIN32) if(CLR_CMAKE_TARGET_ANDROID AND CLR_CMAKE_HOST_ARCH_ARM) set(EXPORTS_LINKER_OPTION "${EXPORTS_LINKER_OPTION} -Wl,--no-warn-shared-textrel") - endif() + endif(CLR_CMAKE_TARGET_ANDROID AND CLR_CMAKE_HOST_ARCH_ARM) + + if(CLR_CMAKE_HOST_SUNOS) + # Add linker exports file option + set(EXPORTS_LINKER_OPTION -Wl,-M,${EXPORTS_FILE}) + endif(CLR_CMAKE_HOST_SUNOS) endif (CLR_CMAKE_HOST_WIN32) diff --git a/src/coreclr/src/gc/env/gcenv.base.h b/src/coreclr/src/gc/env/gcenv.base.h index b8fd0862db96b..837291f345d49 100644 --- a/src/coreclr/src/gc/env/gcenv.base.h +++ b/src/coreclr/src/gc/env/gcenv.base.h @@ -12,6 +12,9 @@ #endif // _MSC_VER #if !defined(_MSC_VER) +#ifdef __sun +#include +#endif #define _alloca alloca #endif //_MSC_VER diff --git a/src/coreclr/src/gc/unix/cgroup.cpp b/src/coreclr/src/gc/unix/cgroup.cpp index 5d8ea5320a89f..c2c1b2b588449 100644 --- a/src/coreclr/src/gc/unix/cgroup.cpp +++ b/src/coreclr/src/gc/unix/cgroup.cpp @@ -132,6 +132,10 @@ class CGroup // modes because both of those involve cgroup v1 controllers managing // resources. +#if !HAVE_NON_LEGACY_STATFS + return 0; +#else + struct statfs stats; int result = statfs("/sys/fs/cgroup", &stats); if (result != 0) @@ -145,6 +149,7 @@ class CGroup assert(!"Unexpected file system type for /sys/fs/cgroup"); return 0; } +#endif } static bool IsCGroup1MemorySubsystem(const char *strTok){ diff --git a/src/coreclr/src/gc/unix/config.gc.h.in b/src/coreclr/src/gc/unix/config.gc.h.in index a1d60d3e1fda2..ad33f95b6bdc8 100644 --- a/src/coreclr/src/gc/unix/config.gc.h.in +++ b/src/coreclr/src/gc/unix/config.gc.h.in @@ -14,6 +14,7 @@ #cmakedefine01 HAVE_SCHED_GETCPU #cmakedefine01 HAVE_NUMA_H #cmakedefine01 HAVE_VM_ALLOCATE +#cmakedefine01 HAVE_SWAPCTL #cmakedefine01 HAVE_SYSCTLBYNAME #cmakedefine01 HAVE_PTHREAD_CONDATTR_SETCLOCK #cmakedefine01 HAVE_MACH_ABSOLUTE_TIME diff --git a/src/coreclr/src/gc/unix/configure.cmake b/src/coreclr/src/gc/unix/configure.cmake index 9ed93b95b7159..cc7fb90265d8b 100644 --- a/src/coreclr/src/gc/unix/configure.cmake +++ b/src/coreclr/src/gc/unix/configure.cmake @@ -98,6 +98,7 @@ check_library_exists(${PTHREAD_LIBRARY} pthread_getaffinity_np "" HAVE_PTHREAD_G check_cxx_symbol_exists(_SC_PHYS_PAGES unistd.h HAVE__SC_PHYS_PAGES) check_cxx_symbol_exists(_SC_AVPHYS_PAGES unistd.h HAVE__SC_AVPHYS_PAGES) +check_cxx_symbol_exists(swapctl sys/swap.h HAVE_SWAPCTL) check_function_exists(sysctl HAVE_SYSCTL) check_function_exists(sysinfo HAVE_SYSINFO) check_function_exists(sysconf HAVE_SYSCONF) diff --git a/src/coreclr/src/gc/unix/gcenv.unix.cpp b/src/coreclr/src/gc/unix/gcenv.unix.cpp index 855f2da02a982..fd3cd5ec91b6d 100644 --- a/src/coreclr/src/gc/unix/gcenv.unix.cpp +++ b/src/coreclr/src/gc/unix/gcenv.unix.cpp @@ -22,6 +22,10 @@ #include "gcenv.unix.inl" #include "volatile.h" +#if HAVE_SWAPCTL +#include +#endif + #undef min #undef max @@ -731,7 +735,7 @@ bool GCToOSInterface::VirtualReset(void * address, size_t size, bool unlock) #endif { // In case the MADV_FREE is not supported, use MADV_DONTNEED - st = madvise(address, size, MADV_DONTNEED); + st = posix_madvise(address, size, MADV_DONTNEED); } return (st == 0); @@ -1112,6 +1116,13 @@ uint64_t GetAvailablePageFile() available += avail * pagesize; } } +#elif HAVE_SWAPCTL + struct anoninfo ai; + if (swapctl(SC_AINFO, &ai) != -1) + { + int pagesize = getpagesize(); + available = ai.ani_free * pagesize; + } #elif HAVE_SYSINFO // Linux struct sysinfo info; diff --git a/src/coreclr/src/hosts/unixcoreruncommon/config.h.in b/src/coreclr/src/hosts/unixcoreruncommon/config.h.in index 0e457b411c3c8..8adb7098ef11b 100644 --- a/src/coreclr/src/hosts/unixcoreruncommon/config.h.in +++ b/src/coreclr/src/hosts/unixcoreruncommon/config.h.in @@ -6,5 +6,6 @@ #define __CONFIG_H__ #cmakedefine01 HAVE_GETAUXVAL +#cmakedefine01 HAVE_DIRENT_D_TYPE #endif // __CONFIG_H__ diff --git a/src/coreclr/src/hosts/unixcoreruncommon/configure.cmake b/src/coreclr/src/hosts/unixcoreruncommon/configure.cmake index ea90cc8a3551c..61c9811394994 100644 --- a/src/coreclr/src/hosts/unixcoreruncommon/configure.cmake +++ b/src/coreclr/src/hosts/unixcoreruncommon/configure.cmake @@ -1,4 +1,5 @@ check_symbol_exists(getauxval sys/auxv.h HAVE_GETAUXVAL) +check_struct_has_member ("struct dirent" d_type dirent.h HAVE_DIRENT_D_TYPE) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/config.h.in diff --git a/src/coreclr/src/hosts/unixcoreruncommon/coreruncommon.cpp b/src/coreclr/src/hosts/unixcoreruncommon/coreruncommon.cpp index a2c00b1c3b4ab..aac6e24ecea11 100644 --- a/src/coreclr/src/hosts/unixcoreruncommon/coreruncommon.cpp +++ b/src/coreclr/src/hosts/unixcoreruncommon/coreruncommon.cpp @@ -35,6 +35,13 @@ #define SUCCEEDED(Status) ((Status) >= 0) #endif // !SUCCEEDED +#if !HAVE_DIRENT_D_TYPE +#define DT_UNKNOWN 0 +#define DT_DIR 4 +#define DT_REG 8 +#define DT_LNK 10 +#endif + // Name of the environment variable controlling server GC. // If set to 1, server GC is enabled on startup. If 0, server GC is // disabled. Server GC is off by default. @@ -216,8 +223,14 @@ void AddFilesFromDirectoryToTpaList(const char* directory, std::string& tpaList) // For all entries in the directory while ((entry = readdir(dir)) != nullptr) { +#if HAVE_DIRENT_D_TYPE + int dirEntryType = entry->d_type; +#else + int dirEntryType = DT_UNKNOWN; +#endif + // We are interested in files only - switch (entry->d_type) + switch (dirEntryType) { case DT_REG: break; diff --git a/src/coreclr/src/ilasm/CMakeLists.txt b/src/coreclr/src/ilasm/CMakeLists.txt index e8f1460f3c414..94fe6b83d3a41 100644 --- a/src/coreclr/src/ilasm/CMakeLists.txt +++ b/src/coreclr/src/ilasm/CMakeLists.txt @@ -52,7 +52,7 @@ if(CLR_CMAKE_HOST_UNIX) set_source_files_properties( prebuilt/asmparse.cpp PROPERTIES COMPILE_FLAGS "-O0" ) endif(CLR_CMAKE_HOST_UNIX) -if(CLR_CMAKE_HOST_LINUX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD) +if(CLR_CMAKE_HOST_LINUX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS) # This option is necessary to ensure that the overloaded delete operator defined inside # of the utilcode will be used instead of the standard library delete operator. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Xlinker -Bsymbolic") @@ -61,8 +61,7 @@ if(CLR_CMAKE_HOST_LINUX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD) # ensure proper resolving of circular references between a subset of the libraries. set(START_LIBRARY_GROUP -Wl,--start-group) set(END_LIBRARY_GROUP -Wl,--end-group) -endif(CLR_CMAKE_HOST_LINUX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD) - +endif(CLR_CMAKE_HOST_LINUX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS) _add_executable(ilasm ${ILASM_SOURCES} diff --git a/src/coreclr/src/ildasm/exe/CMakeLists.txt b/src/coreclr/src/ildasm/exe/CMakeLists.txt index 7ce367ee04897..87a0fa01f820f 100644 --- a/src/coreclr/src/ildasm/exe/CMakeLists.txt +++ b/src/coreclr/src/ildasm/exe/CMakeLists.txt @@ -47,7 +47,7 @@ if (CLR_CMAKE_TARGET_WIN32) list(APPEND ILDASM_SOURCES ${ILDASM_HEADERS}) endif(CLR_CMAKE_TARGET_WIN32) -if(CLR_CMAKE_HOST_LINUX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD) +if(CLR_CMAKE_HOST_LINUX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS) # This option is necessary to ensure that the overloaded delete operator defined inside # of the utilcode will be used instead of the standard library delete operator. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Xlinker -Bsymbolic") @@ -56,7 +56,7 @@ if(CLR_CMAKE_HOST_LINUX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD) # ensure proper resolving of circular references between a subset of the libraries. set(START_LIBRARY_GROUP -Wl,--start-group) set(END_LIBRARY_GROUP -Wl,--end-group) -endif(CLR_CMAKE_HOST_LINUX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD) +endif(CLR_CMAKE_HOST_LINUX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS) _add_executable(ildasm ${ILDASM_SOURCES} diff --git a/src/coreclr/src/inc/crosscomp.h b/src/coreclr/src/inc/crosscomp.h index 81a85641b8e30..93a164c249240 100644 --- a/src/coreclr/src/inc/crosscomp.h +++ b/src/coreclr/src/inc/crosscomp.h @@ -392,9 +392,11 @@ typedef struct _T_KNONVOLATILE_CONTEXT_POINTERS { #define DAC_CS_NATIVE_DATA_SIZE 56 #elif defined(TARGET_NETBSD) && defined(TARGET_X86) #define DAC_CS_NATIVE_DATA_SIZE 56 +#elif defined(__sun) && defined(TARGET_AMD64) +#define DAC_CS_NATIVE_DATA_SIZE 48 #else #warning -#error DAC_CS_NATIVE_DATA_SIZE is not defined for this architecture +#error DAC_CS_NATIVE_DATA_SIZE is not defined for this architecture. This should be same value as PAL_CS_NATIVE_DATA_SIZE (aka sizeof(PAL_CS_NATIVE_DATA)). #endif struct T_CRITICAL_SECTION { diff --git a/src/coreclr/src/jit/CMakeLists.txt b/src/coreclr/src/jit/CMakeLists.txt index 034cdbe38dcd4..582d11d6d4056 100644 --- a/src/coreclr/src/jit/CMakeLists.txt +++ b/src/coreclr/src/jit/CMakeLists.txt @@ -319,7 +319,10 @@ else() set(JIT_EXPORTS_LINKER_OPTION -Wl,--version-script=${JIT_EXPORTS_FILE}) elseif(CLR_CMAKE_TARGET_OSX) set(JIT_EXPORTS_LINKER_OPTION -Wl,-exported_symbols_list,${JIT_EXPORTS_FILE}) - endif() + elseif(CLR_CMAKE_HOST_SUNOS) + # Add linker exports file option + set(JIT_EXPORTS_LINKER_OPTION -Wl,-M,${JIT_EXPORTS_FILE}) + endif(CLR_CMAKE_HOST_SUNOS) set(SHARED_LIB_SOURCES ${SOURCES}) endif() diff --git a/src/coreclr/src/jit/emit.h b/src/coreclr/src/jit/emit.h index dda33e19a36ba..1ded601fadb56 100644 --- a/src/coreclr/src/jit/emit.h +++ b/src/coreclr/src/jit/emit.h @@ -1336,7 +1336,7 @@ class emitter insExecutionCharacteristics getInsExecutionCharacteristics(instrDesc* id); - void emitter::perfScoreUnhandledInstruction(instrDesc* id, insExecutionCharacteristics* result); + void perfScoreUnhandledInstruction(instrDesc* id, insExecutionCharacteristics* result); #endif // defined(DEBUG) || defined(LATE_DISASM) diff --git a/src/coreclr/src/pal/inc/pal.h b/src/coreclr/src/pal/inc/pal.h index 7926b2982322f..861a10f842da7 100644 --- a/src/coreclr/src/pal/inc/pal.h +++ b/src/coreclr/src/pal/inc/pal.h @@ -2365,6 +2365,8 @@ PALIMPORT BOOL PALAPI PAL_VirtualUnwindOutOfProc(CONTEXT *context, KNONVOLATILE_ #define PAL_CS_NATIVE_DATA_SIZE 56 #elif defined(__NetBSD__) && defined(__i386__) #define PAL_CS_NATIVE_DATA_SIZE 56 +#elif defined(__sun) && defined(__x86_64__) +#define PAL_CS_NATIVE_DATA_SIZE 48 #else #warning #error PAL_CS_NATIVE_DATA_SIZE is not defined for this architecture @@ -3935,7 +3937,11 @@ PALIMPORT int __cdecl memcmp(const void *, const void *, size_t); PALIMPORT void * __cdecl memset(void *, int, size_t); PALIMPORT void * __cdecl memmove(void *, const void *, size_t); PALIMPORT void * __cdecl memchr(const void *, int, size_t); -PALIMPORT long long int __cdecl atoll(const char *) THROW_DECL; +PALIMPORT long long int __cdecl atoll(const char *) +#ifndef __sun +THROW_DECL +#endif +; PALIMPORT size_t __cdecl strlen(const char *); PALIMPORT int __cdecl strcmp(const char*, const char *); PALIMPORT int __cdecl strncmp(const char*, const char *, size_t); @@ -4028,14 +4034,14 @@ PALIMPORT int __cdecl _wtoi(const WCHAR *); #ifdef __cplusplus extern "C++" { -inline WCHAR *PAL_wcschr(WCHAR *_S, WCHAR _C) - {return ((WCHAR *)PAL_wcschr((const WCHAR *)_S, _C)); } -inline WCHAR *PAL_wcsrchr(WCHAR *_S, WCHAR _C) - {return ((WCHAR *)PAL_wcsrchr((const WCHAR *)_S, _C)); } -inline WCHAR *PAL_wcspbrk(WCHAR *_S, const WCHAR *_P) - {return ((WCHAR *)PAL_wcspbrk((const WCHAR *)_S, _P)); } -inline WCHAR *PAL_wcsstr(WCHAR *_S, const WCHAR *_P) - {return ((WCHAR *)PAL_wcsstr((const WCHAR *)_S, _P)); } +inline WCHAR *PAL_wcschr(WCHAR* S, WCHAR C) + {return ((WCHAR *)PAL_wcschr((const WCHAR *)S, C)); } +inline WCHAR *PAL_wcsrchr(WCHAR* S, WCHAR C) + {return ((WCHAR *)PAL_wcsrchr((const WCHAR *)S, C)); } +inline WCHAR *PAL_wcspbrk(WCHAR* S, const WCHAR* P) + {return ((WCHAR *)PAL_wcspbrk((const WCHAR *)S, P)); } +inline WCHAR *PAL_wcsstr(WCHAR* S, const WCHAR* P) + {return ((WCHAR *)PAL_wcsstr((const WCHAR *)S, P)); } } #endif @@ -4107,9 +4113,17 @@ PALIMPORT double __cdecl acosh(double); PALIMPORT double __cdecl asin(double); PALIMPORT double __cdecl asinh(double); PALIMPORT double __cdecl atan(double) THROW_DECL; -PALIMPORT double __cdecl atanh(double) THROW_DECL; +PALIMPORT double __cdecl atanh(double) +#ifndef __sun +THROW_DECL +#endif +; PALIMPORT double __cdecl atan2(double, double); -PALIMPORT double __cdecl cbrt(double) THROW_DECL; +PALIMPORT double __cdecl cbrt(double) +#ifndef __sun +THROW_DECL +#endif +; PALIMPORT double __cdecl ceil(double); PALIMPORT double __cdecl cos(double); PALIMPORT double __cdecl cosh(double); @@ -4138,10 +4152,22 @@ PALIMPORT float __cdecl acosf(float); PALIMPORT float __cdecl acoshf(float); PALIMPORT float __cdecl asinf(float); PALIMPORT float __cdecl asinhf(float); -PALIMPORT float __cdecl atanf(float) THROW_DECL; -PALIMPORT float __cdecl atanhf(float) THROW_DECL; +PALIMPORT float __cdecl atanf(float) +#ifndef __sun +THROW_DECL +#endif +; +PALIMPORT float __cdecl atanhf(float) +#ifndef __sun +THROW_DECL +#endif +; PALIMPORT float __cdecl atan2f(float, float); -PALIMPORT float __cdecl cbrtf(float) THROW_DECL; +PALIMPORT float __cdecl cbrtf(float) +#ifndef __sun +THROW_DECL +#endif +; PALIMPORT float __cdecl ceilf(float); PALIMPORT float __cdecl cosf(float); PALIMPORT float __cdecl coshf(float); diff --git a/src/coreclr/src/pal/src/CMakeLists.txt b/src/coreclr/src/pal/src/CMakeLists.txt index e7c1629d5b263..1a39363832285 100644 --- a/src/coreclr/src/pal/src/CMakeLists.txt +++ b/src/coreclr/src/pal/src/CMakeLists.txt @@ -113,7 +113,7 @@ set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -Wl,--no if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") add_compile_options(-Wno-unused-result) -endif() +endif(CMAKE_CXX_COMPILER_ID MATCHES "GNU") set(ARCH_SOURCES arch/${PAL_ARCH_SOURCES_DIR}/context2.S @@ -135,6 +135,10 @@ if(CLR_CMAKE_HOST_ARCH_ARM) endif() endif(CLR_CMAKE_HOST_ARCH_ARM) +if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") + add_compile_options(-Wa,--divide) +endif() + set(SOURCES cruntime/file.cpp cruntime/filecrt.cpp @@ -321,6 +325,13 @@ if(CLR_CMAKE_TARGET_NETBSD) ) endif(CLR_CMAKE_TARGET_NETBSD) +if(CLR_CMAKE_TARGET_SUNOS) + target_link_libraries(coreclrpal + pthread + rt + ) +endif(CLR_CMAKE_TARGET_SUNOS) + if(FEATURE_EVENT_TRACE) add_subdirectory(eventprovider) endif(FEATURE_EVENT_TRACE) diff --git a/src/coreclr/src/pal/src/config.h.in b/src/coreclr/src/pal/src/config.h.in index ddf6ffc5a1a46..8e7e69288bc9e 100644 --- a/src/coreclr/src/pal/src/config.h.in +++ b/src/coreclr/src/pal/src/config.h.in @@ -23,6 +23,7 @@ #cmakedefine01 HAVE_NUMA_H #cmakedefine01 HAVE_PTHREAD_NP_H #cmakedefine01 HAVE_AUXV_HWCAP_H +#cmakedefine01 HAVE_SYS_PTRACE_H #cmakedefine01 HAVE_KQUEUE #cmakedefine01 HAVE_PTHREAD_SUSPEND @@ -51,12 +52,14 @@ #cmakedefine01 HAVE_TIMEGM #cmakedefine01 HAVE_POLL #cmakedefine01 HAVE_STATVFS +#cmakedefine01 HAVE_NON_LEGACY_STATFS #cmakedefine01 HAVE_THREAD_SELF #cmakedefine01 HAVE__LWP_SELF #cmakedefine01 HAVE_MACH_THREADS #cmakedefine01 HAVE_MACH_EXCEPTIONS #cmakedefine01 HAVE_VM_ALLOCATE #cmakedefine01 HAVE_VM_READ +#cmakedefine01 HAVE_DIRECTIO #cmakedefine01 HAVE_SEMAPHORE_H #cmakedefine01 HAS_SYSV_SEMAPHORES #cmakedefine01 HAS_PTHREAD_MUTEXES @@ -70,6 +73,7 @@ #cmakedefine01 HAVE_PUBLIC_XSTATE_STRUCT #cmakedefine01 HAVE__FPX_SW_BYTES_WITH_XSTATE_BV #cmakedefine01 HAVE_PR_SET_PTRACER +#cmakedefine01 HAVE_SWAPCTL #cmakedefine01 HAVE_STAT_TIMESPEC #cmakedefine01 HAVE_STAT_TIM @@ -85,6 +89,8 @@ #cmakedefine01 HAVE_PTHREAD_RWLOCK_T #cmakedefine01 HAVE_PRWATCH_T #cmakedefine SIZEOF_OFF_T @SIZEOF_OFF_T@ +#cmakedefine01 HAVE_DIRENT_D_TYPE +#cmakedefine01 HAVE_FPREGS_WITH_CW #cmakedefine01 HAVE_YIELD_SYSCALL #cmakedefine01 HAVE_INFTIM @@ -110,7 +116,6 @@ #cmakedefine01 HAVE_MACH_ABSOLUTE_TIME #cmakedefine01 HAVE_CLOCK_THREAD_CPUTIME #cmakedefine01 HAVE_PTHREAD_CONDATTR_SETCLOCK -#cmakedefine01 STATVFS64_PROTOTYPE_BROKEN #cmakedefine01 HAVE_MMAP_DEV_ZERO #cmakedefine01 MMAP_ANON_IGNORES_PROTECTION #cmakedefine01 ONE_SHARED_MAPPING_PER_FILEREGION_PER_PROCESS diff --git a/src/coreclr/src/pal/src/configure.cmake b/src/coreclr/src/pal/src/configure.cmake index 62e5690af3203..b2ae2cc607599 100644 --- a/src/coreclr/src/pal/src/configure.cmake +++ b/src/coreclr/src/pal/src/configure.cmake @@ -2,6 +2,7 @@ include(CheckCXXSourceCompiles) include(CheckCXXSourceRuns) include(CheckCXXSymbolExists) include(CheckFunctionExists) +include(CheckPrototypeDefinition) include(CheckIncludeFiles) include(CheckStructHasMember) include(CheckTypeSize) @@ -45,6 +46,7 @@ check_include_files(sys/prctl.h HAVE_PRCTL_H) check_include_files(numa.h HAVE_NUMA_H) check_include_files(pthread_np.h HAVE_PTHREAD_NP_H) check_include_files("sys/auxv.h;asm/hwcap.h" HAVE_AUXV_HWCAP_H) +check_include_files("sys/ptrace.h" HAVE_SYS_PTRACE_H) set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_DL_LIBS}) @@ -143,6 +145,8 @@ check_struct_has_member ("ucontext_t" uc_mcontext.gregs[0] ucontext.h HAVE_GREGS check_struct_has_member ("ucontext_t" uc_mcontext.__gregs[0] ucontext.h HAVE___GREGSET_T) check_struct_has_member ("ucontext_t" uc_mcontext.fpregs->__glibc_reserved1[0] ucontext.h HAVE_FPSTATE_GLIBC_RESERVED1) check_struct_has_member ("struct sysinfo" mem_unit "sys/sysinfo.h" HAVE_SYSINFO_WITH_MEM_UNIT) +check_struct_has_member ("struct dirent" d_type dirent.h HAVE_DIRENT_D_TYPE) +check_struct_has_member ("struct _fpchip_state" cw sys/ucontext.h HAVE_FPREGS_WITH_CW) set(CMAKE_EXTRA_INCLUDE_FILES machine/reg.h) check_type_size("struct reg" BSD_REGS_T) @@ -169,6 +173,7 @@ check_cxx_symbol_exists(CHAR_BIT limits.h HAVE_CHAR_BIT) check_cxx_symbol_exists(_DEBUG sys/user.h USER_H_DEFINES_DEBUG) check_cxx_symbol_exists(_SC_PHYS_PAGES unistd.h HAVE__SC_PHYS_PAGES) check_cxx_symbol_exists(_SC_AVPHYS_PAGES unistd.h HAVE__SC_AVPHYS_PAGES) +check_cxx_symbol_exists(swapctl sys/swap.h HAVE_SWAPCTL) check_cxx_source_runs(" #include @@ -1390,4 +1395,30 @@ else() # Anything else is Linux set(HAVE_SCHED_OTHER_ASSIGNABLE 1) endif(CLR_CMAKE_TARGET_OSX) +check_struct_has_member( + "struct statfs" + f_fstypename + "sys/mount.h" + HAVE_STATFS_FSTYPENAME) + +check_struct_has_member( + "struct statvfs" + f_fstypename + "sys/mount.h" + HAVE_STATVFS_FSTYPENAME) + +# statfs: Find whether this struct exists +if (HAVE_STATFS_FSTYPENAME OR HAVE_STATVFS_FSTYPENAME) + set (STATFS_INCLUDES sys/mount.h) +else () + set (STATFS_INCLUDES sys/statfs.h) +endif () + +check_prototype_definition( + statfs + "int statfs(const char *path, struct statfs *buf)" + 0 + ${STATFS_INCLUDES} + HAVE_NON_LEGACY_STATFS) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h) diff --git a/src/coreclr/src/pal/src/exception/remote-unwind.cpp b/src/coreclr/src/pal/src/exception/remote-unwind.cpp index f1251fd7a0ab4..355905e334736 100644 --- a/src/coreclr/src/pal/src/exception/remote-unwind.cpp +++ b/src/coreclr/src/pal/src/exception/remote-unwind.cpp @@ -359,10 +359,12 @@ find_proc_info(unw_addr_space_t as, unw_word_t ip, unw_proc_info_t *pip, int nee ehFrameHdrLen = ph.p_memsz; break; +#ifdef PT_ARM_EXIDX case PT_ARM_EXIDX: exidxFrameHdrAddr = loadbias + ph.p_vaddr; exidxFrameHdrLen = ph.p_memsz; break; +#endif } } diff --git a/src/coreclr/src/pal/src/exception/seh.cpp b/src/coreclr/src/pal/src/exception/seh.cpp index e0ebff145b893..f194156509d49 100644 --- a/src/coreclr/src/pal/src/exception/seh.cpp +++ b/src/coreclr/src/pal/src/exception/seh.cpp @@ -271,7 +271,7 @@ SEHProcessException(PAL_SEHException* exception) void* stackLimit = CPalThread::GetStackLimit(); void* stackOverflowBottom = (void*)((size_t)stackLimit - GetVirtualPageSize()); // On some versions of glibc / platforms the stackLimit is an address of the guard page, on some - // it is right above the guard page. + // it is right above the guard page. // So consider SIGSEGV in one page above and below stack limit to be stack overflow. void* stackOverflowTop = (void*)((size_t)stackLimit + GetVirtualPageSize()); void* violationAddr = (void*)exceptionRecord->ExceptionInformation[1]; @@ -322,9 +322,7 @@ PAL_ERROR SEHEnable(CPalThread *pthrCurrent) { #if HAVE_MACH_EXCEPTIONS return pthrCurrent->EnableMachExceptions(); -#elif defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) - // TODO: This needs to be implemented. Cannot put an ASSERT here - // because it will make other parts of PAL fail. +#elif defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__sun) return NO_ERROR; #else// HAVE_MACH_EXCEPTIONS #error not yet implemented @@ -349,9 +347,7 @@ PAL_ERROR SEHDisable(CPalThread *pthrCurrent) { #if HAVE_MACH_EXCEPTIONS return pthrCurrent->DisableMachExceptions(); - // TODO: This needs to be implemented. Cannot put an ASSERT here - // because it will make other parts of PAL fail. -#elif defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) +#elif defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__sun) return NO_ERROR; #else // HAVE_MACH_EXCEPTIONS #error not yet implemented diff --git a/src/coreclr/src/pal/src/exception/signal.cpp b/src/coreclr/src/pal/src/exception/signal.cpp index d6d8256610e5c..27ea7c2df015d 100644 --- a/src/coreclr/src/pal/src/exception/signal.cpp +++ b/src/coreclr/src/pal/src/exception/signal.cpp @@ -183,7 +183,11 @@ BOOL SEHInitializeSignals(CorUnix::CPalThread *pthrCurrent, DWORD flags) int stackOverflowStackSize = ALIGN_UP(sizeof(SignalHandlerWorkerReturnPoint), 16) + 7 * 4096; // Align the size to virtual page size and add one virtual page as a stack guard stackOverflowStackSize = ALIGN_UP(stackOverflowStackSize, GetVirtualPageSize()) + GetVirtualPageSize(); - g_stackOverflowHandlerStack = mmap(NULL, stackOverflowStackSize, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_STACK | MAP_PRIVATE, -1, 0); + int flags = MAP_ANONYMOUS | MAP_PRIVATE; +#ifdef MAP_STACK + flags |= MAP_STACK; +#endif + g_stackOverflowHandlerStack = mmap(NULL, stackOverflowStackSize, PROT_READ | PROT_WRITE, flags, -1, 0); if (g_stackOverflowHandlerStack == MAP_FAILED) { return FALSE; @@ -534,7 +538,7 @@ static void sigsegv_handler(int code, siginfo_t *siginfo, void *context) { (void)write(STDERR_FILENO, StackOverflowMessage, sizeof(StackOverflowMessage) - 1); PROCAbort(); - } + } } // Now that we know the SIGSEGV didn't happen due to a stack overflow, execute the common diff --git a/src/coreclr/src/pal/src/file/file.cpp b/src/coreclr/src/pal/src/file/file.cpp index 20dcfc43326c0..92695fd631590 100644 --- a/src/coreclr/src/pal/src/file/file.cpp +++ b/src/coreclr/src/pal/src/file/file.cpp @@ -679,6 +679,14 @@ CorUnix::InternalCreateFile( palError = ERROR_INTERNAL_ERROR; goto done; } +#elif HAVE_DIRECTIO + if (-1 == directio(filed, DIRECTIO_ON)) + { + ASSERT("Can't set DIRECTIO_ON; directio() failed. errno is %d (%s)\n", + errno, strerror(errno)); + palError = ERROR_INTERNAL_ERROR; + goto done; + } #else #error Insufficient support for uncached I/O on this platform #endif diff --git a/src/coreclr/src/pal/src/include/pal/context.h b/src/coreclr/src/pal/src/include/pal/context.h index 482ec3471c5cd..9313fc51653f7 100644 --- a/src/coreclr/src/pal/src/include/pal/context.h +++ b/src/coreclr/src/pal/src/include/pal/context.h @@ -121,7 +121,11 @@ using asm_sigcontext::_xstate; #define MCREG_Rax(mc) ((mc).gregs[REG_RAX]) #define MCREG_Rip(mc) ((mc).gregs[REG_RIP]) #define MCREG_Rsp(mc) ((mc).gregs[REG_RSP]) +#ifdef REG_CSGSFS #define MCREG_SegCs(mc) (*(WORD*)&((mc).gregs[REG_CSGSFS])) +#else +#define MCREG_SegCs(mc) (*(WORD*)&((mc).gregs[REG_CS])) +#endif #define MCREG_R8(mc) ((mc).gregs[REG_R8]) #define MCREG_R9(mc) ((mc).gregs[REG_R9]) #define MCREG_R10(mc) ((mc).gregs[REG_R10]) @@ -131,20 +135,35 @@ using asm_sigcontext::_xstate; #define MCREG_R14(mc) ((mc).gregs[REG_R14]) #define MCREG_R15(mc) ((mc).gregs[REG_R15]) +#if HAVE_FPREGS_WITH_CW +#define FPREG_Fpstate(uc) (&((uc)->uc_mcontext.fpregs.fp_reg_set.fpchip_state)) + +#define FPREG_Xmm(uc, index) *(M128A*)&(FPREG_Fpstate(uc)->xmm[index]) +#define FPREG_St(uc, index) *(M128A*)&(FPREG_Fpstate(uc)->st[index]) +#define FPREG_ControlWord(uc) (FPREG_Fpstate(uc)->cw) +#define FPREG_StatusWord(uc) (FPREG_Fpstate(uc)->sw) +#define FPREG_MxCsr_Mask(uc) (FPREG_Fpstate(uc)->mxcsr_mask) + +// on SunOS, fctw and __fx_rsvd are uint8_t, whereas on linux ftw is uint16_t, +// so we use split and join technique for these two uint8_t members at call sites. +#define FPREG_TagWord1(uc) (FPREG_Fpstate(uc)->fctw) +#define FPREG_TagWord2(uc) (FPREG_Fpstate(uc)->__fx_rsvd) +#else #define FPREG_Fpstate(uc) ((uc)->uc_mcontext.fpregs) -#define FPREG_Xmm(uc, index) *(M128A*)&(FPREG_Fpstate(uc)->_xmm[index]) +#define FPREG_Xmm(uc, index) *(M128A*)&(FPREG_Fpstate(uc)->_xmm[index]) #define FPREG_St(uc, index) *(M128A*)&(FPREG_Fpstate(uc)->_st[index]) - #define FPREG_ControlWord(uc) (FPREG_Fpstate(uc)->cwd) #define FPREG_StatusWord(uc) (FPREG_Fpstate(uc)->swd) #define FPREG_TagWord(uc) (FPREG_Fpstate(uc)->ftw) +#define FPREG_MxCsr_Mask(uc) (FPREG_Fpstate(uc)->mxcr_mask) +#endif + #define FPREG_ErrorOffset(uc) *(DWORD*)&(FPREG_Fpstate(uc)->rip) #define FPREG_ErrorSelector(uc) *(((WORD*)&(FPREG_Fpstate(uc)->rip)) + 2) #define FPREG_DataOffset(uc) *(DWORD*)&(FPREG_Fpstate(uc)->rdp) #define FPREG_DataSelector(uc) *(((WORD*)&(FPREG_Fpstate(uc)->rdp)) + 2) #define FPREG_MxCsr(uc) (FPREG_Fpstate(uc)->mxcsr) -#define FPREG_MxCsr_Mask(uc) (FPREG_Fpstate(uc)->mxcr_mask) ///////////////////// // Extended state @@ -239,7 +258,11 @@ inline void *FPREG_Xstate_Ymmh(const ucontext_t *uc) #endif // HOST_64BIT +#ifdef REG_EFL #define MCREG_EFlags(mc) ((mc).gregs[REG_EFL]) +#else +#define MCREG_EFlags(mc) ((mc).gregs[EFL]) +#endif #else // HAVE_GREGSET_T diff --git a/src/coreclr/src/pal/src/map/map.cpp b/src/coreclr/src/pal/src/map/map.cpp index ddc715b25c994..cac736460bb3f 100644 --- a/src/coreclr/src/pal/src/map/map.cpp +++ b/src/coreclr/src/pal/src/map/map.cpp @@ -2706,7 +2706,7 @@ BOOL MAPMarkSectionAsNotNeeded(LPCVOID lpAddress) if (pView->lpAddress == lpAddress) // this entry is associated with the section { - if (-1 == madvise(pView->lpAddress, pView->NumberOfBytesToMap, MADV_DONTNEED)) + if (-1 == posix_madvise(pView->lpAddress, pView->NumberOfBytesToMap, POSIX_MADV_DONTNEED)) { ERROR_(LOADER)("Unable to mark the section as NotNeeded.\n"); retval = FALSE; diff --git a/src/coreclr/src/pal/src/map/virtual.cpp b/src/coreclr/src/pal/src/map/virtual.cpp index 571273cf40d8b..d6a33c793143c 100644 --- a/src/coreclr/src/pal/src/map/virtual.cpp +++ b/src/coreclr/src/pal/src/map/virtual.cpp @@ -141,7 +141,7 @@ namespace VirtualMemoryLogging LogRecord* curRec = (LogRecord*)&logRecords[i % MaxRecords]; curRec->RecordId = i; - curRec->CurrentThread = (LPVOID)pthread_self(); + curRec->CurrentThread = reinterpret_cast(pthread_self()); curRec->RequestedAddress = requestedAddress; curRec->ReturnedAddress = returnedAddress; curRec->Size = size; @@ -847,7 +847,7 @@ static LPVOID VIRTUALResetMemory( #endif { // In case the MADV_FREE is not supported, use MADV_DONTNEED - st = madvise((LPVOID)StartBoundary, MemSize, MADV_DONTNEED); + st = posix_madvise((LPVOID)StartBoundary, MemSize, POSIX_MADV_DONTNEED); } if (st == 0) diff --git a/src/coreclr/src/pal/src/misc/cgroup.cpp b/src/coreclr/src/pal/src/misc/cgroup.cpp index df6d59f0c7756..42a5dd27d2756 100644 --- a/src/coreclr/src/pal/src/misc/cgroup.cpp +++ b/src/coreclr/src/pal/src/misc/cgroup.cpp @@ -121,8 +121,12 @@ class CGroup // modes because both of those involve cgroup v1 controllers managing // resources. +#if !HAVE_NON_LEGACY_STATFS + return 0; +#else struct statfs stats; int result = statfs("/sys/fs/cgroup", &stats); + if (result != 0) return 0; @@ -134,6 +138,7 @@ class CGroup _ASSERTE(!"Unexpected file system type for /sys/fs/cgroup"); return 0; } +#endif } static bool IsCGroup1MemorySubsystem(const char *strTok){ diff --git a/src/coreclr/src/pal/src/misc/sysinfo.cpp b/src/coreclr/src/pal/src/misc/sysinfo.cpp index 7e9bf4b3b6e6f..17efa171c2848 100644 --- a/src/coreclr/src/pal/src/misc/sysinfo.cpp +++ b/src/coreclr/src/pal/src/misc/sysinfo.cpp @@ -93,6 +93,10 @@ Revision History: #include +#if HAVE_SWAPCTL +#include +#endif + SET_DEFAULT_DEBUG_CHANNEL(MISC); #ifndef __APPLE__ @@ -221,6 +225,8 @@ GetSystemInfo( lpSystemInfo->lpMaximumApplicationAddress = (PVOID) VM_MAXUSER_ADDRESS; #elif defined(__linux__) lpSystemInfo->lpMaximumApplicationAddress = (PVOID) (1ull << 47); +#elif defined(__sun) + lpSystemInfo->lpMaximumApplicationAddress = (PVOID) 0xfffffd7fffe00000ul; #elif defined(USERLIMIT) lpSystemInfo->lpMaximumApplicationAddress = (PVOID) USERLIMIT; #elif defined(HOST_64BIT) @@ -404,6 +410,14 @@ GlobalMemoryStatusEx( lpBuffer->ullAvailPageFile += (DWORDLONG)avail * pagesize; } } +#elif HAVE_SWAPCTL + struct anoninfo ai; + if (swapctl(SC_AINFO, &ai) != -1) + { + int pagesize = getpagesize(); + lpBuffer->ullTotalPageFile = ai.ani_max * pagesize; + lpBuffer->ullAvailPageFile = ai.ani_free * pagesize; + } #elif HAVE_SYSINFO // Linux struct sysinfo info; diff --git a/src/coreclr/src/pal/src/safecrt/input.inl b/src/coreclr/src/pal/src/safecrt/input.inl index 4045f423ca7b7..0f578e099ebae 100644 --- a/src/coreclr/src/pal/src/safecrt/input.inl +++ b/src/coreclr/src/pal/src/safecrt/input.inl @@ -115,6 +115,9 @@ static int __cdecl _whiteout(int *, miniFILE *); #endif /* CPRFLAG */ +#undef _ISDIGIT +#undef _ISXDIGIT + #ifndef _UNICODE #define _ISDIGIT(chr) isdigit((unsigned char)chr) #define _ISXDIGIT(chr) isxdigit((unsigned char)chr) diff --git a/src/coreclr/src/pal/src/safecrt/mbusafecrt_internal.h b/src/coreclr/src/pal/src/safecrt/mbusafecrt_internal.h index 00136ecfe2839..4f9ee5f6c5af0 100644 --- a/src/coreclr/src/pal/src/safecrt/mbusafecrt_internal.h +++ b/src/coreclr/src/pal/src/safecrt/mbusafecrt_internal.h @@ -65,6 +65,10 @@ typedef struct miniFILE_struct int _flag; } miniFILE; +#undef _IOWRT +#undef _IOREAD +#undef _IOMYBUF + #define _IOSTRG 1 #define _IOWRT 2 #define _IOREAD 4 diff --git a/src/coreclr/src/pal/src/shmemory/shmemory.cpp b/src/coreclr/src/pal/src/shmemory/shmemory.cpp index 46d8e160fef24..9539d10aebec7 100644 --- a/src/coreclr/src/pal/src/shmemory/shmemory.cpp +++ b/src/coreclr/src/pal/src/shmemory/shmemory.cpp @@ -155,7 +155,7 @@ int SHMLock(void) PALCEnterCriticalSection(&shm_critsec); _ASSERTE((0 == lock_count && 0 == locking_thread) || - (0 < lock_count && (HANDLE)pthread_self() == locking_thread)); + (0 < lock_count && reinterpret_cast(pthread_self()) == locking_thread)); if(lock_count == 0) { @@ -166,7 +166,7 @@ int SHMLock(void) // Store the id of the current thread as the (only) one that is // trying to grab the spinlock from the current process - locking_thread = (HANDLE)pthread_self(); + locking_thread = reinterpret_cast(pthread_self()); my_pid = gPID; @@ -336,7 +336,7 @@ SHMPTR SHMGetInfo(SHM_INFO_ID element) /* verify that this thread holds the SHM lock. No race condition: if the current thread is here, it can't be in SHMLock or SHMUnlock */ - if( (HANDLE)pthread_self() != locking_thread ) + if( reinterpret_cast(pthread_self()) != locking_thread ) { ASSERT("SHMGetInfo called while thread does not hold the SHM lock!\n"); } @@ -374,7 +374,7 @@ BOOL SHMSetInfo(SHM_INFO_ID element, SHMPTR value) /* verify that this thread holds the SHM lock. No race condition: if the current thread is here, it can't be in SHMLock or SHMUnlock */ - if( (HANDLE)pthread_self() != locking_thread ) + if( reinterpret_cast(pthread_self()) != locking_thread ) { ASSERT("SHMGetInfo called while thread does not hold the SHM lock!\n"); } diff --git a/src/coreclr/src/pal/src/thread/context.cpp b/src/coreclr/src/pal/src/thread/context.cpp index a89bdb2649f0d..435b04715eda4 100644 --- a/src/coreclr/src/pal/src/thread/context.cpp +++ b/src/coreclr/src/pal/src/thread/context.cpp @@ -29,7 +29,9 @@ SET_DEFAULT_DEBUG_CHANNEL(THREAD); // some headers have code with asserts, so do #include "pal/utils.h" #include "pal/virtual.h" +#if HAVE_SYS_PTRACE_H #include +#endif #include #include @@ -428,26 +430,33 @@ void CONTEXTToNativeContext(CONST CONTEXT *lpContext, native_context_t *native) } #undef ASSIGN_REG +#if !HAVE_FPREGS_WITH_CW #if HAVE_GREGSET_T || HAVE_GREGSET_T #if HAVE_GREGSET_T if (native->uc_mcontext.fpregs == nullptr) #elif HAVE___GREGSET_T if (native->uc_mcontext.__fpregs == nullptr) -#endif +#endif // HAVE_GREGSET_T { // If the pointer to the floating point state in the native context // is not valid, we can't copy floating point registers regardless of // whether CONTEXT_FLOATING_POINT is set in the CONTEXT's flags. return; } -#endif +#endif // HAVE_GREGSET_T || HAVE_GREGSET_T +#endif // !HAVE_FPREGS_WITH_CW if ((lpContext->ContextFlags & CONTEXT_FLOATING_POINT) == CONTEXT_FLOATING_POINT) { #ifdef HOST_AMD64 FPREG_ControlWord(native) = lpContext->FltSave.ControlWord; FPREG_StatusWord(native) = lpContext->FltSave.StatusWord; +#if HAVE_FPREGS_WITH_CW + FPREG_TagWord1(native) = lpContext->FltSave.TagWord >> 8; + FPREG_TagWord2(native) = lpContext->FltSave.TagWord & 0xff; +#else FPREG_TagWord(native) = lpContext->FltSave.TagWord; +#endif FPREG_ErrorOffset(native) = lpContext->FltSave.ErrorOffset; FPREG_ErrorSelector(native) = lpContext->FltSave.ErrorSelector; FPREG_DataOffset(native) = lpContext->FltSave.DataOffset; @@ -537,12 +546,13 @@ void CONTEXTFromNativeContext(const native_context_t *native, LPCONTEXT lpContex } #undef ASSIGN_REG +#if !HAVE_FPREGS_WITH_CW #if HAVE_GREGSET_T || HAVE___GREGSET_T #if HAVE_GREGSET_T if (native->uc_mcontext.fpregs == nullptr) #elif HAVE___GREGSET_T if (native->uc_mcontext.__fpregs == nullptr) -#endif +#endif // HAVE_GREGSET_T { // Reset the CONTEXT_FLOATING_POINT bit(s) and the CONTEXT_XSTATE bit(s) so it's // clear that the floating point and extended state data in the CONTEXT is not @@ -559,14 +569,19 @@ void CONTEXTFromNativeContext(const native_context_t *native, LPCONTEXT lpContex // Bail out regardless of whether the caller wanted CONTEXT_FLOATING_POINT or CONTEXT_XSTATE return; } -#endif +#endif // HAVE_GREGSET_T || HAVE___GREGSET_T +#endif // !HAVE_FPREGS_WITH_CW if ((contextFlags & CONTEXT_FLOATING_POINT) == CONTEXT_FLOATING_POINT) { #ifdef HOST_AMD64 lpContext->FltSave.ControlWord = FPREG_ControlWord(native); lpContext->FltSave.StatusWord = FPREG_StatusWord(native); +#if HAVE_FPREGS_WITH_CW + lpContext->FltSave.TagWord = ((DWORD)FPREG_TagWord1(native) << 8) | FPREG_TagWord2(native); +#else lpContext->FltSave.TagWord = FPREG_TagWord(native); +#endif lpContext->FltSave.ErrorOffset = FPREG_ErrorOffset(native); lpContext->FltSave.ErrorSelector = FPREG_ErrorSelector(native); lpContext->FltSave.DataOffset = FPREG_DataOffset(native); diff --git a/src/coreclr/src/pal/src/thread/process.cpp b/src/coreclr/src/pal/src/thread/process.cpp index 49c1291adc6d8..e002f236d47ae 100644 --- a/src/coreclr/src/pal/src/thread/process.cpp +++ b/src/coreclr/src/pal/src/thread/process.cpp @@ -198,8 +198,11 @@ PathCharString* gSharedFilesPath = nullptr; #define CLR_SEM_MAX_NAMELEN 15 #elif defined(__APPLE__) #define CLR_SEM_MAX_NAMELEN PSEMNAMLEN -#else +#elif defined(NAME_MAX) #define CLR_SEM_MAX_NAMELEN (NAME_MAX - 4) +#else +// On Solaris, MAXNAMLEN is 512, which is higher than MAX_PATH defined by pal.h +#define CLR_SEM_MAX_NAMELEN MAX_PATH #endif static_assert_no_msg(CLR_SEM_MAX_NAMELEN <= MAX_PATH); diff --git a/src/coreclr/src/pal/src/thread/thread.cpp b/src/coreclr/src/pal/src/thread/thread.cpp index 159ef03cf0b60..a6a14c20f9ba8 100644 --- a/src/coreclr/src/pal/src/thread/thread.cpp +++ b/src/coreclr/src/pal/src/thread/thread.cpp @@ -1580,7 +1580,7 @@ GetThreadTimes( HRESULT PALAPI -SetThreadDescription( +SetThreadDescription( IN HANDLE hThread, IN PCWSTR lpThreadDescription) { @@ -1673,7 +1673,7 @@ CorUnix::InternalSetThreadDescription( error = pthread_setname_np(pTargetThread->GetPThreadSelf(), nameBuf); - if (error != 0) + if (error != 0) { palError = ERROR_INTERNAL_ERROR; } @@ -2490,7 +2490,11 @@ CPalThread::EnsureSignalAlternateStack() altStackSize += SIGSTKSZ * 4; #endif altStackSize = ALIGN_UP(altStackSize, GetVirtualPageSize()); - void* altStack = mmap(NULL, altStackSize, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_STACK | MAP_PRIVATE, -1, 0); + int flags = MAP_ANONYMOUS | MAP_PRIVATE; +#ifdef MAP_STACK + flags |= MAP_STACK; +#endif + void* altStack = mmap(NULL, altStackSize, PROT_READ | PROT_WRITE, flags, -1, 0); if (altStack != MAP_FAILED) { // create a guard page for the alternate stack diff --git a/src/coreclr/src/pal/tests/palsuite/exception_handling/pal_sxs/test1/CMakeLists.txt b/src/coreclr/src/pal/tests/palsuite/exception_handling/pal_sxs/test1/CMakeLists.txt index 353e578446292..ff2588ce21a1a 100644 --- a/src/coreclr/src/pal/tests/palsuite/exception_handling/pal_sxs/test1/CMakeLists.txt +++ b/src/coreclr/src/pal/tests/palsuite/exception_handling/pal_sxs/test1/CMakeLists.txt @@ -24,7 +24,12 @@ endif(CLR_CMAKE_TARGET_LINUX OR CLR_CMAKE_TARGET_FREEBSD OR CLR_CMAKE_TARGET_NET if(CLR_CMAKE_TARGET_OSX) set(EXPORTS_LINKER_OPTION1 -Wl,-exported_symbols_list,${EXPORTS_FILE1}) -endif(CLR_CMAKE_TARGET_OSX) +endif(CLR_CMAKE_HOST_OSX) + +if(CLR_CMAKE_HOST_SUNOS) + # Add linker exports file option + set(EXPORTS_LINKER_OPTION -Wl,-M,${EXPORTS_FILE}) +endif(CLR_CMAKE_HOST_SUNOS) set(DLL1SOURCES dlltest1.cpp) add_library(paltest_pal_sxs_test1_dll1 SHARED ${DLL1SOURCES}) diff --git a/src/coreclr/src/pal/tools/gen-dactable-rva.sh b/src/coreclr/src/pal/tools/gen-dactable-rva.sh index fd4fa76c6eaab..c1fc13118deb3 100644 --- a/src/coreclr/src/pal/tools/gen-dactable-rva.sh +++ b/src/coreclr/src/pal/tools/gen-dactable-rva.sh @@ -1 +1 @@ -${NM:-nm} $1 | grep g_dacTable | cut -f 1 -d' ' | head -n 1 | awk '{ print "#define DAC_TABLE_RVA 0x" $1}' > $2 +${NM:-nm} -P -t x $1 | awk -F ' ' '/g_dacTable/ { print "#define DAC_TABLE_RVA 0x" substr("0000000000000000" $3, length($3) + 1); exit }' > $2 diff --git a/src/coreclr/src/tools/crossgen/CMakeLists.txt b/src/coreclr/src/tools/crossgen/CMakeLists.txt index a8a4629a65420..685ba73c11fe5 100644 --- a/src/coreclr/src/tools/crossgen/CMakeLists.txt +++ b/src/coreclr/src/tools/crossgen/CMakeLists.txt @@ -30,12 +30,12 @@ if(FEATURE_MERGE_JIT_AND_ENGINE) set(CLRJIT_CROSSGEN clrjit_crossgen) endif(FEATURE_MERGE_JIT_AND_ENGINE) -if(CLR_CMAKE_HOST_LINUX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD) +if(CLR_CMAKE_HOST_LINUX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS) # The following linked options can be inserted into the linker libraries list to # ensure proper resolving of circular references between a subset of the libraries. set(START_LIBRARY_GROUP -Wl,--start-group) set(END_LIBRARY_GROUP -Wl,--end-group) -endif(CLR_CMAKE_HOST_LINUX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD) +endif(CLR_CMAKE_HOST_LINUX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS) target_link_libraries(crossgen ${START_LIBRARY_GROUP} # Start group of libraries that have circular references diff --git a/src/libraries/Native/Unix/configure.cmake b/src/libraries/Native/Unix/configure.cmake index 8faaf1f56444a..eec3f32c94d33 100644 --- a/src/libraries/Native/Unix/configure.cmake +++ b/src/libraries/Native/Unix/configure.cmake @@ -31,9 +31,9 @@ elseif (CLR_CMAKE_TARGET_NETBSD) set(PAL_UNIX_NAME \"NETBSD\") elseif (CLR_CMAKE_TARGET_SUNOS) set(PAL_UNIX_NAME \"SUNOS\") - set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} /opt/local/include) - set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} /opt/local/lib) - include_directories(SYSTEM /opt/local/include) + # requires /opt/tools when building in Global Zone (GZ) + include_directories(SYSTEM /opt/local/include /opt/tools/include) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector") else () message(FATAL_ERROR "Unknown platform. Cannot define PAL_UNIX_NAME, used by RuntimeInformation.") endif ()