From 4686f6bc61d6f9d1dbe12e4e67583a25cdb12040 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Sun, 1 Dec 2024 06:02:26 -0700 Subject: [PATCH] repair executable-relative boot file search on NetBSD (#889) --- c/self-exe.c | 39 +++++++++++++++++++++++++++++++- release_notes/release_notes.stex | 6 +++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/c/self-exe.c b/c/self-exe.c index fecc82fb1..cbcfcaf86 100644 --- a/c/self-exe.c +++ b/c/self-exe.c @@ -187,6 +187,33 @@ static char *get_self_path_platform() { } #endif +#if defined(__NetBSD__) +#define HAVE_GET_SELF_PATH_PLATFORM +#include +static char *get_self_path_platform() { + int mib[4]; + char *s; + size_t len; + int r; + + mib[0] = CTL_KERN; + mib[1] = KERN_PROC_ARGS; + mib[2] = getpid(); + mib[3] = KERN_PROC_PATHNAME; + + r = sysctl(mib, 4, NULL, &len, NULL, 0); + if (r < 0) + return NULL; + s = malloc(len); + if (s == NULL) + return NULL; + r = sysctl(mib, 4, s, &len, NULL, 0); + if (r < 0) + return NULL; + return s; +} +#endif + #if defined(__sun__) && defined(__svr4__) #define HAVE_GET_SELF_PATH_PLATFORM static char *get_self_path_platform() { @@ -203,12 +230,22 @@ static char *get_self_path_platform() { static char *get_self_path_platform() { return copy_string("/proc/self/exe"); } #endif -#if defined(__NetBSD__) || defined(__minix) || defined(__DragonFly__) || \ +#if defined(__minix) || defined(__DragonFly__) || \ defined(__FreeBSD_kernel__) || defined(_AIX) #define HAVE_GET_SELF_PATH_PLATFORM static char *get_self_path_platform() { return copy_string("/proc/curproc/file"); } #endif +#ifndef HAVE_GET_SELF_PATH_PLATFORM +/* sysctl() approach should be used, instead, but leaving this here as a reminder + (1) to not switch back to "/proc" for NetBSD; and (2) if switching is somehow + needed, don't confuse "/proc/curproc/file" with "/proc/curproc/exe" */ +#if defined(__NetBSD__) +#define HAVE_GET_SELF_PATH_PLATFORM +static char *get_self_path_platform() { return copy_string("/proc/curproc/exe"); } +#endif +#endif + #ifndef HAVE_GET_SELF_PATH_PLATFORM static char *get_self_path_platform() { return NULL; } #endif diff --git a/release_notes/release_notes.stex b/release_notes/release_notes.stex index 95b1cc685..24ca06876 100644 --- a/release_notes/release_notes.stex +++ b/release_notes/release_notes.stex @@ -2769,6 +2769,12 @@ in fasl files does not generally make sense. %----------------------------------------------------------------------------- \section{Bug Fixes}\label{section:bugfixes} +\subsection{Repair executable-releative search for NetBSD (10.2.0)} + +An incorrect approach to finding the current executable's path on +NetBSD meant that boot files could not be found relative to the +executable. + \subsection{Incorrect assembly code for threaded ARMv5 and earlier (10.1.0)} A bug that generated incorrect assembly code in threaded mode for ARMv5 and earlier