2018-10-16 09:01:38 +00:00
|
|
|
#pragma once
|
|
|
|
|
2018-10-22 11:55:11 +00:00
|
|
|
#include <AK/Types.h>
|
2019-09-03 19:14:42 +00:00
|
|
|
|
|
|
|
#ifdef __serenity__
|
|
|
|
# include <LibC/fd_set.h>
|
|
|
|
#endif
|
2018-10-22 11:55:11 +00:00
|
|
|
|
2019-06-07 15:13:23 +00:00
|
|
|
extern "C" {
|
|
|
|
struct timeval;
|
2019-11-02 18:34:06 +00:00
|
|
|
struct timespec;
|
2019-06-07 15:13:23 +00:00
|
|
|
}
|
2019-06-07 09:52:27 +00:00
|
|
|
|
2019-05-28 09:53:16 +00:00
|
|
|
#define ENUMERATE_SYSCALLS \
|
|
|
|
__ENUMERATE_SYSCALL(sleep) \
|
|
|
|
__ENUMERATE_SYSCALL(yield) \
|
|
|
|
__ENUMERATE_SYSCALL(putch) \
|
|
|
|
__ENUMERATE_SYSCALL(open) \
|
|
|
|
__ENUMERATE_SYSCALL(close) \
|
|
|
|
__ENUMERATE_SYSCALL(read) \
|
|
|
|
__ENUMERATE_SYSCALL(lseek) \
|
|
|
|
__ENUMERATE_SYSCALL(kill) \
|
|
|
|
__ENUMERATE_SYSCALL(getuid) \
|
|
|
|
__ENUMERATE_SYSCALL(exit) \
|
|
|
|
__ENUMERATE_SYSCALL(getgid) \
|
|
|
|
__ENUMERATE_SYSCALL(getpid) \
|
|
|
|
__ENUMERATE_SYSCALL(waitpid) \
|
|
|
|
__ENUMERATE_SYSCALL(mmap) \
|
|
|
|
__ENUMERATE_SYSCALL(munmap) \
|
|
|
|
__ENUMERATE_SYSCALL(get_dir_entries) \
|
|
|
|
__ENUMERATE_SYSCALL(lstat) \
|
|
|
|
__ENUMERATE_SYSCALL(getcwd) \
|
|
|
|
__ENUMERATE_SYSCALL(gettimeofday) \
|
|
|
|
__ENUMERATE_SYSCALL(gethostname) \
|
|
|
|
__ENUMERATE_SYSCALL(chdir) \
|
|
|
|
__ENUMERATE_SYSCALL(uname) \
|
|
|
|
__ENUMERATE_SYSCALL(set_mmap_name) \
|
|
|
|
__ENUMERATE_SYSCALL(readlink) \
|
|
|
|
__ENUMERATE_SYSCALL(write) \
|
|
|
|
__ENUMERATE_SYSCALL(ttyname_r) \
|
|
|
|
__ENUMERATE_SYSCALL(stat) \
|
|
|
|
__ENUMERATE_SYSCALL(getsid) \
|
|
|
|
__ENUMERATE_SYSCALL(setsid) \
|
|
|
|
__ENUMERATE_SYSCALL(getpgid) \
|
|
|
|
__ENUMERATE_SYSCALL(setpgid) \
|
|
|
|
__ENUMERATE_SYSCALL(getpgrp) \
|
|
|
|
__ENUMERATE_SYSCALL(fork) \
|
|
|
|
__ENUMERATE_SYSCALL(execve) \
|
|
|
|
__ENUMERATE_SYSCALL(geteuid) \
|
|
|
|
__ENUMERATE_SYSCALL(getegid) \
|
|
|
|
__ENUMERATE_SYSCALL(isatty) \
|
|
|
|
__ENUMERATE_SYSCALL(getdtablesize) \
|
|
|
|
__ENUMERATE_SYSCALL(dup) \
|
|
|
|
__ENUMERATE_SYSCALL(dup2) \
|
|
|
|
__ENUMERATE_SYSCALL(sigaction) \
|
|
|
|
__ENUMERATE_SYSCALL(getppid) \
|
|
|
|
__ENUMERATE_SYSCALL(umask) \
|
|
|
|
__ENUMERATE_SYSCALL(getgroups) \
|
|
|
|
__ENUMERATE_SYSCALL(setgroups) \
|
|
|
|
__ENUMERATE_SYSCALL(sigreturn) \
|
|
|
|
__ENUMERATE_SYSCALL(sigprocmask) \
|
|
|
|
__ENUMERATE_SYSCALL(sigpending) \
|
|
|
|
__ENUMERATE_SYSCALL(pipe) \
|
|
|
|
__ENUMERATE_SYSCALL(killpg) \
|
|
|
|
__ENUMERATE_SYSCALL(setuid) \
|
|
|
|
__ENUMERATE_SYSCALL(setgid) \
|
|
|
|
__ENUMERATE_SYSCALL(alarm) \
|
|
|
|
__ENUMERATE_SYSCALL(fstat) \
|
|
|
|
__ENUMERATE_SYSCALL(access) \
|
|
|
|
__ENUMERATE_SYSCALL(fcntl) \
|
|
|
|
__ENUMERATE_SYSCALL(ioctl) \
|
|
|
|
__ENUMERATE_SYSCALL(mkdir) \
|
|
|
|
__ENUMERATE_SYSCALL(times) \
|
|
|
|
__ENUMERATE_SYSCALL(utime) \
|
|
|
|
__ENUMERATE_SYSCALL(sync) \
|
|
|
|
__ENUMERATE_SYSCALL(ptsname_r) \
|
|
|
|
__ENUMERATE_SYSCALL(select) \
|
|
|
|
__ENUMERATE_SYSCALL(unlink) \
|
|
|
|
__ENUMERATE_SYSCALL(poll) \
|
|
|
|
__ENUMERATE_SYSCALL(read_tsc) \
|
|
|
|
__ENUMERATE_SYSCALL(rmdir) \
|
|
|
|
__ENUMERATE_SYSCALL(chmod) \
|
|
|
|
__ENUMERATE_SYSCALL(usleep) \
|
|
|
|
__ENUMERATE_SYSCALL(socket) \
|
|
|
|
__ENUMERATE_SYSCALL(bind) \
|
|
|
|
__ENUMERATE_SYSCALL(accept) \
|
|
|
|
__ENUMERATE_SYSCALL(listen) \
|
|
|
|
__ENUMERATE_SYSCALL(connect) \
|
|
|
|
__ENUMERATE_SYSCALL(create_shared_buffer) \
|
2019-07-18 07:52:22 +00:00
|
|
|
__ENUMERATE_SYSCALL(share_buffer_with) \
|
2019-05-28 09:53:16 +00:00
|
|
|
__ENUMERATE_SYSCALL(get_shared_buffer) \
|
|
|
|
__ENUMERATE_SYSCALL(release_shared_buffer) \
|
|
|
|
__ENUMERATE_SYSCALL(link) \
|
|
|
|
__ENUMERATE_SYSCALL(chown) \
|
|
|
|
__ENUMERATE_SYSCALL(fchmod) \
|
|
|
|
__ENUMERATE_SYSCALL(symlink) \
|
|
|
|
__ENUMERATE_SYSCALL(restore_signal_mask) \
|
2019-03-08 11:22:55 +00:00
|
|
|
__ENUMERATE_SYSCALL(get_shared_buffer_size) \
|
2019-05-28 09:53:16 +00:00
|
|
|
__ENUMERATE_SYSCALL(seal_shared_buffer) \
|
|
|
|
__ENUMERATE_SYSCALL(sendto) \
|
|
|
|
__ENUMERATE_SYSCALL(recvfrom) \
|
|
|
|
__ENUMERATE_SYSCALL(getsockopt) \
|
|
|
|
__ENUMERATE_SYSCALL(setsockopt) \
|
|
|
|
__ENUMERATE_SYSCALL(create_thread) \
|
|
|
|
__ENUMERATE_SYSCALL(gettid) \
|
|
|
|
__ENUMERATE_SYSCALL(donate) \
|
|
|
|
__ENUMERATE_SYSCALL(rename) \
|
|
|
|
__ENUMERATE_SYSCALL(shm_open) \
|
2019-11-09 21:18:16 +00:00
|
|
|
__ENUMERATE_SYSCALL(shm_unlink) \
|
2019-05-28 09:53:16 +00:00
|
|
|
__ENUMERATE_SYSCALL(ftruncate) \
|
|
|
|
__ENUMERATE_SYSCALL(systrace) \
|
|
|
|
__ENUMERATE_SYSCALL(exit_thread) \
|
|
|
|
__ENUMERATE_SYSCALL(mknod) \
|
|
|
|
__ENUMERATE_SYSCALL(writev) \
|
|
|
|
__ENUMERATE_SYSCALL(beep) \
|
|
|
|
__ENUMERATE_SYSCALL(getsockname) \
|
2019-05-29 21:20:51 +00:00
|
|
|
__ENUMERATE_SYSCALL(getpeername) \
|
2019-06-01 18:31:36 +00:00
|
|
|
__ENUMERATE_SYSCALL(sched_setparam) \
|
|
|
|
__ENUMERATE_SYSCALL(sched_getparam) \
|
2019-06-16 09:49:39 +00:00
|
|
|
__ENUMERATE_SYSCALL(fchown) \
|
2019-07-19 07:58:12 +00:00
|
|
|
__ENUMERATE_SYSCALL(halt) \
|
2019-07-21 07:59:17 +00:00
|
|
|
__ENUMERATE_SYSCALL(reboot) \
|
2019-08-02 13:18:47 +00:00
|
|
|
__ENUMERATE_SYSCALL(mount) \
|
2019-08-11 13:56:39 +00:00
|
|
|
__ENUMERATE_SYSCALL(umount) \
|
2019-07-21 17:45:31 +00:00
|
|
|
__ENUMERATE_SYSCALL(dump_backtrace) \
|
2019-07-21 19:43:37 +00:00
|
|
|
__ENUMERATE_SYSCALL(dbgputch) \
|
2019-07-22 18:01:11 +00:00
|
|
|
__ENUMERATE_SYSCALL(dbgputstr) \
|
2019-07-29 05:26:01 +00:00
|
|
|
__ENUMERATE_SYSCALL(watch_file) \
|
|
|
|
__ENUMERATE_SYSCALL(share_buffer_globally) \
|
2019-08-12 17:33:24 +00:00
|
|
|
__ENUMERATE_SYSCALL(set_process_icon) \
|
2019-08-15 18:55:10 +00:00
|
|
|
__ENUMERATE_SYSCALL(mprotect) \
|
2019-08-25 16:17:05 +00:00
|
|
|
__ENUMERATE_SYSCALL(realpath) \
|
2019-09-13 13:59:05 +00:00
|
|
|
__ENUMERATE_SYSCALL(get_process_name) \
|
2019-10-13 14:41:55 +00:00
|
|
|
__ENUMERATE_SYSCALL(fchdir) \
|
2019-11-02 18:34:06 +00:00
|
|
|
__ENUMERATE_SYSCALL(getrandom) \
|
|
|
|
__ENUMERATE_SYSCALL(clock_gettime) \
|
|
|
|
__ENUMERATE_SYSCALL(clock_nanosleep)
|
2018-11-06 12:23:22 +00:00
|
|
|
|
2018-10-16 09:01:38 +00:00
|
|
|
namespace Syscall {
|
|
|
|
|
2019-06-07 15:13:23 +00:00
|
|
|
enum Function {
|
2018-11-06 12:23:22 +00:00
|
|
|
#undef __ENUMERATE_SYSCALL
|
2019-05-28 09:53:16 +00:00
|
|
|
#define __ENUMERATE_SYSCALL(x) SC_##x,
|
2018-11-06 12:23:22 +00:00
|
|
|
ENUMERATE_SYSCALLS
|
|
|
|
#undef __ENUMERATE_SYSCALL
|
2019-11-09 21:18:16 +00:00
|
|
|
__Count
|
2018-10-16 09:01:38 +00:00
|
|
|
};
|
|
|
|
|
2019-01-31 16:31:23 +00:00
|
|
|
inline constexpr const char* to_string(Function function)
|
2018-11-06 12:23:22 +00:00
|
|
|
{
|
|
|
|
switch (function) {
|
|
|
|
#undef __ENUMERATE_SYSCALL
|
2019-05-28 09:53:16 +00:00
|
|
|
#define __ENUMERATE_SYSCALL(x) \
|
|
|
|
case SC_##x: \
|
|
|
|
return #x;
|
|
|
|
ENUMERATE_SYSCALLS
|
2018-11-06 12:23:22 +00:00
|
|
|
#undef __ENUMERATE_SYSCALL
|
2019-11-09 21:18:16 +00:00
|
|
|
default:
|
|
|
|
break;
|
2018-11-06 12:23:22 +00:00
|
|
|
}
|
2018-11-07 20:19:47 +00:00
|
|
|
return "Unknown";
|
2018-11-06 12:23:22 +00:00
|
|
|
}
|
|
|
|
|
2019-04-20 10:58:02 +00:00
|
|
|
#ifdef __serenity__
|
2018-11-08 10:37:01 +00:00
|
|
|
struct SC_mmap_params {
|
|
|
|
uint32_t addr;
|
|
|
|
uint32_t size;
|
|
|
|
int32_t prot;
|
|
|
|
int32_t flags;
|
|
|
|
int32_t fd;
|
2018-11-09 09:09:46 +00:00
|
|
|
int32_t offset; // FIXME: 64-bit off_t?
|
2019-05-19 13:54:56 +00:00
|
|
|
const char* name { nullptr };
|
2018-11-08 10:37:01 +00:00
|
|
|
};
|
|
|
|
|
2019-07-08 18:01:49 +00:00
|
|
|
struct SC_open_params {
|
|
|
|
const char* path;
|
|
|
|
int path_length;
|
|
|
|
int options;
|
|
|
|
u16 mode;
|
|
|
|
};
|
|
|
|
|
2019-01-15 22:12:20 +00:00
|
|
|
struct SC_select_params {
|
|
|
|
int nfds;
|
|
|
|
fd_set* readfds;
|
|
|
|
fd_set* writefds;
|
|
|
|
fd_set* exceptfds;
|
|
|
|
struct timeval* timeout;
|
|
|
|
};
|
|
|
|
|
2019-11-02 18:34:06 +00:00
|
|
|
struct SC_clock_nanosleep_params {
|
|
|
|
int clock_id;
|
|
|
|
int flags;
|
|
|
|
const struct timespec* requested_sleep;
|
|
|
|
struct timespec* remaining_sleep;
|
|
|
|
};
|
|
|
|
|
2019-03-12 14:51:42 +00:00
|
|
|
struct SC_sendto_params {
|
|
|
|
int sockfd;
|
|
|
|
const void* data;
|
|
|
|
size_t data_length;
|
|
|
|
int flags;
|
2019-05-28 09:53:16 +00:00
|
|
|
const void* addr; // const sockaddr*
|
2019-03-12 14:51:42 +00:00
|
|
|
size_t addr_length; // socklen_t
|
|
|
|
};
|
|
|
|
|
2019-03-12 16:27:07 +00:00
|
|
|
struct SC_recvfrom_params {
|
|
|
|
int sockfd;
|
|
|
|
void* buffer;
|
|
|
|
size_t buffer_length;
|
|
|
|
int flags;
|
2019-05-28 09:53:16 +00:00
|
|
|
void* addr; // sockaddr*
|
2019-03-13 13:47:21 +00:00
|
|
|
void* addr_length; // socklen_t*
|
2019-03-12 16:27:07 +00:00
|
|
|
};
|
|
|
|
|
2019-03-13 12:13:23 +00:00
|
|
|
struct SC_getsockopt_params {
|
|
|
|
int sockfd;
|
|
|
|
int level;
|
|
|
|
int option;
|
|
|
|
void* value;
|
|
|
|
void* value_size; // socklen_t*
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SC_setsockopt_params {
|
|
|
|
int sockfd;
|
|
|
|
int level;
|
|
|
|
int option;
|
|
|
|
const void* value;
|
|
|
|
size_t value_size; // socklen_t
|
|
|
|
};
|
|
|
|
|
2018-10-16 09:01:38 +00:00
|
|
|
void initialize();
|
2018-12-20 01:41:55 +00:00
|
|
|
int sync();
|
2018-10-18 11:05:00 +00:00
|
|
|
|
2019-07-03 19:17:35 +00:00
|
|
|
inline u32 invoke(Function function)
|
2018-10-18 11:05:00 +00:00
|
|
|
{
|
2019-07-03 19:17:35 +00:00
|
|
|
u32 result;
|
2019-05-28 09:53:16 +00:00
|
|
|
asm volatile("int $0x82"
|
|
|
|
: "=a"(result)
|
|
|
|
: "a"(function)
|
|
|
|
: "memory");
|
2018-10-18 11:05:00 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-12-21 02:02:06 +00:00
|
|
|
template<typename T1>
|
2019-07-03 19:17:35 +00:00
|
|
|
inline u32 invoke(Function function, T1 arg1)
|
2018-10-18 11:05:00 +00:00
|
|
|
{
|
2019-07-03 19:17:35 +00:00
|
|
|
u32 result;
|
2019-05-28 09:53:16 +00:00
|
|
|
asm volatile("int $0x82"
|
|
|
|
: "=a"(result)
|
2019-07-03 19:17:35 +00:00
|
|
|
: "a"(function), "d"((u32)arg1)
|
2019-05-28 09:53:16 +00:00
|
|
|
: "memory");
|
2018-10-18 11:05:00 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-12-21 02:02:06 +00:00
|
|
|
template<typename T1, typename T2>
|
2019-07-03 19:17:35 +00:00
|
|
|
inline u32 invoke(Function function, T1 arg1, T2 arg2)
|
2018-10-18 11:05:00 +00:00
|
|
|
{
|
2019-07-03 19:17:35 +00:00
|
|
|
u32 result;
|
2019-05-28 09:53:16 +00:00
|
|
|
asm volatile("int $0x82"
|
|
|
|
: "=a"(result)
|
2019-07-03 19:17:35 +00:00
|
|
|
: "a"(function), "d"((u32)arg1), "c"((u32)arg2)
|
2019-05-28 09:53:16 +00:00
|
|
|
: "memory");
|
2018-10-18 11:05:00 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-12-21 02:02:06 +00:00
|
|
|
template<typename T1, typename T2, typename T3>
|
2019-07-03 19:17:35 +00:00
|
|
|
inline u32 invoke(Function function, T1 arg1, T2 arg2, T3 arg3)
|
2018-10-18 11:05:00 +00:00
|
|
|
{
|
2019-07-03 19:17:35 +00:00
|
|
|
u32 result;
|
2019-05-28 09:53:16 +00:00
|
|
|
asm volatile("int $0x82"
|
|
|
|
: "=a"(result)
|
2019-07-03 19:17:35 +00:00
|
|
|
: "a"(function), "d"((u32)arg1), "c"((u32)arg2), "b"((u32)arg3)
|
2019-05-28 09:53:16 +00:00
|
|
|
: "memory");
|
2018-10-18 11:05:00 +00:00
|
|
|
return result;
|
|
|
|
}
|
2019-01-25 04:19:29 +00:00
|
|
|
#endif
|
2018-10-16 09:01:38 +00:00
|
|
|
|
|
|
|
}
|
2018-12-21 02:02:06 +00:00
|
|
|
|
|
|
|
#undef __ENUMERATE_SYSCALL
|
2019-05-28 09:53:16 +00:00
|
|
|
#define __ENUMERATE_SYSCALL(x) using Syscall::SC_##x;
|
|
|
|
ENUMERATE_SYSCALLS
|
2018-12-21 02:02:06 +00:00
|
|
|
#undef __ENUMERATE_SYSCALL
|
|
|
|
#define syscall Syscall::invoke
|