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