Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
c630b82
Implement localloc IL instruction
josesimoes Nov 25, 2025
51a2269
Implement ctor from pointer for Span and ReadOnlySpan
josesimoes Nov 25, 2025
2dde11e
Add implementation of cpblk IL isntruction
josesimoes Nov 27, 2025
42764cb
Add new data type DATATYPE_PTR
josesimoes Nov 27, 2025
3dcc6a4
Local allocation array is not of uintptr_t type
josesimoes Nov 27, 2025
e016185
Work in local alloc code
josesimoes Nov 27, 2025
d945147
Numeric add and substract can now handle operations with unmaged poin…
josesimoes Nov 27, 2025
c029754
ldsflda now properly handles fields with RVA
josesimoes Nov 27, 2025
750b1ef
Fix Span .ctor from unmaged pointer
josesimoes Nov 27, 2025
93c5e76
Code style fixes
nfbot Nov 27, 2025
0070171
Merge pull request #107 from nanoframework/nfbot/clang-format-fix/900…
josesimoes Nov 27, 2025
81c52b2
Add check for array creation
josesimoes Nov 27, 2025
c661286
Rename unnused var for clarity
josesimoes Nov 27, 2025
df4fb02
Fix type
josesimoes Nov 27, 2025
6bb60cc
Add new APIs to heap block to deal with unmanaged pointers
josesimoes Nov 27, 2025
8bac145
Code style fixes
nfbot Nov 27, 2025
90e4a41
Merge pull request #108 from nanoframework/nfbot/clang-format-fix/0e6…
josesimoes Nov 27, 2025
9aaaff5
Fix call to BuildTypeName for TypeSpec in DumpToken
josesimoes Dec 2, 2025
ea7ecad
Add new reflection type for storage pointer
josesimoes Dec 2, 2025
946af06
Add support for storage pointers in heap block array
josesimoes Dec 2, 2025
70edd2f
Fix handler for ldsflda to deal correctly with fields with RVA
josesimoes Dec 2, 2025
fd9b575
Fix Span<T> constructors and copy operations to use storage pointers
josesimoes Dec 2, 2025
cfa0be9
GetGenericArgument at MethodSpec instance now returns a signature ele…
josesimoes Dec 2, 2025
3d910ff
Fix ComputeHashForClosedGenericType
josesimoes Dec 2, 2025
ffb1e52
Resolving token in TypeDef instance now take optional parameter typeS…
josesimoes Dec 2, 2025
e06ea50
BuildTypeName now is able to resolve VAR elements
josesimoes Dec 2, 2025
7b825a4
Creating HeapBlock array now accepts typeSpec parameter for type reso…
josesimoes Dec 2, 2025
9582948
Missed commit ffb1e521b24212bf665b4616f00c2295228eb2a0
josesimoes Dec 2, 2025
faa5fb2
AllocateGenericStaticFieldsOnDemand now correctly stores TypeSpec con…
josesimoes Dec 2, 2025
65b7476
Improve BuildMethodName to build type name for generic instances
josesimoes Dec 2, 2025
aac7793
Code style fixes
josesimoes Dec 2, 2025
8fbe833
Fix constructors of ReadOnlySpan
josesimoes Dec 2, 2025
c894eef
Code style fixes
josesimoes Dec 3, 2025
0bc02e0
Add robust stack validation
josesimoes Dec 3, 2025
7931474
Signature parser now can consume modifiers in types
josesimoes Dec 3, 2025
b8492c3
Fix arithmetic of stack validation
josesimoes Dec 3, 2025
e04dec8
Moved readonly. prefix to group of "do nothing" op codes
josesimoes Dec 3, 2025
29c82dc
Merge branch 'develop' of https://github.com/nanoframework/nf-interpr…
josesimoes Dec 3, 2025
63052c8
Code style fixes
nfbot Dec 3, 2025
0787624
Merge pull request #109 from nanoframework/nfbot/clang-format-fix/afe…
josesimoes Dec 3, 2025
76dd1b8
Remove unused var
josesimoes Dec 3, 2025
8e63742
Addressing code reviews
josesimoes Dec 3, 2025
efe42d9
Remove unused vars
josesimoes Dec 3, 2025
769059b
Fix the context being stored in the delegate to generic static .cctor
josesimoes Dec 4, 2025
6392da0
Fix resolving token of TypeDef for a VAR in a TypeSpec
josesimoes Dec 4, 2025
ff0f76b
Dump assembly token now takes TypeSpec parameter for context
josesimoes Dec 4, 2025
4218d94
Code style fixes
nfbot Dec 4, 2025
92f3b52
Merge pull request #110 from nanoframework/nfbot/clang-format-fix/38a…
josesimoes Dec 4, 2025
a98bfe0
Fix corruption in virtual methods cache table
josesimoes Dec 5, 2025
1398722
Merge branch 'develop' of https://github.com/nanoframework/nf-interpr…
josesimoes Dec 5, 2025
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
19 changes: 18 additions & 1 deletion src/CLR/CorLib/corlib_native.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,10 @@ static const CLR_RT_MethodHandler method_lookup[] =
Library_corlib_native_System_Random::_ctor___VOID,
Library_corlib_native_System_Random::_ctor___VOID__I4,
nullptr,
Library_corlib_native_System_ReadOnlySpan_1::_ctor___VOID__VOIDptr__I4,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
Expand All @@ -711,6 +715,14 @@ static const CLR_RT_MethodHandler method_lookup[] =
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
Library_corlib_native_System_Reflection_ConstructorInfo::GetCustomAttributes___SZARRAY_OBJECT__BOOLEAN,
Library_corlib_native_System_Reflection_ConstructorInfo::Invoke___OBJECT__SZARRAY_OBJECT,
nullptr,
Expand Down Expand Up @@ -798,6 +810,7 @@ static const CLR_RT_MethodHandler method_lookup[] =
nullptr,
nullptr,
nullptr,
Library_corlib_native_System_Span_1::_ctor___VOID__VOIDptr__I4,
nullptr,
nullptr,
nullptr,
Expand Down Expand Up @@ -827,6 +840,10 @@ static const CLR_RT_MethodHandler method_lookup[] =
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
Library_corlib_native_System_Threading_AutoResetEvent::_ctor___VOID__BOOLEAN,
Library_corlib_native_System_Threading_AutoResetEvent::Reset___BOOLEAN,
Library_corlib_native_System_Threading_AutoResetEvent::Set___BOOLEAN,
Expand Down Expand Up @@ -1596,7 +1613,7 @@ const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_mscorlib =

