Initialize system call table at compile time.

This commit is contained in:
Jonas 'Sortie' Termansen 2014-10-17 00:04:47 +02:00
parent 67cbc0715c
commit ba1e0882ec
37 changed files with 502 additions and 808 deletions

View File

@ -36,7 +36,6 @@
#include <sortix/kernel/timer.h>
namespace Sortix {
namespace Alarm {
static void alarm_handler(Clock* /*clock*/, Timer* /*timer*/, void* user)
{
@ -45,7 +44,6 @@ static void alarm_handler(Clock* /*clock*/, Timer* /*timer*/, void* user)
process->DeliverSignal(SIGALRM);
}
static
int sys_alarmns(const struct timespec* user_delay, struct timespec* user_odelay)
{
Process* process = CurrentProcess();
@ -64,10 +62,4 @@ int sys_alarmns(const struct timespec* user_delay, struct timespec* user_odelay)
return 0;
}
void Init()
{
Syscall::Register(SYSCALL_ALARMNS, (void*) sys_alarmns);
}
} // namespace Alarm
} // namespace Sortix

View File

@ -1,31 +0,0 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013.
This file is part of Sortix.
Sortix is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
Sortix is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
You should have received a copy of the GNU General Public License along with
Sortix. If not, see <http://www.gnu.org/licenses/>.
alarm.h
Sends a signal after a certain amount of time has passed.
*******************************************************************************/
namespace Sortix {
namespace Alarm {
void Init();
} // namespace Alarm
} // namespace Sortix

View File

@ -55,7 +55,6 @@
#include <sortix/kernel/vnode.h>
namespace Sortix {
namespace UserFS {
class ChannelDirection;
@ -1485,7 +1484,12 @@ Ref<Inode> FactoryNode::open(ioctx_t* /*ctx*/, const char* filename,
return errno = ENOENT, Ref<Inode>(NULL);
}
static int sys_fsm_fsbind(int rootfd, int mpointfd, int /*flags*/)
} // namespace UserFS
} // namespace Sortix
namespace Sortix {
int sys_fsm_fsbind(int rootfd, int mpointfd, int /*flags*/)
{
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(rootfd);
if ( !desc ) { return -1; }
@ -1496,6 +1500,11 @@ static int sys_fsm_fsbind(int rootfd, int mpointfd, int /*flags*/)
return mtable->AddMount(mpoint->ino, mpoint->dev, node) ? 0 : -1;
}
} // namespace Sortix
namespace Sortix {
namespace UserFS {
void Init(const char* devpath, Ref<Descriptor> slashdev)
{
ioctx_t ctx; SetupKernelIOCtx(&ctx);
@ -1514,8 +1523,6 @@ void Init(const char* devpath, Ref<Descriptor> slashdev)
// for this on the file descriptor class!
if ( !mtable->AddMount(mpoint->ino, mpoint->dev, node) )
PanicF("Unable to mount filesystem on %s/fs", devpath);
Syscall::Register(SYSCALL_FSM_FSBIND, (void*) sys_fsm_fsbind);
}
} // namespace UserFS

View File

@ -32,17 +32,14 @@
#include <sortix/kernel/kthread.h>
#include <sortix/kernel/syscall.h>
#include "hostname.h"
namespace Sortix {
namespace Hostname {
static kthread_mutex_t hostname_lock = KTHREAD_MUTEX_INITIALIZER;
static char hostname[HOST_NAME_MAX + 1] = "sortix";
static size_t hostname_length = 6;
static int sys_gethostname(char* dst_name, size_t dst_name_size)
int sys_gethostname(char* dst_name, size_t dst_name_size)
{
if ( dst_name_size == 0 )
return errno = EINVAL, -1;
@ -60,7 +57,7 @@ static int sys_gethostname(char* dst_name, size_t dst_name_size)
return 0;
}
static int sys_sethostname(const char* src_name, size_t src_name_size)
int sys_sethostname(const char* src_name, size_t src_name_size)
{
char new_hostname[HOST_NAME_MAX + 1];
if ( sizeof(new_hostname) < src_name_size )
@ -77,11 +74,4 @@ static int sys_sethostname(const char* src_name, size_t src_name_size)
return 0;
}
void Init()
{
Syscall::Register(SYSCALL_GETHOSTNAME, (void*) sys_gethostname);
Syscall::Register(SYSCALL_SETHOSTNAME, (void*) sys_sethostname);
}
} // namespace Hostname
} // namespace Sortix

View File

@ -1,36 +0,0 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2014.
This file is part of Sortix.
Sortix is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
Sortix is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
You should have received a copy of the GNU General Public License along with
Sortix. If not, see <http://www.gnu.org/licenses/>.
hostname.h
System calls for managing the hostname of the current system.
*******************************************************************************/
#ifndef SORTIX_HOSTNAME_H
#define SORTIX_HOSTNAME_H
namespace Sortix {
namespace Hostname {
void Init();
} // namespace Hostname
} // namespace Sortix
#endif

View File

@ -22,83 +22,69 @@
*******************************************************************************/
#include <sys/types.h>
#include <sortix/kernel/kernel.h>
#include <sortix/kernel/kthread.h>
#include <sortix/kernel/process.h>
#include <sortix/kernel/syscall.h>
#include "identity.h"
namespace Sortix {
namespace Identity {
static uid_t sys_getuid()
uid_t sys_getuid()
{
Process* process = CurrentProcess();
ScopedLock lock(&process->idlock);
return process->uid;
}
static int sys_setuid(uid_t uid)
int sys_setuid(uid_t uid)
{
Process* process = CurrentProcess();
ScopedLock lock(&process->idlock);
return process->uid = uid, 0;
}
static gid_t sys_getgid()
gid_t sys_getgid()
{
Process* process = CurrentProcess();
ScopedLock lock(&process->idlock);
return process->gid;
}
static int sys_setgid(gid_t gid)
int sys_setgid(gid_t gid)
{
Process* process = CurrentProcess();
ScopedLock lock(&process->idlock);
return process->gid = gid, 0;
}
static uid_t sys_geteuid()
uid_t sys_geteuid()
{
Process* process = CurrentProcess();
ScopedLock lock(&process->idlock);
return process->euid;
}
static int sys_seteuid(uid_t euid)
int sys_seteuid(uid_t euid)
{
Process* process = CurrentProcess();
ScopedLock lock(&process->idlock);
return process->euid = euid, 0;
}
static gid_t sys_getegid()
gid_t sys_getegid()
{
Process* process = CurrentProcess();
ScopedLock lock(&process->idlock);
return process->egid;
}
static int sys_setegid(gid_t egid)
int sys_setegid(gid_t egid)
{
Process* process = CurrentProcess();
ScopedLock lock(&process->idlock);
return process->egid = egid, 0;
}
void Init()
{
Syscall::Register(SYSCALL_GETUID, (void*) sys_getuid);
Syscall::Register(SYSCALL_GETGID, (void*) sys_getgid);
Syscall::Register(SYSCALL_SETUID, (void*) sys_setuid);
Syscall::Register(SYSCALL_SETGID, (void*) sys_setgid);
Syscall::Register(SYSCALL_GETEUID, (void*) sys_geteuid);
Syscall::Register(SYSCALL_GETEGID, (void*) sys_getegid);
Syscall::Register(SYSCALL_SETEUID, (void*) sys_seteuid);
Syscall::Register(SYSCALL_SETEGID, (void*) sys_setegid);
}
} // namespace Identity
} // namespace Sortix

View File

@ -1,36 +0,0 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2013.
This file is part of Sortix.
Sortix is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
Sortix is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
You should have received a copy of the GNU General Public License along with
Sortix. If not, see <http://www.gnu.org/licenses/>.
identity.h
System calls for managing user and group identities.
*******************************************************************************/
#ifndef SORTIX_IDENTITY_H
#define SORTIX_IDENTITY_H
namespace Sortix {
namespace Identity {
void Init();
} // namespace Identity
} // namespace Sortix
#endif

View File

@ -66,9 +66,6 @@ public:
Process();
~Process();
public:
static void Init();
public:
char* string_table;
size_t string_table_length;

View File

@ -1,31 +0,0 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2014.
This file is part of Sortix.
Sortix is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
Sortix is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
You should have received a copy of the GNU General Public License along with
Sortix. If not, see <http://www.gnu.org/licenses/>.
sortix/kernel/random.h
Kernel entropy gathering.
*******************************************************************************/
namespace Sortix {
namespace Random {
void Init();
} // namespace Random
} // namespace Sortix

View File

@ -25,17 +25,154 @@
#ifndef INCLUDE_SORTIX_KERNEL_SYSCALL_H
#define INCLUDE_SORTIX_KERNEL_SYSCALL_H
#include <stddef.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <stddef.h>
#include <stdint.h>
#include <sortix/dirent.h>
#include <sortix/exit.h>
#include <sortix/fork.h>
#include <sortix/itimerspec.h>
#include <sortix/poll.h>
#include <sortix/resource.h>
#include <sortix/sigaction.h>
#include <sortix/sigevent.h>
#include <sortix/sigset.h>
#include <sortix/stack.h>
#include <sortix/stat.h>
#include <sortix/statvfs.h>
#include <sortix/syscall.h>
#include <sortix/termios.h>
#include <sortix/timespec.h>
#include <sortix/tmns.h>
namespace Sortix {
namespace Syscall {
void Init();
void Register(size_t index, void* funcptr);
struct mmap_request;
int sys_accept4(int, void*, size_t*, int);
int sys_alarmns(const struct timespec*, struct timespec*);
int sys_bad_syscall(void);
int sys_bind(int, const void*, size_t);
int sys_clock_gettimeres(clockid_t, struct timespec*, struct timespec*);
int sys_clock_nanosleep(clockid_t, int, const struct timespec*, struct timespec*);
int sys_clock_settimeres(clockid_t, const struct timespec*, const struct timespec*);
int sys_close(int);
int sys_connect(int, const void*, size_t);
int sys_dispmsg_issue(void*, size_t);
int sys_dup(int);
int sys_dup2(int, int);
int sys_dup3(int, int, int);
int sys_execve(const char*, char* const [], char* const []);
int sys_exit_thread(int, int, const struct exit_thread*);
int sys_faccessat(int, const char*, int, int);
int sys_fchdir(int);
int sys_fchdirat(int, const char*);
int sys_fchmod(int, mode_t);
int sys_fchmodat(int, const char*, mode_t, int);
int sys_fchown(int, uid_t, gid_t);
int sys_fchownat(int, const char*, uid_t, gid_t, int);
int sys_fchroot(int);
int sys_fchrootat(int, const char*);
int sys_fcntl(int, int, uintptr_t);
int sys_fsm_fsbind(int, int, int);
int sys_fstat(int, struct stat*);
int sys_fstatat(int, const char*, struct stat*, int);
int sys_fstatvfs(int, struct statvfs*);
int sys_fstatvfsat(int, const char*, struct statvfs*, int);
int sys_fsync(int);
int sys_ftruncate(int, off_t);
int sys_futimens(int, const struct timespec [2]);
gid_t sys_getegid(void);
int sys_getentropy(void*, size_t);
uid_t sys_geteuid(void);
gid_t sys_getgid(void);
int sys_gethostname(char*, size_t);
size_t sys_getpagesize(void);
int sys_getpeername(int, struct sockaddr*, socklen_t*);
pid_t sys_getpgid(pid_t);
pid_t sys_getpid(void);
pid_t sys_getppid(void);
int sys_getpriority(int, id_t);
int sys_getsockname(int, struct sockaddr*, socklen_t*);
int sys_getsockopt(int, int, int, void*, size_t*);
int sys_gettermmode(int, unsigned*);
uid_t sys_getuid(void);
mode_t sys_getumask(void);
int sys_ioctl(int, int, void*);
int sys_isatty(int);
ssize_t sys_kernelinfo(const char*, char*, size_t);
int sys_kill(pid_t, int);
int sys_linkat(int, const char*, int, const char*, int);
off_t sys_lseek(int, off_t, int);
int sys_listen(int, int);
int sys_memstat(size_t*, size_t*);
int sys_mkdirat(int, const char*, mode_t);
int sys_mkpartition(int, off_t, off_t, int);
void* sys_mmap_wrapper(struct mmap_request*);
int sys_mprotect(const void*, size_t, int);
int sys_munmap(void*, size_t);
int sys_openat(int, const char*, int, mode_t);
int sys_pipe2(int [2], int);
int sys_ppoll(struct pollfd*, nfds_t, const struct timespec*, const sigset_t*);
ssize_t sys_pread(int, void*, size_t, off_t);
ssize_t sys_preadv(int, const struct iovec*, int, off_t);
int sys_prlimit(pid_t, int, const struct rlimit*, struct rlimit*);
ssize_t sys_pwrite(int, const void*, size_t, off_t);
ssize_t sys_pwritev(int, const struct iovec*, int, off_t);
int sys_raise(int);
uint64_t sys_rdmsr(uint32_t);
ssize_t sys_read(int, void*, size_t);
ssize_t sys_readdirents(int, struct kernel_dirent*, size_t);
ssize_t sys_readlinkat(int, const char*, char*, size_t);
ssize_t sys_readv(int, const struct iovec*, int);
ssize_t sys_recv(int, void*, size_t, int);
ssize_t sys_recvmsg(int, struct msghdr*, int);
int sys_renameat(int, const char*, int, const char*);
void* sys_sbrk(intptr_t);
int sys_sched_yield(void);
ssize_t sys_send(int, const void*, size_t, int);
ssize_t sys_sendmsg(int, const struct msghdr*, int);
int sys_setegid(gid_t);
int sys_seteuid(uid_t);
int sys_setgid(gid_t);
int sys_sethostname(const char*, size_t);
int sys_setpgid(pid_t, pid_t);
int sys_setpriority(int, id_t, int);
int sys_setsockopt(int, int, int, const void*, size_t);
int sys_settermmode(int, unsigned);
int sys_setuid(uid_t);
int sys_shutdown(int, int);
int sys_sigaction(int, const struct sigaction*, struct sigaction*);
int sys_sigaltstack(const stack_t*, stack_t*);
int sys_sigpending(sigset_t*);
int sys_sigprocmask(int, const sigset_t*, sigset_t*);
int sys_sigsuspend(const sigset_t*);
int sys_symlinkat(const char*, int, const char*);
ssize_t sys_tcgetblob(int, const char*, void*, size_t);
int sys_tcgetpgrp(int);
int sys_tcgetwincurpos(int, struct wincurpos*);
int sys_tcgetwinsize(int, struct winsize*);
ssize_t sys_tcsetblob(int, const char*, const void*, size_t);
int sys_tcsetpgrp(int, pid_t);
pid_t sys_tfork(int, struct tfork*);
int sys_timens(struct tmns*);
int sys_timer_create(clockid_t clockid, struct sigevent*, timer_t*);
int sys_timer_delete(timer_t);
int sys_timer_getoverrun(timer_t);
int sys_timer_gettime(timer_t, struct itimerspec*);
int sys_timer_settime(timer_t, int, const struct itimerspec*, struct itimerspec*);
int sys_truncateat(int, const char*, off_t);
mode_t sys_umask(mode_t);
int sys_unlinkat(int, const char*, int);
int sys_utimensat(int, const char*, const struct timespec [2], int);
pid_t sys_waitpid(pid_t, int*, int);
ssize_t sys_write(int, const void*, size_t);
ssize_t sys_writev(int, const struct iovec*, int);
uint64_t sys_wrmsr(uint32_t, uint64_t);
} // namespace Syscall
} // namespace Sortix
#endif

View File

@ -59,9 +59,6 @@ Thread* RunKernelThread(void (*entry)(void*), void* user, size_t stacksize = 0);
class Thread
{
public:
static void Init();
public:
Thread();
~Thread();

View File

@ -41,10 +41,6 @@ struct UserTimer
struct sigevent event;
Process* process;
timer_t timerid;
public:
static void Init();
};
} // namespace Sortix

