Skip to content

Prefer asm! in std - all in sgx module #77292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions library/std/src/sys/sgx/abi/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,15 @@ extern "C" {
#[inline(always)]
#[unstable(feature = "sgx_platform", issue = "56975")]
pub fn image_base() -> u64 {
let base;
unsafe { llvm_asm!("lea IMAGE_BASE(%rip),$0":"=r"(base)) };
let base: u64;
unsafe {
asm!(
"lea IMAGE_BASE(%rip), {}",
lateout(reg) base,
// NOTE(#76738): ATT syntax is used to support LLVM 8 and 9.
options(att_syntax, nostack, preserves_flags, nomem, pure),
)
};
base
}

Expand Down
29 changes: 15 additions & 14 deletions library/std/src/sys/sgx/ext/arch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ pub fn egetkey(request: &Align512<[u8; 512]>) -> Result<Align16<[u8; 16]>, u32>
let mut out = MaybeUninit::uninit();
let error;

llvm_asm!(
"enclu"
: "={eax}"(error)
: "{eax}"(ENCLU_EGETKEY),
"{rbx}"(request),
"{rcx}"(out.as_mut_ptr())
: "flags"
asm!(
"enclu",
inlateout("eax") ENCLU_EGETKEY => error,
in("rbx") request,
in("rcx") out.as_mut_ptr(),
// NOTE(#76738): ATT syntax is used to support LLVM 8 and 9.
options(att_syntax, nostack),
);

match error {
Expand All @@ -60,13 +60,14 @@ pub fn ereport(
unsafe {
let mut report = MaybeUninit::uninit();

llvm_asm!(
"enclu"
: /* no output registers */
: "{eax}"(ENCLU_EREPORT),
"{rbx}"(targetinfo),
"{rcx}"(reportdata),
"{rdx}"(report.as_mut_ptr())
asm!(
"enclu",
in("eax") ENCLU_EREPORT,
in("rbx") targetinfo,
in("rcx") reportdata,
in("rdx") report.as_mut_ptr(),
// NOTE(#76738): ATT syntax is used to support LLVM 8 and 9.
options(att_syntax, preserves_flags, nostack),
);

report.assume_init()
Expand Down