Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/coreclr/debug/createdump/crashinfounix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,8 @@ CrashInfo::VisitProgramHeader(uint64_t loadbias, uint64_t baseAddress, Phdr* phd
TRACE("VisitProgramHeader: ehFrameHdrStart %016llx ehFrameHdrSize %08llx\n", ehFrameHdrStart, ehFrameHdrSize);
InsertMemoryRegion(ehFrameHdrStart, ehFrameHdrSize);

uint64_t ehFrameStart;
uint64_t ehFrameSize;
ULONG64 ehFrameStart;
ULONG64 ehFrameSize;
if (PAL_GetUnwindInfoSize(baseAddress, ehFrameHdrStart, ReadMemoryAdapter, &ehFrameStart, &ehFrameSize))
{
TRACE("VisitProgramHeader: ehFrameStart %016llx ehFrameSize %08llx\n", ehFrameStart, ehFrameSize);
Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/debug/inc/dacdbistructures.inl
Original file line number Diff line number Diff line change
Expand Up @@ -640,8 +640,6 @@ void FieldData::ClearFields()
m_pFldStaticAddress = NULL;
}

typedef ULONG_PTR SIZE_T;

inline
BOOL FieldData::OkToGetOrSetInstanceOffset()
{
Expand Down
3 changes: 0 additions & 3 deletions src/coreclr/dlls/mscordac/mscordac_unixexports.src
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ nativeStringResourceTable_mscorrc
#PAL_fwprintf
#PAL_GetLogicalCpuCountFromOS
#PAL_GetTotalCpuCount
#PAL_GetNumaProcessorNode
#PAL_GetUnwindInfoSize
#PAL_get_stdout
#PAL_get_stderr
Expand Down Expand Up @@ -126,7 +125,6 @@ nativeStringResourceTable_mscorrc
#GetFullPathNameW
#GetLastError
#GetModuleFileNameW
#GetNumaHighestNodeNumber
#GetProcAddress
#GetStdHandle
#GetSystemInfo
Expand Down Expand Up @@ -168,7 +166,6 @@ nativeStringResourceTable_mscorrc
#SwitchToThread
#TerminateProcess
#VirtualAlloc
#VirtualAllocExNuma
#VirtualFree
#VirtualProtect
#VirtualQuery
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ set_property(TARGET coreclr APPEND_STRING PROPERTY LINK_DEPENDS ${EXPORTS_FILE})

if (CLR_CMAKE_HOST_UNIX)
set(LIB_UNWINDER unwinder_wks)
set(GC_PAL gc_unix)
endif (CLR_CMAKE_HOST_UNIX)

# IMPORTANT! Please do not rearrange the order of the libraries. The linker on Linux is
Expand All @@ -108,6 +109,7 @@ set(CORECLR_LIBRARIES
System.Globalization.Native-Static
interop
coreclrminipal
${GC_PAL}
)

if(CLR_CMAKE_TARGET_WIN32)
Expand Down
8 changes: 3 additions & 5 deletions src/coreclr/gc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ set(GC_SOURCES
handletablecache.cpp)

if(CLR_CMAKE_HOST_UNIX)
add_subdirectory(unix)
include(unix/configure.cmake)
set (GC_SOURCES
${GC_SOURCES}
unix/gcenv.unix.cpp
unix/events.cpp
unix/cgroup.cpp)
${GC_SOURCES})
else()
set (GC_SOURCES
${GC_SOURCES}
Expand Down Expand Up @@ -101,7 +99,7 @@ if(CLR_CMAKE_HOST_WIN32)
kernel32.lib
advapi32.lib)
else()
set (GC_LINK_LIBRARIES)
set (GC_LINK_LIBRARIES gc_unix)
endif(CLR_CMAKE_HOST_WIN32)

list(APPEND GC_SOURCES ${GC_HEADERS})
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/gc/unix/cgroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ Module Name:

extern bool ReadMemoryValueFromFile(const char* filename, uint64_t* val);

namespace
{
class CGroup
{
// the cgroup version number or 0 to indicate cgroups are not found or not enabled
Expand Down Expand Up @@ -453,6 +455,7 @@ class CGroup
return foundInactiveFileValue;
}
};
}

