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*>.
This commit is contained in:
Andreas Kling 2021-12-17 08:34:27 +01:00
parent 9c7659306a
commit 39d9337db5
Notes: sideshowbarker 2024-07-17 22:40:15 +09:00
3 changed files with 6 additions and 8 deletions

View File

@ -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);

View File

@ -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));

View File

@ -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);