1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 19:08:10 +00:00

Kernel: Use FixedStringBuffer for fixed-length strings in syscalls

Using the kernel stack is preferable, especially when the examined
strings should be limited to a reasonable length.

This is a small improvement, because if we don't actually move these
strings then we don't need to own heap allocations for them during the
syscall handler function scope.

In addition to that, some kernel strings are known to be limited, like
the hostname string, for these strings we also can use FixedStringBuffer
to store and copy to and from these buffers, without using any heap
allocations at all.
This commit is contained in:
Liav A 2023-07-17 19:22:01 +03:00 committed by Andrew Kaster
parent 3fd4997fc2
commit d8b514873f
13 changed files with 100 additions and 46 deletions

View file

@ -101,19 +101,16 @@ ErrorOr<FlatPtr> Process::sys$unveil(Userspace<Syscall::SC_unveil_params const*>
if (!params.path.characters || !params.permissions.characters)
return EINVAL;
if (params.permissions.length > 5)
return EINVAL;
auto path = TRY(get_syscall_path_argument(params.path));
if (path->is_empty() || !path->view().starts_with('/'))
return EINVAL;
auto permissions = TRY(try_copy_kstring_from_user(params.permissions));
auto permissions = TRY(get_syscall_string_fixed_buffer<5>(params.permissions));
// Let's work out permissions first...
unsigned new_permissions = 0;
for (char const permission : permissions->view()) {
for (char const permission : permissions.representable_view()) {
switch (permission) {
case 'r':
new_permissions |= UnveilAccess::Read;