1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-10 03:47:34 +00:00

Kernel: Use the Syscall string and buffer types more

While I was updating syscalls to stop passing null-terminated strings,
I added some helpful struct types:

    - StringArgument { const char*; size_t; }
    - ImmutableBuffer<Data, Size> { const Data*; Size; }
    - MutableBuffer<Data, Size> { Data*; Size; }

The Process class has some convenience functions for validating and
optionally extracting the contents from these structs:

    - get_syscall_path_argument(StringArgument)
    - validate_and_copy_string_from_user(StringArgument)
    - validate(ImmutableBuffer)
    - validate(MutableBuffer)

There's still so much code around this and I'm wondering if we should
generate most of it instead. Possible nice little project.
This commit is contained in:
Andreas Kling 2020-01-11 12:47:47 +01:00
parent 1434f30f92
commit 24c736b0e7
8 changed files with 148 additions and 121 deletions

View file

@ -711,7 +711,7 @@ char* realpath(const char* pathname, char* buffer)
size_t size = PATH_MAX;
if (buffer == nullptr)
buffer = (char*)malloc(size);
Syscall::SC_realpath_params params { pathname, strlen(pathname), buffer, size };
Syscall::SC_realpath_params params { { pathname, strlen(pathname) }, { buffer, size } };
int rc = syscall(SC_realpath, &params);
if (rc < 0) {
errno = -rc;