summaryrefslogtreecommitdiff
path: root/src/vm/comdynamic.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/vm/comdynamic.cpp')
-rw-r--r--src/vm/comdynamic.cpp442
1 files changed, 0 insertions, 442 deletions
diff --git a/src/vm/comdynamic.cpp b/src/vm/comdynamic.cpp
index 835b5cab3b..97e408ac32 100644
--- a/src/vm/comdynamic.cpp
+++ b/src/vm/comdynamic.cpp
@@ -714,33 +714,6 @@ INT32 QCALLTYPE COMDynamicWrite::SetParamInfo(QCall::ModuleHandle pModule, UINT3
return (INT32)retVal;
}
-#ifndef FEATURE_CORECLR
-/*============================CWSetMarshal============================
-**Action: Helper to set marshal information
-**Returns:
-**Arguments:
-**Exceptions:
-==============================================================================*/
-void QCALLTYPE COMDynamicWrite::SetFieldMarshal(QCall::ModuleHandle pModule, UINT32 tk, LPCBYTE pMarshal, INT32 cbMarshal)
-{
- QCALL_CONTRACT;
-
- BEGIN_QCALL;
-
- RefClassWriter * pRCW = pModule->GetReflectionModule()->GetClassWriter();
- _ASSERTE(pRCW);
-
- _ASSERTE(pMarshal);
-
- // Define the signature
- IfFailThrow(pRCW->GetEmitter()->SetFieldMarshal(
- tk,
- (PCCOR_SIGNATURE)pMarshal, // marshal blob
- cbMarshal)); // blob length
-
- END_QCALL;
-}
-#endif
/*============================SetConstantValue============================
**Action: Helper to set constant value to field or parameter
@@ -1103,275 +1076,6 @@ void ManagedBitnessFlagsToUnmanagedBitnessFlags(
*pPeFlags |= ICEE_CREATE_MACHINE_ARM|ICEE_CREATE_FILE_PE32;
}
-#ifndef FEATURE_CORECLR
-//=============================PreSavePEFile=====================================*/
-// PreSave the PEFile
-//==============================================================================*/
-void QCALLTYPE COMDynamicWrite::PreSavePEFile(QCall::ModuleHandle pModule, INT32 portableExecutableKind, INT32 imageFileMachine)
-{
- QCALL_CONTRACT;
-
- BEGIN_QCALL;
-
- RefClassWriter *pRCW = pModule->GetReflectionModule()->GetClassWriter();
- _ASSERTE(pRCW);
-
- DWORD peFlags = 0, corhFlags = 0;
- ManagedBitnessFlagsToUnmanagedBitnessFlags(portableExecutableKind, imageFileMachine, &peFlags, &corhFlags);
- IfFailThrow(pRCW->EnsureCeeFileGenCreated(corhFlags, peFlags));
-
- ICeeFileGen *pCeeFileGen = pRCW->GetCeeFileGen();
- HCEEFILE ceeFile = pRCW->GetHCEEFILE();
- _ASSERTE(ceeFile && pCeeFileGen);
-
- // We should not have the on disk emitter yet
- if (pRCW->GetOnDiskEmitter() != NULL)
- pRCW->SetOnDiskEmitter(NULL);
-
- // Get the dispenser.
- SafeComHolderPreemp<IMetaDataDispenserEx> pDisp;
- IfFailThrow(MetaDataGetDispenser(CLSID_CorMetaDataDispenser, IID_IMetaDataDispenserEx, (void**)&pDisp));
-
- //Get the emitter and the importer
- IMetaDataImport *pImport = pRCW->GetRWImporter();
- IMetaDataEmit *pEmit = pRCW->GetEmitter();
- _ASSERTE((pEmit != NULL ) && (pImport != NULL));
-
- // Set the option on the dispenser turn on duplicate check for TypeDef and moduleRef
- VARIANT varOption;
- V_VT(&varOption) = VT_UI4;
- V_I4(&varOption) = MDDupDefault | MDDupTypeDef | MDDupModuleRef | MDDupExportedType | MDDupAssemblyRef | MDDupFile | MDDupAssembly;
- IfFailThrow(pDisp->SetOption(MetaDataCheckDuplicatesFor, &varOption));
-
- V_VT(&varOption) = VT_UI4;
- V_I4(&varOption) = MDRefToDefNone;
- IfFailThrow(pDisp->SetOption(MetaDataRefToDefCheck, &varOption));
-
- V_VT(&varOption) = VT_UI4;
- V_I4(&varOption) = MergeManifest;
- IfFailThrow(pDisp->SetOption(MetaDataMergerOptions, &varOption));
-
- //Define an empty scope
- SafeComHolderPreemp<IMetaDataEmit> pEmitNew;
- IfFailThrow(pDisp->DefineScope(CLSID_CorMetaDataRuntime, 0, IID_IMetaDataEmit, (IUnknown**)&pEmitNew));
-
- // Token can move upon merge. Get the IMapToken from the CeeFileGen that is created for save
- // and pass it to merge to receive token movement notification.
- // Note that this is not a long term fix. We are relying on the fact that those tokens embedded
- // in PE cannot move after the merge. These tokens are TypeDef, TypeRef, MethodDef, FieldDef, MemberRef,
- // TypeSpec, UserString. If this is no longer true, we can break!
- //
- // Note that we don't need to release pIMapToken because it is not AddRef'ed in the GetIMapTokenIfaceEx.
- //
- IUnknown *pUnknown = NULL;
- IfFailThrow(pCeeFileGen->GetIMapTokenIfaceEx(ceeFile, pEmit, &pUnknown));
-
- SafeComHolderPreemp<IMapToken> pIMapToken;
- IfFailThrow(SafeQueryInterfacePreemp(pUnknown, IID_IMapToken, (IUnknown**) &pIMapToken));
-
- // get the unmanaged writer.
- ISymUnmanagedWriter *pWriter = pModule->GetReflectionModule()->GetISymUnmanagedWriter();
- SafeComHolderPreemp<CSymMapToken> pSymMapToken(new CSymMapToken(pWriter, pIMapToken));
-
- //Merge the old tokens into the new (empty) scope
- //This is a copy.
- IfFailThrow(pEmitNew->Merge(pImport, pSymMapToken, NULL));
- IfFailThrow(pEmitNew->MergeEnd());
-
- // Update the Module name in the new scope.
- CQuickArray<WCHAR> cqModuleName;
- ULONG cchName;
-
- IfFailThrow(pImport->GetScopeProps(0, 0, &cchName, 0));
-
- cqModuleName.ReSizeThrows(cchName);
-
- IfFailThrow(pImport->GetScopeProps(cqModuleName.Ptr(), cchName, &cchName, 0));
- IfFailThrow(pEmitNew->SetModuleProps(cqModuleName.Ptr()));
-
- // cache the pEmitNew to RCW!!
- pRCW->SetOnDiskEmitter(pEmitNew);
-
- END_QCALL;
-} // COMDynamicWrite::PreSavePEFile
-
-//=============================SavePEFile=====================================*/
-// Save the PEFile to disk
-//==============================================================================*/
-void QCALLTYPE COMDynamicWrite::SavePEFile(QCall::ModuleHandle pModule, LPCWSTR wszPeName, UINT32 entryPoint, UINT32 fileKind, BOOL isManifestFile)
-{
- QCALL_CONTRACT;
-
- BEGIN_QCALL;
-
- HRESULT hr=S_OK;
- HCORENUM hTypeDefs=0;
- mdTypeDef td;
- ULONG count;
- IMetaDataImport *pImportNew = 0;
- ULONG newMethRVA;
- DWORD metaDataSize;
- BYTE *metaData;
- ULONG metaDataOffset;
- HCEESECTION pILSection;
- ISymUnmanagedWriter *pWriter = NULL;
-
- if (wszPeName==NULL)
- COMPlusThrow(kArgumentNullException, W("ArgumentNull_String"));
- if (wszPeName[0] == '\0')
- COMPlusThrow(kFormatException, W("Format_StringZeroLength"));
-
- Assembly * pAssembly = pModule->GetAssembly();
- _ASSERTE( pAssembly );
-
- RefClassWriter * pRCW = pModule->GetReflectionModule()->GetClassWriter();
- _ASSERTE(pRCW);
-
- ICeeFileGen * pCeeFileGen = pRCW->GetCeeFileGen();
- HCEEFILE ceeFile = pRCW->GetHCEEFILE();
- _ASSERTE(ceeFile && pCeeFileGen);
-
- IMetaDataEmit * pEmitNew = pRCW->GetOnDiskEmitter();
- _ASSERTE(pEmitNew);
-
- //Get the emitter and the importer
-
- if (pAssembly->IsDynamic() && isManifestFile)
- {
- // manifest is stored in this file
-
- // Allocate space for a strong name signature if an originator was supplied
- // (this doesn't strong name the assembly, but it makes it possible to do so
- // as a post processing step).
- if (pAssembly->IsStrongNamed())
- IfFailGo(pAssembly->AllocateStrongNameSignature(pCeeFileGen, ceeFile));
- }
-
- //Set the Output FileName
- IfFailGo( pCeeFileGen->SetOutputFileName(ceeFile, (LPWSTR)wszPeName) );
-
- //Set the Entry Point or throw the dll switch if we're creating a dll.
- if (entryPoint!=0)
- {
- IfFailGo( pCeeFileGen->SetEntryPoint(ceeFile, entryPoint) );
- }
-
- switch (fileKind)
- {
- case Dll:
- {
- IfFailGo( pCeeFileGen->SetDllSwitch(ceeFile, true) );
- break;
- }
- case WindowApplication:
- {
- // window application. Set the SubSystem
- IfFailGo( pCeeFileGen->SetSubsystem(ceeFile, IMAGE_SUBSYSTEM_WINDOWS_GUI, CEE_IMAGE_SUBSYSTEM_MAJOR_VERSION, CEE_IMAGE_SUBSYSTEM_MINOR_VERSION) );
- break;
- }
- case ConsoleApplication:
- {
- // Console application. Set the SubSystem
- IfFailGo( pCeeFileGen->SetSubsystem(ceeFile, IMAGE_SUBSYSTEM_WINDOWS_CUI, CEE_IMAGE_SUBSYSTEM_MAJOR_VERSION, CEE_IMAGE_SUBSYSTEM_MINOR_VERSION) );
- break;
- }
- default:
- {
- _ASSERTE(!"Unknown file kind!");
- break;
- }
- }
-
- IfFailGo( pCeeFileGen->GetIlSection(ceeFile, &pILSection) );
- IfFailGo( pEmitNew->GetSaveSize(cssAccurate, &metaDataSize) );
- IfFailGo( pCeeFileGen->GetSectionBlock(pILSection, metaDataSize, sizeof(DWORD), (void**) &metaData) );
- IfFailGo( pCeeFileGen->GetSectionDataLen(pILSection, &metaDataOffset) );
- metaDataOffset -= metaDataSize;
-
- // get the unmanaged writer.
- pWriter = pModule->GetReflectionModule()->GetISymUnmanagedWriter();
- IfFailGo( EmitDebugInfoBegin(pModule, pCeeFileGen, ceeFile, pILSection, wszPeName, pWriter) );
-
- if (pAssembly->IsDynamic() && pRCW->m_ulResourceSize)
- {
- // There are manifest in this file
-
- IfFailGo( pCeeFileGen->GetMethodRVA(ceeFile, 0, &newMethRVA) );
-
- // Point to manifest resource
- IfFailGo( pCeeFileGen->SetManifestEntry( ceeFile, pRCW->m_ulResourceSize, newMethRVA ) );
- }
-
- IfFailGo( pCeeFileGen->LinkCeeFile(ceeFile) );
-
- // Get the import interface from the new Emit interface.
- IfFailGo( pEmitNew->QueryInterface(IID_IMetaDataImport, (void **)&pImportNew));
-
-
- //Enumerate the TypeDefs and update method RVAs.
- while ((hr = pImportNew->EnumTypeDefs( &hTypeDefs, &td, 1, &count)) == S_OK)
- {
- UpdateMethodRVAs(pEmitNew, pImportNew, pCeeFileGen, ceeFile, td, pModule->GetReflectionModule()->m_sdataSection);
- }
-
- if (hTypeDefs)
- {
- pImportNew->CloseEnum(hTypeDefs);
- }
- hTypeDefs=0;
-
- //Update Global Methods.
- UpdateMethodRVAs(pEmitNew, pImportNew, pCeeFileGen, ceeFile, 0, pModule->GetReflectionModule()->m_sdataSection);
-
-
- //Emit the MetaData
- // IfFailGo( pCeeFileGen->EmitMetaDataEx(ceeFile, pEmitNew));
- IfFailGo( pCeeFileGen->EmitMetaDataAt(ceeFile, pEmitNew, pILSection, metaDataOffset, metaData, metaDataSize) );
-
- // finish the debugging info emitting after the metadata save so that token remap will be caught correctly
- IfFailGo( EmitDebugInfoEnd(pModule, pCeeFileGen, ceeFile, pILSection, wszPeName, pWriter) );
-
- //Generate the CeeFile
- IfFailGo(pCeeFileGen->GenerateCeeFile(ceeFile) );
-
- // Strong name sign the resulting assembly if required.
- if (pAssembly->IsDynamic() && isManifestFile && pAssembly->IsStrongNamed())
- IfFailGo(pAssembly->SignWithStrongName((LPWSTR)wszPeName));
-
-ErrExit:
-
- pRCW->SetOnDiskEmitter(NULL);
-
- //Release the interfaces. This should free some of the associated resources.
- if (pImportNew)
- pImportNew->Release();
-
- //Release our interfaces if we allocated them to begin with
- pRCW->DestroyCeeFileGen();
-
- //Check all file IO errors. If so, throw IOException. Otherwise, just throw the hr.
- if (FAILED(hr))
- {
- if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
- {
- if (IsWin32IOError(HRESULT_CODE(hr)))
- {
- SString hrMessage;
- GenerateTopLevelHRExceptionMessage(hr, hrMessage);
- COMPlusThrowHR(COR_E_IO, IDS_EE_GENERIC, hrMessage.GetUnicode());
- }
- else
- {
- COMPlusThrowHR(hr);
- }
- }
- COMPlusThrowHR(hr);
- }
-
- END_QCALL;
-}
-
-#endif // FEATURE_CORECLR
//=============================EmitDebugInfoBegin============================*/
// Phase 1 of emit debugging directory and symbol file.
@@ -1592,152 +1296,6 @@ ErrExit:
}
-#ifndef FEATURE_CORECLR
-//==============================================================================
-// Define external file for native resource.
-//==============================================================================
-void QCALLTYPE COMDynamicWrite::DefineNativeResourceFile(QCall::ModuleHandle pModule, LPCWSTR pwzFileName, INT32 portableExecutableKind, INT32 imageFileMachine)
-{
- QCALL_CONTRACT;
-
- BEGIN_QCALL;
-
- RefClassWriter * pRCW = pModule->GetReflectionModule()->GetClassWriter();
- _ASSERTE(pRCW);
-
- DWORD peFlags = 0, corhFlags = 0;
- ManagedBitnessFlagsToUnmanagedBitnessFlags(portableExecutableKind, imageFileMachine, &peFlags, &corhFlags);
- IfFailThrow( pRCW->EnsureCeeFileGenCreated(corhFlags, peFlags) );
-
- ICeeFileGen * pCeeFileGen = pRCW->GetCeeFileGen();
- HCEEFILE ceeFile = pRCW->GetHCEEFILE();
- _ASSERTE(ceeFile && pCeeFileGen);
-
- // Set the resource file name.
- IfFailThrow( pCeeFileGen->SetResourceFileName(ceeFile, (LPWSTR)pwzFileName) );
-
- END_QCALL;
-} // void __stdcall COMDynamicWrite::DefineNativeResourceFile()
-
-//==============================================================================
-// Define array of bytes for native resource.
-//==============================================================================
-void QCALLTYPE COMDynamicWrite::DefineNativeResourceBytes(QCall::ModuleHandle pModule, LPCBYTE pbResource, INT32 cbResource, INT32 portableExecutableKind, INT32 imageFileMachine)
-{
- QCALL_CONTRACT;
-
- BEGIN_QCALL;
-
- RefClassWriter * pRCW = pModule->GetReflectionModule()->GetClassWriter();
- _ASSERTE(pRCW);
-
- DWORD peFlags = 0, corhFlags = 0;
- ManagedBitnessFlagsToUnmanagedBitnessFlags(portableExecutableKind, imageFileMachine, &peFlags, &corhFlags);
- IfFailThrow( pRCW->EnsureCeeFileGenCreated(corhFlags, peFlags) );
-
- ICeeFileGen * pCeeFileGen = pRCW->GetCeeFileGen();
- HCEEFILE ceeFile = pRCW->GetHCEEFILE();
- _ASSERTE(ceeFile && pCeeFileGen);
-
- // Set the resource stream.
- HCEESECTION ceeSection = NULL;
- IfFailThrow( pCeeFileGen->GetSectionCreate(ceeFile, ".rsrc", sdReadOnly, &ceeSection) );
-
- void * pvResource;
- IfFailThrow( pCeeFileGen->GetSectionBlock(ceeSection, cbResource, 1, &pvResource) );
- memcpy(pvResource, pbResource, cbResource);
-
- END_QCALL;
-} // void __stdcall COMDynamicWrite::DefineNativeResourceBytes()
-
-//=============================AddResource=====================================*/
-// ecall for adding embedded resource to this module
-//==============================================================================*/
-void QCALLTYPE COMDynamicWrite::AddResource(QCall::ModuleHandle pModule, LPCWSTR pName, LPCBYTE pResBytes, INT32 resByteCount, UINT32 uFileTk, UINT32 iAttribute, INT32 portableExecutableKind, INT32 imageFileMachine)
-{
- QCALL_CONTRACT;
-
- BEGIN_QCALL;
-
- RefClassWriter * pRCW = pModule->GetReflectionModule()->GetClassWriter();
- _ASSERTE(pRCW);
-
- DWORD peFlags = 0, corhFlags = 0;
- ManagedBitnessFlagsToUnmanagedBitnessFlags(portableExecutableKind, imageFileMachine, &peFlags, &corhFlags);
- IfFailThrow( pRCW->EnsureCeeFileGenCreated(corhFlags, peFlags) );
-
- Assembly * pAssembly = pModule->GetAssembly();
- _ASSERTE( pAssembly && pAssembly->IsDynamic() );
-
- ICeeFileGen * pCeeFileGen = pRCW->GetCeeFileGen();
- HCEEFILE ceeFile = pRCW->GetHCEEFILE();
- _ASSERTE(ceeFile && pCeeFileGen);
-
- IMetaDataEmit * pOnDiskEmit = pRCW->GetOnDiskEmitter();
-
- // First, put it into .rdata section. The only reason that we choose .rdata section at
- // this moment is because this is the first section on the PE file. We don't need to deal with
- // reloc. Actually, I don't know how to deal with the reloc with CeeFileGen given that the reloc
- // position is not in the same file!
-
- // Get the .rdata section
- HCEESECTION hSection;
- IfFailThrow( pCeeFileGen->GetRdataSection(ceeFile, &hSection) );
-
- // the current section data length is the RVA
- ULONG ulOffset;
- IfFailThrow( pCeeFileGen->GetSectionDataLen(hSection, &ulOffset) );
-
- // Allocate a block of space fromt he .rdata section
- BYTE * pbBuffer;
- IfFailThrow( pCeeFileGen->GetSectionBlock(
- hSection, // from .rdata section
- resByteCount + sizeof(DWORD), // number of bytes that we need
- 1, // alignment
- (void**) &pbBuffer) );
-
- // now copy over the resource
- memcpy( pbBuffer, &resByteCount, sizeof(DWORD) );
- memcpy( pbBuffer + sizeof(DWORD), pResBytes, resByteCount );
-
- // track the total resource size so far. The size is actually the offset into the section
- // after writing the resource out
- IfFailThrow( pCeeFileGen->GetSectionDataLen(hSection, &pRCW->m_ulResourceSize) );
-
- mdFile tkFile = RidFromToken(uFileTk) ? uFileTk : mdFileNil;
- mdManifestResource mr;
-
- if (tkFile != mdFileNil)
- {
- SafeComHolderPreemp<IMetaDataAssemblyEmit> pOnDiskAssemblyEmit;
-
- IfFailThrow( pOnDiskEmit->QueryInterface(IID_IMetaDataAssemblyEmit, (void **) &pOnDiskAssemblyEmit) );
-
- // The resource is stored in a file other than the manifest file
- IfFailThrow(pOnDiskAssemblyEmit->DefineManifestResource(
- pName,
- mdFileNil, // implementation -- should be file token of this module in the manifest
- ulOffset, // offset to this file -- need to be adjusted upon save
- iAttribute, // resource flag
- &mr)); // manifest resource token
- }
-
- // Add an entry into the ManifestResource table for this resource
- // The RVA is ulOffset
- SafeComHolderPreemp<IMetaDataAssemblyEmit> pAssemEmitter(pAssembly->GetOnDiskMDAssemblyEmitter());
- IfFailThrow(pAssemEmitter->DefineManifestResource(
- pName,
- tkFile, // implementation -- should be file token of this module in the manifest
- ulOffset, // offset to this file -- need to be adjusted upon save
- iAttribute, // resource flag
- &mr)); // manifest resource token
-
- pRCW->m_tkFile = tkFile;
-
- END_QCALL;
-}
-
-#endif // FEATURE_CORECLR
//============================AddDeclarativeSecurity============================*/
// Add a declarative security serialized blob and a security action code to a