1 /*
2  * Copyright (C) 2016 Oracle.
3  *
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.
8  *
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.
13  *
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
16  *
17  * Copyright 2019 Joyent, Inc.
18  */
19 
20 /*
21  * Heavily borrowed from check_wine.c: what we're doing here is teaching smatch
22  * that cmn_err(CE_PANIC, ...) is noreturn.
23  */
24 
25 #include "scope.h"
26 #include "smatch.h"
27 #include "smatch_extra.h"
28 
29 #define	CE_PANIC (3)
30 
match_cmn_err(const char * fn,struct expression * expr,void * unused)31 void match_cmn_err(const char *fn, struct expression *expr,
32 			void *unused)
33 {
34 	struct expression *arg;
35 	sval_t sval;
36 
37 	arg = get_argument_from_call_expr(expr->args, 0);
38 	if (!get_implied_value(arg, &sval))
39 		return;
40 
41 	if (sval.value == CE_PANIC)
42 		nullify_path();
43 }
44 
45 
check_cmn_err(int id)46 void check_cmn_err(int id)
47 {
48 	if (option_project != PROJ_ILLUMOS_KERNEL)
49 		return;
50 
51 	add_function_hook("cmn_err", &match_cmn_err, NULL);
52 }
53