2 * Copyright (C) 2017 Oracle.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
19 * The idea is to generate syscall templates for the Trinity fuzzer. There
20 * isn't currently quite enough information to do it right but I want to start
21 * and see how far I can get.
26 #include "smatch_slist.h"
32 static int gen_custom_struct(int nr
, struct symbol
*arg
)
37 static void print_arg(int nr
, struct symbol
*arg
)
39 fprintf(sysc_fd
, "\t.arg%dname = \"%s\",\n", nr
+ 1, arg
->ident
->name
);
40 fprintf(sysc_fd
, "\t.arg%dtype = %s,\n", nr
+ 1, get_syscall_arg_type(arg
));
43 static void match_return(struct expression
*ret_value
)
50 int has_custom_struct
[6];
52 if (!get_function() || !cur_func_sym
)
54 if (strncmp(get_function(), "SYSC_", 5) != 0)
57 num_args
= ptr_list_size((struct ptr_list
*)cur_func_sym
->ctype
.base_type
->arguments
);
58 name
= get_function() + 5;
60 snprintf(buf
, sizeof(buf
), "smatch_trinity_%s", name
);
61 sysc_fd
= fopen(buf
, "w");
63 printf("Error: Cannot open %s\n", buf
);
68 FOR_EACH_PTR(cur_func_sym
->ctype
.base_type
->arguments
, arg
) {
69 if (gen_custom_struct(i
, arg
))
70 has_custom_struct
[i
] = true;
72 has_custom_struct
[i
] = false;
74 } END_FOR_EACH_PTR(arg
);
76 fprintf(sysc_fd
, "struct syscallentry sm_%s = {\n", name
);
77 fprintf(sysc_fd
, "\t.name = \"%s\",\n", name
);
78 fprintf(sysc_fd
, "\t.num_args = %d,\n", num_args
);
81 FOR_EACH_PTR(cur_func_sym
->ctype
.base_type
->arguments
, arg
) {
82 if (has_custom_struct
[i
])
86 } END_FOR_EACH_PTR(arg
);
88 fprintf(sysc_fd
, "};\n");
91 void check_trinity_generator(int id
)
95 if (option_project
!= PROJ_KERNEL
)
97 add_hook(&match_return
, RETURN_HOOK
);