1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00
sortix--sortix/kernel/include/sortix/syscall.h

183 lines
5.8 KiB
C
Raw Normal View History

/*******************************************************************************
2014-01-19 16:45:49 -05:00
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013, 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/syscall.h
Numeric constants identifying each system call.
*******************************************************************************/
2013-05-03 15:43:01 -04:00
#ifndef INCLUDE_SORTIX_SYSCALLNUM_H
#define INCLUDE_SORTIX_SYSCALLNUM_H
#define SYSCALL_BAD_SYSCALL 0
#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 */
#define SYSCALL_EXECVE 10
2014-02-23 08:41:51 -05:00
#define SYSCALL_PRINT_PATH_FILES 11 /* OBSOLETE */
#define SYSCALL_FORK 12 /* OBSOLETE */
Implemented the fork() system call and what it needed to work properly. This commit got completely out of control. Added the fork(), getpid(), getppid(), sleep(), usleep() system calls, and aliases in the Maxsi:: namespace. Fixed a bug where zero-byte allocation would fail. Worked on the DescriptorTable class which now works and can fork. Got rid of some massive print-registers statements and replaced them with the portable InterruptRegisters::LogRegisters() function. Removed the SysExecuteOld function and replaced it with Process::Execute(). Rewrote the boot sequence in kernel.cpp such that it now loads the system idle process 'idle' as PID 0, and the initization process 'init' as PID 1. Rewrote the SIGINT hack. Processes now maintain a family-tree structure and keep track of their threads. PIDs are now allocated using a simple hack. Virtual memory per-process can now be allocated using a simple hack. Processes can now be forked. Fixed the Process::Execute function such that it now resets the stack pointer to where the stack actually is - not just a magic value. Removed the old and ugly Process::_endcodesection hack. Rewrote the scheduler into a much cleaner and faster version. Debug code is now moved to designated functions. The noop kernel-thread has been replaced by a simple user-space infinite-loop program 'idle'. The Thread class has been seperated from the Scheduler except in Scheduler- related code. Thread::{Save,Load}Registers has been improved and has been moved to $(CPU)/thread.cpp. Threads can now be forked. A new CreateThread function creates threads properly and portably. Added a MicrosecondsSinceBoot() function. Fixed a crucial bug in MemoryManagement::Fork(). Added an 'idle' user-space program that is a noop infinite loop, which is used by the scheduler when there is nothing to do. Rewrote the 'init' program such that it now forks off a shell, instead of becoming the shell. Added the $$ (current PID) and $PPID (parent PPID) variables to the shell.
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 */
#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 */
#define SYSCALL_CLOSE 21
#define SYSCALL_DUP 22
2014-02-23 08:41:51 -05:00
#define SYSCALL_OPEN 23 /* OBSOLETE */
#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 */
#define SYSCALL_SIGRETURN 30 /* OBSOLETE */
#define SYSCALL_KILL 31
#define SYSCALL_MEMSTAT 32
#define SYSCALL_ISATTY 33
2014-02-23 08:41:51 -05:00
#define SYSCALL_UPTIME 34 /* OBSOLETE */
#define SYSCALL_SBRK 35 /* OBSOLETE */
#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 */
#define SYSCALL_FTRUNCATE 41
#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 */
#define SYSCALL_KERNELINFO 48
#define SYSCALL_PREAD 49
#define SYSCALL_PWRITE 50
#define SYSCALL_TFORK 51
#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
#define SYSCALL_OPENAT 54
2012-12-15 20:10:19 -05:00
#define SYSCALL_DISPMSG_ISSUE 55
#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
#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
#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
#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
#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
#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
#define SYSCALL_MAX_NUM 152 /* index of highest constant + 1 */
#endif