-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cc
135 lines (101 loc) · 2.2 KB
/
main.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <iostream>
#include <thread>
#include "redmagic.h"
#include <unistd.h>
using namespace std;
enum {
PRINT_NUM,
JUMP_BACK,
EXIT,
COND_JUMP,
COND_SET,
COND_ADD,
MERGE_TEST,
};
int main(int argc, char* argv[]) {
// will perform a fork internally
// to be called as early as possible
redmagic_start();
int program2[] = {
PRINT_NUM, 0,
JUMP_BACK, 0,
EXIT,
};
int program[] = {
PRINT_NUM, 0,
COND_SET, 400,
PRINT_NUM, 1,
COND_ADD, -1,
MERGE_TEST, 0,
COND_JUMP, 4, // print num
EXIT,
};
// sleep(1);
// init so that the dynamic resolve doesn't cause an early abort
redmagic_fellthrough_branch((void*)123123);
int pc = 0;
int cond_var = 0;
float a = 1.2;
redmagic_begin_branchable_frame(NULL);
while(1) {
switch(program[pc]) {
case PRINT_NUM:
redmagic_temp_disable();
cout << program[pc + 1] << endl;
redmagic_temp_enable();
//printf("%i\n", program[pc + 1]);
a *= 1.001;
pc += 2;
break;
case JUMP_BACK:
redmagic_backwards_branch((void*)pc);
pc = program[pc + 1];
break;
case COND_JUMP:
if(cond_var != 0) {
redmagic_backwards_branch((void*)pc);
pc = program[pc + 1];
} else {
redmagic_fellthrough_branch((void*)pc);
pc += 2;
}
break;
case COND_SET:
cond_var = program[pc + 1];
pc += 2;
break;
case COND_ADD:
cond_var += program[pc + 1];
pc += 2;
break;
case MERGE_TEST:
redmagic_begin_merge_block();
if(cond_var % 2 == 0) {
cout << "a\n";
} else {
cout << "b\n";
}
pc += 2;
redmagic_end_merge_block();
break;
case EXIT:
cout << "hitting normal exit case\n" << a;
exit(0);
default:
exit(-1);
}
}
redmagic_end_branchable_frame(NULL);
// redmagic_force_begin_trace((void*)123);
// cout << "asdf\n";
// sleep(2);
// char *a = (char*)malloc(1000);
// *a = 1;
// //asm("int3");
// redmagic_temp_disable();
// cout << "test123";
// redmagic_temp_enable();
// sleep(1);
// redmagic_force_end_trace((void*)123);
cout << "program exiting\n";
}