-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
PInvoke
We need to handle PInvokes before we have wasm codegen. In the proof of concept code I use simple
replacement for InvokeCompiledMethod. It is now just handling simple Qcalls with i32 parameters and void return types. This allowed us to get further in the runtime initialization and needs to be improved.
Current next step
It needs to map MetaSig to wasm signatures to get the right forwarding function and C function type. Alternatively it might be easier to map the known entrypoints to the forwarding functions and types.
For example, it should map System.RuntimeTypeHandle.GetRuntimeTypeFromHandleSlow signature to [CallWasmFuncVoidI32I32, void (*fn)(int, int)] which can then be used to call the native RuntimeTypeHandle_GetRuntimeTypeFromHandleSlow function.
Or alternatively map StackTrace_GetStackFramesInternal to [CallWasmFuncVoidI32I32, void (*fn)(int, int)].
Currently we are reaching these entrypoints (native functions)
InvokeCompiledMethod: System.RuntimeTypeHandle.GetRuntimeTypeFromHandleSlow --> RuntimeTypeHandle_GetRuntimeTypeFromHandleSlow [entrypoint]
InvokeCompiledMethod: System.Runtime.CompilerServices.InitHelpers.InitClassHelper --> InitClassHelper [entrypoint]
InvokeCompiledMethod: System.Diagnostics.StackTrace.<GetStackFramesInternal>g____PInvoke|0_0 --> StackTrace_GetStackFramesInternal [entrypoint]
Note: you can use wa-info to check the wasm signatures, like this:
> wa-info -d -f StackTrace_GetStackFramesInternal ../../artifacts/obj/coreclr/browser.wasm.Debug/hosts/corewasmrun/corewasmrun.wasm|head -1
which outputs
(func StackTrace_GetStackFramesInternal(param $0 i32, $1 i32, $2 i32))
Future
We can continue using hand written forwarding functions like
void CallWasmFuncVoidI32I32(void (*fn)(int, int), int8_t* pArgs)
{
(*fn)(((int*)pArgs)[0], ((int*)pArgs)[2]);
}
and we can later generate them, when we hit a call with unavailable forwarding function. We can generate them at buildtime as C source or at runtime with JS (JavaScript).
Once we have codegen, they can be replaced by real stubs.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status