Skip to content
Open
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
10 changes: 5 additions & 5 deletions eng/native.wasm.targets
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@
</ItemGroup>
<ItemGroup Condition="'$(TargetsWasi)' == 'true' and '$(RuntimeFlavor)' == 'CoreCLR'">
<NativeCMakeArg Include="-cmakeargs &quot;-DGEN_PINVOKE=1&quot;" />
<!-- Initial WASI bring-up disables EventPipe / diagnostic-server PAL
via FEATURE_PERFTRACING=0 in src/coreclr/CMakeLists.txt; the
PERFTRACING_DISABLE_* flags are unused while PERFTRACING is off
but kept for symmetry with browser-CoreCLR and for when we
re-enable PERFTRACING in a follow-up. -->
<!-- WASI has no AF_UNIX sockets, so build the TCP flavor of the diagnostic
server PAL. Listen and connect ports stay disabled until a WASI
transport is validated; EventPipe works in-process only. -->
<NativeCMakeArg Include="-cmakeargs &quot;-DFEATURE_PERFTRACING_PAL_TCP=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;" />
<NativeCMakeArg Include="-cmakeargs &quot;-DFEATURE_PERFTRACING_DISABLE_CONNECT_PORTS=1&quot;" />
</ItemGroup>
<ItemGroup Condition="'$(FeatureMultithreading)' != 'true'">
<NativeCMakeArg Include="-cmakeargs &quot;-DFEATURE_PERFTRACING_DISABLE_THREADS=1&quot;" />
Expand Down
4 changes: 0 additions & 4 deletions src/coreclr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ if(CLR_CMAKE_TARGET_WASI)
add_compile_definitions(_WASI_EMULATED_PROCESS_CLOCKS)
add_compile_definitions(_WASI_EMULATED_MMAN)
add_compile_definitions(_WASI_EMULATED_GETPID)
# EventPipe / diag-server PAL require sockets we have not validated
# for the WASI bring-up; revisit once corerun.wasm runs.
set(FEATURE_EVENT_TRACE 0)
set(FEATURE_PERFTRACING 0)
include_directories(BEFORE SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/pal/src/include/pal/wasi)
# Cross-compile try_run() answers — wasm32 binaries cannot execute on
# the build host, so pre-seed the cache.
Expand Down
12 changes: 0 additions & 12 deletions src/coreclr/clr.featuredefines.props
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,6 @@
<ProfilingSupportedBuild>false</ProfilingSupportedBuild>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetsWasi)' == 'true'">
<!-- Match the WASI native build (src/coreclr/CMakeLists.txt sets
FEATURE_PERFTRACING=0 for CLR_CMAKE_TARGET_WASI). Keeping
FEATURE_PERFTRACING on in managed CoreLib while the native
side has it off causes EventPipeInternal QCalls (e.g.
EventPipeInternal_CreateProvider) to resolve to NULL at
runtime; any EventSource activation (e.g. ArrayPoolEventSource
via DefaultInterpolatedStringHandler) then traps on a NULL
function pointer. -->
<FeaturePerfTracing>false</FeaturePerfTracing>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetsUnix)' == 'true'">
<FeatureXplatEventSource Condition="'$(FeatureXplatEventSource)' == '' AND '$(TargetOS)' == 'linux'">true</FeatureXplatEventSource>
<FeatureComWrappers>true</FeatureComWrappers>
Expand Down
7 changes: 1 addition & 6 deletions src/coreclr/debug/debug-pal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@ if(CLR_CMAKE_HOST_WIN32)
endif(CLR_CMAKE_HOST_WIN32)

if(CLR_CMAKE_HOST_UNIX)
if (NOT CLR_CMAKE_TARGET_WASI)
# ds-ipc-pal-socket.c needs UNIX/TCP sockets; re-enable once
# WASI PERFTRACING is wired. Tracked by https://github.com/dotnet/runtime/issues/130383

