Kernel: Convert Process::get_syscall_path_argument() to KString

This API now returns a KResultOr<NonnullOwnPtr<KString>> and allocation
failures should be propagated everywhere nicely. :^)
This commit is contained in:
Andreas Kling 2021-05-29 16:59:40 +02:00
parent 66f3ec687b
commit 1123af361d
Notes: sideshowbarker 2024-07-18 17:12:01 +09:00
25 changed files with 42 additions and 42 deletions

View file

@ -434,19 +434,19 @@ Custody& Process::current_directory()
return *m_cwd;
}
KResultOr<String> Process::get_syscall_path_argument(const char* user_path, size_t path_length) const
KResultOr<NonnullOwnPtr<KString>> Process::get_syscall_path_argument(char const* user_path, size_t path_length) const
{
if (path_length == 0)
return EINVAL;
if (path_length > PATH_MAX)
return ENAMETOOLONG;
auto copied_string = copy_string_from_user(user_path, path_length);
if (copied_string.is_null())
return EFAULT;
return copied_string;
auto string_or_error = try_copy_kstring_from_user(user_path, path_length);
if (string_or_error.is_error())
return string_or_error.error();
return string_or_error.release_value();
}
KResultOr<String> Process::get_syscall_path_argument(const Syscall::StringArgument& path) const
KResultOr<NonnullOwnPtr<KString>> Process::get_syscall_path_argument(Syscall::StringArgument const& path) const
{
return get_syscall_path_argument(path.characters, path.length);
}

View file

@ -546,12 +546,12 @@ private:
KResultOr<siginfo_t> do_waitid(idtype_t idtype, int id, int options);
KResultOr<String> get_syscall_path_argument(const char* user_path, size_t path_length) const;
KResultOr<String> get_syscall_path_argument(Userspace<const char*> user_path, size_t path_length) const
KResultOr<NonnullOwnPtr<KString>> get_syscall_path_argument(const char* user_path, size_t path_length) const;
KResultOr<NonnullOwnPtr<KString>> get_syscall_path_argument(Userspace<const char*> user_path, size_t path_length) const
{
return get_syscall_path_argument(user_path.unsafe_userspace_ptr(), path_length);
}
KResultOr<String> get_syscall_path_argument(const Syscall::StringArgument&) const;
KResultOr<NonnullOwnPtr<KString>> get_syscall_path_argument(const Syscall::StringArgument&) const;
bool has_tracee_thread(ProcessID tracer_pid);

View file

@ -16,7 +16,7 @@ KResultOr<int> Process::sys$access(Userspace<const char*> user_path, size_t path
auto path = get_syscall_path_argument(user_path, path_length);
if (path.is_error())
return path.error();
return VFS::the().access(path.value(), mode, current_directory());
return VFS::the().access(path.value()->view(), mode, current_directory());
}
}

View file

@ -17,7 +17,7 @@ KResultOr<int> Process::sys$chdir(Userspace<const char*> user_path, size_t path_
auto path = get_syscall_path_argument(user_path, path_length);
if (path.is_error())
return path.error();
auto directory_or_error = VFS::the().open_directory(path.value(), current_directory());
auto directory_or_error = VFS::the().open_directory(path.value()->view(), current_directory());
if (directory_or_error.is_error())
return directory_or_error.error();
m_cwd = *directory_or_error.value();

View file

@ -17,7 +17,7 @@ KResultOr<int> Process::sys$chmod(Userspace<const char*> user_path, size_t path_
auto path = get_syscall_path_argument(user_path, path_length);
if (path.is_error())
return path.error();
return VFS::the().chmod(path.value(), mode, current_directory());
return VFS::the().chmod(path.value()->view(), mode, current_directory());
}
KResultOr<int> Process::sys$fchmod(int fd, mode_t mode)

View file

@ -27,7 +27,7 @@ KResultOr<int> Process::sys$chown(Userspace<const Syscall::SC_chown_params*> use
auto path = get_syscall_path_argument(params.path);
if (path.is_error())
return path.error();
return VFS::the().chown(path.value(), params.uid, params.gid, current_directory());
return VFS::the().chown(path.value()->view(), params.uid, params.gid, current_directory());
}
}

View file

