-
Notifications
You must be signed in to change notification settings - Fork 508
implemented portable PInvoke infrastructure for CppCodeGen #4503
Conversation
@hippiehunter, |
src/Native/Runtime/thread.cpp
Outdated
COOP_PINVOKE_HELPER(void, RhpPInvoke2, (PInvokeTransitionFrame* pFrame)) | ||
{ | ||
Thread * pCurThread = ThreadStore::RawGetCurrentThread(); | ||
pCurThread->InlinePInvoke(pFrame); |
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.
Nit: Indentation
src/Native/Runtime/thread.cpp
Outdated
@@ -1158,6 +1158,31 @@ FORCEINLINE void Thread::InlineReversePInvokeReturn(ReversePInvokeFrame * pFrame | |||
} | |||
} | |||
|
|||
FORCEINLINE void Thread::InlinePInvoke(PInvokeTransitionFrame * pFrame) | |||
{ | |||
pFrame->m_pThread = this; |
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.
Nit: indentation
src/Native/Runtime/thread.cpp
Outdated
|
||
FORCEINLINE void Thread::InlinePInvokeReturn(PInvokeTransitionFrame * pFrame) | ||
{ | ||
m_pTransitionFrame = NULL; |
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.
Nit: indentation
src/Native/Runtime/thread.h
Outdated
@@ -255,6 +255,9 @@ class Thread : private ThreadBuffer | |||
bool InlineTryFastReversePInvoke(ReversePInvokeFrame * pFrame); | |||
void InlineReversePInvokeReturn(ReversePInvokeFrame * pFrame); | |||
|
|||
void InlinePInvoke(PInvokeTransitionFrame * pFrame); |
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.
Nit: Indentiation
src/Native/Runtime/thread.cpp
Outdated
@@ -1287,4 +1312,16 @@ COOP_PINVOKE_HELPER(void, RhpReversePInvokeReturn2, (ReversePInvokeFrame * pFram | |||
pFrame->m_savedThread->InlineReversePInvokeReturn(pFrame); | |||
} | |||
|
|||
COOP_PINVOKE_HELPER(void, RhpPInvoke2, (PInvokeTransitionFrame* pFrame)) |
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.
RhpPInvoke2/RhpPInvokeReturn2 should be under #ifdef USE_PORTABLE_HELPERS
here. It does not make sense otherwise.
src/Native/Bootstrap/CppCodeGen.h
Outdated
@@ -41,4 +41,33 @@ inline double __uint64_to_double(uint64_t v) | |||
return val.d; | |||
} | |||
|
|||
#endif // __CPP_CODE_GEN_H | |||
#ifdef USE_PORTABLE_HELPERS |
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.
I meant this ifdef to be in rhbinder.h. This file is only used when USE_PORTABLE_HELPERS
is defined, so the ifdef does not need to be here.
src/Native/Bootstrap/CppCodeGen.h
Outdated
#ifdef _TARGET_ARM_ | ||
TgtPTR_Void m_ChainPointer; // R11, used by OS to walk stack quickly | ||
#endif | ||
TgtPTR_Void m_RIP; |
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.
What is the minimal struct PInvokeTransitionFrame
that we can get away for USE_PORTABLE_HELPERS
? Ideally, it would have just m_pThread
and nothing else.
if (method.IsRawPInvoke()) | ||
{ | ||
AppendLine(); | ||
Append("PInvokeTransitionFrame __piframe"); |
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.
This assumes that there will be at most one RawPInvoke callsite per method. It is a safe assumption to make today, but it maybe worth a comment.
@@ -41,4 +41,33 @@ inline double __uint64_to_double(uint64_t v) | |||
return val.d; | |||
} |
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.
You can move ReversePInvokeFrame from common.h here as well while you are on it.
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.
(Most of the CppCodeGen specific stuff should really be in this file actually and not in common.h.)
14204b5
to
bf53dc5
Compare
It appears that StackFrameIterator.cpp depends on most of the fields in PInvokeTransitionFrame. I guess that brings me to my next question, what is the way forward on enabling the stack walker here? Is it as simple as filling out the values of the transition frame when we pinvoke? |
The stackwalker will need significant overhaul for CppCodeGen. It maybe useful to mention it in a comment in the portable version of PInvokeTransitionFrame. Stackwalker is used for several purposes today:
|
src/Native/Runtime/thread.cpp
Outdated
pFrame->m_pThread->InlinePInvokeReturn(pFrame); | ||
} | ||
|
||
#endif |
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.
Nit: We typically have the name of the ifdef as comment on #endif
.
src/Native/Runtime/inc/rhbinder.h
Outdated
@@ -646,6 +657,7 @@ struct PInvokeTransitionFrame | |||
#endif | |||
UIntTarget m_PreservedRegs[]; | |||
}; | |||
#endif |
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.
Same here
bf53dc5
to
10698e4
Compare
updated for comments |
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.
Thanks!
No description provided.