xref: /freebsd/sys/sys/exterrvar.h (revision c27f7d6b9cf6d4ab01cb3d0972726c14e0aca146)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2025 The FreeBSD Foundation
5  * All rights reserved.
6  *
7  * This software were developed by Konstantin Belousov <kib@FreeBSD.org>
8  * under sponsorship from the FreeBSD Foundation.
9  */
10 
11 #ifndef _SYS_EXTERRVAR_H_
12 #define	_SYS_EXTERRVAR_H_
13 
14 #include <sys/_exterr.h>
15 #include <sys/_uexterror.h>
16 #include <sys/exterr_cat.h>
17 
18 #define	UEXTERROR_MAXLEN	256
19 
20 #define	UEXTERROR_VER		0x10010002
21 
22 #define	EXTERRCTL_ENABLE	1
23 #define	EXTERRCTL_DISABLE	2
24 
25 #define	EXTERRCTLF_FORCE	0x00000001
26 
27 #ifdef _KERNEL
28 
29 #ifndef EXTERR_CATEGORY
30 #error "Specify error category before including sys/exterrvar.h"
31 #endif
32 
33 #ifdef	BLOAT_KERNEL_WITH_EXTERR
34 #define	SET_ERROR_MSG(mmsg)	_Td->td_kexterr.msg = mmsg
35 #else
36 #define	SET_ERROR_MSG(mmsg)	_Td->td_kexterr.msg = NULL
37 #endif
38 
39 #define	SET_ERROR2(eerror, mmsg, pp1, pp2) do {	\
40 	struct thread *_Td = curthread;				\
41 	if ((_Td->td_pflags2 & TDP2_UEXTERR) != 0) {		\
42 		_Td->td_pflags2 |= TDP2_EXTERR;			\
43 		_Td->td_kexterr.error = eerror;			\
44 		_Td->td_kexterr.cat = EXTERR_CATEGORY;		\
45 		SET_ERROR_MSG(mmsg);				\
46 		_Td->td_kexterr.p1 = (uintptr_t)pp1;		\
47 		_Td->td_kexterr.p2 = (uintptr_t)pp2;		\
48 		_Td->td_kexterr.src_line = __LINE__;		\
49 		ktrexterr(_Td);					\
50 	}							\
51 } while (0)
52 #define	SET_ERROR0(eerror, mmsg)	SET_ERROR2(eerror, mmsg, 0, 0)
53 #define	SET_ERROR1(eerror, mmsg, pp1)	SET_ERROR2(eerror, mmsg, pp1, 0)
54 
55 int exterr_to_ue(struct thread *td, struct uexterror *ue);
56 void ktrexterr(struct thread *td);
57 
58 #else	/* _KERNEL */
59 
60 #include <sys/types.h>
61 
62 __BEGIN_DECLS
63 int exterrctl(u_int op, u_int flags, void *ptr);
64 __END_DECLS
65 
66 #endif	/* _KERNEL */
67 
68 #endif
69