@ -19,7 +19,7 @@ KResultOr<int> Process::sys$chroot(Userspace<const char*> user_path, size_t path
auto path = get_syscall_path_argument(user_path, path_length);
if (path.is_error())
return path.error();
auto directory_or_error = VFS::the().open_directory(path.value(), current_directory());
auto directory_or_error = VFS::the().open_directory(path.value()->view(), current_directory());
if (directory_or_error.is_error())
return directory_or_error.error();
auto directory = directory_or_error.value();

View file

@ -920,7 +920,7 @@ KResultOr<int> Process::sys$execve(Userspace<const Syscall::SC_execve_params*> u
auto path_arg = get_syscall_path_argument(params.path);
if (path_arg.is_error())
return path_arg.error();
path = path_arg.value();
path = path_arg.value()->view();
}
auto copy_user_strings = [](const auto& list, auto& output) {

View file

@ -59,7 +59,7 @@ KResultOr<int> Process::sys$inode_watcher_add_watch(Userspace<const Syscall::SC_
if (path.is_error())
return path.error();
auto custody_or_error = VFS::the().resolve_path(path.value(), current_directory());
auto custody_or_error = VFS::the().resolve_path(path.value()->view(), current_directory());
if (custody_or_error.is_error())
return custody_or_error.error();

View file

@ -36,13 +36,12 @@ KResultOr<int> Process::sys$setkeymap(Userspace<const Syscall::SC_setkeymap_para
return EFAULT;
auto map_name = get_syscall_path_argument(params.map_name);
if (map_name.is_error()) {
if (map_name.is_error())
return map_name.error();
}
if (map_name.value().length() > map_name_max_size) {
if (map_name.value()->length() > map_name_max_size)
return ENAMETOOLONG;
}
HIDManagement::the().set_maps(character_map_data, map_name.value());
HIDManagement::the().set_maps(character_map_data, map_name.value()->view());
return 0;
}

View file

@ -37,7 +37,7 @@ KResultOr<int> Process::sys$symlink(Userspace<const Syscall::SC_symlink_params*>
auto linkpath = get_syscall_path_argument(params.linkpath);
if (linkpath.is_error())
return linkpath.error();
return VFS::the().symlink(target.value(), linkpath.value(), current_directory());
return VFS::the().symlink(target.value()->view(), linkpath.value()->view(), current_directory());
}
}

View file

@ -16,6 +16,6 @@ KResultOr<int> Process::sys$mkdir(Userspace<const char*> user_path, size_t path_
auto path = get_syscall_path_argument(user_path, path_length);
if (path.is_error())
return path.error();
return VFS::the().mkdir(path.value(), mode & ~umask(), current_directory());
return VFS::the().mkdir(path.value()->view(), mode & ~umask(), current_directory());
}
}

View file

@ -21,7 +21,7 @@ KResultOr<int> Process::sys$mknod(Userspace<const Syscall::SC_mknod_params*> use
auto path = get_syscall_path_argument(params.path);
if (path.is_error())
return path.error();
return VFS::the().mknod(path.value(), params.mode & ~umask(), params.dev, current_directory());
return VFS::the().mknod(path.value()->view(), params.mode & ~umask(), params.dev, current_directory());
}
}

View file

