1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2025 The FreeBSD Foundation 5 * Copyright (c) 2026 Capabilities Limited 6 * All rights reserved. 7 * 8 * This software were developed by Konstantin Belousov <kib@FreeBSD.org> 9 * under sponsorship from the FreeBSD Foundation. 10 * 11 * This software was developed by Capabilities Limited with funding from 12 * Innovate UK and the Department for Science, Innovation and Technology 13 * for the adoption and diffusion of CHERI technology under project 14 * 10168042 (“CheriBSD feature extraction, maturity, and testing”). 15 */ 16 17 #ifndef _UEXTERROR_H_ 18 #define _UEXTERROR_H_ 19 20 #include <sys/types.h> 21 #include <sys/linker_set.h> 22 23 struct exterr_cat { 24 unsigned int cat; 25 const char *file; 26 }; 27 28 #ifndef UEXTERR_CATEGORY 29 #error "Specify error category before including uexterror.h" 30 #endif 31 32 #ifndef NO_UEXTERR_STRINGS 33 static struct exterr_cat __dynamic_cat = { .file = UEXTERR_CATEGORY }; 34 DATA_WSET(exterr_cats, __dynamic_cat); 35 #define _UEXTERR_CATEGORY \ 36 (__dynamic_cat.cat | EXTERR_CAT_SRC_USER) 37 #else 38 #define _UEXTERR_CATEGORY (EXTERR_CAT_NONE | EXTERR_CAT_SRC_USER) 39 #endif 40 41 42 #ifdef NO_UEXTERR_STRINGS 43 #define SET_ERROR_MSG(mmsg) NULL 44 #else 45 #define SET_ERROR_MSG(mmsg) (mmsg) 46 #endif 47 48 #define _SET_ERROR2(eerror, mmsg, pp1, pp2) \ 49 uexterr_set(eerror, _UEXTERR_CATEGORY, SET_ERROR_MSG(mmsg), \ 50 (uint64ptr_t)(pp1), (uint64ptr_t)(pp2), __LINE__) 51 #define _SET_ERROR0(eerror, mmsg) _SET_ERROR2(eerror, mmsg, 0, 0) 52 #define _SET_ERROR1(eerror, mmsg, pp1) _SET_ERROR2(eerror, mmsg, pp1, 0) 53 54 #define _UEXTERROR_MACRO(eerror, mmsg, _1, _2, NAME, ...) \ 55 NAME 56 #define UEXTERROR(...) \ 57 _UEXTERROR_MACRO(__VA_ARGS__, _SET_ERROR2, _SET_ERROR1, \ 58 _SET_ERROR0)(__VA_ARGS__) 59 60 __BEGIN_DECLS 61 void uexterr_set(int error, int category, const char *mmsg, uint64ptr_t pp1, 62 uint64ptr_t pp2, int line); 63 __END_DECLS 64 65 #endif 66