1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:28:12 +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

@ -202,8 +202,8 @@ public:
void sys$exit_thread(void*);
int sys$join_thread(int tid, void** exit_value);
int sys$detach_thread(int tid);
int sys$set_thread_name(int tid, const char* buffer, int buffer_size);
int sys$get_thread_name(int tid, char* buffer, int buffer_size);
int sys$set_thread_name(int tid, const char* buffer, size_t buffer_size);
int sys$get_thread_name(int tid, char* buffer, size_t buffer_size);
int sys$rename(const Syscall::SC_rename_params*);
int sys$systrace(pid_t);
int sys$mknod(const Syscall::SC_mknod_params*);
@ -262,7 +262,10 @@ public:
bool validate_write_typed(T* value, size_t count = 1) { return validate_write(value, sizeof(T) * count); }
template<typename DataType, typename SizeType>
bool validate(const Syscall::MutableBufferArgument<DataType, SizeType>&);
template<typename DataType, typename SizeType>
bool validate(const Syscall::ImmutableBufferArgument<DataType, SizeType>&);
String validate_and_copy_string_from_user(const char*, size_t) const;
String validate_and_copy_string_from_user(const Syscall::StringArgument&) const;
Custody& current_directory();
@ -334,7 +337,8 @@ private:
KResult do_kill(Process&, int signal);
KResult do_killpg(pid_t pgrp, int signal);
KResultOr<String> get_syscall_path_argument(const char* user_path, size_t path_length);
KResultOr<String> get_syscall_path_argument(const char* user_path, size_t path_length) const;
KResultOr<String> get_syscall_path_argument(const Syscall::StringArgument&) const;
RefPtr<PageDirectory> m_page_directory;