1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 03:57:43 +00:00

Add templated helpers for read/write validation, and one for strings, too.

This commit is contained in:
Andreas Kling 2018-11-16 16:23:39 +01:00
parent 8a286b9244
commit 52d1822c3c
2 changed files with 28 additions and 27 deletions

View file

@ -171,8 +171,6 @@ public:
unsigned sys$alarm(unsigned seconds);
int sys$access(const char* pathname, int mode);
int sys$fcntl(int fd, int cmd, dword extra_arg);
int sys$tcgetattr(int fd, Unix::termios*);
int sys$tcsetattr(int fd, int optional_actions, const Unix::termios*);
int sys$ioctl(int fd, unsigned request, unsigned arg);
static void initialize();
@ -199,6 +197,9 @@ public:
bool validate_read(const void*, size_t) const;
bool validate_write(void*, size_t) const;
bool validate_read_str(const char* str) { return validate_read(str, strlen(str) + 1); }
template<typename T> bool validate_read_typed(T* value, size_t count = 1) { return validate_read(value, sizeof(T) * count); }
template<typename T> bool validate_write_typed(T* value, size_t count = 1) { return validate_write(value, sizeof(T) * count); }
CoreInode* cwd_inode() { return m_cwd ? m_cwd->core_inode() : nullptr; }
CoreInode* executable_inode() { return m_executable ? m_executable->core_inode() : nullptr; }