Kernel: Use Userspace<T> in sys$getcwd() and sys$chdir()

Add more validation helper overloads as we go. :^)
This commit is contained in:
Andreas Kling 2020-07-31 16:34:47 +02:00
parent 314dbc10d4
commit 62a4099581
3 changed files with 16 additions and 4 deletions

View file

@ -230,8 +230,8 @@ public:
int sys$select(const Syscall::SC_select_params*);
int sys$poll(const Syscall::SC_poll_params*);
ssize_t sys$get_dir_entries(int fd, void*, ssize_t);
int sys$getcwd(char*, ssize_t);
int sys$chdir(const char*, size_t);
int sys$getcwd(Userspace<char*>, ssize_t);
int sys$chdir(Userspace<const char*>, size_t);
int sys$fchdir(int fd);
int sys$sleep(unsigned seconds);
int sys$usleep(useconds_t usec);

View file

@ -83,3 +83,15 @@ inline void copy_to_user(Userspace<T*> dest, const T* src)
{
copy_to_user((T*)dest.ptr(), src, sizeof(T));
}
template<typename T>
inline void copy_to_user(Userspace<T*> dest, const void* src, size_t size)
{
copy_to_user((void*)dest.ptr(), src, size);
}
template<typename T>
inline void copy_from_user(void* dest, Userspace<const T*> src, size_t size)
{
copy_from_user(dest, (const void*)src.ptr(), size);
}

View file

@ -31,7 +31,7 @@
namespace Kernel {
int Process::sys$chdir(const char* user_path, size_t path_length)
int Process::sys$chdir(Userspace<const char*> user_path, size_t path_length)
{
REQUIRE_PROMISE(rpath);
auto path = get_syscall_path_argument(user_path, path_length);
@ -61,7 +61,7 @@ int Process::sys$fchdir(int fd)
return 0;
}
int Process::sys$getcwd(char* buffer, ssize_t size)
int Process::sys$getcwd(Userspace<char*> buffer, ssize_t size)
{
REQUIRE_PROMISE(rpath);
if (size < 0)