Skip to content

Commit

Permalink
fix: do not use rbx register in asm!()
Browse files Browse the repository at this point in the history
error: invalid register `rbx`: rbx is used internally by LLVM and
cannot be used as an operand for inline asm

See:
rust-lang/rust#84658 (comment)

and:
https://github.com/rust-lang/rust/pull/84658/files#diff-d7283132d97a993fad4e2d491ac883dbce4e17fe248cdf37fa3f9334e2a5a115
  • Loading branch information
haraldh committed May 3, 2021
1 parent 9e3617b commit 21db5cd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/attestation_types/ti.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ impl TargetInfo {
let mut report = core::mem::MaybeUninit::<report::Report>::uninit();

asm!(
"xchg {RBX}, rbx",
"enclu",
"mov rbx, {RBX}",

RBX = inout(reg) self => _,
in("rax") EREPORT,
in("rbx") self,
in("rcx") data.0.as_ptr(),
in("rdx") report.as_mut_ptr(),
);
Expand Down
3 changes: 2 additions & 1 deletion src/enclave/enclave.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ impl Thread {
let rax: i32;
unsafe {
asm!(
"push rbx", // save rbx
"push rbp", // save rbp
"mov rbp, rsp", // save rsp
"and rsp, ~0xf", // align to 16+0
Expand All @@ -203,6 +204,7 @@ impl Thread {

"mov rsp, rbp", // restore rsp
"pop rbp", // restore rbp
"pop rbx", // restore rbx

inout("rdi") usize::from(registers.rdi) => _,
inout("rsi") usize::from(registers.rsi) => _,
Expand All @@ -212,7 +214,6 @@ impl Thread {
inout("r9") usize::from(registers.r9) => _,
inout("r10") &mut run => _,
inout("r11") self.fnc => _,
lateout("rbx") _,
lateout("r12") _,
lateout("r13") _,
lateout("r14") _,
Expand Down

0 comments on commit 21db5cd

Please sign in to comment.