1 |
|
|
#include <signal.h> |
2 |
|
|
#include "gwion_util.h" |
3 |
|
|
#include "gwion_ast.h" |
4 |
|
|
#include "gwion_env.h" |
5 |
|
|
#include "vm.h" |
6 |
|
|
#include "gwion.h" |
7 |
|
|
#include "arg.h" |
8 |
|
|
|
9 |
|
1 |
static void sig(int unused NUSED) { |
10 |
|
|
#ifdef BUILD_ON_WINDOWS |
11 |
|
|
exit(EXIT_FAILURE); |
12 |
|
|
#else |
13 |
|
1 |
pthread_kill(pthread_self(), SIGTERM); |
14 |
|
1 |
pthread_exit(NULL); |
15 |
|
|
#endif |
16 |
|
|
} |
17 |
|
|
|
18 |
|
|
#ifdef __AFL_HAVE_MANUAL_CONTROL |
19 |
|
|
|
20 |
|
|
static void afl_run(const Gwion gwion) { |
21 |
|
|
gw_seed(gwion->vm->rand, 0); |
22 |
|
|
__AFL_INIT(); |
23 |
|
|
while (__AFL_LOOP(256)) { |
24 |
|
|
FILE* f = fdopen(0, "r"); |
25 |
|
|
push_global(gwion, "[afl]"); |
26 |
|
|
if(compile_file(gwion, "afl", f)) |
27 |
|
|
gwion_run(gwion); |
28 |
|
|
pop_global(gwion); |
29 |
|
|
} |
30 |
|
|
} |
31 |
|
|
|
32 |
|
|
#define gwion_run(a) { afl_run(a); return 0; } |
33 |
|
|
#endif |
34 |
|
|
|
35 |
|
715 |
int main(int argc, char** argv) { |
36 |
|
715 |
Arg arg = { .arg={.argc=argc, .argv=argv}, .loop=-1 }; |
37 |
|
715 |
signal(SIGINT, sig); |
38 |
|
715 |
signal(SIGTERM, sig); |
39 |
|
715 |
struct Gwion_ gwion = {}; |
40 |
|
715 |
const m_bool ini = gwion_ini(&gwion, &arg); |
41 |
|
715 |
arg_release(&arg); |
42 |
✓✓ |
715 |
if(ini > 0) |
43 |
|
712 |
gwion_run(&gwion); |
44 |
|
714 |
gwion_end(&gwion); |
45 |
|
|
#ifndef BUILD_ON_WINDOWS |
46 |
|
714 |
pthread_exit(NULL); |
47 |
|
|
#endif |
48 |
|
|
return EXIT_SUCCESS; |
49 |
|
|
} |