Skip to content

Commit

Permalink
Adjust logic in cor.h, corhdr.h, corinfo.h, corjit.h and such so that…
Browse files Browse the repository at this point in the history
… they may be included without the PAL (dotnet#46055)

This was done via simple substitution of the standard sized integer types, and dealing with the fallout. It is tested by using the ICorJitInfo interface directly within the crossgen2 jitinterface thunk library.

Effort was made to use a minimum number of casts, as casts in such a large change are likely to be wrong somewhere.
- Exceptions are the use of casting to handle some calls to the existing internal metadata api and around use of char16_t.

In addition, a small amount of logic from the PAL headers were pulled into the proper header to allow compilation in the presence of some SAL annotation, and other small details.
  • Loading branch information
davidwrighton committed Feb 18, 2021
1 parent aa138f7 commit 4f3545e
Show file tree
Hide file tree
Showing 102 changed files with 1,970 additions and 1,865 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ void CompileResult::repAllocGCInfo(size_t* size, void** retval)
*retval = (void*)AllocGCInfo->GetBuffer(value.retval_offset);
}

void CompileResult::recCompileMethod(BYTE** nativeEntry, ULONG* nativeSizeOfCode, CorJitResult result)
void CompileResult::recCompileMethod(uint8_t** nativeEntry, uint32_t* nativeSizeOfCode, CorJitResult result)
{
if (CompileMethod == nullptr)
CompileMethod = new LightWeightMap<DWORD, Agnostic_CompileMethodResults>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class CompileResult
void dmpAllocGCInfo(DWORD key, const Agnostic_AllocGCInfo& value);
void repAllocGCInfo(size_t* size, void** retval);

void recCompileMethod(BYTE** nativeEntry, ULONG* nativeSizeOfCode, CorJitResult result);
void recCompileMethod(uint8_t** nativeEntry, uint32_t* nativeSizeOfCode, CorJitResult result);
void dmpCompileMethod(DWORD key, const Agnostic_CompileMethodResults& value);
void repCompileMethod(BYTE** nativeEntry, ULONG* nativeSizeOfCode, CorJitResult* result);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
// * For the 64 bit jit this is implemented by code:PreJit.compileMethod
//
// Note: Obfuscators that are hacking the JIT depend on this method having __stdcall calling convention
CorJitResult __stdcall compileMethod(ICorJitInfo* comp, /* IN */
struct CORINFO_METHOD_INFO* info, /* IN */
unsigned /* code:CorJitFlag */ flags, /* IN */
BYTE** nativeEntry, /* OUT */
ULONG* nativeSizeOfCode /* OUT */
);
CorJitResult compileMethod(ICorJitInfo* comp, /* IN */
struct CORINFO_METHOD_INFO* info, /* IN */
unsigned /* code:CorJitFlag */ flags, /* IN */
uint8_t** nativeEntry, /* OUT */
uint32_t* nativeSizeOfCode /* OUT */
);

// Do any appropriate work at process shutdown. Default impl is to do nothing.
void ProcessShutdownWork(ICorStaticInfo* info); /* {}; */
Expand Down
30 changes: 15 additions & 15 deletions src/coreclr/ToolBox/superpmi/superpmi-shared/methodcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ void MethodContext::repGetVars(CORINFO_METHOD_HANDLE ftn,
// Note - the jit will call freearray on the array we give back....
void MethodContext::recGetBoundaries(CORINFO_METHOD_HANDLE ftn,
unsigned int* cILOffsets,
DWORD** pILOffsets,
uint32_t** pILOffsets,
ICorDebugInfo::BoundaryTypes* implictBoundaries)
{
if (GetBoundaries == nullptr)
Expand Down Expand Up @@ -882,7 +882,7 @@ void MethodContext::dmpGetBoundaries(DWORDLONG key, const Agnostic_GetBoundaries
}
void MethodContext::repGetBoundaries(CORINFO_METHOD_HANDLE ftn,
unsigned int* cILOffsets,
DWORD** pILOffsets,
uint32_t** pILOffsets,
ICorDebugInfo::BoundaryTypes* implictBoundaries)
{
Agnostic_GetBoundaries value;
Expand All @@ -891,7 +891,7 @@ void MethodContext::repGetBoundaries(CORINFO_METHOD_HANDLE ftn,

*cILOffsets = (unsigned int)value.cILOffsets;
if (*cILOffsets > 0)
*pILOffsets = (DWORD*)GetBoundaries->GetBuffer(value.pILOffset_offset);
*pILOffsets = (uint32_t*)GetBoundaries->GetBuffer(value.pILOffset_offset);
*implictBoundaries = (ICorDebugInfo::BoundaryTypes)value.implicitBoundaries;

DEBUG_REP(dmpGetBoundaries(CastHandle(ftn), value));
Expand Down Expand Up @@ -1164,7 +1164,7 @@ LPCWSTR MethodContext::repGetJitTimeLogFilename()

void MethodContext::recCanInline(CORINFO_METHOD_HANDLE callerHnd,
CORINFO_METHOD_HANDLE calleeHnd,
DWORD* pRestrictions,
uint32_t* pRestrictions,
CorInfoInline response,
DWORD exceptionCode)
{
Expand Down Expand Up @@ -1196,7 +1196,7 @@ void MethodContext::dmpCanInline(DLDL key, const Agnostic_CanInline& value)
}
CorInfoInline MethodContext::repCanInline(CORINFO_METHOD_HANDLE callerHnd,
CORINFO_METHOD_HANDLE calleeHnd,
DWORD* pRestrictions,
uint32_t* pRestrictions,
DWORD* exceptionCode)
{
DLDL key;
Expand Down Expand Up @@ -4161,7 +4161,7 @@ const void* MethodContext::repGetInlinedCallFrameVptr(void** ppIndirection)
return (const void*)value.B;
}

void MethodContext::recGetAddrOfCaptureThreadGlobal(void** ppIndirection, LONG* result)
void MethodContext::recGetAddrOfCaptureThreadGlobal(void** ppIndirection, int32_t* result)
{
if (GetAddrOfCaptureThreadGlobal == nullptr)
GetAddrOfCaptureThreadGlobal = new LightWeightMap<DWORD, DLDL>();
Expand All @@ -4181,7 +4181,7 @@ void MethodContext::dmpGetAddrOfCaptureThreadGlobal(DWORD key, DLDL value)
{
printf("GetAddrOfCaptureThreadGlobal key %u, value ppi-%016llX res-%016llX", key, value.A, value.B);
}
LONG* MethodContext::repGetAddrOfCaptureThreadGlobal(void** ppIndirection)
int32_t* MethodContext::repGetAddrOfCaptureThreadGlobal(void** ppIndirection)
{
DLDL value;

Expand All @@ -4191,7 +4191,7 @@ LONG* MethodContext::repGetAddrOfCaptureThreadGlobal(void** ppIndirection)
LogDebug("Sparse - repGetAddrOfCaptureThreadGlobal returning nullptr and 0xCAFE0001");
if (ppIndirection != nullptr)
*ppIndirection = nullptr;
return (LONG*)(size_t)0xCAFE0001;
return (int32_t*)(size_t)0xCAFE0001;
#else
LogException(EXCEPTIONCODE_MC, "Didn't find anything for GetAddrOfCaptureThreadGlobal", "");
#endif
Expand All @@ -4201,7 +4201,7 @@ LONG* MethodContext::repGetAddrOfCaptureThreadGlobal(void** ppIndirection)
if (ppIndirection != nullptr)
*ppIndirection = (void*)value.A;
DEBUG_REP(dmpGetAddrOfCaptureThreadGlobal((DWORD)0, value));
return (LONG*)value.B;
return (int32_t*)value.B;
}

void MethodContext::recGetClassDomainID(CORINFO_CLASS_HANDLE cls, void** ppIndirection, unsigned result)
Expand Down Expand Up @@ -4586,7 +4586,7 @@ bool MethodContext::repIsValidStringRef(CORINFO_MODULE_HANDLE module, unsigned m
}


void MethodContext::recGetStringLiteral(CORINFO_MODULE_HANDLE module, unsigned metaTOK, int length, LPCWSTR result)
void MethodContext::recGetStringLiteral(CORINFO_MODULE_HANDLE module, unsigned metaTOK, int length, const char16_t* result)
{
if (GetStringLiteral == nullptr)
GetStringLiteral = new LightWeightMap<DLD, DD>();
Expand All @@ -4600,7 +4600,7 @@ void MethodContext::recGetStringLiteral(CORINFO_MODULE_HANDLE module, unsigned m

DWORD strBuf = (DWORD)-1;
if (result != nullptr)
strBuf = (DWORD)GetStringLiteral->AddBuffer((unsigned char*)result, (unsigned int)((wcslen(result) * 2) + 2));
strBuf = (DWORD)GetStringLiteral->AddBuffer((unsigned char*)result, (unsigned int)((wcslen((LPCWSTR)result) * 2) + 2));

DD value;
value.A = (DWORD)length;
Expand All @@ -4615,7 +4615,7 @@ void MethodContext::dmpGetStringLiteral(DLD key, DD value)
GetStringLiteral->GetBuffer(value.B), value.A);
}

LPCWSTR MethodContext::repGetStringLiteral(CORINFO_MODULE_HANDLE module, unsigned metaTOK, int* length)
const char16_t* MethodContext::repGetStringLiteral(CORINFO_MODULE_HANDLE module, unsigned metaTOK, int* length)
{
if (GetStringLiteral == nullptr)
{
Expand All @@ -4640,7 +4640,7 @@ LPCWSTR MethodContext::repGetStringLiteral(CORINFO_MODULE_HANDLE module, unsigne
{
DD result = GetStringLiteral->Get(key);
*length = (int)result.A;
return (LPCWSTR)GetStringLiteral->GetBuffer(itemIndex);
return (const char16_t*)GetStringLiteral->GetBuffer(itemIndex);
}
}

Expand Down Expand Up @@ -6187,7 +6187,7 @@ CORINFO_CLASS_HANDLE MethodContext::repGetTypeInstantiationArgument(CORINFO_CLAS
}

void MethodContext::recAppendClassName(
CORINFO_CLASS_HANDLE cls, bool fNamespace, bool fFullInst, bool fAssembly, const WCHAR* result)
CORINFO_CLASS_HANDLE cls, bool fNamespace, bool fFullInst, bool fAssembly, const char16_t* result)
{
if (AppendClassName == nullptr)
AppendClassName = new LightWeightMap<Agnostic_AppendClassName, DWORD>();
Expand All @@ -6202,7 +6202,7 @@ void MethodContext::recAppendClassName(

DWORD temp = (DWORD)-1;
if (result != nullptr)
temp = (DWORD)AppendClassName->AddBuffer((unsigned char*)result, (unsigned int)((wcslen(result) * 2) + 2));
temp = (DWORD)AppendClassName->AddBuffer((unsigned char*)result, (unsigned int)((wcslen((LPCWSTR)result) * 2) + 2));

AppendClassName->Add(key, (DWORD)temp);
DEBUG_REC(dmpAppendClassName(key, (DWORD)temp));
Expand Down
18 changes: 9 additions & 9 deletions src/coreclr/ToolBox/superpmi/superpmi-shared/methodcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ class MethodContext

void recGetBoundaries(CORINFO_METHOD_HANDLE ftn,
unsigned int* cILOffsets,
DWORD** pILOffsets,
uint32_t** pILOffsets,
ICorDebugInfo::BoundaryTypes* implictBoundaries);
void dmpGetBoundaries(DWORDLONG key, const Agnostic_GetBoundaries& value);
void repGetBoundaries(CORINFO_METHOD_HANDLE ftn,
unsigned int* cILOffsets,
DWORD** pILOffsets,
uint32_t** pILOffsets,
ICorDebugInfo::BoundaryTypes* implictBoundaries);

void recInitClass(CORINFO_FIELD_HANDLE field,
Expand Down Expand Up @@ -154,13 +154,13 @@ class MethodContext

void recCanInline(CORINFO_METHOD_HANDLE callerHnd,
CORINFO_METHOD_HANDLE calleeHnd,
DWORD* pRestrictions,
uint32_t* pRestrictions,
CorInfoInline response,
DWORD exceptionCode);
void dmpCanInline(DLDL key, const Agnostic_CanInline& value);
CorInfoInline repCanInline(CORINFO_METHOD_HANDLE callerHnd,
CORINFO_METHOD_HANDLE calleeHnd,
DWORD* pRestrictions,
uint32_t* pRestrictions,
DWORD* exceptionCode);

void recResolveToken(CORINFO_RESOLVED_TOKEN* pResolvedToken, DWORD exceptionCode);
Expand Down Expand Up @@ -509,9 +509,9 @@ class MethodContext
void dmpGetInlinedCallFrameVptr(DWORD key, DLDL value);
const void* repGetInlinedCallFrameVptr(void** ppIndirection);

void recGetAddrOfCaptureThreadGlobal(void** ppIndirection, LONG* result);
void recGetAddrOfCaptureThreadGlobal(void** ppIndirection, int32_t* result);
void dmpGetAddrOfCaptureThreadGlobal(DWORD key, DLDL value);
LONG* repGetAddrOfCaptureThreadGlobal(void** ppIndirection);
int32_t* repGetAddrOfCaptureThreadGlobal(void** ppIndirection);

void recGetClassDomainID(CORINFO_CLASS_HANDLE cls, void** ppIndirection, unsigned result);
void dmpGetClassDomainID(DWORDLONG key, DLD value);
Expand Down Expand Up @@ -567,9 +567,9 @@ class MethodContext
void dmpIsValidStringRef(DLD key, DWORD value);
bool repIsValidStringRef(CORINFO_MODULE_HANDLE module, unsigned metaTOK);

void recGetStringLiteral(CORINFO_MODULE_HANDLE module, unsigned metaTOK, int length, LPCWSTR result);
void recGetStringLiteral(CORINFO_MODULE_HANDLE module, unsigned metaTOK, int length, const char16_t* result);
void dmpGetStringLiteral(DLD key, DD value);
LPCWSTR repGetStringLiteral(CORINFO_MODULE_HANDLE module, unsigned metaTOK, int* length);
const char16_t* repGetStringLiteral(CORINFO_MODULE_HANDLE module, unsigned metaTOK, int* length);

void recGetHelperName(CorInfoHelpFunc funcNum, const char* result);
void dmpGetHelperName(DWORD key, DWORD value);
Expand Down Expand Up @@ -754,7 +754,7 @@ class MethodContext
CORINFO_CLASS_HANDLE repGetTypeInstantiationArgument(CORINFO_CLASS_HANDLE cls, unsigned index);

void recAppendClassName(
CORINFO_CLASS_HANDLE cls, bool fNamespace, bool fFullInst, bool fAssembly, const WCHAR* result);
CORINFO_CLASS_HANDLE cls, bool fNamespace, bool fFullInst, bool fAssembly, const char16_t* result);
void dmpAppendClassName(const Agnostic_AppendClassName& key, DWORD value);
const WCHAR* repAppendClassName(CORINFO_CLASS_HANDLE cls, bool fNamespace, bool fFullInst, bool fAssembly);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

#define fatMC // this is nice to have on so ildump works...

CorJitResult __stdcall interceptor_ICJC::compileMethod(ICorJitInfo* comp, /* IN */
struct CORINFO_METHOD_INFO* info, /* IN */
unsigned /* code:CorJitFlag */ flags, /* IN */
BYTE** nativeEntry, /* OUT */
ULONG* nativeSizeOfCode /* OUT */
)
CorJitResult interceptor_ICJC::compileMethod(ICorJitInfo* comp, /* IN */
struct CORINFO_METHOD_INFO* info, /* IN */
unsigned /* code:CorJitFlag */ flags, /* IN */
uint8_t** nativeEntry, /* OUT */
uint32_t* nativeSizeOfCode /* OUT */
)
{
interceptor_ICJI our_ICorJitInfo;
our_ICorJitInfo.original_ICorJitInfo = comp;
Expand Down
Loading

0 comments on commit 4f3545e

Please sign in to comment.