From eca05a1685dbac4ab8f0799540940b4a660cd42c Mon Sep 17 00:00:00 2001 From: equation314 Date: Sun, 17 Mar 2019 23:05:09 +0800 Subject: [PATCH] add non-x86 syscall ids --- kernel/src/arch/aarch64/syscall.rs | 288 +++++++++++++++++++++++- kernel/src/arch/riscv32/syscall.rs | 319 +++++++++++++++++++++++--- kernel/src/arch/x86_64/syscall.rs | 346 ++++++++++++++++++++++++++++- kernel/src/syscall/mod.rs | 268 ++++++++++++---------- user | 2 +- 5 files changed, 1058 insertions(+), 165 deletions(-) diff --git a/kernel/src/arch/aarch64/syscall.rs b/kernel/src/arch/aarch64/syscall.rs index 68bf3f5..0348770 100644 --- a/kernel/src/arch/aarch64/syscall.rs +++ b/kernel/src/arch/aarch64/syscall.rs @@ -1,4 +1,284 @@ -pub fn translate(id: usize) -> usize { - // FIXME: translate syscall id on aarch64 - id -} +//! AArch64 syscall ids +//! Reference: https://git.musl-libc.org/cgit/musl/tree/arch/aarch64/bits/syscall.h.in + +pub const SYS_IO_SETUP: usize = 0; +pub const SYS_IO_DESTROY: usize = 1; +pub const SYS_IO_SUBMIT: usize = 2; +pub const SYS_IO_CANCEL: usize = 3; +pub const SYS_IO_GETEVENTS: usize = 4; +pub const SYS_SETXATTR: usize = 5; +pub const SYS_LSETXATTR: usize = 6; +pub const SYS_FSETXATTR: usize = 7; +pub const SYS_GETXATTR: usize = 8; +pub const SYS_LGETXATTR: usize = 9; +pub const SYS_FGETXATTR: usize = 10; +pub const SYS_LISTXATTR: usize = 11; +pub const SYS_LLISTXATTR: usize = 12; +pub const SYS_FLISTXATTR: usize = 13; +pub const SYS_REMOVEXATTR: usize = 14; +pub const SYS_LREMOVEXATTR: usize = 15; +pub const SYS_FREMOVEXATTR: usize = 16; +pub const SYS_GETCWD: usize = 17; +pub const SYS_LOOKUP_DCOOKIE: usize = 18; +pub const SYS_EVENTFD2: usize = 19; +pub const SYS_EPOLL_CREATE1: usize = 20; +pub const SYS_EPOLL_CTL: usize = 21; +pub const SYS_EPOLL_PWAIT: usize = 22; +pub const SYS_DUP: usize = 23; +pub const SYS_DUP3: usize = 24; +pub const SYS_FCNTL: usize = 25; +pub const SYS_INOTIFY_INIT1: usize = 26; +pub const SYS_INOTIFY_ADD_WATCH: usize = 27; +pub const SYS_INOTIFY_RM_WATCH: usize = 28; +pub const SYS_IOCTL: usize = 29; +pub const SYS_IOPRIO_SET: usize = 30; +pub const SYS_IOPRIO_GET: usize = 31; +pub const SYS_FLOCK: usize = 32; +pub const SYS_MKNODAT: usize = 33; +pub const SYS_MKDIRAT: usize = 34; +pub const SYS_UNLINKAT: usize = 35; +pub const SYS_SYMLINKAT: usize = 36; +pub const SYS_LINKAT: usize = 37; +pub const SYS_RENAMEAT: usize = 38; +pub const SYS_UMOUNT2: usize = 39; +pub const SYS_MOUNT: usize = 40; +pub const SYS_PIVOT_ROOT: usize = 41; +pub const SYS_NFSSERVCTL: usize = 42; +pub const SYS_STATFS: usize = 43; +pub const SYS_FSTATFS: usize = 44; +pub const SYS_TRUNCATE: usize = 45; +pub const SYS_FTRUNCATE: usize = 46; +pub const SYS_FALLOCATE: usize = 47; +pub const SYS_FACCESSAT: usize = 48; +pub const SYS_CHDIR: usize = 49; +pub const SYS_FCHDIR: usize = 50; +pub const SYS_CHROOT: usize = 51; +pub const SYS_FCHMOD: usize = 52; +pub const SYS_FCHMODAT: usize = 53; +pub const SYS_FCHOWNAT: usize = 54; +pub const SYS_FCHOWN: usize = 55; +pub const SYS_OPENAT: usize = 56; +pub const SYS_CLOSE: usize = 57; +pub const SYS_VHANGUP: usize = 58; +pub const SYS_PIPE2: usize = 59; +pub const SYS_QUOTACTL: usize = 60; +pub const SYS_GETDENTS64: usize = 61; +pub const SYS_LSEEK: usize = 62; +pub const SYS_READ: usize = 63; +pub const SYS_WRITE: usize = 64; +pub const SYS_READV: usize = 65; +pub const SYS_WRITEV: usize = 66; +pub const SYS_PREAD64: usize = 67; +pub const SYS_PWRITE64: usize = 68; +pub const SYS_PREADV: usize = 69; +pub const SYS_PWRITEV: usize = 70; +pub const SYS_SENDFILE: usize = 71; +pub const SYS_PSELECT6: usize = 72; +pub const SYS_PPOLL: usize = 73; +pub const SYS_SIGNALFD4: usize = 74; +pub const SYS_VMSPLICE: usize = 75; +pub const SYS_SPLICE: usize = 76; +pub const SYS_TEE: usize = 77; +pub const SYS_READLINKAT: usize = 78; +pub const SYS_NEWFSTATAT: usize = 79; +pub const SYS_FSTAT: usize = 80; +pub const SYS_SYNC: usize = 81; +pub const SYS_FSYNC: usize = 82; +pub const SYS_FDATASYNC: usize = 83; +pub const SYS_SYNC_FILE_RANGE: usize = 84; +pub const SYS_TIMERFD_CREATE: usize = 85; +pub const SYS_TIMERFD_SETTIME: usize = 86; +pub const SYS_TIMERFD_GETTIME: usize = 87; +pub const SYS_UTIMENSAT: usize = 88; +pub const SYS_ACCT: usize = 89; +pub const SYS_CAPGET: usize = 90; +pub const SYS_CAPSET: usize = 91; +pub const SYS_PERSONALITY: usize = 92; +pub const SYS_EXIT: usize = 93; +pub const SYS_EXIT_GROUP: usize = 94; +pub const SYS_WAITID: usize = 95; +pub const SYS_SET_TID_ADDRESS: usize = 96; +pub const SYS_UNSHARE: usize = 97; +pub const SYS_FUTEX: usize = 98; +pub const SYS_SET_ROBUST_LIST: usize = 99; +pub const SYS_GET_ROBUST_LIST: usize = 100; +pub const SYS_NANOSLEEP: usize = 101; +pub const SYS_GETITIMER: usize = 102; +pub const SYS_SETITIMER: usize = 103; +pub const SYS_KEXEC_LOAD: usize = 104; +pub const SYS_INIT_MODULE: usize = 105; +pub const SYS_DELETE_MODULE: usize = 106; +pub const SYS_TIMER_CREATE: usize = 107; +pub const SYS_TIMER_GETTIME: usize = 108; +pub const SYS_TIMER_GETOVERRUN: usize = 109; +pub const SYS_TIMER_SETTIME: usize = 110; +pub const SYS_TIMER_DELETE: usize = 111; +pub const SYS_CLOCK_SETTIME: usize = 112; +pub const SYS_CLOCK_GETTIME: usize = 113; +pub const SYS_CLOCK_GETRES: usize = 114; +pub const SYS_CLOCK_NANOSLEEP: usize = 115; +pub const SYS_SYSLOG: usize = 116; +pub const SYS_PTRACE: usize = 117; +pub const SYS_SCHED_SETPARAM: usize = 118; +pub const SYS_SCHED_SETSCHEDULER: usize = 119; +pub const SYS_SCHED_GETSCHEDULER: usize = 120; +pub const SYS_SCHED_GETPARAM: usize = 121; +pub const SYS_SCHED_SETAFFINITY: usize = 122; +pub const SYS_SCHED_GETAFFINITY: usize = 123; +pub const SYS_SCHED_YIELD: usize = 124; +pub const SYS_SCHED_GET_PRIORITY_MAX: usize = 125; +pub const SYS_SCHED_GET_PRIORITY_MIN: usize = 126; +pub const SYS_SCHED_RR_GET_INTERVAL: usize = 127; +pub const SYS_RESTART_SYSCALL: usize = 128; +pub const SYS_KILL: usize = 129; +pub const SYS_TKILL: usize = 130; +pub const SYS_TGKILL: usize = 131; +pub const SYS_SIGALTSTACK: usize = 132; +pub const SYS_RT_SIGSUSPEND: usize = 133; +pub const SYS_RT_SIGACTION: usize = 134; +pub const SYS_RT_SIGPROCMASK: usize = 135; +pub const SYS_RT_SIGPENDING: usize = 136; +pub const SYS_RT_SIGTIMEDWAIT: usize = 137; +pub const SYS_RT_SIGQUEUEINFO: usize = 138; +pub const SYS_RT_SIGRETURN: usize = 139; +pub const SYS_SETPRIORITY: usize = 140; +pub const SYS_GETPRIORITY: usize = 141; +pub const SYS_REBOOT: usize = 142; +pub const SYS_SETREGID: usize = 143; +pub const SYS_SETGID: usize = 144; +pub const SYS_SETREUID: usize = 145; +pub const SYS_SETUID: usize = 146; +pub const SYS_SETRESUID: usize = 147; +pub const SYS_GETRESUID: usize = 148; +pub const SYS_SETRESGID: usize = 149; +pub const SYS_GETRESGID: usize = 150; +pub const SYS_SETFSUID: usize = 151; +pub const SYS_SETFSGID: usize = 152; +pub const SYS_TIMES: usize = 153; +pub const SYS_SETPGID: usize = 154; +pub const SYS_GETPGID: usize = 155; +pub const SYS_GETSID: usize = 156; +pub const SYS_SETSID: usize = 157; +pub const SYS_GETGROUPS: usize = 158; +pub const SYS_SETGROUPS: usize = 159; +pub const SYS_UNAME: usize = 160; +pub const SYS_SETHOSTNAME: usize = 161; +pub const SYS_SETDOMAINNAME: usize = 162; +pub const SYS_GETRLIMIT: usize = 163; +pub const SYS_SETRLIMIT: usize = 164; +pub const SYS_GETRUSAGE: usize = 165; +pub const SYS_UMASK: usize = 166; +pub const SYS_PRCTL: usize = 167; +pub const SYS_GETCPU: usize = 168; +pub const SYS_GETTIMEOFDAY: usize = 169; +pub const SYS_SETTIMEOFDAY: usize = 170; +pub const SYS_ADJTIMEX: usize = 171; +pub const SYS_GETPID: usize = 172; +pub const SYS_GETPPID: usize = 173; +pub const SYS_GETUID: usize = 174; +pub const SYS_GETEUID: usize = 175; +pub const SYS_GETGID: usize = 176; +pub const SYS_GETEGID: usize = 177; +pub const SYS_GETTID: usize = 178; +pub const SYS_SYSINFO: usize = 179; +pub const SYS_MQ_OPEN: usize = 180; +pub const SYS_MQ_UNLINK: usize = 181; +pub const SYS_MQ_TIMEDSEND: usize = 182; +pub const SYS_MQ_TIMEDRECEIVE: usize = 183; +pub const SYS_MQ_NOTIFY: usize = 184; +pub const SYS_MQ_GETSETATTR: usize = 185; +pub const SYS_MSGGET: usize = 186; +pub const SYS_MSGCTL: usize = 187; +pub const SYS_MSGRCV: usize = 188; +pub const SYS_MSGSND: usize = 189; +pub const SYS_SEMGET: usize = 190; +pub const SYS_SEMCTL: usize = 191; +pub const SYS_SEMTIMEDOP: usize = 192; +pub const SYS_SEMOP: usize = 193; +pub const SYS_SHMGET: usize = 194; +pub const SYS_SHMCTL: usize = 195; +pub const SYS_SHMAT: usize = 196; +pub const SYS_SHMDT: usize = 197; +pub const SYS_SOCKET: usize = 198; +pub const SYS_SOCKETPAIR: usize = 199; +pub const SYS_BIND: usize = 200; +pub const SYS_LISTEN: usize = 201; +pub const SYS_ACCEPT: usize = 202; +pub const SYS_CONNECT: usize = 203; +pub const SYS_GETSOCKNAME: usize = 204; +pub const SYS_GETPEERNAME: usize = 205; +pub const SYS_SENDTO: usize = 206; +pub const SYS_RECVFROM: usize = 207; +pub const SYS_SETSOCKOPT: usize = 208; +pub const SYS_GETSOCKOPT: usize = 209; +pub const SYS_SHUTDOWN: usize = 210; +pub const SYS_SENDMSG: usize = 211; +pub const SYS_RECVMSG: usize = 212; +pub const SYS_READAHEAD: usize = 213; +pub const SYS_BRK: usize = 214; +pub const SYS_MUNMAP: usize = 215; +pub const SYS_MREMAP: usize = 216; +pub const SYS_ADD_KEY: usize = 217; +pub const SYS_REQUEST_KEY: usize = 218; +pub const SYS_KEYCTL: usize = 219; +pub const SYS_CLONE: usize = 220; +pub const SYS_EXECVE: usize = 221; +pub const SYS_MMAP: usize = 222; +pub const SYS_FADVISE64: usize = 223; +pub const SYS_SWAPON: usize = 224; +pub const SYS_SWAPOFF: usize = 225; +pub const SYS_MPROTECT: usize = 226; +pub const SYS_MSYNC: usize = 227; +pub const SYS_MLOCK: usize = 228; +pub const SYS_MUNLOCK: usize = 229; +pub const SYS_MLOCKALL: usize = 230; +pub const SYS_MUNLOCKALL: usize = 231; +pub const SYS_MINCORE: usize = 232; +pub const SYS_MADVISE: usize = 233; +pub const SYS_REMAP_FILE_PAGES: usize = 234; +pub const SYS_MBIND: usize = 235; +pub const SYS_GET_MEMPOLICY: usize = 236; +pub const SYS_SET_MEMPOLICY: usize = 237; +pub const SYS_MIGRATE_PAGES: usize = 238; +pub const SYS_MOVE_PAGES: usize = 239; +pub const SYS_RT_TGSIGQUEUEINFO: usize = 240; +pub const SYS_PERF_EVENT_OPEN: usize = 241; +pub const SYS_ACCEPT4: usize = 242; +pub const SYS_RECVMMSG: usize = 243; +pub const SYS_WAIT4: usize = 260; +pub const SYS_PRLIMIT64: usize = 261; +pub const SYS_FANOTIFY_INIT: usize = 262; +pub const SYS_FANOTIFY_MARK: usize = 263; +pub const SYS_NAME_TO_HANDLE_AT: usize = 264; +pub const SYS_OPEN_BY_HANDLE_AT: usize = 265; +pub const SYS_CLOCK_ADJTIME: usize = 266; +pub const SYS_SYNCFS: usize = 267; +pub const SYS_SETNS: usize = 268; +pub const SYS_SENDMMSG: usize = 269; +pub const SYS_PROCESS_VM_READV: usize = 270; +pub const SYS_PROCESS_VM_WRITEV: usize = 271; +pub const SYS_KCMP: usize = 272; +pub const SYS_FINIT_MODULE: usize = 273; +pub const SYS_SCHED_SETATTR: usize = 274; +pub const SYS_SCHED_GETATTR: usize = 275; +pub const SYS_RENAMEAT2: usize = 276; +pub const SYS_SECCOMP: usize = 277; +pub const SYS_GETRANDOM: usize = 278; +pub const SYS_MEMFD_CREATE: usize = 279; +pub const SYS_BPF: usize = 280; +pub const SYS_EXECVEAT: usize = 281; +pub const SYS_USERFAULTFD: usize = 282; +pub const SYS_MEMBARRIER: usize = 283; +pub const SYS_MLOCK2: usize = 284; +pub const SYS_COPY_FILE_RANGE: usize = 285; +pub const SYS_PREADV2: usize = 286; +pub const SYS_PWRITEV2: usize = 287; +pub const SYS_PKEY_MPROTECT: usize = 288; +pub const SYS_PKEY_ALLOC: usize = 289; +pub const SYS_PKEY_FREE: usize = 290; +pub const SYS_STATX: usize = 291; +pub const SYS_IO_PGETEVENTS: usize = 292; + +// custom temporary syscall +pub const SYS_MAP_PCI_DEVICE: usize = 999; +pub const SYS_GET_PADDR: usize = 998; diff --git a/kernel/src/arch/riscv32/syscall.rs b/kernel/src/arch/riscv32/syscall.rs index a85fb7a..b1db116 100644 --- a/kernel/src/arch/riscv32/syscall.rs +++ b/kernel/src/arch/riscv32/syscall.rs @@ -1,34 +1,285 @@ -pub fn translate(id: usize) -> usize { - match id { - 17 => 79, // getcwd - 25 => 72, // fcntl - 29 => 16, // ioctl - 49 => 80, // chdir - 50 => 81, // fchdir - 51 => 161, // chroot - 59 => 293, // pipe2 - 61 => 217, // getdents64 - 62 => 8, // lseek - 63 => 0, // read - 64 => 1, // write - 65 => 19, // readv - 66 => 20, // writev - 67 => 17, // pread64 - 68 => 18, // pwrite64 - 69 => 295, // preadv - 70 => 296, // pwritev - 124 => 24, // sched_yield - 166 => 95, // umask - 172 => 39, // getpid - 173 => 110, // getppid - 174 => 102, // getuid - 175 => 107, // geteuid - 176 => 104, // getgid - 177 => 108, // getegid - 214 => 12, // brk - 220 => 56, // clone - 221 => 59, // execve - 260 => 61, // wait4 - _ => panic!("riscv syscall id {} not found", id) - } -} +//! RISCV32 syscall ids +//! Reference: https://github.com/riscv/riscv-musl/blob/staging/arch/riscv32/bits/syscall.h.in + +pub const SYS_IO_SETUP: usize = 0; +pub const SYS_IO_DESTROY: usize = 1; +pub const SYS_IO_SUBMIT: usize = 2; +pub const SYS_IO_CANCEL: usize = 3; +pub const SYS_IO_GETEVENTS: usize = 4; +pub const SYS_SETXATTR: usize = 5; +pub const SYS_LSETXATTR: usize = 6; +pub const SYS_FSETXATTR: usize = 7; +pub const SYS_GETXATTR: usize = 8; +pub const SYS_LGETXATTR: usize = 9; +pub const SYS_FGETXATTR: usize = 10; +pub const SYS_LISTXATTR: usize = 11; +pub const SYS_LLISTXATTR: usize = 12; +pub const SYS_FLISTXATTR: usize = 13; +pub const SYS_REMOVEXATTR: usize = 14; +pub const SYS_LREMOVEXATTR: usize = 15; +pub const SYS_FREMOVEXATTR: usize = 16; +pub const SYS_GETCWD: usize = 17; +pub const SYS_LOOKUP_DCOOKIE: usize = 18; +pub const SYS_EVENTFD2: usize = 19; +pub const SYS_EPOLL_CREATE1: usize = 20; +pub const SYS_EPOLL_CTL: usize = 21; +pub const SYS_EPOLL_PWAIT: usize = 22; +pub const SYS_DUP: usize = 23; +pub const SYS_DUP3: usize = 24; +pub const SYS_FCNTL: usize = 25; +pub const SYS_INOTIFY_INIT1: usize = 26; +pub const SYS_INOTIFY_ADD_WATCH: usize = 27; +pub const SYS_INOTIFY_RM_WATCH: usize = 28; +pub const SYS_IOCTL: usize = 29; +pub const SYS_IOPRIO_SET: usize = 30; +pub const SYS_IOPRIO_GET: usize = 31; +pub const SYS_FLOCK: usize = 32; +pub const SYS_MKNODAT: usize = 33; +pub const SYS_MKDIRAT: usize = 34; +pub const SYS_UNLINKAT: usize = 35; +pub const SYS_SYMLINKAT: usize = 36; +pub const SYS_LINKAT: usize = 37; +pub const SYS_RENAMEAT: usize = 38; // FIXME +pub const SYS_UMOUNT2: usize = 39; +pub const SYS_MOUNT: usize = 40; +pub const SYS_PIVOT_ROOT: usize = 41; +pub const SYS_NFSSERVCTL: usize = 42; +pub const SYS_STATFS: usize = 43; +pub const SYS_FSTATFS: usize = 44; +pub const SYS_TRUNCATE: usize = 45; +pub const SYS_FTRUNCATE: usize = 46; +pub const SYS_FALLOCATE: usize = 47; +pub const SYS_FACCESSAT: usize = 48; +pub const SYS_CHDIR: usize = 49; +pub const SYS_FCHDIR: usize = 50; +pub const SYS_CHROOT: usize = 51; +pub const SYS_FCHMOD: usize = 52; +pub const SYS_FCHMODAT: usize = 53; +pub const SYS_FCHOWNAT: usize = 54; +pub const SYS_FCHOWN: usize = 55; +pub const SYS_OPENAT: usize = 56; +pub const SYS_CLOSE: usize = 57; +pub const SYS_VHANGUP: usize = 58; +pub const SYS_PIPE2: usize = 59; +pub const SYS_QUOTACTL: usize = 60; +pub const SYS_GETDENTS64: usize = 61; +pub const SYS_LSEEK: usize = 62; +pub const SYS_READ: usize = 63; +pub const SYS_WRITE: usize = 64; +pub const SYS_READV: usize = 65; +pub const SYS_WRITEV: usize = 66; +pub const SYS_PREAD64: usize = 67; +pub const SYS_PWRITE64: usize = 68; +pub const SYS_PREADV: usize = 69; +pub const SYS_PWRITEV: usize = 70; +pub const SYS_SENDFILE: usize = 71; +pub const SYS_PSELECT6: usize = 72; +pub const SYS_PPOLL: usize = 73; +pub const SYS_SIGNALFD4: usize = 74; +pub const SYS_VMSPLICE: usize = 75; +pub const SYS_SPLICE: usize = 76; +pub const SYS_TEE: usize = 77; +pub const SYS_READLINKAT: usize = 78; +pub const SYS_NEWFSTATAT: usize = 79; +pub const SYS_FSTAT: usize = 80; +pub const SYS_SYNC: usize = 81; +pub const SYS_FSYNC: usize = 82; +pub const SYS_FDATASYNC: usize = 83; +pub const SYS_SYNC_FILE_RANGE: usize = 84; +pub const SYS_TIMERFD_CREATE: usize = 85; +pub const SYS_TIMERFD_SETTIME: usize = 86; +pub const SYS_TIMERFD_GETTIME: usize = 87; +pub const SYS_UTIMENSAT: usize = 88; +pub const SYS_ACCT: usize = 89; +pub const SYS_CAPGET: usize = 90; +pub const SYS_CAPSET: usize = 91; +pub const SYS_PERSONALITY: usize = 92; +pub const SYS_EXIT: usize = 93; +pub const SYS_EXIT_GROUP: usize = 94; +pub const SYS_WAITID: usize = 95; +pub const SYS_SET_TID_ADDRESS: usize = 96; +pub const SYS_UNSHARE: usize = 97; +pub const SYS_FUTEX: usize = 98; +pub const SYS_SET_ROBUST_LIST: usize = 99; +pub const SYS_GET_ROBUST_LIST: usize = 100; +pub const SYS_NANOSLEEP: usize = 101; +pub const SYS_GETITIMER: usize = 102; +pub const SYS_SETITIMER: usize = 103; +pub const SYS_KEXEC_LOAD: usize = 104; +pub const SYS_INIT_MODULE: usize = 105; +pub const SYS_DELETE_MODULE: usize = 106; +pub const SYS_TIMER_CREATE: usize = 107; +pub const SYS_TIMER_GETTIME: usize = 108; +pub const SYS_TIMER_GETOVERRUN: usize = 109; +pub const SYS_TIMER_SETTIME: usize = 110; +pub const SYS_TIMER_DELETE: usize = 111; +pub const SYS_CLOCK_SETTIME: usize = 112; +pub const SYS_CLOCK_GETTIME: usize = 113; +pub const SYS_CLOCK_GETRES: usize = 114; +pub const SYS_CLOCK_NANOSLEEP: usize = 115; +pub const SYS_SYSLOG: usize = 116; +pub const SYS_PTRACE: usize = 117; +pub const SYS_SCHED_SETPARAM: usize = 118; +pub const SYS_SCHED_SETSCHEDULER: usize = 119; +pub const SYS_SCHED_GETSCHEDULER: usize = 120; +pub const SYS_SCHED_GETPARAM: usize = 121; +pub const SYS_SCHED_SETAFFINITY: usize = 122; +pub const SYS_SCHED_GETAFFINITY: usize = 123; +pub const SYS_SCHED_YIELD: usize = 124; +pub const SYS_SCHED_GET_PRIORITY_MAX: usize = 125; +pub const SYS_SCHED_GET_PRIORITY_MIN: usize = 126; +pub const SYS_SCHED_RR_GET_INTERVAL: usize = 127; +pub const SYS_RESTART_SYSCALL: usize = 128; +pub const SYS_KILL: usize = 129; +pub const SYS_TKILL: usize = 130; +pub const SYS_TGKILL: usize = 131; +pub const SYS_SIGALTSTACK: usize = 132; +pub const SYS_RT_SIGSUSPEND: usize = 133; +pub const SYS_RT_SIGACTION: usize = 134; +pub const SYS_RT_SIGPROCMASK: usize = 135; +pub const SYS_RT_SIGPENDING: usize = 136; +pub const SYS_RT_SIGTIMEDWAIT: usize = 137; +pub const SYS_RT_SIGQUEUEINFO: usize = 138; +pub const SYS_RT_SIGRETURN: usize = 139; +pub const SYS_SETPRIORITY: usize = 140; +pub const SYS_GETPRIORITY: usize = 141; +pub const SYS_REBOOT: usize = 142; +pub const SYS_SETREGID: usize = 143; +pub const SYS_SETGID: usize = 144; +pub const SYS_SETREUID: usize = 145; +pub const SYS_SETUID: usize = 146; +pub const SYS_SETRESUID: usize = 147; +pub const SYS_GETRESUID: usize = 148; +pub const SYS_SETRESGID: usize = 149; +pub const SYS_GETRESGID: usize = 150; +pub const SYS_SETFSUID: usize = 151; +pub const SYS_SETFSGID: usize = 152; +pub const SYS_TIMES: usize = 153; +pub const SYS_SETPGID: usize = 154; +pub const SYS_GETPGID: usize = 155; +pub const SYS_GETSID: usize = 156; +pub const SYS_SETSID: usize = 157; +pub const SYS_GETGROUPS: usize = 158; +pub const SYS_SETGROUPS: usize = 159; +pub const SYS_UNAME: usize = 160; +pub const SYS_SETHOSTNAME: usize = 161; +pub const SYS_SETDOMAINNAME: usize = 162; +pub const SYS_GETRLIMIT: usize = 163; +pub const SYS_SETRLIMIT: usize = 164; +pub const SYS_GETRUSAGE: usize = 165; +pub const SYS_UMASK: usize = 166; +pub const SYS_PRCTL: usize = 167; +pub const SYS_GETCPU: usize = 168; +pub const SYS_GETTIMEOFDAY: usize = 169; +pub const SYS_SETTIMEOFDAY: usize = 170; +pub const SYS_ADJTIMEX: usize = 171; +pub const SYS_GETPID: usize = 172; +pub const SYS_GETPPID: usize = 173; +pub const SYS_GETUID: usize = 174; +pub const SYS_GETEUID: usize = 175; +pub const SYS_GETGID: usize = 176; +pub const SYS_GETEGID: usize = 177; +pub const SYS_GETTID: usize = 178; +pub const SYS_SYSINFO: usize = 179; +pub const SYS_MQ_OPEN: usize = 180; +pub const SYS_MQ_UNLINK: usize = 181; +pub const SYS_MQ_TIMEDSEND: usize = 182; +pub const SYS_MQ_TIMEDRECEIVE: usize = 183; +pub const SYS_MQ_NOTIFY: usize = 184; +pub const SYS_MQ_GETSETATTR: usize = 185; +pub const SYS_MSGGET: usize = 186; +pub const SYS_MSGCTL: usize = 187; +pub const SYS_MSGRCV: usize = 188; +pub const SYS_MSGSND: usize = 189; +pub const SYS_SEMGET: usize = 190; +pub const SYS_SEMCTL: usize = 191; +pub const SYS_SEMTIMEDOP: usize = 192; +pub const SYS_SEMOP: usize = 193; +pub const SYS_SHMGET: usize = 194; +pub const SYS_SHMCTL: usize = 195; +pub const SYS_SHMAT: usize = 196; +pub const SYS_SHMDT: usize = 197; +pub const SYS_SOCKET: usize = 198; +pub const SYS_SOCKETPAIR: usize = 199; +pub const SYS_BIND: usize = 200; +pub const SYS_LISTEN: usize = 201; +pub const SYS_ACCEPT: usize = 202; +pub const SYS_CONNECT: usize = 203; +pub const SYS_GETSOCKNAME: usize = 204; +pub const SYS_GETPEERNAME: usize = 205; +pub const SYS_SENDTO: usize = 206; +pub const SYS_RECVFROM: usize = 207; +pub const SYS_SETSOCKOPT: usize = 208; +pub const SYS_GETSOCKOPT: usize = 209; +pub const SYS_SHUTDOWN: usize = 210; +pub const SYS_SENDMSG: usize = 211; +pub const SYS_RECVMSG: usize = 212; +pub const SYS_READAHEAD: usize = 213; +pub const SYS_BRK: usize = 214; +pub const SYS_MUNMAP: usize = 215; +pub const SYS_MREMAP: usize = 216; +pub const SYS_ADD_KEY: usize = 217; +pub const SYS_REQUEST_KEY: usize = 218; +pub const SYS_KEYCTL: usize = 219; +pub const SYS_CLONE: usize = 220; +pub const SYS_EXECVE: usize = 221; +pub const SYS_MMAP: usize = 222; +pub const SYS_FADVISE64: usize = 223; +pub const SYS_SWAPON: usize = 224; +pub const SYS_SWAPOFF: usize = 225; +pub const SYS_MPROTECT: usize = 226; +pub const SYS_MSYNC: usize = 227; +pub const SYS_MLOCK: usize = 228; +pub const SYS_MUNLOCK: usize = 229; +pub const SYS_MLOCKALL: usize = 230; +pub const SYS_MUNLOCKALL: usize = 231; +pub const SYS_MINCORE: usize = 232; +pub const SYS_MADVISE: usize = 233; +pub const SYS_REMAP_FILE_PAGES: usize = 234; +pub const SYS_MBIND: usize = 235; +pub const SYS_GET_MEMPOLICY: usize = 236; +pub const SYS_SET_MEMPOLICY: usize = 237; +pub const SYS_MIGRATE_PAGES: usize = 238; +pub const SYS_MOVE_PAGES: usize = 239; +pub const SYS_RT_TGSIGQUEUEINFO: usize = 240; +pub const SYS_PERF_EVENT_OPEN: usize = 241; +pub const SYS_ACCEPT4: usize = 242; +pub const SYS_RECVMMSG: usize = 243; +pub const SYS_ARCH_SPECIFIC_SYSCALL: usize = 244; +pub const SYS_WAIT4: usize = 260; +pub const SYS_PRLIMIT64: usize = 261; +pub const SYS_FANOTIFY_INIT: usize = 262; +pub const SYS_FANOTIFY_MARK: usize = 263; +pub const SYS_NAME_TO_HANDLE_AT: usize = 264; +pub const SYS_OPEN_BY_HANDLE_AT: usize = 265; +pub const SYS_CLOCK_ADJTIME: usize = 266; +pub const SYS_SYNCFS: usize = 267; +pub const SYS_SETNS: usize = 268; +pub const SYS_SENDMMSG: usize = 269; +pub const SYS_PROCESS_VM_READV: usize = 270; +pub const SYS_PROCESS_VM_WRITEV: usize = 271; +pub const SYS_KCMP: usize = 272; +pub const SYS_FINIT_MODULE: usize = 273; +pub const SYS_SCHED_SETATTR: usize = 274; +pub const SYS_SCHED_GETATTR: usize = 275; +pub const SYS_RENAMEAT2: usize = 276; +pub const SYS_SECCOMP: usize = 277; +pub const SYS_GETRANDOM: usize = 278; +pub const SYS_MEMFD_CREATE: usize = 279; +pub const SYS_BPF: usize = 280; +pub const SYS_EXECVEAT: usize = 281; +pub const SYS_USERFAULTFD: usize = 282; +pub const SYS_MEMBARRIER: usize = 283; +pub const SYS_MLOCK2: usize = 284; +pub const SYS_COPY_FILE_RANGE: usize = 285; +pub const SYS_PREADV2: usize = 286; +pub const SYS_PWRITEV2: usize = 287; +pub const SYS_PKEY_MPROTECT: usize = 288; +pub const SYS_PKEY_ALLOC: usize = 289; +pub const SYS_PKEY_FREE: usize = 290; +pub const SYS_SYSRISCV: usize = SYS_ARCH_SPECIFIC_SYSCALL; +pub const SYS_RISCV_FLUSH_ICACHE: usize = SYS_SYSRISCV + 15; + +// custom temporary syscall +pub const SYS_MAP_PCI_DEVICE: usize = 999; +pub const SYS_GET_PADDR: usize = 998; diff --git a/kernel/src/arch/x86_64/syscall.rs b/kernel/src/arch/x86_64/syscall.rs index 8a55b03..a5c5ff9 100644 --- a/kernel/src/arch/x86_64/syscall.rs +++ b/kernel/src/arch/x86_64/syscall.rs @@ -1,4 +1,342 @@ -/// We use x86_64 syscall numbers -pub fn translate(id: usize) -> usize { - id -} +//! x86_64 syscall ids +//! Reference: https://git.musl-libc.org/cgit/musl/tree/arch/x86_64/bits/syscall.h.in + +pub const SYS_READ: usize = 0; +pub const SYS_WRITE: usize = 1; +pub const SYS_OPEN: usize = 2; +pub const SYS_CLOSE: usize = 3; +pub const SYS_STAT: usize = 4; +pub const SYS_FSTAT: usize = 5; +pub const SYS_LSTAT: usize = 6; +pub const SYS_POLL: usize = 7; +pub const SYS_LSEEK: usize = 8; +pub const SYS_MMAP: usize = 9; +pub const SYS_MPROTECT: usize = 10; +pub const SYS_MUNMAP: usize = 11; +pub const SYS_BRK: usize = 12; +pub const SYS_RT_SIGACTION: usize = 13; +pub const SYS_RT_SIGPROCMASK: usize = 14; +pub const SYS_RT_SIGRETURN: usize = 15; +pub const SYS_IOCTL: usize = 16; +pub const SYS_PREAD64: usize = 17; +pub const SYS_PWRITE64: usize = 18; +pub const SYS_READV: usize = 19; +pub const SYS_WRITEV: usize = 20; +pub const SYS_ACCESS: usize = 21; +pub const SYS_PIPE: usize = 22; +pub const SYS_SELECT: usize = 23; +pub const SYS_SCHED_YIELD: usize = 24; +pub const SYS_MREMAP: usize = 25; +pub const SYS_MSYNC: usize = 26; +pub const SYS_MINCORE: usize = 27; +pub const SYS_MADVISE: usize = 28; +pub const SYS_SHMGET: usize = 29; +pub const SYS_SHMAT: usize = 30; +pub const SYS_SHMCTL: usize = 31; +pub const SYS_DUP: usize = 32; +pub const SYS_DUP2: usize = 33; +pub const SYS_PAUSE: usize = 34; +pub const SYS_NANOSLEEP: usize = 35; +pub const SYS_GETITIMER: usize = 36; +pub const SYS_ALARM: usize = 37; +pub const SYS_SETITIMER: usize = 38; +pub const SYS_GETPID: usize = 39; +pub const SYS_SENDFILE: usize = 40; +pub const SYS_SOCKET: usize = 41; +pub const SYS_CONNECT: usize = 42; +pub const SYS_ACCEPT: usize = 43; +pub const SYS_SENDTO: usize = 44; +pub const SYS_RECVFROM: usize = 45; +pub const SYS_SENDMSG: usize = 46; +pub const SYS_RECVMSG: usize = 47; +pub const SYS_SHUTDOWN: usize = 48; +pub const SYS_BIND: usize = 49; +pub const SYS_LISTEN: usize = 50; +pub const SYS_GETSOCKNAME: usize = 51; +pub const SYS_GETPEERNAME: usize = 52; +pub const SYS_SOCKETPAIR: usize = 53; +pub const SYS_SETSOCKOPT: usize = 54; +pub const SYS_GETSOCKOPT: usize = 55; +pub const SYS_CLONE: usize = 56; +pub const SYS_FORK: usize = 57; +pub const SYS_VFORK: usize = 58; +pub const SYS_EXECVE: usize = 59; +pub const SYS_EXIT: usize = 60; +pub const SYS_WAIT4: usize = 61; +pub const SYS_KILL: usize = 62; +pub const SYS_UNAME: usize = 63; +pub const SYS_SEMGET: usize = 64; +pub const SYS_SEMOP: usize = 65; +pub const SYS_SEMCTL: usize = 66; +pub const SYS_SHMDT: usize = 67; +pub const SYS_MSGGET: usize = 68; +pub const SYS_MSGSND: usize = 69; +pub const SYS_MSGRCV: usize = 70; +pub const SYS_MSGCTL: usize = 71; +pub const SYS_FCNTL: usize = 72; +pub const SYS_FLOCK: usize = 73; +pub const SYS_FSYNC: usize = 74; +pub const SYS_FDATASYNC: usize = 75; +pub const SYS_TRUNCATE: usize = 76; +pub const SYS_FTRUNCATE: usize = 77; +pub const SYS_GETDENTS: usize = 78; +pub const SYS_GETCWD: usize = 79; +pub const SYS_CHDIR: usize = 80; +pub const SYS_FCHDIR: usize = 81; +pub const SYS_RENAME: usize = 82; +pub const SYS_MKDIR: usize = 83; +pub const SYS_RMDIR: usize = 84; +pub const SYS_CREAT: usize = 85; +pub const SYS_LINK: usize = 86; +pub const SYS_UNLINK: usize = 87; +pub const SYS_SYMLINK: usize = 88; +pub const SYS_READLINK: usize = 89; +pub const SYS_CHMOD: usize = 90; +pub const SYS_FCHMOD: usize = 91; +pub const SYS_CHOWN: usize = 92; +pub const SYS_FCHOWN: usize = 93; +pub const SYS_LCHOWN: usize = 94; +pub const SYS_UMASK: usize = 95; +pub const SYS_GETTIMEOFDAY: usize = 96; +pub const SYS_GETRLIMIT: usize = 97; +pub const SYS_GETRUSAGE: usize = 98; +pub const SYS_SYSINFO: usize = 99; +pub const SYS_TIMES: usize = 100; +pub const SYS_PTRACE: usize = 101; +pub const SYS_GETUID: usize = 102; +pub const SYS_SYSLOG: usize = 103; +pub const SYS_GETGID: usize = 104; +pub const SYS_SETUID: usize = 105; +pub const SYS_SETGID: usize = 106; +pub const SYS_GETEUID: usize = 107; +pub const SYS_GETEGID: usize = 108; +pub const SYS_SETPGID: usize = 109; +pub const SYS_GETPPID: usize = 110; +pub const SYS_GETPGRP: usize = 111; +pub const SYS_SETSID: usize = 112; +pub const SYS_SETREUID: usize = 113; +pub const SYS_SETREGID: usize = 114; +pub const SYS_GETGROUPS: usize = 115; +pub const SYS_SETGROUPS: usize = 116; +pub const SYS_SETRESUID: usize = 117; +pub const SYS_GETRESUID: usize = 118; +pub const SYS_SETRESGID: usize = 119; +pub const SYS_GETRESGID: usize = 120; +pub const SYS_GETPGID: usize = 121; +pub const SYS_SETFSUID: usize = 122; +pub const SYS_SETFSGID: usize = 123; +pub const SYS_GETSID: usize = 124; +pub const SYS_CAPGET: usize = 125; +pub const SYS_CAPSET: usize = 126; +pub const SYS_RT_SIGPENDING: usize = 127; +pub const SYS_RT_SIGTIMEDWAIT: usize = 128; +pub const SYS_RT_SIGQUEUEINFO: usize = 129; +pub const SYS_RT_SIGSUSPEND: usize = 130; +pub const SYS_SIGALTSTACK: usize = 131; +pub const SYS_UTIME: usize = 132; +pub const SYS_MKNOD: usize = 133; +pub const SYS_USELIB: usize = 134; +pub const SYS_PERSONALITY: usize = 135; +pub const SYS_USTAT: usize = 136; +pub const SYS_STATFS: usize = 137; +pub const SYS_FSTATFS: usize = 138; +pub const SYS_SYSFS: usize = 139; +pub const SYS_GETPRIORITY: usize = 140; +pub const SYS_SETPRIORITY: usize = 141; +pub const SYS_SCHED_SETPARAM: usize = 142; +pub const SYS_SCHED_GETPARAM: usize = 143; +pub const SYS_SCHED_SETSCHEDULER: usize = 144; +pub const SYS_SCHED_GETSCHEDULER: usize = 145; +pub const SYS_SCHED_GET_PRIORITY_MAX: usize = 146; +pub const SYS_SCHED_GET_PRIORITY_MIN: usize = 147; +pub const SYS_SCHED_RR_GET_INTERVAL: usize = 148; +pub const SYS_MLOCK: usize = 149; +pub const SYS_MUNLOCK: usize = 150; +pub const SYS_MLOCKALL: usize = 151; +pub const SYS_MUNLOCKALL: usize = 152; +pub const SYS_VHANGUP: usize = 153; +pub const SYS_MODIFY_LDT: usize = 154; +pub const SYS_PIVOT_ROOT: usize = 155; +pub const SYS__SYSCTL: usize = 156; +pub const SYS_PRCTL: usize = 157; +pub const SYS_ARCH_PRCTL: usize = 158; +pub const SYS_ADJTIMEX: usize = 159; +pub const SYS_SETRLIMIT: usize = 160; +pub const SYS_CHROOT: usize = 161; +pub const SYS_SYNC: usize = 162; +pub const SYS_ACCT: usize = 163; +pub const SYS_SETTIMEOFDAY: usize = 164; +pub const SYS_MOUNT: usize = 165; +pub const SYS_UMOUNT2: usize = 166; +pub const SYS_SWAPON: usize = 167; +pub const SYS_SWAPOFF: usize = 168; +pub const SYS_REBOOT: usize = 169; +pub const SYS_SETHOSTNAME: usize = 170; +pub const SYS_SETDOMAINNAME: usize = 171; +pub const SYS_IOPL: usize = 172; +pub const SYS_IOPERM: usize = 173; +pub const SYS_CREATE_MODULE: usize = 174; +pub const SYS_INIT_MODULE: usize = 175; +pub const SYS_DELETE_MODULE: usize = 176; +pub const SYS_GET_KERNEL_SYMS: usize = 177; +pub const SYS_QUERY_MODULE: usize = 178; +pub const SYS_QUOTACTL: usize = 179; +pub const SYS_NFSSERVCTL: usize = 180; +pub const SYS_GETPMSG: usize = 181; +pub const SYS_PUTPMSG: usize = 182; +pub const SYS_AFS_SYSCALL: usize = 183; +pub const SYS_TUXCALL: usize = 184; +pub const SYS_SECURITY: usize = 185; +pub const SYS_GETTID: usize = 186; +pub const SYS_READAHEAD: usize = 187; +pub const SYS_SETXATTR: usize = 188; +pub const SYS_LSETXATTR: usize = 189; +pub const SYS_FSETXATTR: usize = 190; +pub const SYS_GETXATTR: usize = 191; +pub const SYS_LGETXATTR: usize = 192; +pub const SYS_FGETXATTR: usize = 193; +pub const SYS_LISTXATTR: usize = 194; +pub const SYS_LLISTXATTR: usize = 195; +pub const SYS_FLISTXATTR: usize = 196; +pub const SYS_REMOVEXATTR: usize = 197; +pub const SYS_LREMOVEXATTR: usize = 198; +pub const SYS_FREMOVEXATTR: usize = 199; +pub const SYS_TKILL: usize = 200; +pub const SYS_TIME: usize = 201; +pub const SYS_FUTEX: usize = 202; +pub const SYS_SCHED_SETAFFINITY: usize = 203; +pub const SYS_SCHED_GETAFFINITY: usize = 204; +pub const SYS_SET_THREAD_AREA: usize = 205; +pub const SYS_IO_SETUP: usize = 206; +pub const SYS_IO_DESTROY: usize = 207; +pub const SYS_IO_GETEVENTS: usize = 208; +pub const SYS_IO_SUBMIT: usize = 209; +pub const SYS_IO_CANCEL: usize = 210; +pub const SYS_GET_THREAD_AREA: usize = 211; +pub const SYS_LOOKUP_DCOOKIE: usize = 212; +pub const SYS_EPOLL_CREATE: usize = 213; +pub const SYS_EPOLL_CTL_OLD: usize = 214; +pub const SYS_EPOLL_WAIT_OLD: usize = 215; +pub const SYS_REMAP_FILE_PAGES: usize = 216; +pub const SYS_GETDENTS64: usize = 217; +pub const SYS_SET_TID_ADDRESS: usize = 218; +pub const SYS_RESTART_SYSCALL: usize = 219; +pub const SYS_SEMTIMEDOP: usize = 220; +pub const SYS_FADVISE64: usize = 221; +pub const SYS_TIMER_CREATE: usize = 222; +pub const SYS_TIMER_SETTIME: usize = 223; +pub const SYS_TIMER_GETTIME: usize = 224; +pub const SYS_TIMER_GETOVERRUN: usize = 225; +pub const SYS_TIMER_DELETE: usize = 226; +pub const SYS_CLOCK_SETTIME: usize = 227; +pub const SYS_CLOCK_GETTIME: usize = 228; +pub const SYS_CLOCK_GETRES: usize = 229; +pub const SYS_CLOCK_NANOSLEEP: usize = 230; +pub const SYS_EXIT_GROUP: usize = 231; +pub const SYS_EPOLL_WAIT: usize = 232; +pub const SYS_EPOLL_CTL: usize = 233; +pub const SYS_TGKILL: usize = 234; +pub const SYS_UTIMES: usize = 235; +pub const SYS_VSERVER: usize = 236; +pub const SYS_MBIND: usize = 237; +pub const SYS_SET_MEMPOLICY: usize = 238; +pub const SYS_GET_MEMPOLICY: usize = 239; +pub const SYS_MQ_OPEN: usize = 240; +pub const SYS_MQ_UNLINK: usize = 241; +pub const SYS_MQ_TIMEDSEND: usize = 242; +pub const SYS_MQ_TIMEDRECEIVE: usize = 243; +pub const SYS_MQ_NOTIFY: usize = 244; +pub const SYS_MQ_GETSETATTR: usize = 245; +pub const SYS_KEXEC_LOAD: usize = 246; +pub const SYS_WAITID: usize = 247; +pub const SYS_ADD_KEY: usize = 248; +pub const SYS_REQUEST_KEY: usize = 249; +pub const SYS_KEYCTL: usize = 250; +pub const SYS_IOPRIO_SET: usize = 251; +pub const SYS_IOPRIO_GET: usize = 252; +pub const SYS_INOTIFY_INIT: usize = 253; +pub const SYS_INOTIFY_ADD_WATCH: usize = 254; +pub const SYS_INOTIFY_RM_WATCH: usize = 255; +pub const SYS_MIGRATE_PAGES: usize = 256; +pub const SYS_OPENAT: usize = 257; +pub const SYS_MKDIRAT: usize = 258; +pub const SYS_MKNODAT: usize = 259; +pub const SYS_FCHOWNAT: usize = 260; +pub const SYS_FUTIMESAT: usize = 261; +pub const SYS_NEWFSTATAT: usize = 262; +pub const SYS_UNLINKAT: usize = 263; +pub const SYS_RENAMEAT: usize = 264; +pub const SYS_LINKAT: usize = 265; +pub const SYS_SYMLINKAT: usize = 266; +pub const SYS_READLINKAT: usize = 267; +pub const SYS_FCHMODAT: usize = 268; +pub const SYS_FACCESSAT: usize = 269; +pub const SYS_PSELECT6: usize = 270; +pub const SYS_PPOLL: usize = 271; +pub const SYS_UNSHARE: usize = 272; +pub const SYS_SET_ROBUST_LIST: usize = 273; +pub const SYS_GET_ROBUST_LIST: usize = 274; +pub const SYS_SPLICE: usize = 275; +pub const SYS_TEE: usize = 276; +pub const SYS_SYNC_FILE_RANGE: usize = 277; +pub const SYS_VMSPLICE: usize = 278; +pub const SYS_MOVE_PAGES: usize = 279; +pub const SYS_UTIMENSAT: usize = 280; +pub const SYS_EPOLL_PWAIT: usize = 281; +pub const SYS_SIGNALFD: usize = 282; +pub const SYS_TIMERFD_CREATE: usize = 283; +pub const SYS_EVENTFD: usize = 284; +pub const SYS_FALLOCATE: usize = 285; +pub const SYS_TIMERFD_SETTIME: usize = 286; +pub const SYS_TIMERFD_GETTIME: usize = 287; +pub const SYS_ACCEPT4: usize = 288; +pub const SYS_SIGNALFD4: usize = 289; +pub const SYS_EVENTFD2: usize = 290; +pub const SYS_EPOLL_CREATE1: usize = 291; +pub const SYS_DUP3: usize = 292; +pub const SYS_PIPE2: usize = 293; +pub const SYS_INOTIFY_INIT1: usize = 294; +pub const SYS_PREADV: usize = 295; +pub const SYS_PWRITEV: usize = 296; +pub const SYS_RT_TGSIGQUEUEINFO: usize = 297; +pub const SYS_PERF_EVENT_OPEN: usize = 298; +pub const SYS_RECVMMSG: usize = 299; +pub const SYS_FANOTIFY_INIT: usize = 300; +pub const SYS_FANOTIFY_MARK: usize = 301; +pub const SYS_PRLIMIT64: usize = 302; +pub const SYS_NAME_TO_HANDLE_AT: usize = 303; +pub const SYS_OPEN_BY_HANDLE_AT: usize = 304; +pub const SYS_CLOCK_ADJTIME: usize = 305; +pub const SYS_SYNCFS: usize = 306; +pub const SYS_SENDMMSG: usize = 307; +pub const SYS_SETNS: usize = 308; +pub const SYS_GETCPU: usize = 309; +pub const SYS_PROCESS_VM_READV: usize = 310; +pub const SYS_PROCESS_VM_WRITEV: usize = 311; +pub const SYS_KCMP: usize = 312; +pub const SYS_FINIT_MODULE: usize = 313; +pub const SYS_SCHED_SETATTR: usize = 314; +pub const SYS_SCHED_GETATTR: usize = 315; +pub const SYS_RENAMEAT2: usize = 316; +pub const SYS_SECCOMP: usize = 317; +pub const SYS_GETRANDOM: usize = 318; +pub const SYS_MEMFD_CREATE: usize = 319; +pub const SYS_KEXEC_FILE_LOAD: usize = 320; +pub const SYS_BPF: usize = 321; +pub const SYS_EXECVEAT: usize = 322; +pub const SYS_USERFAULTFD: usize = 323; +pub const SYS_MEMBARRIER: usize = 324; +pub const SYS_MLOCK2: usize = 325; +pub const SYS_COPY_FILE_RANGE: usize = 326; +pub const SYS_PREADV2: usize = 327; +pub const SYS_PWRITEV2: usize = 328; +pub const SYS_PKEY_MPROTECT: usize = 329; +pub const SYS_PKEY_ALLOC: usize = 330; +pub const SYS_PKEY_FREE: usize = 331; +pub const SYS_STATX: usize = 332; +pub const SYS_IO_PGETEVENTS: usize = 333; +pub const SYS_RSEQ: usize = 334; + +// custom temporary syscall +pub const SYS_MAP_PCI_DEVICE: usize = 999; +pub const SYS_GET_PADDR: usize = 998; diff --git a/kernel/src/syscall/mod.rs b/kernel/src/syscall/mod.rs index ae897c7..bae5d96 100644 --- a/kernel/src/syscall/mod.rs +++ b/kernel/src/syscall/mod.rs @@ -33,7 +33,6 @@ mod custom; /// System call dispatcher pub fn syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> isize { - let x86_64_id = syscall::translate(id); let cid = cpu::id(); let pid = { process().pid.clone() @@ -41,201 +40,182 @@ pub fn syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> isize { let tid = processor().tid(); if !pid.is_init() { // we trust pid 0 process - debug!("{}:{}:{} syscall id {}->{} begin", cid, pid, tid, id, x86_64_id); + debug!("{}:{}:{} syscall id {} begin", cid, pid, tid, id); } // use syscall numbers in Linux x86_64 // See https://filippo.io/linux-syscall-table/ // And https://fedora.juszkiewicz.com.pl/syscalls.html. - let ret = match x86_64_id { + let ret = match id { // file - 000 => sys_read(args[0], args[1] as *mut u8, args[2]), - 001 => sys_write(args[0], args[1] as *const u8, args[2]), - 002 => sys_open(args[0] as *const u8, args[1], args[2]), - 003 => sys_close(args[0]), - 004 => sys_stat(args[0] as *const u8, args[1] as *mut Stat), - 005 => sys_fstat(args[0], args[1] as *mut Stat), - 006 => sys_lstat(args[0] as *const u8, args[1] as *mut Stat), - 007 => sys_poll(args[0] as *mut PollFd, args[1], args[2]), - 008 => sys_lseek(args[0], args[1] as i64, args[2] as u8), - 009 => sys_mmap(args[0], args[1], args[2], args[3], args[4] as i32, args[5]), - 010 => sys_mprotect(args[0], args[1], args[2]), - 011 => sys_munmap(args[0], args[1]), - 017 => sys_pread(args[0], args[1] as *mut u8, args[2], args[3]), - 018 => sys_pwrite(args[0], args[1] as *const u8, args[2], args[3]), - 019 => sys_readv(args[0], args[1] as *const IoVec, args[2]), - 020 => sys_writev(args[0], args[1] as *const IoVec, args[2]), - 021 => sys_access(args[0] as *const u8, args[1]), - 022 => sys_pipe(args[0] as *mut u32), - 023 => sys_select(args[0], args[1] as *mut u32, args[2] as *mut u32, args[3] as *mut u32, args[4] as *const TimeVal), - 024 => sys_yield(), - 033 => sys_dup2(args[0], args[1]), -// 034 => sys_pause(), - 035 => sys_nanosleep(args[0] as *const TimeSpec), - 039 => sys_getpid(), - 041 => sys_socket(args[0], args[1], args[2]), - 042 => sys_connect(args[0], args[1] as *const SockAddr, args[2]), - 043 => sys_accept(args[0], args[1] as *mut SockAddr, args[2] as *mut u32), - 044 => sys_sendto(args[0], args[1] as *const u8, args[2], args[3], args[4] as *const SockAddr, args[5]), - 045 => sys_recvfrom(args[0], args[1] as *mut u8, args[2], args[3], args[4] as *mut SockAddr, args[5] as *mut u32), -// 046 => sys_sendmsg(), -// 047 => sys_recvmsg(), - 048 => sys_shutdown(args[0], args[1]), - 049 => sys_bind(args[0], args[1] as *const SockAddr, args[2]), - 050 => sys_listen(args[0], args[1]), - 051 => sys_getsockname(args[0], args[1] as *mut SockAddr, args[2] as *mut u32), - 052 => sys_getpeername(args[0], args[1] as *mut SockAddr, args[2] as *mut u32), - 054 => sys_setsockopt(args[0], args[1], args[2], args[3] as *const u8, args[4]), - 055 => sys_getsockopt(args[0], args[1], args[2], args[3] as *mut u8, args[4] as *mut u32), - 056 => sys_clone(args[0], args[1], args[2] as *mut u32, args[3] as *mut u32, args[4], tf), - 057 => sys_fork(tf), - // use fork for vfork - 058 => sys_fork(tf), - 059 => sys_exec(args[0] as *const u8, args[1] as *const *const u8, args[2] as *const *const u8, tf), - 060 => sys_exit(args[0] as usize), - 061 => sys_wait4(args[0] as isize, args[1] as *mut i32), // TODO: wait4 - 062 => sys_kill(args[0], args[1]), - 063 => sys_uname(args[0] as *mut u8), -// 072 => sys_fcntl(), - 074 => sys_fsync(args[0]), - 075 => sys_fdatasync(args[0]), - 076 => sys_truncate(args[0] as *const u8, args[1]), - 077 => sys_ftruncate(args[0], args[1]), - 079 => sys_getcwd(args[0] as *mut u8, args[1]), - 080 => sys_chdir(args[0] as *const u8), - 082 => sys_rename(args[0] as *const u8, args[1] as *const u8), - 083 => sys_mkdir(args[0] as *const u8, args[1]), - 086 => sys_link(args[0] as *const u8, args[1] as *const u8), - 087 => sys_unlink(args[0] as *const u8), - 096 => sys_gettimeofday(args[0] as *mut TimeVal, args[1] as *const u8), -// 097 => sys_getrlimit(), - 098 => sys_getrusage(args[0], args[1] as *mut RUsage), - 099 => sys_sysinfo(args[0] as *mut SysInfo), - 110 => sys_getppid(), -// 133 => sys_mknod(), - 141 => sys_set_priority(args[0]), - 158 => sys_arch_prctl(args[0] as i32, args[1], tf), -// 160 => sys_setrlimit(), -// 162 => sys_sync(), - 169 => sys_reboot(args[0] as u32, args[1] as u32, args[2] as u32, args[3] as *const u8), - 186 => sys_gettid(), - 201 => sys_time(args[0] as *mut u64), - 202 => sys_futex(args[0], args[1] as u32, args[2] as i32, args[3] as *const TimeSpec), - 204 => sys_sched_getaffinity(args[0], args[1], args[2] as *mut u32), - 217 => sys_getdents64(args[0], args[1] as *mut LinuxDirent64, args[2]), - 228 => sys_clock_gettime(args[0], args[1] as *mut TimeSpec), - 231 => sys_exit_group(args[0]), - 288 => sys_accept(args[0], args[1] as *mut SockAddr, args[2] as *mut u32), // use accept for accept4 + syscall::SYS_READ => sys_read(args[0], args[1] as *mut u8, args[2]), + syscall::SYS_WRITE => sys_write(args[0], args[1] as *const u8, args[2]), + syscall::SYS_CLOSE => sys_close(args[0]), + syscall::SYS_FSTAT => sys_fstat(args[0], args[1] as *mut Stat), + syscall::SYS_LSEEK => sys_lseek(args[0], args[1] as i64, args[2] as u8), + syscall::SYS_MMAP => sys_mmap(args[0], args[1], args[2], args[3], args[4] as i32, args[5]), + syscall::SYS_MPROTECT => sys_mprotect(args[0], args[1], args[2]), + syscall::SYS_MUNMAP => sys_munmap(args[0], args[1]), + syscall::SYS_PREAD64 => sys_pread(args[0], args[1] as *mut u8, args[2], args[3]), + syscall::SYS_PWRITE64 => sys_pwrite(args[0], args[1] as *const u8, args[2], args[3]), + syscall::SYS_READV => sys_readv(args[0], args[1] as *const IoVec, args[2]), + syscall::SYS_WRITEV => sys_writev(args[0], args[1] as *const IoVec, args[2]), + syscall::SYS_SCHED_YIELD => sys_yield(), + syscall::SYS_NANOSLEEP => sys_nanosleep(args[0] as *const TimeSpec), + syscall::SYS_GETPID => sys_getpid(), + syscall::SYS_SOCKET => sys_socket(args[0], args[1], args[2]), + syscall::SYS_CONNECT => sys_connect(args[0], args[1] as *const SockAddr, args[2]), + syscall::SYS_ACCEPT => sys_accept(args[0], args[1] as *mut SockAddr, args[2] as *mut u32), + syscall::SYS_SENDTO => sys_sendto(args[0], args[1] as *const u8, args[2], args[3], args[4] as *const SockAddr, args[5]), + syscall::SYS_RECVFROM => sys_recvfrom(args[0], args[1] as *mut u8, args[2], args[3], args[4] as *mut SockAddr, args[5] as *mut u32), +// syscall::SYS_SENDMSG => sys_sendmsg(), +// syscall::SYS_RECVMSG => sys_recvmsg(), + syscall::SYS_SHUTDOWN => sys_shutdown(args[0], args[1]), + syscall::SYS_BIND => sys_bind(args[0], args[1] as *const SockAddr, args[2]), + syscall::SYS_LISTEN => sys_listen(args[0], args[1]), + syscall::SYS_GETSOCKNAME => sys_getsockname(args[0], args[1] as *mut SockAddr, args[2] as *mut u32), + syscall::SYS_GETPEERNAME => sys_getpeername(args[0], args[1] as *mut SockAddr, args[2] as *mut u32), + syscall::SYS_SETSOCKOPT => sys_setsockopt(args[0], args[1], args[2], args[3] as *const u8, args[4]), + syscall::SYS_GETSOCKOPT => sys_getsockopt(args[0], args[1], args[2], args[3] as *mut u8, args[4] as *mut u32), + syscall::SYS_CLONE => sys_clone(args[0], args[1], args[2] as *mut u32, args[3] as *mut u32, args[4], tf), + syscall::SYS_EXECVE => sys_exec(args[0] as *const u8, args[1] as *const *const u8, args[2] as *const *const u8, tf), + syscall::SYS_EXIT => sys_exit(args[0] as usize), + syscall::SYS_WAIT4 => sys_wait4(args[0] as isize, args[1] as *mut i32), // TODO: wait4 + syscall::SYS_KILL => sys_kill(args[0], args[1]), + syscall::SYS_UNAME => sys_uname(args[0] as *mut u8), + syscall::SYS_FSYNC => sys_fsync(args[0]), + syscall::SYS_FDATASYNC => sys_fdatasync(args[0]), + syscall::SYS_TRUNCATE => sys_truncate(args[0] as *const u8, args[1]), + syscall::SYS_FTRUNCATE => sys_ftruncate(args[0], args[1]), + syscall::SYS_GETCWD => sys_getcwd(args[0] as *mut u8, args[1]), + syscall::SYS_CHDIR => sys_chdir(args[0] as *const u8), + syscall::SYS_GETTIMEOFDAY => sys_gettimeofday(args[0] as *mut TimeVal, args[1] as *const u8), +// syscall::SYS_GETRLIMIT => sys_getrlimit(), + syscall::SYS_GETRUSAGE => sys_getrusage(args[0], args[1] as *mut RUsage), + syscall::SYS_SYSINFO => sys_sysinfo(args[0] as *mut SysInfo), + syscall::SYS_GETPPID => sys_getppid(), + syscall::SYS_SETPRIORITY => sys_set_priority(args[0]), +// syscall::SYS_SETRLIMIT => sys_setrlimit(), +// syscall::SYS_SYNC => sys_sync(), + syscall::SYS_REBOOT => sys_reboot(args[0] as u32, args[1] as u32, args[2] as u32, args[3] as *const u8), + syscall::SYS_GETTID => sys_gettid(), + syscall::SYS_FUTEX => sys_futex(args[0], args[1] as u32, args[2] as i32, args[3] as *const TimeSpec), + syscall::SYS_SCHED_GETAFFINITY => sys_sched_getaffinity(args[0], args[1], args[2] as *mut u32), + syscall::SYS_GETDENTS64 => sys_getdents64(args[0], args[1] as *mut LinuxDirent64, args[2]), + syscall::SYS_CLOCK_GETTIME => sys_clock_gettime(args[0], args[1] as *mut TimeSpec), + syscall::SYS_EXIT_GROUP => sys_exit_group(args[0]), + syscall::SYS_OPENAT => sys_open(args[1] as *const u8, args[2], args[3]), // TODO: handle `dfd` + syscall::SYS_MKDIRAT => sys_mkdir(args[1] as *const u8, args[2]), // TODO: handle `dfd` +// syscall::SYS_MKNODAT => sys_mknod(), + syscall::SYS_NEWFSTATAT => sys_stat(args[1] as *const u8, args[2] as *mut Stat), // TODO: handle `dfd`, `flag` + syscall::SYS_UNLINKAT => sys_unlink(args[1] as *const u8), // TODO: handle `dfd`, `flag` + syscall::SYS_RENAMEAT => sys_rename(args[1] as *const u8, args[3] as *const u8), // TODO: handle `olddfd`, `newdfd` + syscall::SYS_LINKAT => sys_link(args[1] as *const u8, args[3] as *const u8), // TODO: handle `olddfd`, `newdfd`, `flags` + syscall::SYS_FACCESSAT => sys_access(args[1] as *const u8, args[2]), // TODO: handle `dfd` + syscall::SYS_ACCEPT4 => sys_accept(args[0], args[1] as *mut SockAddr, args[2] as *mut u32), // use accept for accept4 + syscall::SYS_DUP3 => sys_dup2(args[0], args[1]), // TODO: handle `flags` + syscall::SYS_PIPE2 => sys_pipe(args[0] as *mut u32), // TODO: handle `flags` // custom temporary syscall - 999 => sys_map_pci_device(args[0], args[1]), - 998 => sys_get_paddr(args[0] as *const u64, args[1] as *mut u64, args[2]), -// 293 => sys_pipe(), + syscall::SYS_MAP_PCI_DEVICE => sys_map_pci_device(args[0], args[1]), + syscall::SYS_GET_PADDR => sys_get_paddr(args[0] as *const u64, args[1] as *mut u64, args[2]), // for musl: empty impl - 012 => { + syscall::SYS_BRK => { warn!("sys_brk is unimplemented"); Ok(0) } - 013 => { + syscall::SYS_RT_SIGACTION => { warn!("sys_sigaction is unimplemented"); Ok(0) } - 014 => { + syscall::SYS_RT_SIGPROCMASK => { warn!("sys_sigprocmask is unimplemented"); Ok(0) } - 016 => { + syscall::SYS_IOCTL => { warn!("sys_ioctl is unimplemented"); Ok(0) } - 028 => { + syscall::SYS_MADVISE => { warn!("sys_madvise is unimplemented"); Ok(0) } - 037 => { - warn!("sys_alarm is unimplemented"); - Ok(0) - } - 038 => { + syscall::SYS_SETITIMER => { warn!("sys_setitimer is unimplemented"); Ok(0) } - 072 => { + syscall::SYS_FCNTL => { warn!("sys_fcntl is unimplemented"); Ok(0) } - 089 => { - warn!("sys_readlink is unimplemented"); - Err(SysError::ENOENT) - } - 092 => { - warn!("sys_chown is unimplemented"); - Ok(0) - } - 095 => { + syscall::SYS_UMASK => { warn!("sys_umask is unimplemented"); Ok(0o777) } - 102 => { + syscall::SYS_GETUID => { warn!("sys_getuid is unimplemented"); Ok(0) } - 104 => { + syscall::SYS_GETGID => { warn!("sys_getgid is unimplemented"); Ok(0) } - 105 => { + syscall::SYS_SETUID => { warn!("sys_setuid is unimplemented"); Ok(0) } - 107 => { + syscall::SYS_GETEUID => { warn!("sys_geteuid is unimplemented"); Ok(0) } - 108 => { + syscall::SYS_GETEGID => { warn!("sys_getegid is unimplemented"); Ok(0) } - 112 => { + syscall::SYS_SETSID => { warn!("sys_setsid is unimplemented"); Ok(0) } - 131 => { + syscall::SYS_SIGALTSTACK => { warn!("sys_sigaltstack is unimplemented"); Ok(0) } - 162 => { + syscall::SYS_SYNC => { warn!("sys_sync is unimplemented"); Ok(0) } - 213 => { - warn!("sys_epoll_create is unimplemented"); - Err(SysError::ENOSYS) - } - 218 => { + syscall::SYS_SET_TID_ADDRESS => { warn!("sys_set_tid_address is unimplemented"); Ok(thread::current().id()) } - 280 => { + syscall::SYS_UTIMENSAT => { warn!("sys_utimensat is unimplemented"); Ok(0) } - 291 => { + syscall::SYS_EPOLL_CREATE1 => { warn!("sys_epoll_create1 is unimplemented"); Err(SysError::ENOSYS) } - 302 => { + syscall::SYS_PRLIMIT64 => { warn!("sys_prlimit64 is unimplemented"); Ok(0) } _ => { - error!("unknown syscall id: {}->{}, args: {:x?}", id, x86_64_id, args); - crate::trap::error(tf); + #[cfg(target_arch = "x86_64")] + let x86_64_ret = x86_64_syscall(id, args, tf); + #[cfg(not(target_arch = "x86_64"))] + let x86_64_ret = None; + if let Some(ret) = x86_64_ret { + ret + } else { + error!("unknown syscall id: {}, args: {:x?}", id, args); + crate::trap::error(tf); + } } }; if !pid.is_init() { // we trust pid 0 process - debug!("{}:{}:{} syscall id {}->{} ret with {:x?}", cid, pid, tid, id, x86_64_id, ret); + debug!("{}:{}:{} syscall id {} ret with {:x?}", cid, pid, tid, id, ret); } match ret { Ok(code) => code as isize, @@ -243,6 +223,50 @@ pub fn syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> isize { } } +#[cfg(target_arch = "x86_64")] +fn x86_64_syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> Option { + let ret = match id { + syscall::SYS_OPEN => sys_open(args[0] as *const u8, args[1], args[2]), + syscall::SYS_STAT => sys_stat(args[0] as *const u8, args[1] as *mut Stat), + syscall::SYS_LSTAT => sys_lstat(args[0] as *const u8, args[1] as *mut Stat), + syscall::SYS_POLL => sys_poll(args[0] as *mut PollFd, args[1], args[2]), + syscall::SYS_ACCESS => sys_access(args[0] as *const u8, args[1]), + syscall::SYS_PIPE => sys_pipe(args[0] as *mut u32), + syscall::SYS_SELECT => sys_select(args[0], args[1] as *mut u32, args[2] as *mut u32, args[3] as *mut u32, args[4] as *const TimeVal), + syscall::SYS_DUP2 => sys_dup2(args[0], args[1]), +// syscall::SYS_PAUSE => sys_pause(), + SYS_FORK => sys_fork(tf), + // use fork for vfork + syscall::SYS_VFORK => sys_fork(tf), + syscall::SYS_RENAME => sys_rename(args[0] as *const u8, args[1] as *const u8), + syscall::SYS_MKDIR => sys_mkdir(args[0] as *const u8, args[1]), + syscall::SYS_LINK => sys_link(args[0] as *const u8, args[1] as *const u8), + syscall::SYS_UNLINK => sys_unlink(args[0] as *const u8), + syscall::SYS_ARCH_PRCTL => sys_arch_prctl(args[0] as i32, args[1], tf), + syscall::SYS_TIME => sys_time(args[0] as *mut u64), + syscall::SYS_ALARM => { + warn!("sys_alarm is unimplemented"); + Ok(0) + } + syscall::SYS_READLINK => { + warn!("sys_readlink is unimplemented"); + Err(SysError::ENOENT) + } + syscall::SYS_CHOWN => { + warn!("sys_chown is unimplemented"); + Ok(0) + } + syscall::SYS_EPOLL_CREATE => { + warn!("sys_epoll_create is unimplemented"); + Err(SysError::ENOSYS) + } + _ => { + return None; + } + }; + Some(ret) +} + pub type SysResult = Result; #[allow(dead_code)] diff --git a/user b/user index 06084d9..10d4972 160000 --- a/user +++ b/user @@ -1 +1 @@ -Subproject commit 06084d9925a9f8e4234fefeabcbffc96cedf1e90 +Subproject commit 10d49723dfbdb9015f16beb55e97c108de7e19da