git: a5b0b2a7d421 - main - C runtime: add kernel version guards on exterrctl
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 04 Jun 2025 18:09:30 UTC
The branch main has been updated by brooks:
URL: https://cgit.FreeBSD.org/src/commit/?id=a5b0b2a7d4219ae86f152433b6fcecd9e8c767d6
commit a5b0b2a7d4219ae86f152433b6fcecd9e8c767d6
Author: Brooks Davis <brooks@FreeBSD.org>
AuthorDate: 2025-06-04 17:58:03 +0000
Commit: Brooks Davis <brooks@FreeBSD.org>
CommitDate: 2025-06-04 18:09:19 +0000
C runtime: add kernel version guards on exterrctl
This allows userspace to run on a (somewhat) out of date kernel.
Avoid a __FreeBSD_version bump and use the bump from a02180cf60a6 which
has occured since exterrctl was added.
Reviewed by: kevans
Fixes: b9c8a07d4dd9 ("C runtime: enable extended error reporting from kernel")
Sponsored by: DARPA, AFRL
Differential Revision: https://reviews.freebsd.org/D50687
---
lib/libc/gen/uexterr_gettext.c | 8 ++++++--
lib/libthr/thread/thr_create.c | 6 +++++-
lib/libthr/thread/thr_init.c | 5 ++++-
sys/sys/param.h | 1 +
4 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/lib/libc/gen/uexterr_gettext.c b/lib/libc/gen/uexterr_gettext.c
index b4bb93cfdb50..5b8a5cd17a48 100644
--- a/lib/libc/gen/uexterr_gettext.c
+++ b/lib/libc/gen/uexterr_gettext.c
@@ -8,7 +8,8 @@
* under sponsorship from the FreeBSD Foundation.
*/
-#include <sys/types.h>
+#define _WANT_P_OSREL
+#include <sys/param.h>
#include <sys/exterrvar.h>
#include <exterr.h>
#include <string.h>
@@ -18,11 +19,14 @@ static struct uexterror uexterr = {
.ver = UEXTERROR_VER,
};
+int __getosreldate(void);
+
static void uexterr_ctr(void) __attribute__((constructor));
static void
uexterr_ctr(void)
{
- exterrctl(EXTERRCTL_ENABLE, 0, &uexterr);
+ if (__getosreldate() >= P_OSREL_EXTERRCTL)
+ exterrctl(EXTERRCTL_ENABLE, 0, &uexterr);
}
int
diff --git a/lib/libthr/thread/thr_create.c b/lib/libthr/thread/thr_create.c
index ba2575d461e5..c66a5bb3bd21 100644
--- a/lib/libthr/thread/thr_create.c
+++ b/lib/libthr/thread/thr_create.c
@@ -27,6 +27,7 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#define _WANT_P_OSREL
#include "namespace.h"
#include <sys/types.h>
#include <sys/rtprio.h>
@@ -44,6 +45,8 @@
#include "libc_private.h"
#include "thr_private.h"
+int __getosreldate(void);
+
static int create_stack(struct pthread_attr *pattr);
static void thread_start(struct pthread *curthread);
@@ -287,7 +290,8 @@ thread_start(struct pthread *curthread)
#endif
curthread->uexterr.ver = UEXTERROR_VER;
- exterrctl(EXTERRCTL_ENABLE, 0, &curthread->uexterr);
+ if (__getosreldate() >= P_OSREL_EXTERRCTL)
+ exterrctl(EXTERRCTL_ENABLE, 0, &curthread->uexterr);
/* Run the current thread's start routine with argument: */
_pthread_exit(curthread->start_routine(curthread->arg));
diff --git a/lib/libthr/thread/thr_init.c b/lib/libthr/thread/thr_init.c
index aef2281c5f22..bd1474a7c6e8 100644
--- a/lib/libthr/thread/thr_init.c
+++ b/lib/libthr/thread/thr_init.c
@@ -33,6 +33,7 @@
* SUCH DAMAGE.
*/
+#define _WANT_P_OSREL
#include "namespace.h"
#include <sys/param.h>
#include <sys/auxv.h>
@@ -59,6 +60,7 @@
#include "libc_private.h"
#include "thr_private.h"
+int __getosreldate(void);
char *_usrstack;
struct pthread *_thr_initial;
int _libthr_debug;
@@ -434,7 +436,8 @@ init_main_thread(struct pthread *thread)
#endif
thread->uexterr.ver = UEXTERROR_VER;
- exterrctl(EXTERRCTL_ENABLE, EXTERRCTLF_FORCE, &thread->uexterr);
+ if (__getosreldate() >= P_OSREL_EXTERRCTL)
+ exterrctl(EXTERRCTL_ENABLE, EXTERRCTLF_FORCE, &thread->uexterr);
/* Others cleared to zero by thr_alloc() */
}
diff --git a/sys/sys/param.h b/sys/sys/param.h
index 98fb0aeacef0..da2089918323 100644
--- a/sys/sys/param.h
+++ b/sys/sys/param.h
@@ -107,6 +107,7 @@
#define P_OSREL_TIDPID 1400079
#define P_OSREL_ARM64_SPSR 1400084
#define P_OSREL_TLSBASE 1500044
+#define P_OSREL_EXTERRCTL 1500045
#define P_OSREL_MAJOR(x) ((x) / 100000)
#endif