Update MentOs code to the latest development version.

This commit is contained in:
Enrico Fraccaroli
2021-10-04 11:44:02 +02:00
parent 6fd063984a
commit b01eccca2e
484 changed files with 42358 additions and 20285 deletions
+3 -1
View File
@@ -1,7 +1,7 @@
/// MentOS, The Mentoring Operating system project
/// @file panic.h
/// @brief Functions used to manage kernel panic.
/// @copyright (c) 2019 This file is distributed under the MIT License.
/// @copyright (c) 2014-2021 This file is distributed under the MIT License.
/// See LICENSE.md for details.
#pragma once
@@ -10,3 +10,5 @@
/// the kernel.
/// @param msg The message that has to be shown.
void kernel_panic(const char *msg);
#define TODO(msg) kernel_panic(#msg);
+7 -4
View File
@@ -1,10 +1,13 @@
/// MentOS, The Mentoring Operating system project
/// @file printk.c
/// @brief
/// @copyright (c) 2019 This file is distributed under the MIT License.
/// @file printk.h
/// @brief Functions for managing the kernel messages.
/// @copyright (c) 2014-2021 This file is distributed under the MIT License.
/// See LICENSE.md for details.
#pragma once
/// @brief Write formatted output to stdout.
void printk(const char *, ...);
/// @param format Output formatted as for printf.
/// @param ... List of arguments.
/// @return The number of bytes written in syslog.
int sys_syslog(const char *format, ...);
+325
View File
@@ -0,0 +1,325 @@
/// MentOS, The Mentoring Operating system project
/// @file signal.h
/// @brief Signals definition.
/// @copyright (c) 2014-2021 This file is distributed under the MIT License.
/// See LICENSE.md for details.
#pragma once
#include "stdatomic.h"
#include "spinlock.h"
#include "list_head.h"
#include "syscall.h"
/// @brief Signal codes.
typedef enum {
SIGHUP = 1, ///< Hang up detected on controlling terminal or death of controlling process.
SIGINT = 2, ///< Issued if the user sends an interrupt signal (Ctrl + C).
SIGQUIT = 3, ///< Issued if the user sends a quit signal (Ctrl + D).
SIGILL = 4, ///< Illegal Instruction.
SIGTRAP = 5, ///< Trace/breakpoint trap.
SIGABRT = 6, ///< Abort signal from abort().
SIGEMT = 7, ///< Emulator trap.
SIGFPE = 8, ///< Floating-point arithmetic exception.
SIGKILL = 9, ///< If a process gets this signal it must quit immediately and will not perform any clean-up operations.
SIGBUS = 10, ///< Bus error (bad memory access).
SIGSEGV = 11, ///< Invalid memory reference.
SIGSYS = 12, ///< Bad system call (SVr4).
SIGPIPE = 13, ///< Broken pipe: write to pipe with no readers.
SIGALRM = 14, ///< Alarm clock signal (used for timers).
SIGTERM = 15, ///< Software termination signal (sent by kill by default).
SIGUSR1 = 16, ///< User-defined signal 1.
SIGUSR2 = 17, ///< User-defined signal 2.
SIGCHLD = 18, ///< Child stopped or terminated.
SIGPWR = 19, ///< Power failure.
SIGWINCH = 20, ///< Window resize signal.
SIGURG = 21, ///< Urgent condition on socket.
SIGPOLL = 22, ///< Pollable event.
SIGSTOP = 23, ///< Stop process.
SIGTSTP = 24, ///< Stop typed at terminal.
SIGCONT = 25, ///< Continue if stopped.
SIGTTIN = 26, ///< Terminal input for background process.
SIGTTOU = 27, ///< Terminal output for background process.
SIGVTALRM = 28, ///< Virtual alarm clock.
SIGPROF = 29, ///< Profiling timer expired.
SIGXCPU = 30, ///< CPU time limit exceeded.
SIGXFSZ = 31, ///< File size limit exceeded.
NSIG
} signal_type_t;
/// @brief Codes that indentify the sender of a signal.
typedef enum {
SI_NOINFO, ///< Unable to determine complete signal information.
// Signal : -
// Enabled fields : si_pid, si_uid
SI_USER, ///< Signal sent by kill(), pthread_kill(), raise(), abort() or alarm().
// Signal : -
// Enabled fields : -
SI_KERNEL, ///< Generic kernel function
// Signal : -
// Enabled fields : si_pid, si_uid, si_value
SI_QUEUE, ///< Signal was sent by sigqueue().
SI_TIMER, ///< Signal was generated by expiration of a timer set by timer_settimer().
SI_ASYNCIO, ///< Signal was generated by completion of an asynchronous I/O request.
SI_MESGQ, ///< Signal was generated by arrival of a message on an empty message queue.
// Signal : SIGILL
// Enabled fields : si_addr (address of failing instruction)
ILL_ILLOPC, ///< Illegal opcode.
ILL_ILLOPN, ///< Illegal operand.
ILL_ILLADR, ///< Illegal addressing mode.
ILL_ILLTRP, ///< Illegal trap.
ILL_PRVOPC, ///< Privileged opcode.
ILL_PRVREG, ///< Privileged register.
ILL_COPROC, ///< Coprocessor error.
ILL_BADSTK, ///< Internal stack error.
// Signal : SIGFPE
// Enabled fields : si_addr (address of failing instruction)
FPE_INTDIV, ///< Integer divide-by-zero.
FPE_INTOVF, ///< Integer overflow.
FPE_FLTDIV, ///< Floating point divide-by-zero.
FPE_FLTOVF, ///< Floating point overflow.
FPE_FLTUND, ///< Floating point underflow.
FPE_FLTRES, ///< Floating point inexact result.
FPE_FLTINV, ///< Invalid floating point operation.
FPE_FLTSUB, ///< Subscript out of range.
// Signal : SIGSEGV
// Enabled fields : si_addr (address of faulting memory reference)
SEGV_MAPERR, ///< Address not mapped.
SEGV_ACCERR, ///< Invalid permissions.
// Signal : SIGBUS
// Enabled fields : si_addr (address of faulting memory reference)
BUS_ADRALN, ///< Invalid address alignment.
BUS_ADRERR, ///< Non-existent physical address.
BUS_OBJERR, ///< Object-specific hardware error.
// Signal : SIGTRAP
// Enabled fields : -
TRAP_BRKPT, ///< Process breakpoint.
TRAP_TRACE, ///< Process trace trap.
// Signal : SIGCHLD
// Enabled fields : si_pid (child process ID)
// si_uid (real user ID of process that sent the signal)
// si_status (exit value or signal)
CLD_EXITED, ///< Child has exited.
CLD_KILLED, ///< Child has terminated abnormally and did not create a core file.
CLD_DUMPED, ///< Child has terminated abnormally and created a core file.
CLD_TRAPPED, ///< Traced child has trapped.
CLD_STOPPED, ///< Child has stopped.
CLD_CONTINUED, ///< Stopped child has continued.
// Signal : SIGIO/SIGPOLL
// Enabled fields : si_band
POLL_IN, ///< Data input available.
POLL_OUT, ///< Output buffers available.
POLL_MSG, ///< Input message available.
POLL_ERR, ///< I/O error.
POLL_PRI, ///< High priority input available.
POLL_HUP, ///< Device disconnected.
} signal_sender_code_t;
/// @brief Defines what to do with the provided signal mask.
typedef enum {
/// @brief The set of blocked signals is the union of the current set
/// and the set argument.
SIG_BLOCK,
/// @brief The signals in set are removed from the current set of
/// blocked signals. It is permissible to attempt to unblock
/// a signal which is not blocked.
SIG_UNBLOCK,
/// @brief The set of blocked signals is set to the argument set.
SIG_SETMASK
} sigmask_how_t;
/// @defgroup SigactionFlags Flags associated with a sigaction.
/// @{
#define SA_NOCLDSTOP 0x00000001U ///< Turn off SIGCHLD when children stop.
#define SA_NOCLDWAIT 0x00000002U ///< Flag on SIGCHLD to inhibit zombies.
#define SA_SIGINFO 0x00000004U ///< sa_sigaction specifies the signal-handling function for signum.
#define SA_ONSTACK 0x08000000U ///< Indicates that a registered stack_t will be used.
#define SA_RESTART 0x10000000U ///< Flag to get restarting signals (which were the default long ago)
#define SA_NODEFER 0x40000000U ///< Prevents the current signal from being masked in the handler.
#define SA_RESETHAND 0x80000000U ///< Clears the handler when the signal is delivered.
/// @}
/// Type of a signal handler.
typedef void (*sighandler_t)(int);
#define SIG_DFL ((sighandler_t)0) ///< Default signal handling.
#define SIG_IGN ((sighandler_t)1) ///< ignore signal.
#define SIG_ERR ((sighandler_t)-1) ///< error return from signal.
/// @brief Structure used to mask and unmask signals.
/// @details
/// Each unsigned long consists of 32 bits, thus, the maximum number of signals
/// that may be declared is 64.
/// Signals are divided into two cathegories, identified by the two unsigned longs:
/// [ 1, 31] corresponds to normal signals;
/// [32, 64] corresponds to real-time signals.
typedef struct sigset_t {
/// Signals divided into two cathegories.
unsigned long sig[2];
} sigset_t;
/// @brief Holds the information on how to handle a specific signal.
typedef struct sigaction_t {
/// This field specifies the type of action to be performed; its value can be a pointer
/// to the signal handler, SIG_DFL (that is, the value 0) to specify that the default
/// action is performed, or SIG_IGN (that is, the value 1) to specify that the signal is
/// ignored.
sighandler_t sa_handler;
/// This sigset_t variable specifies the signals to be masked when running the signal handler
sigset_t sa_mask;
/// This set of flags specifies how the signal must be handled;
unsigned int sa_flags;
} sigaction_t;
/// @brief Describes how each signal must be handled.
typedef struct sighand_t {
/// Usage counter of the signal handler descriptor.
atomic_t count;
/// Array of structures specifying the actions to be performed upon delivering the signals
sigaction_t action[NSIG];
/// Spinlock protecting both the signal descriptor and the signal handler descriptor.
spinlock_t siglock;
} sighand_t;
/// @brief Data passed with signal info.
typedef union sigval {
int sival_int; ///< Integer value.
void *sival_ptr; ///< Pointer value.
} sigval_t;
/// @brief Stores information about an occurrence of a specific signal.
typedef struct siginfo_t {
/// The signal number.
int si_signo;
/// A code identifying who raised the signal (see signal_sender_code_t).
int si_code;
/// Signal value.
sigval_t si_value;
/// The error code of the instruction that caused the signal to be raised, or 0 if there was no error.
int si_errno;
/// Process ID of sending process.
pid_t si_pid;
/// Real user ID of sending process.
uid_t si_uid;
/// Address at which fault occurred.
void *si_addr;
/// Exit value or signal for process termination.
int si_status;
/// Band event for SIGPOLL/SIGIO.
int si_band;
} siginfo_t;
/// @brief An entry of the signal queue.
typedef struct sigqueue_t {
/// Links for the pending signal queues list.
list_head list;
/// Flags associated with the queued signal.
int flags;
/// Describes the event that raised the signal.
siginfo_t info;
// Pointer to the user data structure of the processs owner.
//struct user_struct *user;
} sigqueue_t;
/// @brief Keeps information of pending signals.
typedef struct sigpending_t {
/// Head of the list of pending signals.
list_head list;
/// The mask which can be queried to know which signals are pending.
sigset_t signal;
} sigpending_t;
/// These can be the second arg to send_sig_info/send_group_sig_info.
#define SEND_SIG_NOINFO ((siginfo_t *)0)
/// @brief Handle the return from a signal handler.
/// @param f The stack frame when returning from a signal handler.
/// @return never.
long sys_sigreturn(struct pt_regs *f);
/// @brief Handles the signals of the current process.
/// @param f The address of the stack area where the User Mode register
/// contents of the current process are saved.
/// @return If we are handling a signal, thus, `regs` have been modified
/// to handle it (e.g., eip is now poiting at the handler).
int do_signal(struct pt_regs *f);
/// @brief Initialize the signals.
/// @return 1 on success, 0 on failure.
int signals_init();
/// @brief Send signal to one specific process.
/// @param pid The PID of the process.
/// @param sig The signal to be sent.
/// @return
int sys_kill(pid_t pid, int sig);
/// @brief Sets the disposition of the signal signum to handler.
/// @param signum The signal number.
/// @param handler The handler for the signal.
/// @return The previous value of the signal handler, or SIG_ERR on error.
sighandler_t sys_signal(int signum, sighandler_t handler);
/// @brief Examine and change a signal action.
/// @param signum Specifies the signal and can be any valid signal except SIGKILL and SIGSTOP.
/// @param act If non-NULL, the new action for signal signum is installed from act.
/// @param oldact If non-NULL, the previous action is saved in oldact.
/// @return returns 0 on success; on error, -1 is returned, and errno is set to indicate the error.
int sys_sigaction(int signum, const sigaction_t *act, sigaction_t *oldact);
/// @brief Examine and change blocked signals.
/// @param how Determines the behavior of the call.
/// @param set The set of signals to manage by the function.
/// @param oldset If non-NULL, the previous value of the signal mask is stored here.
/// @return returns 0 on success, and -1 on error (errno is set to indicate the cause).
/// @details
/// If set is NULL, then the signal mask is unchanged (i.e., how is
/// ignored), but the current value of the signal mask is
/// nevertheless returned in oldset (if it is not NULL).
int sys_sigprocmask(int how, const sigset_t *set, sigset_t *oldset);
/// @brief Returns the string describing the given signal.
/// @param sig The signal to inquire.
/// @return String representing the signal.
const char *strsignal(int sig);
/// @brief Prepare an empty set.
/// @param set The set to manipulate.
/// @return 0 on success and -1 on error.
int sigemptyset(sigset_t *set);
/// @brief Prepare a full set.
/// @param set The set to manipulate.
/// @return 0 on success and -1 on error.
int sigfillset(sigset_t *set);
/// @brief Adds the given signal to the correct set.
/// @param set The set to manipulate.
/// @param signum The signalt to handle.
/// @return 0 on success and -1 on error.
int sigaddset(sigset_t *set, int signum);
/// @brief Removes the given signal to the correct set.
/// @param set The set to manipulate.
/// @param signum The signalt to handle.
/// @return 0 on success and -1 on error.
int sigdelset(sigset_t *set, int signum);
/// @brief Checks if the given signal is part of the set.
/// @param set The set to manipulate.
/// @param signum The signalt to handle.
/// @return 1 if signum is a member of set,
/// 0 if signum is not a member, and -1 on error.
int sigismember(sigset_t *set, int signum);
-121
View File
@@ -1,121 +0,0 @@
/// MentOS, The Mentoring Operating system project
/// @file signal_defs.h
/// @brief
/// @copyright (c) 2019 This file is distributed under the MIT License.
/// See LICENSE.md for details.
// Signal names (from the Unix specification on signals)
/// Hangup.
#define SIGHUP 1
/// Interupt.
#define SIGINT 2
/// Quit.
#define SIGQUIT 3
/// Illegal instruction.
#define SIGILL 4
/// A breakpoint or trace instruction has been reached.
#define SIGTRAP 5
/// Another process has requested that you abort.
#define SIGABRT 6
/// Emulation trap XXX.
#define SIGEMT 7
/// Floating-point arithmetic exception.
#define SIGFPE 8
/// You have been stabbed repeated with a large knife.
#define SIGKILL 9
/// Bus error (device error).
#define SIGBUS 10
/// Segmentation fault.
#define SIGSEGV 11
/// Bad system call.
#define SIGSYS 12
/// Attempted to read or write from a broken pipe.
#define SIGPIPE 13
/// This is your wakeup call.
#define SIGALRM 14
/// You have been Schwarzenegger'd.
#define SIGTERM 15
/// User Defined Signal #1.
#define SIGUSR1 16
/// User Defined Signal #2.
#define SIGUSR2 17
/// Child status report.
#define SIGCHLD 18
/// We need moar powah!.
#define SIGPWR 19
/// Your containing terminal has changed size.
#define SIGWINCH 20
/// An URGENT! event (On a socket).
#define SIGURG 21
/// XXX OBSOLETE; socket i/o possible.
#define SIGPOLL 22
/// Stopped (signal).
#define SIGSTOP 23
/// ^Z (suspend).
#define SIGTSTP 24
/// Unsuspended (please, continue).
#define SIGCONT 25
/// TTY input has stopped.
#define SIGTTIN 26
/// TTY output has stopped.
#define SIGTTOUT 27
/// Virtual timer has expired.
#define SIGVTALRM 28
/// Profiling timer expired.
#define SIGPROF 29
/// CPU time limit exceeded.
#define SIGXCPU 30
/// File size limit exceeded.
#define SIGXFSZ 31
/// Herp.
#define SIGWAITING 32
/// Die in a fire.
#define SIGDIAF 33
/// The sending process does not like you.
#define SIGHATE 34
/// Window server event.
#define SIGWINEVENT 35
/// Everybody loves cats.
#define SIGCAT 36
#define SIGTTOU 37
#define NUMSIGNALS 38
#define NSIG NUMSIGNALS
+135 -18
View File
@@ -1,40 +1,56 @@
/// MentOS, The Mentoring Operating system project
/// @file syscall.h
/// @brief System Call handler definition.
/// @copyright (c) 2019 This file is distributed under the MIT License.
/// @copyright (c) 2014-2021 This file is distributed under the MIT License.
/// See LICENSE.md for details.
#pragma once
#include "syscall_types.h"
#include "vfs_types.h"
#include "kernel.h"
#include "dirent.h"
#include "sys/dirent.h"
#include "types.h"
#include "stat.h"
/// @brief Initialize the system calls.
void syscall_init();
/// @brief Handler for the system calls.
void syscall_handler(pt_regs *r);
/// @param f The interrupt stack frame.
void syscall_handler(pt_regs *f);
/// @brief Returns the current interrupt stack frame.
/// @return Pointer to the stack frame.
pt_regs* get_current_interrupt_stack_frame();
/// The exit() function causes normal process termination.
/// @param exit_code The exit code.
void sys_exit(int exit_code);
/// @brief Read data from a file descriptor.
/// @brief Read data from a file descriptor.
/// @param fd The file descriptor.
/// @param buf The buffer.
/// @param nbytes The number of bytes to read.
/// @return The number of read characters.
/// @return The number of read characters.
ssize_t sys_read(int fd, void *buf, size_t nbytes);
/// @brief Write data into a file descriptor.
/// @brief Write data into a file descriptor.
/// @param fd The file descriptor.
/// @param buf The buffer collecting data to written.
/// @param nbytes The number of bytes to write.
/// @return The number of written bytes.
/// @return The number of written bytes.
ssize_t sys_write(int fd, void *buf, size_t nbytes);
/// @brief Repositions the file offset inside a file.
/// @param fd The file descriptor of the file.
/// @param offset The offest to use for the operation.
/// @param whence The type of operation.
/// @return Upon successful completion, returns the resulting offset
/// location as measured in bytes from the beginning of the file. On
/// error, the value (off_t) -1 is returned and errno is set to
/// indicate the error.
off_t sys_lseek(int fd, off_t offset, int whence);
/// @brief Given a pathname for a file, open() returns a file
/// descriptor, a small, nonnegative integer for use in
/// subsequent system calls.
@@ -52,33 +68,134 @@ int sys_open(const char *pathname, int flags, mode_t mode);
/// @return
int sys_close(int fd);
/// @brief Delete a name and possibly the file it refers to.
/// @param path A pathname for a file.
/// @return On success, zero is returned. On error, -1 is returned, and errno is set appropriately.
int sys_unlink(const char *path);
/// @brief Suspends execution of the calling thread until a child specified
/// by pid argument has changed state.
/// by pid argument has changed state.
/// @param pid The pid to wait.
/// @param status If not NULL, store status information here.
/// @param options Determines the wait behaviour.
/// @return on success, returns the process ID of the terminated
/// child; on error, -1 is returned.
pid_t sys_waitpid(pid_t pid, int *status, int options);
/// @brief Replaces the current process image with a new process image.
int sys_execve(pt_regs *r);
/// @param f CPU registers whe calling this function.
/// @return 0 on success, -1 on error.
int sys_execve(pt_regs *f);
/// @brief Changes the working directory.
/// @param path The new working directory.
void sys_chdir(char const *path);
/// Returns the process ID (PID) of the calling process.
/// @brief Changes the working directory.
/// @param fd File descriptor of the new working directory.
void sys_fchdir(int fd);
/// @brief Returns the process ID (PID) of the calling process.
/// @return The process ID.
pid_t sys_getpid();
/// @brief Adds the increment to the priority value of the task.
int sys_nice(int increment);
///@brief Return session id of the given process.
/// If pid == 0 return the SID of the calling process
/// If pid != 0 return the SID corresponding to the process having identifier == pid
///@param pid process identifier from wich we want the SID
///@return On success return SID of the session
/// Otherwise return -1 with errno set on: EPERM or ESRCH
pid_t sys_getsid(pid_t pid);
/// Returns the parent process ID (PPID) of the calling process.
///@brief creates a new session if the calling process is not a
/// process group leader. The calling process is the leader of the
/// new session (i.e., its session ID is made the same as its process
/// ID). The calling process also becomes the process group leader
/// of a new process group in the session (i.e., its process group ID
/// is made the same as its process ID).
///@return On success return SID of the session just created
/// Otherwise return -1 with errno : EPERM
pid_t sys_setsid();
///@brief returns the group ID of the calling process.
///@return GID of the current process
pid_t sys_getgid();
///@brief sets the effective group ID of the calling process.
///@param pid process identifier to
///@return On success, zero is returned.
/// Otherwise returns -1 with errno set to :EINVAL or EPERM
int sys_setgid(pid_t pid);
/// @brief Returns the parent process ID (PPID) of the calling process.
/// @return The parent process ID.
pid_t sys_getppid();
/// @brief Adds the increment to the priority value of the task.
/// @param increment The modifier to apply to the nice value.
/// @return The new nice value.
int sys_nice(int increment);
/// @brief Reboots the system, or enables/disables the reboot keystroke.
/// @param magic1 fails (with the error EINVAL) unless equals LINUX_REBOOT_MAGIC1.
/// @param magic2 fails (with the error EINVAL) unless equals LINUX_REBOOT_MAGIC2.
/// @param cmd The command to send to the reboot.
/// @param arg Argument passed with some specific commands.
/// @return For the values of cmd that stop or restart the system, a
/// successful call to reboot() does not return. For the other cmd
/// values, zero is returned on success. In all cases, -1 is
/// returned on failure, and errno is set appropriately.
int sys_reboot(int magic1, int magic2, unsigned int cmd, void *arg);
void sys_getcwd(char *path, size_t size);
/// @brief Get current working directory.
/// @param buf The array where the CWD will be copied.
/// @param size The size of the array.
/// @return On success, returns the same pointer to buf.
/// On failure, returnr NULL, and errno is set to indicate the error.
char *sys_getcwd(char *buf, size_t size);
/// @brief Create a child process.
pid_t sys_vfork(pt_regs *r);
/// @brief Clone the calling process, but without copying the whole address space.
/// The calling process is suspended until the new process exits or is
/// replaced by a call to `execve'.
/// @param f CPU registers whe calling this function.
/// @return Return -1 for errors, 0 to the new process, and the process ID of
/// the new process to the old process.
pid_t sys_fork(pt_regs *f);
/// @brief Stat the file at the given path.
/// @param path Path to the file for which we are retrieving the statistics.
/// @param buf Buffer where we are storing the statistics.
/// @return 0 on success, a negative number if fails and errno is set.
int sys_stat(const char *path, stat_t *buf);
/// @brief Retrieves information about the file at the given location.
/// @param fd The file descriptor of the file that is being inquired.
/// @param buf A structure where data about the file will be stored.
/// @return Returns a negative value on failure.
int sys_fstat(int fd, stat_t *buf);
/// @brief Creates a new directory at the given path.
/// @param path The path of the new directory.
/// @param mode The permission of the new directory.
/// @return Returns a negative value on failure.
int sys_mkdir(const char *path, mode_t mode);
dirent_t *sys_readdir(DIR *dirp);
/// @brief Removes the given directory.
/// @param path The path to the directory to remove.
/// @return Returns a negative value on failure.
int sys_rmdir(const char *path);
/// Provide access to the directory entries.
/// @param fd The file descriptor of the directory for which we accessing
/// the entries.
/// @param dirp The buffer where de data should be placed.
/// @param count The size of the buffer.
/// @return On success, the number of bytes read is returned. On end of
/// directory, 0 is returned. On error, -1 is returned, and errno is set
/// appropriately.
int sys_getdents(int fd, dirent_t *dirp, unsigned int count);
/// @brief Returns the current time.
/// @param time Where the time should be stored.
/// @return The current time.
time_t sys_time(time_t *time);
+191 -214
View File
@@ -1,220 +1,197 @@
/// MentOS, The Mentoring Operating system project
/// @file syscall_number.h
/// @file syscall_types.h
/// @brief System Call numbers.
/// @copyright (c) 2019 This file is distributed under the MIT License.
/// @copyright (c) 2014-2021 This file is distributed under the MIT License.
/// See LICENSE.md for details.
#pragma once
// Return result in eax ("=a").
// System call number in eax ("a").
#define DEFN_SYSCALL0(__res, num) \
__asm__ __volatile__("INT $0x80" : "=a"(__res) : "a"(num))
// Return result in eax ("=a").
// System call number in eax ("a").
// p1 in ebx ("+b").
#define DEFN_SYSCALL1(__res, num, p1) \
__asm__ __volatile__("INT $0x80" : "=a"(__res), "+b"(p1) : "a"(num))
#define DEFN_SYSCALL2(__res, num, p1, p2) \
__asm__ __volatile__("INT $0x80" \
: "=a"(__res), "+b"(p1), "+c"(p2) \
: "a"(num));
#define DEFN_SYSCALL3(__res, num, p1, p2, p3) \
__asm__ __volatile__("INT $0x80" \
: "=a"(__res), "+b"(p1), "+c"(p2), "+d"(p3) \
: "a"(num))
#define DEFN_SYSCALL4(__res, num, p1, p2, p3, p4) \
__asm__ __volatile__("INT $0x80" \
: "=a"(__res), "+b"(p1), "+c"(p2), "+d"(p3), "+S"(p4) \
: "a"(num))
#define DEFN_SYSCALL5(__res, num, p1, p2, p3, p4, p5) \
__asm__ __volatile__("INT $0x80" \
: "=a"(__res), "+b"(p1), "+c"(p2), "+d"(p3), \
"+S"(p4), "+D"(p5) \
: "a"(num))
#define __NR_exit 1
#define __NR_fork 2
#define __NR_read 3
#define __NR_write 4
#define __NR_open 5
#define __NR_close 6
#define __NR_waitpid 7
#define __NR_creat 8
#define __NR_link 9
#define __NR_unlink 10
#define __NR_execve 11
#define __NR_chdir 12
#define __NR_time 13
#define __NR_mknod 14
#define __NR_chmod 15
#define __NR_lchown 16
#define __NR_stat 18
#define __NR_lseek 19
#define __NR_getpid 20
#define __NR_mount 21
#define __NR_oldumount 22
#define __NR_setuid 23
#define __NR_getuid 24
#define __NR_stime 25
#define __NR_ptrace 26
#define __NR_alarm 27
#define __NR_fstat 28
#define __NR_pause 29
#define __NR_utime 30
#define __NR_access 33
#define __NR_nice 34
#define __NR_sync 36
#define __NR_kill 37
#define __NR_rename 38
#define __NR_mkdir 39
#define __NR_rmdir 40
#define __NR_dup 41
#define __NR_pipe 42
#define __NR_times 43
#define __NR_brk 45
#define __NR_setgid 46
#define __NR_getgid 47
#define __NR_signal 48
#define __NR_geteuid 49
#define __NR_getegid 50
#define __NR_acct 51
#define __NR_umount 52
#define __NR_ioctl 54
#define __NR_fcntl 55
#define __NR_setpgid 57
#define __NR_olduname 59
#define __NR_umask 60
#define __NR_chroot 61
#define __NR_ustat 62
#define __NR_dup2 63
#define __NR_getppid 64
#define __NR_getpgrp 65
#define __NR_setsid 66
#define __NR_sigaction 67
#define __NR_sgetmask 68
#define __NR_ssetmask 69
#define __NR_setreuid 70
#define __NR_setregid 71
#define __NR_sigsuspend 72
#define __NR_sigpending 73
#define __NR_sethostname 74
#define __NR_setrlimit 75
#define __NR_getrlimit 76
#define __NR_getrusage 77
#define __NR_gettimeofday 78
#define __NR_settimeofday 79
#define __NR_getgroups 80
#define __NR_setgroups 81
#define __NR_symlink 83
#define __NR_lstat 84
#define __NR_readlink 85
#define __NR_uselib 86
#define __NR_swapon 87
#define __NR_reboot 88
#define __NR_readdir 89
#define __NR_mmap 90
#define __NR_munmap 91
#define __NR_truncate 92
#define __NR_ftruncate 93
#define __NR_fchmod 94
#define __NR_fchown 95
#define __NR_getpriority 96
#define __NR_setpriority 97
#define __NR_statfs 99
#define __NR_fstatfs 100
#define __NR_ioperm 101
#define __NR_socketcall 102
#define __NR_syslog 103
#define __NR_setitimer 104
#define __NR_getitimer 105
#define __NR_newstat 106
#define __NR_newlstat 107
#define __NR_newfstat 108
#define __NR_uname 109
#define __NR_iopl 110
#define __NR_vhangup 111
#define __NR_idle 112
#define __NR_vm86old 113
#define __NR_wait4 114
#define __NR_swapoff 115
#define __NR_sysinfo 116
#define __NR_ipc 117
#define __NR_fsync 118
#define __NR_sigreturn 119
#define __NR_clone 120
#define __NR_setdomainname 121
#define __NR_newuname 122
#define __NR_modify_ldt 123
#define __NR_adjtimex 124
#define __NR_mprotect 125
#define __NR_sigprocmask 126
#define __NR_create_module 127
#define __NR_init_module 128
#define __NR_delete_module 129
#define __NR_get_kernel_syms 130
#define __NR_quotactl 131
#define __NR_getpgid 132
#define __NR_fchdir 133
#define __NR_bdflush 134
#define __NR_sysfs 135
#define __NR_personality 136
#define __NR_setfsuid 138
#define __NR_setfsgid 139
#define __NR_llseek 140
#define __NR_getdents 141
#define __NR_select 142
#define __NR_flock 143
#define __NR_msync 144
#define __NR_readv 145
#define __NR_writev 146
#define __NR_getsid 147
#define __NR_fdatasync 148
#define __NR_sysctl 149
#define __NR_mlock 150
#define __NR_munlock 151
#define __NR_mlockall 152
#define __NR_munlockall 153
#define __NR_sched_setparam 154
#define __NR_sched_getparam 155
#define __NR_sched_setscheduler 156
#define __NR_sched_getscheduler 157
#define __NR_sched_yield 158
#define __NR_sched_get_priority_max 159
#define __NR_sched_get_priority_min 160
#define __NR_sched_rr_get_interval 161
#define __NR_nanosleep 162
#define __NR_mremap 163
#define __NR_setresuid 164
#define __NR_getresuid 165
#define __NR_vm86 166
#define __NR_query_module 167
#define __NR_poll 168
#define __NR_nfsservctl 169
#define __NR_setresgid 170
#define __NR_getresgid 171
#define __NR_prctl 172
#define __NR_rt_sigreturn 173
#define __NR_rt_sigaction 174
#define __NR_rt_sigprocmask 175
#define __NR_rt_sigpending 176
#define __NR_rt_sigtimedwait 177
#define __NR_rt_sigqueueinfo 178
#define __NR_rt_sigsuspend 179
#define __NR_pread 180
#define __NR_pwrite 181
#define __NR_chown 182
#define __NR_getcwd 183
#define __NR_capget 184
#define __NR_capset 185
#define __NR_sigaltstack 186
#define __NR_sendfile 187
#define __NR_vfork 188
#define __NR_free 189 // TODO: remove me!
#define SYSCALL_NUMBER 190
#define __NR_exit 1 ///< System-call number for `exit`
#define __NR_fork 2 ///< System-call number for `fork`
#define __NR_read 3 ///< System-call number for `read`
#define __NR_write 4 ///< System-call number for `write`
#define __NR_open 5 ///< System-call number for `open`
#define __NR_close 6 ///< System-call number for `close`
#define __NR_waitpid 7 ///< System-call number for `waitpid`
#define __NR_creat 8 ///< System-call number for `creat`
#define __NR_link 9 ///< System-call number for `link`
#define __NR_unlink 10 ///< System-call number for `unlink`
#define __NR_execve 11 ///< System-call number for `execve`
#define __NR_chdir 12 ///< System-call number for `chdir`
#define __NR_time 13 ///< System-call number for `time`
#define __NR_mknod 14 ///< System-call number for `mknod`
#define __NR_chmod 15 ///< System-call number for `chmod`
#define __NR_lchown 16 ///< System-call number for `lchown`
#define __NR_stat 18 ///< System-call number for `stat`
#define __NR_lseek 19 ///< System-call number for `lseek`
#define __NR_getpid 20 ///< System-call number for `getpid`
#define __NR_mount 21 ///< System-call number for `mount`
#define __NR_oldumount 22 ///< System-call number for `oldumount`
#define __NR_setuid 23 ///< System-call number for `setuid`
#define __NR_getuid 24 ///< System-call number for `getuid`
#define __NR_stime 25 ///< System-call number for `stime`
#define __NR_ptrace 26 ///< System-call number for `ptrace`
#define __NR_alarm 27 ///< System-call number for `alarm`
#define __NR_fstat 28 ///< System-call number for `fstat`
#define __NR_pause 29 ///< System-call number for `pause`
#define __NR_utime 30 ///< System-call number for `utime`
#define __NR_access 33 ///< System-call number for `access`
#define __NR_nice 34 ///< System-call number for `nice`
#define __NR_sync 36 ///< System-call number for `sync`
#define __NR_kill 37 ///< System-call number for `kill`
#define __NR_rename 38 ///< System-call number for `rename`
#define __NR_mkdir 39 ///< System-call number for `mkdir`
#define __NR_rmdir 40 ///< System-call number for `rmdir`
#define __NR_dup 41 ///< System-call number for `dup`
#define __NR_pipe 42 ///< System-call number for `pipe`
#define __NR_times 43 ///< System-call number for `times`
#define __NR_brk 45 ///< System-call number for `brk`
#define __NR_setgid 46 ///< System-call number for `setgid`
#define __NR_getgid 47 ///< System-call number for `getgid`
#define __NR_signal 48 ///< System-call number for `signal`
#define __NR_geteuid 49 ///< System-call number for `geteuid`
#define __NR_getegid 50 ///< System-call number for `getegid`
#define __NR_acct 51 ///< System-call number for `acct`
#define __NR_umount 52 ///< System-call number for `umount`
#define __NR_ioctl 54 ///< System-call number for `ioctl`
#define __NR_fcntl 55 ///< System-call number for `fcntl`
#define __NR_setpgid 57 ///< System-call number for `setpgid`
#define __NR_olduname 59 ///< System-call number for `olduname`
#define __NR_umask 60 ///< System-call number for `umask`
#define __NR_chroot 61 ///< System-call number for `chroot`
#define __NR_ustat 62 ///< System-call number for `ustat`
#define __NR_dup2 63 ///< System-call number for `dup2`
#define __NR_getppid 64 ///< System-call number for `getppid`
#define __NR_getpgrp 65 ///< System-call number for `getpgrp`
#define __NR_setsid 66 ///< System-call number for `setsid`
#define __NR_sigaction 67 ///< System-call number for `sigaction`
#define __NR_sgetmask 68 ///< System-call number for `sgetmask`
#define __NR_ssetmask 69 ///< System-call number for `ssetmask`
#define __NR_setreuid 70 ///< System-call number for `setreuid`
#define __NR_setregid 71 ///< System-call number for `setregid`
#define __NR_sigsuspend 72 ///< System-call number for `sigsuspend`
#define __NR_sigpending 73 ///< System-call number for `sigpending`
#define __NR_sethostname 74 ///< System-call number for `sethostname`
#define __NR_setrlimit 75 ///< System-call number for `setrlimit`
#define __NR_getrlimit 76 ///< System-call number for `getrlimit`
#define __NR_getrusage 77 ///< System-call number for `getrusage`
#define __NR_gettimeofday 78 ///< System-call number for `gettimeofday`
#define __NR_settimeofday 79 ///< System-call number for `settimeofday`
#define __NR_getgroups 80 ///< System-call number for `getgroups`
#define __NR_setgroups 81 ///< System-call number for `setgroups`
#define __NR_symlink 83 ///< System-call number for `symlink`
#define __NR_lstat 84 ///< System-call number for `lstat`
#define __NR_readlink 85 ///< System-call number for `readlink`
#define __NR_uselib 86 ///< System-call number for `uselib`
#define __NR_swapon 87 ///< System-call number for `swapon`
#define __NR_reboot 88 ///< System-call number for `reboot`
#define __NR_readdir 89 ///< System-call number for `readdir`
#define __NR_mmap 90 ///< System-call number for `mmap`
#define __NR_munmap 91 ///< System-call number for `munmap`
#define __NR_truncate 92 ///< System-call number for `truncate`
#define __NR_ftruncate 93 ///< System-call number for `ftruncate`
#define __NR_fchmod 94 ///< System-call number for `fchmod`
#define __NR_fchown 95 ///< System-call number for `fchown`
#define __NR_getpriority 96 ///< System-call number for `getpriority`
#define __NR_setpriority 97 ///< System-call number for `setpriority`
#define __NR_statfs 99 ///< System-call number for `statfs`
#define __NR_fstatfs 100 ///< System-call number for `fstatfs`
#define __NR_ioperm 101 ///< System-call number for `ioperm`
#define __NR_socketcall 102 ///< System-call number for `socketcall`
#define __NR_syslog 103 ///< System-call number for `syslog`
#define __NR_setitimer 104 ///< System-call number for `setitimer`
#define __NR_getitimer 105 ///< System-call number for `getitimer`
#define __NR_newstat 106 ///< System-call number for `newstat`
#define __NR_newlstat 107 ///< System-call number for `newlstat`
#define __NR_newfstat 108 ///< System-call number for `newfstat`
#define __NR_uname 109 ///< System-call number for `uname`
#define __NR_iopl 110 ///< System-call number for `iopl`
#define __NR_vhangup 111 ///< System-call number for `vhangup`
#define __NR_idle 112 ///< System-call number for `idle`
#define __NR_vm86old 113 ///< System-call number for `vm86old`
#define __NR_wait4 114 ///< System-call number for `wait4`
#define __NR_swapoff 115 ///< System-call number for `swapoff`
#define __NR_sysinfo 116 ///< System-call number for `sysinfo`
#define __NR_ipc 117 ///< System-call number for `ipc`
#define __NR_fsync 118 ///< System-call number for `fsync`
#define __NR_sigreturn 119 ///< System-call number for `sigreturn`
#define __NR_clone 120 ///< System-call number for `clone`
#define __NR_setdomainname 121 ///< System-call number for `setdomainname`
#define __NR_newuname 122 ///< System-call number for `newuname`
#define __NR_modify_ldt 123 ///< System-call number for `modify_ldt`
#define __NR_adjtimex 124 ///< System-call number for `adjtimex`
#define __NR_mprotect 125 ///< System-call number for `mprotect`
#define __NR_sigprocmask 126 ///< System-call number for `sigprocmask`
#define __NR_create_module 127 ///< System-call number for `create_module`
#define __NR_init_module 128 ///< System-call number for `init_module`
#define __NR_delete_module 129 ///< System-call number for `delete_module`
#define __NR_get_kernel_syms 130 ///< System-call number for `get_kernel_syms`
#define __NR_quotactl 131 ///< System-call number for `quotactl`
#define __NR_getpgid 132 ///< System-call number for `getpgid`
#define __NR_fchdir 133 ///< System-call number for `fchdir`
#define __NR_bdflush 134 ///< System-call number for `bdflush`
#define __NR_sysfs 135 ///< System-call number for `sysfs`
#define __NR_personality 136 ///< System-call number for `personality`
#define __NR_setfsuid 138 ///< System-call number for `setfsuid`
#define __NR_setfsgid 139 ///< System-call number for `setfsgid`
#define __NR_llseek 140 ///< System-call number for `llseek`
#define __NR_getdents 141 ///< System-call number for `getdents`
#define __NR_select 142 ///< System-call number for `select`
#define __NR_flock 143 ///< System-call number for `flock`
#define __NR_msync 144 ///< System-call number for `msync`
#define __NR_readv 145 ///< System-call number for `readv`
#define __NR_writev 146 ///< System-call number for `writev`
#define __NR_getsid 147 ///< System-call number for `getsid`
#define __NR_fdatasync 148 ///< System-call number for `fdatasync`
#define __NR_sysctl 149 ///< System-call number for `sysctl`
#define __NR_mlock 150 ///< System-call number for `mlock`
#define __NR_munlock 151 ///< System-call number for `munlock`
#define __NR_mlockall 152 ///< System-call number for `mlockall`
#define __NR_munlockall 153 ///< System-call number for `munlockall`
#define __NR_sched_setparam 154 ///< System-call number for `sched_setparam`
#define __NR_sched_getparam 155 ///< System-call number for `sched_getparam`
#define __NR_sched_setscheduler 156 ///< System-call number for `sched_setscheduler`
#define __NR_sched_getscheduler 157 ///< System-call number for `sched_getscheduler`
#define __NR_sched_yield 158 ///< System-call number for `sched_yield`
#define __NR_sched_get_priority_max 159 ///< System-call number for `sched_get_priority_max`
#define __NR_sched_get_priority_min 160 ///< System-call number for `sched_get_priority_min`
#define __NR_sched_rr_get_interval 161 ///< System-call number for `sched_rr_get_interval`
#define __NR_nanosleep 162 ///< System-call number for `nanosleep`
#define __NR_mremap 163 ///< System-call number for `mremap`
#define __NR_setresuid 164 ///< System-call number for `setresuid`
#define __NR_getresuid 165 ///< System-call number for `getresuid`
#define __NR_vm86 166 ///< System-call number for `vm86`
#define __NR_query_module 167 ///< System-call number for `query_module`
#define __NR_poll 168 ///< System-call number for `poll`
#define __NR_nfsservctl 169 ///< System-call number for `nfsservctl`
#define __NR_setresgid 170 ///< System-call number for `setresgid`
#define __NR_getresgid 171 ///< System-call number for `getresgid`
#define __NR_prctl 172 ///< System-call number for `prctl`
#define __NR_rt_sigreturn 173 ///< System-call number for `rt_sigreturn`
#define __NR_rt_sigaction 174 ///< System-call number for `rt_sigaction`
#define __NR_rt_sigprocmask 175 ///< System-call number for `rt_sigprocmask`
#define __NR_rt_sigpending 176 ///< System-call number for `rt_sigpending`
#define __NR_rt_sigtimedwait 177 ///< System-call number for `rt_sigtimedwait`
#define __NR_rt_sigqueueinfo 178 ///< System-call number for `rt_sigqueueinfo`
#define __NR_rt_sigsuspend 179 ///< System-call number for `rt_sigsuspend`
#define __NR_pread 180 ///< System-call number for `pread`
#define __NR_pwrite 181 ///< System-call number for `pwrite`
#define __NR_chown 182 ///< System-call number for `chown`
#define __NR_getcwd 183 ///< System-call number for `getcwd`
#define __NR_capget 184 ///< System-call number for `capget`
#define __NR_capset 185 ///< System-call number for `capset`
#define __NR_sigaltstack 186 ///< System-call number for `sigaltstack`
#define __NR_sendfile 187 ///< System-call number for `sendfile`
#define __NR_waitperiod 188 ///< System-call number for `waitperiod`
#define __NR_msgctl 189 ///< System-call number for `msgctl`
#define __NR_msgget 190 ///< System-call number for `msgget`
#define __NR_msgrcv 191 ///< System-call number for `msgrcv`
#define __NR_msgsnd 192 ///< System-call number for `msgsnd`
#define __NR_semctl 193 ///< System-call number for `semctl`
#define __NR_semget 194 ///< System-call number for `semget`
#define __NR_semop 195 ///< System-call number for `semop`
#define __NR_shmat 196 ///< System-call number for `shmat`
#define __NR_shmctl 197 ///< System-call number for `shmctl`
#define __NR_shmdt 198 ///< System-call number for `shmdt`
#define __NR_shmget 199 ///< System-call number for `shmget`
#define SYSCALL_NUMBER 200 ///< The total number of system-calls.