|
ginnOS
The reference: libc, the libraries and the kernel
|
#include "kernel/memory/shm.h"#include "syscall_internal.h"#include "syscall.h"#include "kernel/vfs/vfs.h"#include "kernel/usermode/usermode.h"#include "kernel/usermode/uaccess.h"#include "kernel/process/process.h"#include "kernel/process/wait_status.h"#include "kernel/scheduler/scheduler.h"#include "kernel/memory/pmm.h"#include "kernel/memory/pmm_layout.h"#include "kernel/memory/mman.h"#include "kernel/memory/mm.h"#include "kernel/memory/memory_layout.h"#include "fd_table.h"#include "arch/arch.h"#include "common/memory.h"#include "common/string.h"#include "kernel/memory/heap.h"Macros | |
| #define | NO_ENTRY ((size_t)-1) |
| #define | CLONE_VM 0x00000100 |
| #define | CLONE_FS 0x00000200 |
| #define | CLONE_FILES 0x00000400 |
| #define | CLONE_SIGHAND 0x00000800 |
| #define | CLONE_THREAD 0x00010000 |
| #define | CLONE_SYSVSEM 0x00040000 |
| #define | CLONE_SETTLS 0x00080000 |
| #define | CLONE_PARENT_SETTID 0x00100000 |
| #define | CLONE_CHILD_CLEARTID 0x00200000 |
| #define | CLONE_CHILD_SETTID 0x01000000 |
| #define | PRIO_PROCESS 0 |
| #define | PRIO_PGRP 1 |
| #define | PRIO_USER 2 |
| #define | NICE_MIN (-20) |
| #define | NICE_MAX 19 |
Functions | |
| syscall_ret_t | sys_exit (struct registers *regs) |
| SYS_exit: terminate the current process. | |
| syscall_ret_t | sys_exec (struct registers *regs) |
| SYS_exec: start an ELF binary as a child process (spawn, not execve). | |
| syscall_ret_t | sys_execve (struct registers *regs) |
| SYS_execve: replace the calling process's program. | |
| syscall_ret_t | sys_fork (struct registers *regs) |
| SYS_fork: create a child process that is a copy of the caller. | |
| syscall_ret_t | sys_exit_group (struct registers *regs) |
| SYS_exit_group: end every thread of the current process. | |
| syscall_ret_t | sys_clone (struct registers *regs) |
| SYS_clone: make a thread of the current process. | |
| syscall_ret_t | sys_set_tls (struct registers *regs) |
| SYS_set_tls: set the calling thread's thread pointer, which user code reaches its thread-local storage through (fs:0 on x86_64, gs:0 on i686). | |
| syscall_ret_t | sys_gettid (struct registers *regs) |
| SYS_gettid: the calling thread's id (the pid for a single thread). | |
| syscall_ret_t | sys_getpid (struct registers *regs) |
| SYS_getpid: return the current process ID (the thread group's id). | |
| syscall_ret_t | sys_waitpid (struct registers *regs) |
| SYS_waitpid: wait for a child process to exit and reap it. | |
| syscall_ret_t | sys_getppid (struct registers *regs) |
| SYS_getppid: return the parent's pid, or 0 if the parent has exited. | |
| syscall_ret_t | sys_sched_yield (struct registers *regs) |
| SYS_sched_yield: let other ready processes run first. | |
| syscall_ret_t | sys_sbrk (struct registers *regs) |
| syscall_ret_t | sys_mmap (struct registers *regs) |
| syscall_ret_t | sys_shm_create (struct registers *regs) |
| SYS_shm_create: make a shared memory object (kernel/memory/shm.h). | |
| syscall_ret_t | sys_munmap (struct registers *regs) |
| syscall_ret_t | sys_mprotect (struct registers *regs) |
| syscall_ret_t | sys_setpgid (struct registers *regs) |
| SYS_setpgid: move a process into a process group. | |
| syscall_ret_t | sys_getpgid (struct registers *regs) |
| SYS_getpgid: the process group of a process (pid 0: the caller). | |
| syscall_ret_t | sys_setsid (struct registers *regs) |
| SYS_setsid: start a new session, with the caller as the leader of it and of a new process group, and no controlling terminal. | |
| syscall_ret_t | sys_getsid (struct registers *regs) |
| SYS_getsid: the session of a process (pid 0: the caller). | |
| syscall_ret_t | sys_getpriority (struct registers *regs) |
| SYS_getpriority: the nice value of processes. | |
| syscall_ret_t | sys_setpriority (struct registers *regs) |
| SYS_setpriority: set the nice value (-20 to 19) of processes; it sets the length of their time slice. | |
| #define NO_ENTRY ((size_t)-1) |
| #define CLONE_VM 0x00000100 |
| #define CLONE_FS 0x00000200 |
| #define CLONE_FILES 0x00000400 |
| #define CLONE_SIGHAND 0x00000800 |
| #define CLONE_THREAD 0x00010000 |
| #define CLONE_SYSVSEM 0x00040000 |
| #define CLONE_SETTLS 0x00080000 |
| #define CLONE_PARENT_SETTID 0x00100000 |
| #define CLONE_CHILD_CLEARTID 0x00200000 |
| #define CLONE_CHILD_SETTID 0x01000000 |
| #define PRIO_PROCESS 0 |
| #define PRIO_PGRP 1 |
| #define PRIO_USER 2 |
| #define NICE_MIN (-20) |
| #define NICE_MAX 19 |
| syscall_ret_t sys_exit | ( | struct registers * | regs | ) |
SYS_exit: terminate the current process.
arg: EBX = exit code. never returns: the process becomes a zombie until its parent reaps it.
| syscall_ret_t sys_exec | ( | struct registers * | regs | ) |
SYS_exec: start an ELF binary as a child process (spawn, not execve).
args: EBX = path string pointer, ECX = argv array pointer (may be NULL). returns the child's PID, or negative errno on failure.
| syscall_ret_t sys_execve | ( | struct registers * | regs | ) |
SYS_execve: replace the calling process's program.
SYS_execve: replace the calling process's program with a new one.
args: EBX = path, ECX = argv, EDX = envp (both NULL-terminated, may be NULL). on success it does not return: the syscall frame now enters the new program (exec_replace). returns a negative errno on failure, with the old program still running.
SYS_execve: replace the calling process's program.
| syscall_ret_t sys_fork | ( | struct registers * | regs | ) |
SYS_fork: create a child process that is a copy of the caller.
no arguments. returns the child's PID in the parent, 0 in the child (set up by process_fork), or -ENOMEM.
returns the child's PID in the parent and 0 in the child, or a negative errno.
| syscall_ret_t sys_exit_group | ( | struct registers * | regs | ) |
SYS_exit_group: end every thread of the current process.
arg: the exit code. never returns.
| syscall_ret_t sys_clone | ( | struct registers * | regs | ) |
SYS_clone: make a thread of the current process.
args: flags, the new thread's user stack pointer, parent_tid, child_tid, tls. only a thread can be made: flags must have CLONE_VM, FS, FILES, SIGHAND and THREAD (fork makes a process). SETTLS gives the thread tls as its thread pointer (else it has the caller's). PARENT_SETTID and CHILD_SETTID write the new thread's id to parent_tid and child_tid; CHILD_CLEARTID makes the kernel write 0 there when the thread ends. SYSVSEM is accepted and has no effect. returns the new thread's id in the caller and 0 in the thread; -EINVAL for other flags or no stack, -EFAULT for a bad tid address, -EAGAIN if the process table or the memory ran out.
| syscall_ret_t sys_set_tls | ( | struct registers * | regs | ) |
SYS_set_tls: set the calling thread's thread pointer, which user code reaches its thread-local storage through (fs:0 on x86_64, gs:0 on i686).
arg: the address. returns 0.
| syscall_ret_t sys_gettid | ( | struct registers * | regs | ) |
SYS_gettid: the calling thread's id (the pid for a single thread).
| syscall_ret_t sys_getpid | ( | struct registers * | regs | ) |
SYS_getpid: return the current process ID (the thread group's id).
| syscall_ret_t sys_waitpid | ( | struct registers * | regs | ) |
SYS_waitpid: wait for a child process to exit and reap it.
args: EBX = pid (a child's pid, or -1 for any child), ECX = int *status (may be NULL; receives the wait status, wait_status.h), EDX = options (WNOHANG). with WUNTRACED a stopped child and with WCONTINUED a continued one is reported (once) too, without reaping it. returns the child's pid; 0 with WNOHANG when no matching child has anything to report yet; -ECHILD if there is no matching child; -EINVAL for a pid of 0 or below -1 (process groups come later); -EFAULT for a bad status pointer (the child is reaped anyway).
| syscall_ret_t sys_getppid | ( | struct registers * | regs | ) |
SYS_getppid: return the parent's pid, or 0 if the parent has exited.
| syscall_ret_t sys_sched_yield | ( | struct registers * | regs | ) |
SYS_sched_yield: let other ready processes run first.
returns 0.
| syscall_ret_t sys_sbrk | ( | struct registers * | regs | ) |
| syscall_ret_t sys_mmap | ( | struct registers * | regs | ) |
| syscall_ret_t sys_shm_create | ( | struct registers * | regs | ) |
SYS_shm_create: make a shared memory object (kernel/memory/shm.h).
args: EBX = size in bytes (rounded up to pages), ECX = fd flags (FD_CLOEXEC). returns the new fd (open read-write; map it with mmap), or -EINVAL, -ENOMEM, -EMFILE.
| syscall_ret_t sys_munmap | ( | struct registers * | regs | ) |
| syscall_ret_t sys_mprotect | ( | struct registers * | regs | ) |
| syscall_ret_t sys_setpgid | ( | struct registers * | regs | ) |
SYS_setpgid: move a process into a process group.
args: EBX = pid (0: the caller; else the caller or one of its children), ECX = pgid (0: the target's own pid, a new group). the group must be new or exist in the caller's session. returns 0, or -ESRCH, -EPERM, -EINVAL.
| syscall_ret_t sys_getpgid | ( | struct registers * | regs | ) |
SYS_getpgid: the process group of a process (pid 0: the caller).
| syscall_ret_t sys_setsid | ( | struct registers * | regs | ) |
SYS_setsid: start a new session, with the caller as the leader of it and of a new process group, and no controlling terminal.
returns the new session id, or -EPERM if the caller leads a group.
| syscall_ret_t sys_getsid | ( | struct registers * | regs | ) |
SYS_getsid: the session of a process (pid 0: the caller).
| syscall_ret_t sys_getpriority | ( | struct registers * | regs | ) |
SYS_getpriority: the nice value of processes.
args: which (PRIO_PROCESS, PRIO_PGRP, PRIO_USER), who (0: the caller's). returns 20 - nice of the one with the most CPU (1 to 40, never negative), or a negative errno (ESRCH: none, EINVAL).
| syscall_ret_t sys_setpriority | ( | struct registers * | regs | ) |
SYS_setpriority: set the nice value (-20 to 19) of processes; it sets the length of their time slice.
only root may lower it. args: which, who (as getpriority), the nice value. returns 0, or a negative errno (ESRCH, EPERM, EACCES, EINVAL).