Skip to content

Commit a1792cf

Browse files
uweigandmichaelgsharp
authored andcommitted
s390x: Fix nonvolatile context restoration (dotnet#101854)
Fix s390x context restoration along the lines of dotnet#101709
1 parent 0c9be47 commit a1792cf

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/coreclr/pal/src/arch/s390x/context2.S

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,17 @@ LEAF_END RtlCaptureContext, _TEXT
6161

6262
LEAF_ENTRY RtlRestoreContext, _TEXT
6363

64+
// Set %r1 and %r0 to hold the target return address and stack pointer.
65+
// These will be installed only at the very end, to avoid potentially
66+
// clobbering the context structure on the local stack.
6467
lgr %r1, %r14
68+
lgr %r0, %r15
69+
tm CONTEXT_ContextFlags+3(%r2), CONTEXT_CONTROL
70+
je LOCAL_LABEL(Done_Restore_CONTEXT_CONTROL)
71+
// We do *not* attempt to restore the PSW mask here!
72+
lg %r1, CONTEXT_PSWAddr(%r2)
73+
lg %r0, CONTEXT_R15(%r2)
74+
LOCAL_LABEL(Done_Restore_CONTEXT_CONTROL):
6575

6676
tm CONTEXT_ContextFlags+3(%r2), CONTEXT_FLOATING_POINT
6777
je LOCAL_LABEL(Done_Restore_CONTEXT_FLOATING_POINT)
@@ -83,19 +93,13 @@ LEAF_ENTRY RtlRestoreContext, _TEXT
8393
ld %f15, CONTEXT_F15(%r2)
8494
LOCAL_LABEL(Done_Restore_CONTEXT_FLOATING_POINT):
8595

86-
tm CONTEXT_ContextFlags+3(%r2), CONTEXT_CONTROL
87-
je LOCAL_LABEL(Done_Restore_CONTEXT_CONTROL)
88-
// We do *not* attempt to restore the PSW mask here!
89-
lg %r1, CONTEXT_PSWAddr(%r2)
90-
lg %r15, CONTEXT_R15(%r2)
91-
LOCAL_LABEL(Done_Restore_CONTEXT_CONTROL):
92-
9396
tm CONTEXT_ContextFlags+3(%r2), CONTEXT_INTEGER
9497
je LOCAL_LABEL(Done_Restore_CONTEXT_INTEGER)
9598
// We do *not* restore %r0 and %r1 here!
9699
lmg %r2, %r14, CONTEXT_R2(%r2)
97100
LOCAL_LABEL(Done_Restore_CONTEXT_INTEGER):
98101

102+
lgr %r15, %r0
99103
br %r1
100104
LEAF_END RtlRestoreContext, _TEXT
101105

0 commit comments

Comments
 (0)