git: f56d7a73be66 - main - kboot: Add host_exit and use it to implement exit()

From: Warner Losh <imp_at_FreeBSD.org>
Date: Thu, 28 Jul 2022 21:37:45 UTC
The branch main has been updated by imp:

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

commit f56d7a73be6688299c7ec97fac6d505c657aa55c
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2022-07-28 21:18:08 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2022-07-28 21:35:42 +0000

    kboot: Add host_exit and use it to implement exit()
    
    Clients of libsa are expected to implement exit(). The current exit just
    loops forever. It is better to really exit: when running as init that
    will reboot the system. When not running as init, other programs can
    recover (not that we support running as init, but when we do in the
    future, this is still the rigtht thing).
    
    Sponsored by: Netflix
---
 stand/kboot/arch/aarch64/syscall_nr.h   | 1 +
 stand/kboot/arch/amd64/syscall_nr.h     | 1 +
 stand/kboot/arch/powerpc64/syscall_nr.h | 1 +
 stand/kboot/host_syscall.h              | 1 +
 stand/kboot/host_syscalls.c             | 6 ++++++
 stand/kboot/main.c                      | 2 +-
 6 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/stand/kboot/arch/aarch64/syscall_nr.h b/stand/kboot/arch/aarch64/syscall_nr.h
index 511d1fa8b2a7..79bf22947e94 100644
--- a/stand/kboot/arch/aarch64/syscall_nr.h
+++ b/stand/kboot/arch/aarch64/syscall_nr.h
@@ -1,5 +1,6 @@
 #define SYS_close		 57
 #define	SYS_dup			 23
+#define SYS_exit		 93
 #define SYS_fstat		 80
 #define SYS_getdents64		 61
 #define	SYS_getpid		172
diff --git a/stand/kboot/arch/amd64/syscall_nr.h b/stand/kboot/arch/amd64/syscall_nr.h
index 71930001c1cf..71469109a55e 100644
--- a/stand/kboot/arch/amd64/syscall_nr.h
+++ b/stand/kboot/arch/amd64/syscall_nr.h
@@ -1,5 +1,6 @@
 #define SYS_close		  3
 #define	SYS_dup			 32
+#define	SYS_exit		 60
 #define SYS_getdents64		217
 #define	SYS_getpid		 39
 #define SYS_gettimeofday	 96
diff --git a/stand/kboot/arch/powerpc64/syscall_nr.h b/stand/kboot/arch/powerpc64/syscall_nr.h
index 0702673c7228..7b425e36c517 100644
--- a/stand/kboot/arch/powerpc64/syscall_nr.h
+++ b/stand/kboot/arch/powerpc64/syscall_nr.h
@@ -1,5 +1,6 @@
 #define SYS_close		  6
 #define	SYS_dup			 41
+#define SYS_exit		  1
 #define SYS_fstat		108
 #define SYS_getdents64		202
 #define	SYS_getpid		 20
diff --git a/stand/kboot/host_syscall.h b/stand/kboot/host_syscall.h
index 9f876952641e..09f5355e520d 100644
--- a/stand/kboot/host_syscall.h
+++ b/stand/kboot/host_syscall.h
@@ -155,6 +155,7 @@ struct host_dirent64 {
  */
 int host_close(int fd);
 int host_dup(int fd);
+int host_exit(int code);
 int host_fstat(int fd, struct host_kstat *sb);
 int host_getdents64(int fd, void *dirp, int count);
 int host_getpid(void);
diff --git a/stand/kboot/host_syscalls.c b/stand/kboot/host_syscalls.c
index 52371021f282..8b364083b15c 100644
--- a/stand/kboot/host_syscalls.c
+++ b/stand/kboot/host_syscalls.c
@@ -19,6 +19,12 @@ host_dup(int fd)
 	return host_syscall(SYS_dup, fd);
 }
 
+int
+host_exit(int code)
+{
+	return host_syscall(SYS_exit, code);
+}
+
 /* Same system call with different names on different Linux architectures due to history */
 int
 host_fstat(int fd, struct host_kstat *sb)
diff --git a/stand/kboot/main.c b/stand/kboot/main.c
index 83ad0ceb8a18..5d40e2c3b582 100644
--- a/stand/kboot/main.c
+++ b/stand/kboot/main.c
@@ -303,7 +303,7 @@ main(int argc, const char **argv)
 void
 exit(int code)
 {
-	while (1); /* XXX: host_exit */
+	host_exit(code);
 	__unreachable();
 }