set(DEBUG_PAL_REFEREENCE_DIAGNOSTICSERVER ON)
endif()
set(DEBUG_PAL_REFEREENCE_DIAGNOSTICSERVER ON)

add_definitions(-DPAL_IMPLEMENTATION)
add_definitions(-D_POSIX_C_SOURCE=200809L)
Expand Down
14 changes: 14 additions & 0 deletions src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,24 @@ ep_rt_init_finish (void)
STATIC_CONTRACT_NOTHROW;
}

#if defined(TARGET_WASI) && defined(PERFTRACING_DISABLE_THREADS)
// WASI has no host event loop, so jobs are kept on a native list that the managed
// WASI event loop drains (see eventpipeinternal.cpp).
bool ep_rt_coreclr_wasi_queue_job (size_t (*cb)(void *data), void *data);
void ep_rt_coreclr_wasi_run_jobs (void);
#endif

static
inline
void
ep_rt_shutdown (void)
{
STATIC_CONTRACT_NOTHROW;
#if defined(TARGET_WASI) && defined(PERFTRACING_DISABLE_THREADS)
// The event loop no longer runs, so run the queued jobs once to let the now-disabled streaming
// sessions release their references; freeing a session ends its trace file.
ep_rt_coreclr_wasi_run_jobs ();
#endif
}

