forked from gramineproject/gramine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
These tests verify the process initialization state as described in section 3.4 of System V Application binary Interface for x86_64. They verify stack alignment, stack arguments, and values of rFLAGS, x87 Floating-Point Control Word, MXCSR Status Bits. Signed-off-by: Mariusz Zaborski <[email protected]>
- Loading branch information
Showing
18 changed files
with
325 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
if host_machine.cpu_family() == 'x86_64' | ||
subdir(host_machine.cpu_family()) | ||
endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/*.manifest | ||
/*.xml | ||
|
||
/build.ninja | ||
/.ninja_* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
; SPDX-License-Identifier: LGPL-3.0-or-later | ||
; Copyright (C) 2022 Intel Corporation | ||
; Mariusz Zaborski <[email protected]> | ||
|
||
; rdx contains a function pointer that the application should register with atexit. | ||
; Gramine sets rdx to NULL - it does not use this feature at all. | ||
|
||
extern test_exit | ||
global _start | ||
|
||
section .text | ||
|
||
_start: | ||
mov rdi, rdx | ||
jmp test_exit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* SPDX-License-Identifier: LGPL-3.0-or-later */ | ||
/* Copyright (C) 2022 Intel Corporation | ||
* Mariusz Zaborski <[email protected]> | ||
*/ | ||
|
||
/* | ||
* We have to add a function declaration to avoid warnings. | ||
* This function is used with NASM, so creating a header is pointless. | ||
*/ | ||
int test_str_neq(const char* orig, const char* new); | ||
|
||
int test_str_neq(const char* orig, const char* new) { | ||
if (orig == new) | ||
return 0; | ||
|
||
while (*orig && *orig == *new) { | ||
orig++; | ||
new++; | ||
} | ||
|
||
return *orig != *new; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
; SPDX-License-Identifier: LGPL-3.0-or-later | ||
; Copyright (C) 2022 Intel Corporation | ||
; Mariusz Zaborski <[email protected]> | ||
|
||
global test_exit | ||
|
||
%define __NR_exit 60 | ||
|
||
section .text | ||
|
||
test_exit: | ||
xor rax, rax | ||
test rdi, rdi | ||
setne al | ||
mov rdi, rax | ||
mov rax, __NR_exit | ||
syscall |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
; SPDX-License-Identifier: LGPL-3.0-or-later | ||
; Copyright (C) 2022 Intel Corporation | ||
; Mariusz Zaborski <[email protected]> | ||
|
||
; The x87 FPU Control Word register: | ||
; +--+--+--+--+--+--+--+--+--+--+--+--+--+ | ||
; | X| RC| PC| R| R|PM|UM|OM|ZM|DM|IM| | ||
; +--+--+--+--+--+--+--+--+--+--+--+--+--+ | ||
; The x87 FPU Control Word should be set as follow: | ||
; +--+--+--+--+--+--+--+--+--+--+--+--+--+ | ||
; | X| 0 0| 1 1| X| X| 1| 1| 1| 1| 1| 1| | ||
; +--+--+--+--+--+--+--+--+--+--+--+--+--+ | ||
|
||
extern test_exit | ||
global _start | ||
|
||
section .text | ||
|
||
_start: | ||
fstcw [rsp] | ||
|
||
mov ax, [rsp] | ||
mov rdi, rax | ||
and rdi, 0b0111100111111 | ||
xor rdi, 0b0001100111111 | ||
|
||
jmp test_exit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
loader.entrypoint = "file:{{ gramine.libos }}" | ||
libos.entrypoint = "{{ entrypoint }}" | ||
|
||
# We set the argv[0] to the name of the entrypoint. | ||
# This is crucial for stack tests as otherwise argv[0] contains an absolute path | ||
# to the binary, and tests become unreliable. | ||
loader.argv0_override = "{{ entrypoint }}" | ||
loader.insecure__use_cmdline_argv = true | ||
|
||
fs.mounts = [ | ||
{ path = "/lib", uri = "file:{{ gramine.runtimedir() }}" }, | ||
{ path = "/{{ entrypoint }}", uri = "file:{{ binary_dir }}/{{ entrypoint }}" }, | ||
] | ||
|
||
sgx.nonpie_binary = true | ||
sgx.debug = true | ||
sgx.thread_num = 4 | ||
|
||
sgx.trusted_files = [ | ||
"file:{{ gramine.libos }}", | ||
"file:{{ binary_dir }}/{{ entrypoint }}", | ||
"file:{{ gramine.runtimedir() }}/", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
common_lib = static_library('common_lib', | ||
'common.c', | ||
nasm_gen.process('exit.asm') | ||
) | ||
|
||
tests = { | ||
'atexit_func': {}, | ||
'fpu_control_word': {}, | ||
'mxcsr': {}, | ||
'rflags': {}, | ||
'stack': {}, | ||
'stack_arg': {}, | ||
} | ||
|
||
install_dir = join_paths(pkglibdir, 'tests', 'libos', 'entrypoint') | ||
|
||
foreach name, params : tests | ||
filename = '' | ||
if (params.get('type', 'asm') == 'asm') | ||
filename = nasm_gen.process('@[email protected]'.format(name)) | ||
else | ||
filename = '@[email protected]'.format(name) | ||
endif | ||
|
||
exe = executable(name, | ||
filename, | ||
|
||
link_with: [ | ||
params.get('link_with', [common_lib]), | ||
], | ||
|
||
link_args: params.get('link_args', ['-nostdlib', '-static']), | ||
|
||
install: true, | ||
install_dir: install_dir, | ||
) | ||
endforeach |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
; SPDX-License-Identifier: LGPL-3.0-or-later | ||
; Copyright (C) 2022 Intel Corporation | ||
; Mariusz Zaborski <[email protected]> | ||
|
||
; The MXCSR register: | ||
; +--+--+--+--+--+--+--+--+--+---+--+--+--+--+--+--+ | ||
; |FZ| RC|PM|UM|OM|ZM|DM|IM|DAZ|PE|UE|OE|ZE|DE|IE| | ||
; +--+--+--+--+--+--+--+--+--+---+--+--+--+--+--+--+ | ||
; The MXCSR should be set as follow: | ||
; +--+--+--+--+--+--+--+--+--+---+--+--+--+--+--+--+ | ||
; | 0| 0 0| 1| 1| 1| 1| 1| 1| 0| X| X| X| X| X| X| | ||
; +--+--+--+--+--+--+--+--+--+---+--+--+--+--+--+--+ | ||
|
||
extern test_exit | ||
|
||
global _start | ||
|
||
section .text | ||
|
||
_start: | ||
stmxcsr [rsp] | ||
|
||
mov edi, [rsp] | ||
and rdi, 0b1111111111000000 | ||
xor rdi, 0b0001111110000000 | ||
|
||
jmp test_exit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
; SPDX-License-Identifier: LGPL-3.0-or-later | ||
; Copyright (C) 2022 Intel Corporation | ||
; Mariusz Zaborski <[email protected]> | ||
|
||
; The rFlags should be cleared. | ||
; Verify OF, DF, SF, ZF, AF, PF, CF | ||
; The EFLAGS: | ||
; +--+--+--+--+--+--+--+--+--+--+--+--+ | ||
; |OF|DF|IF|TF|SF|ZF| 0|AF| 0|PF| 1|CF| | ||
; +--+--+--+--+--+--+--+--+--+--+--+--+ | ||
; Mask to get interesting bits: | ||
; +--+--+--+--+--+--+--+--+--+--+--+--+ | ||
; | 1| 1| 0| 0| 1| 1| 0| 1| 0| 1| 0| 1| | ||
; +--+--+--+--+--+--+--+--+--+--+--+--+ | ||
|
||
extern test_exit | ||
|
||
global _start | ||
|
||
section .text | ||
|
||
_start: | ||
pushfq | ||
pop rdi | ||
|
||
and rdi, 0b110011010101 | ||
|
||
jmp test_exit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
; SPDX-License-Identifier: LGPL-3.0-or-later | ||
; Copyright (C) 2022 Intel Corporation | ||
; Mariusz Zaborski <[email protected]> | ||
|
||
; "The end of the input argument area shall be aligned on a 16..." | ||
|
||
extern test_exit | ||
|
||
global _start | ||
|
||
section .text | ||
|
||
_start: | ||
xor rdi, rdi | ||
|
||
mov rax, rsp | ||
and rax, 0xF | ||
setne dil | ||
|
||
jmp test_exit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
; SPDX-License-Identifier: LGPL-3.0-or-later | ||
; Copyright (C) 2022 Intel Corporation | ||
; Mariusz Zaborski <[email protected]> | ||
|
||
; Verify argv which should be in rsp + 8. | ||
|
||
default rel | ||
|
||
extern test_exit | ||
extern test_str_neq | ||
|
||
global _start | ||
|
||
section .text | ||
|
||
_start: | ||
mov rdi, [rsp] ; Verify argc | ||
cmp rdi, 3 | ||
mov rdi, 1 | ||
jne test_exit | ||
|
||
lea rdi, [argv0] ; Verify argv[0] | ||
mov rsi, [rsp + 8 * 1] | ||
call test_str_neq | ||
mov rdi, rax | ||
cmp rdi, 1 | ||
je test_exit | ||
|
||
lea rdi, [argv1] ; Verify argv[1] | ||
mov rsi, [rsp + 8 * 2] | ||
call test_str_neq | ||
mov rdi, rax | ||
cmp rdi, 1 | ||
je test_exit | ||
|
||
lea rdi, [argv2] ; Verify argv[2] | ||
mov rsi, [rsp + 8 * 3] | ||
call test_str_neq | ||
mov rdi, rax | ||
cmp rdi, 1 | ||
je test_exit | ||
|
||
mov rdi, [rsp + 8 * 4] | ||
jmp test_exit | ||
|
||
section .data | ||
|
||
argv0 db "stack_arg", 0x00 | ||
argv1 db "foo", 0x00 | ||
argv2 db "bar", 0x00 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from graminelibos.regression import RegressionTestCase | ||
|
||
class TC_00_Entrypoint(RegressionTestCase): | ||
def test_000_atexit_func(self): | ||
self.run_binary(['atexit_func']) | ||
|
||
def test_000_fpu_control_word(self): | ||
self.run_binary(['fpu_control_word']) | ||
|
||
def test_000_rflags(self): | ||
self.run_binary(['rflags']) | ||
|
||
def test_000_mxcsr(self): | ||
self.run_binary(['mxcsr']) | ||
|
||
def test_000_stack(self): | ||
self.run_binary(['stack']) | ||
|
||
def test_000_arg(self): | ||
self.run_binary(['stack_arg', 'foo', 'bar']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
binary_dir = "@GRAMINE_PKGLIBDIR@/tests/libos/entrypoint" | ||
|
||
manifests = [ | ||
"atexit_func", | ||
"fpu_control_word", | ||
"mxcsr", | ||
"rflags", | ||
"stack", | ||
"stack_arg", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
subdir('abi') | ||
subdir('regression') | ||
subdir('fs') |