Path: blob/main/stand/kboot/libkboot/host_syscalls.c
34860 views
/*1* Copyright (c) 2022-2024, Netflix, Inc.2*3* SPDX-License-Identifier: BSD-2-Clause4*/56#include "host_syscall.h"7#include "syscall_nr.h"8#include <stand.h>910/*11* Various trivial wrappers for Linux system calls. Please keep sorted12* alphabetically.13*/1415int16host_close(int fd)17{18return host_syscall(SYS_close, fd);19}2021int22host_dup(int fd)23{24return host_syscall(SYS_dup, fd);25}2627int28host_exit(int code)29{30return host_syscall(SYS_exit, code);31}3233/* Same system call with different names on different Linux architectures due to history */34int35host_fstat(int fd, struct host_kstat *sb)36{37#ifdef SYS_newfstat38return host_syscall(SYS_newfstat, fd, (uintptr_t)sb);39#else40return host_syscall(SYS_fstat, fd, (uintptr_t)sb);41#endif42}4344int45host_getdents64(int fd, void *dirp, int count)46{47return host_syscall(SYS_getdents64, fd, (uintptr_t)dirp, count);48}4950int51host_getpid(void)52{53return host_syscall(SYS_getpid);54}5556int57host_gettimeofday(struct host_timeval *a, void *b)58{59return host_syscall(SYS_gettimeofday, (uintptr_t)a, (uintptr_t)b);60}6162int63host_ioctl(int fd, unsigned long request, unsigned long arg)64{65return host_syscall(SYS_ioctl, fd, request, arg);66}6768ssize_t69host_llseek(int fd, int32_t offset_high, int32_t offset_lo, uint64_t *result, int whence)70{71#ifdef SYS_llseek72return host_syscall(SYS_llseek, fd, offset_high, offset_lo, (uintptr_t)result, whence);73#else74int64_t rv = host_syscall(SYS_lseek, fd,75(int64_t)((uint64_t)offset_high << 32 | (uint32_t)offset_lo), whence);76if (rv > 0)77*result = (uint64_t)rv;78return (rv);79#endif80}8182int83host_kexec_load(unsigned long entry, unsigned long nsegs, struct host_kexec_segment *segs, unsigned long flags)84{85return host_syscall(SYS_kexec_load, entry, nsegs, segs, flags);86}8788int89host_mkdir(const char *path, host_mode_t mode)90{91return host_syscall(SYS_mkdirat, HOST_AT_FDCWD, (uintptr_t)path, mode);92}9394void *95host_mmap(void *addr, size_t len, int prot, int flags, int fd, off_t off)96{97return (void *)host_syscall(SYS_mmap, (uintptr_t)addr, len, prot, flags, fd, off);98}99100int101host_mount(const char *src, const char *target, const char *type, unsigned long flags,102void *data)103{104return host_syscall(SYS_mount, src, target, type, flags, data);105}106107int108host_munmap(void *addr, size_t len)109{110return host_syscall(SYS_munmap, (uintptr_t)addr, len);111}112113int114host_open(const char *path, int flags, int mode)115{116return host_syscall(SYS_openat, HOST_AT_FDCWD, (uintptr_t)path, flags, mode);117/* XXX original overrode errors */118}119120ssize_t121host_read(int fd, void *buf, size_t nbyte)122{123return host_syscall(SYS_read, fd, (uintptr_t)buf, nbyte);124/* XXX original overrode errors */125}126127int128host_reboot(int magic1, int magic2, int cmd, uintptr_t arg)129{130return host_syscall(SYS_reboot, magic1, magic2, cmd, arg);131}132133int134host_select(int nfds, long *readfds, long *writefds, long *exceptfds,135struct host_timeval *timeout)136{137struct timespec ts = { .tv_sec = timeout->tv_sec, .tv_nsec = timeout->tv_usec * 1000 };138139/*140* Note, final arg is a sigset_argpack since most arch can only have 6141* syscall args. Since we're not masking signals, though, we can just142* pass a NULL.143*/144return host_syscall(SYS_pselect6, nfds, (uintptr_t)readfds, (uintptr_t)writefds,145(uintptr_t)exceptfds, (uintptr_t)&ts, (uintptr_t)NULL);146}147148int149host_stat(const char *path, struct host_kstat *sb)150{151return host_syscall(SYS_newfstatat, HOST_AT_FDCWD, (uintptr_t)path, (uintptr_t)sb, 0);152}153154int155host_symlink(const char *path1, const char *path2)156{157return host_syscall(SYS_symlinkat, HOST_AT_FDCWD, path1, path2);158}159160int161host_uname(struct old_utsname *uts)162{163return host_syscall(SYS_uname, (uintptr_t)uts);164}165166ssize_t167host_write(int fd, const void *buf, size_t nbyte)168{169return host_syscall(SYS_write, fd, (uintptr_t)buf, nbyte);170}171172173