Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9bf9b7c
[wasm coreclr] Initial changes for corewasmrun host
radekdoulik Mar 26, 2025
14ed390
Make alternate signal stack calls no-op on wasm
radekdoulik Mar 26, 2025
7c3bd24
[wasm coreclr] Fix field alignment
radekdoulik May 7, 2025
d193fc5
Update conditions to use TARGET_WASM
radekdoulik May 7, 2025
4a7481d
Save WIP changes before rebase
radekdoulik May 15, 2025
4914ac3
Update after rebase
radekdoulik May 16, 2025
64b74e2
Merge remote-tracking branch 'remotes/origin/main'
radekdoulik Jun 3, 2025
477350b
[wasm][coreclr] Implement CallDescrWorkerInternal
radekdoulik May 29, 2025
45843ee
Remaining changes
radekdoulik Jun 3, 2025
feef9d1
Update after merge
radekdoulik Jun 3, 2025
11dc45b
Remove parts which are not needed anymore
radekdoulik Jun 3, 2025
27f3bcb
Make some of the CORECLR_LIBRARIES conditional
radekdoulik Jun 3, 2025
fb89f83
Remove unwanted changes from conflicts resolve
radekdoulik Jun 3, 2025
1aa0e14
Enable interpreter verbose mode on wasm only
radekdoulik Jun 3, 2025
1a50037
Make the PE image loading changes wasm specific
radekdoulik Jun 3, 2025
d776675
Remove debug prints
radekdoulik Jun 3, 2025
5c6dc22
Fix whitespace
radekdoulik Jun 3, 2025
12ed21e
Do not use unsupported syscalls
radekdoulik Jun 5, 2025
19e6949
Link statically on wasm
radekdoulik Jun 5, 2025
a9eff81
Remove unwanted changes
radekdoulik Jun 5, 2025
d083b0a
Add MONO_RUNTIME to detect when we build mono runtime
radekdoulik Jun 5, 2025
9c041fa
Remove debug prints
radekdoulik Jun 5, 2025
e825c3b
Remove runtime init test
radekdoulik Jun 5, 2025
e1f4573
Rename log files
radekdoulik Jun 5, 2025
3cdb237
Make preload conditional
radekdoulik Jun 6, 2025
58b6a76
Fix comment
radekdoulik Jun 6, 2025
9cd5621
Remove debug code
radekdoulik Jun 6, 2025
ae9b5ea
Remove old files
radekdoulik Jun 6, 2025
c711276
Remove old file
radekdoulik Jun 6, 2025
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
Prev Previous commit
Next Next commit
Do not use unsupported syscalls
  • Loading branch information
radekdoulik committed Jun 5, 2025
commit 12ed21ef85fe98ff00e9896d60f2b5261e158618
12 changes: 10 additions & 2 deletions src/coreclr/gc/unix/gcenv.unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ bool GCToOSInterface::Initialize()
// Verify that the s_helperPage is really aligned to the g_SystemInfo.dwPageSize
assert((((size_t)g_helperPage) & (OS_PAGE_SIZE - 1)) == 0);

#ifndef TARGET_BROWSER
// Locking the page ensures that it stays in memory during the two mprotect
// calls in the FlushProcessWriteBuffers below. If the page was unmapped between
// those calls, they would not have the expected effect of generating IPI.
Expand All @@ -253,6 +254,9 @@ bool GCToOSInterface::Initialize()
{
return false;
}
#else
int status;
#endif // !TARGET_BROWSER

status = pthread_mutex_init(&g_flushProcessWriteBuffersMutex, NULL);
if (status != 0)
Expand Down Expand Up @@ -576,7 +580,7 @@ static void* VirtualReserveInner(size_t size, size_t alignment, uint32_t flags,
}

