mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 02:18:11 +00:00
Kernel+LibC: Unify sys$open() and sys$openat()
The syscall is now called sys$open(), but it behaves like the old sys$openat(). In userspace, open_with_path_length() is made a wrapper over openat_with_path_length().
This commit is contained in:
parent
d6184afcae
commit
e0013a6b4c
4 changed files with 4 additions and 66 deletions
|
@ -1862,50 +1862,6 @@ int Process::sys$open(const Syscall::SC_open_params* user_params)
|
||||||
if (!validate_read_and_copy_typed(¶ms, user_params))
|
if (!validate_read_and_copy_typed(¶ms, user_params))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
|
|
||||||
auto options = params.options;
|
|
||||||
auto mode = params.mode;
|
|
||||||
|
|
||||||
if (options & O_NOFOLLOW_NOERROR)
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
if ((options & O_RDWR) || (options & O_WRONLY))
|
|
||||||
REQUIRE_PROMISE(wpath);
|
|
||||||
else
|
|
||||||
REQUIRE_PROMISE(rpath);
|
|
||||||
|
|
||||||
if (options & O_CREAT)
|
|
||||||
REQUIRE_PROMISE(cpath);
|
|
||||||
|
|
||||||
auto path = get_syscall_path_argument(params.path);
|
|
||||||
if (path.is_error())
|
|
||||||
return path.error();
|
|
||||||
|
|
||||||
// Ignore everything except permission bits.
|
|
||||||
mode &= 04777;
|
|
||||||
|
|
||||||
int fd = alloc_fd();
|
|
||||||
#ifdef DEBUG_IO
|
|
||||||
dbgprintf("%s(%u) sys$open(\"%s\") -> %d\n", name().characters(), pid(), path.value().characters(), fd);
|
|
||||||
#endif
|
|
||||||
if (fd < 0)
|
|
||||||
return fd;
|
|
||||||
auto result = VFS::the().open(path.value(), options, mode & ~umask(), current_directory());
|
|
||||||
if (result.is_error())
|
|
||||||
return result.error();
|
|
||||||
auto description = result.value();
|
|
||||||
description->set_rw_mode(options);
|
|
||||||
description->set_file_flags(options);
|
|
||||||
u32 fd_flags = (options & O_CLOEXEC) ? FD_CLOEXEC : 0;
|
|
||||||
m_fds[fd].set(move(description), fd_flags);
|
|
||||||
return fd;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Process::sys$openat(const Syscall::SC_openat_params* user_params)
|
|
||||||
{
|
|
||||||
Syscall::SC_openat_params params;
|
|
||||||
if (!validate_read_and_copy_typed(¶ms, user_params))
|
|
||||||
return -EFAULT;
|
|
||||||
|
|
||||||
int dirfd = params.dirfd;
|
int dirfd = params.dirfd;
|
||||||
int options = params.options;
|
int options = params.options;
|
||||||
u16 mode = params.mode;
|
u16 mode = params.mode;
|
||||||
|
@ -1928,7 +1884,7 @@ int Process::sys$openat(const Syscall::SC_openat_params* user_params)
|
||||||
if (path.is_error())
|
if (path.is_error())
|
||||||
return path.error();
|
return path.error();
|
||||||
#ifdef DEBUG_IO
|
#ifdef DEBUG_IO
|
||||||
dbgprintf("%s(%u) sys$openat(%d, \"%s\")\n", dirfd, name().characters(), pid(), path.value().characters());
|
dbgprintf("%s(%u) sys$open(%d, \"%s\")\n", dirfd, name().characters(), pid(), path.value().characters());
|
||||||
#endif
|
#endif
|
||||||
int fd = alloc_fd();
|
int fd = alloc_fd();
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
|
|
|
@ -145,7 +145,6 @@ public:
|
||||||
pid_t sys$getppid();
|
pid_t sys$getppid();
|
||||||
mode_t sys$umask(mode_t);
|
mode_t sys$umask(mode_t);
|
||||||
int sys$open(const Syscall::SC_open_params*);
|
int sys$open(const Syscall::SC_open_params*);
|
||||||
int sys$openat(const Syscall::SC_openat_params*);
|
|
||||||
int sys$close(int fd);
|
int sys$close(int fd);
|
||||||
ssize_t sys$read(int fd, u8*, ssize_t);
|
ssize_t sys$read(int fd, u8*, ssize_t);
|
||||||
ssize_t sys$write(int fd, const u8*, ssize_t);
|
ssize_t sys$write(int fd, const u8*, ssize_t);
|
||||||
|
|
|
@ -132,7 +132,6 @@ typedef u32 socklen_t;
|
||||||
__ENUMERATE_SYSCALL(setkeymap) \
|
__ENUMERATE_SYSCALL(setkeymap) \
|
||||||
__ENUMERATE_SYSCALL(clock_gettime) \
|
__ENUMERATE_SYSCALL(clock_gettime) \
|
||||||
__ENUMERATE_SYSCALL(clock_nanosleep) \
|
__ENUMERATE_SYSCALL(clock_nanosleep) \
|
||||||
__ENUMERATE_SYSCALL(openat) \
|
|
||||||
__ENUMERATE_SYSCALL(join_thread) \
|
__ENUMERATE_SYSCALL(join_thread) \
|
||||||
__ENUMERATE_SYSCALL(module_load) \
|
__ENUMERATE_SYSCALL(module_load) \
|
||||||
__ENUMERATE_SYSCALL(module_unload) \
|
__ENUMERATE_SYSCALL(module_unload) \
|
||||||
|
@ -218,12 +217,6 @@ struct SC_mmap_params {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SC_open_params {
|
struct SC_open_params {
|
||||||
StringArgument path;
|
|
||||||
int options;
|
|
||||||
u16 mode;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct SC_openat_params {
|
|
||||||
int dirfd;
|
int dirfd;
|
||||||
StringArgument path;
|
StringArgument path;
|
||||||
int options;
|
int options;
|
||||||
|
|
|
@ -33,17 +33,7 @@ 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)
|
int open_with_path_length(const char* path, size_t path_length, int options, mode_t mode)
|
||||||
{
|
{
|
||||||
if (!path) {
|
return openat_with_path_length(AT_FDCWD, path, path_length, options, mode);
|
||||||
errno = EFAULT;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (path_length > INT32_MAX) {
|
|
||||||
errno = EINVAL;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
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)
|
int openat_with_path_length(int dirfd, const char* path, size_t path_length, int options, mode_t mode)
|
||||||
|
@ -56,8 +46,8 @@ int openat_with_path_length(int dirfd, const char* path, size_t path_length, int
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
Syscall::SC_openat_params params { dirfd, { path, path_length }, options, mode };
|
Syscall::SC_open_params params { dirfd, { path, path_length }, options, mode };
|
||||||
int rc = syscall(SC_openat, ¶ms);
|
int rc = syscall(SC_open, ¶ms);
|
||||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue