18 syscall_log(
LOG_DEBUG,
"exit(code=%d)\n", code);
42long sys_execve(
const char *path,
char *
const argp[],
char *
const envp[])
44 syscall_log(
LOG_DEBUG,
"execve(path=%p, argp=%p, envp=%p)\n", path, argp, envp);
116 syscall_log(
LOG_DEBUG,
"sbrk(incr=0x%x)\n", incr);
128 if ((incr < 0 && (
uintptr_t) -incr > heap - heap_start) ||
129 (incr > 0 && (heap_limit < heap || (
uintptr_t) incr > heap_limit - heap))) {
150 syscall_log(
LOG_DEBUG,
"times(buf=%p)\n", buf);
154 struct aquila_tms tms = {
161 if (copyout(buf, &tms,
sizeof(tms))) {
183 syscall_log(
LOG_DEBUG,
"waitpid(pid=%d, stat_loc=%p, options=0x%x)\n", pid, stat_loc,
options);
196 int status,
event = 0;
221 if (stat_loc && copyout(stat_loc, &status,
sizeof(status))) {
261 syscall_log(
LOG_DEBUG,
"uname(name=%p)\n", name);
274 return copyout(name, &u,
sizeof(u));
288 struct aquila_thread_args a;
290 if (copyin(&a, __uthread,
sizeof(a))) {
295 "thread_create(stack=%p, entry=%p, uentry=%p, arg=%p, attr=%p)\n",
296 a.stack, a.entry, a.uentry, a.arg, a.attr);
327 syscall_log(
LOG_DEBUG,
"thread_exit(value_ptr=%p)\n", value_ptr);
369 syscall_log(
LOG_DEBUG,
"thread_join(tid=%d, value_ptr=%p)\n",
tid, value_ptr);
375 struct thread *_thread = node->value;
420 syscall_log(
LOG_DEBUG,
"setpgid(pid=%d, pgid=%d)\n", pid, pgid);
453 syscall_log(
LOG_DEBUG,
"setuid(uid=%d)\n", uid);
472 syscall_log(
LOG_DEBUG,
"setgid(gid=%d)\n", gid);
514long sys_mmap(
struct aquila_mmap_args *uargs,
void **ret)
516 struct aquila_mmap_args _args, *args = &_args;
520 if (copyin(args, uargs,
sizeof(*args)) || copyout(ret, &none,
sizeof(none))) {
524 syscall_log(
LOG_DEBUG,
"mmap(addr=%p, len=%d, prot=%x, flags=%x, fildes=%d, off=%d, ret=%p)\n",
525 args->addr, args->len, args->prot, args->flags, args->fildes, args->off, ret);
528 int anon = args->flags & MAP_ANONYMOUS;
532 if (anon && (args->flags & MAP_SHARED)) {
538 if (!anon && !
file) {
585 if (!(args->flags & MAP_FIXED))
596 err = copyout(ret, &addr,
sizeof(addr));
624 syscall_log(
LOG_DEBUG,
"munmap(addr=%p, len=%d)\n", addr, len);
661 syscall_log(
LOG_DEBUG,
"sysconf(name=%d)\n", name);
709 size_t n =
MIN(len - done,
sizeof(kbuf));
712 if (copyout((
char *) buf + done, kbuf, n))
718 memset(kbuf, 0,
sizeof(kbuf));
719 return done || !len ? (
ssize_t) done : -EFAULT;
742 syscall_log(
LOG_DEBUG,
"reboot(cmd=0x%x)\n", cmd);
780 queue_node_remove(pgrp->
procs, pgrp_node);
795 syscall_log(
LOG_DEBUG,
"sethostname(name=%p, len=%d)\n", name, len);
807 if (copyin(name_in, name, len)) {
void arch_sleep(void)
Puts the current thread to sleep.
void arch_cur_thread_kill(void)
Ends the current thread.
struct vm_object * vm_object_vnode(struct vnode *vnode)
Gets a vnode's vm object, making it the first time.
void kfree(void *)
Frees an object that kmalloc() gave.
void * memset(void *dst, int c, size_t n)
Sets n bytes to c.
void * memcpy(void *dst, const void *src, size_t n)
Copies n bytes; dst and src must not overlap.
int proc_reap(struct proc *proc)
Frees a zombie, once its parent waited for it (or doesn't wait for its children).
int proc_fork(struct thread *thread, struct proc **ref)
Makes a child process, a copy of the process of thread.
int proc_execve(struct thread *thread, const char *fn, char *const argv[], char *const env[])
Runs another program in a thread's process, for execve().
#define PROC_EXIT(info, code)
struct proc * proc_pid_find(pid_t pid)
Finds a process by its ID.
int session_new(struct proc *proc)
Makes a new session, with a new process group, both led by a process and with its ID,...
int proc_setpgid(struct proc *proc, pid_t pgid)
Moves a process into a process group of its session, as setpgid() does.
void proc_kill(struct proc *proc)
Ends a process: its threads end, its descriptors are closed, its memory is freed, its children go to ...
void pgrp_release(struct pgroup *pgrp)
Frees a process group if no process is left in it, and its session if that was the session's last gro...
void random_get(void *_buf, size_t len)
Fills a buffer with random bytes.
int kernel_reboot(unsigned cmd)
Carries out a reboot() command.
void sched_thread_ready(struct thread *thread)
Puts a thread at the end of the ready list, to run in its turn.
void sched_thread_spawn(struct thread *thread)
Starts running a thread for the first time.
__PTRDIFF_TYPE__ ptrdiff_t
unsigned long long int uint64_t
An open file (POSIX's "open file description", fs/file.c).
A process group: the processes of a job.
struct queue * procs
its processes
struct session * session
its session
pid_t pid
the process's ID
struct proc * parent
its parent
struct waitq thread_join
threads waiting in thread_join() sleep here
int exit
its exit status (PROC_EXIT())
int stopped
the signal that stopped it, or 0; and what waitpid() has to report (WAIT_*)
struct queue threads
its threads
struct pgroup * pgrp
its process group, and its node on the group's list
int zombie
proc_kill() is done with it, so it can be reaped (that isn't as soon as it stops running: closing its...
A queue's node, holding one entry.
A session: its process groups, and its controlling terminal.
struct proc * leader
its leader, the process that made it
tid_t tid
the thread's ID, in its process
uintptr_t stack
its user stack
struct proc * owner
its process
void * exit_value
what the thread exited with (thread_exit()), for thread_join()
A mapping (map entry): a range of an address space, its permissions, and where its pages come from.
uint32_t flags
its permissions and flags (VM_*)
size_t off
where the mapping starts in its object
vaddr_t base
where the mapping starts in its address space
struct vm_object * vm_object
its object: what its other pages come from (a file)
struct qnode * qnode
its node in its address space's list of mappings
An address space: its mappings, and its page tables.
struct queue vm_entries
its mappings (map entries), in address order
struct file * fd_file(int fd)
Finds the open file that a descriptor of the current process refers to, and holds it until the system...
int upath_get(const char *upath, char **path)
Copies a path from user memory into a new kernel buffer.
long sys_setuid(uid_t uid)
Implements setuid(): sets the process's user ID.
long sys_uname(struct utsname *name)
Implements uname(): the system's name, release, version and machine, and the host name.
long sys_thread_self(void)
Returns the calling thread's ID, for pthread_self().
long sys_setgid(gid_t gid)
Implements setgid(): sets the process's group ID.
long sys_getgid(void)
Implements getgid().
long sys_getpid(void)
Implements getpid().
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...
long sys_getpgrp(void)
Implements getpgrp().
long sys_sethostname(const char *name, size_t len)
Implements sethostname().
long sys_thread_exit(void *value_ptr)
Ends the calling thread (for pthread_exit()).
static char nodename[sizeof(((struct utsname *) 0) ->nodename)]
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_fork(void)
Implements fork(): makes a child process, a copy of the caller.
long sys_setsid(void)
Implements setsid(): makes the calling process the leader of a new session and process group.
long sys_munmap(void *addr, size_t len)
Implements munmap(): removes a mapping.
long sys_mmap(struct aquila_mmap_args *uargs, void **ret)
Implements mmap(): maps anonymous memory or a file into the calling process.
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,...
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_getppid(void)
Implements getppid().
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 e...
long sys_reboot(unsigned cmd)
Implements reboot(): restarts, halts or powers off the machine, or sets what Ctrl+Alt+Del does.
long sys_getuid(void)
Implements getuid().
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_execve(const char *path, char *const argp[], char *const envp[])
Implements execve(): runs another program in the calling process.
long sys_sysconf(int name)
Implements sysconf(): not supported; the C library answers it.
long sys_exit(int code)
Implements _exit(): ends the calling process.
int thread_create(struct thread *thread, uintptr_t stack, uintptr_t entry, uintptr_t uentry, uintptr_t arg, uintptr_t attr, struct thread **new_thread)
Makes a new thread in the process of an existing one, for pthread_create().
uint64_t arch_rtime_ns(void)
Reads the monotonic clock, which starts at boot.
static void(*) tick(void)
static int uaccess_check(const void *ptr, size_t len)
Checks that [ptr, ptr + len) is in user space.
void vm_unmap_full(struct vm_space *vm_space, struct vm_entry *vm_entry)
Unmaps every page of a map entry's range.
int vm_space_insert(struct vm_space *vm_space, struct vm_entry *vm_entry)
Adds a map entry to an address space, in address order.
void vm_object_decref(struct vm_object *vm_object)
Drops a reference to a vm object: one mapping of it less.
#define VM_SHARED
shared: a fork doesn't copy it
void vm_entry_destroy(struct vm_entry *vm_entry)
Releases what a map entry holds: its references to its anon and its object.
struct vm_entry * vm_entry_new(void)
Makes a new, empty map entry.
#define VM_UX
user execute
void vm_object_incref(struct vm_object *vm_object)
Adds a reference to a vm object: one more mapping of it.
int vfs_map(struct vm_space *vm_space, struct vm_entry *vm_entry)
Maps a file into an address space, for mmap(): a device's own mapping, or the filesystem's.
void waitq_wakeup(struct waitq *waitq)
Wakes up every thread sleeping on a wait queue, and every thread polling it.
int waitq_sleep(struct waitq *waitq)
Puts the current thread to sleep on a wait queue until it is woken up.