#if (NANOCLR_REFLECTION == TRUE)

0x3C34952A,
0xCECAB752,

#elif (NANOCLR_REFLECTION == FALSE)

Expand Down
2 changes: 2 additions & 0 deletions src/CLR/CorLib/corlib_native.h
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,7 @@ struct Library_corlib_native_System_ReadOnlySpan_1
static const int FIELD___array = 1;
static const int FIELD___length = 2;

NANOCLR_NATIVE_DECLARE(_ctor___VOID__VOIDptr__I4);
NANOCLR_NATIVE_DECLARE(NativeReadOnlySpanConstructor___VOID__SZARRAY_GENERICTYPE__I4__I4);

//--//
Expand Down Expand Up @@ -962,6 +963,7 @@ struct Library_corlib_native_System_Span_1
static const int FIELD___array = 1;
static const int FIELD___length = 2;

NANOCLR_NATIVE_DECLARE(_ctor___VOID__VOIDptr__I4);
NANOCLR_NATIVE_DECLARE(CopyTo___VOID__SystemSpan_1);
NANOCLR_NATIVE_DECLARE(NativeSpanConstructor___VOID__SZARRAY_GENERICTYPE__I4__I4);

Expand Down
132 changes: 112 additions & 20 deletions src/CLR/CorLib/corlib_native_System_ReadOnlySpan_1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,105 @@

#include "CorLib.h"

typedef Library_corlib_native_System_Runtime_CompilerServices_RuntimeHelpers RuntimeHelpers;

HRESULT Library_corlib_native_System_ReadOnlySpan_1::_ctor___VOID__VOIDptr__I4(CLR_RT_StackFrame &stack)
{
NANOCLR_HEADER();

int32_t length;
bool isRefContainsRefs = false;
uintptr_t objectRawPointer;

CLR_RT_HeapBlock *thisSpan = stack.This();

// grab caller to get the generic type
CLR_RT_MethodDef_Instance &caller = stack.MethodCall();

if (caller.genericType == nullptr || !NANOCLR_INDEX_IS_VALID(*caller.genericType))
{
NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE);
}

