Skip to content

Commit dbf2bdb

Browse files
Merge #336
336: Avoiding use of LLVM reserved register `rbx` r=jethrogb a=raoulstrackx LLVM reserves register `rbx` in inline assembly (issue: #335). This PR avoids the use of this register until [rust-lang issue 85056](rust-lang/rust#85056) is merged Co-authored-by: Raoul Strackx <raoul.strackx@fortanix.com>
2 parents 3341ce1 + 0cac62f commit dbf2bdb

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

enclave-runner/src/tcs.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,12 @@ pub(crate) fn coenter<T: Tcs>(
184184
} else {
185185
asm!("
186186
lea 1f(%rip), %rcx // set SGX AEP
187+
xchg {0}, %rbx
187188
1: enclu
189+
xchg %rbx, {0}
188190
",
191+
inout(reg) tcs.address() => _, // rbx is used internally by LLVM and cannot be used as an operand for inline asm (#84658)
189192
inout("eax") Enclu::EEnter as u32 => sgx_result,
190-
inout("rbx") tcs.address() => _,
191193
out("rcx") _,
192194
inout("rdx") p3,
193195
inout("rdi") p1,

enclave-runner/src/usercalls/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1226,7 +1226,14 @@ async fn trap_attached_debugger(tcs: usize, debug_buf: *const u8) {
12261226
// Synchronized
12271227
unsafe {
12281228
let old = signal::sigaction(signal::SIGTRAP, &sig_action).unwrap();
1229-
asm!("int3", in("rbx") tcs, in("r10") debug_buf, options(nomem, nostack, att_syntax));
1229+
asm!("
1230+
xchg %rbx, {0}
1231+
int3
1232+
xchg {0}, %rbx
1233+
",
1234+
in(reg) tcs, // rbx is used internally by LLVM and cannot be used as an operand for inline asm (#84658)
1235+
in("r10") debug_buf,
1236+
options(nomem, nostack, att_syntax));
12301237
signal::sigaction(signal::SIGTRAP, &old).unwrap();
12311238
}
12321239
}

0 commit comments

Comments
 (0)