static
Expand Down Expand Up @@ -1111,6 +1123,8 @@ ep_rt_queue_job (
if (!cb (params))
SystemJS_DiagnosticServerQueueJob (cb, params);
return true;
#elif defined(TARGET_WASI)
return ep_rt_coreclr_wasi_queue_job ((size_t (*)(void *))job_func, params);
#else
EP_UNREACHABLE ("Not implemented on this platform");
return false;
Expand Down
82 changes: 82 additions & 0 deletions src/coreclr/vm/eventpipeinternal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,4 +296,86 @@ extern "C" BOOL QCALLTYPE EventPipeInternal_WaitForSessionSignal(UINT64 sessionI
return result;
}

#if defined(TARGET_WASI) && defined(PERFTRACING_DISABLE_THREADS)
// WASI has no host event loop to schedule EventPipe jobs (session streaming, diagnostic server) on,
// so they are kept on this list and run by the managed WasiEventLoop (WasiEventPipeJobs.cs).
// A job returns non-zero when it is done; otherwise it stays queued and runs again on the next pump.
// Single-threaded by construction, so no locking.
struct WasiEventPipeJob
{
size_t (*Callback)(void *data);
void *Data;
WasiEventPipeJob *Next;
};

static WasiEventPipeJob *s_wasiJobsHead = nullptr;
static WasiEventPipeJob *s_wasiJobsTail = nullptr;

static void WasiAppendJob(WasiEventPipeJob *job)
{
job->Next = nullptr;
if (s_wasiJobsTail != nullptr)
s_wasiJobsTail->Next = job;
else
s_wasiJobsHead = job;
s_wasiJobsTail = job;
}

bool ep_rt_coreclr_wasi_queue_job(size_t (*cb)(void *data), void *data)
{
_ASSERTE(cb != nullptr);
WasiEventPipeJob *job = new (nothrow) WasiEventPipeJob();
if (job == nullptr)
return false;

job->Callback = cb;
job->Data = data;
WasiAppendJob(job);
return true;
}

extern "C" CLR_BOOL QCALLTYPE EventPipeInternal_WasiHasPendingJobs(QCallExceptionStatus* qcallError)
{
QCALL_CONTRACT;

CLR_BOOL pending = FALSE;

BEGIN_QCALL;

pending = s_wasiJobsHead != nullptr ? TRUE : FALSE;

END_QCALL;
return pending;
}

void ep_rt_coreclr_wasi_run_jobs()
{
// Detach the current list so jobs queued while running are picked up on the next pump.
WasiEventPipeJob *job = s_wasiJobsHead;
s_wasiJobsHead = nullptr;
s_wasiJobsTail = nullptr;

while (job != nullptr)
{
WasiEventPipeJob *next = job->Next;
if (job->Callback(job->Data) != 0)
delete job;
else
WasiAppendJob(job);
job = next;
}
}

extern "C" void QCALLTYPE EventPipeInternal_WasiRunJobs(QCallExceptionStatus* qcallError)
{
QCALL_CONTRACT;

BEGIN_QCALL;

ep_rt_coreclr_wasi_run_jobs();

END_QCALL;
}
#endif // TARGET_WASI && PERFTRACING_DISABLE_THREADS

#endif // FEATURE_PERFTRACING
6 changes: 6 additions & 0 deletions src/coreclr/vm/eventpipeinternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ extern "C" BOOL QCALLTYPE EventPipeInternal_WaitForSessionSignal(
INT32 timeoutMs,
QCallExceptionStatus* qcallError);

#if defined(TARGET_WASI) && defined(PERFTRACING_DISABLE_THREADS)
extern "C" CLR_BOOL QCALLTYPE EventPipeInternal_WasiHasPendingJobs(QCallExceptionStatus* qcallError);

extern "C" void QCALLTYPE EventPipeInternal_WasiRunJobs(QCallExceptionStatus* qcallError);
#endif // TARGET_WASI && PERFTRACING_DISABLE_THREADS

#endif // FEATURE_PERFTRACING

#endif // __EVENTPIPEINTERNAL_H__
4 changes: 4 additions & 0 deletions src/coreclr/vm/qcallentrypoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,10 @@ static const Entry s_QCall[] =
DllImportEntry(EventPipeInternal_GetNextEvent)
DllImportEntry(EventPipeInternal_SignalSession)
DllImportEntry(EventPipeInternal_WaitForSessionSignal)
#if defined(TARGET_WASI) && defined(PERFTRACING_DISABLE_THREADS)
DllImportEntry(EventPipeInternal_WasiHasPendingJobs)
DllImportEntry(EventPipeInternal_WasiRunJobs)
#endif // TARGET_WASI && PERFTRACING_DISABLE_THREADS
#endif // FEATURE_PERFTRACING
#if defined(TARGET_UNIX)
DllImportEntry(FreeEnvironmentStringsW)
Expand Down
70 changes: 70 additions & 0 deletions src/coreclr/vm/wasm/wasi/callhelpers-interp-to-managed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,12 @@ namespace
*((int32_t*)pRet) = (*fptr)(ARG_I32(0), ARG_I32(1), ARG_I64(2));
}

static void CallFunc_I32_I32_I64_I32_I32_I32_I32_I32_RetI32(PCODE pcode, int8_t* pArgs, int8_t* pRet)
{
int32_t (*fptr)(int32_t, int32_t, int64_t, int32_t, int32_t, int32_t, int32_t, int32_t) = (int32_t (*)(int32_t, int32_t, int64_t, int32_t, int32_t, int32_t, int32_t, int32_t))pcode;
*((int32_t*)pRet) = (*fptr)(ARG_I32(0), ARG_I32(1), ARG_I64(2), ARG_I32(3), ARG_I32(4), ARG_I32(5), ARG_I32(6), ARG_I32(7));
}

static void CallFunc_I32_I32_I64_I64_I32_RetI32(PCODE pcode, int8_t* pArgs, int8_t* pRet)
{
int32_t (*fptr)(int32_t, int32_t, int64_t, int64_t, int32_t) = (int32_t (*)(int32_t, int32_t, int64_t, int64_t, int32_t))pcode;
Expand Down Expand Up @@ -372,6 +378,18 @@ namespace
*((int32_t*)pRet) = (*fptr)(ARG_I64(0));
}

