File: x86_64-naked-fn-no-cet-prolog.rs

package info (click to toggle)
rustc 1.88.0%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 934,128 kB
  • sloc: xml: 158,127; python: 36,062; javascript: 19,855; sh: 19,700; cpp: 18,947; ansic: 12,993; asm: 4,792; makefile: 690; lisp: 29; perl: 29; ruby: 19; sql: 11
file content (24 lines) | stat: -rw-r--r-- 752 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//@ compile-flags: -C no-prepopulate-passes -Zcf-protection=full
//@ assembly-output: emit-asm
//@ needs-asm-support
//@ only-x86_64

#![crate_type = "lib"]

use std::arch::naked_asm;

// The problem at hand: Rust has adopted a fairly strict meaning for "naked functions",
// meaning "no prologue whatsoever, no, really, not one instruction."
// Unfortunately, x86's control-flow enforcement, specifically indirect branch protection,
// works by using an instruction for each possible landing site,
// and LLVM implements this via making sure of that.
#[no_mangle]
#[unsafe(naked)]
pub extern "sysv64" fn will_halt() -> ! {
    // CHECK-NOT: endbr{{32|64}}
    // CHECK: hlt
    naked_asm!("hlt")
}

// what about aarch64?
// "branch-protection"=false