Skip to content

Commit 691c651

Browse files
committed
more
1 parent f09b7b5 commit 691c651

File tree

2 files changed

+153
-37
lines changed

2 files changed

+153
-37
lines changed

src/coreclr/vm/wasm/callhelpers-reverse.cpp

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//
44

55
#include <callhelpers.hpp>
6+
#include <cstdint>
67

78
// Define reverse thunks here
89

@@ -46,10 +47,124 @@ extern "C" void SystemJS_ExecuteTimerCallback()
4647
Call_System_Private_CoreLib_System_Threading_TimerQueue_TimerHandler();
4748
}
4849

50+
static MethodDesc* MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_ReleaseJSOwnedObjectByGCHandle_VoidPtr_RetVoid = nullptr;
51+
static void Call_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_ReleaseJSOwnedObjectByGCHandle(void* arg0)
52+
{
53+
if (!MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_ReleaseJSOwnedObjectByGCHandle_VoidPtr_RetVoid)
54+
{
55+
LookupMethodByName("System.Runtime.InteropServices.JavaScript.JavaScriptExports, System.Runtime.InteropServices.JavaScript", "ReleaseJSOwnedObjectByGCHandle", &MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_ReleaseJSOwnedObjectByGCHandle_VoidPtr_RetVoid);
56+
}
57+
58+
int64_t args[1] = { (int64_t)arg0 };
59+
60+
ExecuteInterpretedMethodFromUnmanaged(MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_ReleaseJSOwnedObjectByGCHandle_VoidPtr_RetVoid, (int8_t*)args, sizeof(args), nullptr);
61+
}
62+
63+
extern "C" void SystemInteropJS_ReleaseJSOwnedObjectByGCHandle(void* arg0)
64+
{
65+
Call_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_ReleaseJSOwnedObjectByGCHandle(arg0);
66+
}
67+
68+
static MethodDesc* MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_CallDelegate_VoidPtr_RetVoid = nullptr;
69+
static void Call_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_CallDelegate(void* arg0)
70+
{
71+
if (!MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_CallDelegate_VoidPtr_RetVoid)
72+
{
73+
LookupMethodByName("System.Runtime.InteropServices.JavaScript.JavaScriptExports, System.Runtime.InteropServices.JavaScript", "CallDelegate", &MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_CallDelegate_VoidPtr_RetVoid);
74+
}
75+
76+
int64_t args[1] = { (int64_t)arg0 };
77+
78+
ExecuteInterpretedMethodFromUnmanaged(MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_CallDelegate_VoidPtr_RetVoid, (int8_t*)args, sizeof(args), nullptr);
79+
}
80+
81+
extern "C" void SystemInteropJS_CallDelegate(void* arg0)
82+
{
83+
Call_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_CallDelegate(arg0);
84+
}
85+
86+
static MethodDesc* MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_CompleteTask_VoidPtr_RetVoid = nullptr;
87+
static void Call_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_CompleteTask(void* arg0)
88+
{
89+
if (!MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_CompleteTask_VoidPtr_RetVoid)
90+
{
91+
LookupMethodByName("System.Runtime.InteropServices.JavaScript.JavaScriptExports, System.Runtime.InteropServices.JavaScript", "CompleteTask", &MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_CompleteTask_VoidPtr_RetVoid);
92+
}
93+
94+
int64_t args[1] = { (int64_t)arg0 };
95+
96+
ExecuteInterpretedMethodFromUnmanaged(MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_CompleteTask_VoidPtr_RetVoid, (int8_t*)args, sizeof(args), nullptr);
97+
}
98+
99+
extern "C" void SystemInteropJS_CompleteTask(void* arg0)
100+
{
101+
Call_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_CompleteTask(arg0);
102+
}
103+
104+
static MethodDesc* MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_GetManagedStackTrace_VoidPtr_RetVoid = nullptr;
105+
static void Call_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_GetManagedStackTrace(void* arg0)
106+
{
107+
if (!MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_GetManagedStackTrace_VoidPtr_RetVoid)
108+
{
109+
LookupMethodByName("System.Runtime.InteropServices.JavaScript.JavaScriptExports, System.Runtime.InteropServices.JavaScript", "GetManagedStackTrace", &MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_GetManagedStackTrace_VoidPtr_RetVoid);
110+
}
111+
112+
int64_t args[1] = { (int64_t)arg0 };
113+
114+
ExecuteInterpretedMethodFromUnmanaged(MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_GetManagedStackTrace_VoidPtr_RetVoid, (int8_t*)args, sizeof(args), nullptr);
115+
}
116+
117+
extern "C" void SystemInteropJS_GetManagedStackTrace(void* arg0)
118+
{
119+
Call_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_GetManagedStackTrace(arg0);
120+
}
121+
122+
static MethodDesc* MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_BindAssemblyExports_VoidPtr_RetVoid = nullptr;
123+
static void Call_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_BindAssemblyExports(void* arg0)
124+
{
125+
if (!MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_BindAssemblyExports_VoidPtr_RetVoid)
126+
{
127+
LookupMethodByName("System.Runtime.InteropServices.JavaScript.JavaScriptExports, System.Runtime.InteropServices.JavaScript", "BindAssemblyExports", &MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_BindAssemblyExports_VoidPtr_RetVoid);
128+
}
129+
130+
int64_t args[1] = { (int64_t)arg0 };
131+
132+
ExecuteInterpretedMethodFromUnmanaged(MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_BindAssemblyExports_VoidPtr_RetVoid, (int8_t*)args, sizeof(args), nullptr);
133+
}
134+
135+
extern "C" void SystemInteropJS_BindAssemblyExports(void* arg0)
136+
{
137+
Call_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_BindAssemblyExports(arg0);
138+
}
139+
140+
static MethodDesc* MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_InvokeJSExport_VoidPtr_RetVoid = nullptr;
141+
static void Call_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_InvokeJSExport(void* arg0, void* arg1)
142+
{
143+
if (!MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_InvokeJSExport_VoidPtr_RetVoid)
144+
{
145+
LookupMethodByName("System.Runtime.InteropServices.JavaScript.JavaScriptExports, System.Runtime.InteropServices.JavaScript", "InvokeJSExport", &MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_InvokeJSExport_VoidPtr_RetVoid);
146+
}
147+
148+
int64_t args[2] = { (int64_t)arg0, (int64_t)arg1 };
149+
150+
ExecuteInterpretedMethodFromUnmanaged(MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_InvokeJSExport_VoidPtr_RetVoid, (int8_t*)args, sizeof(args), nullptr);
151+
}
152+
153+
extern "C" void SystemInteropJS_InvokeJSExport(void* arg0)
154+
{
155+
Call_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_InvokeJSExport(arg0);
156+
}
157+
49158
extern const ReverseThunkMapEntry g_ReverseThunks[] =
50159
{
51160
{ 100678287, { &MD_System_Private_CoreLib_System_Threading_ThreadPool_BackgroundJobHandler_Void_RetVoid, (void*)&Call_System_Private_CoreLib_System_Threading_ThreadPool_BackgroundJobHandler } },
52161
{ 100678363, { &MD_System_Private_CoreLib_System_Threading_TimerQueue_TimerHandler_Void_RetVoid, (void*)&Call_System_Private_CoreLib_System_Threading_TimerQueue_TimerHandler } },
162+
{ 230145789, { &MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_ReleaseJSOwnedObjectByGCHandle_VoidPtr_RetVoid, (void*)&Call_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_ReleaseJSOwnedObjectByGCHandle } },
163+
{ 230145790, { &MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_CallDelegate_VoidPtr_RetVoid, (void*)&Call_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_CallDelegate } },
164+
{ 230145791, { &MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_CompleteTask_VoidPtr_RetVoid, (void*)&Call_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_CompleteTask } },
165+
{ 230145792, { &MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_GetManagedStackTrace_VoidPtr_RetVoid, (void*)&Call_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_GetManagedStackTrace } },
166+
{ 230145793, { &MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_BindAssemblyExports_VoidPtr_RetVoid, (void*)&Call_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_BindAssemblyExports } },
167+
{ 230145794, { &MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_InvokeJSExport_VoidPtr_RetVoid, (void*)&Call_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_InvokeJSExport } },
53168
};
54169

