Skip to content

Commit

Permalink
repair executable-relative boot file search on NetBSD (#889)
Browse files Browse the repository at this point in the history
  • Loading branch information
mflatt authored Dec 1, 2024
1 parent 063485e commit 4686f6b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
39 changes: 38 additions & 1 deletion c/self-exe.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,33 @@ static char *get_self_path_platform() {
}
#endif

#if defined(__NetBSD__)
#define HAVE_GET_SELF_PATH_PLATFORM
#include <sys/sysctl.h>
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() {
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions release_notes/release_notes.stex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4686f6b

Please sign in to comment.