diff --git a/stand/kboot/include/arch/aarch64/syscall_nr.h b/stand/kboot/include/arch/aarch64/syscall_nr.h index 83069dd8dc76..5c776db81d03 100644 --- a/stand/kboot/include/arch/aarch64/syscall_nr.h +++ b/stand/kboot/include/arch/aarch64/syscall_nr.h @@ -1,22 +1,26 @@ +/* + * This file is in the public domain. It only recounts facts in the only way + * possible. + */ #define SYS_close 57 #define SYS_dup 23 #define SYS_exit 93 #define SYS_fstat 80 #define SYS_getdents64 61 #define SYS_getpid 172 #define SYS_gettimeofday 169 #define SYS_ioctl 29 #define SYS_lseek 62 #define SYS_kexec_load 104 #define SYS_mkdirat 34 #define SYS_mmap 222 #define SYS_mount 40 #define SYS_munmap 215 #define SYS_newfstatat 79 #define SYS_openat 56 #define SYS_pselect6 72 #define SYS_read 63 #define SYS_reboot 142 #define SYS_symlinkat 36 #define SYS_uname 160 #define SYS_write 64 diff --git a/stand/kboot/include/arch/amd64/syscall_nr.h b/stand/kboot/include/arch/amd64/syscall_nr.h index 2cf26d7ca4dc..705b39c62f44 100644 --- a/stand/kboot/include/arch/amd64/syscall_nr.h +++ b/stand/kboot/include/arch/amd64/syscall_nr.h @@ -1,22 +1,26 @@ +/* + * This file is in the public domain. It only recounts facts in the only way + * possible. + */ #define SYS_close 3 #define SYS_dup 32 #define SYS_exit 60 #define SYS_getdents64 217 #define SYS_getpid 39 #define SYS_gettimeofday 96 #define SYS_ioctl 16 #define SYS_kexec_load 246 #define SYS_lseek 8 #define SYS_mkdirat 258 #define SYS_mmap 9 #define SYS_mount 165 #define SYS_munmap 11 #define SYS_newfstat 5 #define SYS_newfstatat 262 #define SYS_openat 257 #define SYS_pselect6 270 #define SYS_read 0 #define SYS_reboot 169 #define SYS_symlinkat 266 #define SYS_uname 63 #define SYS_write 1 diff --git a/stand/kboot/include/arch/powerpc64/syscall_nr.h b/stand/kboot/include/arch/powerpc64/syscall_nr.h index 735e79a09158..50946a4f058c 100644 --- a/stand/kboot/include/arch/powerpc64/syscall_nr.h +++ b/stand/kboot/include/arch/powerpc64/syscall_nr.h @@ -1,22 +1,26 @@ +/* + * This file is in the public domain. It only recounts facts in the only way + * possible. + */ #define SYS_close 6 #define SYS_dup 41 #define SYS_exit 1 #define SYS_fstat 108 #define SYS_getdents64 202 #define SYS_getpid 20 #define SYS_gettimeofday 78 #define SYS_ioctl 54 #define SYS_kexec_load 268 #define SYS_llseek 140 #define SYS_mkdirat 287 #define SYS_mmap 90 #define SYS_mount 21 #define SYS_munmap 91 #define SYS_newfstatat 291 #define SYS_openat 286 #define SYS_pselect6 280 #define SYS_read 3 #define SYS_reboot 88 #define SYS_symlinkat 295 #define SYS_uname 120 #define SYS_write 4 diff --git a/stand/kboot/libkboot/host_syscalls.c b/stand/kboot/libkboot/host_syscalls.c index 092ddfd133fd..551ff6b777d6 100644 --- a/stand/kboot/libkboot/host_syscalls.c +++ b/stand/kboot/libkboot/host_syscalls.c @@ -1,165 +1,171 @@ +/* + * Copyright (c) 2022-2024, Netflix, Inc. + * + * SPDX-License-Identifier: BSD-2-Clause + */ + #include "host_syscall.h" #include "syscall_nr.h" #include /* * Various trivial wrappers for Linux system calls. Please keep sorted * alphabetically. */ int host_close(int fd) { return host_syscall(SYS_close, fd); } int 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) { #ifdef SYS_newfstat return host_syscall(SYS_newfstat, fd, (uintptr_t)sb); #else return host_syscall(SYS_fstat, fd, (uintptr_t)sb); #endif } int host_getdents64(int fd, void *dirp, int count) { return host_syscall(SYS_getdents64, fd, (uintptr_t)dirp, count); } int host_getpid(void) { return host_syscall(SYS_getpid); } int host_gettimeofday(struct host_timeval *a, void *b) { return host_syscall(SYS_gettimeofday, (uintptr_t)a, (uintptr_t)b); } int host_ioctl(int fd, unsigned long request, unsigned long arg) { return host_syscall(SYS_ioctl, fd, request, arg); } ssize_t host_llseek(int fd, int32_t offset_high, int32_t offset_lo, uint64_t *result, int whence) { #ifdef SYS_llseek return host_syscall(SYS_llseek, fd, offset_high, offset_lo, (uintptr_t)result, whence); #else int64_t rv = host_syscall(SYS_lseek, fd, (int64_t)((uint64_t)offset_high << 32 | (uint32_t)offset_lo), whence); if (rv > 0) *result = (uint64_t)rv; return (rv); #endif } int host_kexec_load(unsigned long entry, unsigned long nsegs, struct host_kexec_segment *segs, unsigned long flags) { return host_syscall(SYS_kexec_load, entry, nsegs, segs, flags); } int host_mkdir(const char *path, host_mode_t mode) { return host_syscall(SYS_mkdirat, HOST_AT_FDCWD, (uintptr_t)path, mode); } void * host_mmap(void *addr, size_t len, int prot, int flags, int fd, off_t off) { return (void *)host_syscall(SYS_mmap, (uintptr_t)addr, len, prot, flags, fd, off); } int host_mount(const char *src, const char *target, const char *type, unsigned long flags, void *data) { return host_syscall(SYS_mount, src, target, type, flags, data); } int host_munmap(void *addr, size_t len) { return host_syscall(SYS_munmap, (uintptr_t)addr, len); } int host_open(const char *path, int flags, int mode) { return host_syscall(SYS_openat, HOST_AT_FDCWD, (uintptr_t)path, flags, mode); /* XXX original overrode errors */ } ssize_t host_read(int fd, void *buf, size_t nbyte) { return host_syscall(SYS_read, fd, (uintptr_t)buf, nbyte); /* XXX original overrode errors */ } int host_reboot(int magic1, int magic2, int cmd, uintptr_t arg) { return host_syscall(SYS_reboot, magic1, magic2, cmd, arg); } int host_select(int nfds, long *readfds, long *writefds, long *exceptfds, struct host_timeval *timeout) { 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 host_stat(const char *path, struct host_kstat *sb) { return host_syscall(SYS_newfstatat, HOST_AT_FDCWD, (uintptr_t)path, (uintptr_t)sb, 0); } int host_symlink(const char *path1, const char *path2) { return host_syscall(SYS_symlinkat, HOST_AT_FDCWD, path1, path2); } int host_uname(struct old_utsname *uts) { return host_syscall(SYS_uname, (uintptr_t)uts); } ssize_t host_write(int fd, const void *buf, size_t nbyte) { return host_syscall(SYS_write, fd, (uintptr_t)buf, nbyte); }