git: 4bae1d08388f - stable/13 - kboot: Reimplement older system calls in terms of newer ones

From: Warner Losh <imp_at_FreeBSD.org>
Date: Tue, 24 Jan 2023 22:10:52 UTC
The branch stable/13 has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=4bae1d08388f806e0b875eb8693e4e45582f326c

commit 4bae1d08388f806e0b875eb8693e4e45582f326c
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2022-07-07 22:58:27 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2023-01-24 21:49:23 +0000

    kboot: Reimplement older system calls in terms of newer ones
    
    aarch64 doesn't have open, just openat, etc. Cope.
    
    Sponsored by:           Netflix
    
    (cherry picked from commit edc23ddf9cf35d7ea9baf72d14449e04508d2314)
---
 stand/kboot/arch/amd64/syscall_nr.h     |  6 +++---
 stand/kboot/arch/powerpc64/syscall_nr.h |  4 ++--
 stand/kboot/host_syscall.h              |  2 ++
 stand/kboot/host_syscalls.c             | 12 ++++++++++--
 4 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/stand/kboot/arch/amd64/syscall_nr.h b/stand/kboot/arch/amd64/syscall_nr.h
index 9c4fb1024319..506f85b3e731 100644
--- a/stand/kboot/arch/amd64/syscall_nr.h
+++ b/stand/kboot/arch/amd64/syscall_nr.h
@@ -1,13 +1,13 @@
 #define SYS_close		  3
 #define SYS_getdents		 78
 #define SYS_gettimeofday	 96
-#define SYS_lseek		  8
 #define SYS_kexec_load		246
+#define SYS_lseek		  8
 #define SYS_mmap		  9
-#define SYS_open		  2
+#define SYS_openat		257
+#define SYS_pselect6		270
 #define SYS_read		  0
 #define SYS_reboot		169
-#define SYS_select		 23
 #define SYS_uname		 63
 #define SYS_write		  1
 
diff --git a/stand/kboot/arch/powerpc64/syscall_nr.h b/stand/kboot/arch/powerpc64/syscall_nr.h
index 187c434a13d7..592f3d6a7631 100644
--- a/stand/kboot/arch/powerpc64/syscall_nr.h
+++ b/stand/kboot/arch/powerpc64/syscall_nr.h
@@ -4,10 +4,10 @@
 #define SYS_kexec_load		268
 #define SYS_llseek		140
 #define SYS_mmap		 90
-#define SYS_open		  5
+#define SYS_openat		286
+#define SYS_pselect6		280
 #define SYS_read		  3
 #define SYS_reboot		 88
-#define SYS_select		142
 #define SYS_uname		120
 #define SYS_write		  4
 
diff --git a/stand/kboot/host_syscall.h b/stand/kboot/host_syscall.h
index 3a640af30565..b13829e4d05b 100644
--- a/stand/kboot/host_syscall.h
+++ b/stand/kboot/host_syscall.h
@@ -48,6 +48,8 @@ struct host_timeval {
 	long tv_usec;
 };
 
+#define HOST_AT_FDCWD		-100		/* Relative to current directory */
+
 /*
  * System Calls
  */
diff --git a/stand/kboot/host_syscalls.c b/stand/kboot/host_syscalls.c
index 66014462ccdd..3db066acb781 100644
--- a/stand/kboot/host_syscalls.c
+++ b/stand/kboot/host_syscalls.c
@@ -54,7 +54,7 @@ host_mmap(void *addr, size_t len, int prot, int flags, int fd, off_t off)
 int
 host_open(const char *path, int flags, int mode)
 {
-	return host_syscall(SYS_open, (uintptr_t)path, flags, mode);
+	return host_syscall(SYS_openat, HOST_AT_FDCWD, (uintptr_t)path, flags, mode);
 	/* XXX original overrode errors */
 }
 
@@ -75,7 +75,15 @@ int
 host_select(int nfds, long *readfds, long *writefds, long *exceptfds,
     struct host_timeval *timeout)
 {
-	return host_syscall(SYS_select, nfds, (uintptr_t)readfds, (uintptr_t)writefds, (uintptr_t)exceptfds, (uintptr_t)timeout, 0);
+	struct timespec ts = { .tv_sec = timeout->tv_sec, .tv_nsec = timeout->tv_usec * 1000 };
+
+	/*
+	 * Note, final arg is a sigset_argpack since most arch can only have 6
+	 * syscall args. Since we're not masking signals, though, we can just
+	 * pass a NULL.
+	 */
+	return host_syscall(SYS_pselect6, nfds, (uintptr_t)readfds, (uintptr_t)writefds,
+	    (uintptr_t)exceptfds, (uintptr_t)&ts, (uintptr_t)NULL);
 }
 
 int