| 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 | #define	EXTERRCTL_UD		3 |
| 25 | |
| 26 | #define	EXTERRCTLF_FORCE	0x00000001 |
| 27 | |
| 28 | #ifdef _KERNEL |
| 29 | |
| 30 | #ifndef EXTERR_CATEGORY |
| 31 | #error "Specify error category before including sys/exterrvar.h" |
| 32 | #endif |
| 33 | |
| 34 | #ifdef	EXTERR_STRINGS |
| 35 | #define	SET_ERROR_MSG(mmsg)	(mmsg) |
| 36 | #else |
| 37 | #define	SET_ERROR_MSG(mmsg)	NULL |
| 38 | #endif |
| 39 | |
| 40 | #define	_SET_ERROR2(eerror, mmsg, pp1, pp2)				\ |
| 41 | 	exterr_set(eerror, EXTERR_CATEGORY, SET_ERROR_MSG(mmsg),	\ |
| 42 | 	 (uintptr_t)(pp1), (uintptr_t)(pp2), __LINE__) |
| 43 | #define	_SET_ERROR0(eerror, mmsg)	_SET_ERROR2(eerror, mmsg, 0, 0) |
| 44 | #define	_SET_ERROR1(eerror, mmsg, pp1)	_SET_ERROR2(eerror, mmsg, pp1, 0) |
| 45 | |
| 46 | #define	_EXTERROR_MACRO(eerror, mmsg, _1, _2, NAME, ...)		\ |
| 47 | 	NAME |
| 48 | #define	EXTERROR(...)							\ |
| 49 | 	_EXTERROR_MACRO(__VA_ARGS__, _SET_ERROR2, _SET_ERROR1,		\ |
| 50 | 	 _SET_ERROR0)(__VA_ARGS__) |
| 51 | |
| 52 | int exterr_set(int eerror, int category, const char *mmsg, uintptr_t pp1, |
| 53 | uintptr_t pp2, int line); |
| 54 | int exterr_to_ue(struct thread *td, struct uexterror *ue); |
| 55 | void ktrexterr(struct thread *td); |
| 56 | |
| 57 | #else	/* _KERNEL */ |
| 58 | |
| 59 | #include <sys/types.h> |
| 60 | |
| 61 | __BEGIN_DECLS |
| 62 | int exterrctl(u_int op, u_int flags, void *ptr); |
| 63 | __END_DECLS |
| 64 | |
| 65 | #endif	/* _KERNEL */ |
| 66 | |
| 67 | #endif |