static void CallFunc_I64_I32_RetI32(PCODE pcode, int8_t* pArgs, int8_t* pRet)
{
int32_t (*fptr)(int64_t, int32_t) = (int32_t (*)(int64_t, int32_t))pcode;
*((int32_t*)pRet) = (*fptr)(ARG_I64(0), ARG_I32(1));
}

static void CallFunc_I64_I32_I32_RetI32(PCODE pcode, int8_t* pArgs, int8_t* pRet)
{
int32_t (*fptr)(int64_t, int32_t, int32_t) = (int32_t (*)(int64_t, int32_t, int32_t))pcode;
*((int32_t*)pRet) = (*fptr)(ARG_I64(0), ARG_I32(1), ARG_I32(2));
}

static void CallFunc_I64_I32_I64_I32_I32_RetI32(PCODE pcode, int8_t* pArgs, int8_t* pRet)
{
int32_t (*fptr)(int64_t, int32_t, int64_t, int32_t, int32_t) = (int32_t (*)(int64_t, int32_t, int64_t, int32_t, int32_t))pcode;
Expand All @@ -397,12 +415,24 @@ namespace
*((int64_t*)pRet) = (*fptr)(ARG_I32(0));
}

static void CallFunc_I32_I32_RetI64(PCODE pcode, int8_t* pArgs, int8_t* pRet)
{
int64_t (*fptr)(int32_t, int32_t) = (int64_t (*)(int32_t, int32_t))pcode;
*((int64_t*)pRet) = (*fptr)(ARG_I32(0), ARG_I32(1));
}

static void CallFunc_I32_I32_I32_RetI64(PCODE pcode, int8_t* pArgs, int8_t* pRet)
{
int64_t (*fptr)(int32_t, int32_t, int32_t) = (int64_t (*)(int32_t, int32_t, int32_t))pcode;
*((int64_t*)pRet) = (*fptr)(ARG_I32(0), ARG_I32(1), ARG_I32(2));
}

static void CallFunc_I32_I32_I32_I32_I32_I32_RetI64(PCODE pcode, int8_t* pArgs, int8_t* pRet)
{
int64_t (*fptr)(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t) = (int64_t (*)(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t))pcode;
*((int64_t*)pRet) = (*fptr)(ARG_I32(0), ARG_I32(1), ARG_I32(2), ARG_I32(3), ARG_I32(4), ARG_I32(5));
}

static void CallFunc_I32_I32_I32_I64_RetI64(PCODE pcode, int8_t* pArgs, int8_t* pRet)
{
int64_t (*fptr)(int32_t, int32_t, int32_t, int64_t) = (int64_t (*)(int32_t, int32_t, int32_t, int64_t))pcode;
Expand Down Expand Up @@ -523,6 +553,24 @@ namespace
(*fptr)(&framePointer, ARG_I32(0), pPortableEntryPoint);
}

static void CallFunc_F64_F64_F64_F64_F64_F64_F64_F64_F64_I32_I32_I32_RetVoid(PCODE pcode, int8_t* pArgs, int8_t* pRet)
{
void (*fptr)(double, double, double, double, double, double, double, double, double, int32_t, int32_t, int32_t) = (void (*)(double, double, double, double, double, double, double, double, double, int32_t, int32_t, int32_t))pcode;
(*fptr)(ARG_F64(0), ARG_F64(1), ARG_F64(2), ARG_F64(3), ARG_F64(4), ARG_F64(5), ARG_F64(6), ARG_F64(7), ARG_F64(8), ARG_I32(9), ARG_I32(10), ARG_I32(11));
}

static void CallFunc_F64_I32_I32_RetVoid(PCODE pcode, int8_t* pArgs, int8_t* pRet)
{
void (*fptr)(double, int32_t, int32_t) = (void (*)(double, int32_t, int32_t))pcode;
(*fptr)(ARG_F64(0), ARG_I32(1), ARG_I32(2));
}

