# ============================================================================ # 系统调用号表(SDK 侧镜像,由 Scripts/syscall_table.py 生成,禁止手改)。 # 编号口径:与 Linux x86-64 ABI 同名同号;Linux 有而尚未实现的调用暂不占号。 # ============================================================================ # BEGIN GENERATED SYSCALL TABLE enum Syscall: # ---- Linux 对齐段(号 = Linux x86-64 的号) ---- READ = 0 # read(fd, buf, count) WRITE = 1 # write(fd, buf, count) OPEN = 2 # open(path, flags) - Linux O_* CLOSE = 3 # close(fd) STAT = 4 # stat(path, fileinfo*) - legacy struct FSTAT = 5 # fstat(fd, struct stat*) POLL = 7 # poll(fds, nfds, timeout) - stub 0 SEEK = 8 # lseek(fd, offset, whence) -> new offset MMAP = 9 # mmap(addr, len, prot, flags, fd, off) MPROTECT = 10 # mprotect(addr, len, prot) MUNMAP = 11 # munmap(addr, len) BRK = 12 # brk(addr) -> new break RT_SIGACTION = 13 # rt_sigaction() - bookkeeping RT_SIGPROCMASK = 14 # rt_sigprocmask() - bookkeeping RT_SIGRETURN = 15 # rt_sigreturn() IOCTL = 16 # ioctl(fd, request, arg) PREAD64 = 17 # pread64(fd, buf, count, offset) PWRITE64 = 18 # pwrite64(fd, buf, count, offset) READV = 19 # readv(fd, iov, iovcnt) WRITEV = 20 # writev(fd, iov, iovcnt) ACCESS = 21 # access(path, mode) PIPE = 22 # pipe(int[2]) YIELD = 24 # sched_yield() MREMAP = 25 # mremap(old, oldsz, newsz, flags, newaddr) MADVISE = 28 # madvise(addr, len, advice) DUP = 32 # dup(fd) DUP2 = 33 # dup2(oldfd, newfd) NANOSLEEP = 35 # nanosleep(req, rem) GETPID = 39 # getpid() CLONE = 56 # clone(flags, stack, ptid, ctid, tls) FORK = 57 # fork() - copy address space SPAWN = 59 # execve(path, argv, envp) THREAD_EXIT = 60 # exit(): retire current thread WAIT4 = 61 # wait4(pid, status, options, rusage) KILL = 62 # kill(pid, sig) - bookkeeping UNAME = 63 # uname(utsname*) FCNTL = 72 # fcntl(fd, cmd, arg) GETCWD = 79 # getcwd(buf, size) CHDIR = 80 # chdir(path) RENAME = 82 # rename(old, new) MKDIR = 83 # mkdir(path) RMDIR = 84 # rmdir(path) REMOVE = 87 # unlink(path) READLINK = 89 # readlink(path, buf, size) - no symlinks GETUID = 102 # getuid() GETGID = 104 # getgid() GETEUID = 107 # geteuid() GETEGID = 108 # getegid() GETTIMEOFDAY = 96 # gettimeofday(tv, tz) GETPPID = 110 # getppid() ARCH_PRCTL = 158 # arch_prctl(code, addr) REBOOT_LINUX = 169 # reboot(magic1, magic2, cmd, arg) GETTID = 186 # gettid() FUTEX = 202 # futex(uaddr, op, val, timeout) GETDENTS64 = 217 # getdents64(fd, buf, count) SET_TID_ADDRESS = 218 # set_tid_address(tidptr) CLOCK_GETTIME = 228 # clock_gettime(clockid, timespec*) CLOCK_GETRES = 229 # clock_getres(clockid, timespec*) EXIT = 231 # exit_group(): terminate all threads OPENAT = 257 # openat(dirfd, path, flags, mode) NEWFSTATAT = 262 # newfstatat(dirfd, path, stat*, flags) UNLINKAT = 263 # unlinkat(dirfd, path, flags) READLINKAT = 267 # readlinkat(dirfd, path, buf, size) FACCESSAT = 269 # faccessat(dirfd, path, mode, flags) SET_ROBUST_LIST = 273 # set_robust_list(head, len) DUP3 = 292 # dup3(oldfd, newfd, flags) PIPE2 = 293 # pipe2(int[2], flags) PRLIMIT64 = 302 # prlimit64(pid, resource, new, old) GETRANDOM = 318 # getrandom(buf, len, flags) STATX = 332 # statx(...) - -ENOSYS, glibc falls back RSEQ = 334 # rseq(rseq, len, flags) - -ENOSYS # ---- 临时私有段(0x1000+):Linux 无对应,逐条迁出 ---- LOAD_SO = 0x1006 # TODO(userspace): dynamic library loading SO_CALL1 = 0x1007 # TODO(userspace): dynamic library call REBOOT = 0x1008 # TODO(linux): reboot(169) SHUTDOWN = 0x1009 # TODO(linux): reboot(RB_POWER_OFF) SPAWN_PROC = 0x100A # TODO(userspace): Terminal run helper THREAD_CREATE_OLD = 0x100B # TODO(userspace): ViperOS thread_create # END GENERATED SYSCALL TABLE # ---- mmap 的 prot / flags(与内核 VKernel/intr/syscall.vp 及各 Linux 同名常量一致)---- define PROT_NONE = 0x0 define PROT_READ = 0x1 define PROT_WRITE = 0x2 define PROT_EXEC = 0x4 define MAP_SHARED = 0x01 define MAP_PRIVATE = 0x02 define MAP_FIXED = 0x10 define MAP_ANONYMOUS = 0x20 # fd = -1(Linux 匿名映射约定) define MMAP_FD_ANON: uint64 = 0xFFFFFFFFFFFFFFFF define MAP_FAILED: uint64 = 0xFFFFFFFFFFFFFFFF define MREMAP_MAYMOVE = 1 define MREMAP_FIXED = 2 # ---- AT_* / fcntl(Linux 值)---- define AT_FDCWD = -100 define AT_SYMLINK_NOFOLLOW = 256 define AT_REMOVEDIR = 512 define AT_EMPTY_PATH = 4096 define F_DUPFD = 0 define F_GETFD = 1 define F_SETFD = 2 define F_GETFL = 3 define F_SETFL = 4 define F_DUPFD_CLOEXEC = 1030 define FD_CLOEXEC = 1 # ---- TLS / futex / time / wait / reboot ---- define ARCH_SET_GS = 0x1001 define ARCH_SET_FS = 0x1002 define ARCH_GET_FS = 0x1003 define ARCH_GET_GS = 0x1004 define FUTEX_WAIT = 0 define FUTEX_WAKE = 1 define FUTEX_PRIVATE_FLAG = 128 define CLOCK_REALTIME = 0 define CLOCK_MONOTONIC = 1 define WNOHANG = 1 define LINUX_REBOOT_MAGIC1 = 0xFEE1DEAD define LINUX_REBOOT_MAGIC2 = 672274793 define LINUX_REBOOT_CMD_RESTART = 0x01234567 define LINUX_REBOOT_CMD_POWER_OFF = 0x4321FEDC def _syscall0(num: uint64) -> uint64: ret: uint64 __asm__(f"""mov rax, {asminp(num, ASM_DESCR.REG_ANY)} syscall""", out=[asmout(ret, ASM_DESCR.OUTPUT_REG)], op=[ASM_DESCR.CLOBBER_MEMORY, ASM_DESCR.CLOBBER_RCX, ASM_DESCR.CLOBBER_R11]) return ret def _syscall1(num: uint64, a1: uint64) -> uint64: ret: uint64 __asm__(f"""mov rdi, {asminp(a1, ASM_DESCR.REG_ANY)} mov rax, {asminp(num, ASM_DESCR.REG_ANY)} syscall""", out=[asmout(ret, ASM_DESCR.OUTPUT_REG)], op=[ASM_DESCR.CLOBBER_MEMORY, ASM_DESCR.CLOBBER_RCX, ASM_DESCR.CLOBBER_R11, ASM_DESCR.CLOBBER_RDI]) return ret def _syscall2(num: uint64, a1: uint64, a2: uint64) -> uint64: ret: uint64 __asm__(f"""mov rdi, {asminp(a1, ASM_DESCR.REG_ANY)} mov rsi, {asminp(a2, ASM_DESCR.REG_ANY)} mov rax, {asminp(num, ASM_DESCR.REG_ANY)} syscall""", out=[asmout(ret, ASM_DESCR.OUTPUT_REG)], op=[ASM_DESCR.CLOBBER_MEMORY, ASM_DESCR.CLOBBER_RCX, ASM_DESCR.CLOBBER_R11, ASM_DESCR.CLOBBER_RDI, ASM_DESCR.CLOBBER_RSI]) return ret def _syscall3(num: uint64, a1: uint64, a2: uint64, a3: uint64) -> uint64: ret: uint64 __asm__(f"""mov rdi, {asminp(a1, ASM_DESCR.REG_ANY)} mov rsi, {asminp(a2, ASM_DESCR.REG_ANY)} mov rdx, {asminp(a3, ASM_DESCR.REG_ANY)} mov rax, {asminp(num, ASM_DESCR.REG_ANY)} syscall""", out=[asmout(ret, ASM_DESCR.OUTPUT_REG)], op=[ASM_DESCR.CLOBBER_MEMORY, ASM_DESCR.CLOBBER_RCX, ASM_DESCR.CLOBBER_R11, ASM_DESCR.CLOBBER_RDI, ASM_DESCR.CLOBBER_RSI, ASM_DESCR.CLOBBER_RDX]) return ret def _syscall4(num: uint64, a1: uint64, a2: uint64, a3: uint64, a4: uint64) -> uint64: ret: uint64 __asm__(f"""mov rdi, {asminp(a1, ASM_DESCR.REG_ANY)} mov rsi, {asminp(a2, ASM_DESCR.REG_ANY)} mov rdx, {asminp(a3, ASM_DESCR.REG_ANY)} mov r10, {asminp(a4, ASM_DESCR.REG_ANY)} mov rax, {asminp(num, ASM_DESCR.REG_ANY)} syscall""", out=[asmout(ret, ASM_DESCR.OUTPUT_REG)], op=[ASM_DESCR.CLOBBER_MEMORY, ASM_DESCR.CLOBBER_RCX, ASM_DESCR.CLOBBER_R11, ASM_DESCR.CLOBBER_RDI, ASM_DESCR.CLOBBER_RSI, ASM_DESCR.CLOBBER_RDX, ASM_DESCR.CLOBBER_R10]) return ret def _syscall5(num: uint64, a1: uint64, a2: uint64, a3: uint64, a4: uint64, a5: uint64) -> uint64: ret: uint64 __asm__(f"""mov rdi, {asminp(a1, ASM_DESCR.REG_ANY)} mov rsi, {asminp(a2, ASM_DESCR.REG_ANY)} mov rdx, {asminp(a3, ASM_DESCR.REG_ANY)} mov r10, {asminp(a4, ASM_DESCR.REG_ANY)} mov r8, {asminp(a5, ASM_DESCR.REG_ANY)} mov rax, {asminp(num, ASM_DESCR.REG_ANY)} syscall""", out=[asmout(ret, ASM_DESCR.OUTPUT_REG)], op=[ASM_DESCR.CLOBBER_MEMORY, ASM_DESCR.CLOBBER_RCX, ASM_DESCR.CLOBBER_R11, ASM_DESCR.CLOBBER_RDI, ASM_DESCR.CLOBBER_RSI, ASM_DESCR.CLOBBER_RDX, ASM_DESCR.CLOBBER_R10, ASM_DESCR.CLOBBER_R8]) return ret def _syscall6(num: uint64, a1: uint64, a2: uint64, a3: uint64, a4: uint64, a5: uint64, a6: uint64) -> uint64: ret: uint64 __asm__(f"""mov rdi, {asminp(a1, ASM_DESCR.REG_ANY)} mov rsi, {asminp(a2, ASM_DESCR.REG_ANY)} mov rdx, {asminp(a3, ASM_DESCR.REG_ANY)} mov r10, {asminp(a4, ASM_DESCR.REG_ANY)} mov r8, {asminp(a5, ASM_DESCR.REG_ANY)} mov r9, {asminp(a6, ASM_DESCR.REG_ANY)} mov rax, {asminp(num, ASM_DESCR.REG_ANY)} syscall""", out=[asmout(ret, ASM_DESCR.OUTPUT_REG)], op=[ASM_DESCR.CLOBBER_MEMORY, ASM_DESCR.CLOBBER_RCX, ASM_DESCR.CLOBBER_R11, ASM_DESCR.CLOBBER_RDI, ASM_DESCR.CLOBBER_RSI, ASM_DESCR.CLOBBER_RDX, ASM_DESCR.CLOBBER_R10, ASM_DESCR.CLOBBER_R8, ASM_DESCR.CLOBBER_R9]) return ret def mmap(addr: uint64, length: uint64, prot: uint64, flags: uint64, fd: uint64, offset: uint64) -> uint64: """mmap(addr, length, prot, flags, fd, offset):返回映射起始 VA。 内核遵循 Linux 语义(失败返回 MAP_FAILED = -1);SDK 为兼容既有调用方 把它归一化为 0(C 代码里判 `== 0`)。 """ va: uint64 = _syscall6(uint64(Syscall.MMAP), addr, length, prot, flags, fd, offset) if va == MAP_FAILED: return uint64(0) return va def munmap(addr: uint64, length: uint64) -> int: return int(_syscall2(uint64(Syscall.MUNMAP), addr, length)) def mprotect(addr: uint64, length: uint64, prot: uint64) -> int: return int(_syscall3(uint64(Syscall.MPROTECT), addr, length, prot)) def brk(addr: uint64) -> uint64: return _syscall1(uint64(Syscall.BRK), addr) def mremap(old_addr: uint64, old_size: uint64, new_size: uint64, flags: uint64, new_addr: uint64 = 0) -> uint64: va: uint64 = _syscall5(uint64(Syscall.MREMAP), old_addr, old_size, new_size, flags, new_addr) if va == MAP_FAILED: return uint64(0) return va def madvise(addr: uint64, length: uint64, advice: uint32) -> int: return int(_syscall3(uint64(Syscall.MADVISE), addr, length, uint64(advice))) # ============================================================================ # P0 flat wrappers (Linux ABI). Higher level helpers live in vpsdk.fs / process. # ============================================================================ def uname(buf: rawptr) -> int: return int(_syscall1(uint64(Syscall.UNAME), uint64(buf))) def getuid() -> int: return int(_syscall0(uint64(Syscall.GETUID))) def geteuid() -> int: return int(_syscall0(uint64(Syscall.GETEUID))) def getgid() -> int: return int(_syscall0(uint64(Syscall.GETGID))) def getegid() -> int: return int(_syscall0(uint64(Syscall.GETEGID))) def getppid() -> int: return int(_syscall0(uint64(Syscall.GETPPID))) def gettid() -> int: return int(_syscall0(uint64(Syscall.GETTID))) def getcwd(buf: rawptr, size: uint64) -> int: return int(_syscall2(uint64(Syscall.GETCWD), uint64(buf), size)) def chdir(path: const str) -> int: return int(_syscall1(uint64(Syscall.CHDIR), uint64(path))) def access(path: const str, mode: uint32) -> int: return int(_syscall2(uint64(Syscall.ACCESS), uint64(path), uint64(mode))) def faccessat(dirfd: int, path: const str, mode: uint32, flags: uint32) -> int: return int(_syscall4(uint64(Syscall.FACCESSAT), uint64(dirfd), uint64(path), uint64(mode), uint64(flags))) def readlink(path: const str, buf: rawptr, size: uint64) -> int: return int(_syscall3(uint64(Syscall.READLINK), uint64(path), uint64(buf), size)) def readlinkat(dirfd: int, path: const str, buf: rawptr, size: uint64) -> int: return int(_syscall4(uint64(Syscall.READLINKAT), uint64(dirfd), uint64(path), uint64(buf), size)) def set_tid_address(tidptr: rawptr) -> int: return int(_syscall1(uint64(Syscall.SET_TID_ADDRESS), uint64(tidptr))) def set_robust_list(head: rawptr, length: uint64) -> int: return int(_syscall2(uint64(Syscall.SET_ROBUST_LIST), uint64(head), length)) def rseq(rseq_ptr: rawptr, length: uint32, flags: uint32) -> int: return int(_syscall3(uint64(Syscall.RSEQ), uint64(rseq_ptr), uint64(length), uint64(flags))) def prlimit64(pid: int, resource: uint32, new_limit: rawptr, old_limit: rawptr) -> int: return int(_syscall4(uint64(Syscall.PRLIMIT64), uint64(pid), uint64(resource), uint64(new_limit), uint64(old_limit))) def getrandom(buf: rawptr, length: uint64, flags: uint32) -> int: return int(_syscall3(uint64(Syscall.GETRANDOM), uint64(buf), length, uint64(flags))) # ---------------------------------------------------------------- P1 ---- def openat(dirfd: int, path: const str, flags: uint32, mode: uint32 = 0) -> int: return int(_syscall4(uint64(Syscall.OPENAT), uint64(dirfd), uint64(path), uint64(flags), uint64(mode))) def fstat(fd: int, st: rawptr) -> int: return int(_syscall2(uint64(Syscall.FSTAT), uint64(fd), uint64(st))) def newfstatat(dirfd: int, path: const str, st: rawptr, flags: uint32) -> int: return int(_syscall4(uint64(Syscall.NEWFSTATAT), uint64(dirfd), uint64(path), uint64(st), uint64(flags))) def getdents64(fd: int, buf: rawptr, count: uint64) -> int: return int(_syscall3(uint64(Syscall.GETDENTS64), uint64(fd), uint64(buf), count)) def dup(fd: int) -> int: return int(_syscall1(uint64(Syscall.DUP), uint64(fd))) def dup2(oldfd: int, newfd: int) -> int: return int(_syscall2(uint64(Syscall.DUP2), uint64(oldfd), uint64(newfd))) def dup3(oldfd: int, newfd: int, flags: uint32) -> int: return int(_syscall3(uint64(Syscall.DUP3), uint64(oldfd), uint64(newfd), uint64(flags))) def fcntl(fd: int, cmd: uint32, arg: uint64) -> int: return int(_syscall3(uint64(Syscall.FCNTL), uint64(fd), uint64(cmd), arg)) def pread64(fd: int, buf: rawptr, count: uint32, offset: uint64) -> int: return int(_syscall4(uint64(Syscall.PREAD64), uint64(fd), uint64(buf), uint64(count), offset)) def pwrite64(fd: int, buf: rawptr, count: uint32, offset: uint64) -> int: return int(_syscall4(uint64(Syscall.PWRITE64), uint64(fd), uint64(buf), uint64(count), offset)) def rename(old_path: const str, new_path: const str) -> int: return int(_syscall2(uint64(Syscall.RENAME), uint64(old_path), uint64(new_path))) def rmdir(path: const str) -> int: return int(_syscall1(uint64(Syscall.RMDIR), uint64(path))) def unlinkat(dirfd: int, path: const str, flags: uint32) -> int: return int(_syscall3(uint64(Syscall.UNLINKAT), uint64(dirfd), uint64(path), uint64(flags))) # ---------------------------------------------------------------- P4/P5/P6 ---- def arch_prctl(code: int, addr: uint64) -> int: return int(_syscall2(uint64(Syscall.ARCH_PRCTL), uint64(code), addr)) def futex(uaddr: uint64, op: uint32, val: uint32, timeout: uint64 = 0) -> int: return int(_syscall4(uint64(Syscall.FUTEX), uaddr, uint64(op), uint64(val), timeout)) def clock_gettime(clockid: int, ts: rawptr) -> int: return int(_syscall2(uint64(Syscall.CLOCK_GETTIME), uint64(clockid), uint64(ts))) def clock_getres(clockid: int, ts: rawptr) -> int: return int(_syscall2(uint64(Syscall.CLOCK_GETRES), uint64(clockid), uint64(ts))) def gettimeofday(tv: rawptr, tz: rawptr = None) -> int: return int(_syscall2(uint64(Syscall.GETTIMEOFDAY), uint64(tv), uint64(tz))) def nanosleep(req: rawptr, rem: rawptr = None) -> int: return int(_syscall2(uint64(Syscall.NANOSLEEP), uint64(req), uint64(rem))) def rt_sigaction(sig: int, act: rawptr, oldact: rawptr, sigsetsize: uint64 = 8) -> int: return int(_syscall4(uint64(Syscall.RT_SIGACTION), uint64(sig), uint64(act), uint64(oldact), sigsetsize)) def rt_sigprocmask(how: int, setp: rawptr, oldset: rawptr, sigsetsize: uint64 = 8) -> int: return int(_syscall4(uint64(Syscall.RT_SIGPROCMASK), uint64(how), uint64(setp), uint64(oldset), sigsetsize)) def kill(pid: int, sig: int) -> int: return int(_syscall2(uint64(Syscall.KILL), uint64(pid), uint64(sig))) def readv(fd: int, iov: rawptr, iovcnt: int) -> int: return int(_syscall3(uint64(Syscall.READV), uint64(fd), uint64(iov), uint64(iovcnt))) def writev(fd: int, iov: rawptr, iovcnt: int) -> int: return int(_syscall3(uint64(Syscall.WRITEV), uint64(fd), uint64(iov), uint64(iovcnt))) def poll(fds: rawptr, nfds: uint64, timeout: int) -> int: return int(_syscall3(uint64(Syscall.POLL), uint64(fds), nfds, uint64(timeout))) def pipe2(fds: rawptr, flags: uint32 = 0) -> int: return int(_syscall2(uint64(Syscall.PIPE2), uint64(fds), uint64(flags))) def pipe(fds: rawptr) -> int: return int(_syscall1(uint64(Syscall.PIPE), uint64(fds))) def reboot_linux(cmd: uint64) -> int: return int(_syscall4(uint64(Syscall.REBOOT_LINUX), uint64(LINUX_REBOOT_MAGIC1), uint64(LINUX_REBOOT_MAGIC2), cmd, uint64(0)))