int CGroup::s_cgroup_version = 0;
char *CGroup::s_memory_cgroup_path = nullptr;
Expand Down
39 changes: 35 additions & 4 deletions src/coreclr/gc/unix/gcenv.unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,15 +633,15 @@ void GCToOSInterface::YieldThread(uint32_t switchCount)
static void* VirtualReserveInner(size_t size, size_t alignment, uint32_t flags, uint32_t hugePagesFlag = 0)
{
assert(!(flags & VirtualReserveFlags::WriteWatch) && "WriteWatch not supported on Unix");
if (alignment == 0)
if (alignment < OS_PAGE_SIZE)
{
alignment = OS_PAGE_SIZE;
}

size_t alignedSize = size + (alignment - OS_PAGE_SIZE);
void * pRetVal = mmap(nullptr, alignedSize, PROT_NONE, MAP_ANON | MAP_PRIVATE | hugePagesFlag, -1, 0);

if (pRetVal != NULL)
if (pRetVal != MAP_FAILED)
{
void * pAlignedRetVal = (void *)(((size_t)pRetVal + (alignment - 1)) & ~(alignment - 1));
size_t startPadding = (size_t)pAlignedRetVal - (size_t)pRetVal;
Expand All @@ -659,9 +659,14 @@ static void* VirtualReserveInner(size_t size, size_t alignment, uint32_t flags,
}

pRetVal = pAlignedRetVal;
#ifdef MADV_DONTDUMP
// Do not include reserved memory in coredump.
madvise(pRetVal, size, MADV_DONTDUMP);
#endif
return pRetVal;
}

return pRetVal;
return NULL; // return NULL if mmap failed
}

// Reserve virtual memory range.
Expand Down Expand Up @@ -724,6 +729,14 @@ bool GCToOSInterface::VirtualCommit(void* address, size_t size, uint16_t node)
{
bool success = mprotect(address, size, PROT_WRITE | PROT_READ) == 0;

#ifdef MADV_DODUMP
if (success)
{
// Include committed memory in coredump.
madvise(address, size, MADV_DODUMP);
}
#endif

#if HAVE_NUMA_H
if (success && g_numaAvailable && (node != NUMA_NODE_UNDEFINED))
{
Expand Down Expand Up @@ -760,7 +773,17 @@ bool GCToOSInterface::VirtualDecommit(void* address, size_t size)
// that much more clear to the operating system that we no
// longer need these pages. Also, GC depends on re-committed pages to
// be zeroed-out.
return mmap(address, size, PROT_NONE, MAP_FIXED | MAP_ANON | MAP_PRIVATE, -1, 0) != NULL;
bool bRetVal = mmap(address, size, PROT_NONE, MAP_FIXED | MAP_ANON | MAP_PRIVATE, -1, 0) != MAP_FAILED;

#ifdef MADV_DONTDUMP
if (bRetVal)
{
// Do not include freed memory in coredump.
madvise(address, size, MADV_DONTDUMP);
}
#endif

return bRetVal;
}

// Reset virtual memory range. Indicates that data in the memory range specified by address and size is no
Expand Down Expand Up @@ -791,6 +814,14 @@ bool GCToOSInterface::VirtualReset(void * address, size_t size, bool unlock)
#endif
}

#ifdef MADV_DONTDUMP
if (st == 0)
{
// Do not include reset memory in coredump.
madvise(address, size, MADV_DONTDUMP);
}
#endif

return (st == 0);
}

Expand Down
8 changes: 8 additions & 0 deletions src/coreclr/inc/check.inl
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,14 @@ inline CHECK CheckOverflow(const void *address, UINT64 offset)
CHECK_OK;
}

#ifdef __APPLE__
inline CHECK CheckOverflow(const void *address, SIZE_T offset)
{
CHECK((UINT64) address + offset >= (UINT64) address);

CHECK_OK;
}
#endif // __APPLE__

inline CHECK CheckUnderflow(UINT value1, UINT value2)
{
Expand Down
26 changes: 26 additions & 0 deletions src/coreclr/inc/clrtypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,15 @@ inline UINT64 AlignUp(UINT64 value, UINT alignment)
return (value+alignment-1)&~(UINT64)(alignment-1);
}

#ifdef __APPLE__
inline SIZE_T AlignUp(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_LEAF;
STATIC_CONTRACT_SUPPORTS_DAC;
return (value+alignment-1)&~(SIZE_T)(alignment-1);
}
#endif // __APPLE__

inline UINT AlignDown(UINT value, UINT alignment)
{
STATIC_CONTRACT_LEAF;
Expand Down Expand Up @@ -381,6 +390,14 @@ inline UINT AlignmentPad(UINT64 value, UINT alignment)
return (UINT) (AlignUp(value, alignment) - value);
}

#ifdef __APPLE__
inline UINT AlignmentPad(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_WRAPPER;
return (UINT) (AlignUp(value, alignment) - value);
}
#endif // __APPLE__

inline UINT AlignmentTrim(UINT value, UINT alignment)
{
STATIC_CONTRACT_LEAF;
Expand All @@ -406,4 +423,13 @@ inline UINT AlignmentTrim(UINT64 value, UINT alignment)
return ((UINT)value)&(alignment-1);
}

#ifdef __APPLE__
inline UINT AlignmentTrim(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_LEAF;
STATIC_CONTRACT_SUPPORTS_DAC;
return ((UINT)value)&(alignment-1);
}
#endif // __APPLE__

#endif // CLRTYPES_H_
6 changes: 6 additions & 0 deletions src/coreclr/inc/daccess.h
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,12 @@ class __DPtrBase : public __TPtrBase
{
return DPtrType(DacTAddrOffset(m_addr, val, sizeof(type)));
}
#if defined(HOST_UNIX) && defined(HOST_64BIT)
DPtrType operator+(unsigned long long val)
{
return DPtrType(DacTAddrOffset(m_addr, val, sizeof(type)));
}
#endif // HOST_UNIX && HOST_BIT64
DPtrType operator+(short val)
{
return DPtrType(m_addr + val * sizeof(type));
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/inc/regdisp.h
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ inline size_t * getRegAddr (unsigned regNum, PTR_CONTEXT regs)
return (PTR_size_t)(PTR_BYTE(regs) + OFFSET_OF_REGISTERS[regNum]);
#elif defined(TARGET_AMD64)
_ASSERTE(regNum < 16);
return &regs->Rax + regNum;
return (size_t *)&regs->Rax + regNum;
#elif defined(TARGET_ARM)
_ASSERTE(regNum < 16);
return (size_t *)&regs->R0 + regNum;
Expand Down
10 changes: 9 additions & 1 deletion src/coreclr/jit/compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,13 @@ inline unsigned genLog2(unsigned __int64 value)
#endif
}

#ifdef __APPLE__
inline unsigned genLog2(size_t value)
{
return genLog2((unsigned __int64)value);
}
#endif // __APPLE__

/*****************************************************************************
*
* Return the lowest bit that is set in the given register mask.
Expand Down Expand Up @@ -1557,7 +1564,8 @@ void GenTree::BashToConst(T value, var_types type /* = TYP_UNDEF */)
{
static_assert_no_msg((std::is_same<T, int32_t>::value || std::is_same<T, int64_t>::value ||
std::is_same<T, long long>::value || std::is_same<T, float>::value ||
std::is_same<T, double>::value));
std::is_same<T, ssize_t>::value || std::is_same<T, double>::value));

static_assert_no_msg(sizeof(int64_t) == sizeof(long long));

var_types typeOfValue = TYP_UNDEF;
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/jit/gentree.h
Original file line number Diff line number Diff line change
Expand Up @@ -3290,7 +3290,8 @@ inline void GenTreeIntConCommon::SetIntegralValue(int64_t value)
template <typename T>
inline void GenTreeIntConCommon::SetValueTruncating(T value)
{
static_assert_no_msg((std::is_same<T, int32_t>::value || std::is_same<T, int64_t>::value));
static_assert_no_msg(
(std::is_same<T, int32_t>::value || std::is_same<T, int64_t>::value || std::is_same<T, ssize_t>::value));

if (TypeIs(TYP_LONG))
{
Expand Down
11 changes: 9 additions & 2 deletions src/coreclr/jit/jit.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@
#error Unsupported or unset target architecture
#endif

typedef ptrdiff_t ssize_t;

// Include the AMD64 unwind codes when appropriate.
#if defined(TARGET_AMD64)
#include "win64unwind.h"
Expand Down Expand Up @@ -349,8 +351,6 @@ typedef int NATIVE_OFFSET;
// this is used for native code sizes.
typedef unsigned UNATIVE_OFFSET;

typedef ptrdiff_t ssize_t;

// Type used for weights (e.g. block and edge weights)
typedef double weight_t;

Expand Down Expand Up @@ -631,9 +631,16 @@ inline unsigned int unsigned_abs(int x)

#ifdef TARGET_64BIT
inline size_t unsigned_abs(ssize_t x)
{
return ((size_t)abs((__int64)x));
}

#ifdef __APPLE__
inline size_t unsigned_abs(__int64 x)
{
return ((size_t)abs(x));
}
#endif // __APPLE__
#endif // TARGET_64BIT

/*****************************************************************************/
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/register.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ REGALIAS(EDI, RDI)

#ifdef TARGET_AMD64
#define XMMBASE 16
#define XMMMASK(x) (__int64(1) << ((x)+XMMBASE))
#define XMMMASK(x) ((__int64)(1) << ((x)+XMMBASE))
#else // !TARGET_AMD64
#define XMMBASE 8
#define XMMMASK(x) (__int32(1) << ((x)+XMMBASE))
#define XMMMASK(x) ((__int32)(1) << ((x)+XMMBASE))
#endif // !TARGET_AMD64

REGDEF(XMM0, 0+XMMBASE, XMMMASK(0), "mm0" )
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,7 @@ template <typename T>
bool FitsIn(var_types type, T value)
{
static_assert_no_msg((std::is_same<T, int32_t>::value || std::is_same<T, int64_t>::value ||
std::is_same<T, size_t>::value || std::is_same<T, ssize_t>::value ||
std::is_same<T, uint32_t>::value || std::is_same<T, uint64_t>::value));

switch (type)
Expand Down
6 changes: 6 additions & 0 deletions src/coreclr/pal/inc/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -4417,6 +4417,12 @@ inline __int64 abs(__int64 _X) {
return llabs(_X);
}

#ifdef __APPLE__
inline __int64 abs(SSIZE_T _X) {
return llabs((__int64)_X);
}
#endif

}
#endif

Expand Down
Loading