sortix-mirror/kernel/include/sortix/syscall.h

195 lines
6.1 KiB
C
Raw Normal View History

/*
* Copyright (c) 2011-2016, 2021 Jonas 'Sortie' Termansen.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* sortix/syscall.h
* Numeric constants identifying each system call.
*/
#ifndef _INCLUDE_SORTIX_SYSCALL_H
#define _INCLUDE_SORTIX_SYSCALL_H
#define SYSCALL_BAD_SYSCALL 0
#define SYSCALL_EXIT 1 /* OBSOLETE */
2014-02-23 13:41:51 +00: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 13:41:51 +00: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 18:52:29 +00:00
#define SYSCALL_GETPID 13
#define SYSCALL_GETPPID 14
2014-02-23 13:41:51 +00:00
#define SYSCALL_GET_FILEINFO 15 /* OBSOLETE */
#define SYSCALL_GET_NUM_FILES 16 /* OBSOLETE */
#define SYSCALL_WAITPID 17
2011-11-16 07:37:29 +00:00
#define SYSCALL_READ 18
#define SYSCALL_WRITE 19
2014-02-23 13:41:51 +00:00
#define SYSCALL_PIPE 20 /* OBSOLETE */
#define SYSCALL_CLOSE 21
#define SYSCALL_DUP 22
2014-02-23 13:41:51 +00:00
#define SYSCALL_OPEN 23 /* OBSOLETE */
#define SYSCALL_READDIRENTS 24
2014-02-23 13:41:51 +00: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 13:41:51 +00:00
#define SYSCALL_UPTIME 34 /* OBSOLETE */
#define SYSCALL_SBRK 35 /* OBSOLETE */
#define SYSCALL_LSEEK 36
#define SYSCALL_GETPAGESIZE 37
2014-02-23 13:41:51 +00: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 13:41:51 +00:00
#define SYSCALL_STAT 44 /* OBSOLETE */
2012-02-21 23:30:34 +00:00
#define SYSCALL_FSTAT 45
2012-03-04 20:36:40 +00:00
#define SYSCALL_FCNTL 46
2014-02-23 13:41:51 +00: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 15:30:34 +00:00
#define SYSCALL_RAISE 53
#define SYSCALL_OPENAT 54
2012-12-16 01:10:19 +00:00
#define SYSCALL_DISPMSG_ISSUE 55
#define SYSCALL_FSTATAT 56
2014-02-23 13:41:51 +00:00
#define SYSCALL_CHMOD 57 /* OBSOLETE */
#define SYSCALL_CHOWN 58 /* OBSOLETE */
#define SYSCALL_LINK 59 /* OBSOLETE */
2013-06-27 18:47:24 +00:00
#define SYSCALL_DUP2 60
2012-10-23 11:50:33 +00:00
#define SYSCALL_UNLINKAT 61
2012-10-23 21:55:33 +00:00
#define SYSCALL_FACCESSAT 62
2012-10-23 22:07:39 +00:00
#define SYSCALL_MKDIRAT 63
2012-10-24 11:06:12 +00:00
#define SYSCALL_FCHDIR 64
#define SYSCALL_TRUNCATEAT 65
2012-10-24 17:43:11 +00:00
#define SYSCALL_FCHOWNAT 66
2012-10-24 17:52:28 +00:00
#define SYSCALL_FCHOWN 67
2012-10-24 22:17:43 +00:00
#define SYSCALL_FCHMOD 68
2012-10-24 22:29:48 +00:00
#define SYSCALL_FCHMODAT 69
2012-10-25 13:43:53 +00:00
#define SYSCALL_LINKAT 70
2013-01-30 19:33:13 +00:00
#define SYSCALL_FSM_FSBIND 71
2012-12-29 22:09:09 +00:00
#define SYSCALL_PPOLL 72
2012-12-20 15:19:07 +00:00
#define SYSCALL_RENAMEAT 73
2013-03-19 19:18:15 +00:00
#define SYSCALL_READLINKAT 74
2013-03-20 12:16:12 +00:00
#define SYSCALL_FSYNC 75
2013-01-13 01:37:14 +00: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 20:35:51 +00:00
#define SYSCALL_IOCTL 84
2013-03-19 21:01:01 +00:00
#define SYSCALL_UTIMENSAT 85
#define SYSCALL_FUTIMENS 86
2013-03-19 21:40:37 +00: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 19:43:01 +00:00
#define SYSCALL_READV 93
#define SYSCALL_WRITEV 94
#define SYSCALL_PREADV 95
#define SYSCALL_PWRITEV 96
2013-10-13 21:56:58 +00: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 23:24:42 +00:00
#define SYSCALL_ALARMNS 102
2013-05-12 20:10:34 +00:00
#define SYSCALL_CLOCK_GETTIMERES 103
#define SYSCALL_CLOCK_SETTIMERES 104
2013-05-14 16:41:49 +00:00
#define SYSCALL_CLOCK_NANOSLEEP 105
2013-05-15 10:37:39 +00:00
#define SYSCALL_TIMENS 106
2013-05-16 20:03:15 +00:00
#define SYSCALL_UMASK 107
2013-05-29 12:03:53 +00:00
#define SYSCALL_FCHDIRAT 108
#define SYSCALL_FCHROOT 109
#define SYSCALL_FCHROOTAT 110
2013-06-01 11:24:27 +00:00
#define SYSCALL_MKPARTITION 111
2013-06-11 23:02:01 +00:00
#define SYSCALL_GETPGID 112
#define SYSCALL_SETPGID 113
2013-06-12 00:18:07 +00: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 15:35:30 +00:00
#define SYSCALL_GETPRIORITY 119
#define SYSCALL_SETPRIORITY 120
2013-08-30 21:55:09 +00:00
#define SYSCALL_PRLIMIT 121
2013-09-23 18:41:31 +00:00
#define SYSCALL_DUP3 122
2013-11-21 19:27:34 +00:00
#define SYSCALL_SYMLINKAT 123
2013-12-20 20:55:05 +00:00
#define SYSCALL_TCGETWINCURPOS 124
2014-01-15 18:46:36 +00:00
#define SYSCALL_PIPE2 125
2014-01-19 21:45:49 +00:00
#define SYSCALL_GETUMASK 126
#define SYSCALL_FSTATVFS 127
#define SYSCALL_FSTATVFSAT 128
2013-09-14 18:05:17 +00:00
#define SYSCALL_RDMSR 129
#define SYSCALL_WRMSR 130
2013-09-16 19:16:35 +00:00
#define SYSCALL_SCHED_YIELD 131
2013-08-31 17:35:17 +00: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 19:46:56 +00:00
#define SYSCALL_SENDMSG 138
#define SYSCALL_RECVMSG 139
2014-02-28 16:10:08 +00:00
#define SYSCALL_GETSOCKOPT 140
#define SYSCALL_SETSOCKOPT 141
2014-05-05 19:36:40 +00:00
#define SYSCALL_TCGETBLOB 142
#define SYSCALL_TCSETBLOB 143
2014-06-27 21:26:59 +00:00
#define SYSCALL_GETPEERNAME 144
#define SYSCALL_GETSOCKNAME 145
2014-06-27 22:11:13 +00:00
#define SYSCALL_SHUTDOWN 146
2014-07-14 21:24:43 +00:00
#define SYSCALL_GETENTROPY 147
2014-10-05 13:02:50 +00:00
#define SYSCALL_GETHOSTNAME 148
#define SYSCALL_SETHOSTNAME 149
2014-05-07 12:14:38 +00:00
#define SYSCALL_UNMOUNTAT 150
#define SYSCALL_FSM_MOUNTAT 151
2015-05-13 15:48:53 +00:00
#define SYSCALL_CLOSEFROM 152
#define SYSCALL_MKPTY 153
2015-07-30 23:20:39 +00:00
#define SYSCALL_PSCTL 154
2016-01-23 19:56:07 +00: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 16:34:54 +00:00
#define SYSCALL_SCRAM 162
#define SYSCALL_GETSID 163
#define SYSCALL_SETSID 164
#define SYSCALL_SOCKET 165
#define SYSCALL_GETDNSCONFIG 166
#define SYSCALL_SETDNSCONFIG 167
#define SYSCALL_FUTEX 168
#define SYSCALL_MAX_NUM 169 /* index of highest constant + 1 */
#endif