1*efe51d0cSJohn Levon /*
2*efe51d0cSJohn Levon * Copyright (C) 2016 Oracle.
3*efe51d0cSJohn Levon *
4*efe51d0cSJohn Levon * This program is free software; you can redistribute it and/or
5*efe51d0cSJohn Levon * modify it under the terms of the GNU General Public License
6*efe51d0cSJohn Levon * as published by the Free Software Foundation; either version 2
7*efe51d0cSJohn Levon * of the License, or (at your option) any later version.
8*efe51d0cSJohn Levon *
9*efe51d0cSJohn Levon * This program is distributed in the hope that it will be useful,
10*efe51d0cSJohn Levon * but WITHOUT ANY WARRANTY; without even the implied warranty of
11*efe51d0cSJohn Levon * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12*efe51d0cSJohn Levon * GNU General Public License for more details.
13*efe51d0cSJohn Levon *
14*efe51d0cSJohn Levon * You should have received a copy of the GNU General Public License
15*efe51d0cSJohn Levon * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
16*efe51d0cSJohn Levon *
17*efe51d0cSJohn Levon * Copyright 2019 Joyent, Inc.
18*efe51d0cSJohn Levon */
19*efe51d0cSJohn Levon
20*efe51d0cSJohn Levon /*
21*efe51d0cSJohn Levon * Heavily borrowed from check_wine.c: what we're doing here is teaching smatch
22*efe51d0cSJohn Levon * that cmn_err(CE_PANIC, ...) is noreturn.
23*efe51d0cSJohn Levon */
24*efe51d0cSJohn Levon
25*efe51d0cSJohn Levon #include "scope.h"
26*efe51d0cSJohn Levon #include "smatch.h"
27*efe51d0cSJohn Levon #include "smatch_extra.h"
28*efe51d0cSJohn Levon
29*efe51d0cSJohn Levon #define CE_PANIC (3)
30*efe51d0cSJohn Levon
match_cmn_err(const char * fn,struct expression * expr,void * unused)31*efe51d0cSJohn Levon void match_cmn_err(const char *fn, struct expression *expr,
32*efe51d0cSJohn Levon void *unused)
33*efe51d0cSJohn Levon {
34*efe51d0cSJohn Levon struct expression *arg;
35*efe51d0cSJohn Levon sval_t sval;
36*efe51d0cSJohn Levon
37*efe51d0cSJohn Levon arg = get_argument_from_call_expr(expr->args, 0);
38*efe51d0cSJohn Levon if (!get_implied_value(arg, &sval))
39*efe51d0cSJohn Levon return;
40*efe51d0cSJohn Levon
41*efe51d0cSJohn Levon if (sval.value == CE_PANIC)
42*efe51d0cSJohn Levon nullify_path();
43*efe51d0cSJohn Levon }
44*efe51d0cSJohn Levon
45*efe51d0cSJohn Levon
check_cmn_err(int id)46*efe51d0cSJohn Levon void check_cmn_err(int id)
47*efe51d0cSJohn Levon {
48*efe51d0cSJohn Levon if (option_project != PROJ_ILLUMOS_KERNEL)
49*efe51d0cSJohn Levon return;
50*efe51d0cSJohn Levon
51*efe51d0cSJohn Levon add_function_hook("cmn_err", &match_cmn_err, NULL);
52*efe51d0cSJohn Levon }
53