diff options
author | Adin Scannell <ascannell@google.com> | 2019-09-24 13:25:25 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2019-09-24 13:29:46 -0700 |
commit | 502f8f238ea58c4828e528e563d8dbd419faeea7 (patch) | |
tree | e033e3d1ca0d32b9eca9faf0feb45c78a97b1f94 /pkg/sentry/syscalls/linux/sys_read.go | |
parent | 6704d625ef2726a54078f4179d0eaa2c820cc401 (diff) |
Stub out readahead implementation.
Closes #261
PiperOrigin-RevId: 270973347
Diffstat (limited to 'pkg/sentry/syscalls/linux/sys_read.go')
-rw-r--r-- | pkg/sentry/syscalls/linux/sys_read.go | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/pkg/sentry/syscalls/linux/sys_read.go b/pkg/sentry/syscalls/linux/sys_read.go index 3ab54271c..cd31e0649 100644 --- a/pkg/sentry/syscalls/linux/sys_read.go +++ b/pkg/sentry/syscalls/linux/sys_read.go @@ -72,6 +72,39 @@ func Read(t *kernel.Task, args arch.SyscallArguments) (uintptr, *kernel.SyscallC return uintptr(n), nil, handleIOError(t, n != 0, err, kernel.ERESTARTSYS, "read", file) } +// Readahead implements readahead(2). +func Readahead(t *kernel.Task, args arch.SyscallArguments) (uintptr, *kernel.SyscallControl, error) { + fd := args[0].Int() + offset := args[1].Int64() + size := args[2].SizeT() + + file := t.GetFile(fd) + if file == nil { + return 0, nil, syserror.EBADF + } + defer file.DecRef() + + // Check that the file is readable. + if !file.Flags().Read { + return 0, nil, syserror.EBADF + } + + // Check that the size is valid. + if int(size) < 0 { + return 0, nil, syserror.EINVAL + } + + // Check that the offset is legitimate. + if offset < 0 { + return 0, nil, syserror.EINVAL + } + + // Return EINVAL; if the underlying file type does not support readahead, + // then Linux will return EINVAL to indicate as much. In the future, we + // may extend this function to actually support readahead hints. + return 0, nil, syserror.EINVAL +} + // Pread64 implements linux syscall pread64(2). func Pread64(t *kernel.Task, args arch.SyscallArguments) (uintptr, *kernel.SyscallControl, error) { fd := args[0].Int() |