View File

@ -55,7 +55,7 @@
#define SYSCALL_UNLINK 27 /* OBSOLETE */
#define SYSCALL_REGISTER_ERRNO 28 /* OBSOLETE */
#define SYSCALL_REGISTER_SIGNAL_HANDLER 29 /* OBSOLETE */
#define SYSCALL_SIGRETURN /* OBSOLETE */
#define SYSCALL_SIGRETURN 30 /* OBSOLETE */
#define SYSCALL_KILL 31
#define SYSCALL_MEMSTAT 32
#define SYSCALL_ISATTY 33

View File

@ -51,11 +51,9 @@
#include <sortix/kernel/thread.h>
#include <sortix/kernel/vnode.h>
#include "io.h"
#include "partition.h"
namespace Sortix {
namespace IO {
static Ref<Descriptor> PrepareLookup(const char** path, int dirfd = AT_FDCWD)
{
@ -66,7 +64,7 @@ static Ref<Descriptor> PrepareLookup(const char** path, int dirfd = AT_FDCWD)
return CurrentProcess()->GetDescriptor(dirfd);
}
static ssize_t sys_write(int fd, const void* buffer, size_t count)
ssize_t sys_write(int fd, const void* buffer, size_t count)
{
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
if ( !desc )
@ -76,7 +74,7 @@ static ssize_t sys_write(int fd, const void* buffer, size_t count)
return ret;
}
static ssize_t sys_pwrite(int fd, const void* buffer, size_t count, off_t off)
ssize_t sys_pwrite(int fd, const void* buffer, size_t count, off_t off)
{
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
if ( !desc )
@ -86,7 +84,7 @@ static ssize_t sys_pwrite(int fd, const void* buffer, size_t count, off_t off)
return ret;
}
static ssize_t sys_read(int fd, void* buffer, size_t count)
ssize_t sys_read(int fd, void* buffer, size_t count)
{
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
if ( !desc )
@ -96,7 +94,7 @@ static ssize_t sys_read(int fd, void* buffer, size_t count)
return ret;
}
static ssize_t sys_pread(int fd, void* buffer, size_t count, off_t off)
ssize_t sys_pread(int fd, void* buffer, size_t count, off_t off)
{
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
if ( !desc )
@ -106,7 +104,7 @@ static ssize_t sys_pread(int fd, void* buffer, size_t count, off_t off)
return ret;
}
static off_t sys_lseek(int fd, off_t offset, int whence)
off_t sys_lseek(int fd, off_t offset, int whence)
{
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
if ( !desc )
@ -116,7 +114,7 @@ static off_t sys_lseek(int fd, off_t offset, int whence)
return ret;
}
static int sys_close(int fd)
int sys_close(int fd)
{
ioctx_t ctx; SetupUserIOCtx(&ctx);
Ref<DescriptorTable> dtable = CurrentProcess()->GetDTable();
@ -127,14 +125,14 @@ static int sys_close(int fd)
return desc->sync(&ctx);
}
static int sys_dup(int fd)
int sys_dup(int fd)
{
Ref<DescriptorTable> dtable = CurrentProcess()->GetDTable();
Ref<Descriptor> desc = dtable->Get(fd);
return dtable->Allocate(desc, 0);
}
static int sys_dup3(int oldfd, int newfd, int flags)
int sys_dup3(int oldfd, int newfd, int flags)
{
if ( flags & ~(O_CLOEXEC | O_CLOFORK) )
return errno = EINVAL, -1;
@ -145,7 +143,7 @@ static int sys_dup3(int oldfd, int newfd, int flags)
return dtable->Copy(oldfd, newfd, fd_flags);
}
static int sys_dup2(int oldfd, int newfd)
int sys_dup2(int oldfd, int newfd)
{
if ( oldfd < 0 || newfd < 0 )
return errno = EINVAL, -1;
@ -157,7 +155,7 @@ static int sys_dup2(int oldfd, int newfd)
// TODO: If this function fails the file may still have been created. Does a
// standard prohibit this and is that the wrong thing?
static int sys_openat(int dirfd, const char* path, int flags, mode_t mode)
int sys_openat(int dirfd, const char* path, int flags, mode_t mode)
{
char* pathcopy = GetStringFromUser(path);
if ( !pathcopy )
@ -180,7 +178,7 @@ static int sys_openat(int dirfd, const char* path, int flags, mode_t mode)
}
// TODO: This is a hack! Stat the file in some manner and check permissions.
static int sys_faccessat(int dirfd, const char* path, int /*mode*/, int flags)
int sys_faccessat(int dirfd, const char* path, int /*mode*/, int flags)
{
if ( flags & ~(AT_SYMLINK_NOFOLLOW) )
return errno = EINVAL, -1;
@ -197,7 +195,7 @@ static int sys_faccessat(int dirfd, const char* path, int /*mode*/, int flags)
return desc ? 0 : -1;
}
static int sys_unlinkat(int dirfd, const char* path, int flags)
int sys_unlinkat(int dirfd, const char* path, int flags)
{
if ( !(flags & (AT_REMOVEFILE | AT_REMOVEDIR)) )
flags |= AT_REMOVEFILE;
@ -217,7 +215,7 @@ static int sys_unlinkat(int dirfd, const char* path, int flags)
return ret;
}
static int sys_mkdirat(int dirfd, const char* path, mode_t mode)
int sys_mkdirat(int dirfd, const char* path, mode_t mode)
{
char* pathcopy = GetStringFromUser(path);
if ( !pathcopy )
@ -231,7 +229,7 @@ static int sys_mkdirat(int dirfd, const char* path, mode_t mode)
return ret;
}
static int sys_truncateat(int dirfd, const char* path, off_t length)
int sys_truncateat(int dirfd, const char* path, off_t length)
{
char* pathcopy = GetStringFromUser(path);
if ( !pathcopy )
@ -247,7 +245,7 @@ static int sys_truncateat(int dirfd, const char* path, off_t length)
return desc->truncate(&ctx, length);
}
static int sys_ftruncate(int fd, off_t length)
int sys_ftruncate(int fd, off_t length)
{
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
if ( !desc )
@ -256,7 +254,7 @@ static int sys_ftruncate(int fd, off_t length)
return desc->truncate(&ctx, length);
}
static int sys_fstatat(int dirfd, const char* path, struct stat* st, int flags)
int sys_fstatat(int dirfd, const char* path, struct stat* st, int flags)
{
if ( flags & ~(AT_SYMLINK_NOFOLLOW) )
return errno = EINVAL;
@ -275,7 +273,7 @@ static int sys_fstatat(int dirfd, const char* path, struct stat* st, int flags)
return desc->stat(&ctx, st);
}
static int sys_fstat(int fd, struct stat* st)
int sys_fstat(int fd, struct stat* st)
{
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
if ( !desc )
@ -284,7 +282,7 @@ static int sys_fstat(int fd, struct stat* st)
return desc->stat(&ctx, st);
}
static int sys_fstatvfs(int fd, struct statvfs* stvfs)
int sys_fstatvfs(int fd, struct statvfs* stvfs)
{
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
if ( !desc )
@ -293,7 +291,7 @@ static int sys_fstatvfs(int fd, struct statvfs* stvfs)
return desc->statvfs(&ctx, stvfs);
}
static int sys_fstatvfsat(int dirfd, const char* path, struct statvfs* stvfs, int flags)
int sys_fstatvfsat(int dirfd, const char* path, struct statvfs* stvfs, int flags)
{
if ( flags & ~(AT_SYMLINK_NOFOLLOW) )
return errno = EINVAL;
@ -312,7 +310,7 @@ static int sys_fstatvfsat(int dirfd, const char* path, struct statvfs* stvfs, in
return desc->statvfs(&ctx, stvfs);
}
static int sys_fcntl(int fd, int cmd, uintptr_t arg)
int sys_fcntl(int fd, int cmd, uintptr_t arg)
{
// Operations on the descriptor table.
Ref<DescriptorTable> dtable = CurrentProcess()->GetDTable();
@ -344,7 +342,7 @@ static int sys_fcntl(int fd, int cmd, uintptr_t arg)
return errno = EINVAL, -1;
}
static int sys_ioctl(int fd, int cmd, void* /*ptr*/)
int sys_ioctl(int fd, int cmd, void* /*ptr*/)
{
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
if ( !desc )
@ -359,8 +357,7 @@ static int sys_ioctl(int fd, int cmd, void* /*ptr*/)
return ret;
}
static ssize_t sys_readdirents(int fd, kernel_dirent* dirent, size_t size/*,
size_t maxcount*/)
ssize_t sys_readdirents(int fd, struct kernel_dirent* dirent, size_t size)
{
if ( size < sizeof(kernel_dirent) ) { errno = EINVAL; return -1; }
if ( SSIZE_MAX < size )
@ -372,7 +369,7 @@ static ssize_t sys_readdirents(int fd, kernel_dirent* dirent, size_t size/*,
return desc->readdirents(&ctx, dirent, size, 1 /*maxcount*/);
}
static int sys_fchdir(int fd)
int sys_fchdir(int fd)
{
Process* process = CurrentProcess();
Ref<Descriptor> desc = process->GetDescriptor(fd);
@ -384,7 +381,7 @@ static int sys_fchdir(int fd)
return 0;
}
static int sys_fchdirat(int dirfd, const char* path)
int sys_fchdirat(int dirfd, const char* path)
{
char* pathcopy = GetStringFromUser(path);
if ( !pathcopy )
@ -401,7 +398,7 @@ static int sys_fchdirat(int dirfd, const char* path)
return 0;
}
static int sys_fchroot(int fd)
int sys_fchroot(int fd)
{
Process* process = CurrentProcess();
Ref<Descriptor> desc = process->GetDescriptor(fd);
@ -413,7 +410,7 @@ static int sys_fchroot(int fd)
return 0;
}
static int sys_fchrootat(int dirfd, const char* path)
int sys_fchrootat(int dirfd, const char* path)
{
char* pathcopy = GetStringFromUser(path);
if ( !pathcopy )
@ -430,7 +427,7 @@ static int sys_fchrootat(int dirfd, const char* path)
return 0;
}
static int sys_fchown(int fd, uid_t owner, gid_t group)
int sys_fchown(int fd, uid_t owner, gid_t group)
{
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
if ( !desc )
@ -439,7 +436,7 @@ static int sys_fchown(int fd, uid_t owner, gid_t group)
return desc->chown(&ctx, owner, group);
}
static int sys_fchownat(int dirfd, const char* path, uid_t owner, gid_t group, int flags)
int sys_fchownat(int dirfd, const char* path, uid_t owner, gid_t group, int flags)
{
if ( flags & ~(AT_SYMLINK_NOFOLLOW) )
return errno = EINVAL, -1;
@ -459,7 +456,7 @@ static int sys_fchownat(int dirfd, const char* path, uid_t owner, gid_t group, i
return desc->chown(&ctx, owner, group);
}
static int sys_fchmod(int fd, mode_t mode)
int sys_fchmod(int fd, mode_t mode)
{
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
if ( !desc )
@ -468,7 +465,7 @@ static int sys_fchmod(int fd, mode_t mode)
return desc->chmod(&ctx, mode);
}
static int sys_fchmodat(int dirfd, const char* path, mode_t mode, int flags)
int sys_fchmodat(int dirfd, const char* path, mode_t mode, int flags)
{
if ( flags & ~(AT_SYMLINK_NOFOLLOW) )
return errno = EINVAL, -1;
@ -488,7 +485,7 @@ static int sys_fchmodat(int dirfd, const char* path, mode_t mode, int flags)
return desc->chmod(&ctx, mode);
}
static int sys_futimens(int fd, const struct timespec user_times[2])
int sys_futimens(int fd, const struct timespec user_times[2])
{
struct timespec times[2];
if ( !CopyFromUser(times, user_times, sizeof(times)) )
@ -500,8 +497,8 @@ static int sys_futimens(int fd, const struct timespec user_times[2])
return desc->utimens(&ctx, &times[0], NULL, &times[1]);
}
static int sys_utimensat(int dirfd, const char* path,
const struct timespec user_times[2], int flags)
int sys_utimensat(int dirfd, const char* path,
const struct timespec user_times[2], int flags)
{
if ( flags & ~(AT_SYMLINK_NOFOLLOW) )
return errno = EINVAL, -1;
@ -524,9 +521,9 @@ static int sys_utimensat(int dirfd, const char* path,
return desc->utimens(&ctx, &times[0], NULL, &times[1]);
}
static int sys_linkat(int olddirfd, const char* oldpath,
int newdirfd, const char* newpath,
int flags)
int sys_linkat(int olddirfd, const char* oldpath,
int newdirfd, const char* newpath,
int flags)
{
if ( flags & ~(AT_SYMLINK_FOLLOW) )
return errno = EINVAL, -1;
@ -563,7 +560,7 @@ static int sys_linkat(int olddirfd, const char* oldpath,
return ret;
}
static int sys_symlinkat(const char* oldpath, int newdirfd, const char* newpath)
int sys_symlinkat(const char* oldpath, int newdirfd, const char* newpath)
{
ioctx_t ctx; SetupUserIOCtx(&ctx);
@ -587,7 +584,7 @@ static int sys_symlinkat(const char* oldpath, int newdirfd, const char* newpath)
return ret;
}
static int sys_settermmode(int fd, unsigned mode)
int sys_settermmode(int fd, unsigned mode)
{
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
if ( !desc )
@ -596,7 +593,7 @@ static int sys_settermmode(int fd, unsigned mode)
return desc->settermmode(&ctx, mode);
}
static int sys_gettermmode(int fd, unsigned* mode)
int sys_gettermmode(int fd, unsigned* mode)
{
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
if ( !desc )
@ -605,7 +602,7 @@ static int sys_gettermmode(int fd, unsigned* mode)
return desc->gettermmode(&ctx, mode);
}
static int sys_isatty(int fd)
int sys_isatty(int fd)
{
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
if ( !desc )
@ -614,7 +611,7 @@ static int sys_isatty(int fd)
return desc->isatty(&ctx);
}
static int sys_tcgetwincurpos(int fd, struct wincurpos* wcp)
int sys_tcgetwincurpos(int fd, struct wincurpos* wcp)
{
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
if ( !desc )
@ -624,7 +621,7 @@ static int sys_tcgetwincurpos(int fd, struct wincurpos* wcp)
}
static int sys_tcgetwinsize(int fd, struct winsize* ws)
int sys_tcgetwinsize(int fd, struct winsize* ws)
{
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
if ( !desc )
@ -633,7 +630,7 @@ static int sys_tcgetwinsize(int fd, struct winsize* ws)
return desc->tcgetwinsize(&ctx, ws);
}
static int sys_tcsetpgrp(int fd, pid_t pgid)
int sys_tcsetpgrp(int fd, pid_t pgid)
{
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
if ( !desc )
@ -642,7 +639,7 @@ static int sys_tcsetpgrp(int fd, pid_t pgid)
return desc->tcsetpgrp(&ctx, pgid);
}
static int sys_tcgetpgrp(int fd)
int sys_tcgetpgrp(int fd)
{
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
if ( !desc )
@ -668,8 +665,8 @@ static int sys_renameat_inner(int olddirfd, const char* oldpath,
return newdir->rename_here(&ctx, olddir, oldrelpath, newrelpath);
}
static int sys_renameat(int olddirfd, const char* oldpath,
int newdirfd, const char* newpath)
int sys_renameat(int olddirfd, const char* oldpath,
int newdirfd, const char* newpath)
{
char* oldpathcopy = GetStringFromUser(oldpath);
if ( !oldpathcopy ) return -1;
@ -683,7 +680,7 @@ static int sys_renameat(int olddirfd, const char* oldpath,
// TODO: This should probably be moved into user-space. It'd be nice if
// user-space could just open the symlink and read/write it like a regular file.
static ssize_t sys_readlinkat(int dirfd, const char* path, char* buf, size_t size)
ssize_t sys_readlinkat(int dirfd, const char* path, char* buf, size_t size)
{
char* pathcopy = GetStringFromUser(path);
if ( !pathcopy )
@ -699,7 +696,7 @@ static ssize_t sys_readlinkat(int dirfd, const char* path, char* buf, size_t siz
return (int) desc->readlink(&ctx, buf, size);
}
static int sys_fsync(int fd)
int sys_fsync(int fd)
{
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
if ( !desc )
@ -708,7 +705,7 @@ static int sys_fsync(int fd)
return desc->sync(&ctx);
}
static int sys_accept4(int fd, void* addr, size_t* addrlen, int flags)
int sys_accept4(int fd, void* addr, size_t* addrlen, int flags)
{
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
if ( !desc )
@ -726,7 +723,7 @@ static int sys_accept4(int fd, void* addr, size_t* addrlen, int flags)
return CurrentProcess()->GetDTable()->Allocate(conn, fdflags);
}
static int sys_bind(int fd, const void* addr, size_t addrlen)
int sys_bind(int fd, const void* addr, size_t addrlen)
{
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
if ( !desc )
@ -735,7 +732,7 @@ static int sys_bind(int fd, const void* addr, size_t addrlen)
return desc->bind(&ctx, (const uint8_t*) addr, addrlen);
}
static int sys_connect(int fd, const void* addr, size_t addrlen)
int sys_connect(int fd, const void* addr, size_t addrlen)
{
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
if ( !desc )
@ -744,7 +741,7 @@ static int sys_connect(int fd, const void* addr, size_t addrlen)
return desc->connect(&ctx, (const uint8_t*) addr, addrlen);
}
static int sys_listen(int fd, int backlog)
int sys_listen(int fd, int backlog)
{
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
if ( !desc )
@ -753,7 +750,7 @@ static int sys_listen(int fd, int backlog)
return desc->listen(&ctx, backlog);
}
static ssize_t sys_recv(int fd, void* buffer, size_t count, int flags)
ssize_t sys_recv(int fd, void* buffer, size_t count, int flags)
{
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
if ( !desc )
@ -762,7 +759,7 @@ static ssize_t sys_recv(int fd, void* buffer, size_t count, int flags)
return desc->recv(&ctx, (uint8_t*) buffer, count, flags);
}
static ssize_t sys_send(int fd, const void* buffer, size_t count, int flags)
ssize_t sys_send(int fd, const void* buffer, size_t count, int flags)
{
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
if ( !desc )
@ -792,7 +789,7 @@ static struct iovec* FetchIOV(const struct iovec* user_iov, int iovcnt)
return ret;
}
static ssize_t sys_readv(int fd, const struct iovec* user_iov, int iovcnt)
ssize_t sys_readv(int fd, const struct iovec* user_iov, int iovcnt)
{
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
if ( !desc )
@ -827,8 +824,7 @@ static ssize_t sys_readv(int fd, const struct iovec* user_iov, int iovcnt)
return so_far;
}
static ssize_t sys_preadv(int fd, const struct iovec* user_iov, int iovcnt,
off_t offset)
ssize_t sys_preadv(int fd, const struct iovec* user_iov, int iovcnt, off_t offset)
{
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
if ( !desc )
@ -863,7 +859,7 @@ static ssize_t sys_preadv(int fd, const struct iovec* user_iov, int iovcnt,
return so_far;
}
static ssize_t sys_writev(int fd, const struct iovec* user_iov, int iovcnt)
ssize_t sys_writev(int fd, const struct iovec* user_iov, int iovcnt)
{
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
if ( !desc )
@ -898,8 +894,7 @@ static ssize_t sys_writev(int fd, const struct iovec* user_iov, int iovcnt)
return so_far;
}
static ssize_t sys_pwritev(int fd, const struct iovec* user_iov, int iovcnt,
off_t offset)
ssize_t sys_pwritev(int fd, const struct iovec* user_iov, int iovcnt, off_t offset)
{
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
if ( !desc )
@ -934,7 +929,7 @@ static ssize_t sys_pwritev(int fd, const struct iovec* user_iov, int iovcnt,
return so_far;
}
static int sys_mkpartition(int fd, off_t start, off_t length, int flags)
int sys_mkpartition(int fd, off_t start, off_t length, int flags)
{
int fdflags = 0;
if ( flags & O_CLOEXEC ) fdflags |= FD_CLOEXEC;
@ -966,7 +961,7 @@ static int sys_mkpartition(int fd, off_t start, off_t length, int flags)
return CurrentProcess()->GetDTable()->Allocate(partition_desc, fdflags);
}
static ssize_t sys_sendmsg(int fd, const struct msghdr* user_msg, int flags)
ssize_t sys_sendmsg(int fd, const struct msghdr* user_msg, int flags)
{
struct msghdr msg;
if ( !CopyFromUser(&msg, user_msg, sizeof(msg)) )
@ -981,7 +976,7 @@ static ssize_t sys_sendmsg(int fd, const struct msghdr* user_msg, int flags)
return sys_writev(fd, msg.msg_iov, msg.msg_iovlen);
}
static ssize_t sys_recvmsg(int fd, struct msghdr* user_msg, int flags)
ssize_t sys_recvmsg(int fd, struct msghdr* user_msg, int flags)
{
struct msghdr msg;
if ( !CopyFromUser(&msg, user_msg, sizeof(msg)) )
@ -1007,8 +1002,8 @@ static ssize_t sys_recvmsg(int fd, struct msghdr* user_msg, int flags)
return result;
}
static int sys_getsockopt(int fd, int level, int option_name,
void* option_value, size_t* option_size_ptr)
int sys_getsockopt(int fd, int level, int option_name,
void* option_value, size_t* option_size_ptr)
{
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
if ( !desc )
@ -1018,8 +1013,8 @@ static int sys_getsockopt(int fd, int level, int option_name,
return desc->getsockopt(&ctx, level, option_name, option_value, option_size_ptr);
}
static int sys_setsockopt(int fd, int level, int option_name,
const void* option_value, size_t option_size)
int sys_setsockopt(int fd, int level, int option_name,
const void* option_value, size_t option_size)
{
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
if ( !desc )
@ -1029,7 +1024,7 @@ static int sys_setsockopt(int fd, int level, int option_name,
return desc->setsockopt(&ctx, level, option_name, option_value, option_size);
}
static ssize_t sys_tcgetblob(int fd, const char* name, void* buffer, size_t count)
ssize_t sys_tcgetblob(int fd, const char* name, void* buffer, size_t count)
{
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
if ( !desc )
@ -1045,7 +1040,7 @@ static ssize_t sys_tcgetblob(int fd, const char* name, void* buffer, size_t coun
return result;
}
static ssize_t sys_tcsetblob(int fd, const char* name, const void* buffer, size_t count)
ssize_t sys_tcsetblob(int fd, const char* name, const void* buffer, size_t count)
{
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
if ( !desc )
@ -1061,7 +1056,7 @@ static ssize_t sys_tcsetblob(int fd, const char* name, const void* buffer, size_
return result;
}
static int sys_getpeername(int fd, struct sockaddr* addr, socklen_t* addrsize)
int sys_getpeername(int fd, struct sockaddr* addr, socklen_t* addrsize)
{
(void) fd;
(void) addr;
@ -1069,7 +1064,7 @@ static int sys_getpeername(int fd, struct sockaddr* addr, socklen_t* addrsize)
return errno = ENOSYS, -1;
}
static int sys_getsockname(int fd, struct sockaddr* addr, socklen_t* addrsize)
int sys_getsockname(int fd, struct sockaddr* addr, socklen_t* addrsize)
{
(void) fd;
(void) addr;
@ -1077,80 +1072,11 @@ static int sys_getsockname(int fd, struct sockaddr* addr, socklen_t* addrsize)
return errno = ENOSYS, -1;
}
static int sys_shutdown(int fd, int how)
int sys_shutdown(int fd, int how)
{
(void) fd;
(void) how;
return errno = ENOSYS, -1;
}
void Init()
{
Syscall::Register(SYSCALL_ACCEPT4, (void*) sys_accept4);
Syscall::Register(SYSCALL_BIND, (void*) sys_bind);
Syscall::Register(SYSCALL_CLOSE, (void*) sys_close);
Syscall::Register(SYSCALL_CONNECT, (void*) sys_connect);
Syscall::Register(SYSCALL_DUP2, (void*) sys_dup2);
Syscall::Register(SYSCALL_DUP3, (void*) sys_dup3);
Syscall::Register(SYSCALL_DUP, (void*) sys_dup);
Syscall::Register(SYSCALL_FACCESSAT, (void*) sys_faccessat);
Syscall::Register(SYSCALL_FCHDIRAT, (void*) sys_fchdirat);
Syscall::Register(SYSCALL_FCHDIR, (void*) sys_fchdir);
Syscall::Register(SYSCALL_FCHMODAT, (void*) sys_fchmodat);
Syscall::Register(SYSCALL_FCHMOD, (void*) sys_fchmod);
Syscall::Register(SYSCALL_FCHOWNAT, (void*) sys_fchownat);
Syscall::Register(SYSCALL_FCHOWN, (void*) sys_fchown);
Syscall::Register(SYSCALL_FCHROOTAT, (void*) sys_fchrootat);
Syscall::Register(SYSCALL_FCHROOT, (void*) sys_fchroot);
Syscall::Register(SYSCALL_FCNTL, (void*) sys_fcntl);
Syscall::Register(SYSCALL_FSTATAT, (void*) sys_fstatat);
Syscall::Register(SYSCALL_FSTATVFSAT, (void*) sys_fstatvfsat);
Syscall::Register(SYSCALL_FSTATVFS, (void*) sys_fstatvfs);
Syscall::Register(SYSCALL_FSTAT, (void*) sys_fstat);
Syscall::Register(SYSCALL_FSYNC, (void*) sys_fsync);
Syscall::Register(SYSCALL_FTRUNCATE, (void*) sys_ftruncate);
Syscall::Register(SYSCALL_FUTIMENS, (void*) sys_futimens);
Syscall::Register(SYSCALL_GETPEERNAME, (void*) sys_getpeername);
Syscall::Register(SYSCALL_GETSOCKNAME, (void*) sys_getsockname);
Syscall::Register(SYSCALL_GETSOCKOPT, (void*) sys_getsockopt);
Syscall::Register(SYSCALL_GETTERMMODE, (void*) sys_gettermmode);
Syscall::Register(SYSCALL_IOCTL, (void*) sys_ioctl);
Syscall::Register(SYSCALL_ISATTY, (void*) sys_isatty);
Syscall::Register(SYSCALL_LINKAT, (void*) sys_linkat);
Syscall::Register(SYSCALL_LISTEN, (void*) sys_listen);
Syscall::Register(SYSCALL_LSEEK, (void*) sys_lseek);
Syscall::Register(SYSCALL_MKDIRAT, (void*) sys_mkdirat);
Syscall::Register(SYSCALL_MKPARTITION, (void*) sys_mkpartition);
Syscall::Register(SYSCALL_OPENAT, (void*) sys_openat);
Syscall::Register(SYSCALL_PREAD, (void*) sys_pread);
Syscall::Register(SYSCALL_PREADV, (void*) sys_preadv);
Syscall::Register(SYSCALL_PWRITE, (void*) sys_pwrite);
Syscall::Register(SYSCALL_PWRITEV, (void*) sys_pwritev);
Syscall::Register(SYSCALL_READDIRENTS, (void*) sys_readdirents);
Syscall::Register(SYSCALL_READLINKAT, (void*) sys_readlinkat);
Syscall::Register(SYSCALL_READ, (void*) sys_read);
Syscall::Register(SYSCALL_READV, (void*) sys_readv);
Syscall::Register(SYSCALL_RECVMSG, (void*) sys_recvmsg);
Syscall::Register(SYSCALL_RECV, (void*) sys_recv);
Syscall::Register(SYSCALL_RENAMEAT, (void*) sys_renameat);
Syscall::Register(SYSCALL_SENDMSG, (void*) sys_sendmsg);
Syscall::Register(SYSCALL_SEND, (void*) sys_send);
Syscall::Register(SYSCALL_SETSOCKOPT, (void*) sys_setsockopt);
Syscall::Register(SYSCALL_SETTERMMODE, (void*) sys_settermmode);
Syscall::Register(SYSCALL_SHUTDOWN, (void*) sys_shutdown);
Syscall::Register(SYSCALL_SYMLINKAT, (void*) sys_symlinkat);
Syscall::Register(SYSCALL_TCGETBLOB, (void*) sys_tcgetblob);
Syscall::Register(SYSCALL_TCGETPGRP, (void*) sys_tcgetpgrp);
Syscall::Register(SYSCALL_TCGETWINCURPOS, (void*) sys_tcgetwincurpos);
Syscall::Register(SYSCALL_TCGETWINSIZE, (void*) sys_tcgetwinsize);
Syscall::Register(SYSCALL_TCSETBLOB, (void*) sys_tcsetblob);
Syscall::Register(SYSCALL_TCSETPGRP, (void*) sys_tcsetpgrp);
Syscall::Register(SYSCALL_TRUNCATEAT, (void*) sys_truncateat);
Syscall::Register(SYSCALL_UNLINKAT, (void*) sys_unlinkat);
Syscall::Register(SYSCALL_UTIMENSAT, (void*) sys_utimensat);
Syscall::Register(SYSCALL_WRITE, (void*) sys_write);
Syscall::Register(SYSCALL_WRITEV, (void*) sys_writev);
}
} // namespace IO
} // namespace Sortix

View File

@ -1,36 +0,0 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
This file is part of Sortix.
Sortix is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
Sortix is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
You should have received a copy of the GNU General Public License along with
Sortix. If not, see <http://www.gnu.org/licenses/>.
io.h
Provides system calls for input and output.
*******************************************************************************/
#ifndef SORTIX_IO_H
#define SORTIX_IO_H
namespace Sortix {
namespace IO {
void Init();
} // namespace IO
} // namespace Sortix
#endif

View File

@ -54,13 +54,11 @@
#include <sortix/kernel/pci.h>
#include <sortix/kernel/process.h>
#include <sortix/kernel/ptable.h>
#include <sortix/kernel/random.h>
#include <sortix/kernel/refcount.h>
#include <sortix/kernel/scheduler.h>
#include <sortix/kernel/signal.h>
#include <sortix/kernel/string.h>
#include <sortix/kernel/symbol.h>
#include <sortix/kernel/syscall.h>
#include <sortix/kernel/textbuffer.h>
#include <sortix/kernel/thread.h>
#include <sortix/kernel/time.h>
@ -69,7 +67,6 @@
#include <sortix/kernel/vnode.h>
#include <sortix/kernel/worker.h>
#include "alarm.h"
#include "ata.h"
#include "com.h"
#include "elf.h"
@ -79,19 +76,13 @@
#include "fs/user.h"
#include "fs/zero.h"
#include "gpu/bga/bga.h"
#include "hostname.h"
#include "identity.h"
#include "initrd.h"
#include "io.h"
#include "kb/layout/us.h"
#include "kb/ps2.h"
#include "kernelinfo.h"
#include "logterminal.h"
#include "multiboot.h"
#include "net/fs.h"
#include "pipe.h"
#include "poll.h"
#include "resource.h"
#include "textterminal.h"
#include "uart.h"
#include "vga.h"
@ -101,7 +92,6 @@
#include "x86-family/cmos.h"
#include "x86-family/float.h"
#include "x86-family/gdt.h"
#include "x86-family/x86-family.h"
#endif
// Keep the stack size aligned with $CPU/base.s
@ -200,9 +190,6 @@ extern "C" void KernelInit(unsigned long magic, multiboot_info_t* bootinfo)
// TODO: Call global constructors using the _init function.
// Initialize system calls.
Syscall::Init();
// Detect and initialize any serial COM ports in the system.
COM::EarlyInit();
@ -299,9 +286,6 @@ extern "C" void KernelInit(unsigned long magic, multiboot_info_t* bootinfo)
// Initialize the interrupt handler table and enable interrupts.
Interrupt::Init();
// Initialize entropy gathering.
Random::Init();
// Load the kernel symbols if provided by the bootloader.
do if ( bootinfo->flags & MULTIBOOT_INFO_ELF_SHDR )
{
@ -417,18 +401,9 @@ extern "C" void KernelInit(unsigned long magic, multiboot_info_t* bootinfo)
// Stage 2. Transition to Multithreaded Environment
//
// Initialize CPU system calls.
CPU::Init();
// Initialize the clocks.
Time::Init();
// Initialize the process system.
Process::Init();
// Initialize the thread system.
Thread::Init();
// Initialize Unix Signals.
Signal::Init();
@ -611,33 +586,6 @@ static void BootThread(void* /*user*/)
// Initialize the VGA driver.
VGA::Init("/dev", slashdev);
// Initialize the identity system calls.
Identity::Init();
// Initialize the hostname system calls.
Hostname::Init();
// Initialize the IO system.
IO::Init();
// Initialize the pipe system.
Pipe::Init();
// Initialize poll system call.
Poll::Init();
// Initialize per-process timers.
UserTimer::Init();
// Initialize per-process alarm timer.
Alarm::Init();
// Initialize the kernel information query syscall.
Info::Init();
// Initialize resource system calls.
Resource::Init();
// Initialize the Video Driver framework.
Video::Init(textbufhandle);

View File

@ -29,16 +29,13 @@
#include <sortix/kernel/kernel.h>
#include <sortix/kernel/syscall.h>
#include "kernelinfo.h"
#ifndef VERSIONSTR
#define VERSIONSTR "unknown"
#endif
namespace Sortix {
namespace Info {
const char* KernelInfo(const char* req)
static const char* KernelInfo(const char* req)
{
if ( strcmp(req, "name") == 0 ) { return BRAND_KERNEL_NAME; }
if ( strcmp(req, "version") == 0 ) { return VERSIONSTR; }
@ -47,7 +44,7 @@ const char* KernelInfo(const char* req)
return NULL;
}
static ssize_t sys_kernelinfo(const char* req, char* resp, size_t resplen)
ssize_t sys_kernelinfo(const char* req, char* resp, size_t resplen)
{
const char* str = KernelInfo(req);
if ( !str )
@ -60,10 +57,4 @@ static ssize_t sys_kernelinfo(const char* req, char* resp, size_t resplen)
return 0;
}
void Init()
{
Syscall::Register(SYSCALL_KERNELINFO, (void*) sys_kernelinfo);
}
} // namespace Info
} // namespace Sortix

View File

@ -1,37 +0,0 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2012.
This file is part of Sortix.
Sortix is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
Sortix is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
You should have received a copy of the GNU General Public License along with
Sortix. If not, see <http://www.gnu.org/licenses/>.
kernelinfo.h
Lets user-space query information about the kernel.
********************************************************************************/
#ifndef SORTIX_KERNELINFO_H
#define SORTIX_KERNELINFO_H
namespace Sortix {
namespace Info {
const char* KernelInfo(const char* req);
void Init();
} // namespace Version
} // namespace Sortix
#endif

View File

@ -43,13 +43,12 @@
#include <sortix/kernel/syscall.h>
namespace Sortix {
namespace Memory {
static int sys_memstat(size_t* memused, size_t* memtotal)
int sys_memstat(size_t* memused, size_t* memtotal)
{
size_t used;
size_t total;
Statistics(&used, &total);
Memory::Statistics(&used, &total);
if ( memused && !CopyToUser(memused, &used, sizeof(used)) )
return -1;
if ( memtotal && !CopyToUser(memtotal, &total, sizeof(total)) )
@ -57,6 +56,11 @@ static int sys_memstat(size_t* memused, size_t* memtotal)
return 0;
}
} // namespace Sortix
namespace Sortix {
namespace Memory {
void UnmapMemory(Process* process, uintptr_t addr, size_t size)
{
// process->segment_lock is held.
@ -253,6 +257,11 @@ bool MapMemory(Process* process, uintptr_t addr, size_t size, int prot)
return true;
}
} // namespace Memory
} // namespace Sortix
namespace Sortix {
const int USER_SETTABLE_PROT = PROT_USER | PROT_HEAP;
const int UNDERSTOOD_MMAP_FLAGS = MAP_SHARED |
MAP_PRIVATE |
@ -338,7 +347,7 @@ void* sys_mmap(void* addr_ptr, size_t size, int prot, int flags, int fd,
new_segment.prot = prot | PROT_KREAD | PROT_KWRITE | PROT_FORK;
// Allocate a memory segment with the desired properties.
if ( !MapMemory(process, new_segment.addr, new_segment.size, new_segment.prot) )
if ( !Memory::MapMemory(process, new_segment.addr, new_segment.size, new_segment.prot) )
return MAP_FAILED;
// The pread will copy to user-space right requires this lock to be free.
@ -377,7 +386,7 @@ void* sys_mmap(void* addr_ptr, size_t size, int prot, int flags, int fd,
return (void*) new_segment.addr;
}
static int sys_mprotect(const void* addr_ptr, size_t size, int prot)
int sys_mprotect(const void* addr_ptr, size_t size, int prot)
{
// Verify that that the address is suitable aligned.
uintptr_t addr = (uintptr_t) addr_ptr;
@ -393,13 +402,13 @@ static int sys_mprotect(const void* addr_ptr, size_t size, int prot)
Process* process = CurrentProcess();
ScopedLock lock(&process->segment_lock);
if ( !ProtectMemory(process, addr, size, prot) )
if ( !Memory::ProtectMemory(process, addr, size, prot) )
return -1;
return 0;
}
static int sys_munmap(void* addr_ptr, size_t size)
int sys_munmap(void* addr_ptr, size_t size)
{
// Verify that that the address is suitable aligned.
uintptr_t addr = (uintptr_t) addr_ptr;
@ -414,7 +423,7 @@ static int sys_munmap(void* addr_ptr, size_t size)
Process* process = CurrentProcess();
ScopedLock lock(&process->segment_lock);
UnmapMemory(process, addr, size);
Memory::UnmapMemory(process, addr, size);
return 0;
}
@ -434,7 +443,7 @@ struct mmap_request /* duplicated in libc/sys/mman/mmap.cpp */
off_t offset;
};
static void* sys_mmap_wrapper(struct mmap_request* user_request)
void* sys_mmap_wrapper(struct mmap_request* user_request)
{
struct mmap_request request;
if ( !CopyFromUser(&request, user_request, sizeof(request)) )
@ -443,16 +452,16 @@ static void* sys_mmap_wrapper(struct mmap_request* user_request)
request.fd, request.offset);
}
} // namespace Sortix
namespace Sortix {
namespace Memory {
void InitCPU(multiboot_info_t* bootinfo);
void Init(multiboot_info_t* bootinfo)
{
InitCPU(bootinfo);
Syscall::Register(SYSCALL_MEMSTAT, (void*) sys_memstat);
Syscall::Register(SYSCALL_MMAP_WRAPPER, (void*) sys_mmap_wrapper);
Syscall::Register(SYSCALL_MPROTECT, (void*) sys_mprotect);
Syscall::Register(SYSCALL_MUNMAP, (void*) sys_munmap);
}
} // namespace Memory

View File

@ -50,8 +50,6 @@
#include <sortix/kernel/thread.h>
#include <sortix/kernel/vnode.h>
#include "pipe.h"
namespace Sortix {
class PipeChannel
@ -511,9 +509,7 @@ int PipeNode::poll(ioctx_t* ctx, PollNode* node)
return endpoint.poll(ctx, node);
}
namespace Pipe {
static int sys_pipe2(int pipefd[2], int flags)
int sys_pipe2(int pipefd[2], int flags)
{
int fdflags = 0;
if ( flags & O_CLOEXEC ) fdflags |= FD_CLOEXEC;
@ -563,10 +559,4 @@ static int sys_pipe2(int pipefd[2], int flags)
return -1;
}
void Init()
{
Syscall::Register(SYSCALL_PIPE2, (void*) sys_pipe2);
}
} // namespace Pipe
} // namespace Sortix

View File

@ -1,40 +0,0 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013.
This file is part of Sortix.
Sortix is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
Sortix is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
You should have received a copy of the GNU General Public License along with
Sortix. If not, see <http://www.gnu.org/licenses/>.
pipe.h
A device with a writing end and a reading end.
*******************************************************************************/
#ifndef SORTIX_PIPE_H
#define SORTIX_PIPE_H
namespace Sortix {
class Inode;
namespace Pipe {
void Init();
bool CreatePipes(Inode* pipes[2]);
} // namespace Pipe
} // namespace Sortix
#endif

View File

@ -146,8 +146,6 @@ PollNode* PollNode::CreateSlave()
return slave = new_slave;
}
namespace Poll {
static struct pollfd* CopyFdsFromUser(struct pollfd* user_fds, nfds_t nfds)
{
size_t size = sizeof(struct pollfd) * nfds;
@ -179,9 +177,9 @@ static bool FetchTimespec(struct timespec* dest, const struct timespec* user)
return true;
}
static int sys_ppoll(struct pollfd* user_fds, nfds_t nfds,
const struct timespec* user_timeout_ts,
const sigset_t* user_sigmask)
int sys_ppoll(struct pollfd* user_fds, nfds_t nfds,
const struct timespec* user_timeout_ts,
const sigset_t* user_sigmask)
{
ioctx_t ctx; SetupKernelIOCtx(&ctx);
@ -276,11 +274,4 @@ static int sys_ppoll(struct pollfd* user_fds, nfds_t nfds,
return ret;
}
void Init()
{
Syscall::Register(SYSCALL_PPOLL, (void*) sys_ppoll);
}
} // namespace Poll
} // namespace Sortix

View File

@ -1,36 +0,0 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2012.
This file is part of Sortix.
Sortix is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
Sortix is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
You should have received a copy of the GNU General Public License along with
Sortix. If not, see <http://www.gnu.org/licenses/>.
poll.h
Interface for waiting on file descriptor events.
*******************************************************************************/
#ifndef SORTIX_POLL_H
#define SORTIX_POLL_H
namespace Sortix {
namespace Poll {
void Init();
} // nanmespace Poll
} // namespace Sortix
#endif

View File

@ -534,7 +534,7 @@ pid_t Process::Wait(pid_t thepid, int* status_ptr, int options)
return thepid;
}
static pid_t sys_waitpid(pid_t pid, int* user_status, int options)
pid_t sys_waitpid(pid_t pid, int* user_status, int options)
{
int status = 0;
pid_t ret = CurrentProcess()->Wait(pid, &status, options);
@ -1322,7 +1322,6 @@ int sys_execve_kernel(const char* filename,
return result;
}
static
int sys_execve(const char* user_filename,
char* const user_argv[],
char* const user_envp[])
@ -1418,7 +1417,7 @@ cleanup_done:
return result;
}
static pid_t sys_tfork(int flags, struct tfork* user_regs)
pid_t sys_tfork(int flags, struct tfork* user_regs)
{
struct tfork regs;
if ( !CopyFromUser(&regs, user_regs, sizeof(regs)) )
@ -1533,7 +1532,7 @@ static pid_t sys_tfork(int flags, struct tfork* user_regs)
return child_process->pid;
}
static pid_t sys_getpid()
pid_t sys_getpid(void)
{
return CurrentProcess()->pid;
}
@ -1546,12 +1545,12 @@ pid_t Process::GetParentProcessId()
return parent->pid;
}
static pid_t sys_getppid()
pid_t sys_getppid(void)
{
return CurrentProcess()->GetParentProcessId();
}
static pid_t sys_getpgid(pid_t pid)
pid_t sys_getpgid(pid_t pid)
{
Process* process = !pid ? CurrentProcess() : CurrentProcess()->GetPTable()->Get(pid);
if ( !process )
@ -1564,7 +1563,7 @@ static pid_t sys_getpgid(pid_t pid)
return process->group->pid;
}
static int sys_setpgid(pid_t pid, pid_t pgid)
int sys_setpgid(pid_t pid, pid_t pgid)
{
// TODO: Prevent changing the process group of zombies and other volatile
// things that are about to implode.
@ -1626,7 +1625,7 @@ static int sys_setpgid(pid_t pid, pid_t pgid)
return 0;
}
static void* sys_sbrk(intptr_t increment)
void* sys_sbrk(intptr_t increment)
{
Process* process = CurrentProcess();
ScopedLock lock(&process->segment_lock);
@ -1682,12 +1681,12 @@ static void* sys_sbrk(intptr_t increment)
return (void*) (heap_segment->addr + heap_segment->size);
}
static size_t sys_getpagesize()
size_t sys_getpagesize(void)
{
return Page::Size();
}
static mode_t sys_umask(mode_t newmask)
mode_t sys_umask(mode_t newmask)
{
Process* process = CurrentProcess();
ScopedLock lock(&process->idlock);
@ -1696,26 +1695,11 @@ static mode_t sys_umask(mode_t newmask)
return oldmask;
}
static mode_t sys_getumask(void)
mode_t sys_getumask(void)
{
Process* process = CurrentProcess();
ScopedLock lock(&process->idlock);
return process->umask;
}
void Process::Init()
{
Syscall::Register(SYSCALL_EXECVE, (void*) sys_execve);
Syscall::Register(SYSCALL_GETPAGESIZE, (void*) sys_getpagesize);
Syscall::Register(SYSCALL_GETPGID, (void*) sys_getpgid);
Syscall::Register(SYSCALL_GETPID, (void*) sys_getpid);
Syscall::Register(SYSCALL_GETPPID, (void*) sys_getppid);
Syscall::Register(SYSCALL_GETUMASK, (void*) sys_getumask);
Syscall::Register(SYSCALL_SBRK, (void*) sys_sbrk);
Syscall::Register(SYSCALL_SETPGID, (void*) sys_setpgid);
Syscall::Register(SYSCALL_TFORK, (void*) sys_tfork);
Syscall::Register(SYSCALL_UMASK, (void*) sys_umask);
Syscall::Register(SYSCALL_WAITPID, (void*) sys_waitpid);
}
} // namespace Sortix

View File

@ -25,11 +25,9 @@
#include <errno.h>
#include <sortix/kernel/copy.h>
#include <sortix/kernel/random.h>
#include <sortix/kernel/syscall.h>
namespace Sortix {
namespace Random {
int sys_getentropy(void* user_buffer, size_t size)
{
@ -44,10 +42,4 @@ int sys_getentropy(void* user_buffer, size_t size)
return 0;
}
void Init()
{
Syscall::Register(SYSCALL_GETENTROPY, (void*) sys_getentropy);
}
} // namespace Random
} // namespace Sortix

View File

@ -35,10 +35,7 @@
#include <sortix/kernel/ptable.h>
#include <sortix/kernel/syscall.h>
#include "resource.h"
namespace Sortix {
namespace Resource {
static int GetProcessPriority(pid_t who)
{
@ -128,7 +125,7 @@ static int SetUserPriority(uid_t /*who*/, int /*prio*/)
return errno = ENOSYS, -1;
}
static int sys_getpriority(int which, id_t who)
int sys_getpriority(int which, id_t who)
{
switch ( which )
{
@ -139,7 +136,7 @@ static int sys_getpriority(int which, id_t who)
}
}
static int sys_setpriority(int which, id_t who, int prio)
int sys_setpriority(int which, id_t who, int prio)
{
switch ( which )
{
@ -150,7 +147,6 @@ static int sys_setpriority(int which, id_t who, int prio)
}
}
static
int sys_prlimit(pid_t pid,
int resource,
const struct rlimit* user_new_limit,
@ -184,12 +180,4 @@ int sys_prlimit(pid_t pid,
return 0;
}
void Init()
{
Syscall::Register(SYSCALL_GETPRIORITY, (void*) sys_getpriority);
Syscall::Register(SYSCALL_PRLIMIT, (void*) sys_prlimit);
Syscall::Register(SYSCALL_SETPRIORITY, (void*) sys_setpriority);
}
} // namespace Resource
} // namespace Sortix

View File

@ -1,36 +0,0 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2013.
This file is part of Sortix.
Sortix is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
Sortix is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
You should have received a copy of the GNU General Public License along with
Sortix. If not, see <http://www.gnu.org/licenses/>.
resource.h
Resource limits and operations.
*******************************************************************************/
#ifndef SORTIX_RESOURCE_H
#define SORTIX_RESOURCE_H
namespace Sortix {
namespace Resource {
void Init();
} // namespace Resource
} // namespace Sortix
#endif

View File

@ -333,11 +333,21 @@ ThreadState GetThreadState(Thread* thread)
return thread->state;
}
static int sys_sched_yield(void)
} // namespace Scheduler
} // namespace Sortix
namespace Sortix {
int sys_sched_yield(void)
{
return kthread_yield(), 0;
}
} // namespace Sortix
namespace Sortix {
namespace Scheduler {
void ScheduleTrueThread()
{
bool wasenabled = Interrupt::SetEnabled(false);
@ -355,8 +365,6 @@ void Init()
first_runnable_thread = NULL;
true_current_thread = NULL;
idle_thread = NULL;
Syscall::Register(SYSCALL_SCHED_YIELD, (void*) sys_sched_yield);
}
} // namespace Scheduler

View File

@ -105,7 +105,6 @@ void UpdatePendingSignals(Thread* thread) // thread->process->signal_lock held
thread->registers.signal_pending = is_pending;
}
static
int sys_sigaction(int signum,
const struct sigaction* user_newact,
struct sigaction* user_oldact)
@ -149,7 +148,7 @@ int sys_sigaction(int signum,
return 0;
}
static int sys_sigaltstack(const stack_t* user_newstack, stack_t* user_oldstack)
int sys_sigaltstack(const stack_t* user_newstack, stack_t* user_oldstack)
{
Thread* thread = CurrentThread();
@ -174,7 +173,7 @@ static int sys_sigaltstack(const stack_t* user_newstack, stack_t* user_oldstack)
return 0;
}
static int sys_sigpending(sigset_t* set)
int sys_sigpending(sigset_t* set)
{
Process* process = CurrentProcess();
Thread* thread = CurrentThread();
@ -186,7 +185,6 @@ static int sys_sigpending(sigset_t* set)
return CopyToUser(set, &thread->signal_pending, sizeof(sigset_t)) ? 0 : -1;
}
static
int sys_sigprocmask(int how, const sigset_t* user_set, sigset_t* user_oldset)
{
Process* process = CurrentProcess();
@ -232,7 +230,7 @@ int sys_sigprocmask(int how, const sigset_t* user_set, sigset_t* user_oldset)
return 0;
}
static int sys_sigsuspend(const sigset_t* set)
int sys_sigsuspend(const sigset_t* set)
{
Process* process = CurrentProcess();
Thread* thread = CurrentThread();
@ -268,7 +266,7 @@ static int sys_sigsuspend(const sigset_t* set)
return errno = EINTR, -1;
}
static int sys_kill(pid_t pid, int signum)
int sys_kill(pid_t pid, int signum)
{
// Protect the kernel process.
if ( !pid )
@ -344,7 +342,7 @@ bool Process::DeliverSignal(int signum)
return firstthread->DeliverSignal(signum);
}
static int sys_raise(int signum)
int sys_raise(int signum)
{
if ( !CurrentThread()->DeliverSignal(signum) && errno != ESIGPENDING )
return -1;
@ -837,14 +835,6 @@ void Init()
sigemptyset(&unblockable_signals);
sigaddset(&unblockable_signals, SIGKILL);
sigaddset(&unblockable_signals, SIGSTOP);
Syscall::Register(SYSCALL_KILL, (void*) sys_kill);
Syscall::Register(SYSCALL_RAISE, (void*) sys_raise);
Syscall::Register(SYSCALL_SIGACTION, (void*) sys_sigaction);
Syscall::Register(SYSCALL_SIGALTSTACK, (void*) sys_sigaltstack);
Syscall::Register(SYSCALL_SIGPENDING, (void*) sys_sigpending);
Syscall::Register(SYSCALL_SIGPROCMASK, (void*) sys_sigprocmask);
Syscall::Register(SYSCALL_SIGSUSPEND, (void*) sys_sigsuspend);
}
} // namespace Signal

View File

@ -22,46 +22,178 @@
*******************************************************************************/
#include <errno.h>
#include <stddef.h>
#include <sortix/syscall.h>
#include <sortix/kernel/kernel.h>
#include <sortix/kernel/process.h>
#include <sortix/kernel/scheduler.h>
#include <sortix/kernel/log.h>
#include <sortix/kernel/syscall.h>
#include <sortix/kernel/thread.h>
namespace Sortix {
namespace Syscall {
extern "C"
extern "C" {
void* syscall_list[SYSCALL_MAX_NUM + 1] =
{
size_t SYSCALL_MAX;
volatile void* syscall_list[SYSCALL_MAX_NUM];
}
[SYSCALL_BAD_SYSCALL] = (void*) sys_bad_syscall,
[SYSCALL_EXIT] = (void*) sys_bad_syscall,
[SYSCALL_SLEEP] = (void*) sys_bad_syscall,
[SYSCALL_USLEEP] = (void*) sys_bad_syscall,
[SYSCALL_PRINT_STRING] = (void*) sys_bad_syscall,
[SYSCALL_CREATE_FRAME] = (void*) sys_bad_syscall,
[SYSCALL_CHANGE_FRAME] = (void*) sys_bad_syscall,
[SYSCALL_DELETE_FRAME] = (void*) sys_bad_syscall,
[SYSCALL_RECEIVE_KEYSTROKE] = (void*) sys_bad_syscall,
[SYSCALL_SET_FREQUENCY] = (void*) sys_bad_syscall,
[SYSCALL_EXECVE] = (void*) sys_execve,
[SYSCALL_PRINT_PATH_FILES] = (void*) sys_bad_syscall,
[SYSCALL_FORK] = (void*) sys_bad_syscall,
[SYSCALL_GETPID] = (void*) sys_getpid,
[SYSCALL_GETPPID] = (void*) sys_getppid,
[SYSCALL_GET_FILEINFO] = (void*) sys_bad_syscall,
[SYSCALL_GET_NUM_FILES] = (void*) sys_bad_syscall,
[SYSCALL_WAITPID] = (void*) sys_waitpid,
[SYSCALL_READ] = (void*) sys_read,
[SYSCALL_WRITE] = (void*) sys_write,
[SYSCALL_PIPE] = (void*) sys_bad_syscall,
[SYSCALL_CLOSE] = (void*) sys_close,
[SYSCALL_DUP] = (void*) sys_dup,
[SYSCALL_OPEN] = (void*) sys_bad_syscall,
[SYSCALL_READDIRENTS] = (void*) sys_readdirents,
[SYSCALL_CHDIR] = (void*) sys_bad_syscall,
[SYSCALL_GETCWD] = (void*) sys_bad_syscall,
[SYSCALL_UNLINK] = (void*) sys_bad_syscall,
[SYSCALL_REGISTER_ERRNO] = (void*) sys_bad_syscall,
[SYSCALL_REGISTER_SIGNAL_HANDLER] = (void*) sys_bad_syscall,
[SYSCALL_SIGRETURN] = (void*) sys_bad_syscall,
[SYSCALL_KILL] = (void*) sys_kill,
[SYSCALL_MEMSTAT] = (void*) sys_memstat,
[SYSCALL_ISATTY] = (void*) sys_isatty,
[SYSCALL_UPTIME] = (void*) sys_bad_syscall,
[SYSCALL_SBRK] = (void*) sys_sbrk,
[SYSCALL_LSEEK] = (void*) sys_lseek,
[SYSCALL_GETPAGESIZE] = (void*) sys_getpagesize,
[SYSCALL_MKDIR] = (void*) sys_bad_syscall,
[SYSCALL_RMDIR] = (void*) sys_bad_syscall,
[SYSCALL_TRUNCATE] = (void*) sys_bad_syscall,
[SYSCALL_FTRUNCATE] = (void*) sys_ftruncate,
[SYSCALL_SETTERMMODE] = (void*) sys_settermmode,
[SYSCALL_GETTERMMODE] = (void*) sys_gettermmode,
[SYSCALL_STAT] = (void*) sys_bad_syscall,
[SYSCALL_FSTAT] = (void*) sys_fstat,
[SYSCALL_FCNTL] = (void*) sys_fcntl,
[SYSCALL_ACCESS] = (void*) sys_bad_syscall,
[SYSCALL_KERNELINFO] = (void*) sys_kernelinfo,
[SYSCALL_PREAD] = (void*) sys_pread,
[SYSCALL_PWRITE] = (void*) sys_pwrite,
[SYSCALL_TFORK] = (void*) sys_tfork,
[SYSCALL_TCGETWINSIZE] = (void*) sys_tcgetwinsize,
[SYSCALL_RAISE] = (void*) sys_raise,
[SYSCALL_OPENAT] = (void*) sys_openat,
[SYSCALL_DISPMSG_ISSUE] = (void*) sys_dispmsg_issue,
[SYSCALL_FSTATAT] = (void*) sys_fstatat,
[SYSCALL_CHMOD] = (void*) sys_bad_syscall,
[SYSCALL_CHOWN] = (void*) sys_bad_syscall,
[SYSCALL_LINK] = (void*) sys_bad_syscall,
[SYSCALL_DUP2] = (void*) sys_dup2,
[SYSCALL_UNLINKAT] = (void*) sys_unlinkat,
[SYSCALL_FACCESSAT] = (void*) sys_faccessat,
[SYSCALL_MKDIRAT] = (void*) sys_mkdirat,
[SYSCALL_FCHDIR] = (void*) sys_fchdir,
[SYSCALL_TRUNCATEAT] = (void*) sys_truncateat,
[SYSCALL_FCHOWNAT] = (void*) sys_fchownat,
[SYSCALL_FCHOWN] = (void*) sys_fchown,
[SYSCALL_FCHMOD] = (void*) sys_fchmod,
[SYSCALL_FCHMODAT] = (void*) sys_fchmodat,
[SYSCALL_LINKAT] = (void*) sys_linkat,
[SYSCALL_FSM_FSBIND] = (void*) sys_fsm_fsbind,
[SYSCALL_PPOLL] = (void*) sys_ppoll,
[SYSCALL_RENAMEAT] = (void*) sys_renameat,
[SYSCALL_READLINKAT] = (void*) sys_readlinkat,
[SYSCALL_FSYNC] = (void*) sys_fsync,
[SYSCALL_GETUID] = (void*) sys_getuid,
[SYSCALL_GETGID] = (void*) sys_getgid,
[SYSCALL_SETUID] = (void*) sys_setuid,
[SYSCALL_SETGID] = (void*) sys_setgid,
[SYSCALL_GETEUID] = (void*) sys_geteuid,
[SYSCALL_GETEGID] = (void*) sys_getegid,
[SYSCALL_SETEUID] = (void*) sys_seteuid,
[SYSCALL_SETEGID] = (void*) sys_setegid,
[SYSCALL_IOCTL] = (void*) sys_ioctl,
[SYSCALL_UTIMENSAT] = (void*) sys_utimensat,
[SYSCALL_FUTIMENS] = (void*) sys_futimens,
[SYSCALL_RECV] = (void*) sys_recv,
[SYSCALL_SEND] = (void*) sys_send,
[SYSCALL_ACCEPT4] = (void*) sys_accept4,
[SYSCALL_BIND] = (void*) sys_bind,
[SYSCALL_CONNECT] = (void*) sys_connect,
[SYSCALL_LISTEN] = (void*) sys_listen,
[SYSCALL_READV] = (void*) sys_readv,
[SYSCALL_WRITEV] = (void*) sys_writev,
[SYSCALL_PREADV] = (void*) sys_preadv,
[SYSCALL_PWRITEV] = (void*) sys_pwritev,
[SYSCALL_TIMER_CREATE] = (void*) sys_timer_create,
[SYSCALL_TIMER_DELETE] = (void*) sys_timer_delete,
[SYSCALL_TIMER_GETOVERRUN] = (void*) sys_timer_getoverrun,
[SYSCALL_TIMER_GETTIME] = (void*) sys_timer_gettime,
[SYSCALL_TIMER_SETTIME] = (void*) sys_timer_settime,
[SYSCALL_ALARMNS] = (void*) sys_alarmns,
[SYSCALL_CLOCK_GETTIMERES] = (void*) sys_clock_gettimeres,
[SYSCALL_CLOCK_SETTIMERES] = (void*) sys_clock_settimeres,
[SYSCALL_CLOCK_NANOSLEEP] = (void*) sys_clock_nanosleep,
[SYSCALL_TIMENS] = (void*) sys_timens,
[SYSCALL_UMASK] = (void*) sys_umask,
[SYSCALL_FCHDIRAT] = (void*) sys_fchdirat,
[SYSCALL_FCHROOT] = (void*) sys_fchroot,
[SYSCALL_FCHROOTAT] = (void*) sys_fchrootat,
[SYSCALL_MKPARTITION] = (void*) sys_mkpartition,
[SYSCALL_GETPGID] = (void*) sys_getpgid,
[SYSCALL_SETPGID] = (void*) sys_setpgid,
[SYSCALL_TCGETPGRP] = (void*) sys_tcgetpgrp,
[SYSCALL_TCSETPGRP] = (void*) sys_tcsetpgrp,
[SYSCALL_MMAP_WRAPPER] = (void*) sys_mmap_wrapper,
[SYSCALL_MPROTECT] = (void*) sys_mprotect,
[SYSCALL_MUNMAP] = (void*) sys_munmap,
[SYSCALL_GETPRIORITY] = (void*) sys_getpriority,
[SYSCALL_SETPRIORITY] = (void*) sys_setpriority,
[SYSCALL_PRLIMIT] = (void*) sys_prlimit,
[SYSCALL_DUP3] = (void*) sys_dup3,
[SYSCALL_SYMLINKAT] = (void*) sys_symlinkat,
[SYSCALL_TCGETWINCURPOS] = (void*) sys_tcgetwincurpos,
[SYSCALL_PIPE2] = (void*) sys_pipe2,
[SYSCALL_GETUMASK] = (void*) sys_getumask,
[SYSCALL_FSTATVFS] = (void*) sys_fstatvfs,
[SYSCALL_FSTATVFSAT] = (void*) sys_fstatvfsat,
[SYSCALL_RDMSR] = (void*) sys_rdmsr,
[SYSCALL_WRMSR] = (void*) sys_wrmsr,
[SYSCALL_SCHED_YIELD] = (void*) sys_sched_yield,
[SYSCALL_EXIT_THREAD] = (void*) sys_exit_thread,
[SYSCALL_SIGACTION] = (void*) sys_sigaction,
[SYSCALL_SIGALTSTACK] = (void*) sys_sigaltstack,
[SYSCALL_SIGPENDING] = (void*) sys_sigpending,
[SYSCALL_SIGPROCMASK] = (void*) sys_sigprocmask,
[SYSCALL_SIGSUSPEND] = (void*) sys_sigsuspend,
[SYSCALL_SENDMSG] = (void*) sys_sendmsg,
[SYSCALL_RECVMSG] = (void*) sys_recvmsg,
[SYSCALL_GETSOCKOPT] = (void*) sys_getsockopt,
[SYSCALL_SETSOCKOPT] = (void*) sys_setsockopt,
[SYSCALL_TCGETBLOB] = (void*) sys_tcgetblob,
[SYSCALL_TCSETBLOB] = (void*) sys_tcsetblob,
[SYSCALL_GETPEERNAME] = (void*) sys_getpeername,
[SYSCALL_GETSOCKNAME] = (void*) sys_getsockname,
[SYSCALL_SHUTDOWN] = (void*) sys_shutdown,
[SYSCALL_GETENTROPY] = (void*) sys_getentropy,
[SYSCALL_GETHOSTNAME] = (void*) sys_gethostname,
[SYSCALL_SETHOSTNAME] = (void*) sys_sethostname,
[SYSCALL_MAX_NUM] = (void*) sys_bad_syscall,
};
} // extern "C"
static int sys_bad_syscall()
int sys_bad_syscall(void)
{
// TODO: Send signal, set errno, or crash/abort process?
Log::PrintF("I am the bad system call!\n");
return -1;
return errno = EINVAL, -1;
}
void Init()
{
SYSCALL_MAX = SYSCALL_MAX_NUM;
for ( size_t i = 0; i < SYSCALL_MAX_NUM; i++ )
syscall_list[i] = (void*) sys_bad_syscall;
}
void Register(size_t index, void* function)
{
if ( SYSCALL_MAX_NUM <= index )
PanicF("Attempted to register system call %p to index %zu, but "
"SYSCALL_MAX_NUM = %zu", function, index, (size_t) SYSCALL_MAX_NUM);
syscall_list[index] = function;
}
} // namespace Syscall
} // namespace Sortix

View File

@ -292,9 +292,9 @@ Thread* RunKernelThread(void (*entry)(void*), void* user, size_t stacksize)
return thread;
}
static int sys_exit_thread(int requested_exit_code,
int flags,
const struct exit_thread* user_extended)
int sys_exit_thread(int requested_exit_code,
int flags,
const struct exit_thread* user_extended)
{
if ( flags & ~(EXIT_THREAD_ONLY_IF_OTHERS |
EXIT_THREAD_UNMAP |
@ -406,9 +406,4 @@ static int sys_exit_thread(int requested_exit_code,
kthread_exit();
}
void Thread::Init()
{
Syscall::Register(SYSCALL_EXIT_THREAD, (void*) sys_exit_thread);
}
} // namespace Sortix

View File

@ -74,8 +74,9 @@ static Timer* LookupTimer(Process* process, timer_t timerid)
return user_timer ? &user_timer->timer : (Timer*) NULL;
}
static int sys_timer_create(clockid_t clockid, struct sigevent* sigevp,
timer_t* timerid_ptr)
int sys_timer_create(clockid_t clockid,
struct sigevent* sigevp,
timer_t* timerid_ptr)
{
Process* process = CurrentProcess();
ScopedLock lock(&process->user_timers_lock);
@ -115,7 +116,7 @@ static int sys_timer_create(clockid_t clockid, struct sigevent* sigevp,
return 0;
}
static int sys_timer_delete(timer_t timerid)
int sys_timer_delete(timer_t timerid)
{
Process* process = CurrentProcess();
ScopedLock lock(&process->user_timers_lock);
@ -130,7 +131,7 @@ static int sys_timer_delete(timer_t timerid)
return 0;
}
static int sys_timer_getoverrun(timer_t timerid)
int sys_timer_getoverrun(timer_t timerid)
{
Process* process = CurrentProcess();
ScopedLock lock(&process->user_timers_lock);
@ -149,7 +150,7 @@ static int sys_timer_getoverrun(timer_t timerid)
return 0;
}
static int sys_timer_gettime(timer_t timerid, struct itimerspec* user_value)
int sys_timer_gettime(timer_t timerid, struct itimerspec* user_value)
{
Process* process = CurrentProcess();
ScopedLock lock(&process->user_timers_lock);
@ -180,9 +181,10 @@ static void timer_callback(Clock* /*clock*/, Timer* timer, void* user)
}
}
static int sys_timer_settime(timer_t timerid, int flags,
const struct itimerspec* user_value,
struct itimerspec* user_ovalue)
int sys_timer_settime(timer_t timerid,
int flags,
const struct itimerspec* user_value,
struct itimerspec* user_ovalue)
{
Process* process = CurrentProcess();
ScopedLock lock(&process->user_timers_lock);
@ -215,8 +217,9 @@ static int sys_timer_settime(timer_t timerid, int flags,
return 0;
}
static int sys_clock_gettimeres(clockid_t clockid, struct timespec* time,
struct timespec* res)
int sys_clock_gettimeres(clockid_t clockid,
struct timespec* time,
struct timespec* res)
{
Clock* clock = Time::GetClock(clockid);
if ( !clock )
@ -229,8 +232,9 @@ static int sys_clock_gettimeres(clockid_t clockid, struct timespec* time,
(!res || CopyToUser(res, &kres, sizeof(kres))) ? 0 : -1;
}
static int sys_clock_settimeres(clockid_t clockid, const struct timespec* time,
const struct timespec* res)
int sys_clock_settimeres(clockid_t clockid,
const struct timespec* time,
const struct timespec* res)
{
Clock* clock = Time::GetClock(clockid);
if ( !clock )
@ -246,9 +250,10 @@ static int sys_clock_settimeres(clockid_t clockid, const struct timespec* time,
return 0;
}
static int sys_clock_nanosleep(clockid_t clockid, int flags,
const struct timespec* user_duration,
struct timespec* user_remainder)
int sys_clock_nanosleep(clockid_t clockid,
int flags,
const struct timespec* user_duration,
struct timespec* user_remainder)
{
struct timespec time;
@ -268,7 +273,7 @@ static int sys_clock_nanosleep(clockid_t clockid, int flags,
return timespec_eq(time, timespec_nul()) ? 0 : (errno = EINTR, -1);
}
static int sys_timens(struct tmns* user_tmns)
int sys_timens(struct tmns* user_tmns)
{
Clock* execute_clock = Time::GetClock(CLOCK_PROCESS_CPUTIME_ID);
Clock* system_clock = Time::GetClock(CLOCK_PROCESS_SYSTIME_ID);
@ -289,17 +294,4 @@ static int sys_timens(struct tmns* user_tmns)
return CopyToUser(user_tmns, &tmns, sizeof(tmns)) ? 0 : -1;
}
void UserTimer::Init()
{
Syscall::Register(SYSCALL_CLOCK_GETTIMERES, (void*) sys_clock_gettimeres);
Syscall::Register(SYSCALL_CLOCK_NANOSLEEP, (void*) sys_clock_nanosleep);
Syscall::Register(SYSCALL_CLOCK_SETTIMERES, (void*) sys_clock_settimeres);
Syscall::Register(SYSCALL_TIMENS, (void*) sys_timens);
Syscall::Register(SYSCALL_TIMER_CREATE, (void*) sys_timer_create);
Syscall::Register(SYSCALL_TIMER_DELETE, (void*) sys_timer_delete);
Syscall::Register(SYSCALL_TIMER_GETOVERRUN, (void*) sys_timer_getoverrun);
Syscall::Register(SYSCALL_TIMER_GETTIME, (void*) sys_timer_gettime);
Syscall::Register(SYSCALL_TIMER_SETTIME, (void*) sys_timer_settime);
}
} // namespace Sortix

View File

@ -396,8 +396,15 @@ static int ReadMemory(void* ptr, size_t size)
return 0;
}
static int sys_dispmsg_issue(void* ptr, size_t size)
} // namespace Video
} // namespace Sortix
namespace Sortix {
int sys_dispmsg_issue(void* ptr, size_t size)
{
using namespace Video;
struct dispmsg_header hdr;
if ( size < sizeof(hdr) )
return errno = EINVAL, -1;
@ -421,10 +428,14 @@ static int sys_dispmsg_issue(void* ptr, size_t size)
}
}
} // namespace Sortix
namespace Sortix {
namespace Video {
void Init(Ref<TextBufferHandle> thetextbufhandle)
{
textbufhandle = thetextbufhandle;
Syscall::Register(SYSCALL_DISPMSG_ISSUE, (void*) sys_dispmsg_issue);
}
} // namespace Video

View File

@ -22,6 +22,8 @@
*******************************************************************************/
#include <sortix/syscall.h>
.global syscall_handler
.section .text
@ -33,7 +35,7 @@ syscall_handler:
movq %rsp, %rbp
# Make sure the requested system call is valid, if not, then fix it.
cmp SYSCALL_MAX, %rax
cmp $SYSCALL_MAX_NUM, %rax
jae fix_syscall
valid_syscall:

View File

@ -77,7 +77,12 @@ void ShutDown()
Reboot();
}
static uint64_t sys_rdmsr(uint32_t msrid)
} // namespace CPU
} // namespace Sortix
namespace Sortix {
uint64_t sys_rdmsr(uint32_t msrid)
{
switch ( msrid )
{
@ -98,7 +103,7 @@ static uint64_t sys_rdmsr(uint32_t msrid)
};
}
static uint64_t sys_wrmsr(uint32_t msrid, uint64_t value)
uint64_t sys_wrmsr(uint32_t msrid, uint64_t value)
{
switch ( msrid )
{
@ -127,11 +132,4 @@ static uint64_t sys_wrmsr(uint32_t msrid, uint64_t value)
};
}
void Init()
{
Syscall::Register(SYSCALL_RDMSR, (void*) sys_rdmsr);
Syscall::Register(SYSCALL_WRMSR, (void*) sys_wrmsr);
}
} // namespace CPU
} // namespace Sortix

View File

@ -1,38 +0,0 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2014.
This file is part of Sortix.
Sortix is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
Sortix is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
You should have received a copy of the GNU General Public License along with
Sortix. If not, see <http://www.gnu.org/licenses/>.
x86-family/x86-family.h
CPU stuff for the x86 CPU family.
*******************************************************************************/
#ifndef SORTIX_X86_FAMILY_X86_FAMILY_H
#define SORTIX_X86_FAMILY_X86_FAMILY_H
#include <sortix/kernel/decl.h>
namespace Sortix {
namespace CPU {
void Init();
} // namespace CPU
} // namespace Sortix
#endif

View File

@ -22,6 +22,8 @@
*******************************************************************************/
#include <sortix/syscall.h>
.global syscall_handler
.section .text
@ -42,7 +44,7 @@ syscall_handler:
movl %ebp, %es
# Make sure the requested system call is valid.
cmp SYSCALL_MAX, %eax
cmp $SYSCALL_MAX_NUM, %eax
jae fix_syscall
valid_syscall: