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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand Up@@ -126,7 +125,6 @@ nativeStringResourceTable_mscorrc
#GetFullPathNameW
#GetLastError
#GetModuleFileNameW
#GetNumaHighestNodeNumber
#GetProcAddress
#GetStdHandle
#GetSystemInfo
Expand DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
[WIP] Fix to move to using GC pal within coreclr on Linux by mangod9 · Pull Request #78521 · dotnet/runtime · GitHub
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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand Up@@ -126,7 +125,6 @@ nativeStringResourceTable_mscorrc
#GetFullPathNameW
#GetLastError
#GetModuleFileNameW
#GetNumaHighestNodeNumber
#GetProcAddress
#GetStdHandle
#GetSystemInfo
Expand DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' [WIP] Fix to move to using GC pal within coreclr on Linux by mangod9 · Pull Request #78521 · dotnet/runtime · GitHub
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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand Up@@ -126,7 +125,6 @@ nativeStringResourceTable_mscorrc
#GetFullPathNameW
#GetLastError
#GetModuleFileNameW
#GetNumaHighestNodeNumber
#GetProcAddress
#GetStdHandle
#GetSystemInfo
Expand DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' [WIP] Fix to move to using GC pal within coreclr on Linux by mangod9 · Pull Request #78521 · dotnet/runtime · GitHub
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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand Up@@ -126,7 +125,6 @@ nativeStringResourceTable_mscorrc
#GetFullPathNameW
#GetLastError
#GetModuleFileNameW
#GetNumaHighestNodeNumber
#GetProcAddress
#GetStdHandle
#GetSystemInfo
Expand DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' [WIP] Fix to move to using GC pal within coreclr on Linux by mangod9 · Pull Request #78521 · dotnet/runtime · GitHub
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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand Up@@ -126,7 +125,6 @@ nativeStringResourceTable_mscorrc
#GetFullPathNameW
#GetLastError
#GetModuleFileNameW
#GetNumaHighestNodeNumber
#GetProcAddress
#GetStdHandle
#GetSystemInfo
Expand DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' [WIP] Fix to move to using GC pal within coreclr on Linux by mangod9 · Pull Request #78521 · dotnet/runtime · GitHub
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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand Up@@ -126,7 +125,6 @@ nativeStringResourceTable_mscorrc
#GetFullPathNameW
#GetLastError
#GetModuleFileNameW
#GetNumaHighestNodeNumber
#GetProcAddress
#GetStdHandle
#GetSystemInfo
Expand DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' [WIP] Fix to move to using GC pal within coreclr on Linux by mangod9 · Pull Request #78521 · dotnet/runtime · GitHub
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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand Up@@ -126,7 +125,6 @@ nativeStringResourceTable_mscorrc
#GetFullPathNameW
#GetLastError
#GetModuleFileNameW
#GetNumaHighestNodeNumber
#GetProcAddress
#GetStdHandle
#GetSystemInfo
Expand DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); [WIP] Fix to move to using GC pal within coreclr on Linux by mangod9 · Pull Request #78521 · dotnet/runtime · GitHub
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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand Up@@ -126,7 +125,6 @@ nativeStringResourceTable_mscorrc
#GetFullPathNameW
#GetLastError
#GetModuleFileNameW
#GetNumaHighestNodeNumber
#GetProcAddress
#GetStdHandle
#GetSystemInfo
Expand DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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