2012-03-24 10:23:07 -04:00
|
|
|
/*******************************************************************************
|
2011-10-26 18:05:20 -04:00
|
|
|
|
2015-05-13 11:48:53 -04:00
|
|
|
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013, 2014, 2015.
|
2011-10-26 18:05:20 -04:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
This file is part of Sortix.
|
2011-10-26 18:05:20 -04:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
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.
|
2011-10-26 18:05:20 -04:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
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.
|
2011-10-26 18:05:20 -04:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
|
|
Sortix. If not, see <http://www.gnu.org/licenses/>.
|
2012-09-30 07:42:35 -04:00
|
|
|
|
2014-06-27 10:15:30 -04:00
|
|
|
sortix/syscall.h
|
|
|
|
Numeric constants identifying each system call.
|
2011-10-26 18:05:20 -04:00
|
|
|
|
2012-03-24 10:23:07 -04:00
|
|
|
*******************************************************************************/
|
2011-10-26 18:05:20 -04:00
|
|
|
|
2013-05-03 15:43:01 -04:00
|
|
|
#ifndef INCLUDE_SORTIX_SYSCALLNUM_H
|
|
|
|
#define INCLUDE_SORTIX_SYSCALLNUM_H
|
2011-10-26 18:05:20 -04:00
|
|
|
|
|
|
|
#define SYSCALL_BAD_SYSCALL 0
|
2013-08-04 14:24:59 -04:00
|
|
|
#define SYSCALL_EXIT 1 /* OBSOLETE */
|
2014-02-23 08:41:51 -05:00
|
|
|
#define SYSCALL_SLEEP 2 /* OBSOLETE */
|
|
|
|
#define SYSCALL_USLEEP 3 /* OBSOLETE */
|
|
|
|
#define SYSCALL_PRINT_STRING 4 /* OBSOLETE */
|
|
|
|
#define SYSCALL_CREATE_FRAME 5 /* OBSOLETE */
|
|
|
|
#define SYSCALL_CHANGE_FRAME 6 /* OBSOLETE */
|
|
|
|
#define SYSCALL_DELETE_FRAME 7 /* OBSOLETE */
|
|
|
|
#define SYSCALL_RECEIVE_KEYSTROKE 8 /* OBSOLETE */
|
|
|
|
#define SYSCALL_SET_FREQUENCY 9 /* OBSOLETE */
|
2014-06-19 12:57:42 -04:00
|
|
|
#define SYSCALL_EXECVE 10
|
2014-02-23 08:41:51 -05:00
|
|
|
#define SYSCALL_PRINT_PATH_FILES 11 /* OBSOLETE */
|
|
|
|
#define SYSCALL_FORK 12 /* OBSOLETE */
|
2011-09-21 14:52:29 -04:00
|
|
|
#define SYSCALL_GETPID 13
|
|
|
|
#define SYSCALL_GETPPID 14
|
2014-02-23 08:41:51 -05:00
|
|
|
#define SYSCALL_GET_FILEINFO 15 /* OBSOLETE */
|
|
|
|
#define SYSCALL_GET_NUM_FILES 16 /* OBSOLETE */
|
2013-06-12 07:00:11 -04:00
|
|
|
#define SYSCALL_WAITPID 17
|
2011-11-16 02:37:29 -05:00
|
|
|
#define SYSCALL_READ 18
|
|
|
|
#define SYSCALL_WRITE 19
|
2014-02-23 08:41:51 -05:00
|
|
|
#define SYSCALL_PIPE 20 /* OBSOLETE */
|
2011-11-17 04:22:43 -05:00
|
|
|
#define SYSCALL_CLOSE 21
|
2011-11-17 16:28:20 -05:00
|
|
|
#define SYSCALL_DUP 22
|
2014-02-23 08:41:51 -05:00
|
|
|
#define SYSCALL_OPEN 23 /* OBSOLETE */
|
2011-11-20 18:02:53 -05:00
|
|
|
#define SYSCALL_READDIRENTS 24
|
2014-02-23 08:41:51 -05:00
|
|
|
#define SYSCALL_CHDIR 25 /* OBSOLETE */
|
|
|
|
#define SYSCALL_GETCWD 26 /* OBSOLETE */
|
|
|
|
#define SYSCALL_UNLINK 27 /* OBSOLETE */
|
|
|
|
#define SYSCALL_REGISTER_ERRNO 28 /* OBSOLETE */
|
|
|
|
#define SYSCALL_REGISTER_SIGNAL_HANDLER 29 /* OBSOLETE */
|
2014-10-16 18:04:47 -04:00
|
|
|
#define SYSCALL_SIGRETURN 30 /* OBSOLETE */
|
2011-09-15 16:38:40 -04:00
|
|
|
#define SYSCALL_KILL 31
|
2011-11-26 14:14:57 -05:00
|
|
|
#define SYSCALL_MEMSTAT 32
|
2011-11-26 14:56:45 -05:00
|
|
|
#define SYSCALL_ISATTY 33
|
2014-02-23 08:41:51 -05:00
|
|
|
#define SYSCALL_UPTIME 34 /* OBSOLETE */
|
2014-06-18 19:48:20 -04:00
|
|
|
#define SYSCALL_SBRK 35 /* OBSOLETE */
|
2014-06-19 12:57:42 -04:00
|
|
|
#define SYSCALL_LSEEK 36
|
|
|
|
#define SYSCALL_GETPAGESIZE 37
|
2014-02-23 08:41:51 -05:00
|
|
|
#define SYSCALL_MKDIR 38 /* OBSOLETE */
|
|
|
|
#define SYSCALL_RMDIR 39 /* OBSOLETE */
|
|
|
|
#define SYSCALL_TRUNCATE 40 /* OBSOLETE */
|
2012-01-14 10:37:21 -05:00
|
|
|
#define SYSCALL_FTRUNCATE 41
|
2012-01-22 10:48:57 -05:00
|
|
|
#define SYSCALL_SETTERMMODE 42
|
|
|
|
#define SYSCALL_GETTERMMODE 43
|
2014-02-23 08:41:51 -05:00
|
|
|
#define SYSCALL_STAT 44 /* OBSOLETE */
|
2012-02-21 18:30:34 -05:00
|
|
|
#define SYSCALL_FSTAT 45
|
2012-03-04 15:36:40 -05:00
|
|
|
#define SYSCALL_FCNTL 46
|
2014-02-23 08:41:51 -05:00
|
|
|
#define SYSCALL_ACCESS 47 /* OBSOLETE */
|
2012-03-07 12:04:59 -05:00
|
|
|
#define SYSCALL_KERNELINFO 48
|
2012-03-24 10:23:07 -04:00
|
|
|
#define SYSCALL_PREAD 49
|
|
|
|
#define SYSCALL_PWRITE 50
|
2012-08-05 11:35:19 -04:00
|
|
|
#define SYSCALL_TFORK 51
|
2012-07-24 12:43:34 -04:00
|
|
|
#define SYSCALL_TCGETWINSIZE 52
|
Multithreaded kernel and improvement of signal handling.
Pardon the big ass-commit, this took months to develop and debug and the
refactoring got so far that a clean merge became impossible. The good news
is that this commit does quite a bit of cleaning up and generally improves
the kernel quality.
This makes the kernel fully pre-emptive and multithreaded. This was done
by rewriting the interrupt code, the scheduler, introducing new threading
primitives, and rewriting large parts of the kernel. During the past few
commits the kernel has had its device drivers thread secured; this commit
thread secures large parts of the core kernel. There still remains some
parts of the kernel that is _not_ thread secured, but this is not a problem
at this point. Each user-space thread has an associated kernel stack that
it uses when it goes into kernel mode. This stack is by default 8 KiB since
that value works for me and is also used by Linux. Strange things tends to
happen on x86 in case of a stack overflow - there is no ideal way to catch
such a situation right now.
The system call conventions were changed, too. The %edx register is now
used to provide the errno value of the call, instead of the kernel writing
it into a registered global variable. The system call code has also been
updated to better reflect the native calling conventions: not all registers
have to be preserved. This makes system calls faster and simplifies the
assembly. In the kernel, there is no longer the event.h header or the hacky
method of 'resuming system calls' that closely resembles cooperative
multitasking. If a system call wants to block, it should just block.
The signal handling was also improved significantly. At this point, signals
cannot interrupt kernel threads (but can always interrupt user-space threads
if enabled), which introduces some problems with how a SIGINT could
interrupt a blocking read, for instance. This commit introduces and uses a
number of new primitives such as kthread_lock_mutex_signal() that attempts
to get the lock but fails if a signal is pending. In this manner, the kernel
is safer as kernel threads cannot be shut down inconveniently, but in return
for complexity as blocking operations must check they if they should fail.
Process exiting has also been refactored significantly. The _exit(2) system
call sets the exit code and sends SIGKILL to all the threads in the process.
Once all the threads have cleaned themselves up and exited, a worker thread
calls the process's LastPrayer() method that unmaps memory, deletes the
address space, notifies the parent, etc. This provides a very robust way to
terminate processes as even half-constructed processes (during a failing fork
for instance) can be gracefully terminated.
I have introduced a number of kernel threads to help avoid threading problems
and simplify kernel design. For instance, there is now a functional generic
kernel worker thread that any kernel thread can schedule jobs for. Interrupt
handlers run with interrupts off (hence they cannot call kthread_ functions
as it may deadlock the system if another thread holds the lock) therefore
they cannot use the standard kernel worker threads. Instead, they use a
special purpose interrupt worker thread that works much like the generic one
expect that interrupt handlers can safely queue work with interrupts off.
Note that this also means that interrupt handlers cannot allocate memory or
print to the kernel log/screen as such mechanisms uses locks. I'll introduce
a lock free algorithm for such cases later on.
The boot process has also changed. The original kernel init thread in
kernel.cpp creates a new bootstrap thread and becomes the system idle thread.
Note that pid=0 now means the kernel, as there is no longer a system idle
process. The bootstrap thread launches all the kernel worker threads and then
creates a new process and loads /bin/init into it and then creates a thread
in pid=1, which starts the system. The bootstrap thread then quietly waits
for pid=1 to exit after which it shuts down/reboots/panics the system.
In general, the introduction of race conditions and dead locks have forced me
to revise a lot of the design and make sure it was thread secure. Since early
parts of the kernel was quite hacky, I had to refactor such code. So it seems
that the risk of dead locks forces me to write better code.
Note that a real preemptive multithreaded kernel simplifies the construction
of blocking system calls. My hope is that this will trigger a clean up of
the filesystem code that current is almost beyond repair.
Almost all of the kernel was modified during this refactoring. To the extent
possible, these changes have been backported to older non-multithreaded
kernel, but many changes were tightly coupled and went into this commit.
Of interest is the implementation of the kthread_ api based on the design
of pthreads; this library allows easy synchronization mechanisms and
includes C++-style scoped locks. This commit also introduces new worker
threads and tested mechanisms for interrupt handlers to schedule work in a
kernel worker thread.
A lot of code have been rewritten from scratch and has become a lot more
stable and correct.
Share and enjoy!
2012-08-01 11:30:34 -04:00
|
|
|
#define SYSCALL_RAISE 53
|
2012-09-30 07:42:35 -04:00
|
|
|
#define SYSCALL_OPENAT 54
|
2012-12-15 20:10:19 -05:00
|
|
|
#define SYSCALL_DISPMSG_ISSUE 55
|
2012-08-07 18:19:44 -04:00
|
|
|
#define SYSCALL_FSTATAT 56
|
2014-02-23 08:41:51 -05:00
|
|
|
#define SYSCALL_CHMOD 57 /* OBSOLETE */
|
|
|
|
#define SYSCALL_CHOWN 58 /* OBSOLETE */
|
|
|
|
#define SYSCALL_LINK 59 /* OBSOLETE */
|
2013-06-27 14:47:24 -04:00
|
|
|
#define SYSCALL_DUP2 60
|
2012-10-23 07:50:33 -04:00
|
|
|
#define SYSCALL_UNLINKAT 61
|
2012-10-23 17:55:33 -04:00
|
|
|
#define SYSCALL_FACCESSAT 62
|
2012-10-23 18:07:39 -04:00
|
|
|
#define SYSCALL_MKDIRAT 63
|
2012-10-24 07:06:12 -04:00
|
|
|
#define SYSCALL_FCHDIR 64
|
2012-10-24 08:49:19 -04:00
|
|
|
#define SYSCALL_TRUNCATEAT 65
|
2012-10-24 13:43:11 -04:00
|
|
|
#define SYSCALL_FCHOWNAT 66
|
2012-10-24 13:52:28 -04:00
|
|
|
#define SYSCALL_FCHOWN 67
|
2012-10-24 18:17:43 -04:00
|
|
|
#define SYSCALL_FCHMOD 68
|
2012-10-24 18:29:48 -04:00
|
|
|
#define SYSCALL_FCHMODAT 69
|
2012-10-25 09:43:53 -04:00
|
|
|
#define SYSCALL_LINKAT 70
|
2013-01-30 14:33:13 -05:00
|
|
|
#define SYSCALL_FSM_FSBIND 71
|
2012-12-29 17:09:09 -05:00
|
|
|
#define SYSCALL_PPOLL 72
|
2012-12-20 10:19:07 -05:00
|
|
|
#define SYSCALL_RENAMEAT 73
|
2013-03-19 15:18:15 -04:00
|
|
|
#define SYSCALL_READLINKAT 74
|
2013-03-20 08:16:12 -04:00
|
|
|
#define SYSCALL_FSYNC 75
|
2013-01-12 20:37:14 -05:00
|
|
|
#define SYSCALL_GETUID 76
|
|
|
|
#define SYSCALL_GETGID 77
|
|
|
|
#define SYSCALL_SETUID 78
|
|
|
|
#define SYSCALL_SETGID 79
|
|
|
|
#define SYSCALL_GETEUID 80
|
|
|
|
#define SYSCALL_GETEGID 81
|
|
|
|
#define SYSCALL_SETEUID 82
|
|
|
|
#define SYSCALL_SETEGID 83
|
2013-03-21 16:35:51 -04:00
|
|
|
#define SYSCALL_IOCTL 84
|
2013-03-19 17:01:01 -04:00
|
|
|
#define SYSCALL_UTIMENSAT 85
|
|
|
|
#define SYSCALL_FUTIMENS 86
|
2013-03-19 17:40:37 -04:00
|
|
|
#define SYSCALL_RECV 87
|
|
|
|
#define SYSCALL_SEND 88
|
|
|
|
#define SYSCALL_ACCEPT4 89
|
|
|
|
#define SYSCALL_BIND 90
|
|
|
|
#define SYSCALL_CONNECT 91
|
|
|
|
#define SYSCALL_LISTEN 92
|
2013-05-03 15:43:01 -04:00
|
|
|
#define SYSCALL_READV 93
|
|
|
|
#define SYSCALL_WRITEV 94
|
|
|
|
#define SYSCALL_PREADV 95
|
|
|
|
#define SYSCALL_PWRITEV 96
|
2013-10-13 17:56:58 -04:00
|
|
|
#define SYSCALL_TIMER_CREATE 97
|
|
|
|
#define SYSCALL_TIMER_DELETE 98
|
|
|
|
#define SYSCALL_TIMER_GETOVERRUN 99
|
|
|
|
#define SYSCALL_TIMER_GETTIME 100
|
|
|
|
#define SYSCALL_TIMER_SETTIME 101
|
2013-05-11 19:24:42 -04:00
|
|
|
#define SYSCALL_ALARMNS 102
|
2013-05-12 16:10:34 -04:00
|
|
|
#define SYSCALL_CLOCK_GETTIMERES 103
|
|
|
|
#define SYSCALL_CLOCK_SETTIMERES 104
|
2013-05-14 12:41:49 -04:00
|
|
|
#define SYSCALL_CLOCK_NANOSLEEP 105
|
2013-05-15 06:37:39 -04:00
|
|
|
#define SYSCALL_TIMENS 106
|
2013-05-16 16:03:15 -04:00
|
|
|
#define SYSCALL_UMASK 107
|
2013-05-29 08:03:53 -04:00
|
|
|
#define SYSCALL_FCHDIRAT 108
|
2013-05-29 18:32:22 -04:00
|
|
|
#define SYSCALL_FCHROOT 109
|
|
|
|
#define SYSCALL_FCHROOTAT 110
|
2013-06-01 07:24:27 -04:00
|
|
|
#define SYSCALL_MKPARTITION 111
|
2013-06-11 19:02:01 -04:00
|
|
|
#define SYSCALL_GETPGID 112
|
|
|
|
#define SYSCALL_SETPGID 113
|
2013-06-11 20:18:07 -04:00
|
|
|
#define SYSCALL_TCGETPGRP 114
|
|
|
|
#define SYSCALL_TCSETPGRP 115
|
2013-08-19 15:03:07 -04:00
|
|
|
#define SYSCALL_MMAP_WRAPPER 116
|
|
|
|
#define SYSCALL_MPROTECT 117
|
|
|
|
#define SYSCALL_MUNMAP 118
|
2013-08-30 11:35:30 -04:00
|
|
|
#define SYSCALL_GETPRIORITY 119
|
|
|
|
#define SYSCALL_SETPRIORITY 120
|
2013-08-30 17:55:09 -04:00
|
|
|
#define SYSCALL_PRLIMIT 121
|
2013-09-23 14:41:31 -04:00
|
|
|
#define SYSCALL_DUP3 122
|
2013-11-21 14:27:34 -05:00
|
|
|
#define SYSCALL_SYMLINKAT 123
|
2013-12-20 15:55:05 -05:00
|
|
|
#define SYSCALL_TCGETWINCURPOS 124
|
2014-01-15 13:46:36 -05:00
|
|
|
#define SYSCALL_PIPE2 125
|
2014-01-19 16:45:49 -05:00
|
|
|
#define SYSCALL_GETUMASK 126
|
2014-01-20 18:53:18 -05:00
|
|
|
#define SYSCALL_FSTATVFS 127
|
|
|
|
#define SYSCALL_FSTATVFSAT 128
|
2013-09-14 14:05:17 -04:00
|
|
|
#define SYSCALL_RDMSR 129
|
|
|
|
#define SYSCALL_WRMSR 130
|
2013-09-16 15:16:35 -04:00
|
|
|
#define SYSCALL_SCHED_YIELD 131
|
2013-08-31 13:35:17 -04:00
|
|
|
#define SYSCALL_EXIT_THREAD 132
|
2013-08-04 14:24:59 -04:00
|
|
|
#define SYSCALL_SIGACTION 133
|
|
|
|
#define SYSCALL_SIGALTSTACK 134
|
|
|
|
#define SYSCALL_SIGPENDING 135
|
|
|
|
#define SYSCALL_SIGPROCMASK 136
|
|
|
|
#define SYSCALL_SIGSUSPEND 137
|
2014-01-16 14:46:56 -05:00
|
|
|
#define SYSCALL_SENDMSG 138
|
|
|
|
#define SYSCALL_RECVMSG 139
|
2014-02-28 11:10:08 -05:00
|
|
|
#define SYSCALL_GETSOCKOPT 140
|
|
|
|
#define SYSCALL_SETSOCKOPT 141
|
2014-05-05 15:36:40 -04:00
|
|
|
#define SYSCALL_TCGETBLOB 142
|
|
|
|
#define SYSCALL_TCSETBLOB 143
|
2014-06-27 17:26:59 -04:00
|
|
|
#define SYSCALL_GETPEERNAME 144
|
|
|
|
#define SYSCALL_GETSOCKNAME 145
|
2014-06-27 18:11:13 -04:00
|
|
|
#define SYSCALL_SHUTDOWN 146
|
2014-07-14 17:24:43 -04:00
|
|
|
#define SYSCALL_GETENTROPY 147
|
2014-10-05 09:02:50 -04:00
|
|
|
#define SYSCALL_GETHOSTNAME 148
|
|
|
|
#define SYSCALL_SETHOSTNAME 149
|
2014-05-07 08:14:38 -04:00
|
|
|
#define SYSCALL_UNMOUNTAT 150
|
|
|
|
#define SYSCALL_FSM_MOUNTAT 151
|
2015-05-13 11:48:53 -04:00
|
|
|
#define SYSCALL_CLOSEFROM 152
|
2015-07-30 19:20:39 -04:00
|
|
|
#define SYSCALL_RESERVED1 153
|
|
|
|
#define SYSCALL_PSCTL 154
|
2016-01-23 14:56:07 -05:00
|
|
|
#define SYSCALL_TCDRAIN 155
|
|
|
|
#define SYSCALL_TCFLOW 156
|
|
|
|
#define SYSCALL_TCFLUSH 157
|
|
|
|
#define SYSCALL_TCGETATTR 158
|
|
|
|
#define SYSCALL_TCGETSID 159
|
|
|
|
#define SYSCALL_TCSENDBREAK 160
|
|
|
|
#define SYSCALL_TCSETATTR 161
|
2015-10-27 12:34:54 -04:00
|
|
|
#define SYSCALL_SCRAM 162
|
|
|
|
#define SYSCALL_MAX_NUM 163 /* index of highest constant + 1 */
|
2011-10-26 18:05:20 -04:00
|
|
|
|
|
|
|
#endif
|