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

Commit 1a017d6

Browse files
committed
Fix RyuJIT/arm32 GS cookie check before JMP call
The GS cookie check was using r2/r3 registers, after they had been reloaded as outgoing argument registers for the JMP call, thus trashing them. Change the temp regs used to r12/lr, the only non-argument, non-callee-saved registers available on arm32. Partially fixes #14862
1 parent 97d9d59 commit 1a017d6

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/jit/codegencommon.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2647,7 +2647,7 @@ emitJumpKind CodeGen::genJumpKindForOper(genTreeOps cmp, CompareKind compareKind
26472647
#ifdef _TARGET_ARMARCH_
26482648
//------------------------------------------------------------------------
26492649
// genEmitGSCookieCheck: Generate code to check that the GS cookie
2650-
// wasn't thrashed by a buffer overrun. Coomon code for ARM32 and ARM64
2650+
// wasn't thrashed by a buffer overrun. Common code for ARM32 and ARM64.
26512651
//
26522652
void CodeGen::genEmitGSCookieCheck(bool pushReg)
26532653
{
@@ -2658,8 +2658,14 @@ void CodeGen::genEmitGSCookieCheck(bool pushReg)
26582658
if (!pushReg && (compiler->info.compRetType == TYP_REF))
26592659
gcInfo.gcRegGCrefSetCur |= RBM_INTRET;
26602660

2661-
regNumber regGSConst = REG_TMP_0;
2662-
regNumber regGSValue = REG_TMP_1;
2661+
// We need two temporary registers, to load the GS cookie values and compare them. We can't use
2662+
// any argument registers if 'pushReg' is true (meaning we have a JMP call). They should be
2663+
// callee-trash registers, which should not contain anything interesting at this point.
2664+
// We don't have any IR node representing this check, so LSRA can't communicate registers
2665+
// for us to use.
2666+
2667+
regNumber regGSConst = REG_GSCOOKIE_TMP_0;
2668+
regNumber regGSValue = REG_GSCOOKIE_TMP_1;
26632669

26642670
if (compiler->gsGlobalSecurityCookieAddr == nullptr)
26652671
{

src/jit/target.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,6 +1318,12 @@ typedef unsigned short regPairNoSmall; // arm: need 12 bits
13181318
#define REG_TMP_1 REG_R2
13191319
#define RBM_TMP_1 RBM_R2
13201320

1321+
#ifndef LEGACY_BACKEND
1322+
// Temporary registers used for the GS cookie check.
1323+
#define REG_GSCOOKIE_TMP_0 REG_R12
1324+
#define REG_GSCOOKIE_TMP_1 REG_LR
1325+
#endif // !LEGACY_BACKEND
1326+
13211327
// This is the first register pair in REG_TMP_ORDER
13221328
#define REG_PAIR_TMP REG_PAIR_R2R3
13231329
#define REG_PAIR_TMP_REVERSE REG_PAIR_R3R2
@@ -1638,6 +1644,10 @@ typedef unsigned short regPairNoSmall; // arm: need 12 bits
16381644
#define REG_TMP_1 REG_R10
16391645
#define RBM_TMP_1 RBM_R10
16401646

1647+
// Temporary registers used for the GS cookie check.
1648+
#define REG_GSCOOKIE_TMP_0 REG_R9
1649+
#define REG_GSCOOKIE_TMP_1 REG_R10
1650+
16411651
// register to hold shift amount; no special register is required on ARM64.
16421652
#define REG_SHIFT REG_NA
16431653
#define RBM_SHIFT RBM_ALLINT

0 commit comments

Comments
 (0)