CLR_RT_TypeSpec_Instance typeSpec;
if (!typeSpec.InitializeFromIndex(*caller.genericType))
{
NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE);
}

CLR_RT_SignatureParser parser;
parser.Initialize_TypeSpec(typeSpec);

CLR_RT_SignatureParser::Element element;

if (FAILED(parser.Advance(element)))
{
NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE);
}

// The first element should be the generic type instantiation
if (element.DataType != DATATYPE_GENERICINST)
{
NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE);
}

// Advance to get the generic argument (T)
if (FAILED(parser.Advance(element)))
{
NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE);
}

if (element.DataType == DATATYPE_VALUETYPE)
{
// For value types we need to advance again
if (FAILED(parser.Advance(element)))
{
NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE);
}
}

// check if T is a reference type or contains references
NANOCLR_CHECK_HRESULT(
RuntimeHelpers::CheckReferenceOrContainsReferences(
element.Class,
element.DataType,
&parser,
isRefContainsRefs));

if (isRefContainsRefs)
{
NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER);
}

// validate length parameter
length = stack.Arg2().NumericByRefConst().s4;

if (length < 0)
{
NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_RANGE);
}

// get the pointer to the array
// validate data type as being an unmanaged pointer
if (stack.Arg1().DataType() != DATATYPE_PTR)
{
NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER);
}

objectRawPointer = (uintptr_t)stack.Arg1().UnmanagedPointer();

{
CLR_RT_HeapBlock &refArray = thisSpan[FIELD___array];
NANOCLR_CHECK_HRESULT(
CLR_RT_HeapBlock_Array::CreateInstanceWithStorage(refArray, length, objectRawPointer, element.Class));
}

// set length
thisSpan[FIELD___length].NumericByRef().s4 = length;

NANOCLR_NOCLEANUP();
}

HRESULT Library_corlib_native_System_ReadOnlySpan_1::NativeReadOnlySpanConstructor___VOID__SZARRAY_GENERICTYPE__I4__I4(
CLR_RT_StackFrame &stack)
{
Expand All @@ -16,37 +115,30 @@ HRESULT Library_corlib_native_System_ReadOnlySpan_1::NativeReadOnlySpanConstruct

CLR_RT_TypeDescriptor descDst{};
CLR_RT_TypeDef_Index sourceType{};
CLR_RT_HeapBlock_Array *destinationArray;
CLR_RT_HeapBlock_Array *sourceArray = stack.Arg1().DereferenceArray();
CLR_RT_HeapBlock *thisSpan = stack.This();

// get working values
start = stack.Arg2().NumericByRefConst().s4;
length = stack.Arg3().NumericByRefConst().s4;

{
// get type of the source array
NANOCLR_CHECK_HRESULT(descDst.InitializeFromObject(*sourceArray));
descDst.GetElementType(descDst);

sourceType.data = descDst.m_handlerCls.data;

CLR_RT_HeapBlock &refArray = thisSpan[FIELD___array];
CLR_RT_HeapBlock_Array::CreateInstance(refArray, length, sourceType);

// get pointer to the array
destinationArray = thisSpan[FIELD___array].DereferenceArray();
// get type of the source array
NANOCLR_CHECK_HRESULT(descDst.InitializeFromObject(*sourceArray));
descDst.GetElementType(descDst);

// protect from GC
CLR_RT_ProtectFromGC gc1(*sourceArray);
CLR_RT_ProtectFromGC gc2(refArray);
sourceType.data = descDst.m_handlerCls.data;

// copy array
CLR_RT_HeapBlock_Array::Copy(sourceArray, start, destinationArray, 0, length);
{
// get the pointer to the element at start address
uintptr_t ptrToStartElement = (uintptr_t)sourceArray->GetElement(start);

// set length
thisSpan[FIELD___length].NumericByRef().s4 = length;
CLR_RT_HeapBlock &refArray = thisSpan[FIELD___array];
NANOCLR_CHECK_HRESULT(
CLR_RT_HeapBlock_Array::CreateInstanceWithStorage(refArray, length, ptrToStartElement, sourceType));
}

// set length
thisSpan[FIELD___length].NumericByRef().s4 = length;

NANOCLR_NOCLEANUP();
}
Loading