2018-10-16 09:01:38 +00:00
|
|
|
#pragma once
|
|
|
|
|
2018-10-22 11:55:11 +00:00
|
|
|
#include <AK/Types.h>
|
|
|
|
|
2018-11-06 12:23:22 +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(get_arguments) \
|
|
|
|
__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(get_environment) \
|
|
|
|
__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) \
|
2018-11-06 12:33:06 +00:00
|
|
|
__ENUMERATE_SYSCALL(getppid) \
|
2018-11-06 12:40:23 +00:00
|
|
|
__ENUMERATE_SYSCALL(umask) \
|
2018-11-07 00:38:51 +00:00
|
|
|
__ENUMERATE_SYSCALL(getgroups) \
|
|
|
|
__ENUMERATE_SYSCALL(setgroups) \
|
2018-11-07 20:19:47 +00:00
|
|
|
__ENUMERATE_SYSCALL(sigreturn) \
|
2018-11-10 22:29:07 +00:00
|
|
|
__ENUMERATE_SYSCALL(sigprocmask) \
|
|
|
|
__ENUMERATE_SYSCALL(sigpending) \
|
2018-11-10 23:20:53 +00:00
|
|
|
__ENUMERATE_SYSCALL(pipe) \
|
|
|
|
__ENUMERATE_SYSCALL(killpg) \
|
|
|
|
__ENUMERATE_SYSCALL(setuid) \
|
|
|
|
__ENUMERATE_SYSCALL(setgid) \
|
|
|
|
__ENUMERATE_SYSCALL(alarm) \
|
|
|
|
__ENUMERATE_SYSCALL(fstat) \
|
|
|
|
__ENUMERATE_SYSCALL(access) \
|
2018-11-11 09:38:33 +00:00
|
|
|
__ENUMERATE_SYSCALL(fcntl) \
|
2018-11-16 12:11:21 +00:00
|
|
|
__ENUMERATE_SYSCALL(ioctl) \
|
2018-11-18 13:57:41 +00:00
|
|
|
__ENUMERATE_SYSCALL(mkdir) \
|
2018-12-03 00:12:26 +00:00
|
|
|
__ENUMERATE_SYSCALL(times) \
|
2018-12-19 20:14:55 +00:00
|
|
|
__ENUMERATE_SYSCALL(utime) \
|
2018-12-19 23:39:29 +00:00
|
|
|
__ENUMERATE_SYSCALL(sync) \
|
2019-01-15 05:30:19 +00:00
|
|
|
__ENUMERATE_SYSCALL(ptsname_r) \
|
2019-01-24 22:40:12 +00:00
|
|
|
__ENUMERATE_SYSCALL(select) \
|
|
|
|
__ENUMERATE_SYSCALL(unlink) \
|
|
|
|
__ENUMERATE_SYSCALL(poll) \
|
2019-01-25 01:09:29 +00:00
|
|
|
__ENUMERATE_SYSCALL(read_tsc) \
|
2019-01-28 03:16:01 +00:00
|
|
|
__ENUMERATE_SYSCALL(rmdir) \
|
2019-01-29 03:55:08 +00:00
|
|
|
__ENUMERATE_SYSCALL(chmod) \
|
2019-02-03 15:11:28 +00:00
|
|
|
__ENUMERATE_SYSCALL(usleep) \
|
2019-02-14 13:17:38 +00:00
|
|
|
__ENUMERATE_SYSCALL(socket) \
|
|
|
|
__ENUMERATE_SYSCALL(bind) \
|
|
|
|
__ENUMERATE_SYSCALL(accept) \
|
|
|
|
__ENUMERATE_SYSCALL(listen) \
|
|
|
|
__ENUMERATE_SYSCALL(connect) \
|
2019-01-14 14:25:34 +00:00
|
|
|
|
2018-11-06 12:23:22 +00:00
|
|
|
|
2019-01-25 04:19:29 +00:00
|
|
|
#ifdef SERENITY
|
2019-01-15 22:12:20 +00:00
|
|
|
struct fd_set;
|
2019-01-25 04:19:29 +00:00
|
|
|
#endif
|
2019-01-15 22:12:20 +00:00
|
|
|
|
2018-10-16 09:01:38 +00:00
|
|
|
namespace Syscall {
|
|
|
|
|
|
|
|
enum Function {
|
2018-11-06 12:23:22 +00:00
|
|
|
#undef __ENUMERATE_SYSCALL
|
|
|
|
#define __ENUMERATE_SYSCALL(x) SC_ ##x ,
|
|
|
|
ENUMERATE_SYSCALLS
|
|
|
|
#undef __ENUMERATE_SYSCALL
|
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
|
|
|
|
#define __ENUMERATE_SYSCALL(x) case SC_ ##x: return #x;
|
|
|
|
ENUMERATE_SYSCALLS
|
|
|
|
#undef __ENUMERATE_SYSCALL
|
|
|
|
}
|
2018-11-07 20:19:47 +00:00
|
|
|
return "Unknown";
|
2018-11-06 12:23:22 +00:00
|
|
|
}
|
|
|
|
|
2019-01-25 04:19:29 +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?
|
2018-11-08 10:37:01 +00:00
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
2018-11-16 12:11:21 +00:00
|
|
|
inline dword invoke(Function function)
|
2018-10-18 11:05:00 +00:00
|
|
|
{
|
2018-10-22 11:55:11 +00:00
|
|
|
dword result;
|
2018-11-08 10:37:01 +00:00
|
|
|
asm volatile("int $0x80":"=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>
|
|
|
|
inline dword invoke(Function function, T1 arg1)
|
2018-10-18 11:05:00 +00:00
|
|
|
{
|
2018-10-22 11:55:11 +00:00
|
|
|
dword result;
|
2018-12-21 02:02:06 +00:00
|
|
|
asm volatile("int $0x80":"=a"(result):"a"(function),"d"((dword)arg1):"memory");
|
2018-10-18 11:05:00 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-12-21 02:02:06 +00:00
|
|
|
template<typename T1, typename T2>
|
|
|
|
inline dword invoke(Function function, T1 arg1, T2 arg2)
|
2018-10-18 11:05:00 +00:00
|
|
|
{
|
2018-10-22 11:55:11 +00:00
|
|
|
dword result;
|
2018-12-21 02:02:06 +00:00
|
|
|
asm volatile("int $0x80":"=a"(result):"a"(function),"d"((dword)arg1),"c"((dword)arg2):"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>
|
|
|
|
inline dword invoke(Function function, T1 arg1, T2 arg2, T3 arg3)
|
2018-10-18 11:05:00 +00:00
|
|
|
{
|
2018-10-22 11:55:11 +00:00
|
|
|
dword result;
|
2018-12-21 02:02:06 +00:00
|
|
|
asm volatile("int $0x80":"=a"(result):"a"(function),"d"((dword)arg1),"c"((dword)arg2),"b"((dword)arg3):"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
|
|
|
|
#define __ENUMERATE_SYSCALL(x) using Syscall::SC_ ##x;
|
|
|
|
ENUMERATE_SYSCALLS
|
|
|
|
#undef __ENUMERATE_SYSCALL
|
|
|
|
#define syscall Syscall::invoke
|