@ -25,7 +25,7 @@ KResultOr<int> Process::sys$module_load(Userspace<const char*> user_path, size_t
auto path = get_syscall_path_argument(user_path, path_length);
if (path.is_error())
return path.error();
auto description_or_error = VFS::the().open(path.value(), O_RDONLY, 0, current_directory());
auto description_or_error = VFS::the().open(path.value()->view(), O_RDONLY, 0, current_directory());
if (description_or_error.is_error())
return description_or_error.error();
auto& description = description_or_error.value();

View file

@ -119,7 +119,7 @@ KResultOr<int> Process::sys$umount(Userspace<const char*> user_mountpoint, size_
if (mountpoint.is_error())
return mountpoint.error();
auto custody_or_error = VFS::the().resolve_path(mountpoint.value(), current_directory());
auto custody_or_error = VFS::the().resolve_path(mountpoint.value()->view(), current_directory());
if (custody_or_error.is_error())
return custody_or_error.error();

View file

@ -43,7 +43,7 @@ KResultOr<int> Process::sys$open(Userspace<const Syscall::SC_open_params*> user_
if (path.is_error())
return path.error();
dbgln_if(IO_DEBUG, "sys$open(dirfd={}, path='{}', options={}, mode={})", dirfd, path.value(), options, mode);
dbgln_if(IO_DEBUG, "sys$open(dirfd={}, path='{}', options={}, mode={})", dirfd, path.value()->view(), options, mode);
int fd = alloc_fd();
if (fd < 0)
return fd;
@ -62,7 +62,7 @@ KResultOr<int> Process::sys$open(Userspace<const Syscall::SC_open_params*> user_
base = base_description->custody();
}
auto result = VFS::the().open(path.value(), options, mode & ~umask(), *base);
auto result = VFS::the().open(path.value()->view(), options, mode & ~umask(), *base);
if (result.is_error())
return result.error();
auto description = result.value();

View file

@ -23,7 +23,7 @@ KResultOr<int> Process::sys$readlink(Userspace<const Syscall::SC_readlink_params
if (path.is_error())
return path.error();
auto result = VFS::the().open(path.value(), O_RDONLY | O_NOFOLLOW_NOERROR, 0, current_directory());
auto result = VFS::the().open(path.value()->view(), O_RDONLY | O_NOFOLLOW_NOERROR, 0, current_directory());
if (result.is_error())
return result.error();
auto description = result.value();

View file

@ -23,7 +23,7 @@ KResultOr<int> Process::sys$realpath(Userspace<const Syscall::SC_realpath_params
if (path.is_error())
return path.error();
auto custody_or_error = VFS::the().resolve_path(path.value(), current_directory());
auto custody_or_error = VFS::the().resolve_path(path.value()->view(), current_directory());
if (custody_or_error.is_error())
return custody_or_error.error();
auto& custody = custody_or_error.value();

View file

@ -22,7 +22,7 @@ KResultOr<int> Process::sys$rename(Userspace<const Syscall::SC_rename_params*> u
auto new_path = get_syscall_path_argument(params.new_path);
if (new_path.is_error())
return new_path.error();
return VFS::the().rename(old_path.value(), new_path.value(), current_directory());
return VFS::the().rename(old_path.value()->view(), new_path.value()->view(), current_directory());
}
}

View file

@ -16,7 +16,7 @@ KResultOr<int> Process::sys$rmdir(Userspace<const char*> user_path, size_t path_
auto path = get_syscall_path_argument(user_path, path_length);
if (path.is_error())
return path.error();
return VFS::the().rmdir(path.value(), current_directory());
return VFS::the().rmdir(path.value()->view(), current_directory());
}
}

View file

@ -47,7 +47,7 @@ KResultOr<int> Process::sys$stat(Userspace<const Syscall::SC_stat_params*> user_
return EINVAL;
base = base_description->custody();
}
auto metadata_or_error = VFS::the().lookup_metadata(path.value(), *base, params.follow_symlinks ? 0 : O_NOFOLLOW_NOERROR);
auto metadata_or_error = VFS::the().lookup_metadata(path.value()->view(), *base, params.follow_symlinks ? 0 : O_NOFOLLOW_NOERROR);
if (metadata_or_error.is_error())
return metadata_or_error.error();
stat statbuf;

View file

@ -80,7 +80,7 @@ KResultOr<int> Process::sys$statvfs(Userspace<const Syscall::SC_statvfs_params*>
if (path.is_error())
return path.error();
return do_statvfs(path.value(), params.buf);
return do_statvfs(path.value()->view(), params.buf);
}
KResultOr<int> Process::sys$fstatvfs(int fd, statvfs* buf)

View file

@ -16,7 +16,7 @@ KResultOr<int> Process::sys$unlink(Userspace<const char*> user_path, size_t path
auto path = get_syscall_path_argument(user_path, path_length);
if (path.is_error())
return path.error();
return VFS::the().unlink(path.value(), current_directory());
return VFS::the().unlink(path.value()->view(), current_directory());
}
}

View file

@ -32,11 +32,12 @@ KResultOr<int> Process::sys$unveil(Userspace<const Syscall::SC_unveil_params*> u
if (params.permissions.length > 5)
return EINVAL;
auto path = get_syscall_path_argument(params.path);
if (path.is_error())
return path.error();
auto path_or_error = get_syscall_path_argument(params.path);
if (path_or_error.is_error())
return path_or_error.error();
auto& path = *path_or_error.value();
if (path.value().is_empty() || path.value().characters()[0] != '/')
if (path.is_empty() || !path.view().starts_with('/'))
return EINVAL;
auto permissions = copy_string_from_user(params.permissions);
@ -74,11 +75,11 @@ KResultOr<int> Process::sys$unveil(Userspace<const Syscall::SC_unveil_params*> u
// If this case is encountered, the parent node of the path is returned and the custody of that inode is used instead.
RefPtr<Custody> parent_custody; // Parent inode in case of ENOENT
String new_unveiled_path;
auto custody_or_error = VFS::the().resolve_path_without_veil(path.value(), root_directory(), &parent_custody);
auto custody_or_error = VFS::the().resolve_path_without_veil(path.view(), root_directory(), &parent_custody);
if (!custody_or_error.is_error()) {
new_unveiled_path = custody_or_error.value()->absolute_path();
} else if (custody_or_error.error() == -ENOENT && parent_custody && (new_permissions & UnveilAccess::CreateOrRemove)) {
String basename = LexicalPath(path.value()).basename();
String basename = LexicalPath(path.view()).basename();
new_unveiled_path = String::formatted("{}/{}", parent_custody->absolute_path(), basename);
} else {
// FIXME Should this be EINVAL?

View file

@ -25,7 +25,7 @@ KResultOr<int> Process::sys$utime(Userspace<const char*> user_path, size_t path_
// Not a bug!
buf = { now, now };
}
return VFS::the().utime(path.value(), current_directory(), buf.actime, buf.modtime);
return VFS::the().utime(path.value()->view(), current_directory(), buf.actime, buf.modtime);
}
}