1 #include "host_syscall.h" 2 #include "syscall_nr.h" 3 #include <stand.h> 4 5 /* 6 * Various trivial wrappers for Linux system calls. Please keep sorted 7 * alphabetically. 8 */ 9 10 int 11 host_close(int fd) 12 { 13 return host_syscall(SYS_close, fd); 14 } 15 16 int 17 host_dup(int fd) 18 { 19 return host_syscall(SYS_dup, fd); 20 } 21 22 int 23 host_exit(int code) 24 { 25 return host_syscall(SYS_exit, code); 26 } 27 28 /* Same system call with different names on different Linux architectures due to history */ 29 int 30 host_fstat(int fd, struct host_kstat *sb) 31 { 32 #ifdef SYS_newfstat 33 return host_syscall(SYS_newfstat, fd, (uintptr_t)sb); 34 #else 35 return host_syscall(SYS_fstat, fd, (uintptr_t)sb); 36 #endif 37 } 38 39 int 40 host_getdents64(int fd, void *dirp, int count) 41 { 42 return host_syscall(SYS_getdents64, fd, (uintptr_t)dirp, count); 43 } 44 45 int 46 host_getpid(void) 47 { 48 return host_syscall(SYS_getpid); 49 } 50 51 int 52 host_gettimeofday(struct host_timeval *a, void *b) 53 { 54 return host_syscall(SYS_gettimeofday, (uintptr_t)a, (uintptr_t)b); 55 } 56 57 int 58 host_ioctl(int fd, unsigned long request, unsigned long arg) 59 { 60 return host_syscall(SYS_ioctl, fd, request, arg); 61 } 62 63 ssize_t 64 host_llseek(int fd, int32_t offset_high, int32_t offset_lo, uint64_t *result, int whence) 65 { 66 #ifdef SYS_llseek 67 return host_syscall(SYS_llseek, fd, offset_high, offset_lo, (uintptr_t)result, whence); 68 #else 69 int64_t rv = host_syscall(SYS_lseek, fd, 70 (int64_t)((uint64_t)offset_high << 32 | (uint32_t)offset_lo), whence); 71 if (rv > 0) 72 *result = (uint64_t)rv; 73 return (rv); 74 #endif 75 } 76 77 int 78 host_kexec_load(unsigned long entry, unsigned long nsegs, struct host_kexec_segment *segs, unsigned long flags) 79 { 80 return host_syscall(SYS_kexec_load, entry, nsegs, segs, flags); 81 } 82 83 int 84 host_mkdir(const char *path, host_mode_t mode) 85 { 86 return host_syscall(SYS_mkdirat, HOST_AT_FDCWD, (uintptr_t)path, mode); 87 } 88 89 void * 90 host_mmap(void *addr, size_t len, int prot, int flags, int fd, off_t off) 91 { 92 return (void *)host_syscall(SYS_mmap, (uintptr_t)addr, len, prot, flags, fd, off); 93 } 94 95 int 96 host_mount(const char *src, const char *target, const char *type, unsigned long flags, 97 void *data) 98 { 99 return host_syscall(SYS_mount, src, target, type, flags, data); 100 } 101 102 int 103 host_munmap(void *addr, size_t len) 104 { 105 return host_syscall(SYS_munmap, (uintptr_t)addr, len); 106 } 107 108 int 109 host_open(const char *path, int flags, int mode) 110 { 111 return host_syscall(SYS_openat, HOST_AT_FDCWD, (uintptr_t)path, flags, mode); 112 /* XXX original overrode errors */ 113 } 114 115 ssize_t 116 host_read(int fd, void *buf, size_t nbyte) 117 { 118 return host_syscall(SYS_read, fd, (uintptr_t)buf, nbyte); 119 /* XXX original overrode errors */ 120 } 121 122 int 123 host_reboot(int magic1, int magic2, int cmd, uintptr_t arg) 124 { 125 return host_syscall(SYS_reboot, magic1, magic2, cmd, arg); 126 } 127 128 int 129 host_select(int nfds, long *readfds, long *writefds, long *exceptfds, 130 struct host_timeval *timeout) 131 { 132 struct timespec ts = { .tv_sec = timeout->tv_sec, .tv_nsec = timeout->tv_usec * 1000 }; 133 134 /* 135 * Note, final arg is a sigset_argpack since most arch can only have 6 136 * syscall args. Since we're not masking signals, though, we can just 137 * pass a NULL. 138 */ 139 return host_syscall(SYS_pselect6, nfds, (uintptr_t)readfds, (uintptr_t)writefds, 140 (uintptr_t)exceptfds, (uintptr_t)&ts, (uintptr_t)NULL); 141 } 142 143 int 144 host_stat(const char *path, struct host_kstat *sb) 145 { 146 return host_syscall(SYS_newfstatat, HOST_AT_FDCWD, (uintptr_t)path, (uintptr_t)sb, 0); 147 } 148 149 int 150 host_symlink(const char *path1, const char *path2) 151 { 152 return host_syscall(SYS_symlinkat, HOST_AT_FDCWD, path1, path2); 153 } 154 155 int 156 host_uname(struct old_utsname *uts) 157 { 158 return host_syscall(SYS_uname, (uintptr_t)uts); 159 } 160 161 ssize_t 162 host_write(int fd, const void *buf, size_t nbyte) 163 { 164 return host_syscall(SYS_write, fd, (uintptr_t)buf, nbyte); 165 } 166