diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-06-26 16:47:03 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-06-26 16:47:03 +0000 |
commit | fd089990f76ec6392dbd0138ab874d90c632d2a4 (patch) | |
tree | 792c0fd3ba36e1cb85218b0c72df71427b168678 /compiler-rt/test/Unit/enable_execute_stack_test.c | |
parent | 455df54003677523ab702c564f52d2587a55733e (diff) | |
download | bcm5719-llvm-fd089990f76ec6392dbd0138ab874d90c632d2a4.tar.gz bcm5719-llvm-fd089990f76ec6392dbd0138ab874d90c632d2a4.zip |
Initial import of compiler-rt.
-
llvm-svn: 74292
Diffstat (limited to 'compiler-rt/test/Unit/enable_execute_stack_test.c')
-rw-r--r-- | compiler-rt/test/Unit/enable_execute_stack_test.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/compiler-rt/test/Unit/enable_execute_stack_test.c b/compiler-rt/test/Unit/enable_execute_stack_test.c new file mode 100644 index 00000000000..2e0a6c22783 --- /dev/null +++ b/compiler-rt/test/Unit/enable_execute_stack_test.c @@ -0,0 +1,57 @@ +//===-- enable_execute_stack_test.c - Test __enable_execute_stack ----------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + + +#include <stdio.h> +#include <string.h> +#include <stdint.h> +#include <sys/mman.h> + + + +extern void __clear_cache(void* start, void* end); +extern void __enable_execute_stack(void* addr); + +typedef int (*pfunc)(void); + +int func1() +{ + return 1; +} + +int func2() +{ + return 2; +} + + + + +int main() +{ + unsigned char execution_buffer[128]; + // mark stack page containing execution_buffer to be executable + __enable_execute_stack(execution_buffer); + + // verify you can copy and execute a function + memcpy(execution_buffer, &func1, 128); + __clear_cache(execution_buffer, &execution_buffer[128]); + pfunc f1 = (pfunc)execution_buffer; + if ( (*f1)() != 1 ) + return 1; + + // verify you can overwrite a function with another + memcpy(execution_buffer, &func2, 128); + __clear_cache(execution_buffer, &execution_buffer[128]); + pfunc f2 = (pfunc)execution_buffer; + if ( (*f2)() != 2 ) + return 1; + + return 0; +} |