2009-10-29 08:27:08 +08:00
|
|
|
/* ===-- trampoline_setup_test.c - Test __trampoline_setup -----------------===
|
|
|
|
*
|
|
|
|
* The LLVM Compiler Infrastructure
|
|
|
|
*
|
2010-11-17 06:13:33 +08:00
|
|
|
* This file is dual licensed under the MIT and the University of Illinois Open
|
|
|
|
* Source Licenses. See LICENSE.TXT for details.
|
2009-10-29 08:27:08 +08:00
|
|
|
*
|
|
|
|
* ===----------------------------------------------------------------------===
|
|
|
|
*/
|
2009-06-27 00:47:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
|
2009-10-29 08:27:08 +08:00
|
|
|
/*
|
|
|
|
* Tests nested functions
|
|
|
|
* The ppc compiler generates a call to __trampoline_setup
|
|
|
|
* The i386 and x86_64 compilers generate a call to ___enable_execute_stack
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Note that, nested functions are not ISO C and are not supported in Clang.
|
|
|
|
*/
|
|
|
|
|
2010-01-18 14:48:06 +08:00
|
|
|
#if !defined(__clang__)
|
2009-06-27 00:47:03 +08:00
|
|
|
|
|
|
|
typedef int (*nested_func_t)(int x);
|
|
|
|
|
|
|
|
nested_func_t proc;
|
|
|
|
|
2010-01-18 14:48:06 +08:00
|
|
|
int main() {
|
2009-10-29 08:27:08 +08:00
|
|
|
/* Some locals */
|
2009-06-27 00:47:03 +08:00
|
|
|
int c = 10;
|
|
|
|
int d = 7;
|
|
|
|
|
2009-10-29 08:27:08 +08:00
|
|
|
/* Define a nested function: */
|
2009-06-27 00:47:03 +08:00
|
|
|
int bar(int x) { return x*5 + c*d; };
|
|
|
|
|
2009-10-29 08:27:08 +08:00
|
|
|
/* Assign global to point to nested function
|
|
|
|
* (really points to trampoline). */
|
2009-06-27 00:47:03 +08:00
|
|
|
proc = bar;
|
|
|
|
|
2009-10-29 08:27:08 +08:00
|
|
|
/* Invoke nested function: */
|
2009-06-27 00:47:03 +08:00
|
|
|
c = 4;
|
|
|
|
if ( (*proc)(3) != 43 )
|
|
|
|
return 1;
|
|
|
|
d = 5;
|
|
|
|
if ( (*proc)(4) != 40 )
|
|
|
|
return 1;
|
|
|
|
|
2009-10-29 08:27:08 +08:00
|
|
|
/* Success. */
|
2009-06-27 00:47:03 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2009-10-29 08:27:08 +08:00
|
|
|
|
2010-01-18 14:48:06 +08:00
|
|
|
#else
|
|
|
|
|
|
|
|
int main() {
|
2011-05-30 05:43:29 +08:00
|
|
|
printf("skipped\n");
|
|
|
|
return 0;
|
2010-01-18 14:48:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|