mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:38:11 +00:00
Kernel: Have the open() syscall take an explicit path length parameter.
Instead of computing the path length inside the syscall handler, let the caller do that work. This allows us to implement to new variants of open() and creat(), called open_with_path_length() and creat_with_path_length(). These are suitable for use with e.g StringView.
This commit is contained in:
parent
fc4022d173
commit
c110cf193d
9 changed files with 40 additions and 9 deletions
|
@ -1127,12 +1127,18 @@ int Process::number_of_open_file_descriptors() const
|
|||
return count;
|
||||
}
|
||||
|
||||
int Process::sys$open(const char* path, int options, mode_t mode)
|
||||
int Process::sys$open(const Syscall::SC_open_params* params)
|
||||
{
|
||||
if (!validate_read_typed(params))
|
||||
return -EFAULT;
|
||||
auto* path = params->path;
|
||||
auto path_length = params->path_length;
|
||||
auto options = params->options;
|
||||
auto mode = params->mode;
|
||||
#ifdef DEBUG_IO
|
||||
dbgprintf("%s(%u) sys$open(\"%s\")\n", name().characters(), pid(), path);
|
||||
#endif
|
||||
if (!validate_read_str(path))
|
||||
if (!validate_read(path, path_length))
|
||||
return -EFAULT;
|
||||
int fd = alloc_fd();
|
||||
if (fd < 0)
|
||||
|
|
|
@ -118,7 +118,7 @@ public:
|
|||
pid_t sys$getpid();
|
||||
pid_t sys$getppid();
|
||||
mode_t sys$umask(mode_t);
|
||||
int sys$open(const char* path, int options, mode_t mode = 0);
|
||||
int sys$open(const Syscall::SC_open_params*);
|
||||
int sys$close(int fd);
|
||||
ssize_t sys$read(int fd, u8*, ssize_t);
|
||||
ssize_t sys$write(int fd, const u8*, ssize_t);
|
||||
|
|
|
@ -85,7 +85,7 @@ static u32 handle(RegisterDump& regs, u32 function, u32 arg1, u32 arg2, u32 arg3
|
|||
case Syscall::SC_getcwd:
|
||||
return current->process().sys$getcwd((char*)arg1, (size_t)arg2);
|
||||
case Syscall::SC_open:
|
||||
return current->process().sys$open((const char*)arg1, (int)arg2, (mode_t)arg3);
|
||||
return current->process().sys$open((const SC_open_params*)arg1);
|
||||
case Syscall::SC_write:
|
||||
return current->process().sys$write((int)arg1, (const u8*)arg2, (ssize_t)arg3);
|
||||
case Syscall::SC_close:
|
||||
|
|
|
@ -148,6 +148,13 @@ struct SC_mmap_params {
|
|||
const char* name { nullptr };
|
||||
};
|
||||
|
||||
struct SC_open_params {
|
||||
const char* path;
|
||||
int path_length;
|
||||
int options;
|
||||
u16 mode;
|
||||
};
|
||||
|
||||
struct SC_select_params {
|
||||
int nfds;
|
||||
fd_set* readfds;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue