aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWarner Losh <imp@FreeBSD.org>2022-07-28 21:18:08 +0000
committerWarner Losh <imp@FreeBSD.org>2023-01-24 21:49:28 +0000
commitfce2a0a930a7680a4725746a274d61a7ff84ac9d (patch)
tree14b8b3b3b63646a318e34ef5151859d24effe561
parent1fdf0d96c9db672fb79ea11f24de5c751e161cf9 (diff)
downloadsrc-fce2a0a930a7680a4725746a274d61a7ff84ac9d.tar.gz
src-fce2a0a930a7680a4725746a274d61a7ff84ac9d.zip
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 (cherry picked from commit f56d7a73be6688299c7ec97fac6d505c657aa55c)
-rw-r--r--stand/kboot/arch/aarch64/syscall_nr.h1
-rw-r--r--stand/kboot/arch/amd64/syscall_nr.h1
-rw-r--r--stand/kboot/arch/powerpc64/syscall_nr.h1
-rw-r--r--stand/kboot/host_syscall.h1
-rw-r--r--stand/kboot/host_syscalls.c6
-rw-r--r--stand/kboot/main.c2
6 files changed, 11 insertions, 1 deletions
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();
}