From: ragmani Date: Thu, 20 Apr 2017 14:39:54 +0000 (+0900) Subject: [x86/Linux] fix a problem that stack was broken by changing stdcall to cdecl in case... X-Git-Tag: submit/tizen/20210909.063632~11030^2~7186 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3d1f379914de4776579416d5013cd7268a2e7180;p=platform%2Fupstream%2Fdotnet%2Fruntime.git [x86/Linux] fix a problem that stack was broken by changing stdcall to cdecl in case of readytorun. (dotnet/coreclr#11063) * [x86/Linux] fix a problem that stack was broken by changing stdcall to cdecl in case of readytorun. add DynamicHelperArgsStub and change jmp to call. * [x86/Linux] set cfi_def_cfa_offset of DynamicHelperArgsStub to 16. Commit migrated from https://github.com/dotnet/coreclr/commit/fcc25714169626c3c4a8b0e0057443e0e5fa83ab --- diff --git a/src/coreclr/src/vm/i386/asmhelpers.S b/src/coreclr/src/vm/i386/asmhelpers.S index 647442c..9bb4566 100644 --- a/src/coreclr/src/vm/i386/asmhelpers.S +++ b/src/coreclr/src/vm/i386/asmhelpers.S @@ -815,6 +815,14 @@ PATCH_LABEL ExternalMethodFixupPatchLabel NESTED_END ExternalMethodFixupStub, _TEXT #ifdef FEATURE_READYTORUN +NESTED_ENTRY DynamicHelperArgsStub, _TEXT, NoHandler + .cfi_def_cfa_offset 16 + CHECK_STACK_ALIGNMENT + call eax + add esp, 12 + ret +NESTED_END DynamicHelperArgsStub, _TEXT + // ========================================================================== NESTED_ENTRY DelayLoad_MethodCall, _TEXT, NoHandler STUB_PROLOG_2_HIDDEN_ARGS @@ -971,6 +979,7 @@ NESTED_ENTRY DelayLoad_Helper\suffix, _TEXT, NoHandler push eax // indirection cell address. push esi // pTransitionBlock + CHECK_STACK_ALIGNMENT call C_FUNC(DynamicHelperWorker) test eax,eax jnz LOCAL_LABEL(TailCallDelayLoad_Helper\suffix) diff --git a/src/coreclr/src/vm/i386/cgenx86.cpp b/src/coreclr/src/vm/i386/cgenx86.cpp index 4c83265..05cd476 100644 --- a/src/coreclr/src/vm/i386/cgenx86.cpp +++ b/src/coreclr/src/vm/i386/cgenx86.cpp @@ -1878,23 +1878,47 @@ PCODE DynamicHelpers::CreateReturnIndirConst(LoaderAllocator * pAllocator, TADDR END_DYNAMIC_HELPER_EMIT(); } +EXTERN_C VOID DynamicHelperArgsStub(); + PCODE DynamicHelpers::CreateHelperWithTwoArgs(LoaderAllocator * pAllocator, TADDR arg, PCODE target) { +#ifdef UNIX_X86_ABI + BEGIN_DYNAMIC_HELPER_EMIT(18); +#else BEGIN_DYNAMIC_HELPER_EMIT(12); +#endif +#ifdef UNIX_X86_ABI + // sub esp, 8 + *p++ = 0x83; + *p++ = 0xec; + *p++ = 0x8; +#else // pop eax *p++ = 0x58; +#endif // push arg *p++ = 0x68; *(INT32 *)p = arg; p += 4; +#ifdef UNIX_X86_ABI + // mov eax, target + *p++ = 0xB8; + *(INT32 *)p = target; + p += 4; +#else // push eax *p++ = 0x50; +#endif *p++ = X86_INSTR_JMP_REL32; // jmp rel32 +#ifdef UNIX_X86_ABI + *(INT32 *)p = rel32UsingJumpStub((INT32 *)p, (PCODE)DynamicHelperArgsStub); +#else *(INT32 *)p = rel32UsingJumpStub((INT32 *)p, target); +#endif p += 4; END_DYNAMIC_HELPER_EMIT(); @@ -1902,10 +1926,21 @@ PCODE DynamicHelpers::CreateHelperWithTwoArgs(LoaderAllocator * pAllocator, TADD PCODE DynamicHelpers::CreateHelperWithTwoArgs(LoaderAllocator * pAllocator, TADDR arg, TADDR arg2, PCODE target) { +#ifdef UNIX_X86_ABI + BEGIN_DYNAMIC_HELPER_EMIT(23); +#else BEGIN_DYNAMIC_HELPER_EMIT(17); +#endif +#ifdef UNIX_X86_ABI + // sub esp, 4 + *p++ = 0x83; + *p++ = 0xec; + *p++ = 0x4; +#else // pop eax *p++ = 0x58; +#endif // push arg *p++ = 0x68; @@ -1917,11 +1952,22 @@ PCODE DynamicHelpers::CreateHelperWithTwoArgs(LoaderAllocator * pAllocator, TADD *(INT32 *)p = arg2; p += 4; +#ifdef UNIX_X86_ABI + // mov eax, target + *p++ = 0xB8; + *(INT32 *)p = target; + p += 4; +#else // push eax *p++ = 0x50; +#endif *p++ = X86_INSTR_JMP_REL32; // jmp rel32 +#ifdef UNIX_X86_ABI + *(INT32 *)p = rel32UsingJumpStub((INT32 *)p, (PCODE)DynamicHelperArgsStub); +#else *(INT32 *)p = rel32UsingJumpStub((INT32 *)p, target); +#endif p += 4; END_DYNAMIC_HELPER_EMIT();