-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Resolve dllimport.cpp runtimeasync todos #122466
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -2045,6 +2045,10 @@ void COMDelegate::ThrowIfInvalidUnmanagedCallersOnlyUsage(MethodDesc* pMD) | |
| if (pMD->HasClassOrMethodInstantiation()) | ||
| EX_THROW(EEResourceException, (kInvalidProgramException, W("InvalidProgram_GenericMethod"))); | ||
|
|
||
| // No async methods | ||
|
Member
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. We have tests for the other negative cases in src\tests\Interop\UnmanagedCallersOnly\InvalidCallbacks.il . We can add the async one too for completeness. |
||
| if (pMD->IsAsyncMethod()) | ||
| EX_THROW(EEResourceException, (kInvalidProgramException, W("InvalidProgram_AsyncMethod"))); | ||
|
|
||
| // Arguments - Scenarios involving UnmanagedCallersOnly are handled during the jit. | ||
| bool unmanagedCallersOnlyRequiresMarshalling = false; | ||
| if (PInvoke::MarshalingRequired(pMD, NULL, NULL, NULL, unmanagedCallersOnlyRequiresMarshalling)) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -100,6 +100,7 @@ StubSigDesc::StubSigDesc(MethodDesc *pMD) | |
| GC_NOTRIGGER; | ||
| SUPPORTS_DAC; | ||
| PRECONDITION(pMD != NULL); | ||
| PRECONDITION(!pMD->IsAsyncMethod()); | ||
|
||
| } | ||
| CONTRACTL_END; | ||
|
|
||
|
|
@@ -108,9 +109,6 @@ StubSigDesc::StubSigDesc(MethodDesc *pMD) | |
| m_sig = pMD->GetSignature(); | ||
| m_pModule = pMD->GetModule(); // Used for token resolution. | ||
|
|
||
| // TODO: (async) revisit and examine if this needs to be supported somehow | ||
| _ASSERTE(!pMD->IsAsyncMethod()); | ||
|
|
||
| m_tkMethodDef = pMD->GetMemberDef(); | ||
| SigTypeContext::InitTypeContext(pMD, &m_typeContext); | ||
| m_pMetadataModule = pMD->GetModule(); | ||
|
|
@@ -1131,7 +1129,6 @@ class ILStubState : public StubState | |
| DWORD dwToken = 0; | ||
| if (pTargetMD) | ||
| { | ||
| // TODO: (async) revisit and examine if this needs to be supported somehow | ||
| _ASSERTE(!pTargetMD->IsAsyncVariantMethod()); | ||
| dwToken = pTargetMD->GetMemberDef(); | ||
| } | ||
|
|
@@ -2764,6 +2761,10 @@ void PInvokeStaticSigInfo::DllImportInit( | |
|
|
||
| PRECONDITION(CheckPointer(pMD)); | ||
|
|
||
| // P/Invoke methods should never be marked as async. | ||
| // This should be blocked in the class loader. | ||
| PRECONDITION(!pMD->IsAsyncMethod()); | ||
|
|
||
| // These preconditions to prevent multithreaded regression | ||
| // where pMD->m_szLibName was passed in directly, cleared | ||
| // by this API, then accessed on another thread before being reset here. | ||
|
|
@@ -2779,9 +2780,6 @@ void PInvokeStaticSigInfo::DllImportInit( | |
| IMDInternalImport *pInternalImport = pMD->GetMDImport(); | ||
| CorPinvokeMap mappingFlags = pmMaxValue; | ||
| mdModuleRef modref = mdModuleRefNil; | ||
| // TODO: (async) revisit and examine if this needs to be supported somehow | ||
| if (pMD->IsAsyncMethod()) | ||
| ThrowHR(COR_E_NOTSUPPORTED); | ||
|
|
||
| if (FAILED(pInternalImport->GetPinvokeMap(pMD->GetMemberDef(), (DWORD*)&mappingFlags, ppEntryPointName, &modref))) | ||
| { | ||
|
|
@@ -3053,16 +3051,15 @@ namespace | |
| STANDARD_VM_CHECK; | ||
| PRECONDITION(pMD != NULL); | ||
| PRECONDITION(pMD->IsPInvoke()); | ||
| PRECONDITION(!pMD->IsAsyncMethod()); | ||
| PRECONDITION(callConv != NULL); | ||
| } | ||
| CONTRACTL_END; | ||
|
|
||
| CorInfoCallConvExtension callConvLocal; | ||
| IMDInternalImport* pInternalImport = pMD->GetMDImport(); | ||
| CorPinvokeMap mappingFlags = pmMaxValue; | ||
| // TODO: (async) revisit and examine if this needs to be supported somehow | ||
| if (pMD->IsAsyncMethod()) | ||
| ThrowHR(COR_E_NOTSUPPORTED); | ||
|
|
||
|
Comment on lines
+3054
to
+3062
|
||
|
|
||
| HRESULT hr = pInternalImport->GetPinvokeMap(pMD->GetMemberDef(), (DWORD*)&mappingFlags, NULL /*pszImportName*/, NULL /*pmrImportDLL*/); | ||
| if (FAILED(hr)) | ||
|
|
@@ -3249,6 +3246,12 @@ BOOL PInvoke::MarshalingRequired( | |
| { | ||
| STANDARD_VM_CHECK; | ||
| PRECONDITION(pMD != NULL || (!sigPointer.IsNull() && pModule != NULL)); | ||
|
|
||
| // We should never see an async method here. | ||
| // Delegate Invoke methods should never be async. | ||
| // Async P/Invokes are not supported. | ||
| // Async UnmanagedCallersOnly methods are not supported. | ||
| PRECONDITION(pMD == NULL || !pMD->IsAsyncMethod()); | ||
| } | ||
| CONTRACTL_END; | ||
|
|
||
|
|
@@ -3324,10 +3327,6 @@ BOOL PInvoke::MarshalingRequired( | |
| mdMethodDef methodToken = mdMethodDefNil; | ||
| if (pMD != NULL) | ||
| { | ||
| // TODO: (async) revisit and examine if this needs to be supported somehow | ||
| if (pMD->IsAsyncMethod()) | ||
| ThrowHR(COR_E_NOTSUPPORTED); | ||
|
|
||
| methodToken = pMD->GetMemberDef(); | ||
| } | ||
| CollateParamTokens(pMDImport, methodToken, numArgs - 1, pParamTokenArray); | ||
|
|
@@ -6080,12 +6079,10 @@ static void GetILStubForCalli(VASigCookie* pVASigCookie, MethodDesc* pMD) | |
|
|
||
| if (pMD != NULL) | ||
| { | ||
| _ASSERTE(pMD->IsPInvoke()); | ||
| _ASSERTE(!pMD->IsAsyncMethod()); | ||
| PInvokeStaticSigInfo sigInfo(pMD); | ||
|
|
||
| // TODO: (async) revisit and examine if this needs to be supported somehow | ||
| if (pMD->IsAsyncMethod()) | ||
| ThrowHR(COR_E_NOTSUPPORTED); | ||
|
|
||
| md = pMD->GetMemberDef(); | ||
| nlFlags = sigInfo.GetLinkFlags(); | ||
| nlType = sigInfo.GetCharSet(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3183,6 +3183,11 @@ MethodTableBuilder::EnumerateClassMethods() | |
| CONSISTENCY_CHECK(hr == S_OK); | ||
| type = mcPInvoke; | ||
| } | ||
|
|
||
| if (type == mcPInvoke && IsMiAsync(dwImplFlags)) | ||
|
Member
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. Should we reject MiAsync on anything that is not mcIL or mcInstantiated? For example, FCalls or delegate methods marked with MiAsync are not going to work well either. We just do not have them at the moment. |
||
| { | ||
| BuildMethodTableThrowException(BFA_ASYNC_PINVOKE_METHOD); | ||
| } | ||
| } | ||
| else if (IsMiRuntime(dwImplFlags)) | ||
| { | ||
|
|
@@ -3441,6 +3446,13 @@ MethodTableBuilder::EnumerateClassMethods() | |
| asyncVariantType = mcIL; | ||
| } | ||
| #endif // FEATURE_COMINTEROP | ||
| if (type == mcPInvoke) | ||
| { | ||
| // For P/Invoke methods, | ||
|
Member
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. Can a valid P/Invoke actually return Task (marshalled as IUknown) that can awaited by the caller? Should we have a test for it? |
||
| // we don't want to treat the async variant as a P/Invoke method | ||
| // (as it isn't, it's a transient IL method). | ||
| asyncVariantType = mcIL; | ||
| } | ||
|
|
||
| Signature newMemberSig(pNewMemberSignature, cAsyncThunkMemberSignature); | ||
| pNewMethod = new (GetStackingAllocator()) bmtMDMethod( | ||
|
|
||
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.
All BFA_.... are in a block together. Can this be part of that block? (Alternatively, do not call it BFA...)