mirror of
https://github.com/GaloisInc/macaw.git
synced 2024-12-26 23:52:48 +03:00
Add ret test
This commit is contained in:
parent
809e6e8ce2
commit
3e763cc7a1
1
x86/x86_tests/.gitignore
vendored
1
x86/x86_tests/.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
/test_btx
|
||||
/test_ret
|
||||
/test_ucomis
|
@ -1,14 +1,18 @@
|
||||
run : test_btx test_ucomis
|
||||
run : test_btx test_ucomis test_ret
|
||||
./test_btx
|
||||
./test_ucomis
|
||||
./test_ret
|
||||
|
||||
test_btx : test_btx.c btx.s utils.h
|
||||
clang -o test_btx test_btx.c btx.s
|
||||
|
||||
test_ucomis : test_ucomis.c
|
||||
test_ucomis : test_ucomis.c ucomis.s utils.h
|
||||
clang -o test_ucomis test_ucomis.c ucomis.s
|
||||
|
||||
test_ret : test_ret.c ret.s utils.h
|
||||
clang -o test_ret test_ret.c ret.s
|
||||
|
||||
clean :
|
||||
rm -rf test_btx test_ucomis
|
||||
rm -rf test_btx test_ucomis test_ret
|
||||
|
||||
.PHONY : run clean
|
||||
|
95
x86/x86_tests/ret.s
Normal file
95
x86/x86_tests/ret.s
Normal file
@ -0,0 +1,95 @@
|
||||
.intel_syntax noprefix
|
||||
.section __TEXT,__text
|
||||
|
||||
.global _ret_noimm
|
||||
.global _ret_noimm_ret
|
||||
_ret_noimm:
|
||||
// Save rsp to rbp
|
||||
push rbp
|
||||
mov rbp, rsp
|
||||
// Subtract 10 from rsp to have some space
|
||||
sub rsp,0x10
|
||||
// Call function for returning
|
||||
call _ret_noimm_tgt
|
||||
_ret_noimm_ret:
|
||||
// Store rsp post return in third argument
|
||||
mov [rdx], rsp
|
||||
// Restore rsp
|
||||
mov rsp, rbp
|
||||
pop rbp
|
||||
ret
|
||||
_ret_noimm_tgt:
|
||||
mov [rsi], rsp
|
||||
mov rcx, [rsp]
|
||||
mov [rdi], rcx
|
||||
ret
|
||||
|
||||
.global _ret_imm8
|
||||
.global _ret_imm8_ret
|
||||
_ret_imm8:
|
||||
// Save rsp to rbp
|
||||
push rbp
|
||||
mov rbp, rsp
|
||||
// Subtract 10 from rsp to have some space
|
||||
sub rsp,0x18
|
||||
// Call function for returning
|
||||
call _ret_imm8_tgt
|
||||
_ret_imm8_ret:
|
||||
// Store rsp post return in third argument
|
||||
mov [rdx], rsp
|
||||
// Restore rsp
|
||||
mov rsp, rbp
|
||||
pop rbp
|
||||
ret
|
||||
_ret_imm8_tgt:
|
||||
mov [rsi], rsp
|
||||
mov rcx, [rsp]
|
||||
mov [rdi], rcx
|
||||
ret 8
|
||||
|
||||
|
||||
.global _ret_imm8000
|
||||
.global _ret_imm8000_ret
|
||||
_ret_imm8000:
|
||||
// Save rsp to rbp
|
||||
push rbp
|
||||
mov rbp, rsp
|
||||
// Subtract 10 from rsp to have some space
|
||||
sub rsp,0x8000
|
||||
// Call function for returning
|
||||
call _ret_imm8000_tgt
|
||||
_ret_imm8000_ret:
|
||||
// Store rsp post return in third argument
|
||||
mov [rdx], rsp
|
||||
// Restore rsp
|
||||
mov rsp, rbp
|
||||
pop rbp
|
||||
ret
|
||||
_ret_imm8000_tgt:
|
||||
mov [rsi], rsp
|
||||
mov rcx, [rsp]
|
||||
mov [rdi], rcx
|
||||
ret 0x8000
|
||||
|
||||
.global _ret_imm10000
|
||||
.global _ret_imm10000_ret
|
||||
_ret_imm10000:
|
||||
// Save rsp to rbp
|
||||
push rbp
|
||||
mov rbp, rsp
|
||||
// Subtract 10 from rsp to have some space
|
||||
sub rsp,0x10000
|
||||
// Call function for returning
|
||||
call _ret_imm10000_tgt
|
||||
_ret_imm10000_ret:
|
||||
// Store rsp post return in third argument
|
||||
mov [rdx], rsp
|
||||
// Restore rsp
|
||||
mov rsp, rbp
|
||||
pop rbp
|
||||
ret
|
||||
_ret_imm10000_tgt:
|
||||
mov [rsi], rsp
|
||||
mov rcx, [rsp]
|
||||
mov [rdi], rcx
|
||||
ret 0x10000
|
46
x86/x86_tests/test_ret.c
Normal file
46
x86/x86_tests/test_ret.c
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
This file contains some functionality tests to assess properties of ret.
|
||||
*/
|
||||
#include<stdbool.h>
|
||||
#include<stdint.h>
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
#include<stdarg.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
void ret_noimm(uint64_t** ret, uint64_t* pre_rsp, uint64_t* post_rsp);
|
||||
extern uint64_t ret_noimm_ret;
|
||||
|
||||
void ret_imm8(uint64_t** ret, uint64_t* pre_rsp, uint64_t* post_rsp);
|
||||
extern uint64_t ret_imm8_ret;
|
||||
|
||||
void ret_imm8000(uint64_t** ret, uint64_t* pre_rsp, uint64_t* post_rsp);
|
||||
extern uint64_t ret_imm8000_ret;
|
||||
|
||||
void ret_imm10000(uint64_t** ret, uint64_t* pre_rsp, uint64_t* post_rsp);
|
||||
extern uint64_t ret_imm10000_ret;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
uint64_t* ret;
|
||||
uint64_t pre_rsp;
|
||||
uint64_t post_rsp;
|
||||
|
||||
ret_noimm(&ret, &pre_rsp, &post_rsp);
|
||||
my_assert(ret == &ret_noimm_ret, "ret_noimm: Unexpected return\n");
|
||||
my_assert(post_rsp - pre_rsp == 0x08, "ret_noimm: Unexpected stack delta\n");
|
||||
|
||||
ret_imm8(&ret, &pre_rsp, &post_rsp);
|
||||
my_assert(ret == &ret_imm8_ret, "ret_imm8: Unexpected return\n");
|
||||
my_assert(post_rsp - pre_rsp == 0x10, "ret_imm8: Unexpected stack delta\n");
|
||||
|
||||
ret_imm8000(&ret, &pre_rsp, &post_rsp);
|
||||
my_assert(ret == &ret_imm8000_ret, "ret_imm8000: Unexpected return\n");
|
||||
my_assert(post_rsp - pre_rsp == 0x8008, "ret_imm8000: Unexpected stack delta\n");
|
||||
|
||||
ret_imm10000(&ret, &pre_rsp, &post_rsp);
|
||||
my_assert(ret == &ret_imm10000_ret, "ret_imm10000: Unexpected return\n");
|
||||
my_assert(post_rsp - pre_rsp == 0x8, "ret_imm10000: Unexpected stack delta\n");
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user