Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit fcc2571

Browse files
ragmanijanvorli
authored andcommitted
[x86/Linux] fix a problem that stack was broken by changing stdcall to cdecl in case of readytorun. (#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.
1 parent 1e33123 commit fcc2571

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

src/vm/i386/asmhelpers.S

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,14 @@ PATCH_LABEL ExternalMethodFixupPatchLabel
815815
NESTED_END ExternalMethodFixupStub, _TEXT
816816

817817
#ifdef FEATURE_READYTORUN
818+
NESTED_ENTRY DynamicHelperArgsStub, _TEXT, NoHandler
819+
.cfi_def_cfa_offset 16
820+
CHECK_STACK_ALIGNMENT
821+
call eax
822+
add esp, 12
823+
ret
824+
NESTED_END DynamicHelperArgsStub, _TEXT
825+
818826
// ==========================================================================
819827
NESTED_ENTRY DelayLoad_MethodCall, _TEXT, NoHandler
820828
STUB_PROLOG_2_HIDDEN_ARGS
@@ -971,6 +979,7 @@ NESTED_ENTRY DelayLoad_Helper\suffix, _TEXT, NoHandler
971979
push eax // indirection cell address.
972980
push esi // pTransitionBlock
973981

982+
CHECK_STACK_ALIGNMENT
974983
call C_FUNC(DynamicHelperWorker)
975984
test eax,eax
976985
jnz LOCAL_LABEL(TailCallDelayLoad_Helper\suffix)

src/vm/i386/cgenx86.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,34 +1878,69 @@ PCODE DynamicHelpers::CreateReturnIndirConst(LoaderAllocator * pAllocator, TADDR
18781878
END_DYNAMIC_HELPER_EMIT();
18791879
}
18801880

1881+
EXTERN_C VOID DynamicHelperArgsStub();
1882+
18811883
PCODE DynamicHelpers::CreateHelperWithTwoArgs(LoaderAllocator * pAllocator, TADDR arg, PCODE target)
18821884
{
1885+
#ifdef UNIX_X86_ABI
1886+
BEGIN_DYNAMIC_HELPER_EMIT(18);
1887+
#else
18831888
BEGIN_DYNAMIC_HELPER_EMIT(12);
1889+
#endif
18841890

1891+
#ifdef UNIX_X86_ABI
1892+
// sub esp, 8
1893+
*p++ = 0x83;
1894+
*p++ = 0xec;
1895+
*p++ = 0x8;
1896+
#else
18851897
// pop eax
18861898
*p++ = 0x58;
1899+
#endif
18871900

18881901
// push arg
18891902
*p++ = 0x68;
18901903
*(INT32 *)p = arg;
18911904
p += 4;
18921905

1906+
#ifdef UNIX_X86_ABI
1907+
// mov eax, target
1908+
*p++ = 0xB8;
1909+
*(INT32 *)p = target;
1910+
p += 4;
1911+
#else
18931912
// push eax
18941913
*p++ = 0x50;
1914+
#endif
18951915

18961916
*p++ = X86_INSTR_JMP_REL32; // jmp rel32
1917+
#ifdef UNIX_X86_ABI
1918+
*(INT32 *)p = rel32UsingJumpStub((INT32 *)p, (PCODE)DynamicHelperArgsStub);
1919+
#else
18971920
*(INT32 *)p = rel32UsingJumpStub((INT32 *)p, target);
1921+
#endif
18981922
p += 4;
18991923

19001924
END_DYNAMIC_HELPER_EMIT();
19011925
}
19021926

19031927
PCODE DynamicHelpers::CreateHelperWithTwoArgs(LoaderAllocator * pAllocator, TADDR arg, TADDR arg2, PCODE target)
19041928
{
1929+
#ifdef UNIX_X86_ABI
1930+
BEGIN_DYNAMIC_HELPER_EMIT(23);
1931+
#else
19051932
BEGIN_DYNAMIC_HELPER_EMIT(17);
1933+
#endif
19061934

1935+
#ifdef UNIX_X86_ABI
1936+
// sub esp, 4
1937+
*p++ = 0x83;
1938+
*p++ = 0xec;
1939+
*p++ = 0x4;
1940+
#else
19071941
// pop eax
19081942
*p++ = 0x58;
1943+
#endif
19091944

19101945
// push arg
19111946
*p++ = 0x68;
@@ -1917,11 +1952,22 @@ PCODE DynamicHelpers::CreateHelperWithTwoArgs(LoaderAllocator * pAllocator, TADD
19171952
*(INT32 *)p = arg2;
19181953
p += 4;
19191954

1955+
#ifdef UNIX_X86_ABI
1956+
// mov eax, target
1957+
*p++ = 0xB8;
1958+
*(INT32 *)p = target;
1959+
p += 4;
1960+
#else
19201961
// push eax
19211962
*p++ = 0x50;
1963+
#endif
19221964

19231965
*p++ = X86_INSTR_JMP_REL32; // jmp rel32
1966+
#ifdef UNIX_X86_ABI
1967+
*(INT32 *)p = rel32UsingJumpStub((INT32 *)p, (PCODE)DynamicHelperArgsStub);
1968+
#else
19241969
*(INT32 *)p = rel32UsingJumpStub((INT32 *)p, target);
1970+
#endif
19251971
p += 4;
19261972

19271973
END_DYNAMIC_HELPER_EMIT();

0 commit comments

Comments
 (0)