1*44c88cc6Sriastradh /* $NetBSD: bug.h,v 1.4 2021/12/19 12:12:07 riastradh Exp $ */
2202732a5Sriastradh
3202732a5Sriastradh /*-
4202732a5Sriastradh * Copyright (c) 2013 The NetBSD Foundation, Inc.
5202732a5Sriastradh * All rights reserved.
6202732a5Sriastradh *
7202732a5Sriastradh * This code is derived from software contributed to The NetBSD Foundation
8202732a5Sriastradh * by Taylor R. Campbell.
9202732a5Sriastradh *
10202732a5Sriastradh * Redistribution and use in source and binary forms, with or without
11202732a5Sriastradh * modification, are permitted provided that the following conditions
12202732a5Sriastradh * are met:
13202732a5Sriastradh * 1. Redistributions of source code must retain the above copyright
14202732a5Sriastradh * notice, this list of conditions and the following disclaimer.
15202732a5Sriastradh * 2. Redistributions in binary form must reproduce the above copyright
16202732a5Sriastradh * notice, this list of conditions and the following disclaimer in the
17202732a5Sriastradh * documentation and/or other materials provided with the distribution.
18202732a5Sriastradh *
19202732a5Sriastradh * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20202732a5Sriastradh * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21202732a5Sriastradh * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22202732a5Sriastradh * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23202732a5Sriastradh * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24202732a5Sriastradh * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25202732a5Sriastradh * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26202732a5Sriastradh * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27202732a5Sriastradh * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28202732a5Sriastradh * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29202732a5Sriastradh * POSSIBILITY OF SUCH DAMAGE.
30202732a5Sriastradh */
31202732a5Sriastradh
32202732a5Sriastradh #ifndef _ASM_BUG_H_
33202732a5Sriastradh #define _ASM_BUG_H_
34202732a5Sriastradh
35202732a5Sriastradh #include <sys/cdefs.h>
36202732a5Sriastradh #include <sys/systm.h>
37202732a5Sriastradh
380006b9c8Sriastradh #include <linux/build_bug.h> /* XXX */
39202732a5Sriastradh
40202732a5Sriastradh #define BUG() panic("%s:%d: BUG!", __FILE__, __LINE__)
41202732a5Sriastradh #define BUG_ON(CONDITION) KASSERT(!(CONDITION))
42202732a5Sriastradh
43202732a5Sriastradh /* XXX Rate limit? */
44202732a5Sriastradh #define WARN(CONDITION, FMT, ...) \
45202732a5Sriastradh linux_warning((CONDITION)? \
46202732a5Sriastradh (printf("warning: %s:%d: " FMT, __FILE__, __LINE__, \
47202732a5Sriastradh ##__VA_ARGS__), 1) \
48202732a5Sriastradh : 0)
49202732a5Sriastradh
50202732a5Sriastradh #define WARN_ONCE(CONDITION, FMT, ...) \
51*44c88cc6Sriastradh ({ \
52*44c88cc6Sriastradh static volatile unsigned __warn_once_done = 0; \
53*44c88cc6Sriastradh linux_warning((CONDITION) \
54*44c88cc6Sriastradh ? (atomic_swap_uint(&__warn_once_done, 1) == 0 \
55*44c88cc6Sriastradh ? (printf("warning: %s:%d: " FMT, __FILE__, __LINE__, \
56*44c88cc6Sriastradh ##__VA_ARGS__), 1) \
57*44c88cc6Sriastradh : 1) \
58*44c88cc6Sriastradh : 0); \
59*44c88cc6Sriastradh })
60202732a5Sriastradh
61202732a5Sriastradh #define WARN_ON(CONDITION) WARN(CONDITION, "%s\n", #CONDITION)
62202732a5Sriastradh #define WARN_ON_SMP(CONDITION) WARN_ON(CONDITION) /* XXX */
63*44c88cc6Sriastradh #define WARN_ON_ONCE(CONDITION) WARN_ONCE(CONDITION, "%s\n", #CONDITION)
64202732a5Sriastradh
65202732a5Sriastradh /* XXX Kludge to avoid GCC warning about statements without effect. */
66202732a5Sriastradh static inline int
linux_warning(int x)67202732a5Sriastradh linux_warning(int x)
68202732a5Sriastradh {
69202732a5Sriastradh return x;
70202732a5Sriastradh }
71202732a5Sriastradh
72202732a5Sriastradh #endif /* _ASM_BUG_H_ */
73