Page MenuHomeFreeBSD

D58059.id182455.diff
No OneTemporary

D58059.id182455.diff

diff --git a/include/Makefile b/include/Makefile
--- a/include/Makefile
+++ b/include/Makefile
@@ -33,7 +33,8 @@
stddef.h stdnoreturn.h stdio.h stdlib.h string.h stringlist.h \
strings.h sysexits.h tar.h termios.h tgmath.h \
time.h timeconv.h timers.h ttyent.h \
- uchar.h ulimit.h unistd.h utime.h utmpx.h uuid.h varargs.h \
+ uchar.h uexterror.h ulimit.h unistd.h utime.h utmpx.h uuid.h \
+ varargs.h \
wchar.h wctype.h wordexp.h xlocale.h
.PATH: ${SRCTOP}/contrib/libc-vis
diff --git a/include/uexterror.h b/include/uexterror.h
new file mode 100644
--- /dev/null
+++ b/include/uexterror.h
@@ -0,0 +1,59 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2025 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software were developed by Konstantin Belousov <kib@FreeBSD.org>
+ * under sponsorship from the FreeBSD Foundation.
+ */
+
+#ifndef _UEXTERROR_H_
+#define _UEXTERROR_H_
+
+#include <sys/types.h>
+#include <sys/linker_set.h>
+
+struct exterr_cat {
+ unsigned int cat;
+ const char *file;
+};
+
+#ifndef UEXTERR_CATEGORY
+#error "Specify error category before including uexterror.h"
+#endif
+
+#ifndef NO_UEXTERR_STRINGS
+static struct exterr_cat __dynamic_cat = { .file = UEXTERR_CATEGORY };
+DATA_WSET(exterr_cats, __dynamic_cat);
+#define _UEXTERR_CATEGORY \
+ (__dynamic_cat.cat | EXTERR_CAT_SRC_USER)
+#else
+#define _UEXTERR_CATEGORY (EXTERR_CAT_NONE | EXTERR_CAT_SRC_USER)
+#endif
+
+
+#ifdef NO_UEXTERR_STRINGS
+#define SET_ERROR_MSG(mmsg) NULL
+#else
+#define SET_ERROR_MSG(mmsg) (mmsg)
+#endif
+
+#define _SET_ERROR2(eerror, mmsg, pp1, pp2) \
+ uexterr_set(eerror, _UEXTERR_CATEGORY, SET_ERROR_MSG(mmsg), \
+ (uint64ptr_t)(pp1), (uint64ptr_t)(pp2), __LINE__)
+#define _SET_ERROR0(eerror, mmsg) _SET_ERROR2(eerror, mmsg, 0, 0)
+#define _SET_ERROR1(eerror, mmsg, pp1) _SET_ERROR2(eerror, mmsg, pp1, 0)
+
+#define _UEXTERROR_MACRO(eerror, mmsg, _1, _2, NAME, ...) \
+ NAME
+#define UEXTERROR(...) \
+ _UEXTERROR_MACRO(__VA_ARGS__, _SET_ERROR2, _SET_ERROR1, \
+ _SET_ERROR0)(__VA_ARGS__)
+
+__BEGIN_DECLS
+int uexterr_set(int error, int category, const char *mmsg, uint64ptr_t pp1,
+ uint64ptr_t pp2, int line);
+__END_DECLS
+
+#endif
diff --git a/lib/libc/gen/Symbol.map b/lib/libc/gen/Symbol.map
--- a/lib/libc/gen/Symbol.map
+++ b/lib/libc/gen/Symbol.map
@@ -482,6 +482,7 @@
posix_spawnattr_getprocdescp_np;
posix_spawnattr_setexecfd_np;
posix_spawnattr_setprocdescp_np;
+ uexterr_set;
};
FBSDprivate_1.0 {
@@ -612,4 +613,5 @@
__getcontextx_size;
__makecontext;
__uexterr_format;
+ __uexterr_set_ue;
};
diff --git a/lib/libc/gen/libc_interposing_table.c b/lib/libc/gen/libc_interposing_table.c
--- a/lib/libc/gen/libc_interposing_table.c
+++ b/lib/libc/gen/libc_interposing_table.c
@@ -43,6 +43,7 @@
SLOT(spinunlock, __libc_spinunlock_stub),
SLOT(map_stacks_exec, __libc_map_stacks_exec),
SLOT(uexterr_gettext, __libc_uexterr_gettext),
+ SLOT(uexterr_set, __libc_uexterr_set),
};
#undef SLOT
diff --git a/lib/libc/gen/uexterr_gettext.c b/lib/libc/gen/uexterr_gettext.c
--- a/lib/libc/gen/uexterr_gettext.c
+++ b/lib/libc/gen/uexterr_gettext.c
@@ -11,6 +11,7 @@
#define _WANT_P_OSREL
#include <sys/param.h>
#include <sys/exterrvar.h>
+#include <errno.h>
#include <exterr.h>
#include <string.h>
#include "libc_private.h"
@@ -41,3 +42,39 @@
return (((int (*)(char *, size_t))
__libc_interposing[INTERPOS_uexterr_gettext])(buf, bufsz));
}
+
+int
+__uexterr_set_ue(struct uexterror *ue, int error, int category,
+ const char *mmsg, uint64ptr_t pp1, uint64ptr_t pp2, int line)
+{
+ memset((char *)ue + offsetof(struct uexterror, error), 0,
+ sizeof(struct uexterror) - offsetof(struct uexterror, error));
+ ue->error = error;
+ ue->cat = category | EXTERR_CAT_SRC_USER;
+ ue->src_line = line;
+ ue->p1 = pp1;
+ ue->p2 = pp2;
+ if (mmsg != NULL)
+ strlcpy(ue->msg, mmsg, sizeof(ue->msg));
+ else
+ ue->msg[0] = '\0';
+ errno = error;
+ return (0);
+}
+
+int
+__libc_uexterr_set(int error, int category, const char *mmsg, uint64ptr_t pp1,
+ uint64ptr_t pp2, int line)
+{
+ return (__uexterr_set_ue(&uexterr, error, category, mmsg, pp1,
+ pp2, line));
+}
+
+int
+uexterr_set(int error, int category, const char *mmsg, uint64ptr_t pp1,
+ uint64ptr_t pp2, int line)
+{
+ return (((int (*)(int, int, const char *, uint64ptr_t, uint64ptr_t,
+ int))__libc_interposing[INTERPOS_uexterr_set])(error,
+ category, mmsg, pp1, pp2, line));
+}
diff --git a/lib/libc/include/libc_private.h b/lib/libc/include/libc_private.h
--- a/lib/libc/include/libc_private.h
+++ b/lib/libc/include/libc_private.h
@@ -253,6 +253,7 @@
INTERPOS_pdfork,
INTERPOS_uexterr_gettext,
INTERPOS_pdwait,
+ INTERPOS_uexterr_set,
INTERPOS_MAX
};
@@ -382,6 +383,10 @@
struct uexterror;
int __uexterr_format(const struct uexterror *ue, char *buf, size_t bufsz);
+int __uexterr_set_ue(struct uexterror *ue, int error, int category,
+ const char *mmsg, uint64ptr_t pp1, uint64ptr_t pp2, int line);
int __libc_uexterr_gettext(char *buf, size_t bufsz);
+int __libc_uexterr_set(int eerror, int category, const char *mmsg,
+ uint64ptr_t pp1, uint64ptr_t pp2, int line);
#endif /* _LIBC_PRIVATE_H_ */
diff --git a/lib/libthr/thread/thr_syscalls.c b/lib/libthr/thread/thr_syscalls.c
--- a/lib/libthr/thread/thr_syscalls.c
+++ b/lib/libthr/thread/thr_syscalls.c
@@ -643,6 +643,18 @@
return (__uexterr_format(&curthread->uexterr, buf, bufsz));
}
+static int
+__thr_uexterr_set(int error, int category, const char *mmsg, uint64ptr_t pp1,
+ uint64ptr_t pp2, int line)
+{
+ struct pthread *curthread;
+
+ curthread = _get_curthread();
+
+ return (__uexterr_set_ue(&curthread->uexterr, error, category,
+ mmsg, pp1, pp2, line));
+}
+
void
__thr_interpose_libc(void)
{
@@ -700,6 +712,7 @@
SLOT(pdfork);
SLOT(uexterr_gettext);
SLOT(pdwait);
+ SLOT(uexterr_set);
#undef SLOT
*(__libc_interposing_slot(
INTERPOS__pthread_mutex_init_calloc_cb)) =

File Metadata

Mime Type
text/plain
Expires
Tue, Aug 4, 10:42 AM (23 h, 2 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
35962560
Default Alt Text
D58059.id182455.diff (5 KB)

Event Timeline