55170
const size_t g_ReverseThunksCount = sizeof(g_ReverseThunks) / sizeof(g_ReverseThunks[0]);

src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Interop/JavaScriptExports.CoreCLR.cs

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ internal static unsafe partial class JavaScriptExports
1818
[UnmanagedCallersOnly(EntryPoint = "SystemInteropJS_ReleaseJSOwnedObjectByGCHandle")]
1919
// The JS layer invokes this method when the JS wrapper for a JS owned object has been collected by the JS garbage collector
2020
// the marshaled signature is: void ReleaseJSOwnedObjectByGCHandle(GCHandle gcHandle)
21-
public static void ReleaseJSOwnedObjectByGCHandle(JSMarshalerArgument* arguments_buffer)
21+
public static void ReleaseJSOwnedObjectByGCHandle(JSMarshalerArgument* argumentsBuffer)
2222
{
23-
ref JSMarshalerArgument arg_exc = ref arguments_buffer[0]; // initialized by caller in alloc_stack_frame()
24-
ref JSMarshalerArgument arg_1 = ref arguments_buffer[2]; // initialized and set by caller
23+
ref JSMarshalerArgument argException = ref argumentsBuffer[0]; // initialized by caller in alloc_stack_frame()
24+
ref JSMarshalerArgument arg1 = ref argumentsBuffer[2]; // initialized and set by caller
2525

2626
try
2727
{
2828
// when we arrive here, we are on the thread which owns the proxies or on IO thread
29-
var ctx = arg_exc.ToManagedContext;
30-
ctx.ReleaseJSOwnedObjectByGCHandle(arg_1.slot.GCHandle);
29+
var ctx = argException.ToManagedContext;
30+
ctx.ReleaseJSOwnedObjectByGCHandle(arg1.slot.GCHandle);
3131
}
3232
catch (Exception ex)
3333
{
@@ -37,21 +37,21 @@ public static void ReleaseJSOwnedObjectByGCHandle(JSMarshalerArgument* arguments
3737

3838
[UnmanagedCallersOnly(EntryPoint = "SystemInteropJS_CallDelegate")]
3939
// the marshaled signature is: TRes? CallDelegate<T1,T2,T3TRes>(GCHandle callback, T1? arg1, T2? arg2, T3? arg3)
40-
public static void CallDelegate(JSMarshalerArgument* arguments_buffer)
40+
public static void CallDelegate(JSMarshalerArgument* argumentsBuffer)
4141
{
42-
ref JSMarshalerArgument arg_exc = ref arguments_buffer[0]; // initialized by JS caller in alloc_stack_frame()
43-
// arg_res is initialized by JS caller
44-
ref JSMarshalerArgument arg_1 = ref arguments_buffer[2];// initialized and set by JS caller
42+
ref JSMarshalerArgument argException = ref argumentsBuffer[0]; // initialized by JS caller in alloc_stack_frame()
43+
// argResult is initialized by JS caller
44+
ref JSMarshalerArgument arg1 = ref argumentsBuffer[2];// initialized and set by JS caller
4545
// arg_2 set by JS caller when there are arguments
4646
// arg_3 set by JS caller when there are arguments
4747
// arg_4 set by JS caller when there are arguments
4848
try
4949
{
50-
GCHandle callback_gc_handle = (GCHandle)arg_1.slot.GCHandle;
50+
GCHandle callback_gc_handle = (GCHandle)arg1.slot.GCHandle;
5151
if (callback_gc_handle.Target is JSHostImplementation.ToManagedCallback callback)
5252
{
53-
// arg_2, arg_3, arg_4, arg_res are processed by the callback
54-
callback(arguments_buffer);
53+
// arg_2, arg_3, arg_4, argResult are processed by the callback
54+
callback(argumentsBuffer);
5555
}
5656
else
5757
{
@@ -60,33 +60,33 @@ public static void CallDelegate(JSMarshalerArgument* arguments_buffer)
6060
}
6161
catch (Exception ex)
6262
{
63-
arg_exc.ToJS(ex);
63+
argException.ToJS(ex);
6464
}
6565
}
6666

6767
[UnmanagedCallersOnly(EntryPoint = "SystemInteropJS_CompleteTask")]
6868
// the marshaled signature is: void CompleteTask<T>(GCHandle holder, Exception? exceptionResult, T? result)
69-
public static void CompleteTask(JSMarshalerArgument* arguments_buffer)
69+
public static void CompleteTask(JSMarshalerArgument* argumentsBuffer)
7070
{
71-
ref JSMarshalerArgument arg_exc = ref arguments_buffer[0]; // initialized by caller in alloc_stack_frame()
72-
ref JSMarshalerArgument arg_res = ref arguments_buffer[1]; // initialized by caller in alloc_stack_frame()
73-
ref JSMarshalerArgument arg_1 = ref arguments_buffer[2];// initialized and set by caller
71+
ref JSMarshalerArgument argException = ref argumentsBuffer[0]; // initialized by caller in alloc_stack_frame()
72+
ref JSMarshalerArgument argResult = ref argumentsBuffer[1]; // initialized by caller in alloc_stack_frame()
73+
ref JSMarshalerArgument arg1 = ref argumentsBuffer[2];// initialized and set by caller
7474
// arg_2 set by caller when this is SetException call
7575
// arg_3 set by caller when this is SetResult call
7676

7777
try
7878
{
7979
// when we arrive here, we are on the thread which owns the proxies or on IO thread
80-
var ctx = arg_exc.ToManagedContext;
81-
var holder = ctx.GetPromiseHolder(arg_1.slot.GCHandle);
80+
var ctx = argException.ToManagedContext;
81+
var holder = ctx.GetPromiseHolder(arg1.slot.GCHandle);
8282
JSHostImplementation.ToManagedCallback callback;
8383

8484
callback = holder.Callback!;
85-
ctx.ReleasePromiseHolder(arg_1.slot.GCHandle);
85+
ctx.ReleasePromiseHolder(arg1.slot.GCHandle);
8686

8787
// arg_2, arg_3 are processed by the callback
8888
// JSProxyContext.PopOperation() is called by the callback
89-
callback!(arguments_buffer);
89+
callback!(argumentsBuffer);
9090
}
9191
catch (Exception ex)
9292
{
@@ -96,20 +96,20 @@ public static void CompleteTask(JSMarshalerArgument* arguments_buffer)
9696

9797
[UnmanagedCallersOnly(EntryPoint = "SystemInteropJS_GetManagedStackTrace")]
9898
// the marshaled signature is: string GetManagedStackTrace(GCHandle exception)
99-
public static void GetManagedStackTrace(JSMarshalerArgument* arguments_buffer)
99+
public static void GetManagedStackTrace(JSMarshalerArgument* argumentsBuffer)
100100
{
101-
ref JSMarshalerArgument arg_exc = ref arguments_buffer[0]; // initialized by caller in alloc_stack_frame()
102-
ref JSMarshalerArgument arg_res = ref arguments_buffer[1]; // used as return value
103-
ref JSMarshalerArgument arg_1 = ref arguments_buffer[2];// initialized and set by caller
101+
ref JSMarshalerArgument argException = ref argumentsBuffer[0]; // initialized by caller in alloc_stack_frame()
102+
ref JSMarshalerArgument argResult = ref argumentsBuffer[1]; // used as return value
103+
ref JSMarshalerArgument arg1 = ref argumentsBuffer[2];// initialized and set by caller
104104
try
105105
{
106106
// when we arrive here, we are on the thread which owns the proxies
107-
arg_exc.AssertCurrentThreadContext();
107+
argException.AssertCurrentThreadContext();
108108

109-
GCHandle exception_gc_handle = (GCHandle)arg_1.slot.GCHandle;
109+
GCHandle exception_gc_handle = (GCHandle)arg1.slot.GCHandle;
110110
if (exception_gc_handle.Target is Exception exception)
111111
{
112-
arg_res.ToJS(exception.StackTrace);
112+
argResult.ToJS(exception.StackTrace);
113113
}
114114
else
115115
{
@@ -118,37 +118,38 @@ public static void GetManagedStackTrace(JSMarshalerArgument* arguments_buffer)
118118
}
119119
catch (Exception ex)
120120
{
121-
arg_exc.ToJS(ex);
121+
argException.ToJS(ex);
122122
}
123123
}
124124

125125
[UnmanagedCallersOnly(EntryPoint = "SystemInteropJS_BindAssemblyExports")]
126126
// the marshaled signature is: Task BindAssemblyExports(string assemblyName)
127-
public static void BindAssemblyExports(JSMarshalerArgument* arguments_buffer)
127+
public static void BindAssemblyExports(JSMarshalerArgument* argumentsBuffer)
128128
{
129-
ref JSMarshalerArgument arg_exc = ref arguments_buffer[0]; // initialized by caller in alloc_stack_frame()
130-
ref JSMarshalerArgument arg_res = ref arguments_buffer[1]; // used as return value
131-
ref JSMarshalerArgument arg_1 = ref arguments_buffer[2];// initialized and set by caller
129+
ref JSMarshalerArgument argException = ref argumentsBuffer[0]; // initialized by caller in alloc_stack_frame()
130+
ref JSMarshalerArgument argResult = ref argumentsBuffer[1]; // used as return value
131+
ref JSMarshalerArgument arg1 = ref argumentsBuffer[2];// initialized and set by caller
132132
try
133133
{
134134
string? assemblyName;
135135
// when we arrive here, we are on the thread which owns the proxies
136-
arg_exc.AssertCurrentThreadContext();
137-
arg_1.ToManaged(out assemblyName);
136+
argException.AssertCurrentThreadContext();
137+
arg1.ToManaged(out assemblyName);
138138

139139
var result = JSHostImplementation.BindAssemblyExports(assemblyName);
140140

141-
arg_res.ToJS(result);
141+
argResult.ToJS(result);
142142
}
143143
catch (Exception ex)
144144
{
145145
Environment.FailFast($"BindAssemblyExports: Unexpected synchronous failure (ManagedThreadId {Environment.CurrentManagedThreadId}): " + ex);
146146
}
147147
}
148148

149+
#pragma warning disable IDE0060
149150
[UnmanagedCallersOnly(EntryPoint = "SystemInteropJS_InvokeJSExport")]
150151
// the marshaled signature is: Task BindAssemblyExports(string assemblyName)
151-
public static void InvokeJSExport(JSMarshalerArgument* arguments_buffer)
152+
public static void InvokeJSExport(IntPtr methodHandle, JSMarshalerArgument* argumentsBuffer)
152153
{
153154
}
154155
}

0 commit comments

Comments
 (0)