Skip to content
Merged
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
15 changes: 15 additions & 0 deletions eng/native.wasm.targets
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,22 @@
<ItemGroup Condition="'$(TargetsBrowser)' == 'true' and '$(RuntimeFlavor)' == 'CoreCLR'">
<NativeCMakeArg Include="-cmakeargs &quot;-DBUILD_LIBS_NATIVE_BROWSER=1&quot;" />
<NativeCMakeArg Include="-cmakeargs &quot;-DGEN_PINVOKE=1&quot;" />
<NativeCMakeArg Include="-cmakeargs &quot;-DFEATURE_PERFTRACING_PAL_WS=1&quot;" />
<NativeCMakeArg Include="-cmakeargs &quot;-DFEATURE_PERFTRACING_DISABLE_PERFTRACING_LISTEN_PORTS=1&quot;" />
<NativeCMakeArg Include="-cmakeargs &quot;-DFEATURE_PERFTRACING_DISABLE_DEFAULT_LISTEN_PORT=1&quot;" />
</ItemGroup>
<ItemGroup Condition="'$(TargetsBrowser)' == 'true' and '$(RuntimeFlavor)' == 'CoreCLR' and '$(WasmEnableThreads)' != 'true'">
<NativeCMakeArg Include="-cmakeargs &quot;-DFEATURE_PERFTRACING_DISABLE_THREADS=1&quot;" />
<NativeCMakeArg Include="-cmakeargs &quot;-DFEATURE_SINGLE_THREADED=1&quot;" />
</ItemGroup>
<!-- TODO-WASM - https://github.com/dotnet/runtime/issues/68162
<ItemGroup Condition="'$(WasmEnableThreads)' == 'true'">
-sUSE_PTHREADS=1
-sPTHREAD_POOL_SIZE=0
-sPTHREAD_POOL_SIZE_STRICT=0
-Wno-pthreads-mem-growth
</ItemGroup>
-->

<Target Name="GenerateEmccExports" Condition="'$(TargetsBrowser)' == 'true'">
<ItemGroup>
Expand Down
12 changes: 9 additions & 3 deletions src/coreclr/pal/src/debug/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,13 +755,19 @@ PAL_ProbeMemory(
DWORD cbBuffer,
BOOL fWriteAccess)
{
#if defined(__EMSCRIPTEN__)
#if defined(TARGET_BROWSER)
if ((uintptr_t)((PBYTE)pBuffer + cbBuffer) <= emscripten_get_heap_size())
{
return TRUE;
}
return FALSE;
#else // __EMSCRIPTEN__
#elif defined(TARGET_WASI)
if ((uintptr_t)((PBYTE)pBuffer + cbBuffer) <= (__builtin_wasm_memory_size(0) * 65536))
{
return TRUE;
}
return FALSE;
#else // TARGET_BROWSER || TARGET_WASI
int fds[2];
int flags;

Expand Down Expand Up @@ -818,7 +824,7 @@ PAL_ProbeMemory(
close(fds[1]);

return result;
#endif // __EMSCRIPTEN__
#endif // TARGET_BROWSER || TARGET_WASI
}

} // extern "C"
5 changes: 5 additions & 0 deletions src/coreclr/pal/src/file/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2128,6 +2128,10 @@ CorUnix::InternalCreatePipe(
DWORD nSize
)
{
#ifdef TARGET_WASM
// Pipes are not supported on wasm
return ERROR_NOT_SUPPORTED;
#else // TARGET_WASM
PAL_ERROR palError = NO_ERROR;
IPalObject *pReadFileObject = NULL;
IPalObject *pReadRegisteredFile = NULL;
Expand Down Expand Up @@ -2342,6 +2346,7 @@ CorUnix::InternalCreatePipe(
}

return palError;
#endif // !TARGET_WASM
}

