Skip to content

Commit bdf81f5

Browse files
committed
test hardening C inline assembly code (cc crate)
1 parent 0526e75 commit bdf81f5

File tree

5 files changed

+33
-1
lines changed

5 files changed

+33
-1
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
CHECK: cc_plus_one_c_asm
2+
CHECK: lfence
3+
CHECK: lfence
4+
CHECK: lfence
5+
CHECK: lfence
6+
CHECK: lfence
7+
CHECK-NEXT: incl
8+
CHECK-NEXT: jmp
9+
CHECK-NEXT: shlq $0, (%rsp)
10+
CHECK-NEXT: lfence
11+
CHECK-NEXT: retq
12+
CHECK: popq
13+
CHECK-NEXT: popq [[REGISTER:%[a-z]+]]
14+
CHECK-NEXT: lfence
15+
CHECK-NEXT: jmpq *[[REGISTER]]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
fn main() {
22
cc::Build::new()
33
.file("foo.c")
4-
.compile("foo");
4+
.compile("foo_c");
55
}

src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/enclave/foo.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,17 @@
22
int cc_plus_one_c(int *arg) {
33
return *arg + 1;
44
}
5+
6+
int cc_plus_one_c_asm(int *arg) {
7+
int value = 0;
8+
9+
asm volatile ( " movl (%1), %0\n"
10+
" inc %0\n"
11+
" jmp 1f\n"
12+
" retq\n" // never executed, but a shortcut to determine how the assembler deals with `ret` instructions
13+
"1:\n"
14+
: "=r"(value)
15+
: "r"(arg) );
16+
17+
return value;
18+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
extern {
22
fn cc_plus_one_c(arg : &u32) -> u32;
3+
fn cc_plus_one_c_asm(arg : &u32) -> u32;
34
}
45

56
fn main() {
67
let value : u32 = 41;
78

89
unsafe{
910
println!("Answer to the Ultimate Question of Life, the Universe, and Everything: {}!", cc_plus_one_c(&value));
11+
println!("Answer to the Ultimate Question of Life, the Universe, and Everything: {}!", cc_plus_one_c_asm(&value));
1012
}
1113
}

src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/script.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ build
3939

4040
check "std::io::stdio::_print::h87f0c238421c45bc" print.checks
4141
check cc_plus_one_c cc_plus_one_c.checks
42+
check cc_plus_one_c_asm cc_plus_one_c_asm.checks

0 commit comments

Comments
 (0)