From 648a139af36d6803fbe0674d4c6d461f46564e84 Mon Sep 17 00:00:00 2001 From: Daniel Bertalan Date: Sat, 13 Nov 2021 09:28:56 +0100 Subject: [PATCH] Kernel+LibC: Pass off_t to pread() via a pointer `off_t` is a 64-bit signed integer, so passing it in a register on i686 is not the best idea. This fix gets us one step closer to making the LLVM port work. --- Kernel/Process.h | 2 +- Kernel/Syscalls/read.cpp | 4 +++- Userland/Libraries/LibC/unistd.cpp | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Kernel/Process.h b/Kernel/Process.h index f212074fc2..64feb852a0 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -294,7 +294,7 @@ public: ErrorOr sys$open(Userspace); ErrorOr sys$close(int fd); ErrorOr sys$read(int fd, Userspace, size_t); - ErrorOr sys$pread(int fd, Userspace, size_t, off_t); + ErrorOr sys$pread(int fd, Userspace, size_t, Userspace); ErrorOr sys$readv(int fd, Userspace iov, int iov_count); ErrorOr sys$write(int fd, Userspace, size_t); ErrorOr sys$writev(int fd, Userspace iov, int iov_count); diff --git a/Kernel/Syscalls/read.cpp b/Kernel/Syscalls/read.cpp index 4dc7b0d15a..a001285925 100644 --- a/Kernel/Syscalls/read.cpp +++ b/Kernel/Syscalls/read.cpp @@ -90,7 +90,7 @@ ErrorOr Process::sys$read(int fd, Userspace buffer, size_t size) return TRY(description->read(user_buffer.value(), size)); } -ErrorOr Process::sys$pread(int fd, Userspace buffer, size_t size, off_t offset) +ErrorOr Process::sys$pread(int fd, Userspace buffer, size_t size, Userspace userspace_offset) { VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this) REQUIRE_PROMISE(stdio); @@ -98,6 +98,8 @@ ErrorOr Process::sys$pread(int fd, Userspace buffer, size_t size, return 0; if (size > NumericLimits::max()) return EINVAL; + off_t offset; + TRY(copy_from_user(&offset, userspace_offset)); if (offset < 0) return EINVAL; dbgln_if(IO_DEBUG, "sys$pread({}, {}, {}, {})", fd, buffer.ptr(), size, offset); diff --git a/Userland/Libraries/LibC/unistd.cpp b/Userland/Libraries/LibC/unistd.cpp index 88d28f759d..c08c377998 100644 --- a/Userland/Libraries/LibC/unistd.cpp +++ b/Userland/Libraries/LibC/unistd.cpp @@ -296,7 +296,7 @@ ssize_t read(int fd, void* buf, size_t count) ssize_t pread(int fd, void* buf, size_t count, off_t offset) { - int rc = syscall(SC_pread, fd, buf, count, offset); + int rc = syscall(SC_pread, fd, buf, count, &offset); __RETURN_WITH_ERRNO(rc, rc, -1); }