diff options
author | Kyungwoo Lee <kyulee@microsoft.com> | 2015-11-24 12:34:08 -0800 |
---|---|---|
committer | Kyungwoo Lee <kyulee@microsoft.com> | 2015-11-25 11:58:52 -0800 |
commit | 1b6658714821566dd9ab78dcf1fe96fcb0f8772a (patch) | |
tree | c27daab52b3dbadd9cdf7620cb7b94ffceb2d62b /src | |
parent | 6936820475b8c6b66de1807b0d123c195e18b868 (diff) | |
download | coreclr-1b6658714821566dd9ab78dcf1fe96fcb0f8772a.tar.gz coreclr-1b6658714821566dd9ab78dcf1fe96fcb0f8772a.tar.bz2 coreclr-1b6658714821566dd9ab78dcf1fe96fcb0f8772a.zip |
Enable ILDASM for Windows
This enables building ILDASM with Cmake for Windows.
This ILDASM now depends on CoreCLR targeting cross-platform and thus I dropped some features like GUI/PDB -- default output is console.
Metadata related APIs in CoreCLR are directly exported, and used in ILDASM:
MetaDataGetDispenser
GetMetaDataInternalInterface
GetMetaDataInternalInterfaceFromPublic
GetMetaDataPublicInterfaceFromInternal
The code path is diverged by a definition FEATURE_CORECLR.
There are still Window specific components. Among others, resource file/dll generation is the one that should be ported.
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/dlls/mscoree/mscorwks_ntdef.src | 11 | ||||
-rw-r--r-- | src/ildasm/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/ildasm/dasm.cpp | 131 | ||||
-rw-r--r-- | src/ildasm/dasm.rc | 8 | ||||
-rw-r--r-- | src/ildasm/dasm_pr.cpp | 2 | ||||
-rw-r--r-- | src/ildasm/dis.cpp | 6 | ||||
-rw-r--r-- | src/ildasm/dman.cpp | 16 | ||||
-rw-r--r-- | src/ildasm/exe/CMakeLists.txt | 58 | ||||
-rw-r--r-- | src/ildasm/gui.cpp | 5 | ||||
-rw-r--r-- | src/ildasm/rcdll/CMakeLists.txt | 27 | ||||
-rw-r--r-- | src/ildasm/resource.h | 12 | ||||
-rw-r--r-- | src/ildasm/windasm.cpp | 23 | ||||
-rw-r--r-- | src/inc/palclr_win.h | 9 | ||||
-rw-r--r-- | src/tools/metainfo/mdinfo.cpp | 4 |
15 files changed, 248 insertions, 69 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ded1a95bbc..31c37e5a39 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -51,6 +51,7 @@ add_subdirectory(dlls) add_subdirectory(ToolBox) add_subdirectory(tools) add_subdirectory(unwinder) +add_subdirectory(ildasm) if(WIN32) add_subdirectory(ipcman) diff --git a/src/dlls/mscoree/mscorwks_ntdef.src b/src/dlls/mscoree/mscorwks_ntdef.src index dcb68574a9..090e5b6e36 100644 --- a/src/dlls/mscoree/mscorwks_ntdef.src +++ b/src/dlls/mscoree/mscorwks_ntdef.src @@ -24,12 +24,11 @@ EXPORTS coreclr_initialize coreclr_shutdown -#ifdef FEATURE_PREJIT - ; MetaDataGetDispenser is needed for nidump. We want nidump to work on non-debug - ; builds, but we don't want the API to be public, so export it by ordinal. - ; This ordinal is hard-coded in tools\nidump\nidump.cpp. - MetaDataGetDispenser @3 noname private -#endif // FEATURE_PREJIT + ; il{d}asm + MetaDataGetDispenser + GetMetaDataInternalInterface + GetMetaDataInternalInterfaceFromPublic + GetMetaDataPublicInterfaceFromInternal #else //FEATURE_CORECLR diff --git a/src/ildasm/CMakeLists.txt b/src/ildasm/CMakeLists.txt new file mode 100644 index 0000000000..91ab76e066 --- /dev/null +++ b/src/ildasm/CMakeLists.txt @@ -0,0 +1,4 @@ +if (WIN32) + add_subdirectory(exe) + add_subdirectory(rcdll) +endif() diff --git a/src/ildasm/dasm.cpp b/src/ildasm/dasm.cpp index a9cb52e707..fc8f27e085 100644 --- a/src/ildasm/dasm.cpp +++ b/src/ildasm/dasm.cpp @@ -36,12 +36,12 @@ #include <corcompile.h> #endif +#ifndef FEATURE_CORECLR // Define also LegacyActivationShim::CoInitializeEE wrapper around CoInitializeEE #define LEGACY_ACTIVATION_SHIM_DEFINE_CoInitializeEE #include "LegacyActivationShim.h" #include "clrinternal.h" - - +#endif struct MIDescriptor { @@ -114,7 +114,7 @@ BOOL g_fProject = FALSE; // if .winmd file, transform to .NE extern BOOL g_fQuoteAllNames; // declared in formatType.cpp, init to FALSE BOOL g_fShowProgressBar = TRUE; -BOOL g_fForwardDecl=FALSE; +BOOL g_fForwardDecl=FALSE; char g_szAsmCodeIndent[MAX_MEMBER_LENGTH]; char g_szNamespace[MAX_MEMBER_LENGTH]; @@ -259,6 +259,7 @@ WCHAR* RstrW(unsigned id) wcscat_s(buff,cchBuff,L" */"); return buffer; } + char* RstrA(unsigned n, unsigned codepage) { static char buff[2048]; @@ -306,11 +307,14 @@ extern CQuickBytes * g_szBuf_JUMPPT; extern CQuickBytes * g_szBuf_UnquotedProperName; extern CQuickBytes * g_szBuf_ProperName; +#ifndef FEATURE_CORECLR // CLR internal hosting API ICLRRuntimeHostInternal *g_pCLRRuntimeHostInternal = NULL; +#endif BOOL Init() { +#ifndef FEATURE_CORECLR if (FAILED(CoInitialize(NULL))) { return FALSE; @@ -339,6 +343,7 @@ BOOL Init() { return FALSE; } +#endif g_szBuf_KEYWORD = new CQuickBytes(); g_szBuf_COMMENT = new CQuickBytes(); @@ -438,7 +443,9 @@ void Cleanup() void Uninit() { +#ifndef FEATURE_CORECLR GUIAddOpcode(NULL,NULL); +#endif if (g_pPtrTags != NULL) { @@ -495,6 +502,7 @@ void Uninit() SDELETE(g_szBuf_ProperName); } +#ifndef FEATURE_CORECLR if (g_pCLRRuntimeHostInternal != NULL) { g_pCLRRuntimeHostInternal->Release(); @@ -504,6 +512,7 @@ void Uninit() LegacyActivationShim::CoUninitializeEE(COUNINITEE_DEFAULT); LegacyActivationShim::CoUninitializeCor(); CoUninitialize(); +#endif } // Uninit HRESULT IsClassRefInScope(mdTypeRef classref) @@ -644,16 +653,16 @@ BOOL EnumClasses() BOOL fDumpTokens = g_fDumpTokens; g_fDumpTokens = FALSE; - WIN_PAL_CPP_TRY + PAL_CPP_TRY { if (strcmp(PrettyPrintClass(&out, g_cl_list[i], g_pImport), g_pszClassToDump) == 0) { g_tkClassToDump = g_cl_list[i]; } } - WIN_PAL_CPP_CATCH_ALL + PAL_CPP_CATCH_ALL { } - WIN_PAL_CPP_ENDTRY; + PAL_CPP_ENDTRY; g_fDumpTokens = fDumpTokens; } @@ -1345,15 +1354,15 @@ void DumpByteArray(__inout __nullterminated char* szString, const BYTE* pBlob, U printsz = FALSE; } bool bBreak = FALSE; - WIN_PAL_CPP_TRY { + PAL_CPP_TRY { byt = pBlob[j]; } - WIN_PAL_CPP_CATCH_ALL + PAL_CPP_CATCH_ALL { strcat_s(szString, SZSTRING_SIZE,ERRORMSG("INVALID DATA ADDRESS")); bBreak = TRUE; } - WIN_PAL_CPP_ENDTRY; + PAL_CPP_ENDTRY; if (bBreak) break; @@ -1638,10 +1647,17 @@ mdToken TypeRefToTypeDef(mdToken tk, IMDInternalImport *pIMDI, IMDInternalImport IUnknown *pUnk; if(FAILED(pIAMDI[0]->QueryInterface(IID_IUnknown, (void**)&pUnk))) goto AssignAndReturn; +#ifdef FEATURE_CORECLR + if (FAILED(GetMetaDataInternalInterfaceFromPublic( + pUnk, + IID_IMDInternalImport, + (LPVOID *)ppIMDInew))) +#else if (FAILED(g_pCLRRuntimeHostInternal->GetMetaDataInternalInterfaceFromPublic( pUnk, IID_IMDInternalImport, (LPVOID *)ppIMDInew))) +#endif { goto AssignAndReturn; } @@ -2697,11 +2713,11 @@ void DumpDefaultValue(mdToken tok, __inout __nullterminated char* szString, void case ELEMENT_TYPE_STRING: szptr+=sprintf_s(szptr,SZSTRING_REMAINING_SIZE(szptr)," = "); - WIN_PAL_CPP_TRY { + PAL_CPP_TRY { szptr = DumpUnicodeString(GUICookie,szString,(WCHAR*)MDDV.m_wzValue,MDDV.m_cbSize/sizeof(WCHAR)); - } WIN_PAL_CPP_CATCH_ALL { + } PAL_CPP_CATCH_ALL { strcat_s(szString, SZSTRING_SIZE,ERRORMSG("INVALID DATA ADDRESS")); - } WIN_PAL_CPP_ENDTRY; + } PAL_CPP_ENDTRY; break; case ELEMENT_TYPE_CLASS: @@ -2717,11 +2733,11 @@ void DumpDefaultValue(mdToken tok, __inout __nullterminated char* szString, void if(MDDV.m_wzValue) { szptr+=sprintf_s(szptr,SZSTRING_REMAINING_SIZE(szptr),"("); - WIN_PAL_CPP_TRY { + PAL_CPP_TRY { DumpByteArray(szString,(BYTE*)MDDV.m_wzValue,MDDV.m_cbSize,GUICookie); - } WIN_PAL_CPP_CATCH_ALL { + } PAL_CPP_CATCH_ALL { szptr += sprintf_s(szptr,SZSTRING_REMAINING_SIZE(szptr),ERRORMSG(" Invalid blob at 0x%08X)"), MDDV.m_wzValue); - } WIN_PAL_CPP_ENDTRY + } PAL_CPP_ENDTRY } else { @@ -3014,16 +3030,16 @@ BOOL DisassembleWrapper(IMDInternalImport *pImport, BYTE *ILHeader, BOOL fRet = FALSE; //char szString[4096]; - WIN_PAL_CPP_TRY + PAL_CPP_TRY { fRet = Disassemble(pImport, ILHeader, GUICookie, FuncToken, pszArgname, ulArgs); } - WIN_PAL_CPP_CATCH_ALL + PAL_CPP_CATCH_ALL { sprintf_s(szString,SZSTRING_SIZE,RstrUTF(IDS_E_DASMERR),g_szAsmCodeIndent); printLine(GUICookie, szString); } - WIN_PAL_CPP_ENDTRY + PAL_CPP_ENDTRY return fRet; } @@ -3432,7 +3448,7 @@ BOOL DumpMethod(mdToken FuncToken, const char *pszClassName, DWORD dwEntryPointT } bool bRet = FALSE; - WIN_PAL_CPP_TRY { + PAL_CPP_TRY { if((*pComSig & IMAGE_CEE_CS_CALLCONV_MASK) > IMAGE_CEE_CS_CALLCONV_VARARG) { sprintf_s(szString,SZSTRING_SIZE,"%sERROR: signature of method '%s' has invalid calling convention 0x%2.2X",g_szAsmCodeIndent,pszMemberName,*pComSig); @@ -3446,10 +3462,10 @@ BOOL DumpMethod(mdToken FuncToken, const char *pszClassName, DWORD dwEntryPointT DumpGenericPars(szString,FuncToken); //,NULL,FALSE); pszMemberSig = PrettyPrintSig(pComSig, cComSig, szString, &qbMemberSig, g_pImport,NULL); lDone: ; - } WIN_PAL_CPP_CATCH_ALL { + } PAL_CPP_CATCH_ALL { printError(GUICookie,"INVALID DATA ADDRESS"); bRet = TRUE; - } WIN_PAL_CPP_ENDTRY; + } PAL_CPP_ENDTRY; if (bRet) { @@ -3470,16 +3486,16 @@ lDone: ; // temporarily disable token dumping g_fDumpTokens = FALSE; - WIN_PAL_CPP_TRY + PAL_CPP_TRY { CQuickBytes qbTempSig; pszPlainSig = PrettyPrintSig(pComSig, cComSig, "", &qbTempSig, g_pImport, NULL); } - WIN_PAL_CPP_CATCH_ALL + PAL_CPP_CATCH_ALL { pszPlainSig = ""; } - WIN_PAL_CPP_ENDTRY; + PAL_CPP_ENDTRY; g_fDumpTokens = TRUE; } @@ -3919,14 +3935,14 @@ BOOL DumpField(mdToken FuncToken, const char *pszClassName,void *GUICookie, BOOL g_tkRefUser = FuncToken; bool bRet = FALSE; - WIN_PAL_CPP_TRY { + PAL_CPP_TRY { szStr = PrettyPrintSig(pComSig, cComSig, (DumpBody ? pszMemberName : ""), &qbMemberSig, g_pImport,NULL); } - WIN_PAL_CPP_CATCH_ALL + PAL_CPP_CATCH_ALL { printError(GUICookie,"INVALID ADDRESS IN FIELD SIGNATURE"); bRet = TRUE; - } WIN_PAL_CPP_ENDTRY; + } PAL_CPP_ENDTRY; if (bRet) return FALSE; @@ -3948,16 +3964,16 @@ BOOL DumpField(mdToken FuncToken, const char *pszClassName,void *GUICookie, BOOL g_fDumpTokens = FALSE; const char *pszPlainSig; - WIN_PAL_CPP_TRY + PAL_CPP_TRY { CQuickBytes qbTempSig; pszPlainSig = PrettyPrintSig(pComSig, cComSig, "", &qbTempSig, g_pImport, NULL); } - WIN_PAL_CPP_CATCH_ALL + PAL_CPP_CATCH_ALL { pszPlainSig = ""; } - WIN_PAL_CPP_ENDTRY; + PAL_CPP_ENDTRY; g_fDumpTokens = fDumpTokens; @@ -4859,7 +4875,9 @@ BOOL DumpClass(mdTypeDef cl, DWORD dwEntryPointToken, void* GUICookie, ULONG Wha if(WhatToDump & 4) { DumpMembers(cl, pszNamespace, pszClassName, dwClassAttrs, dwEntryPointToken,GUICookie); +#ifndef FEATURE_CORECLR if(!ProgressStep()) g_fAbortDisassembly = TRUE; +#endif } if(g_szAsmCodeIndent[0]) g_szAsmCodeIndent[strlen(g_szAsmCodeIndent)-2] = 0; @@ -4899,11 +4917,13 @@ void DumpGlobalMethods(DWORD dwEntryPointToken) if(DumpMethod(FuncToken, NULL, dwEntryPointToken, g_pFile, TRUE)&& (g_Mode == MODE_DUMP_CLASS_METHOD || g_Mode == MODE_DUMP_CLASS_METHOD_SIG)) break; +#ifndef FEATURE_CORECLR if(!ProgressStep()) { g_fAbortDisassembly = TRUE; break; } +#endif } g_pImport->EnumClose(&hEnumMethod); if(i) @@ -6468,14 +6488,14 @@ void DumpHexbytes(__inout __nullterminated char* szString,BYTE *pb, DWORD fromPt if(curPtr >= limPtr) pb = &zero; // at limPtr and after, pad with 0 else { - WIN_PAL_CPP_TRY + PAL_CPP_TRY { sz[k] = *pb; // check the ptr validity } - WIN_PAL_CPP_CATCH_ALL + PAL_CPP_CATCH_ALL { pb = &zero; - } WIN_PAL_CPP_ENDTRY; + } PAL_CPP_ENDTRY; } szptr+=sprintf_s(szptr,SZSTRING_REMAINING_SIZE(szptr)," %2.2X", *pb); if(isprint(*pb)) @@ -6688,11 +6708,11 @@ void DumpEATEntriesWrapper(void* GUICookie, IMAGE_NT_HEADERS32 *pNTHeader32, IMAGE_OPTIONAL_HEADER32 *pOptHeader32, IMAGE_NT_HEADERS64 *pNTHeader64, IMAGE_OPTIONAL_HEADER64 *pOptHeader64) { - WIN_PAL_CPP_TRY + PAL_CPP_TRY { DumpEATEntries(GUICookie, pNTHeader32, pOptHeader32, pNTHeader64, pOptHeader64); } - WIN_PAL_CPP_CATCH_ALL + PAL_CPP_CATCH_ALL { printError(GUICookie,"// ERROR READING EXPORT ADDRESS TABLE"); if (g_prEATableRef != NULL) @@ -6701,7 +6721,7 @@ void DumpEATEntriesWrapper(void* GUICookie, } g_nEATableRef = 0; } - WIN_PAL_CPP_ENDTRY + PAL_CPP_ENDTRY } void DumpVtable(void* GUICookie) @@ -6947,6 +6967,10 @@ void DumpMetaInfo(__in __nullterminated const WCHAR* pwzFileName, __in_opt __nul if(pch && (!_wcsicmp(pch+1,L"lib") || !_wcsicmp(pch+1,L"obj"))) { // This works only when all the rest does not // Init and run. +#ifdef FEATURE_CORECLR + if (MetaDataGetDispenser(CLSID_CorMetaDataDispenser, + IID_IMetaDataDispenserEx, (void **)&g_pDisp)) +#else if(SUCCEEDED(CoInitialize(0))) { if(SUCCEEDED(LegacyActivationShim::CoInitializeCor(0))) @@ -6954,6 +6978,7 @@ void DumpMetaInfo(__in __nullterminated const WCHAR* pwzFileName, __in_opt __nul if (SUCCEEDED(LegacyActivationShim::ClrCoCreateInstance( CLSID_CorMetaDataDispenser, NULL, CLSCTX_INPROC_SERVER, IID_IMetaDataDispenserEx, (void **) &g_pDisp))) +#endif { WCHAR *pwzObjFileName=NULL; if (pszObjFileName) @@ -6968,19 +6993,26 @@ void DumpMetaInfo(__in __nullterminated const WCHAR* pwzFileName, __in_opt __nul g_pDisp = NULL; if (pwzObjFileName) VDELETE(pwzObjFileName); } +#ifndef FEATURE_CORECLR LegacyActivationShim::CoUninitializeCor(); } CoUninitialize(); } +#endif } else { HRESULT hr = S_OK; if(g_pDisp == NULL) { +#ifdef FEATURE_CORECLR + hr = MetaDataGetDispenser(CLSID_CorMetaDataDispenser, + IID_IMetaDataDispenserEx, (void **)&g_pDisp); +#else hr = LegacyActivationShim::ClrCoCreateInstance( CLSID_CorMetaDataDispenser, NULL, CLSCTX_INPROC_SERVER, IID_IMetaDataDispenserEx, (void **) &g_pDisp); +#endif } if(SUCCEEDED(hr)) { @@ -7466,12 +7498,21 @@ BOOL DumpFile() } const DWORD openFlags = ofRead | (g_fProject ? 0 : ofNoTransform); +#ifdef FEATURE_CORECLR + if (FAILED(GetMetaDataInternalInterface( + (BYTE *)g_pMetaData, + g_cbMetaData, + openFlags, + IID_IMDInternalImport, + (LPVOID *)&g_pImport))) +#else if (FAILED(g_pCLRRuntimeHostInternal->GetMetaDataInternalInterface( (BYTE *)g_pMetaData, g_cbMetaData, openFlags, IID_IMDInternalImport, (LPVOID *)&g_pImport))) +#endif { if (g_fDumpHeader) DumpHeader(g_CORHeader, g_pFile); @@ -7480,7 +7521,11 @@ BOOL DumpFile() } TokenSigInit(g_pImport); +#ifdef FEATURE_CORECLR + if (FAILED(MetaDataGetDispenser(CLSID_CorMetaDataDispenser, IID_IMetaDataDispenser, (LPVOID*)&pMetaDataDispenser))) +#else if (FAILED(CoCreateInstance(CLSID_CorMetaDataDispenser, 0, CLSCTX_INPROC_SERVER, IID_IMetaDataDispenser, (LPVOID*)&pMetaDataDispenser))) +#endif { if (g_fDumpHeader) DumpHeader(g_CORHeader, g_pFile); @@ -7495,7 +7540,7 @@ BOOL DumpFile() goto exit; } - +#ifndef FEATURE_CORECLR // Get a symbol binder. ISymUnmanagedBinder *binder; HRESULT hr; @@ -7518,6 +7563,7 @@ BOOL DumpFile() if (FAILED(hr)) g_fShowSource = FALSE; +#endif if((g_uNCA = g_pImport->GetCountWithTokenKind(mdtCustomAttribute))) { @@ -7546,11 +7592,13 @@ DoneInitialization: } #endif +#ifndef FEATURE_CORECLR if (g_Mode & MODE_GUI) { GUIAddItemsToList(); } else +#endif { // Dump the CLR header info if requested. printLine(g_pFile,COMMENT((char*)0)); // start multiline comment @@ -7590,10 +7638,15 @@ DoneInitialization: ulNumGlobalFunc = g_pImport->EnumGetCount(&hEnumMethod); g_pImport->EnumClose(&hEnumMethod); } +#ifndef FEATURE_CORECLR if(g_fShowProgressBar) CreateProgressBar((LONG) (g_NumClasses + ulNumGlobalFunc)); +#endif + } +#ifndef FEATURE_CORECLR ProgressStep(); +#endif g_fAbortDisassembly = FALSE; //DumpVtable(g_pFile); DumpMscorlib(g_pFile); @@ -7666,7 +7719,9 @@ DoneInitialization: fSuccess = FALSE; goto CloseFileAndExit; } +#ifndef FEATURE_CORECLR ProgressStep(); +#endif #if (0) /* Third, dump GC/EH info about the native methods, using the IPMap */ @@ -7851,7 +7906,9 @@ CloseFileAndExit: fclose(g_pFile); g_pFile = NULL; } +#ifndef FEATURE_CORECLR DestroyProgressBar(); +#endif } exit: diff --git a/src/ildasm/dasm.rc b/src/ildasm/dasm.rc index a1619cff90..9de2a73b64 100644 --- a/src/ildasm/dasm.rc +++ b/src/ildasm/dasm.rc @@ -11,7 +11,9 @@ // // Generated from the TEXTINCLUDE 2 resource. // +#ifndef FEATURE_CORECLR #include "afxres.h" +#endif #include <winresrc.h> ///////////////////////////////////////////////////////////////////////////// @@ -23,8 +25,6 @@ #include <fxver.h> #include <fxver.rc> -#include <copyrightstring.rc> - ///////////////////////////////////////////////////////////////////////////// // English (U.S.) resources @@ -59,7 +59,7 @@ END #endif // APSTUDIO_INVOKED -#ifndef FEATURE_PAL +#if !defined(FEATURE_PAL) && !defined(FEATURE_CORECLR) ///////////////////////////////////////////////////////////////////////////// @@ -281,7 +281,7 @@ BEGIN END #endif // FX_VFT == VFT_DLL -#endif // !FEATURE_PAL +#endif // !defined(FEATURE_PAL) && !defined(FEATURE_CORECLR) #if FX_VFT == VFT_DLL STRINGTABLE DISCARDABLE diff --git a/src/ildasm/dasm_pr.cpp b/src/ildasm/dasm_pr.cpp index 23f9ae1d3f..1194f5222f 100644 --- a/src/ildasm/dasm_pr.cpp +++ b/src/ildasm/dasm_pr.cpp @@ -5,6 +5,7 @@ #include "ildasmpch.h" +#ifndef FEATURE_CORECLR #include "resource.h" #include "formattype.h" @@ -272,3 +273,4 @@ void DestroyProgressBar() g_hwndCancel = NULL; g_ulCount = 0; } +#endif diff --git a/src/ildasm/dis.cpp b/src/ildasm/dis.cpp index 4356b6f40a..a5487360d2 100644 --- a/src/ildasm/dis.cpp +++ b/src/ildasm/dis.cpp @@ -134,9 +134,11 @@ char* AnsiToUtf(__in __nullterminated const char* sz) { return UnicodeToUtf(Ansi static void UnicodeToConsoleOrMsgBox(__in __nullterminated const WCHAR* wz) { +#ifndef FEATURE_CORECLR if (g_Mode & MODE_GUI) WszMessageBox(NULL,wz,RstrW(IDS_ERRORCAPTION),MB_OK|MB_ICONERROR|GetDasmMBRTLStyle()); else +#endif { //DWORD dw; //char* sz = UnicodeToAnsi(wz); @@ -154,9 +156,11 @@ static void UnicodeToFile(__in __nullterminated const WCHAR* wz, FILE* pF) } static void ToGUIOrFile(__in __nullterminated const char* sz, void* GUICookie) { +#ifndef FEATURE_CORECLR if (g_Mode & MODE_GUI) GUIAddOpcode(sz, GUICookie); else +#endif { if(g_fDumpRTF) fprintf((FILE*)GUICookie,"%s\\line\n",sz); else fprintf((FILE*)GUICookie,"%s\n",sz); @@ -872,7 +876,7 @@ BOOL SourceLinesHelper(void *GUICookie, LineCodeDescr* pLCD, __out_ecount(nSize) sprintf_s(szString,SZSTRING_SIZE,RstrUTF(IDS_ERRORREOPENINGFILE),pLCD->FileToken); printError(GUICookie, szString); } - WIN_PAL_ENDTRY + PAL_ENDTRY return param.fRet; } diff --git a/src/ildasm/dman.cpp b/src/ildasm/dman.cpp index 917d3f467a..962a3a740b 100644 --- a/src/ildasm/dman.cpp +++ b/src/ildasm/dman.cpp @@ -940,8 +940,10 @@ void DumpManifestResources(void* GUICookie) else nManRes=0; } +#ifndef FEATURE_CORECLR // CLR internal hosting API extern ICLRRuntimeHostInternal *g_pCLRRuntimeHostInternal; +#endif IMetaDataAssemblyImport* GetAssemblyImport(void* GUICookie) { @@ -992,6 +994,19 @@ IMetaDataAssemblyImport* GetAssemblyImport(void* GUICookie) if(pdwSize && *pdwSize) { pbManifest += sizeof(DWORD); +#ifdef FEATURE_CORECLR + if (SUCCEEDED(hr = GetMetaDataInternalInterface( + pbManifest, + VAL32(*pdwSize), + ofRead, + IID_IMDInternalImport, + (LPVOID *)&pParam->pImport))) + { + if (FAILED(hr = GetMetaDataPublicInterfaceFromInternal( + pParam->pImport, + IID_IMetaDataAssemblyImport, + (LPVOID *)&pParam->pAssemblyImport))) +#else if (SUCCEEDED(hr = g_pCLRRuntimeHostInternal->GetMetaDataInternalInterface( pbManifest, VAL32(*pdwSize), @@ -1003,6 +1018,7 @@ IMetaDataAssemblyImport* GetAssemblyImport(void* GUICookie) pParam->pImport, IID_IMetaDataAssemblyImport, (LPVOID *)&pParam->pAssemblyImport))) +#endif { sprintf_s(szString,SZSTRING_SIZE,RstrUTF(IDS_E_MDAFROMMDI),hr); printLine(pParam->GUICookie,COMMENT(szString)); diff --git a/src/ildasm/exe/CMakeLists.txt b/src/ildasm/exe/CMakeLists.txt new file mode 100644 index 0000000000..0e912c200f --- /dev/null +++ b/src/ildasm/exe/CMakeLists.txt @@ -0,0 +1,58 @@ +project(ildasm) + +add_definitions(-DUNICODE) +add_definitions(-D_UNICODE) +add_definitions(-D_FEATURE_NO_HOST) +add_definitions(-D__ILDASM__) + +add_definitions(-DFEATURE_CORECLR) + +set(ILDASM_SOURCES + ../ceeload.cpp + ../dasm.cpp + ../dasm_formattype.cpp + ../dasm_mi.cpp + ../dasm_pr.cpp + ../dasm_sz.cpp + ../dis.cpp + ../dman.cpp + ../dres.cpp + ../gui.cpp + ../ildasmpch.cpp + ../windasm.cpp +) + +add_executable(ildasm + ${ILDASM_SOURCES} + ${ILDASM_RESOURCES} +) + +set(ILDASM_LINK_LIBRARIES + utilcodestaticnohost + mdhotdata_full + corguids + coreclr +) + +if(CLR_CMAKE_PLATFORM_UNIX) + # TODO + target_link_libraries(ildasm + mscorrc_debug + coreclrpal + palrt + ) +else() + target_link_libraries(ildasm + ${ILDASM_LINK_LIBRARIES} + msvcrt + ole32 + oleaut32 + shell32 + ) + + # We will generate PDB only for the debug configuration + install (FILES ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/ildasm.pdb DESTINATION PDB) + +endif(CLR_CMAKE_PLATFORM_UNIX) + +install (TARGETS ildasm DESTINATION .) diff --git a/src/ildasm/gui.cpp b/src/ildasm/gui.cpp index 14131a83a3..2d2e491881 100644 --- a/src/ildasm/gui.cpp +++ b/src/ildasm/gui.cpp @@ -5,6 +5,7 @@ #include "ildasmpch.h" +#ifndef FEATURE_CORECLR #include "debugmacros.h" #include "corpriv.h" #include "ceeload.h" @@ -41,7 +42,7 @@ ULONG InGlobalBuffer; // Global HINSTANCE // extern HINSTANCE g_hInstance; -HINSTANCE g_hResources; +extern HINSTANCE g_hResources; // // Main window @@ -4010,4 +4011,4 @@ void DumpTreeItem(HTREEITEM hSelf, FILE* pFile, __inout __nullterminated WCHAR* printLineW(pFile,szIndent); } } - +#endif diff --git a/src/ildasm/rcdll/CMakeLists.txt b/src/ildasm/rcdll/CMakeLists.txt new file mode 100644 index 0000000000..8eea5672e1 --- /dev/null +++ b/src/ildasm/rcdll/CMakeLists.txt @@ -0,0 +1,27 @@ +project(ildasmrc) + +add_definitions(-DUNICODE) +add_definitions(-D_UNICODE) +add_definitions(-D_FEATURE_NO_HOST) +add_definitions(-D__ILDASM__) + +add_definitions(-DFEATURE_CORECLR) +add_definitions(-DFX_VFT=VFT_DLL) + +set(ILDASM_RESOURCES + ../dasm.rc +) + +add_library(ildasmrc + SHARED + ${ILDASM_RESOURCES} +) + +target_link_libraries(ildasmrc + msvcrt +) + +# We will generate PDB only for the debug configuration +install (FILES ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/ildasmrc.pdb DESTINATION PDB) + +install (TARGETS ildasmrc DESTINATION .) diff --git a/src/ildasm/resource.h b/src/ildasm/resource.h index bf993b6dcf..1b976b35bb 100644 --- a/src/ildasm/resource.h +++ b/src/ildasm/resource.h @@ -1,15 +1,13 @@ -// ==++== -// -// Copyright (c) Microsoft Corporation. All rights reserved. -// -// ==--== +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + //{{NO_DEPENDENCIES}} // Microsoft Developer Studio generated include file. // Used by dasm.rc // -#include <copyrightstring.h> - #define IDS_FILE 1 #define IDS_VIEW 2 #define IDS_HELP 3 diff --git a/src/ildasm/windasm.cpp b/src/ildasm/windasm.cpp index 43732f939d..e5c78333ee 100644 --- a/src/ildasm/windasm.cpp +++ b/src/ildasm/windasm.cpp @@ -49,7 +49,6 @@ extern BOOL g_fInsertSourceLines; extern BOOL g_fTryInCode; extern BOOL g_fQuoteAllNames; extern BOOL g_fShowProgressBar; -extern HINSTANCE g_hResources; extern BOOL g_fTDC; extern BOOL g_fShowCA; extern BOOL g_fCAVerbal; @@ -90,6 +89,7 @@ extern BOOL g_fUseProperName; extern BOOL g_fDumpMetaInfo; extern ULONG g_ulMetaInfoFilter; HINSTANCE g_hInstance; +HINSTANCE g_hResources; HANDLE hConsoleOut=NULL; HANDLE hConsoleErr=NULL; // These are implemented in DASM.CPP: @@ -109,8 +109,9 @@ BOOL IsGuiILOnly() void PrintLogo() { printf("Microsoft (R) .NET Framework IL Disassembler. Version " VER_FILEVERSION_STR); - printf("\n%S\n\n", RstrW(IDS_LEGALCOPYRIGHT_LOGO)); + printf("\n%S\n\n", VER_LEGALCOPYRIGHT_LOGO_STR_L); } + void SyntaxCon() { DWORD l; @@ -160,7 +161,7 @@ void GetInputFileFullPath() WszMultiByteToWideChar(g_uConsoleCP, 0, g_szInputFile, -1, wzArg, len); // Get the full path - len = GetFullPathName(wzArg, MAX_PATH, g_wszFullInputFile, NULL); + len = WszGetFullPathName(wzArg, MAX_PATH, g_wszFullInputFile, NULL); VDELETE(wzArg); } @@ -216,7 +217,11 @@ int ProcessOneArg(__in __nullterminated char* szArg, __out char** ppszObjFileNam } else if (_stricmp(szOpt, "sou") == 0) { +#ifdef FEATURE_CORECLR + printf("Warning: 'SOURCE' option is ignored for ildasm on CoreCLR.\n"); +#else g_fShowSource = TRUE; +#endif } else if (_stricmp(szOpt, "lin") == 0) { @@ -530,10 +535,14 @@ int ParseCmdLineA(__in __nullterminated char* szCmdLine, __out char** ppszObjFil return ret; } +#ifdef FEATURE_CORECLR +int __cdecl main(int nCmdShow, char* lpCmdLine[]) +#else int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, __in LPSTR lpCmdLine, int nCmdShow) +#endif { // ildasm does not need to be SO-robust. SO_NOT_MAINLINE_FUNCTION; @@ -551,8 +560,10 @@ int APIENTRY WinMain(HINSTANCE hInstance, g_fUseProperName = TRUE; +#ifndef FEATURE_CORECLR g_hInstance = hInstance; g_Mode = MODE_GUI; +#endif g_pszClassToDump[0]=0; g_pszMethodToDump[0]=0; g_pszSigToDump[0]=0; @@ -632,6 +643,9 @@ int APIENTRY WinMain(HINSTANCE hInstance, } else // if GUI ordered, restart as WinApp { +#ifdef FEATURE_CORECLR + _ASSERTE(!"GUI is not supported for ildasm on CoreCLR."); +#else PROCESS_INFORMATION pi; STARTUPINFO si; memset(&pi, 0, sizeof(PROCESS_INFORMATION) ); @@ -658,8 +672,10 @@ int APIENTRY WinMain(HINSTANCE hInstance, exit(1); } exit(0); +#endif } } +#ifndef FEATURE_CORECLR else //Second pass: WinApp { g_uCodePage = CP_UTF8; @@ -693,6 +709,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, Uninit(); return 0 ; } +#endif return 0; } diff --git a/src/inc/palclr_win.h b/src/inc/palclr_win.h index 723b2d81fd..49571d810e 100644 --- a/src/inc/palclr_win.h +++ b/src/inc/palclr_win.h @@ -144,15 +144,6 @@ } \ } -#define WIN_PAL_CPP_TRY try -#define WIN_PAL_CPP_ENDTRY -#define WIN_PAL_CPP_THROW(type, obj) throw obj; -#define WIN_PAL_CPP_RETHROW throw; -#define WIN_PAL_CPP_CATCH_EXCEPTION(obj) catch (Exception * obj) -#define WIN_PAL_CPP_CATCH_DERIVED(type, obj) catch (type * obj) -#define WIN_PAL_CPP_CATCH_ALL catch (...) -#define WIN_PAL_CPP_CATCH_EXCEPTION_NOARG catch (Exception *) - #endif // !PAL_WIN_SEH diff --git a/src/tools/metainfo/mdinfo.cpp b/src/tools/metainfo/mdinfo.cpp index b0db3591b9..334628bc2e 100644 --- a/src/tools/metainfo/mdinfo.cpp +++ b/src/tools/metainfo/mdinfo.cpp @@ -23,7 +23,9 @@ #define LEGACY_ACTIVATION_SHIM_LOAD_LIBRARY WszLoadLibrary #define LEGACY_ACTIVATION_SHIM_DEFINE_CoInitializeEE +#ifndef FEATURE_CORECLR #include "LegacyActivationShim.h" +#endif #define ENUM_BUFFER_SIZE 10 #define TAB_SIZE 8 @@ -754,10 +756,12 @@ void MDInfo::Error(const char* szError, HRESULT hr) pIErr->Release(); } +#ifndef FEATURE_CORECLR LegacyActivationShim::CoUninitializeCor(); #ifndef FEATURE_PAL CoUninitialize(); #endif +#endif exit(hr); } // void MDInfo::Error() |