summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Kernel/Syscall.h27
-rw-r--r--LibC/dirent.cpp2
-rw-r--r--LibC/entry.cpp6
-rw-r--r--LibC/fcntl.cpp2
-rw-r--r--LibC/ioctl.cpp2
-rw-r--r--LibC/mman.cpp6
-rw-r--r--LibC/signal.cpp10
-rw-r--r--LibC/stat.cpp4
-rw-r--r--LibC/time.cpp2
-rw-r--r--LibC/times.cpp2
-rw-r--r--LibC/unistd.cpp80
-rw-r--r--LibC/utime.cpp2
-rw-r--r--LibC/utsname.cpp2
13 files changed, 75 insertions, 72 deletions
diff --git a/Kernel/Syscall.h b/Kernel/Syscall.h
index 3c86fe2694..78b2b81a0f 100644
--- a/Kernel/Syscall.h
+++ b/Kernel/Syscall.h
@@ -67,12 +67,6 @@
__ENUMERATE_SYSCALL(utime) \
__ENUMERATE_SYSCALL(sync) \
-
-#define DO_SYSCALL_A0(function) Syscall::invoke((dword)(function))
-#define DO_SYSCALL_A1(function, arg1) Syscall::invoke((dword)(function), (dword)(arg1))
-#define DO_SYSCALL_A2(function, arg1, arg2) Syscall::invoke((dword)(function), (dword)(arg1), (dword)(arg2))
-#define DO_SYSCALL_A3(function, arg1, arg2, arg3) Syscall::invoke((dword)(function), (dword)(arg1), (dword)(arg2), (dword)arg3)
-
namespace Syscall {
enum Function {
@@ -112,25 +106,34 @@ inline dword invoke(Function function)
return result;
}
-inline dword invoke(Function function, dword arg1)
+template<typename T1>
+inline dword invoke(Function function, T1 arg1)
{
dword result;
- asm volatile("int $0x80":"=a"(result):"a"(function),"d"(arg1):"memory");
+ asm volatile("int $0x80":"=a"(result):"a"(function),"d"((dword)arg1):"memory");
return result;
}
-inline dword invoke(Function function, dword arg1, dword arg2)
+template<typename T1, typename T2>
+inline dword invoke(Function function, T1 arg1, T2 arg2)
{
dword result;
- asm volatile("int $0x80":"=a"(result):"a"(function),"d"(arg1),"c"(arg2):"memory");
+ asm volatile("int $0x80":"=a"(result):"a"(function),"d"((dword)arg1),"c"((dword)arg2):"memory");
return result;
}
-inline dword invoke(Function function, dword arg1, dword arg2, dword arg3)
+template<typename T1, typename T2, typename T3>
+inline dword invoke(Function function, T1 arg1, T2 arg2, T3 arg3)
{
dword result;
- asm volatile("int $0x80":"=a"(result):"a"(function),"d"(arg1),"c"(arg2),"b"(arg3):"memory");
+ asm volatile("int $0x80":"=a"(result):"a"(function),"d"((dword)arg1),"c"((dword)arg2),"b"((dword)arg3):"memory");
return result;
}
}
+
+#undef __ENUMERATE_SYSCALL
+#define __ENUMERATE_SYSCALL(x) using Syscall::SC_ ##x;
+ ENUMERATE_SYSCALLS
+#undef __ENUMERATE_SYSCALL
+#define syscall Syscall::invoke
diff --git a/LibC/dirent.cpp b/LibC/dirent.cpp
index 41fd6443fb..8f70166840 100644
--- a/LibC/dirent.cpp
+++ b/LibC/dirent.cpp
@@ -53,7 +53,7 @@ dirent* readdir(DIR* dirp)
if (!dirp->buffer) {
// FIXME: Figure out how much to actually allocate.
dirp->buffer = (char*)malloc(4096);
- ssize_t nread = Syscall::invoke(Syscall::SC_get_dir_entries, (dword)dirp->fd, (dword)dirp->buffer, 4096);
+ ssize_t nread = syscall(SC_get_dir_entries, dirp->fd, dirp->buffer, 4096);
dirp->buffer_size = nread;
dirp->nextptr = dirp->buffer;
}
diff --git a/LibC/entry.cpp b/LibC/entry.cpp
index c99f699f93..8fd78e3e64 100644
--- a/LibC/entry.cpp
+++ b/LibC/entry.cpp
@@ -23,10 +23,10 @@ extern "C" int _start()
int status = 254;
int argc;
char** argv;
- int rc = Syscall::invoke(Syscall::SC_get_arguments, (dword)&argc, (dword)&argv);
+ int rc = syscall(SC_get_arguments, &argc, &argv);
if (rc < 0)
goto epilogue;
- rc = Syscall::invoke(Syscall::SC_get_environment, (dword)&environ);
+ rc = syscall(SC_get_environment, &environ);
if (rc < 0)
goto epilogue;
status = main(argc, argv);
@@ -35,7 +35,7 @@ extern "C" int _start()
fflush(stderr);
epilogue:
- Syscall::invoke(Syscall::SC_exit, status);
+ syscall(SC_exit, status);
// Birger's birthday <3
return 20150614;
diff --git a/LibC/fcntl.cpp b/LibC/fcntl.cpp
index 7c22b0442d..dd28a65cb6 100644
--- a/LibC/fcntl.cpp
+++ b/LibC/fcntl.cpp
@@ -11,7 +11,7 @@ int fcntl(int fd, int cmd, ...)
va_list ap;
va_start(ap, cmd);
dword extra_arg = va_arg(ap, dword);
- int rc = Syscall::invoke(Syscall::SC_fcntl, (dword)fd, (dword)cmd, extra_arg);
+ int rc = syscall(SC_fcntl, fd, cmd, extra_arg);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
diff --git a/LibC/ioctl.cpp b/LibC/ioctl.cpp
index dcfc7ce7a4..354d49e7b7 100644
--- a/LibC/ioctl.cpp
+++ b/LibC/ioctl.cpp
@@ -11,7 +11,7 @@ int ioctl(int fd, unsigned request, ...)
va_list ap;
va_start(ap, request);
unsigned arg = va_arg(ap, unsigned);
- int rc = Syscall::invoke(Syscall::SC_ioctl, (dword)fd, (dword)request, (dword)arg);
+ int rc = syscall(SC_ioctl, fd, request, arg);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
diff --git a/LibC/mman.cpp b/LibC/mman.cpp
index ff01378aae..a2393f3b02 100644
--- a/LibC/mman.cpp
+++ b/LibC/mman.cpp
@@ -8,19 +8,19 @@ extern "C" {
void* mmap(void* addr, size_t size, int prot, int flags, int fd, off_t offset)
{
Syscall::SC_mmap_params params { (dword)addr, size, prot, flags, fd, offset };
- int rc = Syscall::invoke(Syscall::SC_mmap, (dword)&params);
+ int rc = syscall(SC_mmap, &params);
__RETURN_WITH_ERRNO(rc, (void*)rc, (void*)-1);
}
int munmap(void* addr, size_t size)
{
- int rc = Syscall::invoke(Syscall::SC_munmap, (dword)addr, (dword)size);
+ int rc = syscall(SC_munmap, addr, size);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
int set_mmap_name(void* addr, size_t size, const char* name)
{
- int rc = Syscall::invoke(Syscall::SC_set_mmap_name, (dword)addr, (dword)size, (dword)name);
+ int rc = syscall(SC_set_mmap_name, addr, size, name);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
diff --git a/LibC/signal.cpp b/LibC/signal.cpp
index 215ac2a56c..9e74466793 100644
--- a/LibC/signal.cpp
+++ b/LibC/signal.cpp
@@ -8,13 +8,13 @@ extern "C" {
int kill(pid_t pid, int sig)
{
- int rc = Syscall::invoke(Syscall::SC_kill, (dword)pid, (dword)sig);
+ int rc = syscall(SC_kill, pid, sig);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
int killpg(int pgrp, int sig)
{
- int rc = Syscall::invoke(Syscall::SC_killpg, (dword)pgrp, (dword)sig);
+ int rc = syscall(SC_killpg, pgrp, sig);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
@@ -34,7 +34,7 @@ sighandler_t signal(int signum, sighandler_t handler)
int sigaction(int signum, const struct sigaction* act, struct sigaction* old_act)
{
- int rc = Syscall::invoke(Syscall::SC_sigaction, (dword)signum, (dword)act, (dword)old_act);
+ int rc = syscall(SC_sigaction, signum, act, old_act);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
@@ -83,13 +83,13 @@ int sigismember(const sigset_t* set, int sig)
int sigprocmask(int how, const sigset_t* set, sigset_t* old_set)
{
- int rc = Syscall::invoke(Syscall::SC_sigprocmask, (dword)how, (dword)set, (dword)old_set);
+ int rc = syscall(SC_sigprocmask, how, set, old_set);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
int sigpending(sigset_t* set)
{
- int rc = Syscall::invoke(Syscall::SC_sigpending, (dword)set);
+ int rc = syscall(SC_sigpending, set);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
diff --git a/LibC/stat.cpp b/LibC/stat.cpp
index 7ddd35314c..a210a7b240 100644
--- a/LibC/stat.cpp
+++ b/LibC/stat.cpp
@@ -6,12 +6,12 @@ extern "C" {
mode_t umask(mode_t mask)
{
- return Syscall::invoke(Syscall::SC_umask, (dword)mask);
+ return syscall(SC_umask, mask);
}
int mkdir(const char* pathname, mode_t mode)
{
- int rc = Syscall::invoke(Syscall::SC_mkdir, (dword)pathname, (dword)mode);
+ int rc = syscall(SC_mkdir, pathname, mode);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
diff --git a/LibC/time.cpp b/LibC/time.cpp
index 3bad6fad22..f78a73a114 100644
--- a/LibC/time.cpp
+++ b/LibC/time.cpp
@@ -18,7 +18,7 @@ time_t time(time_t* tloc)
int gettimeofday(struct timeval* tv, struct timezone*)
{
- int rc = Syscall::invoke(Syscall::SC_gettimeofday, (dword)tv);
+ int rc = syscall(SC_gettimeofday, tv);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
diff --git a/LibC/times.cpp b/LibC/times.cpp
index 0fe57c1a9e..7411af706d 100644
--- a/LibC/times.cpp
+++ b/LibC/times.cpp
@@ -4,6 +4,6 @@
clock_t times(struct tms* buf)
{
- int rc = Syscall::invoke(Syscall::SC_times, (dword)buf);
+ int rc = syscall(SC_times, buf);
__RETURN_WITH_ERRNO(rc, rc, (clock_t)-1);
}
diff --git a/LibC/unistd.cpp b/LibC/unistd.cpp
index d7c1d252be..d039c1daef 100644
--- a/LibC/unistd.cpp
+++ b/LibC/unistd.cpp
@@ -13,49 +13,49 @@ extern "C" {
pid_t fork()
{
- int rc = Syscall::invoke(Syscall::SC_fork);
+ int rc = syscall(SC_fork);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
int execve(const char* filename, const char** argv, const char** envp)
{
- int rc = Syscall::invoke(Syscall::SC_execve, (dword)filename, (dword)argv, (dword)envp);
+ int rc = syscall(SC_execve, filename, argv, envp);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
uid_t getuid()
{
- return Syscall::invoke(Syscall::SC_getuid);
+ return syscall(SC_getuid);
}
gid_t getgid()
{
- return Syscall::invoke(Syscall::SC_getgid);
+ return syscall(SC_getgid);
}
uid_t geteuid()
{
- return Syscall::invoke(Syscall::SC_geteuid);
+ return syscall(SC_geteuid);
}
gid_t getegid()
{
- return Syscall::invoke(Syscall::SC_getegid);
+ return syscall(SC_getegid);
}
pid_t getpid()
{
- return Syscall::invoke(Syscall::SC_getpid);
+ return syscall(SC_getpid);
}
pid_t getppid()
{
- return Syscall::invoke(Syscall::SC_getppid);
+ return syscall(SC_getppid);
}
pid_t setsid()
{
- int rc = Syscall::invoke(Syscall::SC_setsid);
+ int rc = syscall(SC_setsid);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
@@ -71,19 +71,19 @@ int tcsetpgrp(int fd, pid_t pgid)
int setpgid(pid_t pid, pid_t pgid)
{
- int rc = Syscall::invoke(Syscall::SC_setpgid, (dword)pid, (dword)pgid);
+ int rc = syscall(SC_setpgid, pid, pgid);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
pid_t getpgid(pid_t pid)
{
- int rc = Syscall::invoke(Syscall::SC_getpgid, (dword)pid);
+ int rc = syscall(SC_getpgid, pid);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
pid_t getpgrp()
{
- int rc = Syscall::invoke(Syscall::SC_getpgrp);
+ int rc = syscall(SC_getpgrp);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
@@ -91,26 +91,26 @@ int open(const char* path, int options, ...)
{
va_list ap;
va_start(ap, options);
- int rc = Syscall::invoke(Syscall::SC_open, (dword)path, (dword)options, (dword)ap);
+ int rc = syscall(SC_open, path, options, ap);
va_end(ap);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
ssize_t read(int fd, void* buf, size_t count)
{
- int rc = Syscall::invoke(Syscall::SC_read, (dword)fd, (dword)buf, (dword)count);
+ int rc = syscall(SC_read, fd, buf, count);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
ssize_t write(int fd, const void* buf, size_t count)
{
- int rc = Syscall::invoke(Syscall::SC_write, (dword)fd, (dword)buf, (dword)count);
+ int rc = syscall(SC_write, fd, buf, count);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
int ttyname_r(int fd, char* buffer, size_t size)
{
- int rc = Syscall::invoke(Syscall::SC_ttyname_r, (dword)fd, (dword)buffer, (dword)size);
+ int rc = syscall(SC_ttyname_r, fd, buffer, size);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
@@ -124,43 +124,43 @@ char* ttyname(int fd)
int close(int fd)
{
- int rc = Syscall::invoke(Syscall::SC_close, fd);
+ int rc = syscall(SC_close, fd);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
pid_t waitpid(pid_t waitee, int* wstatus, int options)
{
- int rc = Syscall::invoke(Syscall::SC_waitpid, waitee, (dword)wstatus, (dword)options);
+ int rc = syscall(SC_waitpid, waitee, wstatus, options);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
int lstat(const char* path, struct stat* statbuf)
{
- int rc = Syscall::invoke(Syscall::SC_lstat, (dword)path, (dword)statbuf);
+ int rc = syscall(SC_lstat, path, statbuf);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
int stat(const char* path, struct stat* statbuf)
{
- int rc = Syscall::invoke(Syscall::SC_stat, (dword)path, (dword)statbuf);
+ int rc = syscall(SC_stat, path, statbuf);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
int fstat(int fd, struct stat *statbuf)
{
- int rc = Syscall::invoke(Syscall::SC_fstat, (dword)fd, (dword)statbuf);
+ int rc = syscall(SC_fstat, fd, statbuf);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
int chdir(const char* path)
{
- int rc = Syscall::invoke(Syscall::SC_chdir, (dword)path);
+ int rc = syscall(SC_chdir, path);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
char* getcwd(char* buffer, size_t size)
{
- int rc = Syscall::invoke(Syscall::SC_getcwd, (dword)buffer, (dword)size);
+ int rc = syscall(SC_getcwd, buffer, size);
__RETURN_WITH_ERRNO(rc, buffer, nullptr);
}
@@ -172,24 +172,24 @@ char* getwd(char* buf)
int sleep(unsigned seconds)
{
- return Syscall::invoke(Syscall::SC_sleep, (dword)seconds);
+ return syscall(SC_sleep, seconds);
}
int gethostname(char* buffer, size_t size)
{
- int rc = Syscall::invoke(Syscall::SC_gethostname, (dword)buffer, (dword)size);
+ int rc = syscall(SC_gethostname, buffer, size);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
ssize_t readlink(const char* path, char* buffer, size_t size)
{
- int rc = Syscall::invoke(Syscall::SC_readlink, (dword)path, (dword)buffer, (dword)size);
+ int rc = syscall(SC_readlink, path, buffer, size);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
off_t lseek(int fd, off_t offset, int whence)
{
- int rc = Syscall::invoke(Syscall::SC_lseek, (dword)fd, (dword)offset, (dword)whence);
+ int rc = syscall(SC_lseek, fd, offset, whence);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
@@ -205,66 +205,66 @@ int unlink(const char*)
int isatty(int fd)
{
- int rc = Syscall::invoke(Syscall::SC_isatty, (dword)fd);
+ int rc = syscall(SC_isatty, fd);
__RETURN_WITH_ERRNO(rc, 1, 0);
}
int getdtablesize()
{
- int rc = Syscall::invoke(Syscall::SC_getdtablesize);
+ int rc = syscall(SC_getdtablesize);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
int dup(int old_fd)
{
- int rc = Syscall::invoke(Syscall::SC_dup, (dword)old_fd);
+ int rc = syscall(SC_dup, old_fd);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
int dup2(int old_fd, int new_fd)
{
- int rc = Syscall::invoke(Syscall::SC_dup2, (dword)old_fd, (dword)new_fd);
+ int rc = syscall(SC_dup2, old_fd, new_fd);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
int setgroups(size_t size, const gid_t* list)
{
- int rc = Syscall::invoke(Syscall::SC_getgroups, (dword)size, (dword)list);
+ int rc = syscall(SC_getgroups, size, list);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
int getgroups(int size, gid_t list[])
{
- int rc = Syscall::invoke(Syscall::SC_getgroups, (dword)size, (dword)list);
+ int rc = syscall(SC_getgroups, size, list);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
int pipe(int pipefd[2])
{
- int rc = Syscall::invoke(Syscall::SC_pipe, (dword)pipefd);
+ int rc = syscall(SC_pipe, pipefd);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
unsigned int alarm(unsigned int seconds)
{
- return Syscall::invoke(Syscall::SC_alarm, (dword)seconds);
+ return syscall(SC_alarm, seconds);
}
int setuid(uid_t uid)
{
- int rc = Syscall::invoke(Syscall::SC_setuid, (dword)uid);
+ int rc = syscall(SC_setuid, uid);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
int setgid(uid_t gid)
{
- int rc = Syscall::invoke(Syscall::SC_setgid, (dword)gid);
+ int rc = syscall(SC_setgid, gid);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
int access(const char* pathname, int mode)
{
- int rc = Syscall::invoke(Syscall::SC_access, (dword)pathname, (dword)mode);
+ int rc = syscall(SC_access, pathname, mode);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
@@ -290,13 +290,13 @@ long pathconf(const char* path, int name)
void _exit(int status)
{
- Syscall::invoke(Syscall::SC_exit, (dword)status);
+ syscall(SC_exit, status);
assert(false);
}
void sync()
{
- Syscall::invoke(Syscall::SC_sync);
+ syscall(SC_sync);
}
}
diff --git a/LibC/utime.cpp b/LibC/utime.cpp
index 310d06c32a..737d958e49 100644
--- a/LibC/utime.cpp
+++ b/LibC/utime.cpp
@@ -6,7 +6,7 @@ extern "C" {
int utime(const char* pathname, const struct utimbuf* buf)
{
- int rc = Syscall::invoke(Syscall::SC_utime, (dword)pathname, (dword)buf);
+ int rc = syscall(SC_utime, (dword)pathname, (dword)buf);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
diff --git a/LibC/utsname.cpp b/LibC/utsname.cpp
index 1e4c4ba2b0..bc8d5f02a6 100644
--- a/LibC/utsname.cpp
+++ b/LibC/utsname.cpp
@@ -6,7 +6,7 @@ extern "C" {
int uname(struct utsname* buf)
{
- int rc = Syscall::invoke(Syscall::SC_uname, (dword)buf);
+ int rc = syscall(SC_uname, buf);
__RETURN_WITH_ERRNO(rc, rc, -1);
}