Mercurial > hg > CbC > CbC_examples
changeset 17:a4f44624a253
asm longjmp (can return correct address but return value is wrong)
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 24 Jan 2016 06:01:43 +0900 |
parents | 23ad5811c88f |
children | bec7f99b60b5 |
files | asmtest2.c |
diffstat | 1 files changed, 37 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/asmtest2.c Sun Jan 24 06:01:43 2016 +0900 @@ -0,0 +1,37 @@ +#include <stdio.h> + +__code factorial(int n,int result,int orig,__code(*print)(int,int,int,__code(*)(),__code(*)(),void*),__code(*exit1)(int,void *), void *exit1env) +{ + if (n<0) { + printf("#0008:err %d!\n",n); + goto (*exit1)(0,exit1env); + } + if (n==0) + goto (*print)(n,result,orig,print,exit1,exit1env); + else { + result *= n; + n--; + goto factorial(n,result,orig,print,exit1,exit1env); + } +} + + +int main( int ac, char *av[]) +{ + int n; + n = 10; + goto factorial(n,1,n,print,__return,__environment); + return 10; +} + +__code print(int n,int result,int orig,__code(*print)(),__code (*exit1)(int, void*),void*exit1env) +{ + printf("#0032:%d! = %d\n",orig, result); + asm volatile("movq 0x8(%%rdi), %%rbp;" + "movq 0x10(%%rdi), %%rsp;" + "incl %%eax;" + "jmpq *0x38(%%rdi);" + ::"D"(((struct __CbC_env *)exit1env)->env)); + goto (*exit1)(100,exit1env); + +}