Skip to content

Commit bd1d206

Browse files
radekdoulikjkotas
andauthored
Fix arguments passing in MethodDescCallSite::CallTargetWorker on wasm (#119969)
* Fix arguments passing in MethodDescCallSite::CallTargetWorker on wasm * Disable fat tokes temporarily and update VirtualCallStubManager::Resolver To work with protable entrypoints * Handle instance signatures * Feedback * Detect intrinsic methods in classes decorated with Intrinsic attribute * Feedback * Feedback * Add RhpNewVariableSizeObject allocator on wasm * Apply suggestions from code review Co-authored-by: Jan Kotas <[email protected]> * Feedback * Update src/coreclr/runtime/portable/AllocFast.cpp Co-authored-by: Jan Kotas <[email protected]> * Feedback --------- Co-authored-by: Jan Kotas <[email protected]>
1 parent 3a353f8 commit bd1d206

File tree

7 files changed

+24
-13
lines changed

7 files changed

+24
-13
lines changed

src/coreclr/runtime/portable/AllocFast.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@
55
#include <fcall.h>
66

77
extern void RhExceptionHandling_FailedAllocation(MethodTable *pMT, bool isOverflow);
8+
EXTERN_C Object* RhpGcAlloc(MethodTable* pMT, uint32_t uFlags, uintptr_t numElements, void * pTransitionFrame);
89

9-
EXTERN_C FCDECL2(Object*, RhpNewVariableSizeObject, MethodTable* pMT, INT_PTR size)
10+
EXTERN_C FCDECL2(Object*, RhpNewVariableSizeObject, MethodTable* pMT, INT_PTR numElements)
1011
{
11-
PORTABILITY_ASSERT("RhpNewVariableSizeObject is not yet implemented");
12-
return nullptr;
12+
Object* obj = RhpGcAlloc(pMT, 0, numElements, nullptr);
13+
if (obj == NULL)
14+
{
15+
RhExceptionHandling_FailedAllocation(pMT, false /* isOverflow */);
16+
}
17+
18+
return obj;
1319
}
1420

1521
static Object* _RhpNewArrayFastCore(MethodTable* pMT, INT_PTR size)
@@ -96,8 +102,7 @@ EXTERN_C FCDECL2(Object*, RhNewString, MethodTable* pMT, INT_PTR stringLength)
96102
if (stringLength > MAX_STRING_LENGTH)
97103
{
98104
RhExceptionHandling_FailedAllocation(pMT, false);
99-
return NULL;
100105
}
101106

102107
return _RhpNewArrayFastCore(pMT, stringLength);
103-
}
108+
}

src/coreclr/tools/Common/Compiler/HardwareIntrinsicHelpers.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public static bool IsHardwareIntrinsic(MethodDesc method)
2929
return method.Context.Target.Architecture switch
3030
{
3131
TargetArchitecture.ARM64 => ns == "System.Runtime.Intrinsics.Arm",
32+
TargetArchitecture.Wasm32 => ns == "System.Runtime.Intrinsics.Wasm",
3233
TargetArchitecture.X64 or TargetArchitecture.X86 => ns == "System.Runtime.Intrinsics.X86",
3334
_ => false,
3435
};

src/coreclr/vm/callhelpers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ void MethodDescCallSite::CallTargetWorker(const ARG_SLOT *pArguments, ARG_SLOT *
543543
callDescrData.fpReturnSize = fpReturnSize;
544544
callDescrData.pTarget = m_pCallTarget;
545545
#ifdef TARGET_WASM
546-
callDescrData.nArgsSize = m_argIt.GetArgSize();
546+
callDescrData.nArgsSize = nStackBytes;
547547
#endif // TARGET_WASM
548548

549549
CallDescrWorkerWithHandler(&callDescrData);

src/coreclr/vm/contractimpl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,8 @@ struct DispatchToken
317317
{
318318
LIMITED_METHOD_CONTRACT;
319319
return typeID > MAX_TYPE_ID_SMALL
320-
#ifdef _DEBUG
320+
// WASM-TODO: fix fat tokens
321+
#if defined(_DEBUG) && !defined(TARGET_WASM)
321322
// Stress the overflow mechanism in debug builds.
322323
|| ((typeID != TYPE_ID_THIS_CLASS) && ((typeID % 7) < 4))
323324
#endif

src/coreclr/vm/methodtablebuilder.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,7 +1513,7 @@ MethodTableBuilder::BuildMethodTableThrowing(
15131513
}
15141514
}
15151515

1516-
#if defined(TARGET_X86) || defined(TARGET_AMD64) || defined(TARGET_ARM64)
1516+
#if defined(TARGET_X86) || defined(TARGET_AMD64) || defined(TARGET_ARM64) || defined(TARGET_WASM)
15171517
if (bmtProp->fIsIntrinsicType && !bmtGenerics->HasInstantiation())
15181518
{
15191519
LPCUTF8 nameSpace;
@@ -1538,11 +1538,12 @@ MethodTableBuilder::BuildMethodTableThrowing(
15381538
IfFailThrow(GetMDImport()->GetNameOfTypeDef(td, NULL, &nameSpace));
15391539
}
15401540

1541+
// All the functions in System.Runtime.Intrinsics.<arch> are hardware intrinsics.
15411542
#if defined(TARGET_ARM64)
1542-
// All the funtions in System.Runtime.Intrinsics.Arm are hardware intrinsics.
15431543
if (hr == S_OK && strcmp(nameSpace, "System.Runtime.Intrinsics.Arm") == 0)
1544+
#elif defined(TARGET_WASM)
1545+
if (hr == S_OK && strcmp(nameSpace, "System.Runtime.Intrinsics.Wasm") == 0)
15441546
#else
1545-
// All the funtions in System.Runtime.Intrinsics.X86 are hardware intrinsics.
15461547
if (hr == S_OK && (strcmp(nameSpace, "System.Runtime.Intrinsics.X86") == 0))
15471548
#endif
15481549
{

src/coreclr/vm/virtualcallstub.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2318,7 +2318,7 @@ VirtualCallStubManager::Resolver(
23182318
}
23192319
}
23202320
#endif // defined(LOGGING) || defined(_DEBUG)
2321-
2321+
#ifndef FEATURE_PORTABLE_ENTRYPOINTS
23222322
BOOL fSlotCallsPrestub = DoesSlotCallPrestub(implSlot.GetTarget());
23232323
if (!fSlotCallsPrestub)
23242324
{
@@ -2361,6 +2361,9 @@ VirtualCallStubManager::Resolver(
23612361
}
23622362
}
23632363
}
2364+
#else
2365+
fShouldPatch = TRUE;
2366+
#endif // !FEATURE_PORTABLE_ENTRYPOINTS
23642367
}
23652368
#ifdef FEATURE_COMINTEROP
23662369
else if (pMT->IsComObjectType()

src/coreclr/vm/wasm/cgencpu.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
inline unsigned StackElemSize(unsigned parmSize, bool isValueType = false /* unused */, bool isFloatHfa = false /* unused */)
2424
{
25-
_ASSERTE("The function is not implemented on wasm");
26-
return 0;
25+
const unsigned stackSlotSize = sizeof(void*);
26+
return ALIGN_UP(parmSize, stackSlotSize);
2727
}
2828

2929
struct HijackArgs

0 commit comments

Comments
 (0)