2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
|
2018-10-16 11:01:38 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2023-02-03 17:36:33 +01:00
|
|
|
#include <AK/Error.h>
|
2018-10-22 13:55:11 +02:00
|
|
|
#include <AK/Types.h>
|
2020-07-31 16:28:37 +02:00
|
|
|
#include <AK/Userspace.h>
|
2022-07-24 16:00:51 +02:00
|
|
|
#include <Kernel/API/POSIX/sched.h>
|
2023-01-25 19:30:00 +00:00
|
|
|
#include <Kernel/Arch/RegisterState.h>
|
2019-09-03 21:14:42 +02:00
|
|
|
|
2020-03-14 20:19:38 +02:00
|
|
|
constexpr int syscall_vector = 0x82;
|
|
|
|
|
|
2019-06-07 17:13:23 +02:00
|
|
|
extern "C" {
|
2020-06-22 11:41:51 -04:00
|
|
|
struct pollfd;
|
2019-06-07 17:13:23 +02:00
|
|
|
struct timeval;
|
2019-11-02 19:34:06 +01:00
|
|
|
struct timespec;
|
2019-11-10 15:32:59 +01:00
|
|
|
struct sockaddr;
|
2020-02-05 19:42:43 +03:00
|
|
|
struct siginfo;
|
2020-08-11 18:57:18 +02:00
|
|
|
struct stat;
|
2021-05-19 11:31:43 +02:00
|
|
|
struct statvfs;
|
2019-11-10 15:32:59 +01:00
|
|
|
typedef u32 socklen_t;
|
2019-06-07 17:13:23 +02:00
|
|
|
}
|
2019-06-07 11:52:27 +02:00
|
|
|
|
2020-02-16 01:27:42 +01:00
|
|
|
namespace Kernel {
|
|
|
|
|
|
2021-07-18 09:18:35 -07:00
|
|
|
enum class NeedsBigProcessLock {
|
|
|
|
|
Yes,
|
|
|
|
|
No
|
|
|
|
|
};
|
|
|
|
|
|
2021-07-18 11:20:12 -07:00
|
|
|
// Declare all syscalls and associated metadata.
|
|
|
|
|
//
|
|
|
|
|
// NOTE: When declaring a new syscall or modifying an existing, please
|
|
|
|
|
// ensure that the proper assert is present at the top of the syscall
|
|
|
|
|
// implementation to both verify and document to any readers if the
|
2021-09-30 19:48:31 -04:00
|
|
|
// syscall acquires the big process lock or not. The asserts are:
|
2021-07-18 11:20:12 -07:00
|
|
|
// - VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
|
|
|
|
// - VERIFY_NO_PROCESS_BIG_LOCK(this)
|
|
|
|
|
//
|
2021-07-18 09:18:35 -07:00
|
|
|
#define ENUMERATE_SYSCALLS(S) \
|
2022-04-09 17:28:31 +02:00
|
|
|
S(accept4, NeedsBigProcessLock::No) \
|
2022-04-04 00:39:43 +02:00
|
|
|
S(adjtime, NeedsBigProcessLock::No) \
|
2021-08-10 12:51:43 +02:00
|
|
|
S(alarm, NeedsBigProcessLock::Yes) \
|
|
|
|
|
S(allocate_tls, NeedsBigProcessLock::Yes) \
|
2022-03-07 16:44:12 +01:00
|
|
|
S(anon_create, NeedsBigProcessLock::No) \
|
2022-12-15 20:38:19 +02:00
|
|
|
S(annotate_mapping, NeedsBigProcessLock::No) \
|
2021-08-10 12:51:43 +02:00
|
|
|
S(beep, NeedsBigProcessLock::No) \
|
2022-04-09 22:41:31 +03:00
|
|
|
S(bind, NeedsBigProcessLock::No) \
|
2022-03-07 18:00:26 +01:00
|
|
|
S(chdir, NeedsBigProcessLock::No) \
|
2022-03-08 16:36:42 +01:00
|
|
|
S(chmod, NeedsBigProcessLock::No) \
|
2022-04-09 22:45:23 +03:00
|
|
|
S(chown, NeedsBigProcessLock::No) \
|
2021-08-10 12:51:43 +02:00
|
|
|
S(clock_gettime, NeedsBigProcessLock::No) \
|
|
|
|
|
S(clock_nanosleep, NeedsBigProcessLock::No) \
|
2022-07-25 11:09:30 +00:00
|
|
|
S(clock_getres, NeedsBigProcessLock::No) \
|
2022-04-04 00:12:57 +02:00
|
|
|
S(clock_settime, NeedsBigProcessLock::No) \
|
2022-04-09 22:49:20 +03:00
|
|
|
S(close, NeedsBigProcessLock::No) \
|
2022-04-09 22:51:14 +03:00
|
|
|
S(connect, NeedsBigProcessLock::No) \
|
2021-08-10 12:51:43 +02:00
|
|
|
S(create_inode_watcher, NeedsBigProcessLock::Yes) \
|
|
|
|
|
S(create_thread, NeedsBigProcessLock::Yes) \
|
|
|
|
|
S(dbgputstr, NeedsBigProcessLock::No) \
|
|
|
|
|
S(detach_thread, NeedsBigProcessLock::Yes) \
|
|
|
|
|
S(disown, NeedsBigProcessLock::Yes) \
|
|
|
|
|
S(dump_backtrace, NeedsBigProcessLock::No) \
|
2022-03-08 16:31:45 +01:00
|
|
|
S(dup2, NeedsBigProcessLock::No) \
|
2022-03-08 16:37:20 +01:00
|
|
|
S(emuctl, NeedsBigProcessLock::No) \
|
2021-08-10 12:51:43 +02:00
|
|
|
S(execve, NeedsBigProcessLock::Yes) \
|
2021-07-18 09:18:35 -07:00
|
|
|
S(exit, NeedsBigProcessLock::Yes) \
|
2021-08-10 12:51:43 +02:00
|
|
|
S(exit_thread, NeedsBigProcessLock::Yes) \
|
2022-10-01 12:24:56 +00:00
|
|
|
S(faccessat, NeedsBigProcessLock::Yes) \
|
2022-03-07 21:26:15 +01:00
|
|
|
S(fchdir, NeedsBigProcessLock::No) \
|
2022-03-08 16:32:29 +01:00
|
|
|
S(fchmod, NeedsBigProcessLock::No) \
|
2022-04-09 22:44:01 +03:00
|
|
|
S(fchown, NeedsBigProcessLock::No) \
|
2021-08-10 12:51:43 +02:00
|
|
|
S(fcntl, NeedsBigProcessLock::Yes) \
|
|
|
|
|
S(fork, NeedsBigProcessLock::Yes) \
|
2022-03-07 21:32:25 +01:00
|
|
|
S(fstat, NeedsBigProcessLock::No) \
|
2022-03-08 15:37:32 +01:00
|
|
|
S(fstatvfs, NeedsBigProcessLock::No) \
|
2022-03-07 21:38:10 +01:00
|
|
|
S(fsync, NeedsBigProcessLock::No) \
|
2022-03-08 16:30:56 +01:00
|
|
|
S(ftruncate, NeedsBigProcessLock::No) \
|
2021-08-10 12:51:43 +02:00
|
|
|
S(futex, NeedsBigProcessLock::Yes) \
|
|
|
|
|
S(get_dir_entries, NeedsBigProcessLock::Yes) \
|
|
|
|
|
S(get_process_name, NeedsBigProcessLock::Yes) \
|
2023-01-10 17:25:01 +01:00
|
|
|
S(get_root_session_id, NeedsBigProcessLock::No) \
|
2021-08-10 12:51:43 +02:00
|
|
|
S(get_stack_bounds, NeedsBigProcessLock::No) \
|
|
|
|
|
S(get_thread_name, NeedsBigProcessLock::Yes) \
|
2022-03-07 17:57:55 +01:00
|
|
|
S(getcwd, NeedsBigProcessLock::No) \
|
2022-08-20 18:36:47 +02:00
|
|
|
S(getegid, NeedsBigProcessLock::No) \
|
|
|
|
|
S(geteuid, NeedsBigProcessLock::No) \
|
|
|
|
|
S(getgid, NeedsBigProcessLock::No) \
|
|
|
|
|
S(getgroups, NeedsBigProcessLock::No) \
|
2021-08-10 12:51:43 +02:00
|
|
|
S(gethostname, NeedsBigProcessLock::No) \
|
|
|
|
|
S(getkeymap, NeedsBigProcessLock::No) \
|
|
|
|
|
S(getpeername, NeedsBigProcessLock::Yes) \
|
|
|
|
|
S(getpgid, NeedsBigProcessLock::Yes) \
|
|
|
|
|
S(getpgrp, NeedsBigProcessLock::Yes) \
|
2021-07-18 11:33:13 -07:00
|
|
|
S(getpid, NeedsBigProcessLock::No) \
|
2022-08-21 13:29:36 +02:00
|
|
|
S(getppid, NeedsBigProcessLock::No) \
|
2021-08-10 12:51:43 +02:00
|
|
|
S(getrandom, NeedsBigProcessLock::No) \
|
2022-08-20 18:36:47 +02:00
|
|
|
S(getresgid, NeedsBigProcessLock::No) \
|
|
|
|
|
S(getresuid, NeedsBigProcessLock::No) \
|
2022-01-31 22:09:30 +01:00
|
|
|
S(getrusage, NeedsBigProcessLock::Yes) \
|
2021-07-18 09:18:35 -07:00
|
|
|
S(getsid, NeedsBigProcessLock::Yes) \
|
2021-08-10 12:51:43 +02:00
|
|
|
S(getsockname, NeedsBigProcessLock::Yes) \
|
2022-04-09 23:01:05 +03:00
|
|
|
S(getsockopt, NeedsBigProcessLock::No) \
|
2021-07-18 11:33:35 -07:00
|
|
|
S(gettid, NeedsBigProcessLock::No) \
|
2022-08-20 18:36:47 +02:00
|
|
|
S(getuid, NeedsBigProcessLock::No) \
|
2021-07-18 09:18:35 -07:00
|
|
|
S(inode_watcher_add_watch, NeedsBigProcessLock::Yes) \
|
|
|
|
|
S(inode_watcher_remove_watch, NeedsBigProcessLock::Yes) \
|
2021-08-10 12:51:43 +02:00
|
|
|
S(ioctl, NeedsBigProcessLock::Yes) \
|
2021-07-18 09:18:35 -07:00
|
|
|
S(join_thread, NeedsBigProcessLock::Yes) \
|
2022-11-02 22:26:02 +02:00
|
|
|
S(jail_create, NeedsBigProcessLock::No) \
|
|
|
|
|
S(jail_attach, NeedsBigProcessLock::No) \
|
2021-08-10 12:51:43 +02:00
|
|
|
S(kill, NeedsBigProcessLock::Yes) \
|
|
|
|
|
S(kill_thread, NeedsBigProcessLock::Yes) \
|
|
|
|
|
S(killpg, NeedsBigProcessLock::Yes) \
|
2022-04-09 23:05:32 +03:00
|
|
|
S(link, NeedsBigProcessLock::No) \
|
2022-04-03 22:22:22 +02:00
|
|
|
S(listen, NeedsBigProcessLock::No) \
|
2022-03-08 16:39:58 +01:00
|
|
|
S(lseek, NeedsBigProcessLock::No) \
|
2021-08-10 12:51:43 +02:00
|
|
|
S(madvise, NeedsBigProcessLock::Yes) \
|
2021-08-10 13:44:01 +02:00
|
|
|
S(map_time_page, NeedsBigProcessLock::Yes) \
|
2022-04-09 23:09:59 +03:00
|
|
|
S(mkdir, NeedsBigProcessLock::No) \
|
2022-08-22 13:16:00 +02:00
|
|
|
S(mknod, NeedsBigProcessLock::No) \
|
2021-08-10 12:51:43 +02:00
|
|
|
S(mmap, NeedsBigProcessLock::Yes) \
|
|
|
|
|
S(mount, NeedsBigProcessLock::Yes) \
|
|
|
|
|
S(mprotect, NeedsBigProcessLock::Yes) \
|
|
|
|
|
S(mremap, NeedsBigProcessLock::Yes) \
|
2021-11-17 19:33:00 +01:00
|
|
|
S(msync, NeedsBigProcessLock::Yes) \
|
2021-08-10 12:51:43 +02:00
|
|
|
S(munmap, NeedsBigProcessLock::Yes) \
|
|
|
|
|
S(open, NeedsBigProcessLock::Yes) \
|
|
|
|
|
S(perf_event, NeedsBigProcessLock::Yes) \
|
2021-08-11 20:28:29 +02:00
|
|
|
S(perf_register_string, NeedsBigProcessLock::Yes) \
|
2022-08-16 20:20:11 +02:00
|
|
|
S(pipe, NeedsBigProcessLock::No) \
|
2023-02-03 17:49:06 +00:00
|
|
|
S(pledge, NeedsBigProcessLock::No) \
|
2021-08-10 12:51:43 +02:00
|
|
|
S(poll, NeedsBigProcessLock::Yes) \
|
2022-06-18 18:37:54 +02:00
|
|
|
S(posix_fallocate, NeedsBigProcessLock::No) \
|
2021-08-10 12:51:43 +02:00
|
|
|
S(prctl, NeedsBigProcessLock::Yes) \
|
2021-07-18 09:18:35 -07:00
|
|
|
S(profiling_disable, NeedsBigProcessLock::Yes) \
|
2021-08-10 12:51:43 +02:00
|
|
|
S(profiling_enable, NeedsBigProcessLock::Yes) \
|
2021-07-18 09:18:35 -07:00
|
|
|
S(profiling_free_buffer, NeedsBigProcessLock::Yes) \
|
|
|
|
|
S(ptrace, NeedsBigProcessLock::Yes) \
|
2021-08-10 12:51:43 +02:00
|
|
|
S(purge, NeedsBigProcessLock::Yes) \
|
|
|
|
|
S(read, NeedsBigProcessLock::Yes) \
|
2021-10-12 21:13:28 +08:00
|
|
|
S(pread, NeedsBigProcessLock::Yes) \
|
2022-03-07 21:36:41 +01:00
|
|
|
S(readlink, NeedsBigProcessLock::No) \
|
2021-08-10 12:51:43 +02:00
|
|
|
S(readv, NeedsBigProcessLock::Yes) \
|
2022-03-07 17:44:27 +01:00
|
|
|
S(realpath, NeedsBigProcessLock::No) \
|
2022-04-03 22:06:03 +02:00
|
|
|
S(recvfd, NeedsBigProcessLock::No) \
|
2021-08-10 12:51:43 +02:00
|
|
|
S(recvmsg, NeedsBigProcessLock::Yes) \
|
2022-04-09 23:08:46 +03:00
|
|
|
S(rename, NeedsBigProcessLock::No) \
|
2022-04-09 23:08:20 +03:00
|
|
|
S(rmdir, NeedsBigProcessLock::No) \
|
2022-07-24 16:00:51 +02:00
|
|
|
S(scheduler_get_parameters, NeedsBigProcessLock::No) \
|
|
|
|
|
S(scheduler_set_parameters, NeedsBigProcessLock::No) \
|
2022-04-03 22:06:03 +02:00
|
|
|
S(sendfd, NeedsBigProcessLock::No) \
|
2021-08-10 12:51:43 +02:00
|
|
|
S(sendmsg, NeedsBigProcessLock::Yes) \
|
2022-04-09 18:30:20 +01:00
|
|
|
S(set_coredump_metadata, NeedsBigProcessLock::No) \
|
2021-08-10 12:51:43 +02:00
|
|
|
S(set_mmap_name, NeedsBigProcessLock::Yes) \
|
|
|
|
|
S(set_process_name, NeedsBigProcessLock::Yes) \
|
|
|
|
|
S(set_thread_name, NeedsBigProcessLock::Yes) \
|
2022-08-20 18:36:47 +02:00
|
|
|
S(setegid, NeedsBigProcessLock::No) \
|
|
|
|
|
S(seteuid, NeedsBigProcessLock::No) \
|
|
|
|
|
S(setgid, NeedsBigProcessLock::No) \
|
|
|
|
|
S(setgroups, NeedsBigProcessLock::No) \
|
2021-08-10 12:51:43 +02:00
|
|
|
S(sethostname, NeedsBigProcessLock::No) \
|
2022-03-07 16:34:14 +01:00
|
|
|
S(setkeymap, NeedsBigProcessLock::No) \
|
2021-08-10 12:51:43 +02:00
|
|
|
S(setpgid, NeedsBigProcessLock::Yes) \
|
2022-10-01 12:47:38 +00:00
|
|
|
S(setregid, NeedsBigProcessLock::No) \
|
2022-08-20 18:36:47 +02:00
|
|
|
S(setresgid, NeedsBigProcessLock::No) \
|
|
|
|
|
S(setresuid, NeedsBigProcessLock::No) \
|
|
|
|
|
S(setreuid, NeedsBigProcessLock::No) \
|
2021-08-10 12:51:43 +02:00
|
|
|
S(setsid, NeedsBigProcessLock::Yes) \
|
2022-04-09 23:01:59 +03:00
|
|
|
S(setsockopt, NeedsBigProcessLock::No) \
|
2022-08-20 18:36:47 +02:00
|
|
|
S(setuid, NeedsBigProcessLock::No) \
|
2022-04-09 22:51:49 +03:00
|
|
|
S(shutdown, NeedsBigProcessLock::No) \
|
2021-08-10 12:51:43 +02:00
|
|
|
S(sigaction, NeedsBigProcessLock::Yes) \
|
2021-10-28 23:33:41 +03:00
|
|
|
S(sigaltstack, NeedsBigProcessLock::Yes) \
|
2021-08-10 12:51:43 +02:00
|
|
|
S(sigpending, NeedsBigProcessLock::Yes) \
|
|
|
|
|
S(sigprocmask, NeedsBigProcessLock::Yes) \
|
|
|
|
|
S(sigreturn, NeedsBigProcessLock::Yes) \
|
2022-05-13 13:15:45 +02:00
|
|
|
S(sigsuspend, NeedsBigProcessLock::Yes) \
|
2021-12-12 01:01:42 +02:00
|
|
|
S(sigtimedwait, NeedsBigProcessLock::Yes) \
|
2022-08-21 15:59:31 +01:00
|
|
|
S(socket, NeedsBigProcessLock::No) \
|
2022-08-16 20:43:23 +02:00
|
|
|
S(socketpair, NeedsBigProcessLock::No) \
|
2022-03-07 21:33:44 +01:00
|
|
|
S(stat, NeedsBigProcessLock::No) \
|
2022-04-09 23:07:20 +03:00
|
|
|
S(statvfs, NeedsBigProcessLock::No) \
|
2022-04-09 23:06:04 +03:00
|
|
|
S(symlink, NeedsBigProcessLock::No) \
|
2021-08-10 12:51:43 +02:00
|
|
|
S(sync, NeedsBigProcessLock::No) \
|
|
|
|
|
S(sysconf, NeedsBigProcessLock::No) \
|
|
|
|
|
S(times, NeedsBigProcessLock::Yes) \
|
|
|
|
|
S(umask, NeedsBigProcessLock::Yes) \
|
|
|
|
|
S(umount, NeedsBigProcessLock::Yes) \
|
|
|
|
|
S(uname, NeedsBigProcessLock::No) \
|
2022-04-09 23:03:24 +03:00
|
|
|
S(unlink, NeedsBigProcessLock::No) \
|
2022-08-16 22:52:58 -04:00
|
|
|
S(unveil, NeedsBigProcessLock::No) \
|
2022-08-22 13:37:07 +02:00
|
|
|
S(utime, NeedsBigProcessLock::No) \
|
|
|
|
|
S(utimensat, NeedsBigProcessLock::No) \
|
2021-08-10 12:51:43 +02:00
|
|
|
S(waitid, NeedsBigProcessLock::Yes) \
|
|
|
|
|
S(write, NeedsBigProcessLock::Yes) \
|
2022-10-01 13:21:20 +00:00
|
|
|
S(pwritev, NeedsBigProcessLock::Yes) \
|
2021-08-10 12:51:43 +02:00
|
|
|
S(yield, NeedsBigProcessLock::No)
|
2018-11-06 13:23:22 +01:00
|
|
|
|
2018-10-16 11:01:38 +02:00
|
|
|
namespace Syscall {
|
|
|
|
|
|
2023-01-25 19:30:00 +00:00
|
|
|
ErrorOr<FlatPtr> handle(RegisterState&, FlatPtr function, FlatPtr arg1, FlatPtr arg2, FlatPtr arg3, FlatPtr arg4);
|
|
|
|
|
|
2020-03-22 13:12:45 +13:00
|
|
|
enum Function {
|
2018-11-06 13:23:22 +01:00
|
|
|
#undef __ENUMERATE_SYSCALL
|
2021-07-18 09:18:35 -07:00
|
|
|
#define __ENUMERATE_SYSCALL(sys_call, needs_lock) SC_##sys_call,
|
2020-08-04 13:00:50 +02:00
|
|
|
ENUMERATE_SYSCALLS(__ENUMERATE_SYSCALL)
|
2018-11-06 13:23:22 +01:00
|
|
|
#undef __ENUMERATE_SYSCALL
|
2020-03-22 13:12:45 +13:00
|
|
|
__Count
|
|
|
|
|
};
|
2018-10-16 11:01:38 +02:00
|
|
|
|
2022-10-09 15:23:23 -06:00
|
|
|
#ifdef AK_OS_SERENITY
|
2020-03-22 13:12:45 +13:00
|
|
|
struct StringArgument {
|
2022-04-01 20:58:27 +03:00
|
|
|
char const* characters;
|
2020-03-22 13:12:45 +13:00
|
|
|
size_t length { 0 };
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<typename DataType, typename SizeType>
|
|
|
|
|
struct MutableBufferArgument {
|
|
|
|
|
DataType* data { nullptr };
|
|
|
|
|
SizeType size { 0 };
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct StringListArgument {
|
2020-09-11 21:11:07 -06:00
|
|
|
StringArgument* strings {};
|
2020-03-22 13:12:45 +13:00
|
|
|
size_t length { 0 };
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct SC_mmap_params {
|
2021-12-22 13:20:32 +01:00
|
|
|
void* addr;
|
2020-10-12 14:49:31 +02:00
|
|
|
size_t size;
|
|
|
|
|
size_t alignment;
|
2020-03-22 13:12:45 +13:00
|
|
|
int32_t prot;
|
|
|
|
|
int32_t flags;
|
|
|
|
|
int32_t fd;
|
2021-03-13 22:02:54 +01:00
|
|
|
int64_t offset;
|
2020-03-22 13:12:45 +13:00
|
|
|
StringArgument name;
|
|
|
|
|
};
|
|
|
|
|
|
2020-12-29 02:11:47 +01:00
|
|
|
struct SC_mremap_params {
|
2021-12-22 13:20:32 +01:00
|
|
|
void* old_address;
|
2020-12-29 02:11:47 +01:00
|
|
|
size_t old_size;
|
|
|
|
|
size_t new_size;
|
|
|
|
|
int32_t flags;
|
|
|
|
|
};
|
|
|
|
|
|
2020-03-22 13:12:45 +13:00
|
|
|
struct SC_open_params {
|
|
|
|
|
int dirfd;
|
|
|
|
|
StringArgument path;
|
|
|
|
|
int options;
|
|
|
|
|
u16 mode;
|
|
|
|
|
};
|
|
|
|
|
|
2020-06-22 11:41:51 -04:00
|
|
|
struct SC_poll_params {
|
|
|
|
|
struct pollfd* fds;
|
|
|
|
|
unsigned nfds;
|
2020-09-11 21:11:07 -06:00
|
|
|
const struct timespec* timeout;
|
2022-04-01 20:58:27 +03:00
|
|
|
u32 const* sigmask;
|
2020-06-22 11:41:51 -04:00
|
|
|
};
|
|
|
|
|
|
2020-03-22 13:12:45 +13:00
|
|
|
struct SC_clock_nanosleep_params {
|
|
|
|
|
int clock_id;
|
|
|
|
|
int flags;
|
2020-09-11 21:11:07 -06:00
|
|
|
const struct timespec* requested_sleep;
|
|
|
|
|
struct timespec* remaining_sleep;
|
2020-03-22 13:12:45 +13:00
|
|
|
};
|
|
|
|
|
|
2022-07-25 11:09:30 +00:00
|
|
|
struct SC_clock_getres_params {
|
|
|
|
|
int clock_id;
|
|
|
|
|
struct timespec* result;
|
|
|
|
|
};
|
|
|
|
|
|
2021-05-16 19:56:11 +02:00
|
|
|
struct SC_accept4_params {
|
|
|
|
|
sockaddr* addr;
|
|
|
|
|
socklen_t* addrlen;
|
2021-09-15 23:41:01 -07:00
|
|
|
int sockfd;
|
2021-05-16 19:56:11 +02:00
|
|
|
int flags;
|
|
|
|
|
};
|
|
|
|
|
|
2020-03-22 13:12:45 +13:00
|
|
|
struct SC_getsockopt_params {
|
|
|
|
|
int sockfd;
|
|
|
|
|
int level;
|
|
|
|
|
int option;
|
2020-09-11 21:11:07 -06:00
|
|
|
void* value;
|
|
|
|
|
socklen_t* value_size;
|
2020-03-22 13:12:45 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct SC_setsockopt_params {
|
2022-04-01 20:58:27 +03:00
|
|
|
void const* value;
|
2020-03-22 13:12:45 +13:00
|
|
|
int sockfd;
|
|
|
|
|
int level;
|
|
|
|
|
int option;
|
|
|
|
|
socklen_t value_size;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct SC_getsockname_params {
|
|
|
|
|
int sockfd;
|
2020-09-11 21:11:07 -06:00
|
|
|
sockaddr* addr;
|
|
|
|
|
socklen_t* addrlen;
|
2020-03-22 13:12:45 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct SC_getpeername_params {
|
|
|
|
|
int sockfd;
|
2020-09-11 21:11:07 -06:00
|
|
|
sockaddr* addr;
|
|
|
|
|
socklen_t* addrlen;
|
2020-03-22 13:12:45 +13:00
|
|
|
};
|
|
|
|
|
|
2021-04-28 12:39:12 +02:00
|
|
|
struct SC_socketpair_params {
|
|
|
|
|
int domain;
|
|
|
|
|
int type;
|
|
|
|
|
int protocol;
|
|
|
|
|
int* sv;
|
|
|
|
|
};
|
|
|
|
|
|
2020-03-22 13:12:45 +13:00
|
|
|
struct SC_futex_params {
|
2020-12-21 23:21:58 -07:00
|
|
|
u32* userspace_address;
|
2020-03-22 13:12:45 +13:00
|
|
|
int futex_op;
|
2020-12-21 23:21:58 -07:00
|
|
|
u32 val;
|
|
|
|
|
union {
|
2022-04-01 20:58:27 +03:00
|
|
|
timespec const* timeout;
|
2021-02-25 16:18:36 +01:00
|
|
|
uintptr_t val2;
|
2020-12-21 23:21:58 -07:00
|
|
|
};
|
|
|
|
|
u32* userspace_address2;
|
|
|
|
|
u32 val3;
|
2020-03-22 13:12:45 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct SC_setkeymap_params {
|
2022-04-01 20:58:27 +03:00
|
|
|
u32 const* map;
|
|
|
|
|
u32 const* shift_map;
|
|
|
|
|
u32 const* alt_map;
|
|
|
|
|
u32 const* altgr_map;
|
|
|
|
|
u32 const* shift_altgr_map;
|
2020-08-06 02:03:32 +03:00
|
|
|
StringArgument map_name;
|
2020-03-22 13:12:45 +13:00
|
|
|
};
|
|
|
|
|
|
2022-11-02 22:26:02 +02:00
|
|
|
struct SC_jail_create_params {
|
|
|
|
|
u64 index;
|
|
|
|
|
StringArgument name;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct SC_jail_attach_params {
|
|
|
|
|
u64 index;
|
|
|
|
|
};
|
|
|
|
|
|
2021-01-30 21:35:54 +01:00
|
|
|
struct SC_getkeymap_params {
|
|
|
|
|
u32* map;
|
|
|
|
|
u32* shift_map;
|
|
|
|
|
u32* alt_map;
|
|
|
|
|
u32* altgr_map;
|
|
|
|
|
u32* shift_altgr_map;
|
|
|
|
|
MutableBufferArgument<char, size_t> map_name;
|
|
|
|
|
};
|
|
|
|
|
|
2020-03-22 13:12:45 +13:00
|
|
|
struct SC_create_thread_params {
|
2021-07-01 11:20:27 +02:00
|
|
|
unsigned int detach_state = 0; // JOINABLE or DETACHED
|
|
|
|
|
int schedule_priority = 30; // THREAD_PRIORITY_NORMAL
|
2020-10-02 22:14:37 +01:00
|
|
|
// FIXME: Implement guard pages in create_thread (unreadable pages at "overflow" end of stack)
|
2020-03-22 13:12:45 +13:00
|
|
|
// "If an implementation rounds up the value of guardsize to a multiple of {PAGESIZE},
|
|
|
|
|
// a call to pthread_attr_getguardsize() specifying attr shall store in the guardsize
|
|
|
|
|
// parameter the guard size specified by the previous pthread_attr_setguardsize() function call"
|
|
|
|
|
// ... ok, if you say so posix. Guess we get to lie to people about guard page size
|
2021-07-01 11:15:00 +02:00
|
|
|
unsigned int guard_page_size = 0; // Rounded up to PAGE_SIZE
|
|
|
|
|
unsigned int reported_guard_page_size = 0; // The lie we tell callers
|
2022-10-01 19:29:59 +00:00
|
|
|
unsigned int stack_size = 1 * MiB; // Equal to Thread::default_userspace_stack_size
|
2021-07-01 11:15:00 +02:00
|
|
|
void* stack_location; // nullptr means any, o.w. process virtual address
|
|
|
|
|
# if ARCH(X86_64)
|
|
|
|
|
FlatPtr rdi;
|
|
|
|
|
FlatPtr rsi;
|
|
|
|
|
FlatPtr rcx;
|
|
|
|
|
FlatPtr rdx;
|
|
|
|
|
# endif
|
2020-03-22 13:12:45 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct SC_realpath_params {
|
|
|
|
|
StringArgument path;
|
|
|
|
|
MutableBufferArgument<char, size_t> buffer;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct SC_set_mmap_name_params {
|
|
|
|
|
void* addr;
|
|
|
|
|
size_t size;
|
|
|
|
|
StringArgument name;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct SC_execve_params {
|
|
|
|
|
StringArgument path;
|
|
|
|
|
StringListArgument arguments;
|
|
|
|
|
StringListArgument environment;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct SC_readlink_params {
|
|
|
|
|
StringArgument path;
|
|
|
|
|
MutableBufferArgument<char, size_t> buffer;
|
2022-10-01 11:20:08 +00:00
|
|
|
int dirfd;
|
2020-03-22 13:12:45 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct SC_link_params {
|
|
|
|
|
StringArgument old_path;
|
|
|
|
|
StringArgument new_path;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct SC_chown_params {
|
|
|
|
|
StringArgument path;
|
|
|
|
|
u32 uid;
|
|
|
|
|
u32 gid;
|
2021-12-31 19:20:17 +01:00
|
|
|
int dirfd;
|
|
|
|
|
int follow_symlinks;
|
2020-03-22 13:12:45 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct SC_mknod_params {
|
|
|
|
|
StringArgument path;
|
|
|
|
|
u16 mode;
|
|
|
|
|
u32 dev;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct SC_symlink_params {
|
|
|
|
|
StringArgument target;
|
|
|
|
|
StringArgument linkpath;
|
2022-10-01 11:15:02 +00:00
|
|
|
int dirfd;
|
2020-03-22 13:12:45 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct SC_rename_params {
|
2022-10-01 11:42:25 +00:00
|
|
|
int olddirfd;
|
2020-03-22 13:12:45 +13:00
|
|
|
StringArgument old_path;
|
2022-10-01 11:42:25 +00:00
|
|
|
int newdirfd;
|
2020-03-22 13:12:45 +13:00
|
|
|
StringArgument new_path;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct SC_mount_params {
|
|
|
|
|
StringArgument target;
|
|
|
|
|
StringArgument fs_type;
|
2021-09-15 23:44:07 -07:00
|
|
|
int source_fd;
|
2020-03-22 13:12:45 +13:00
|
|
|
int flags;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct SC_pledge_params {
|
|
|
|
|
StringArgument promises;
|
|
|
|
|
StringArgument execpromises;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct SC_unveil_params {
|
2022-11-04 19:20:11 +02:00
|
|
|
int flags;
|
2020-03-22 13:12:45 +13:00
|
|
|
StringArgument path;
|
|
|
|
|
StringArgument permissions;
|
|
|
|
|
};
|
|
|
|
|
|
2022-05-02 15:26:10 -05:00
|
|
|
struct SC_utimensat_params {
|
|
|
|
|
int dirfd;
|
|
|
|
|
StringArgument path;
|
|
|
|
|
struct timespec const* times;
|
|
|
|
|
int flag;
|
|
|
|
|
};
|
|
|
|
|
|
2020-03-22 13:12:45 +13:00
|
|
|
struct SC_waitid_params {
|
|
|
|
|
int idtype;
|
|
|
|
|
int id;
|
2020-09-11 21:11:07 -06:00
|
|
|
struct siginfo* infop;
|
2020-03-22 13:12:45 +13:00
|
|
|
int options;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct SC_stat_params {
|
|
|
|
|
StringArgument path;
|
2020-09-11 21:11:07 -06:00
|
|
|
struct stat* statbuf;
|
2021-09-15 23:45:30 -07:00
|
|
|
int dirfd;
|
2021-03-02 19:44:09 +01:00
|
|
|
int follow_symlinks;
|
2020-03-22 13:12:45 +13:00
|
|
|
};
|
|
|
|
|
|
2021-11-25 22:55:12 +01:00
|
|
|
struct SC_ptrace_buf_params {
|
|
|
|
|
MutableBufferArgument<u8, size_t> buf;
|
|
|
|
|
};
|
|
|
|
|
|
2020-03-28 11:47:16 +03:00
|
|
|
struct SC_ptrace_params {
|
|
|
|
|
int request;
|
2020-08-09 01:08:24 +02:00
|
|
|
pid_t tid;
|
2021-11-19 16:13:07 +02:00
|
|
|
void* addr;
|
|
|
|
|
FlatPtr data;
|
2020-03-28 11:47:16 +03:00
|
|
|
};
|
|
|
|
|
|
2020-12-30 15:19:57 +01:00
|
|
|
struct SC_set_coredump_metadata_params {
|
|
|
|
|
StringArgument key;
|
|
|
|
|
StringArgument value;
|
|
|
|
|
};
|
|
|
|
|
|
2021-05-12 19:17:51 +00:00
|
|
|
struct SC_inode_watcher_add_watch_params {
|
|
|
|
|
StringArgument user_path;
|
2021-09-15 23:37:39 -07:00
|
|
|
int fd;
|
2021-05-12 19:17:51 +00:00
|
|
|
u32 event_mask;
|
|
|
|
|
};
|
|
|
|
|
|
2021-05-19 11:31:43 +02:00
|
|
|
struct SC_statvfs_params {
|
|
|
|
|
StringArgument path;
|
|
|
|
|
struct statvfs* buf;
|
|
|
|
|
};
|
|
|
|
|
|
2022-01-11 16:51:34 +01:00
|
|
|
struct SC_chmod_params {
|
|
|
|
|
int dirfd;
|
|
|
|
|
StringArgument path;
|
|
|
|
|
u16 mode;
|
|
|
|
|
int follow_symlinks;
|
|
|
|
|
};
|
|
|
|
|
|
2022-07-24 16:00:51 +02:00
|
|
|
enum class SchedulerParametersMode : bool {
|
|
|
|
|
Process,
|
|
|
|
|
Thread,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct SC_scheduler_parameters_params {
|
|
|
|
|
pid_t pid_or_tid;
|
|
|
|
|
SchedulerParametersMode mode;
|
|
|
|
|
struct sched_param parameters;
|
|
|
|
|
};
|
|
|
|
|
|
2022-10-01 12:24:56 +00:00
|
|
|
struct SC_faccessat_params {
|
|
|
|
|
int dirfd;
|
|
|
|
|
StringArgument pathname;
|
|
|
|
|
int mode;
|
|
|
|
|
int flags;
|
|
|
|
|
};
|
|
|
|
|
|
2020-03-22 13:12:45 +13:00
|
|
|
void initialize();
|
|
|
|
|
int sync();
|
|
|
|
|
|
2022-10-04 03:05:54 +03:00
|
|
|
# if ARCH(X86_64) || ARCH(AARCH64)
|
2020-10-12 14:49:31 +02:00
|
|
|
inline uintptr_t invoke(Function function)
|
2020-03-22 13:12:45 +13:00
|
|
|
{
|
2020-10-12 14:49:31 +02:00
|
|
|
uintptr_t result;
|
2022-10-04 03:05:54 +03:00
|
|
|
# if ARCH(X86_64)
|
2021-07-23 21:52:25 +01:00
|
|
|
asm volatile("syscall"
|
|
|
|
|
: "=a"(result)
|
|
|
|
|
: "a"(function)
|
|
|
|
|
: "rcx", "r11", "memory");
|
2022-10-12 22:04:17 +02:00
|
|
|
# elif ARCH(AARCH64)
|
|
|
|
|
register uintptr_t x0 asm("x0");
|
|
|
|
|
register uintptr_t x8 asm("x8") = function;
|
|
|
|
|
asm volatile("svc #0"
|
|
|
|
|
: "=r"(x0)
|
|
|
|
|
: "r"(x8)
|
|
|
|
|
: "memory");
|
|
|
|
|
result = x0;
|
2021-07-23 21:52:25 +01:00
|
|
|
# endif
|
2020-03-22 13:12:45 +13:00
|
|
|
return result;
|
|
|
|
|
}
|
2018-10-18 13:05:00 +02:00
|
|
|
|
2020-03-22 13:12:45 +13:00
|
|
|
template<typename T1>
|
2020-10-12 14:49:31 +02:00
|
|
|
inline uintptr_t invoke(Function function, T1 arg1)
|
2020-03-22 13:12:45 +13:00
|
|
|
{
|
2020-10-12 14:49:31 +02:00
|
|
|
uintptr_t result;
|
2022-10-04 03:05:54 +03:00
|
|
|
# if ARCH(X86_64)
|
2021-07-23 21:52:25 +01:00
|
|
|
asm volatile("syscall"
|
|
|
|
|
: "=a"(result)
|
|
|
|
|
: "a"(function), "d"((uintptr_t)arg1)
|
|
|
|
|
: "rcx", "r11", "memory");
|
2022-10-04 03:05:54 +03:00
|
|
|
# elif ARCH(AARCH64)
|
2022-10-12 22:04:17 +02:00
|
|
|
register uintptr_t x0 asm("x0");
|
|
|
|
|
register uintptr_t x1 asm("x1") = arg1;
|
|
|
|
|
register uintptr_t x8 asm("x8") = function;
|
|
|
|
|
asm volatile("svc #0"
|
|
|
|
|
: "=r"(x0)
|
|
|
|
|
: "r"(x1), "r"(x8)
|
|
|
|
|
: "memory");
|
|
|
|
|
result = x0;
|
2021-07-23 21:52:25 +01:00
|
|
|
# endif
|
2020-03-22 13:12:45 +13:00
|
|
|
return result;
|
|
|
|
|
}
|
2018-10-18 13:05:00 +02:00
|
|
|
|
2020-03-22 13:12:45 +13:00
|
|
|
template<typename T1, typename T2>
|
2020-10-12 14:49:31 +02:00
|
|
|
inline uintptr_t invoke(Function function, T1 arg1, T2 arg2)
|
2020-03-22 13:12:45 +13:00
|
|
|
{
|
2020-10-12 14:49:31 +02:00
|
|
|
uintptr_t result;
|
2022-10-04 03:05:54 +03:00
|
|
|
# if ARCH(X86_64)
|
2021-07-23 21:52:25 +01:00
|
|
|
asm volatile("syscall"
|
|
|
|
|
: "=a"(result)
|
|
|
|
|
: "a"(function), "d"((uintptr_t)arg1), "D"((uintptr_t)arg2)
|
|
|
|
|
: "rcx", "r11", "memory");
|
2022-10-04 03:05:54 +03:00
|
|
|
# elif ARCH(AARCH64)
|
2022-10-12 22:04:17 +02:00
|
|
|
register uintptr_t x0 asm("x0");
|
|
|
|
|
register uintptr_t x1 asm("x1") = arg1;
|
|
|
|
|
register uintptr_t x2 asm("x2") = arg2;
|
|
|
|
|
register uintptr_t x8 asm("x8") = function;
|
|
|
|
|
asm volatile("svc #0"
|
|
|
|
|
: "=r"(x0)
|
|
|
|
|
: "r"(x1), "r"(x2), "r"(x8)
|
|
|
|
|
: "memory");
|
|
|
|
|
result = x0;
|
2021-07-23 21:52:25 +01:00
|
|
|
# endif
|
2020-03-22 13:12:45 +13:00
|
|
|
return result;
|
|
|
|
|
}
|
2018-10-18 13:05:00 +02:00
|
|
|
|
2020-03-22 13:12:45 +13:00
|
|
|
template<typename T1, typename T2, typename T3>
|
2020-10-12 14:49:31 +02:00
|
|
|
inline uintptr_t invoke(Function function, T1 arg1, T2 arg2, T3 arg3)
|
2020-03-22 13:12:45 +13:00
|
|
|
{
|
2020-10-12 14:49:31 +02:00
|
|
|
uintptr_t result;
|
2022-10-04 03:05:54 +03:00
|
|
|
# if ARCH(X86_64)
|
2021-07-23 21:52:25 +01:00
|
|
|
asm volatile("syscall"
|
|
|
|
|
: "=a"(result)
|
|
|
|
|
: "a"(function), "d"((uintptr_t)arg1), "D"((uintptr_t)arg2), "b"((uintptr_t)arg3)
|
|
|
|
|
: "rcx", "r11", "memory");
|
2022-10-04 03:05:54 +03:00
|
|
|
# elif ARCH(AARCH64)
|
2022-10-12 22:04:17 +02:00
|
|
|
register uintptr_t x0 asm("x0");
|
|
|
|
|
register uintptr_t x1 asm("x1") = arg1;
|
|
|
|
|
register uintptr_t x2 asm("x2") = arg2;
|
|
|
|
|
register uintptr_t x3 asm("x3") = arg3;
|
|
|
|
|
register uintptr_t x8 asm("x8") = function;
|
|
|
|
|
asm volatile("svc #0"
|
|
|
|
|
: "=r"(x0)
|
|
|
|
|
: "r"(x1), "r"(x2), "r"(x3), "r"(x8)
|
|
|
|
|
: "memory");
|
|
|
|
|
result = x0;
|
2021-07-23 21:52:25 +01:00
|
|
|
# endif
|
2020-03-22 13:12:45 +13:00
|
|
|
return result;
|
|
|
|
|
}
|
2021-07-24 02:15:07 +02:00
|
|
|
|
|
|
|
|
template<typename T1, typename T2, typename T3, typename T4>
|
|
|
|
|
inline uintptr_t invoke(Function function, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
|
|
|
|
|
{
|
|
|
|
|
uintptr_t result;
|
2022-10-04 03:05:54 +03:00
|
|
|
# if ARCH(X86_64)
|
2021-07-23 21:52:25 +01:00
|
|
|
asm volatile("syscall"
|
|
|
|
|
: "=a"(result)
|
|
|
|
|
: "a"(function), "d"((uintptr_t)arg1), "D"((uintptr_t)arg2), "b"((uintptr_t)arg3), "S"((uintptr_t)arg4)
|
|
|
|
|
: "memory");
|
2022-10-04 03:05:54 +03:00
|
|
|
# elif ARCH(AARCH64)
|
2022-10-12 22:04:17 +02:00
|
|
|
register uintptr_t x0 asm("x0");
|
|
|
|
|
register uintptr_t x1 asm("x1") = arg1;
|
|
|
|
|
register uintptr_t x2 asm("x2") = arg2;
|
|
|
|
|
register uintptr_t x3 asm("x3") = arg3;
|
|
|
|
|
register uintptr_t x4 asm("x4") = arg4;
|
|
|
|
|
register uintptr_t x8 asm("x8") = function;
|
|
|
|
|
asm volatile("svc #0"
|
|
|
|
|
: "=r"(x0)
|
|
|
|
|
: "r"(x1), "r"(x2), "r"(x3), "r"(x4), "r"(x8)
|
|
|
|
|
: "memory");
|
|
|
|
|
result = x0;
|
2021-07-23 21:52:25 +01:00
|
|
|
# endif
|
2021-07-24 02:15:07 +02:00
|
|
|
return result;
|
|
|
|
|
}
|
2021-12-04 09:15:19 +01:00
|
|
|
# endif
|
2019-01-25 05:19:29 +01:00
|
|
|
#endif
|
2018-10-16 11:01:38 +02:00
|
|
|
|
|
|
|
|
}
|
2018-12-21 03:02:06 +01:00
|
|
|
|
|
|
|
|
#undef __ENUMERATE_SYSCALL
|
2021-07-18 09:18:35 -07:00
|
|
|
#define __ENUMERATE_SYSCALL(sys_call, needs_lock) using Syscall::SC_##sys_call;
|
2020-08-04 13:00:50 +02:00
|
|
|
ENUMERATE_SYSCALLS(__ENUMERATE_SYSCALL)
|
2018-12-21 03:02:06 +01:00
|
|
|
#undef __ENUMERATE_SYSCALL
|
2020-02-16 01:27:42 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using namespace Kernel;
|