diff options
| author | seyko <seyko2@gmail.com> | 2015-04-10 15:17:22 +0300 |
|---|---|---|
| committer | seyko <seyko2@gmail.com> | 2015-04-10 15:17:22 +0300 |
| commit | 559675b90acec03b67ed3f2cece1940f00e44c49 (patch) | |
| tree | 3875745ba543b7b8bb8474d9b7910272fcf75b9d /lib/alloca86_64-bt.S | |
| parent | e92dc595cd10405b3ed14b2663affeb50b47e169 (diff) | |
| download | tinycc-559675b90acec03b67ed3f2cece1940f00e44c49.tar.gz tinycc-559675b90acec03b67ed3f2cece1940f00e44c49.tar.bz2 | |
a bounds checking code for the ARCH=x86_64
Diffstat (limited to 'lib/alloca86_64-bt.S')
| -rw-r--r-- | lib/alloca86_64-bt.S | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/lib/alloca86_64-bt.S b/lib/alloca86_64-bt.S new file mode 100644 index 0000000..ab8629d --- /dev/null +++ b/lib/alloca86_64-bt.S @@ -0,0 +1,60 @@ +/* ---------------------------------------------- */ +/* alloca86_64.S */ + +.globl __bound_alloca +__bound_alloca: + +#ifdef TCC_TARGET_PE + # bound checking is not implemented + pop %rdx + mov %rcx,%rax + add $15,%rax + and $-16,%rax + jz p3 + +p1: + cmp $4096,%rax + jbe p2 + test %rax,-4096(%rsp) + sub $4096,%rsp + sub $4096,%rax + jmp p1 +p2: + + sub %rax,%rsp + mov %rsp,%rax + add $32,%rax + +p3: + push %rdx + ret +#else + pop %rdx + mov %rdi,%rax + movl %rax,%rsi # size, a second parm to the __bound_new_region + + add $15,%rax + and $-16,%rax + jz p3 + + + sub %rax,%rsp + mov %rsp,%rdi # pointer, a first parm to the __bound_new_region + mov %rsp,%rax + + push %rdx + push %rax + call __bound_new_region + pop %rax + pop %rdx + +p3: + push %rdx + ret +#endif + +/* mark stack as nonexecutable */ +#if defined __ELF__ && defined __linux__ + .section .note.GNU-stack,"",@progbits +#endif +/* ---------------------------------------------- */ |
