From 7a079f778097502d12d90962a58e422e0d76d14e Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Boric Date: Sat, 13 Mar 2021 22:02:54 +0100 Subject: [PATCH] LibC+Kernel: Switch off_t to 64 bits --- Kernel/API/Syscall.h | 2 +- Kernel/Process.h | 4 ++-- Kernel/Syscalls/ftruncate.cpp | 5 ++++- Kernel/Syscalls/lseek.cpp | 13 +++++++++++-- Kernel/UnixTypes.h | 4 +--- Userland/Libraries/LibC/sys/types.h | 2 +- Userland/Libraries/LibC/unistd.cpp | 6 +++--- 7 files changed, 23 insertions(+), 13 deletions(-) diff --git a/Kernel/API/Syscall.h b/Kernel/API/Syscall.h index 4c873e2688b..88aa5a13132 100644 --- a/Kernel/API/Syscall.h +++ b/Kernel/API/Syscall.h @@ -244,7 +244,7 @@ struct SC_mmap_params { int32_t prot; int32_t flags; int32_t fd; - ssize_t offset; + int64_t offset; StringArgument name; }; diff --git a/Kernel/Process.h b/Kernel/Process.h index c27bf874a23..b1e864817dc 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -276,7 +276,6 @@ public: KResultOr sys$dump_backtrace(); KResultOr sys$gettid(); KResultOr sys$donate(pid_t tid); - KResultOr sys$ftruncate(int fd, off_t); KResultOr sys$setsid(); KResultOr sys$getsid(pid_t); KResultOr sys$setpgid(pid_t pid, pid_t pgid); @@ -299,7 +298,8 @@ public: KResultOr sys$writev(int fd, Userspace iov, int iov_count); KResultOr sys$fstat(int fd, Userspace); KResultOr sys$stat(Userspace); - KResultOr sys$lseek(int fd, off_t, int whence); + KResultOr sys$lseek(int fd, Userspace, int whence); + KResultOr sys$ftruncate(int fd, Userspace); KResultOr sys$kill(pid_t pid_or_pgid, int sig); [[noreturn]] void sys$exit(int status); KResultOr sys$sigreturn(RegisterState& registers); diff --git a/Kernel/Syscalls/ftruncate.cpp b/Kernel/Syscalls/ftruncate.cpp index 6fc9afcc79a..2a1a00530ec 100644 --- a/Kernel/Syscalls/ftruncate.cpp +++ b/Kernel/Syscalls/ftruncate.cpp @@ -29,9 +29,12 @@ namespace Kernel { -KResultOr Process::sys$ftruncate(int fd, off_t length) +KResultOr Process::sys$ftruncate(int fd, Userspace userspace_length) { REQUIRE_PROMISE(stdio); + off_t length; + if (!copy_from_user(&length, userspace_length)) + return EFAULT; if (length < 0) return EINVAL; auto description = file_description(fd); diff --git a/Kernel/Syscalls/lseek.cpp b/Kernel/Syscalls/lseek.cpp index 14e2cea1fff..015c490c508 100644 --- a/Kernel/Syscalls/lseek.cpp +++ b/Kernel/Syscalls/lseek.cpp @@ -29,13 +29,22 @@ namespace Kernel { -KResultOr Process::sys$lseek(int fd, off_t offset, int whence) +KResultOr Process::sys$lseek(int fd, Userspace userspace_offset, int whence) { REQUIRE_PROMISE(stdio); auto description = file_description(fd); if (!description) return EBADF; - return description->seek(offset, whence); + off_t offset; + if (!copy_from_user(&offset, userspace_offset)) + return EFAULT; + offset = description->seek(offset, whence); + if (!copy_to_user(userspace_offset, &offset)) + return EFAULT; + if (offset < 0) + return offset; + else + return 0; } } diff --git a/Kernel/UnixTypes.h b/Kernel/UnixTypes.h index 6932baae62e..3846dbe10e1 100644 --- a/Kernel/UnixTypes.h +++ b/Kernel/UnixTypes.h @@ -424,9 +424,7 @@ struct sigaction { #define CLD_STOPPED 4 #define CLD_CONTINUED 5 -#define OFF_T_MAX 2147483647 - -typedef ssize_t off_t; +typedef i64 off_t; typedef i64 time_t; struct utimbuf { diff --git a/Userland/Libraries/LibC/sys/types.h b/Userland/Libraries/LibC/sys/types.h index 5bb4dc4150f..e044904f808 100644 --- a/Userland/Libraries/LibC/sys/types.h +++ b/Userland/Libraries/LibC/sys/types.h @@ -55,7 +55,7 @@ typedef int id_t; typedef __WINT_TYPE__ wint_t; typedef uint32_t ino_t; -typedef ssize_t off_t; +typedef int64_t off_t; typedef uint32_t dev_t; typedef uint16_t mode_t; diff --git a/Userland/Libraries/LibC/unistd.cpp b/Userland/Libraries/LibC/unistd.cpp index e6a29bc41ba..e20c49d4c11 100644 --- a/Userland/Libraries/LibC/unistd.cpp +++ b/Userland/Libraries/LibC/unistd.cpp @@ -440,8 +440,8 @@ ssize_t readlink(const char* path, char* buffer, size_t size) off_t lseek(int fd, off_t offset, int whence) { - int rc = syscall(SC_lseek, fd, offset, whence); - __RETURN_WITH_ERRNO(rc, rc, -1); + int rc = syscall(SC_lseek, fd, &offset, whence); + __RETURN_WITH_ERRNO(rc, offset, -1); } int link(const char* old_path, const char* new_path) @@ -633,7 +633,7 @@ char* getlogin() int ftruncate(int fd, off_t length) { - int rc = syscall(SC_ftruncate, fd, length); + int rc = syscall(SC_ftruncate, fd, &length); __RETURN_WITH_ERRNO(rc, rc, -1); }