/*++
Expand Down
14 changes: 14 additions & 0 deletions src/coreclr/pal/src/synchmgr/synchmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,19 @@ namespace CorUnix
goto TNW_exit;
}

#ifdef FEATURE_SINGLE_THREADED
// In single-threaded WASM, if the object is not already signaled (iPred == FALSE),
// we cannot wait because there is no other thread to signal us - this would deadlock.
// This is a programming error in single-threaded WASM.
_ASSERT_MSG(FALSE != ptnwdNativeWaitData->iPred, "Cannot wait in single-threaded mode\n");
if (FALSE == ptnwdNativeWaitData->iPred)
{
iRet = pthread_mutex_unlock(&ptnwdNativeWaitData->mutex);
palErr = ERROR_NOT_SUPPORTED;
*ptwrWakeupReason = WaitFailed;
}
#else // FEATURE_SINGLE_THREADED

while (FALSE == ptnwdNativeWaitData->iPred)
{
if (INFINITE == dwTimeout)
Expand Down Expand Up @@ -475,6 +488,7 @@ namespace CorUnix
*ptwrWakeupReason = WaitTimeout;
}

#endif // FEATURE_SINGLE_THREADED
TNW_exit:
TRACE("ThreadNativeWait: returning %u [WakeupReason=%u]\n", palErr, *ptwrWakeupReason);
return palErr;
Expand Down
17 changes: 17 additions & 0 deletions src/coreclr/pal/src/synchmgr/wait.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,14 @@ DWORD CorUnix::InternalWaitForMultipleObjectsEx(

if (fNeedToBlock)
{
#ifdef FEATURE_SINGLE_THREADED
// In single-threaded WASM, blocking would deadlock because there is no other
// thread to signal the object. This is a programming error.
_ASSERT_MSG(false, "Cannot block on wait in single-threaded mode\n");
pThread->SetLastError(ERROR_NOT_SUPPORTED);
dwRet = WAIT_FAILED;
goto WFMOExIntCleanup;
#else // FEATURE_SINGLE_THREADED
ThreadWakeupReason twrWakeupReason;

//
Expand Down Expand Up @@ -452,6 +460,7 @@ DWORD CorUnix::InternalWaitForMultipleObjectsEx(
dwRet = WAIT_FAILED;
break;
}
#endif // FEATURE_SINGLE_THREADED
}

if (!fWAll && (WAIT_OBJECT_0 == dwRet))
Expand Down Expand Up @@ -493,6 +502,13 @@ DWORD CorUnix::InternalSleepEx (
CPalThread * pThread,
DWORD dwMilliseconds)
{
#ifdef FEATURE_SINGLE_THREADED
// In single-threaded WASM, Sleep returns immediately.
// There's no other thread that could make progress while we sleep.
(void)pThread;
(void)dwMilliseconds;
return 0;
#else // FEATURE_SINGLE_THREADED
PAL_ERROR palErr = NO_ERROR;
DWORD dwRet = WAIT_FAILED;
int iSignaledObjIndex;
Expand Down Expand Up @@ -535,5 +551,6 @@ DWORD CorUnix::InternalSleepEx (

TRACE("Done sleeping %u ms", dwMilliseconds);
return dwRet;
#endif // FEATURE_SINGLE_THREADED
}

8 changes: 4 additions & 4 deletions src/coreclr/pal/src/thread/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ CorUnix::InternalCreateProcess(
LPPROCESS_INFORMATION lpProcessInformation
)
{
#ifdef TARGET_TVOS
#if defined(TARGET_TVOS) || defined(TARGET_WASM)
return ERROR_NOT_SUPPORTED;
#else
PAL_ERROR palError = NO_ERROR;
Expand Down Expand Up @@ -1025,7 +1025,7 @@ CorUnix::InternalCreateProcess(
}

return palError;
#endif // !TARGET_TVOS
#endif // !TARGET_TVOS && !TARGET_WASM
}


Expand Down Expand Up @@ -2396,7 +2396,7 @@ PROCCreateCrashDump(
INT cbErrorMessageBuffer,
bool serialize)
{
#if defined(TARGET_IOS) || defined(TARGET_TVOS)
#if defined(TARGET_IOS) || defined(TARGET_TVOS) || defined(TARGET_WASM)
return FALSE;
#else
_ASSERTE(argv[0] != nullptr);
Expand Down Expand Up @@ -2573,7 +2573,7 @@ PROCCreateCrashDump(
}
}
return true;
#endif // !TARGET_IOS && !TARGET_TVOS
#endif // !TARGET_IOS && !TARGET_TVOS && !TARGET_WASM
}

/*++
Expand Down
7 changes: 7 additions & 0 deletions src/coreclr/pal/src/thread/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,10 @@ CorUnix::InternalCreateThread(
HANDLE *phThread
)
{
#ifdef FEATURE_SINGLE_THREADED
ERROR("Threads are not supported in single-threaded mode.\n");
return ERROR_NOT_SUPPORTED;
#else // FEATURE_SINGLE_THREADED
PAL_ERROR palError;
CPalThread *pNewThread = NULL;
CObjectAttributes oa;
Expand Down Expand Up @@ -629,6 +633,7 @@ CorUnix::InternalCreateThread(
}

return palError;
#endif // FEATURE_SINGLE_THREADED
}


Expand Down Expand Up @@ -1352,6 +1357,7 @@ SetThreadDescription(
return HRESULT_FROM_WIN32(palError);
}

#ifndef FEATURE_SINGLE_THREADED
void *
CPalThread::ThreadEntry(
void *pvParam
Expand Down Expand Up @@ -1497,6 +1503,7 @@ CPalThread::ThreadEntry(
above should release all resources */
return NULL;
}
#endif // !FEATURE_SINGLE_THREADED

