From bc84de741dfd3b81cc7d332f8e6f0d84afe4eee1 Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Thu, 30 Jun 2022 12:25:49 -0600 Subject: [PATCH] kboot: Implement dup(2) Early in boot, we need to create the normal stdin/out/err env for the boot loader to run in. To do that, we need to open the console and duplicate the file descriptors which requires dup(2). Implement a wrapper as host_dup. Sponsored by: Netflix --- 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 ++++++ 4 files changed, 9 insertions(+) diff --git a/stand/kboot/arch/amd64/syscall_nr.h b/stand/kboot/arch/amd64/syscall_nr.h index 756b3e93af9..62deefe7353 100644 --- a/stand/kboot/arch/amd64/syscall_nr.h +++ b/stand/kboot/arch/amd64/syscall_nr.h @@ -1,4 +1,5 @@ #define SYS_close 3 +#define SYS_dup 32 #define SYS_getdents 78 #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 13f26d80f6a..d6678d9044d 100644 --- a/stand/kboot/arch/powerpc64/syscall_nr.h +++ b/stand/kboot/arch/powerpc64/syscall_nr.h @@ -1,4 +1,5 @@ #define SYS_close 6 +#define SYS_dup 41 #define SYS_fstat 108 #define SYS_getdents 141 #define SYS_getpid 20 diff --git a/stand/kboot/host_syscall.h b/stand/kboot/host_syscall.h index 3b02f2e7830..10d4166514b 100644 --- a/stand/kboot/host_syscall.h +++ b/stand/kboot/host_syscall.h @@ -92,6 +92,7 @@ struct host_timeval { * System Calls */ int host_close(int fd); +int host_dup(int fd); int host_fstat(int fd, struct host_kstat *sb); int host_getdents(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 a69937a5a0e..2fe4c599df8 100644 --- a/stand/kboot/host_syscalls.c +++ b/stand/kboot/host_syscalls.c @@ -13,6 +13,12 @@ host_close(int fd) return host_syscall(SYS_close, fd); } +int +host_dup(int fd) +{ + return host_syscall(SYS_dup, fd); +} + int host_fstat(int fd, struct host_kstat *sb) {