Skip to content

Commit

Permalink
Kernel: Convert Process::get_syscall_path_argument() to KString
Browse files Browse the repository at this point in the history
This API now returns a KResultOr<NonnullOwnPtr<KString>> and allocation
failures should be propagated everywhere nicely. :^)
  • Loading branch information
awesomekling committed May 29, 2021
1 parent 66f3ec6 commit 1123af3
Show file tree
Hide file tree
Showing 25 changed files with 42 additions and 42 deletions.
12 changes: 6 additions & 6 deletions Kernel/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions Kernel/Process.h
Original file line number Diff line number Diff line change
Expand Up @@ -546,12 +546,12 @@ class Process

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

Expand Down
2 changes: 1 addition & 1 deletion Kernel/Syscalls/access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

}
2 changes: 1 addition & 1 deletion Kernel/Syscalls/chdir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Syscalls/chmod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Syscalls/chown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

}
2 changes: 1 addition & 1 deletion Kernel/Syscalls/chroot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Syscalls/execve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Syscalls/inode_watcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
9 changes: 4 additions & 5 deletions Kernel/Syscalls/keymap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion Kernel/Syscalls/link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

}
2 changes: 1 addition & 1 deletion Kernel/Syscalls/mkdir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
2 changes: 1 addition & 1 deletion Kernel/Syscalls/mknod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

}
2 changes: 1 addition & 1 deletion Kernel/Syscalls/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Syscalls/mount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions Kernel/Syscalls/open.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Syscalls/readlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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__NOERROR, 0, current_directory());
auto result = VFS::the().open(path.value()->view(), O_RDONLY | O__NOERROR, 0, current_directory());
if (result.is_error())
return result.error();
auto description = result.value();
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Syscalls/realpath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Syscalls/rename.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

}
2 changes: 1 addition & 1 deletion Kernel/Syscalls/rmdir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

}
2 changes: 1 addition & 1 deletion Kernel/Syscalls/stat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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__NOERROR);
auto metadata_or_error = VFS::the().lookup_metadata(path.value()->view(), *base, params.follow_symlinks ? 0 : O__NOERROR);
if (metadata_or_error.is_error())
return metadata_or_error.error();
stat statbuf;
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Syscalls/statvfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Syscalls/unlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

}
13 changes: 7 additions & 6 deletions Kernel/Syscalls/unveil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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?
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Syscalls/utime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}

0 comments on commit 1123af3

Please sign in to comment.