static void CallFunc_F64_I32_I32_I32_I32_RetVoid(PCODE pcode, int8_t* pArgs, int8_t* pRet)
{
void (*fptr)(double, int32_t, int32_t, int32_t, int32_t) = (void (*)(double, int32_t, int32_t, int32_t, int32_t))pcode;
(*fptr)(ARG_F64(0), ARG_I32(1), ARG_I32(2), ARG_I32(3), ARG_I32(4));
}

NOINLINE static void CallFunc_F64_I32_I32_RetVoid_PE(PCODE pPortableEntryPoint, int8_t* pArgs, int8_t* pRet)
{
alignas(16) int framePointer = TERMINATE_R2R_STACK_WALK;
Expand Down Expand Up @@ -567,6 +615,12 @@ namespace
(*fptr)(ARG_I32(0), ARG_I32(1), ARG_IND(2), ARG_IND(3), ARG_I32(4), ARG_I32(5), ARG_I32(6));
}

static void CallFunc_I32_I32_F64_I32_RetVoid(PCODE pcode, int8_t* pArgs, int8_t* pRet)
{
void (*fptr)(int32_t, int32_t, double, int32_t) = (void (*)(int32_t, int32_t, double, int32_t))pcode;
(*fptr)(ARG_I32(0), ARG_I32(1), ARG_F64(2), ARG_I32(3));
}

static void CallFunc_I32_I32_I32_RetVoid(PCODE pcode, int8_t* pArgs, int8_t* pRet)
{
void (*fptr)(int32_t, int32_t, int32_t) = (void (*)(int32_t, int32_t, int32_t))pcode;
Expand Down Expand Up @@ -609,6 +663,12 @@ namespace
(*fptr)(ARG_I32(0), ARG_I32(1), ARG_I32(2), ARG_I32(3), ARG_I32(4), ARG_I32(5), ARG_I32(6));
}

static void CallFunc_I32_I32_I32_I32_I64_I32_RetVoid(PCODE pcode, int8_t* pArgs, int8_t* pRet)
{
void (*fptr)(int32_t, int32_t, int32_t, int32_t, int64_t, int32_t) = (void (*)(int32_t, int32_t, int32_t, int32_t, int64_t, int32_t))pcode;
(*fptr)(ARG_I32(0), ARG_I32(1), ARG_I32(2), ARG_I32(3), ARG_I64(4), ARG_I32(5));
}

