Skip to content

Commit e1feed8

Browse files
authored
[clr-interp] Implement missing support for startup path (dotnet#118404)
* Refactor string allocation method to use native-sized integer; add support for CPBLK operation in interpreter; Special-case RuntimeHandle constructors * Add null reference checks before memcpy * Include namespace checks for RuntimeHandle types * Refactor EmitCall method to simplify type handling; replace memcpy with memcpyNoGCRefs for null reference safety * Remove unnecessary include of classnames.h
1 parent d000ce2 commit e1feed8

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

src/coreclr/System.Private.CoreLib/src/System/String.CoreCLR.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ internal static unsafe string StrCns(uint rid, IntPtr scopeHandle)
2525
}
2626

2727
[MethodImpl(MethodImplOptions.InternalCall)]
28-
internal static extern unsafe string FastAllocateString(MethodTable *pMT, int length);
28+
internal static extern unsafe string FastAllocateString(MethodTable *pMT, nint length);
2929

3030
[DebuggerHidden]
31-
internal static unsafe string FastAllocateString(int length)
31+
internal static unsafe string FastAllocateString(nint length)
3232
{
3333
return FastAllocateString(TypeHandle.TypeHandleOf<string>().AsMethodTable(), length);
3434
}

src/coreclr/interpreter/compiler.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2834,7 +2834,7 @@ void InterpCompiler::EmitCall(CORINFO_RESOLVED_TOKEN* pConstrainedToken, bool re
28342834
if (newObjThisArgLocation != INT_MAX)
28352835
{
28362836
ctorType = GetInterpType(m_compHnd->asCorInfoType(resolvedCallToken.hClass));
2837-
if (ctorType == InterpTypeVT)
2837+
if (ctorType != InterpTypeO)
28382838
{
28392839
vtsize = m_compHnd->getClassSize(resolvedCallToken.hClass);
28402840
PushTypeVT(resolvedCallToken.hClass, vtsize);
@@ -2966,7 +2966,7 @@ void InterpCompiler::EmitCall(CORINFO_RESOLVED_TOKEN* pConstrainedToken, bool re
29662966
case CORINFO_CALL:
29672967
if (newObj && !doCallInsteadOfNew)
29682968
{
2969-
if (ctorType == InterpTypeVT)
2969+
if (ctorType != InterpTypeO)
29702970
{
29712971
// If this is a newobj for a value type, we need to call the constructor
29722972
// and then copy the value type to the stack.
@@ -5412,6 +5412,18 @@ void InterpCompiler::GenerateCode(CORINFO_METHOD_INFO* methodInfo)
54125412
m_ip += 5;
54135413
break;
54145414
}
5415+
case CEE_CPBLK:
5416+
CHECK_STACK(3);
5417+
if (volatile_)
5418+
{
5419+
AddIns(INTOP_MEMBAR);
5420+
volatile_ = false;
5421+
}
5422+
AddIns(INTOP_CPBLK);
5423+
m_pStackPointer -= 3;
5424+
m_pLastNewIns->SetSVars3(m_pStackPointer[0].var, m_pStackPointer[1].var, m_pStackPointer[2].var);
5425+
m_ip++;
5426+
break;
54155427
default:
54165428
{
54175429
const uint8_t *ip = m_ip - 1;

src/coreclr/interpreter/intops.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ OPDEF(INTOP_GENERICLOOKUP, "generic", 4, 1, 1, InterpOpGenericLookup)
390390
OPDEF(INTOP_CALL_FINALLY, "call.finally", 2, 0, 0, InterpOpBranch)
391391

392392
OPDEF(INTOP_ZEROBLK_IMM, "zeroblk.imm", 3, 0, 1, InterpOpInt)
393+
OPDEF(INTOP_CPBLK, "cpblk", 4, 0, 3, InterpOpNoArgs)
393394
OPDEF(INTOP_LOCALLOC, "localloc", 3, 1, 1, InterpOpNoArgs)
394395
OPDEF(INTOP_BREAKPOINT, "breakpoint", 1, 0, 0, InterpOpNoArgs)
395396

src/coreclr/vm/interpexec.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,6 +2012,18 @@ void InterpExecMethod(InterpreterFrame *pInterpreterFrame, InterpMethodContextFr
20122012
memset(LOCAL_VAR(ip[1], void*), 0, ip[2]);
20132013
ip += 3;
20142014
break;
2015+
case INTOP_CPBLK:
2016+
{
2017+
void* dst = LOCAL_VAR(ip[1], void*);
2018+
void* src = LOCAL_VAR(ip[2], void*);
2019+
size_t size = LOCAL_VAR(ip[3], size_t);
2020+
if (size && (!dst || !src))
2021+
COMPlusThrow(kNullReferenceException);
2022+
else
2023+
memcpyNoGCRefs(dst, src, size);
2024+
ip += 4;
2025+
break;
2026+
}
20152027
case INTOP_LOCALLOC:
20162028
{
20172029
size_t len = LOCAL_VAR(ip[2], size_t);

0 commit comments

Comments
 (0)