pRetVal = pAlignedRetVal;
#ifdef MADV_DONTDUMP
#if defined(MADV_DONTDUMP) && !defined(TARGET_BROWSER)
// Do not include reserved uncommitted memory in coredump.
if (!committing)
{
Expand Down Expand Up @@ -624,9 +628,13 @@ bool GCToOSInterface::VirtualRelease(void* address, size_t size)
// true if it has succeeded, false if it has failed
static bool VirtualCommitInner(void* address, size_t size, uint16_t node, bool newMemory)
{
#ifndef TARGET_BROWSER
bool success = mprotect(address, size, PROT_WRITE | PROT_READ) == 0;
#else
bool success = true;
#endif // !TARGET_BROWSER

#ifdef MADV_DODUMP
#if defined(MADV_DONTDUMP) && !defined(TARGET_BROWSER)
if (success && !newMemory)
{
// Include committed memory in coredump. New memory is included by default.
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/pal/src/exception/signal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,15 @@ BOOL SEHInitializeSignals(CorUnix::CPalThread *pthrCurrent, DWORD flags)
return FALSE;
}

#ifndef TARGET_BROWSER
// create a guard page for the alternate stack
int st = mprotect((void*)g_stackOverflowHandlerStack, GetVirtualPageSize(), PROT_NONE);
if (st != 0)
{
munmap((void*)g_stackOverflowHandlerStack, stackOverflowStackSize);
return FALSE;
}
#endif // TARGET_BROWSER

g_stackOverflowHandlerStack = (void*)((size_t)g_stackOverflowHandlerStack + stackOverflowStackSize);
#endif // HAVE_MACH_EXCEPTIONS
Expand Down
16 changes: 12 additions & 4 deletions src/coreclr/pal/src/map/virtual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ static LPVOID ReserveVirtualMemory(
}
#endif // MMAP_ANON_IGNORES_PROTECTION

#ifdef MADV_DONTDUMP
#if defined(MADV_DONTDUMP) && !defined(TARGET_BROWSER)
// Do not include reserved uncommitted memory in coredump.
if (!(fAllocationType & MEM_COMMIT))
{
Expand Down Expand Up @@ -730,14 +730,16 @@ VIRTUALCommitMemory(

nProtect = W32toUnixAccessControl(flProtect);

#ifndef TARGET_BROWSER
// Commit the pages
if (mprotect((void *) StartBoundary, MemSize, nProtect) != 0)
{
ERROR("mprotect() failed! Error(%d)=%s\n", errno, strerror(errno));
goto error;
}
#endif

#ifdef MADV_DODUMP
#if defined(MADV_DONTDUMP) && !defined(TARGET_BROWSER)
// Include committed memory in coredump. Any newly allocated memory included by default.
if (!IsNewMemory)
{
Expand All @@ -748,7 +750,9 @@ VIRTUALCommitMemory(
pRetVal = (void *) StartBoundary;
goto done;

#ifndef TARGET_BROWSER
error:
#endif
if ( flAllocationType & MEM_RESERVE || IsLocallyReserved )
{
munmap( pRetVal, MemSize );
Expand Down Expand Up @@ -1073,7 +1077,7 @@ VirtualFree(
}
#endif // MMAP_ANON_IGNORES_PROTECTION

#ifdef MADV_DONTDUMP
#if defined(MADV_DONTDUMP) && !defined(TARGET_BROWSER)
// Do not include freed memory in coredump.
madvise((LPVOID) StartBoundary, MemSize, MADV_DONTDUMP);
#endif
Expand Down Expand Up @@ -1207,9 +1211,11 @@ VirtualProtect(
}

pEntry = VIRTUALFindRegionInformation( StartBoundary );
#ifndef TARGET_BROWSER
if ( 0 == mprotect( (LPVOID)StartBoundary, MemSize,
W32toUnixAccessControl( flNewProtect ) ) )
{
#endif // !TARGET_BROWSER
/* Reset the access protection. */
TRACE( "Number of pages to change %d, starting page %d \n",
NumberOfPagesToChange, OffSet );
Expand All @@ -1220,13 +1226,14 @@ VirtualProtect(
*/
*lpflOldProtect = PAGE_EXECUTE_READWRITE;

#ifdef MADV_DONTDUMP
#if defined(MADV_DONTDUMP) && !defined(TARGET_BROWSER)
// Include or exclude memory from coredump based on the protection.
int advise = flNewProtect == PAGE_NOACCESS ? MADV_DONTDUMP : MADV_DODUMP;
madvise((LPVOID)StartBoundary, MemSize, advise);
#endif

bRetVal = TRUE;
#ifndef TARGET_BROWSER
}
else
{
Expand All @@ -1240,6 +1247,7 @@ VirtualProtect(
SetLastError( ERROR_INVALID_ACCESS );
}
}
#endif // !TARGET_BROWSER
ExitVirtualProtect:
minipal_mutex_leave(&virtual_critsec);

Expand Down
8 changes: 8 additions & 0 deletions src/coreclr/pal/src/thread/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2610,6 +2610,7 @@ InitializeFlushProcessWriteBuffers()
// Verify that the s_helperPage is really aligned to the GetVirtualPageSize()
_ASSERTE((((SIZE_T)s_helperPage) & (GetVirtualPageSize() - 1)) == 0);

#ifndef TARGET_BROWSER
// Locking the page ensures that it stays in memory during the two mprotect
// calls in the FlushProcessWriteBuffers below. If the page was unmapped between
// those calls, they would not have the expected effect of generating IPI.
Expand All @@ -2619,6 +2620,9 @@ InitializeFlushProcessWriteBuffers()
{
return FALSE;
}
#else
int status;
#endif // !TARGET_BROWSER

status = pthread_mutex_init(&flushProcessWriteBuffersMutex, NULL);
if (status != 0)
Expand Down Expand Up @@ -2664,18 +2668,22 @@ FlushProcessWriteBuffers()
int status = pthread_mutex_lock(&flushProcessWriteBuffersMutex);
FATAL_ASSERT(status == 0, "Failed to lock the flushProcessWriteBuffersMutex lock");

#ifndef TARGET_BROWSER
// Changing a helper memory page protection from read / write to no access
// causes the OS to issue IPI to flush TLBs on all processors. This also
// results in flushing the processor buffers.
status = mprotect(s_helperPage, GetVirtualPageSize(), PROT_READ | PROT_WRITE);
FATAL_ASSERT(status == 0, "Failed to change helper page protection to read / write");
#endif // !TARGET_BROWSER

// Ensure that the page is dirty before we change the protection so that
// we prevent the OS from skipping the global TLB flush.
InterlockedIncrement(s_helperPage);

#ifndef TARGET_BROWSER
status = mprotect(s_helperPage, GetVirtualPageSize(), PROT_NONE);
FATAL_ASSERT(status == 0, "Failed to change helper page protection to no access");
#endif // !TARGET_BROWSER

status = pthread_mutex_unlock(&flushProcessWriteBuffersMutex);
FATAL_ASSERT(status == 0, "Failed to unlock the flushProcessWriteBuffersMutex lock");
Expand Down