github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/pkg/sentry/syscalls/linux/vfs2/vfs2.go (about) 1 // Copyright 2020 The gVisor Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Package vfs2 provides syscall implementations that use VFS2. 16 package vfs2 17 18 import ( 19 "github.com/SagerNet/gvisor/pkg/sentry/syscalls" 20 "github.com/SagerNet/gvisor/pkg/sentry/syscalls/linux" 21 ) 22 23 // Override syscall table to add syscalls implementations from this package. 24 func Override() { 25 // Override AMD64. 26 s := linux.AMD64 27 s.Table[0] = syscalls.Supported("read", Read) 28 s.Table[1] = syscalls.Supported("write", Write) 29 s.Table[2] = syscalls.Supported("open", Open) 30 s.Table[3] = syscalls.Supported("close", Close) 31 s.Table[4] = syscalls.Supported("stat", Stat) 32 s.Table[5] = syscalls.Supported("fstat", Fstat) 33 s.Table[6] = syscalls.Supported("lstat", Lstat) 34 s.Table[7] = syscalls.Supported("poll", Poll) 35 s.Table[8] = syscalls.Supported("lseek", Lseek) 36 s.Table[9] = syscalls.Supported("mmap", Mmap) 37 s.Table[16] = syscalls.Supported("ioctl", Ioctl) 38 s.Table[17] = syscalls.Supported("pread64", Pread64) 39 s.Table[18] = syscalls.Supported("pwrite64", Pwrite64) 40 s.Table[19] = syscalls.Supported("readv", Readv) 41 s.Table[20] = syscalls.Supported("writev", Writev) 42 s.Table[21] = syscalls.Supported("access", Access) 43 s.Table[22] = syscalls.Supported("pipe", Pipe) 44 s.Table[23] = syscalls.Supported("select", Select) 45 s.Table[32] = syscalls.Supported("dup", Dup) 46 s.Table[33] = syscalls.Supported("dup2", Dup2) 47 s.Table[40] = syscalls.Supported("sendfile", Sendfile) 48 s.Table[41] = syscalls.Supported("socket", Socket) 49 s.Table[42] = syscalls.Supported("connect", Connect) 50 s.Table[43] = syscalls.Supported("accept", Accept) 51 s.Table[44] = syscalls.Supported("sendto", SendTo) 52 s.Table[45] = syscalls.Supported("recvfrom", RecvFrom) 53 s.Table[46] = syscalls.Supported("sendmsg", SendMsg) 54 s.Table[47] = syscalls.Supported("recvmsg", RecvMsg) 55 s.Table[48] = syscalls.Supported("shutdown", Shutdown) 56 s.Table[49] = syscalls.Supported("bind", Bind) 57 s.Table[50] = syscalls.Supported("listen", Listen) 58 s.Table[51] = syscalls.Supported("getsockname", GetSockName) 59 s.Table[52] = syscalls.Supported("getpeername", GetPeerName) 60 s.Table[53] = syscalls.Supported("socketpair", SocketPair) 61 s.Table[54] = syscalls.Supported("setsockopt", SetSockOpt) 62 s.Table[55] = syscalls.Supported("getsockopt", GetSockOpt) 63 s.Table[59] = syscalls.Supported("execve", Execve) 64 s.Table[72] = syscalls.Supported("fcntl", Fcntl) 65 s.Table[73] = syscalls.Supported("flock", Flock) 66 s.Table[74] = syscalls.Supported("fsync", Fsync) 67 s.Table[75] = syscalls.Supported("fdatasync", Fdatasync) 68 s.Table[76] = syscalls.Supported("truncate", Truncate) 69 s.Table[77] = syscalls.Supported("ftruncate", Ftruncate) 70 s.Table[78] = syscalls.Supported("getdents", Getdents) 71 s.Table[79] = syscalls.Supported("getcwd", Getcwd) 72 s.Table[80] = syscalls.Supported("chdir", Chdir) 73 s.Table[81] = syscalls.Supported("fchdir", Fchdir) 74 s.Table[82] = syscalls.Supported("rename", Rename) 75 s.Table[83] = syscalls.Supported("mkdir", Mkdir) 76 s.Table[84] = syscalls.Supported("rmdir", Rmdir) 77 s.Table[85] = syscalls.Supported("creat", Creat) 78 s.Table[86] = syscalls.Supported("link", Link) 79 s.Table[87] = syscalls.Supported("unlink", Unlink) 80 s.Table[88] = syscalls.Supported("symlink", Symlink) 81 s.Table[89] = syscalls.Supported("readlink", Readlink) 82 s.Table[90] = syscalls.Supported("chmod", Chmod) 83 s.Table[91] = syscalls.Supported("fchmod", Fchmod) 84 s.Table[92] = syscalls.Supported("chown", Chown) 85 s.Table[93] = syscalls.Supported("fchown", Fchown) 86 s.Table[94] = syscalls.Supported("lchown", Lchown) 87 s.Table[132] = syscalls.Supported("utime", Utime) 88 s.Table[133] = syscalls.Supported("mknod", Mknod) 89 s.Table[137] = syscalls.Supported("statfs", Statfs) 90 s.Table[138] = syscalls.Supported("fstatfs", Fstatfs) 91 s.Table[161] = syscalls.Supported("chroot", Chroot) 92 s.Table[162] = syscalls.Supported("sync", Sync) 93 s.Table[165] = syscalls.Supported("mount", Mount) 94 s.Table[166] = syscalls.Supported("umount2", Umount2) 95 s.Table[187] = syscalls.Supported("readahead", Readahead) 96 s.Table[188] = syscalls.Supported("setxattr", SetXattr) 97 s.Table[189] = syscalls.Supported("lsetxattr", Lsetxattr) 98 s.Table[190] = syscalls.Supported("fsetxattr", Fsetxattr) 99 s.Table[191] = syscalls.Supported("getxattr", GetXattr) 100 s.Table[192] = syscalls.Supported("lgetxattr", Lgetxattr) 101 s.Table[193] = syscalls.Supported("fgetxattr", Fgetxattr) 102 s.Table[194] = syscalls.Supported("listxattr", ListXattr) 103 s.Table[195] = syscalls.Supported("llistxattr", Llistxattr) 104 s.Table[196] = syscalls.Supported("flistxattr", Flistxattr) 105 s.Table[197] = syscalls.Supported("removexattr", RemoveXattr) 106 s.Table[198] = syscalls.Supported("lremovexattr", Lremovexattr) 107 s.Table[199] = syscalls.Supported("fremovexattr", Fremovexattr) 108 s.Table[209] = syscalls.PartiallySupported("io_submit", IoSubmit, "Generally supported with exceptions. User ring optimizations are not implemented.", []string{"github.com/SagerNet/issue/204"}) 109 s.Table[213] = syscalls.Supported("epoll_create", EpollCreate) 110 s.Table[217] = syscalls.Supported("getdents64", Getdents64) 111 s.Table[221] = syscalls.PartiallySupported("fadvise64", Fadvise64, "The syscall is 'supported', but ignores all provided advice.", nil) 112 s.Table[232] = syscalls.Supported("epoll_wait", EpollWait) 113 s.Table[233] = syscalls.Supported("epoll_ctl", EpollCtl) 114 s.Table[235] = syscalls.Supported("utimes", Utimes) 115 s.Table[253] = syscalls.PartiallySupported("inotify_init", InotifyInit, "inotify events are only available inside the sandbox.", nil) 116 s.Table[254] = syscalls.PartiallySupported("inotify_add_watch", InotifyAddWatch, "inotify events are only available inside the sandbox.", nil) 117 s.Table[255] = syscalls.PartiallySupported("inotify_rm_watch", InotifyRmWatch, "inotify events are only available inside the sandbox.", nil) 118 s.Table[257] = syscalls.Supported("openat", Openat) 119 s.Table[258] = syscalls.Supported("mkdirat", Mkdirat) 120 s.Table[259] = syscalls.Supported("mknodat", Mknodat) 121 s.Table[260] = syscalls.Supported("fchownat", Fchownat) 122 s.Table[261] = syscalls.Supported("futimesat", Futimesat) 123 s.Table[262] = syscalls.Supported("newfstatat", Newfstatat) 124 s.Table[263] = syscalls.Supported("unlinkat", Unlinkat) 125 s.Table[264] = syscalls.Supported("renameat", Renameat) 126 s.Table[265] = syscalls.Supported("linkat", Linkat) 127 s.Table[266] = syscalls.Supported("symlinkat", Symlinkat) 128 s.Table[267] = syscalls.Supported("readlinkat", Readlinkat) 129 s.Table[268] = syscalls.Supported("fchmodat", Fchmodat) 130 s.Table[269] = syscalls.Supported("faccessat", Faccessat) 131 s.Table[270] = syscalls.Supported("pselect", Pselect) 132 s.Table[271] = syscalls.Supported("ppoll", Ppoll) 133 s.Table[275] = syscalls.Supported("splice", Splice) 134 s.Table[276] = syscalls.Supported("tee", Tee) 135 s.Table[277] = syscalls.Supported("sync_file_range", SyncFileRange) 136 s.Table[280] = syscalls.Supported("utimensat", Utimensat) 137 s.Table[281] = syscalls.Supported("epoll_pwait", EpollPwait) 138 s.Table[282] = syscalls.Supported("signalfd", Signalfd) 139 s.Table[283] = syscalls.Supported("timerfd_create", TimerfdCreate) 140 s.Table[284] = syscalls.Supported("eventfd", Eventfd) 141 s.Table[285] = syscalls.PartiallySupported("fallocate", Fallocate, "Not all options are supported.", nil) 142 s.Table[286] = syscalls.Supported("timerfd_settime", TimerfdSettime) 143 s.Table[287] = syscalls.Supported("timerfd_gettime", TimerfdGettime) 144 s.Table[288] = syscalls.Supported("accept4", Accept4) 145 s.Table[289] = syscalls.Supported("signalfd4", Signalfd4) 146 s.Table[290] = syscalls.Supported("eventfd2", Eventfd2) 147 s.Table[291] = syscalls.Supported("epoll_create1", EpollCreate1) 148 s.Table[292] = syscalls.Supported("dup3", Dup3) 149 s.Table[293] = syscalls.Supported("pipe2", Pipe2) 150 s.Table[294] = syscalls.PartiallySupported("inotify_init1", InotifyInit1, "inotify events are only available inside the sandbox.", nil) 151 s.Table[295] = syscalls.Supported("preadv", Preadv) 152 s.Table[296] = syscalls.Supported("pwritev", Pwritev) 153 s.Table[299] = syscalls.Supported("recvmmsg", RecvMMsg) 154 s.Table[306] = syscalls.Supported("syncfs", Syncfs) 155 s.Table[307] = syscalls.Supported("sendmmsg", SendMMsg) 156 s.Table[316] = syscalls.Supported("renameat2", Renameat2) 157 s.Table[319] = syscalls.Supported("memfd_create", MemfdCreate) 158 s.Table[322] = syscalls.Supported("execveat", Execveat) 159 s.Table[327] = syscalls.Supported("preadv2", Preadv2) 160 s.Table[328] = syscalls.Supported("pwritev2", Pwritev2) 161 s.Table[332] = syscalls.Supported("statx", Statx) 162 s.Table[441] = syscalls.Supported("epoll_pwait2", EpollPwait2) 163 s.Init() 164 165 // Override ARM64. 166 s = linux.ARM64 167 s.Table[2] = syscalls.PartiallySupported("io_submit", IoSubmit, "Generally supported with exceptions. User ring optimizations are not implemented.", []string{"github.com/SagerNet/issue/204"}) 168 s.Table[5] = syscalls.Supported("setxattr", SetXattr) 169 s.Table[6] = syscalls.Supported("lsetxattr", Lsetxattr) 170 s.Table[7] = syscalls.Supported("fsetxattr", Fsetxattr) 171 s.Table[8] = syscalls.Supported("getxattr", GetXattr) 172 s.Table[9] = syscalls.Supported("lgetxattr", Lgetxattr) 173 s.Table[10] = syscalls.Supported("fgetxattr", Fgetxattr) 174 s.Table[11] = syscalls.Supported("listxattr", ListXattr) 175 s.Table[12] = syscalls.Supported("llistxattr", Llistxattr) 176 s.Table[13] = syscalls.Supported("flistxattr", Flistxattr) 177 s.Table[14] = syscalls.Supported("removexattr", RemoveXattr) 178 s.Table[15] = syscalls.Supported("lremovexattr", Lremovexattr) 179 s.Table[16] = syscalls.Supported("fremovexattr", Fremovexattr) 180 s.Table[17] = syscalls.Supported("getcwd", Getcwd) 181 s.Table[19] = syscalls.Supported("eventfd2", Eventfd2) 182 s.Table[20] = syscalls.Supported("epoll_create1", EpollCreate1) 183 s.Table[21] = syscalls.Supported("epoll_ctl", EpollCtl) 184 s.Table[22] = syscalls.Supported("epoll_pwait", EpollPwait) 185 s.Table[23] = syscalls.Supported("dup", Dup) 186 s.Table[24] = syscalls.Supported("dup3", Dup3) 187 s.Table[25] = syscalls.Supported("fcntl", Fcntl) 188 s.Table[26] = syscalls.PartiallySupported("inotify_init1", InotifyInit1, "inotify events are only available inside the sandbox.", nil) 189 s.Table[27] = syscalls.PartiallySupported("inotify_add_watch", InotifyAddWatch, "inotify events are only available inside the sandbox.", nil) 190 s.Table[28] = syscalls.PartiallySupported("inotify_rm_watch", InotifyRmWatch, "inotify events are only available inside the sandbox.", nil) 191 s.Table[29] = syscalls.Supported("ioctl", Ioctl) 192 s.Table[32] = syscalls.Supported("flock", Flock) 193 s.Table[33] = syscalls.Supported("mknodat", Mknodat) 194 s.Table[34] = syscalls.Supported("mkdirat", Mkdirat) 195 s.Table[35] = syscalls.Supported("unlinkat", Unlinkat) 196 s.Table[36] = syscalls.Supported("symlinkat", Symlinkat) 197 s.Table[37] = syscalls.Supported("linkat", Linkat) 198 s.Table[38] = syscalls.Supported("renameat", Renameat) 199 s.Table[39] = syscalls.Supported("umount2", Umount2) 200 s.Table[40] = syscalls.Supported("mount", Mount) 201 s.Table[43] = syscalls.Supported("statfs", Statfs) 202 s.Table[44] = syscalls.Supported("fstatfs", Fstatfs) 203 s.Table[45] = syscalls.Supported("truncate", Truncate) 204 s.Table[46] = syscalls.Supported("ftruncate", Ftruncate) 205 s.Table[47] = syscalls.PartiallySupported("fallocate", Fallocate, "Not all options are supported.", nil) 206 s.Table[48] = syscalls.Supported("faccessat", Faccessat) 207 s.Table[49] = syscalls.Supported("chdir", Chdir) 208 s.Table[50] = syscalls.Supported("fchdir", Fchdir) 209 s.Table[51] = syscalls.Supported("chroot", Chroot) 210 s.Table[52] = syscalls.Supported("fchmod", Fchmod) 211 s.Table[53] = syscalls.Supported("fchmodat", Fchmodat) 212 s.Table[54] = syscalls.Supported("fchownat", Fchownat) 213 s.Table[55] = syscalls.Supported("fchown", Fchown) 214 s.Table[56] = syscalls.Supported("openat", Openat) 215 s.Table[57] = syscalls.Supported("close", Close) 216 s.Table[59] = syscalls.Supported("pipe2", Pipe2) 217 s.Table[61] = syscalls.Supported("getdents64", Getdents64) 218 s.Table[62] = syscalls.Supported("lseek", Lseek) 219 s.Table[63] = syscalls.Supported("read", Read) 220 s.Table[64] = syscalls.Supported("write", Write) 221 s.Table[65] = syscalls.Supported("readv", Readv) 222 s.Table[66] = syscalls.Supported("writev", Writev) 223 s.Table[67] = syscalls.Supported("pread64", Pread64) 224 s.Table[68] = syscalls.Supported("pwrite64", Pwrite64) 225 s.Table[69] = syscalls.Supported("preadv", Preadv) 226 s.Table[70] = syscalls.Supported("pwritev", Pwritev) 227 s.Table[71] = syscalls.Supported("sendfile", Sendfile) 228 s.Table[72] = syscalls.Supported("pselect", Pselect) 229 s.Table[73] = syscalls.Supported("ppoll", Ppoll) 230 s.Table[74] = syscalls.Supported("signalfd4", Signalfd4) 231 s.Table[76] = syscalls.Supported("splice", Splice) 232 s.Table[77] = syscalls.Supported("tee", Tee) 233 s.Table[78] = syscalls.Supported("readlinkat", Readlinkat) 234 s.Table[79] = syscalls.Supported("newfstatat", Newfstatat) 235 s.Table[80] = syscalls.Supported("fstat", Fstat) 236 s.Table[81] = syscalls.Supported("sync", Sync) 237 s.Table[82] = syscalls.Supported("fsync", Fsync) 238 s.Table[83] = syscalls.Supported("fdatasync", Fdatasync) 239 s.Table[84] = syscalls.Supported("sync_file_range", SyncFileRange) 240 s.Table[85] = syscalls.Supported("timerfd_create", TimerfdCreate) 241 s.Table[86] = syscalls.Supported("timerfd_settime", TimerfdSettime) 242 s.Table[87] = syscalls.Supported("timerfd_gettime", TimerfdGettime) 243 s.Table[88] = syscalls.Supported("utimensat", Utimensat) 244 s.Table[198] = syscalls.Supported("socket", Socket) 245 s.Table[199] = syscalls.Supported("socketpair", SocketPair) 246 s.Table[200] = syscalls.Supported("bind", Bind) 247 s.Table[201] = syscalls.Supported("listen", Listen) 248 s.Table[202] = syscalls.Supported("accept", Accept) 249 s.Table[203] = syscalls.Supported("connect", Connect) 250 s.Table[204] = syscalls.Supported("getsockname", GetSockName) 251 s.Table[205] = syscalls.Supported("getpeername", GetPeerName) 252 s.Table[206] = syscalls.Supported("sendto", SendTo) 253 s.Table[207] = syscalls.Supported("recvfrom", RecvFrom) 254 s.Table[208] = syscalls.Supported("setsockopt", SetSockOpt) 255 s.Table[209] = syscalls.Supported("getsockopt", GetSockOpt) 256 s.Table[210] = syscalls.Supported("shutdown", Shutdown) 257 s.Table[211] = syscalls.Supported("sendmsg", SendMsg) 258 s.Table[212] = syscalls.Supported("recvmsg", RecvMsg) 259 s.Table[213] = syscalls.Supported("readahead", Readahead) 260 s.Table[221] = syscalls.Supported("execve", Execve) 261 s.Table[222] = syscalls.Supported("mmap", Mmap) 262 s.Table[223] = syscalls.PartiallySupported("fadvise64", Fadvise64, "Not all options are supported.", nil) 263 s.Table[242] = syscalls.Supported("accept4", Accept4) 264 s.Table[243] = syscalls.Supported("recvmmsg", RecvMMsg) 265 s.Table[267] = syscalls.Supported("syncfs", Syncfs) 266 s.Table[269] = syscalls.Supported("sendmmsg", SendMMsg) 267 s.Table[276] = syscalls.Supported("renameat2", Renameat2) 268 s.Table[279] = syscalls.Supported("memfd_create", MemfdCreate) 269 s.Table[281] = syscalls.Supported("execveat", Execveat) 270 s.Table[286] = syscalls.Supported("preadv2", Preadv2) 271 s.Table[287] = syscalls.Supported("pwritev2", Pwritev2) 272 s.Table[291] = syscalls.Supported("statx", Statx) 273 s.Table[441] = syscalls.Supported("epoll_pwait2", EpollPwait2) 274 275 s.Init() 276 }