Skip to content

Commit 3c94a47

Browse files
radekdoulikam11jkotas
authored
[wasm][coreclr] Get further in the runtime initialization (#116383)
* [wasm][coreclr] Get further in the runtime initialization Add corewasmhost binary to test runtime initialization Fix linking of the host binary with coreclr and interpreter Allow calling interpreter with arguments and handle return value Use fake precode stubs to pass the precode type and method desc Make alternate signal stack calls no-op on wasm Implement CallDescrWorkerInternal on wasm Fix PE image loading without RTR on wasm Do not use unsupported syscalls * Fix condition Co-authored-by: Adeel Mujahid <[email protected]> * Fix build The jit helpers are used later unconditionally * Update after merge * Feedback * Update after merge * Fix release build offsets * Build Debug runtime configuration on CI, so that interpreter is enabled * Fix build * Enable interpreter in all configuration on wasm Fix build * Build in Release again as we are missing debug packages * Move inline keyword Co-authored-by: Jan Kotas <[email protected]> * Feedback * Feedback * Fix release build * Feedback Do not special case missing mono_wasm_browser_entropy and just add it to helpers with an assert * Feedback * Feedback Use MethodDesc's GetInterpreterCode() instead of GetNativeCode() * Feedback Do not use FEATURE_JIT for callstub exclusion, until we support it on wasm, use TARGET_WASM instead. Also update build after merge * Feedback Use PORTABILITY_ASSERT * Feedback, add FEATURE_PEIMAGE_FLAT_LAYOUT * Revert mapping changes for PE loaded layout We use the flat layout now * Feedback, change call order of execute interp method * Feedback, change condition to avoid dynamic loads in corhost * Increase stub size to fit interpreter stub data This way we get further in the initialization log: stdout: Interpreter compile method System.AppContext:Setup(ptr,ptr,int) log: stdout: Interpreter compile method System.Diagnostics.Debug:Assert(bool,System.String) log: stdout: Interpreter compile method System.Collections.Generic.Dictionary`2[System.__Canon,System.__Canon]:.ctor(int,System.Collections.Generic.IEqualityComparer`1[System.__Canon]) log: stdout: Interpreter compile method System.Diagnostics.Debug:Assert(bool,System.String,System.String) log: stdout: Interpreter compile method System.Collections.Generic.Dictionary`2[System.__Canon,System.__Canon]:.ctor(int) * Update precode sizes, feedback and size check * Feedback, TODO, transition block * Feedback * Use coreclr_static library for wasm And do not build coreclr * Feedback Disable larger part of GCToOSInterface::Initialize than before * Feedback Make InitializeFlushProcessWriteBuffers no-op on wasm * Write barriers helper updated Co-authored-by: Jan Kotas <[email protected]> * Write barriers helper updated Co-authored-by: Jan Kotas <[email protected]> * Feedback Return false from ExecutableAllocator::IsDoubleMappingEnabled instead of making the double mapping init no-op on wasm * Make InitJITWriteBarrierHelpers no-op on wasm Co-authored-by: Jan Kotas <[email protected]> * Feedback Fix few asserts * Feedback Define PEIMAGE_FLAT_LAYOUT_ONLY in inc\switches.h * Feedback Replace __wasm__ where appropriate * Feedback Do not use __builtin_return_address on wasm * Feedback Add InvokeCalliStub to helpers * Feedback Update comments and remove unwanted fields * Feedback Add comment to the wasm specific call description data fields * Feedback Add portability assert in DispatchCallSimple to light up if we get called through this path * Fix build * Fix non-wasm build * Feedback Use FEATURE_JIT instead of not WASM check * Feedback Co-authored-by: Jan Kotas <[email protected]> * Feedback * Feedback Disable stack limit assert only in Debug configuration * Feedback Return flat layout from GetLoadedLayout when PEIMAGE_FLAT_LAYOUT_ONLY switch is enabled * Feedback Add more explanation in the comment and use the CodeSize in the assert * Add comment Co-authored-by: Jan Kotas <[email protected]> * Feedback Move _ReturnAddress macro ro pal.h * Fix build * Feedback Make FlushProcessWriteBuffers no-op on wasm * Feedback Fix path * Fix whitespace Co-authored-by: Jan Kotas <[email protected]> * Prefer TARGET_WASM Co-authored-by: Jan Kotas <[email protected]> * Update src/coreclr/pal/src/init/pal.cpp Co-authored-by: Jan Kotas <[email protected]> * Prefer TARGET_WASM Co-authored-by: Jan Kotas <[email protected]> * Prefer TARGET_WASM * Few more places to use more general TARGET_WASM * Prefer TARGET_WASM Co-authored-by: Jan Kotas <[email protected]> --------- Co-authored-by: Adeel Mujahid <[email protected]> Co-authored-by: Jan Kotas <[email protected]>
1 parent 5c4ebcc commit 3c94a47

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1076
-99
lines changed

src/coreclr/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ if (DEFINED CLR_CMAKE_ICU_DIR)
3939
include_directories(${CLR_CMAKE_ICU_DIR}/include)
4040
endif(DEFINED CLR_CMAKE_ICU_DIR)
4141

42+
if (CLR_CMAKE_TARGET_ARCH_WASM)
43+
add_compile_options(-fwasm-exceptions)
44+
endif()
45+
4246
#----------------------------------------------------
4347
# Cross target Component build specific configuration
4448
#----------------------------------------------------

src/coreclr/System.Private.CoreLib/src/System/Runtime/ExceptionServices/AsmOffsets.cs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ class AsmOffsets
5151
public const int OFFSETOF__REGDISPLAY__SP = 0xba8;
5252
public const int OFFSETOF__REGDISPLAY__ControlPC = 0xbb0;
5353
#elif TARGET_WASM
54-
public const int SIZEOF__REGDISPLAY = 0x3c;
55-
public const int OFFSETOF__REGDISPLAY__SP = 0x34;
56-
public const int OFFSETOF__REGDISPLAY__ControlPC = 0x38;
54+
public const int SIZEOF__REGDISPLAY = 0x38;
55+
public const int OFFSETOF__REGDISPLAY__SP = 0x30;
56+
public const int OFFSETOF__REGDISPLAY__ControlPC = 0x34;
5757
#endif
5858

5959
#if TARGET_64BIT
@@ -73,9 +73,14 @@ class AsmOffsets
7373
public const int OFFSETOF__StackFrameIterator__m_AdjustedControlPC = 0x3d0;
7474
#else // TARGET_64BIT
7575
public const int OFFSETOF__REGDISPLAY__m_pCurrentContext = 0x4;
76+
#if FEATURE_INTERPRETER
77+
public const int SIZEOF__StackFrameIterator = 0xdc;
78+
public const int OFFSETOF__StackFrameIterator__m_AdjustedControlPC = 0xd8;
79+
#else
7680
public const int SIZEOF__StackFrameIterator = 0xcc;
77-
public const int OFFSETOF__StackFrameIterator__m_isRuntimeWrappedExceptions = 0xba;
7881
public const int OFFSETOF__StackFrameIterator__m_AdjustedControlPC = 0xc8;
82+
#endif
83+
public const int OFFSETOF__StackFrameIterator__m_isRuntimeWrappedExceptions = 0xba;
7984
#endif // TARGET_64BIT
8085

8186
#else // DEBUG
@@ -117,9 +122,9 @@ class AsmOffsets
117122
public const int OFFSETOF__REGDISPLAY__SP = 0xba0;
118123
public const int OFFSETOF__REGDISPLAY__ControlPC = 0xba8;
119124
#elif TARGET_WASM
120-
public const int SIZEOF__REGDISPLAY = 0x3c;
121-
public const int OFFSETOF__REGDISPLAY__SP = 0x34;
122-
public const int OFFSETOF__REGDISPLAY__ControlPC = 0x38;
125+
public const int SIZEOF__REGDISPLAY = 0x34;
126+
public const int OFFSETOF__REGDISPLAY__SP = 0x2c;
127+
public const int OFFSETOF__REGDISPLAY__ControlPC = 0x30;
123128
#endif
124129

125130
#if TARGET_64BIT
@@ -139,9 +144,14 @@ class AsmOffsets
139144
public const int OFFSETOF__StackFrameIterator__m_AdjustedControlPC = 0x3c8;
140145
#else // TARGET_64BIT
141146
public const int OFFSETOF__REGDISPLAY__m_pCurrentContext = 0x4;
147+
#if FEATURE_INTERPRETER
148+
public const int SIZEOF__StackFrameIterator = 0xd4;
149+
public const int OFFSETOF__StackFrameIterator__m_AdjustedControlPC = 0xd0;
150+
#else
142151
public const int SIZEOF__StackFrameIterator = 0xc4;
143-
public const int OFFSETOF__StackFrameIterator__m_isRuntimeWrappedExceptions = 0xb2;
144152
public const int OFFSETOF__StackFrameIterator__m_AdjustedControlPC = 0xc0;
153+
#endif
154+
public const int OFFSETOF__StackFrameIterator__m_isRuntimeWrappedExceptions = 0xb2;
145155
#endif // TARGET_64BIT
146156

147157
#endif // DEBUG
@@ -167,7 +177,7 @@ class AsmOffsets
167177
#elif TARGET_LOONGARCH64
168178
public const int SIZEOF__PAL_LIMITED_CONTEXT = 0x520;
169179
#elif TARGET_WASM
170-
public const int SIZEOF__PAL_LIMITED_CONTEXT = 0x08;
180+
public const int SIZEOF__PAL_LIMITED_CONTEXT = 0x04;
171181
#endif
172182

173183
#if TARGET_AMD64

src/coreclr/clrfeatures.cmake

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@ endif(NOT DEFINED FEATURE_DBGIPC)
3232

3333
if(NOT DEFINED FEATURE_INTERPRETER)
3434
if(CLR_CMAKE_TARGET_ANDROID)
35-
set(FEATURE_INTERPRETER 0)
35+
set(FEATURE_INTERPRETER 0)
36+
elseif(CLR_CMAKE_TARGET_ARCH_WASM)
37+
set(FEATURE_INTERPRETER 1)
3638
else()
37-
if(CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_ARCH_ARM64)
38-
set(FEATURE_INTERPRETER $<IF:$<CONFIG:Debug,Checked>,1,0>)
39-
else(CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_ARCH_ARM64)
40-
set(FEATURE_INTERPRETER 0)
41-
endif(CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_ARCH_ARM64)
39+
if(CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_ARCH_ARM64)
40+
set(FEATURE_INTERPRETER $<IF:$<CONFIG:Debug,Checked>,1,0>)
41+
else(CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_ARCH_ARM64)
42+
set(FEATURE_INTERPRETER 0)
43+
endif(CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_ARCH_ARM64)
4244
endif()
4345
endif(NOT DEFINED FEATURE_INTERPRETER)
4446

@@ -54,7 +56,7 @@ if(NOT DEFINED FEATURE_SINGLE_FILE_DIAGNOSTICS)
5456
set(FEATURE_SINGLE_FILE_DIAGNOSTICS 1)
5557
endif(NOT DEFINED FEATURE_SINGLE_FILE_DIAGNOSTICS)
5658

57-
if (CLR_CMAKE_TARGET_WIN32 OR CLR_CMAKE_TARGET_UNIX)
59+
if ((CLR_CMAKE_TARGET_WIN32 OR CLR_CMAKE_TARGET_UNIX) AND NOT CLR_CMAKE_TARGET_ARCH_WASM)
5860
set(FEATURE_COMWRAPPERS 1)
5961
endif()
6062

src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -56,31 +56,36 @@ endif (CLR_CMAKE_HOST_WIN32)
5656

5757
add_definitions(-DFX_VER_INTERNALNAME_STR=CoreCLR.dll)
5858

59-
add_library_clr(coreclr
60-
SHARED
61-
${CLR_SOURCES}
62-
)
59+
if (NOT CLR_CMAKE_HOST_ARCH_WASM)
60+
add_library_clr(coreclr
61+
SHARED
62+
${CLR_SOURCES}
63+
)
6364

64-
add_custom_target(coreclr_exports DEPENDS ${EXPORTS_FILE})
65-
add_custom_target(coreclr_def DEPENDS ${DEF_FILE})
65+
add_custom_target(coreclr_exports DEPENDS ${EXPORTS_FILE})
66+
add_custom_target(coreclr_def DEPENDS ${DEF_FILE})
6667

67-
add_dependencies(coreclr coreclr_def)
68-
add_dependencies(coreclr coreclr_exports)
68+
add_dependencies(coreclr coreclr_def)
69+
add_dependencies(coreclr coreclr_exports)
6970

70-
set_property(TARGET coreclr APPEND_STRING PROPERTY LINK_FLAGS ${EXPORTS_LINKER_OPTION})
71-
set_property(TARGET coreclr APPEND_STRING PROPERTY LINK_DEPENDS ${EXPORTS_FILE})
71+
set_property(TARGET coreclr APPEND_STRING PROPERTY LINK_FLAGS ${EXPORTS_LINKER_OPTION})
72+
set_property(TARGET coreclr APPEND_STRING PROPERTY LINK_DEPENDS ${EXPORTS_FILE})
73+
set(LIB_CORDBEE cordbee_wks)
74+
set(LIB_INTEROP interop)
75+
set(LIB_CDAC_CONTRACT_DESCRIPTOR cdac_contract_descriptor)
76+
endif(NOT CLR_CMAKE_HOST_ARCH_WASM)
7277

73-
if (CLR_CMAKE_HOST_UNIX)
78+
if (CLR_CMAKE_HOST_UNIX AND NOT CLR_CMAKE_TARGET_ARCH_WASM)
7479
set(LIB_UNWINDER unwinder_wks)
75-
endif (CLR_CMAKE_HOST_UNIX)
80+
endif (CLR_CMAKE_HOST_UNIX AND NOT CLR_CMAKE_TARGET_ARCH_WASM)
7681

7782
# IMPORTANT! Please do not rearrange the order of the libraries. The linker on Linux is
7883
# order dependent and changing the order can result in undefined symbols in the shared
7984
# library.
8085
set(CORECLR_LIBRARIES
8186
utilcode
8287
${START_LIBRARY_GROUP} # Start group of libraries that have circular references
83-
cordbee_wks
88+
${LIB_CORDBEE}
8489
debug-pal
8590
${LIB_UNWINDER}
8691
v3binder
@@ -95,10 +100,10 @@ set(CORECLR_LIBRARIES
95100
utilcode
96101
v3binder
97102
System.Globalization.Native-Static
98-
interop
103+
${LIB_INTEROP}
99104
coreclrminipal
100105
gc_pal
101-
cdac_contract_descriptor
106+
${LIB_CDAC_CONTRACT_DESCRIPTOR}
102107
)
103108

104109
if(CLR_CMAKE_TARGET_ARCH_AMD64)
@@ -172,12 +177,25 @@ if(FEATURE_STATICALLY_LINKED)
172177
set(CLRJIT_STATIC clrjit_static)
173178
endif(FEATURE_STATICALLY_LINKED)
174179

180+
if(FEATURE_JIT)
181+
set(CORECLR_STATIC_CLRJIT_STATIC clrjit_static)
182+
endif(FEATURE_JIT)
183+
184+
if(NOT CLR_CMAKE_HOST_ARCH_WASM)
185+
set(CEE_WKS_STATIC cee_wks_mergeable)
186+
else()
187+
set(CEE_WKS_STATIC cee_wks)
188+
endif(NOT CLR_CMAKE_HOST_ARCH_WASM)
189+
175190
if (CLR_CMAKE_TARGET_OSX)
176191
find_library(FOUNDATION Foundation REQUIRED)
177192
endif()
178193

179-
target_link_libraries(coreclr PUBLIC ${CORECLR_LIBRARIES} ${CLRJIT_STATIC} cee_wks_core cee_wks ${FOUNDATION})
180-
target_link_libraries(coreclr_static PUBLIC ${CORECLR_LIBRARIES} cee_wks_core clrjit_static cee_wks_mergeable ${FOUNDATION})
194+
if(NOT CLR_CMAKE_HOST_ARCH_WASM)
195+
target_link_libraries(coreclr PUBLIC ${CORECLR_LIBRARIES} ${CLRJIT_STATIC} cee_wks_core cee_wks ${FOUNDATION})
196+
endif(NOT CLR_CMAKE_HOST_ARCH_WASM)
197+
198+
target_link_libraries(coreclr_static PUBLIC ${CORECLR_LIBRARIES} cee_wks_core ${CORECLR_STATIC_CLRJIT_STATIC} ${CEE_WKS_STATIC} ${FOUNDATION})
181199
target_compile_definitions(coreclr_static PUBLIC CORECLR_EMBEDDED)
182200

183201
if (CLR_CMAKE_HOST_ANDROID)
@@ -227,10 +245,13 @@ if(CLR_CMAKE_TARGET_WIN32)
227245
endif(CLR_CMAKE_TARGET_WIN32)
228246

229247
# add the install targets
230-
install_clr(TARGETS coreclr DESTINATIONS . sharedFramework COMPONENT runtime)
231-
if(CLR_CMAKE_HOST_MACCATALYST OR CLR_CMAKE_HOST_IOS OR CLR_CMAKE_HOST_TVOS OR CLR_CMAKE_HOST_ANDROID)
248+
if(NOT CLR_CMAKE_HOST_ARCH_WASM)
249+
install_clr(TARGETS coreclr DESTINATIONS . sharedFramework COMPONENT runtime)
250+
endif(NOT CLR_CMAKE_HOST_ARCH_WASM)
251+
252+
if(CLR_CMAKE_HOST_MACCATALYST OR CLR_CMAKE_HOST_IOS OR CLR_CMAKE_HOST_TVOS OR CLR_CMAKE_HOST_ANDROID OR CLR_CMAKE_HOST_ARCH_WASM)
232253
install_clr(TARGETS coreclr_static DESTINATIONS . sharedFramework COMPONENT runtime)
233-
endif(CLR_CMAKE_HOST_MACCATALYST OR CLR_CMAKE_HOST_IOS OR CLR_CMAKE_HOST_TVOS OR CLR_CMAKE_HOST_ANDROID)
254+
endif(CLR_CMAKE_HOST_MACCATALYST OR CLR_CMAKE_HOST_IOS OR CLR_CMAKE_HOST_TVOS OR CLR_CMAKE_HOST_ANDROID OR CLR_CMAKE_HOST_ARCH_WASM)
234255

235256
# Enable profile guided optimization
236257
add_pgo(coreclr)

src/coreclr/gc/unix/gcenv.unix.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ bool GCToOSInterface::Initialize()
222222
//
223223
// support for FlusProcessWriteBuffers
224224
//
225-
225+
#ifndef TARGET_WASM
226226
assert(s_flushUsingMemBarrier == 0);
227227

228228
if (CanFlushUsingMembarrier())
@@ -262,6 +262,7 @@ bool GCToOSInterface::Initialize()
262262
}
263263
}
264264
#endif // !TARGET_APPLE
265+
#endif // !TARGET_WASM
265266

