xref: /freebsd/lib/libc/gen/uexterr_set.c (revision 95e33099c74d9fc7963968f052b7546ad3040317)
1 /*-
2  * Copyright (c) 2026 Capabilities Limited
3  *
4  * SPDX-License-Identifier: BSD-2-Clause
5  *
6  * This software was developed by Capabilities Limited with funding from
7  * Innovate UK and the Department for Science, Innovation and Technology
8  * for the adoption and diffusion of CHERI technology under project
9  * 10168042 (“CheriBSD feature extraction, maturity, and testing”).
10  */
11 
12 #include <sys/exterrvar.h>
13 #include <errno.h>
14 #include <exterr.h>
15 #include <string.h>
16 #include "libc_private.h"
17 
18 void
__uexterr_set_ue(struct uexterror * ue,int error,int category,const char * mmsg,uint64ptr_t pp1,uint64ptr_t pp2,int line)19 __uexterr_set_ue(struct uexterror *ue, int error, int category,
20     const char *mmsg, uint64ptr_t pp1, uint64ptr_t pp2, int line)
21 {
22 	memset((char *)ue + offsetof(struct uexterror, error), 0,
23 	    sizeof(struct uexterror) - offsetof(struct uexterror, error));
24 	ue->error = error;
25 	ue->cat = category | EXTERR_CAT_SRC_USER;
26 	ue->src_line = line;
27 	ue->p1 = pp1;
28 	ue->p2 = pp2;
29 	if (mmsg != NULL)
30 		strlcpy(ue->msg, mmsg, sizeof(ue->msg));
31 	else
32 		ue->msg[0] = '\0';
33 	errno = error;
34 }
35 
36 void
__libc_uexterr_set(int error,int category,const char * mmsg,uint64ptr_t pp1,uint64ptr_t pp2,int line)37 __libc_uexterr_set(int error, int category, const char *mmsg, uint64ptr_t pp1,
38     uint64ptr_t pp2, int line)
39 {
40 	__uexterr_set_ue(&uexterr, error, category, mmsg, pp1, pp2, line);
41 }
42 
43 void
uexterr_set(int error,int category,const char * mmsg,uint64ptr_t pp1,uint64ptr_t pp2,int line)44 uexterr_set(int error, int category, const char *mmsg, uint64ptr_t pp1,
45     uint64ptr_t pp2, int line)
46 {
47 	((void (*)(int, int, const char *, uint64ptr_t, uint64ptr_t, int))
48 	    __libc_interposing[INTERPOS_uexterr_set])(error, category,
49 	    mmsg, pp1, pp2, line);
50 }
51