/*++
Function:
Expand Down
7 changes: 7 additions & 0 deletions src/coreclr/pal/src/thread/threadsusp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ SET_DEFAULT_DEBUG_CHANNEL(THREAD);
in suspended state in order to resume it. */
CONST BYTE WAKEUPCODE=0x2A;

#ifndef FEATURE_SINGLE_THREADED
/*++
Function:
InternalSuspendNewThreadFromData
Expand Down Expand Up @@ -118,6 +119,7 @@ CThreadSuspensionInfo::InternalSuspendNewThreadFromData(

return palError;
}
#endif // !FEATURE_SINGLE_THREADED

/*++
Function:
Expand All @@ -132,6 +134,10 @@ ResumeThread(
IN HANDLE hThread
)
{
#ifdef FEATURE_SINGLE_THREADED
ERROR("Threads are not supported in single-threaded mode.\n");
return ERROR_NOT_SUPPORTED;
#else // FEATURE_SINGLE_THREADED
PAL_ERROR palError;
CPalThread *pthrResumer;
DWORD dwSuspendCount = (DWORD)-1;
Expand Down Expand Up @@ -159,6 +165,7 @@ ResumeThread(
LOGEXIT("ResumeThread returns DWORD %u\n", dwSuspendCount);
PERF_EXIT(ResumeThread);
return dwSuspendCount;
#endif // FEATURE_SINGLE_THREADED
}

/*++
Expand Down
4 changes: 2 additions & 2 deletions src/mono/browser/runtime/dotnet.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@ interface DotnetHostBuilder {
* Note: after the runtime exits, it would reject all further calls to the API.
* You can use runMain() if you want to keep the runtime alive.
*/
runMainAndExit (): Promise<number>;
runMainAndExit(): Promise<number>;
/**
* Runs the Main() method of the application and keeps the runtime alive.
* You can provide "command line" arguments for the Main() method using
* - dotnet.withApplicationArguments("A", "B", "C")
* - dotnet.withApplicationArgumentsFromQuery()
*/
runMain (): Promise<number>;
runMain(): Promise<number>;
}
type MonoConfig = {
/**
Expand Down
24 changes: 24 additions & 0 deletions src/native/eventpipe/ds-ipc-pal-websocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,30 @@ ep_rt_object_array_free (void *ptr)
if (ptr)
free (ptr);
}

static
inline
ep_char8_t *
ep_rt_utf8_string_dup (const ep_char8_t *str)
{
if (!str)
return NULL;

return strdup (str);
}

static
inline
void
ep_rt_utf8_string_free (ep_char8_t *str)
{
if (str)
free (str);
}

#undef EP_UNREACHABLE
#define EP_UNREACHABLE(msg) do { EP_ASSERT (!(msg)); abort (); } while (0)

#endif

static bool _ipc_pal_socket_init = false;
Expand Down
23 changes: 16 additions & 7 deletions src/native/libs/System.Native/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
project(System.Native C)

if (NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS AND NOT CLR_CMAKE_TARGET_WASI)
if (NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS AND NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI)
add_definitions(-DHAS_CONSOLE_SIGNALS)
endif ()

Expand All @@ -21,7 +21,7 @@ set(NATIVE_SOURCES
pal_sysctl.c
)

if (NOT CLR_CMAKE_TARGET_WASI)
if (NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI)
list (APPEND NATIVE_SOURCES
pal_dynamicload.c
pal_mount.c
Expand All @@ -30,12 +30,21 @@ if (NOT CLR_CMAKE_TARGET_WASI)
pal_threading.c
pal_uid.c
)
else()
elseif (CLR_CMAKE_TARGET_BROWSER)
list (APPEND NATIVE_SOURCES
pal_dynamicload_wasm.c
pal_mount.c
pal_process.c
pal_signal_wasm.c
pal_threading.c
pal_uid.c
)
else() # WASI
list (APPEND NATIVE_SOURCES
pal_dynamicload_wasi.c
pal_dynamicload_wasm.c
pal_mount_wasi.c
pal_process_wasi.c
pal_signal_wasi.c
pal_signal_wasm.c
pal_threading_wasi.c
pal_uid_wasi.c
)
Expand Down Expand Up @@ -84,8 +93,8 @@ else()
pal_log.c
pal_iossupportversion.c)

if (CLR_CMAKE_TARGET_WASI)
list (APPEND NATIVE_SOURCES pal_console_wasi.c)
if (CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI)
list (APPEND NATIVE_SOURCES pal_console_wasm.c)
else()
list (APPEND NATIVE_SOURCES pal_console.c)
endif()
Expand Down
Loading
Loading