-
-
Notifications
You must be signed in to change notification settings - Fork 185
Fix loading token for TypeSpec #3189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -232,17 +232,54 @@ HRESULT CLR_RT_HeapBlock::SetReflection(const CLR_RT_Assembly_Index &assm) | |||||||||||||||||||||||||||||
NANOCLR_NOCLEANUP_NOLABEL(); | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
HRESULT CLR_RT_HeapBlock::SetReflection(const CLR_RT_TypeSpec_Index &sig) | ||||||||||||||||||||||||||||||
HRESULT CLR_RT_HeapBlock::SetReflection(const CLR_RT_TypeSpec_Instance &tsInst, const CLR_RT_TypeSpec_Index *caller) | ||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||
NATIVE_PROFILE_CLR_CORE(); | ||||||||||||||||||||||||||||||
NANOCLR_HEADER(); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
CLR_RT_TypeDescriptor desc{}; | ||||||||||||||||||||||||||||||
m_id.raw = CLR_RT_HEAPBLOCK_RAW_ID(DATATYPE_REFLECTION, 0, 1); | ||||||||||||||||||||||||||||||
m_data.reflection.kind = REFLECTION_TYPE; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
NANOCLR_CHECK_HRESULT(desc.InitializeFromTypeSpec(sig)); | ||||||||||||||||||||||||||||||
// start parsing the signature | ||||||||||||||||||||||||||||||
CLR_RT_SignatureParser parser; | ||||||||||||||||||||||||||||||
parser.Initialize_TypeSpec(tsInst.assembly, tsInst.target); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
m_id.raw = CLR_RT_HEAPBLOCK_RAW_ID(DATATYPE_REFLECTION, 0, 1); | ||||||||||||||||||||||||||||||
m_data.reflection = desc.m_reflex; | ||||||||||||||||||||||||||||||
// read first element | ||||||||||||||||||||||||||||||
CLR_RT_SignatureParser::Element elem; | ||||||||||||||||||||||||||||||
if (FAILED(parser.Advance(elem))) | ||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||
NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
if (elem.DataType == DATATYPE_VAR || elem.DataType == DATATYPE_MVAR) | ||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||
int gpIndex = elem.GenericParamPosition; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
// if the caller's genericType is non‐null, ask the CLR to map !n→actual argument: | ||||||||||||||||||||||||||||||
if (caller != nullptr && NANOCLR_INDEX_IS_VALID(*caller)) | ||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||
CLR_RT_TypeDef_Index tdArg{}; | ||||||||||||||||||||||||||||||
NanoCLRDataType dtArg; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
bool ok = g_CLR_RT_TypeSystem.m_assemblies[caller->Assembly() - 1] | ||||||||||||||||||||||||||||||
->FindGenericParamAtTypeSpec(caller->TypeSpec(), gpIndex, tdArg, dtArg); | ||||||||||||||||||||||||||||||
if (ok) | ||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||
m_data.reflection.data.type = tdArg; | ||||||||||||||||||||||||||||||
m_data.reflection.levels = elem.Levels; | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
Comment on lines
+266
to
+270
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle failed generic parameter resolution properly. When if (ok)
{
m_data.reflection.data.type = tdArg;
m_data.reflection.levels = elem.Levels;
}
+ else
+ {
+ NANOCLR_SET_AND_LEAVE(CLR_E_TYPE_UNAVAILABLE);
+ } 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
else | ||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||
// TODO | ||||||||||||||||||||||||||||||
_ASSERTE(false); | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
Comment on lines
+272
to
+276
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove TODO section with always-failing assertion. The TODO comment with - else
- {
- // TODO
- _ASSERTE(false);
- }
+ else
+ {
+ // No caller provided for generic parameter resolution
+ NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE);
+ } 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
else | ||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||
m_data.reflection.data.type = elem.Class; | ||||||||||||||||||||||||||||||
m_data.reflection.levels = elem.Levels; | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
NANOCLR_NOCLEANUP(); | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add bounds checking to prevent array access violation.
The code accesses
g_CLR_RT_TypeSystem.m_assemblies[caller->Assembly() - 1]
without bounds checking. IfAssembly()
returns 0, this will cause an underflow and potential memory corruption.📝 Committable suggestion
🤖 Prompt for AI Agents