266267
InitializeCGroup();
267268

@@ -412,6 +413,7 @@ bool GCToOSInterface::CanGetCurrentProcessorNumber()
412413
// Flush write buffers of processors that are executing threads of the current process
413414
void GCToOSInterface::FlushProcessWriteBuffers()
414415
{
416+
#ifndef TARGET_WASM
415417
#if defined(__linux__) || HAVE_SYS_MEMBARRIER_H
416418
if (s_flushUsingMemBarrier)
417419
{
@@ -490,6 +492,7 @@ void GCToOSInterface::FlushProcessWriteBuffers()
490492
CHECK_MACH("vm_deallocate()", machret);
491493
}
492494
#endif // TARGET_APPLE
495+
#endif // !TARGET_WASM
493496
}
494497

495498
// Break into a debugger. Uses a compiler intrinsic if one is available,
@@ -576,7 +579,7 @@ static void* VirtualReserveInner(size_t size, size_t alignment, uint32_t flags,
576579
}
577580

578581
pRetVal = pAlignedRetVal;
579-
#ifdef MADV_DONTDUMP
582+
#if defined(MADV_DONTDUMP) && !defined(TARGET_WASM)
580583
// Do not include reserved uncommitted memory in coredump.
581584
if (!committing)
582585
{
@@ -624,9 +627,13 @@ bool GCToOSInterface::VirtualRelease(void* address, size_t size)
624627
// true if it has succeeded, false if it has failed
625628
static bool VirtualCommitInner(void* address, size_t size, uint16_t node, bool newMemory)
626629
{
630+
#ifndef TARGET_WASM
627631
bool success = mprotect(address, size, PROT_WRITE | PROT_READ) == 0;
632+
#else
633+
bool success = true;
634+
#endif // !TARGET_WASM
628635

629-
#ifdef MADV_DODUMP
636+
#if defined(MADV_DONTDUMP) && !defined(TARGET_WASM)
630637
if (success && !newMemory)
631638
{
632639
// Include committed memory in coredump. New memory is included by default.

src/coreclr/hosts/CMakeLists.txt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
include_directories(inc)
22

3-
if(CLR_CMAKE_HOST_WIN32)
4-
add_subdirectory(coreshim)
5-
endif(CLR_CMAKE_HOST_WIN32)
3+
if (CLR_CMAKE_TARGET_ARCH_WASM)
4+
add_subdirectory(corewasmrun)
5+
else()
6+
if(CLR_CMAKE_HOST_WIN32)
7+
add_subdirectory(coreshim)
8+
endif(CLR_CMAKE_HOST_WIN32)
69

7-
add_subdirectory(corerun)
10+
add_subdirectory(corerun)
11+
endif()
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
project(corewasmrun)
2+
3+
set(CMAKE_INCLUDE_CURRENT_DIR ON)
4+
5+
if (DEFINED CLR_CMAKE_ICU_DIR)
6+
link_directories(${CLR_CMAKE_ICU_DIR}/lib)
7+
endif(DEFINED CLR_CMAKE_ICU_DIR)
8+
9+
add_executable_clr(corewasmrun
10+
corewasmrun.cpp
11+
)
12+
13+
set(_WASM_PRELOAD_DIR "${CMAKE_INSTALL_PREFIX}/IL")
14+
if (EXISTS "${_WASM_PRELOAD_DIR}")
15+
set(_WASM_PRELOAD_FILE --preload-file ${_WASM_PRELOAD_DIR}@/)
16+
endif (EXISTS "${_WASM_PRELOAD_DIR}")
17+
18+
target_compile_options(corewasmrun PRIVATE -fwasm-exceptions)
19+
target_link_options(corewasmrun PRIVATE -fwasm-exceptions -sEXIT_RUNTIME=1 -sINITIAL_MEMORY=134217728 -sFORCE_FILESYSTEM=1 ${_WASM_PRELOAD_FILE} -Wl,-error-limit=0)
20+
21+
target_link_libraries(corewasmrun PRIVATE coreclr_static)
22+
target_link_libraries(corewasmrun PRIVATE clrinterpreter)
23+
24+
target_link_libraries(corewasmrun PRIVATE icuuc)
25+
target_link_libraries(corewasmrun PRIVATE icui18n)
26+
target_link_libraries(corewasmrun PRIVATE icudata)
27+
28+
install_clr(TARGETS corewasmrun DESTINATIONS . COMPONENT hosts)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
//
4+
5+
#include <cstdio>
6+
#include <coreclrhost.h>
7+
8+
static void log_error_info(const char* line)
9+
{
10+
std::fprintf(stderr, "log error: %s\n", line);
11+
}
12+
13+
// The current CoreCLR instance details.
14+
static void* CurrentClrInstance;
15+
static unsigned int CurrentAppDomainId;
16+
17+
static int run()
18+
{
19+
const char* exe_path = "<coreclr-wasm>";
20+
const char* app_domain_name = "corewasmrun";
21+
const char* entry_assembly = "ManagedAssembly.dll";
22+
23+
coreclr_set_error_writer(log_error_info);
24+
25+
printf("call coreclr_initialize\n");
26+
int retval = coreclr_initialize(exe_path, app_domain_name, 0, nullptr, nullptr, &CurrentClrInstance, &CurrentAppDomainId);
27+
28+
if (retval < 0)
29+
{
30+
std::fprintf(stderr, "coreclr_initialize failed - Error: 0x%08x\n", retval);
31+
return -1;
32+
}
33+
else
34+
{
35+
printf("coreclr_initialize succeeded - retval: 0x%08x\n", retval);
36+
}
37+
38+
// coreclr_execute_assembly();
39+
// coreclr_shutdown();
40+
41+
return retval;
42+
}
43+
44+
int main()
45+
{
46+
int retval = run();
47+
48+
return retval;
49+
}

0 commit comments

Comments
 (0)