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