annotate longjump.c @ 5:4e7858590985

remove malloc , free and include<stdlib.h>
author Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
date Sat, 23 Nov 2013 23:31:02 +0900
parents dee9711aeb06
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include <stdio.h>
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #include <setjmp.h>
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 #include <stdlib.h>
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 __attribute__((noinline))
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 __code code1(void *__return,void *__enviroment){
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 void(*ret)(void *);
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 printf("code1\n");
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 ret = (void(*)(void *))__return;
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 ret(__enviroment);
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 }
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 void *return1 (void* env){
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 printf("return1\n");
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 longjmp(*(jmp_buf*)env,1);
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 }
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 void main1 (){
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 void *__return;
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 void *__enviroment;
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 printf("main1 entry\n");
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 __enviroment = (void*)malloc(sizeof(jmp_buf));
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 if (setjmp(__enviroment)){
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 free(__enviroment);
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 printf("main1 return\n");
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 return;
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 }
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 __return = (void*)return1;
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 goto code1(__return,__enviroment);
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 }
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 int main (){
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 main1();
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 printf("returned\n");
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 return 1;
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 }