NOINLINE static void CallFunc_I32_I32_I32_RetVoid_PE(PCODE pPortableEntryPoint, int8_t* pArgs, int8_t* pRet)
{
alignas(16) int framePointer = TERMINATE_R2R_STACK_WALK;
Expand Down Expand Up @@ -698,6 +758,7 @@ const StringToPortableSigThunk g_portableCallHelperThunks[] = {
{ "Miiiil", (void*)&CallFunc_I32_I32_I32_I64_RetI32 },
{ "Miiiip", (void*)&CallFunc_I32_I32_I32_RetI32_PE },
{ "Miiil", (void*)&CallFunc_I32_I32_I64_RetI32 },
{ "Miiiliiiii", (void*)&CallFunc_I32_I32_I64_I32_I32_I32_I32_I32_RetI32 },
{ "Miiilli", (void*)&CallFunc_I32_I32_I64_I64_I32_RetI32 },
{ "Miiip", (void*)&CallFunc_I32_I32_RetI32_PE },
{ "Miil", (void*)&CallFunc_I32_I64_RetI32 },
Expand All @@ -707,11 +768,15 @@ const StringToPortableSigThunk g_portableCallHelperThunks[] = {
{ "Miilli", (void*)&CallFunc_I32_I64_I64_I32_RetI32 },
{ "Miip", (void*)&CallFunc_I32_RetI32_PE },
{ "Mil", (void*)&CallFunc_I64_RetI32 },
{ "Mili", (void*)&CallFunc_I64_I32_RetI32 },
{ "Milii", (void*)&CallFunc_I64_I32_I32_RetI32 },
{ "Mililii", (void*)&CallFunc_I64_I32_I64_I32_I32_RetI32 },
{ "Mip", (void*)&CallFunc_Void_RetI32_PE },
{ "Ml", (void*)&CallFunc_Void_RetI64 },
{ "Mli", (void*)&CallFunc_I32_RetI64 },
{ "Mlii", (void*)&CallFunc_I32_I32_RetI64 },
{ "Mliii", (void*)&CallFunc_I32_I32_I32_RetI64 },
{ "Mliiiiii", (void*)&CallFunc_I32_I32_I32_I32_I32_I32_RetI64 },
{ "Mliiil", (void*)&CallFunc_I32_I32_I32_I64_RetI64 },
{ "Mlili", (void*)&CallFunc_I32_I64_I32_RetI64 },
{ "Mlillp", (void*)&CallFunc_I32_I64_I64_RetI64_PE },
Expand All @@ -731,20 +796,25 @@ const StringToPortableSigThunk g_portableCallHelperThunks[] = {
{ "MvS8iiiiiii", (void*)&CallFunc_S8_I32_I32_I32_I32_I32_I32_I32_RetVoid },
{ "MvS8iiiiiiiiiiii", (void*)&CallFunc_S8_I32_I32_I32_I32_I32_I32_I32_I32_I32_I32_I32_I32_RetVoid },
{ "MvTp", (void*)&CallFunc_This_RetVoid_PE },
{ "Mvdddddddddiii", (void*)&CallFunc_F64_F64_F64_F64_F64_F64_F64_F64_F64_I32_I32_I32_RetVoid },
{ "Mvdii", (void*)&CallFunc_F64_I32_I32_RetVoid },
{ "Mvdiiii", (void*)&CallFunc_F64_I32_I32_I32_I32_RetVoid },
{ "Mvdiip", (void*)&CallFunc_F64_I32_I32_RetVoid_PE },
{ "Mvfiip", (void*)&CallFunc_F32_I32_I32_RetVoid_PE },
{ "Mvi", (void*)&CallFunc_I32_RetVoid },
{ "MviS8ii", (void*)&CallFunc_I32_S8_I32_I32_RetVoid },
{ "Mvii", (void*)&CallFunc_I32_I32_RetVoid },
{ "MviiS8S8ii", (void*)&CallFunc_I32_I32_S8_S8_I32_I32_RetVoid },
{ "MviiS8S8iii", (void*)&CallFunc_I32_I32_S8_S8_I32_I32_I32_RetVoid },
{ "Mviidi", (void*)&CallFunc_I32_I32_F64_I32_RetVoid },
{ "Mviii", (void*)&CallFunc_I32_I32_I32_RetVoid },
{ "MviiiS8S8i", (void*)&CallFunc_I32_I32_I32_S8_S8_I32_RetVoid },
{ "MviiiS8S8ii", (void*)&CallFunc_I32_I32_I32_S8_S8_I32_I32_RetVoid },
{ "Mviiii", (void*)&CallFunc_I32_I32_I32_I32_RetVoid },
{ "Mviiiii", (void*)&CallFunc_I32_I32_I32_I32_I32_RetVoid },
{ "Mviiiiii", (void*)&CallFunc_I32_I32_I32_I32_I32_I32_RetVoid },
{ "Mviiiiiii", (void*)&CallFunc_I32_I32_I32_I32_I32_I32_I32_RetVoid },
{ "Mviiiili", (void*)&CallFunc_I32_I32_I32_I32_I64_I32_RetVoid },
{ "Mviiip", (void*)&CallFunc_I32_I32_I32_RetVoid_PE },
{ "Mviip", (void*)&CallFunc_I32_I32_RetVoid_PE },
{ "Mvili", (void*)&CallFunc_I32_I64_I32_RetVoid },
Expand Down
Loading
Loading