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
Next Next commit
[wasm coreclr] Initial changes for corewasmrun host
  • Loading branch information
radekdoulik committed May 15, 2025
commit 9bf9b7cd2ecb6cf68dddaa620f18a0b6daffdb25
5 changes: 5 additions & 0 deletions src/coreclr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ if (DEFINED CLR_CMAKE_ICU_DIR)
include_directories(${CLR_CMAKE_ICU_DIR}/include)
endif(DEFINED CLR_CMAKE_ICU_DIR)

if (CLR_CMAKE_TARGET_ARCH_WASM)
add_compile_options(-fwasm-exceptions)
add_link_options(-fwasm-exceptions -sEXIT_RUNTIME=1 -sUSE_OFFSET_CONVERTER=1)
endif()

#----------------------------------------------------
# Cross target Component build specific configuration
#----------------------------------------------------
Expand Down
10 changes: 5 additions & 5 deletions src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ add_dependencies(coreclr coreclr_exports)
set_property(TARGET coreclr APPEND_STRING PROPERTY LINK_FLAGS ${EXPORTS_LINKER_OPTION})
set_property(TARGET coreclr APPEND_STRING PROPERTY LINK_DEPENDS ${EXPORTS_FILE})

if (CLR_CMAKE_HOST_UNIX)
if (CLR_CMAKE_HOST_UNIX AND NOT CLR_CMAKE_TARGET_ARCH_WASM)
set(LIB_UNWINDER unwinder_wks)
endif (CLR_CMAKE_HOST_UNIX)
endif (CLR_CMAKE_HOST_UNIX AND NOT CLR_CMAKE_TARGET_ARCH_WASM)

