|
AquilaOS documentation
How it works, and its code
|
System calls about processes and threads: exit(), execve(), fork(), waitpid(), threads, IDs, process groups and sessions, memory (sbrk(), mmap(), munmap()), and the machine (uname(), reboot(), sethostname()). More...
#include "syscalls.h"Go to the source code of this file.
Functions | |
| long | sys_exit (int code) |
| Implements _exit(): ends the calling process. | |
| long | sys_execve (const char *path, char *const argp[], char *const envp[]) |
| Implements execve(): runs another program in the calling process. | |
| long | sys_fork (void) |
| Implements fork(): makes a child process, a copy of the caller. | |
| long | sys_getpid (void) |
| Implements getpid(). | |
| long | sys_sbrk (ptrdiff_t incr) |
| Implements sbrk(): grows or shrinks the heap. | |
| long | sys_times (struct aquila_tms *buf) |
| Implements times(): the CPU times of the process and of its children that it waited for, in ticks (AQUILA_CLK_TCK a second). | |
| long | sys_waitpid (int pid, int *stat_loc, int options) |
| Implements waitpid(): waits for a child to end (or stop, or continue, if asked), and reaps it if it ended. | |
| long | sys_uname (struct utsname *name) |
| Implements uname(): the system's name, release, version and machine, and the host name. | |
| long | sys_thread_create (struct aquila_thread_args *__uthread) |
| Makes a new thread in the calling process (for pthread_create()), and makes it ready to run. | |
| long | sys_thread_exit (void *value_ptr) |
| Ends the calling thread (for pthread_exit()). | |
| long | sys_thread_join (int tid, void **value_ptr) |
| Waits for a thread of the calling process to end, and frees it (for pthread_join()). | |
| long | sys_setpgid (pid_t pid, pid_t pgid) |
| Implements setpgid(): moves a process (the caller or one of its children) into a process group of its session. | |
| long | sys_setuid (uid_t uid) |
| Implements setuid(): sets the process's user ID. | |
| long | sys_setgid (gid_t gid) |
| Implements setgid(): sets the process's group ID. | |
| long | sys_getuid (void) |
| Implements getuid(). | |
| long | sys_getgid (void) |
| Implements getgid(). | |
| long | sys_mmap (struct aquila_mmap_args *uargs, void **ret) |
| Implements mmap(): maps anonymous memory or a file into the calling process. | |
| long | sys_munmap (void *addr, size_t len) |
| Implements munmap(): removes a mapping. | |
| long | sys_sysconf (int name) |
| Implements sysconf(): not supported; the C library answers it. | |
| long | sys_getppid (void) |
| Implements getppid(). | |
| long | sys_getpgrp (void) |
| Implements getpgrp(). | |
| long | sys_getrandom (void *buf, size_t len, unsigned flags) |
| Implements getrandom() (and the C library's getentropy()): fills a buffer with random bytes. | |
| long | sys_thread_self (void) |
| Returns the calling thread's ID, for pthread_self(). | |
| long | sys_reboot (unsigned cmd) |
| Implements reboot(): restarts, halts or powers off the machine, or sets what Ctrl+Alt+Del does. | |
| long | sys_setsid (void) |
| Implements setsid(): makes the calling process the leader of a new session and process group. | |
| long | sys_sethostname (const char *name, size_t len) |
| Implements sethostname(). | |
Variables | |
| static char | nodename [sizeof(((struct utsname *) 0) ->nodename)] = UTSNAME_NODENAME |
System calls about processes and threads: exit(), execve(), fork(), waitpid(), threads, IDs, process groups and sessions, memory (sbrk(), mmap(), munmap()), and the machine (uname(), reboot(), sethostname()).
Definition in file sys_proc.c.
| long sys_execve | ( | const char * | path, |
| char *const | argp[], | ||
| char *const | envp[] ) |
Implements execve(): runs another program in the calling process.
| path | the program's path |
| argp | its arguments, a NULL-terminated array |
| envp | its environment, a NULL-terminated array |
Definition at line 42 of file sys_proc.c.
References curthread, kfree(), LOG_DEBUG, proc_execve(), sched_thread_spawn(), sys_execve(), and upath_get().
Referenced by sys_execve().
| long sys_exit | ( | int | code | ) |
Implements _exit(): ends the calling process.
It doesn't return.
| code | the exit status, which the parent's wait() reports |
Definition at line 16 of file sys_proc.c.
References arch_sleep(), curproc, proc::exit, LOG_DEBUG, PROC_EXIT, proc_kill(), and sys_exit().
Referenced by sys_exit(), and sys_thread_exit().
| long sys_fork | ( | void | ) |
Implements fork(): makes a child process, a copy of the caller.
Definition at line 76 of file sys_proc.c.
References curthread, queue::head, LOG_DEBUG, NULL, proc::pid, proc_fork(), sched_thread_ready(), sys_fork(), proc::threads, and qnode::value.
Referenced by sys_fork().
| long sys_getgid | ( | void | ) |
Implements getgid().
Definition at line 498 of file sys_proc.c.
References curproc, LOG_DEBUG, and sys_getgid().
Referenced by sys_getgid().
| long sys_getpgrp | ( | void | ) |
Implements getpgrp().
Definition at line 683 of file sys_proc.c.
References curproc, LOG_DEBUG, and sys_getpgrp().
Referenced by sys_getpgrp().
| long sys_getpid | ( | void | ) |
Implements getpid().
Definition at line 100 of file sys_proc.c.
References curproc, LOG_DEBUG, and sys_getpid().
Referenced by sys_getpid().
| long sys_getppid | ( | void | ) |
Implements getppid().
Definition at line 670 of file sys_proc.c.
References curproc, LOG_DEBUG, and sys_getppid().
Referenced by sys_getppid().
| long sys_getrandom | ( | void * | buf, |
| size_t | len, | ||
| unsigned | flags ) |
Implements getrandom() (and the C library's getentropy()): fills a buffer with random bytes.
| buf | the buffer |
| len | its size |
| flags | not used |
Definition at line 698 of file sys_proc.c.
References memset(), MIN, random_get(), sys_getrandom(), and uaccess_check().
Referenced by sys_getrandom().
| long sys_getuid | ( | void | ) |
Implements getuid().
Definition at line 487 of file sys_proc.c.
References curproc, LOG_DEBUG, and sys_getuid().
Referenced by sys_getuid().
| long sys_mmap | ( | struct aquila_mmap_args * | uargs, |
| void ** | ret ) |
Implements mmap(): maps anonymous memory or a file into the calling process.
Pages are brought in by page faults, when first touched.
| uargs | the arguments, in user memory: the address, length, protection, flags, descriptor and offset |
| ret | where to put the mapping's address |
Definition at line 514 of file sys_proc.c.
References vm_entry::base, curproc, fd_file(), FILE_SOCKET, file::flags, vm_entry::flags, kfree(), LOG_DEBUG, NULL, vm_entry::off, PAGE_MASK, PAGE_ROUND, vm_entry::qnode, vm_entry::size, sys_mmap(), uaccess_check(), vfs_map(), vm_entry_new(), vm_entry::vm_object, vm_object_decref(), vm_object_incref(), vm_object_vnode(), VM_SHARED, vm_space_insert(), VM_UR, VM_UW, and VM_UX.
Referenced by sys_mmap().
| long sys_munmap | ( | void * | addr, |
| size_t | len ) |
Implements munmap(): removes a mapping.
Only a whole mapping can be removed, not a part of one; the heap and the stack can't be.
| addr | the mapping's address |
| len | its length |
Definition at line 622 of file sys_proc.c.
References vm_entry::base, curproc, kfree(), LOG_DEBUG, PAGE_ROUND, vm_entry::qnode, queue_for, vm_entry::size, sys_munmap(), vm_space::vm_entries, vm_entry_destroy(), and vm_unmap_full().
Referenced by sys_munmap().
| long sys_reboot | ( | unsigned | cmd | ) |
Implements reboot(): restarts, halts or powers off the machine, or sets what Ctrl+Alt+Del does.
Only root may.
| cmd | the command (RB_*) |
Definition at line 740 of file sys_proc.c.
References curproc, kernel_reboot(), LOG_DEBUG, and sys_reboot().
Referenced by sys_reboot().
| long sys_sbrk | ( | ptrdiff_t | incr | ) |
Implements sbrk(): grows or shrinks the heap.
The heap may grow up to the next mapping (or the stack).
| incr | how many bytes to add (or take off, if negative) |
Definition at line 114 of file sys_proc.c.
References vm_entry::base, curproc, LOG_DEBUG, qnode::next, PAGE_ROUND, sys_sbrk(), USER_STACK_BASE, and qnode::value.
Referenced by sys_sbrk().
| long sys_setgid | ( | gid_t | gid | ) |
Implements setgid(): sets the process's group ID.
Root may set any ID, other users only their own.
| gid | the group ID |
Definition at line 470 of file sys_proc.c.
References curproc, LOG_DEBUG, and sys_setgid().
Referenced by sys_setgid().
| long sys_sethostname | ( | const char * | name, |
| size_t | len ) |
Implements sethostname().
Only root may.
| name | the host name (not NUL-terminated) |
| len | its length |
Definition at line 793 of file sys_proc.c.
References curproc, LOG_DEBUG, memcpy(), nodename, and sys_sethostname().
Referenced by sys_sethostname().
Implements setpgid(): moves a process (the caller or one of its children) into a process group of its session.
| pid | the process, or 0 for the caller |
| pgid | the group's ID, or 0 for the process's own ID (a new group) |
Definition at line 418 of file sys_proc.c.
References curproc, session::leader, LOG_DEBUG, proc::parent, proc::pgrp, proc::pid, proc_pid_find(), proc_setpgid(), pgroup::session, and sys_setpgid().
Referenced by sys_setpgid().
| long sys_setsid | ( | void | ) |
Implements setsid(): makes the calling process the leader of a new session and process group.
Definition at line 758 of file sys_proc.c.
References curproc, LOG_DEBUG, pgroup::pgid, proc::pgrp, proc::pgrp_node, pgrp_release(), proc::pid, pgroup::procs, session_new(), and sys_setsid().
Referenced by sys_setsid().
| long sys_setuid | ( | uid_t | uid | ) |
Implements setuid(): sets the process's user ID.
There are no separate effective or saved IDs: root may set any ID, other users only their own.
| uid | the user ID |
Definition at line 451 of file sys_proc.c.
References curproc, LOG_DEBUG, and sys_setuid().
Referenced by sys_setuid().
| long sys_sysconf | ( | int | name | ) |
Implements sysconf(): not supported; the C library answers it.
| name | the variable |
Definition at line 659 of file sys_proc.c.
References LOG_DEBUG, and sys_sysconf().
Referenced by sys_sysconf().
| long sys_thread_create | ( | struct aquila_thread_args * | __uthread | ) |
Makes a new thread in the calling process (for pthread_create()), and makes it ready to run.
| __uthread | the arguments, in user memory: the thread's stack, the C library's start, the thread's function and its argument |
Definition at line 286 of file sys_proc.c.
References curthread, LOG_DEBUG, NULL, sched_thread_ready(), thread::stack, sys_thread_create(), thread_create(), thread::tid, and uaccess_check().
Referenced by sys_thread_create().
| long sys_thread_exit | ( | void * | value_ptr | ) |
Ends the calling thread (for pthread_exit()).
It stays as a zombie until another thread joins it. The last live thread ending ends the process. It doesn't return.
| value_ptr | the value that thread_join() returns |
Definition at line 325 of file sys_proc.c.
References arch_cur_thread_kill(), curproc, curthread, LOG_DEBUG, thread::owner, queue_for, thread::state, sys_exit(), sys_thread_exit(), proc::thread_join, proc::threads, waitq_wakeup(), and ZOMBIE.
Referenced by sys_thread_exit().
| long sys_thread_join | ( | int | tid, |
| void ** | value_ptr ) |
Waits for a thread of the calling process to end, and frees it (for pthread_join()).
| tid | the thread's ID |
| value_ptr | where to put the value it ended with, or NULL |
Definition at line 367 of file sys_proc.c.
References curproc, curthread, ERESTARTSYS, thread::exit_value, kfree(), LOG_DEBUG, NULL, thread::owner, queue_for, thread::state, sys_thread_join(), proc::threads, thread::tid, waitq_sleep(), and ZOMBIE.
Referenced by sys_thread_join().
| long sys_thread_self | ( | void | ) |
Returns the calling thread's ID, for pthread_self().
Definition at line 727 of file sys_proc.c.
References curthread, and sys_thread_self().
Referenced by sys_thread_self().
| long sys_times | ( | struct aquila_tms * | buf | ) |
Implements times(): the CPU times of the process and of its children that it waited for, in ticks (AQUILA_CLK_TCK a second).
| buf | where to put them |
Definition at line 148 of file sys_proc.c.
References arch_rtime_ns(), curproc, LOG_DEBUG, sys_times(), and tick.
Referenced by sys_times().
| long sys_uname | ( | struct utsname * | name | ) |
Implements uname(): the system's name, release, version and machine, and the host name.
| name | where to put them |
Definition at line 259 of file sys_proc.c.
References LOG_DEBUG, memcpy(), memset(), MIN, nodename, sys_uname(), UTSNAME_MACHINE, UTSNAME_RELEASE, UTSNAME_SYSNAME, and UTSNAME_VERSION.
Referenced by sys_uname().
| long sys_waitpid | ( | int | pid, |
| int * | stat_loc, | ||
| int | options ) |
Implements waitpid(): waits for a child to end (or stop, or continue, if asked), and reaps it if it ended.
| pid | which child: that one if > 0, any if -1, any in the caller's process group if 0, or any in process group -pid if < -1 |
| stat_loc | where to put its status, or NULL |
| options | WNOHANG, WUNTRACED, WCONTINUED |
Definition at line 181 of file sys_proc.c.
References curproc, ERESTARTSYS, proc::exit, LOG_DEBUG, options(), proc::parent, pgroup::pgid, proc::pgrp, proc::pid, proc_reap(), procs, queue_for, proc::stopped, sys_waitpid(), WAIT_CONTINUED, proc::wait_event, WAIT_STOPPED, waitq_sleep(), and proc::zombie.
Referenced by sys_waitpid().
|
static |
Definition at line 250 of file sys_proc.c.
Referenced by sys_sethostname(), and sys_uname().