diff options
author | Andreas Kling <kling@serenityos.org> | 2021-12-17 08:34:27 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-12-18 11:30:10 +0100 |
commit | 39d9337db5056c9d8c9eb17cbceb6cec0b627510 (patch) | |
tree | 72f638f4578fbe94af6ec1735ce82b25ade8a853 | |
parent | 9c7659306a7d072f1c3b701533436c45644df693 (diff) | |
download | serenity-39d9337db5056c9d8c9eb17cbceb6cec0b627510.zip |
Kernel: Make sys${ftruncate,pread} take off_t as const pointer
These syscalls don't write back to the off_t value (unlike sys$lseek)
so let's take Userspace<off_t const*> instead of Userspace<off_t*>.
-rw-r--r-- | Kernel/Process.h | 4 | ||||
-rw-r--r-- | Kernel/Syscalls/ftruncate.cpp | 5 | ||||
-rw-r--r-- | Kernel/Syscalls/read.cpp | 5 |
3 files changed, 6 insertions, 8 deletions
diff --git a/Kernel/Process.h b/Kernel/Process.h index 0e64e326cf..dff5e01325 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -294,14 +294,14 @@ public: ErrorOr<FlatPtr> sys$open(Userspace<const Syscall::SC_open_params*>); ErrorOr<FlatPtr> sys$close(int fd); ErrorOr<FlatPtr> sys$read(int fd, Userspace<u8*>, size_t); - ErrorOr<FlatPtr> sys$pread(int fd, Userspace<u8*>, size_t, Userspace<off_t*>); + ErrorOr<FlatPtr> sys$pread(int fd, Userspace<u8*>, size_t, Userspace<off_t const*>); ErrorOr<FlatPtr> sys$readv(int fd, Userspace<const struct iovec*> iov, int iov_count); ErrorOr<FlatPtr> sys$write(int fd, Userspace<const u8*>, size_t); ErrorOr<FlatPtr> sys$writev(int fd, Userspace<const struct iovec*> iov, int iov_count); ErrorOr<FlatPtr> sys$fstat(int fd, Userspace<stat*>); ErrorOr<FlatPtr> sys$stat(Userspace<const Syscall::SC_stat_params*>); ErrorOr<FlatPtr> sys$lseek(int fd, Userspace<off_t*>, int whence); - ErrorOr<FlatPtr> sys$ftruncate(int fd, Userspace<off_t*>); + ErrorOr<FlatPtr> sys$ftruncate(int fd, Userspace<off_t const*>); ErrorOr<FlatPtr> sys$kill(pid_t pid_or_pgid, int sig); [[noreturn]] void sys$exit(int status); ErrorOr<FlatPtr> sys$sigreturn(RegisterState& registers); diff --git a/Kernel/Syscalls/ftruncate.cpp b/Kernel/Syscalls/ftruncate.cpp index f430d25433..feaf027a99 100644 --- a/Kernel/Syscalls/ftruncate.cpp +++ b/Kernel/Syscalls/ftruncate.cpp @@ -9,12 +9,11 @@ namespace Kernel { -ErrorOr<FlatPtr> Process::sys$ftruncate(int fd, Userspace<off_t*> userspace_length) +ErrorOr<FlatPtr> Process::sys$ftruncate(int fd, Userspace<off_t const*> userspace_length) { VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this) REQUIRE_PROMISE(stdio); - off_t length; - TRY(copy_from_user(&length, userspace_length)); + auto length = TRY(copy_typed_from_user(userspace_length)); if (length < 0) return EINVAL; auto description = TRY(fds().open_file_description(fd)); diff --git a/Kernel/Syscalls/read.cpp b/Kernel/Syscalls/read.cpp index 190a7fe8c5..2f9e21e98a 100644 --- a/Kernel/Syscalls/read.cpp +++ b/Kernel/Syscalls/read.cpp @@ -86,7 +86,7 @@ ErrorOr<FlatPtr> Process::sys$read(int fd, Userspace<u8*> buffer, size_t size) return TRY(description->read(user_buffer, size)); } -ErrorOr<FlatPtr> Process::sys$pread(int fd, Userspace<u8*> buffer, size_t size, Userspace<off_t*> userspace_offset) +ErrorOr<FlatPtr> Process::sys$pread(int fd, Userspace<u8*> buffer, size_t size, Userspace<off_t const*> userspace_offset) { VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this) REQUIRE_PROMISE(stdio); @@ -94,8 +94,7 @@ ErrorOr<FlatPtr> Process::sys$pread(int fd, Userspace<u8*> buffer, size_t size, return 0; if (size > NumericLimits<ssize_t>::max()) return EINVAL; - off_t offset; - TRY(copy_from_user(&offset, userspace_offset)); + auto offset = TRY(copy_typed_from_user(userspace_offset)); if (offset < 0) return EINVAL; dbgln_if(IO_DEBUG, "sys$pread({}, {}, {}, {})", fd, buffer.ptr(), size, offset); |