# IMPORTANT! Please do not rearrange the order of the libraries. The linker on Linux is
# order dependent and changing the order can result in undefined symbols in the shared
# library.
set(CORECLR_LIBRARIES
utilcode
${START_LIBRARY_GROUP} # Start group of libraries that have circular references
cordbee_wks
# cordbee_wks
debug-pal
${LIB_UNWINDER}
v3binder
Expand All @@ -95,10 +95,10 @@ set(CORECLR_LIBRARIES
utilcode
v3binder
System.Globalization.Native-Static
interop
# interop
coreclrminipal
gc_pal
cdac_contract_descriptor
# cdac_contract_descriptor
)

if(CLR_CMAKE_TARGET_ARCH_AMD64)
Expand Down
12 changes: 8 additions & 4 deletions src/coreclr/hosts/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
include_directories(inc)

if(CLR_CMAKE_HOST_WIN32)
add_subdirectory(coreshim)
endif(CLR_CMAKE_HOST_WIN32)
if (CLR_CMAKE_TARGET_ARCH_WASM)
add_subdirectory(corewasmrun)
else()
if(CLR_CMAKE_HOST_WIN32)
add_subdirectory(coreshim)
endif(CLR_CMAKE_HOST_WIN32)

add_subdirectory(corerun)
add_subdirectory(corerun)
endif()
25 changes: 25 additions & 0 deletions src/coreclr/hosts/corewasmrun/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
project(corewasmrun)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

if (DEFINED CLR_CMAKE_ICU_DIR)
link_directories(${CLR_CMAKE_ICU_DIR}/lib)
endif(DEFINED CLR_CMAKE_ICU_DIR)

add_executable_clr(corewasmrun
corewasmrun.cpp
)

target_link_options(corewasmrun PRIVATE "-Wl,-error-limit=0")

target_link_libraries(corewasmrun PRIVATE coreclr)
target_link_libraries(corewasmrun PRIVATE clrinterpreter)

target_link_libraries(corewasmrun PRIVATE icuuc)
target_link_libraries(corewasmrun PRIVATE icui18n)
target_link_libraries(corewasmrun PRIVATE icudata)

add_compile_options(-fwasm-exceptions)
add_link_options(-fwasm-exceptions -sEXIT_RUNTIME=1 -sUSE_OFFSET_CONVERTER=1)

install_clr(TARGETS corewasmrun DESTINATIONS . COMPONENT hosts)
17 changes: 17 additions & 0 deletions src/coreclr/hosts/corewasmrun/corewasmrun.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
extern "C" int coreclr_initialize(
const char* exePath,
const char* appDomainFriendlyName,
int propertyCount,
const char** propertyKeys,
const char** propertyValues,
void** hostHandle,
unsigned int* domainId);

int main()
{
coreclr_initialize("<wasm>", "corewasmrun", 0, nullptr, nullptr, nullptr, nullptr);
// coreclr_execute_assembly();
// coreclr_shutdown();

return 0;
}
56 changes: 56 additions & 0 deletions src/coreclr/hosts/corewasmrun/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>corewasmrun</title>
</head>
<body>
<h1>corewasmrun</h1>
<pre id="log"></pre>
<script>
Module = {
preRun: function () {
ENV.PAL_DBG_CHANNELS="+all.all";
// ENV.PAL_DBG_CHANNELS="+all.ERROR";
},
onExit: function (code) {
console.log("onExit, code: " + code);
},
};

const originalConsoleLog = console.log;
console.log = function(message) {
originalConsoleLog(message);
fetch('/log=paltests-log.txt', {
method: 'POST',
body: ('stdout: ' + message),
headers: {
'Content-Type': 'text/plain'
}
});
if (capturingTestCaseNames) {
capturedTestCaseNames.push(message.trim());
} else {
const elt = document.createElement("span");
elt.textContent = message + "\n";
document.querySelector("#log").appendChild(elt);
}
};
const originalConsoleError = console.error;
console.error = function(message) {
originalConsoleError(message);
fetch('/log=paltests-log.txt', {
method: 'POST',
body: ('stderr: ' + message),
headers: {
'Content-Type': 'text/plain'
}
});
const elt = document.createElement("span");
elt.textContent = message + "\n";
elt.style.color = "red";
document.querySelector("#log").appendChild(elt);
};
</script>
<script src="corewasmrun.js"></script>
</body>
8 changes: 6 additions & 2 deletions src/coreclr/inc/clrnt.h
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ RtlVirtualUnwind(
#define UNW_FLAG_EHANDLER 0x1 /* filter handler */
#define UNW_FLAG_UHANDLER 0x2 /* unwind handler */

PEXCEPTION_ROUTINE
PEXCEPTION_ROUTINE inline
RtlVirtualUnwind (
_In_ DWORD HandlerType,
_In_ DWORD ImageBase,
Expand All @@ -520,7 +520,11 @@ RtlVirtualUnwind (
_Out_ PVOID *HandlerData,
_Out_ PDWORD EstablisherFrame,
__inout_opt PT_KNONVOLATILE_CONTEXT_POINTERS ContextPointers
);
)
{
_ASSERTE("The function RtlVirtualUnwind is not implemented on wasm");
return nullptr;
}

FORCEINLINE
ULONG
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/pal/inc/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -2453,6 +2453,7 @@ typedef struct _KNONVOLATILE_CONTEXT_POINTERS {

typedef struct _CONTEXT {
ULONG ContextFlags;
UINT32 DummyReg;
} CONTEXT, *PCONTEXT, *LPCONTEXT;

typedef struct _KNONVOLATILE_CONTEXT_POINTERS {
Expand Down
6 changes: 5 additions & 1 deletion src/coreclr/pal/inc/rt/palrt.h
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,11 @@ typedef struct _DISPATCHER_CONTEXT {
typedef struct _DISPATCHER_CONTEXT {
// WASM does not build the VM or JIT at this point,
// so we only provide a dummy definition.
DWORD Reserved;
UINT32 ControlPc;
UINT32 ImageBase;
PRUNTIME_FUNCTION FunctionEntry;
UINT32 EstablisherFrame;
PCONTEXT ContextRecord;
} DISPATCHER_CONTEXT, *PDISPATCHER_CONTEXT;

#else
Expand Down
16 changes: 16 additions & 0 deletions src/coreclr/pal/src/loader/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,22 @@ PAL_CopyModuleData(PVOID moduleBase, PVOID destinationBufferStart, PVOID destina
}
return param.result;
}
#elif defined(__wasm__)
// TODO: get rid of whole module loading on wasm
static int CopyModuleDataCallback(struct dl_phdr_info *info, size_t size, void *data)
{
_ASSERTE("CopyModuleDataCallback not implemented for wasm");
return 0;
}

PALIMPORT
int
PALAPI
PAL_CopyModuleData(PVOID moduleBase, PVOID destinationBufferStart, PVOID destinationBufferEnd)
{
_ASSERTE("PAL_CopyModuleData not implemented for wasm");
return 0;
}
#else
static int CopyModuleDataCallback(struct dl_phdr_info *info, size_t size, void *data)
{
Expand Down
7 changes: 7 additions & 0 deletions src/coreclr/vm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,13 @@ elseif(CLR_CMAKE_TARGET_ARCH_RISCV64)
${ARCH_SOURCES_DIR}/singlestepper.cpp
gcinfodecoder.cpp
)
elseif(CLR_CMAKE_TARGET_ARCH_WASM)
set(VM_SOURCES_WKS_ARCH
${ARCH_SOURCES_DIR}/profiler.cpp
${ARCH_SOURCES_DIR}/helpers.cpp
exceptionhandling.cpp
gcinfodecoder.cpp
)
endif()

set(VM_SOURCES_DAC_ARCH
Expand Down
10 changes: 9 additions & 1 deletion src/coreclr/vm/gcinfodecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2148,7 +2148,6 @@ template <typename GcInfoEncoding> void TGcInfoDecoder<GcInfoEncoding>::ReportRe

pCallBack(hCallBack, pObjRef, gcFlags DAC_ARG(DacSlotLocation(regNum, 0, false)));
}

#else // Unknown platform

template <typename GcInfoEncoding> OBJECTREF* TGcInfoDecoder<GcInfoEncoding>::GetRegisterSlot(
Expand Down Expand Up @@ -2183,6 +2182,15 @@ template <typename GcInfoEncoding> void TGcInfoDecoder<GcInfoEncoding>::ReportRe
_ASSERTE( !"NYI" );
}

OBJECTREF* GcInfoDecoder::GetCapturedRegister(
int regNum,
PREGDISPLAY pRD
)
{
_ASSERTE( !"NYI" );
return nullptr;
}

#endif // Unknown platform

#ifdef FEATURE_INTERPRETER
Expand Down
9 changes: 9 additions & 0 deletions src/coreclr/vm/wasm/asmhelpers.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
void __stdcall GetCurrentIP(void)
{
_ASSERTE("GetCurrentIP is not implemented on wasm");
}

void __stdcall GetCurrentSP(void)
{
_ASSERTE("GetCurrentSP is not implemented on wasm");
}
9 changes: 9 additions & 0 deletions src/coreclr/vm/wasm/asmhelpers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
void __stdcall GetCurrentIP(void)
{
_ASSERTE("GetCurrentIP is not implemented on wasm");
}

void __stdcall GetCurrentSP(void)
{
_ASSERTE("GetCurrentSP is not implemented on wasm");
}
10 changes: 7 additions & 3 deletions src/coreclr/vm/wasm/cgencpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,13 @@ struct ArgumentRegisters {
class StubLinkerCPU : public StubLinker
{
public:
static void Init();
void EmitShuffleThunk(struct ShuffleEntry *pShuffleEntryArray);
VOID EmitComputedInstantiatingMethodStub(MethodDesc* pSharedMD, struct ShuffleEntry *pShuffleEntryArray, void* extraArg);
static void Init() { /* no-op on wasm */ }
inline void EmitShuffleThunk(struct ShuffleEntry *pShuffleEntryArray) {
_ASSERTE("The EmitShuffleThunk is not implemented on wasm");
}
inline VOID EmitComputedInstantiatingMethodStub(MethodDesc* pSharedMD, struct ShuffleEntry *pShuffleEntryArray, void* extraArg) {
_ASSERTE("The EmitComputedInstantiatingMethodStub is not implemented on wasm");
}
};

//**********************************************************************
Expand Down
5 changes: 4 additions & 1 deletion src/coreclr/vm/wasm/excepcpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ PCODE GetAdjustedCallAddress(PCODE returnAddress)
return returnAddress;
}

BOOL AdjustContextForVirtualStub(EXCEPTION_RECORD *pExceptionRecord, T_CONTEXT *pContext);
inline BOOL AdjustContextForVirtualStub(EXCEPTION_RECORD *pExceptionRecord, T_CONTEXT *pContext) {
_ASSERTE("AdjustContextForVirtualStub is not implemented on wasm");
return FALSE;
}

#endif // __excepcpu_h__
10 changes: 8 additions & 2 deletions src/coreclr/vm/wasm/gmscpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@
static void unwindLazyState(LazyMachState* baseState,
MachState* lazyState,
DWORD threadId,
int funCallDepth = 1);
int funCallDepth = 1)
{
_ASSERTE("LazyMachState::unwindLazyState is not implemented");
}

friend class HelperMethodFrame;
friend class CheckAsmOffsets;
Expand All @@ -60,7 +63,10 @@
// as light weight as possible, as we may never need the state that
// we capture. Thus to complete the process you need to call
// 'getMachState()', which finishes the process
EXTERN_C void LazyMachStateCaptureState(struct LazyMachState *pState);
EXTERN_C inline void LazyMachStateCaptureState(struct LazyMachState *pState)
{
_ASSERTE("LazyMachStateCaptureState is not implemented");
}

// CAPTURE_STATE captures just enough register state so that the state of the
// processor can be deterined just after the routine that has CAPTURE_STATE in
Expand Down
12 changes: 12 additions & 0 deletions src/coreclr/vm/wasm/helpers.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//extern "C" void CallCountingStubCode();

__cdecl void CallCountingStubCode()
{
_ASSERTE("CallCountingStubCode is not implemented on wasm");
}

UINT_PTR STDCALL GetCurrentIP(void)
{
_ASSERTE("GetCurrentIP is not implemented on wasm");
return 0;
}
Loading