mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 23:07: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:
parent
1434f30f92
commit
24c736b0e7
8 changed files with 148 additions and 121 deletions
|
@ -33,22 +33,30 @@ int creat_with_path_length(const char* path, size_t path_length, mode_t mode)
|
|||
|
||||
int open_with_path_length(const char* path, size_t path_length, int options, mode_t mode)
|
||||
{
|
||||
if (!path) {
|
||||
errno = EFAULT;
|
||||
return -1;
|
||||
}
|
||||
if (path_length > INT32_MAX) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
Syscall::SC_open_params params { path, (int)path_length, options, mode };
|
||||
Syscall::SC_open_params params { { path, path_length }, options, mode };
|
||||
int rc = syscall(SC_open, ¶ms);
|
||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
||||
int openat_with_path_length(int dirfd, const char* path, size_t path_length, int options, mode_t mode)
|
||||
{
|
||||
if (!path) {
|
||||
errno = EFAULT;
|
||||
return -1;
|
||||
}
|
||||
if (path_length > INT32_MAX) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
Syscall::SC_openat_params params { dirfd, path, (int)path_length, options, mode };
|
||||
Syscall::SC_openat_params params { dirfd, { path, path_length }, options, mode };
|
||||
int rc = syscall(SC_openat, ¶ms);
|
||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue