AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
syscalls.h File Reference
#include <core/system.h>
#include <aquila/syscall.h>
#include <core/panic.h>
#include <core/string.h>
#include <core/arch.h>
#include <core/time.h>
#include <sys/proc.h>
#include <sys/sched.h>
#include <sys/signal.h>
#include <sys/binfmt.h>
#include <sys/uaccess.h>
#include <sys/syscall.h>
#include <fs/iobuf.h>
#include <net/socket.h>
#include <aquila/errno.h>
#include <aquila/dirent.h>
#include <aquila/utsname.h>
#include <aquila/fcntl.h>
#include <aquila/mman.h>
#include <aquila/time.h>
#include <aquila/ioctl.h>
#include <aquila/wait.h>
#include <aquila/poll.h>
#include <aquila/un.h>
#include <fs/devpts.h>
#include <fs/pipe.h>
#include <fs/stat.h>
#include <mm/vm.h>
#include <sys/reboot.h>
#include <dev/random.h>

Go to the source code of this file.

Macros

#define UPATH_MAX   1024

Functions

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 call returns, so that a close() by another thread meanwhile doesn't free it.
int upath_get (const char *upath, char **path)
 Copies a path from user memory into a new kernel buffer.
long sys_close (int fildes)
 Implements close(): frees a descriptor.
long sys_fstat (int fildes, struct aquila_stat *buf)
 Implements fstat(): an open file's attributes.
long sys_isatty (int fildes)
 Says whether a descriptor refers to a character device, the only kind of file that can be a terminal.
long sys_link (const char *oldpath, const char *newpath)
 Implements link(): a new name for a file.
long sys_linkat (int olddirfd, const char *oldpath, int newdirfd, const char *newpath, int flags)
 Implements linkat(): link(), with paths relative to directories.
long sys_lseek (int fildes, off_t offset, int whence)
 Implements lseek(): moves an open file's offset.
long sys_open (const char *path, int oflags, mode_t mode)
 Implements open(): opens a file on a new descriptor, creating it with O_CREAT.
long sys_openat (int dirfd, const char *path, int oflags, mode_t mode)
 Implements openat(): open(), with the path relative to a directory.
long sys_read (int fildes, void *buf, size_t nbytes)
 Implements read().
long sys_stat (const char *path, struct aquila_stat *buf)
 Implements stat(): a file's attributes, following a symbolic link.
long sys_fstatat (int dirfd, const char *path, struct aquila_stat *buf, int flags)
 Implements fstatat(): stat(), with the path relative to a directory.
long sys_unlink (const char *path)
 Implements unlink(): removes a name of a file (not a directory's).
long sys_unlinkat (int dirfd, const char *path, int flags)
 Implements unlinkat(): unlink(), or rmdir() with AT_REMOVEDIR, with the path relative to a directory.
long sys_write (int fd, void *buf, size_t nbytes)
 Implements write().
long sys_ioctl (int fd, int request, void *argp)
 Implements ioctl(): a device's, a socket's, or a terminal's request.
long sys_readdir (int fd, struct dirent *dirent)
 Reads a directory's next entry, for the C library's readdir().
long sys_mount (struct aquila_mount_args *args)
 Implements mount(): mounts a file system on a directory.
long sys_mkdir (const char *path, mode_t mode)
 Implements mkdir(): makes a directory.
long sys_pipe (int fd[2])
 Implements pipe(): makes a pipe, its read end and its write end open on two new descriptors.
long sys_fcntl (int fd, int cmd, uintptr_t arg)
 Implements fcntl(): duplicates a descriptor, or reads and sets the descriptor's flags (FD_CLOEXEC) or the open file's status flags.
long sys_chdir (const char *upath)
 Implements chdir(): changes the working directory.
long sys_getcwd (char *buf, size_t size)
 Implements getcwd(): the working directory's path.
long sys_mknod (const char *path, uint32_t mode, uint32_t dev)
 Implements mknod(): makes a file, a directory, a FIFO, or (only root) a device file.
long sys_mknodat (int dirfd, const char *path, uint32_t mode, uint32_t dev)
 Implements mknodat(): mknod(), with the path relative to a directory.
long sys_lstat (const char *path, struct aquila_stat *buf)
 Implements lstat(): a file's attributes, a symbolic link's own.
long sys_ftruncate (int fildes, off_t len)
 Implements ftruncate(): sets an open file's size.
long sys_umask (mode_t mask)
 Implements umask(): sets the permissions that new files don't get.
long sys_chmod (const char *path, mode_t mode)
 Implements chmod(): changes a file's permissions.
long sys_fchmodat (int dirfd, const char *path, mode_t mode, int flags)
 Implements fchmodat(): chmod(), with the path relative to a directory.
long sys_fchmod (int fd, mode_t mode)
 Implements fchmod(): changes an open file's permissions.
long sys_access (const char *path, int mode)
 Implements access(): says whether the process may read, write or execute a file.
long sys_faccessat (int dirfd, const char *path, int mode, int flags)
 Implements faccessat(): access(), with the path relative to a directory.
long sys_chown (const char *path, uid_t owner, gid_t group)
 Implements chown(): changes a file's owner and group.
long sys_fchownat (int dirfd, const char *path, uid_t owner, gid_t group, int flags)
 Implements fchownat(): chown(), with the path relative to a directory.
long sys_fchown (int fd, uid_t owner, gid_t group)
 Implements fchown(): changes an open file's owner and group.
long sys_lchown (const char *path, uid_t owner, gid_t group)
 Implements lchown(): chown() of a symbolic link itself.
long sys_utimensat (int dirfd, const char *path, const struct aquila_timespec times[2], int flags)
 Implements utimensat() (and futimens()): sets a file's access and modification times.
long sys_rmdir (const char *path)
 Implements rmdir(): removes an empty directory.
long sys_symlinkat (const char *utarget, int dirfd, const char *upath)
 Implements symlinkat(): makes a symbolic link.
long sys_readlinkat (int dirfd, const char *upath, char *buf, size_t size)
 Implements readlinkat(): what a symbolic link points to (not NUL-terminated).
long sys_renameat (int olddirfd, const char *oldpath, int newdirfd, const char *newpath)
 Implements renameat() (and rename()): moves a file to another name, replacing what was there.
long sys_flock (int fd, int op)
 Implements flock(): takes or releases an advisory lock on an open file.
long sys_sync (void)
 Implements sync(): writes out what the devices' caches hold.
long sys_fchdir (int fd)
 Implements fchdir(): changes the working directory to an open directory.
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().
long sys_kill (pid_t pid, int sig)
 Implements kill(): sends a signal to a process or a process group.
long sys_sigaction (int sig, const struct aquila_sigaction *act, struct aquila_sigaction *oact)
 Implements sigaction(): reads a signal's action, and sets a new one.
long sys_gettimeofday (struct timeval *tv, struct timezone *tz)
 Implements gettimeofday(): the time of day.
long sys_sigmask (int how, const sigset_t *set, sigset_t *oldset)
 Implements sigprocmask(): reads and changes the process's signal mask.
long sys_sigsuspend (const sigset_t *set)
 Implements sigsuspend(): replaces the signal mask and waits for a signal.
long sys_sigreturn (void)
 Implements sigreturn(): a signal handler returns, and the registers and signal mask that its frame saved are restored.
long sys_setitimer (int which, const struct aquila_itimer *new, struct aquila_itimer *old)
 Implements setitimer(): sets the real time timer, which sends SIGALRM, and reads the old one.
long sys_nanosleep (const struct aquila_timespec *req, struct aquila_timespec *rem)
 Implements nanosleep(): sleeps for a time.
long sys_clock_gettime (int clock, struct aquila_timespec *ts)
 Implements clock_gettime(): reads a clock.
long sys_socket (int domain, int type, int protocol)
 Implements socket(): makes a socket, open on a new descriptor.
long sys_accept (int fd, const struct sockaddr *addr, socklen_t *len)
 Implements accept(): takes a connection from a listening socket, open on a new descriptor.
long sys_bind (int fd, const struct sockaddr *addr, socklen_t len)
 Implements bind(): gives a socket its local address.
long sys_connect (int fd, const struct sockaddr *addr, socklen_t len)
 Implements connect(): connects a socket to a peer.
long sys_listen (int fd, int backlog)
 Implements listen(): makes a socket accept connections.
long sys_send (struct aquila_socket_io_args *us)
 Implements send() and sendto().
long sys_recv (struct aquila_socket_io_args *us)
 Implements recv() and recvfrom().
long sys_getsockname (int fd, struct sockaddr *addr, socklen_t *len)
 Implements getsockname(): a socket's local address.
long sys_getpeername (int fd, struct sockaddr *addr, socklen_t *len)
 Implements getpeername(): the address of a socket's peer.
long sys_getsockopt (int fd, int level, int name, void *val, socklen_t *len)
 Implements getsockopt(): reads a socket option.
long sys_setsockopt (int fd, int level, int name, const void *val, socklen_t len)
 Implements setsockopt(): sets a socket option.
long sys_shutdown (int fd, int how)
 Implements shutdown(): shuts down reading, writing or both on a socket, which stays open.
long sys_select (struct aquila_select_args *args)
 Implements select() and pselect(): waits until a descriptor of the sets can be read or written, or the timeout passes, and says which can.
long sys_poll (struct pollfd *fds, nfds_t nfds, int timeout_ms)
 Implements poll(): waits until one of the descriptors can be read or written, or the timeout passes, and says which can.

Macro Definition Documentation

◆ UPATH_MAX

#define UPATH_MAX   1024

Definition at line 54 of file syscalls.h.

Referenced by sys_getcwd(), sys_readlinkat(), and upath_get().

Function Documentation

◆ fd_file()

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 call returns, so that a close() by another thread meanwhile doesn't free it.

Parameters
fdthe descriptor
Returns
the open file, or NULL if fd isn't open

Definition at line 22 of file syscall.c.

References curproc, fd_file(), file_hold(), NULL, and proc_fd_file().

Referenced by at_uio(), fd_file(), fd_vnode(), socket_name(), sys_accept(), sys_bind(), sys_connect(), sys_fchdir(), sys_fcntl(), sys_flock(), sys_fstat(), sys_ftruncate(), sys_getsockopt(), sys_ioctl(), sys_isatty(), sys_listen(), sys_lseek(), sys_mmap(), sys_read(), sys_readdir(), sys_recv(), sys_send(), sys_setsockopt(), sys_shutdown(), and sys_write().

◆ sys_accept()

long sys_accept ( int fd,
const struct sockaddr * addr,
socklen_t * len )

Implements accept(): takes a connection from a listening socket, open on a new descriptor.

Parameters
fdthe listening socket
addrwhere to put the peer's address, or NULL
lenthe room at addr, set to the address's size
Returns
the connection's descriptor, or a negative errno: -EBADF, -EMFILE, -ENOMEM, -EAGAIN, -EINVAL, -EFAULT

Definition at line 97 of file sys_net.c.

References curproc, fd_file(), file_new(), kfree(), LOG_DEBUG, memset(), NULL, proc_fd_close(), proc_fd_get(), proc_fd_install(), proc_fd_release(), ksockaddr::sa, sockaddr_copyout(), sockaddr_room(), socket_accept(), and sys_accept().

Referenced by sys_accept().

◆ sys_access()

long sys_access ( const char * path,
int mode )

Implements access(): says whether the process may read, write or execute a file.

Parameters
paththe file's path
modeF_OK, or R_OK, W_OK and X_OK together
Returns
0 if it may, or a negative errno: -EACCES, -ENOENT, ...

Definition at line 1220 of file sys_file.c.

References do_faccessat(), LOG_DEBUG, and sys_access().

Referenced by sys_access().

◆ sys_bind()

long sys_bind ( int fd,
const struct sockaddr * addr,
socklen_t len )

Implements bind(): gives a socket its local address.

Parameters
fdthe socket
addrthe address
lenits size
Returns
0, or a negative errno: -EBADF, -EADDRINUSE, -EADDRNOTAVAIL, -EACCES, -EINVAL, -EFAULT

Definition at line 161 of file sys_net.c.

References fd_file(), LOG_DEBUG, memset(), ksockaddr::sa, sockaddr_copyin(), socket_bind(), and sys_bind().

Referenced by sys_bind().

◆ sys_chdir()

long sys_chdir ( const char * upath)

Implements chdir(): changes the working directory.

Parameters
upaththe directory's path
Returns
0, or a negative errno: -ENOENT, -ENOTDIR, -EACCES, ...

Definition at line 956 of file sys_file.c.

References curproc, cwd_set(), kfree(), LOG_DEBUG, NULL, PROC_UIO, sys_chdir(), upath_get(), vfs_close(), and vfs_lookup().

Referenced by sys_chdir().

◆ sys_chmod()

long sys_chmod ( const char * path,
mode_t mode )

Implements chmod(): changes a file's permissions.

Parameters
paththe file's path
modethe new permissions
Returns
0, or a negative errno: -ENOENT, -EPERM, ...

Definition at line 1129 of file sys_file.c.

References do_fchmodat(), LOG_DEBUG, and sys_chmod().

Referenced by sys_chmod().

◆ sys_chown()

long sys_chown ( const char * path,
uid_t owner,
gid_t group )

Implements chown(): changes a file's owner and group.

Parameters
paththe file's path
ownerthe new owner, or -1 to keep it
groupthe new group, or -1 to keep it
Returns
0, or a negative errno: -EPERM, -ENOENT, ...

Definition at line 1269 of file sys_file.c.

References do_fchownat(), LOG_DEBUG, and sys_chown().

Referenced by sys_chown().

◆ sys_clock_gettime()

long sys_clock_gettime ( int clock,
struct aquila_timespec * ts )

Implements clock_gettime(): reads a clock.

Parameters
clockCLOCK_REALTIME or CLOCK_MONOTONIC
tswhere to put the time
Returns
0, -EINVAL for another clock, or -EFAULT

Definition at line 293 of file sys_signal.c.

References arch_rtime_ns(), clock, gettime(), LOG_DEBUG, sys_clock_gettime(), timespec::tv_nsec, and timespec::tv_sec.

Referenced by sys_clock_gettime().

◆ sys_close()

long sys_close ( int fildes)

Implements close(): frees a descriptor.

The open file is closed once nothing else refers to it (another descriptor, or a call using it).

Parameters
fildesthe descriptor
Returns
0, -EBADF, or an error from closing the file

Definition at line 86 of file sys_file.c.

References curproc, LOG_DEBUG, proc_fd_close(), and sys_close().

Referenced by sys_close().

◆ sys_connect()

long sys_connect ( int fd,
const struct sockaddr * addr,
socklen_t len )

Implements connect(): connects a socket to a peer.

Parameters
fdthe socket
addrthe peer's address
lenits size
Returns
0, or a negative errno: -EBADF, -ECONNREFUSED, -EINPROGRESS, -ENETUNREACH, -ETIMEDOUT, -EFAULT

Definition at line 192 of file sys_net.c.

References fd_file(), LOG_DEBUG, memset(), ksockaddr::sa, sockaddr_copyin(), socket_connect(), and sys_connect().

Referenced by sys_connect().

◆ sys_execve()

long sys_execve ( const char * path,
char *const argp[],
char *const envp[] )

Implements execve(): runs another program in the calling process.

Parameters
paththe program's path
argpits arguments, a NULL-terminated array
envpits environment, a NULL-terminated array
Returns
a negative errno on failure (-ENOENT, -EACCES, -ENOEXEC, -E2BIG, -EFAULT, -ENOMEM); on success it doesn't return, the new program starts

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().

◆ sys_exit()

long sys_exit ( int code)

Implements _exit(): ends the calling process.

It doesn't return.

Parameters
codethe exit status, which the parent's wait() reports
Returns
nothing: it doesn't return

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().

◆ sys_faccessat()

long sys_faccessat ( int dirfd,
const char * path,
int mode,
int flags )

Implements faccessat(): access(), with the path relative to a directory.

Parameters
dirfdthe directory, or AT_FDCWD
paththe file's path
modeF_OK, or R_OK, W_OK and X_OK together
flagsAT_EACCESS (which changes nothing), AT_SYMLINK_NOFOLLOW
Returns
0 if it may, or a negative errno

Definition at line 1236 of file sys_file.c.

References do_faccessat(), uio::flags, LOG_DEBUG, and sys_faccessat().

Referenced by sys_faccessat().

◆ sys_fchdir()

long sys_fchdir ( int fd)

Implements fchdir(): changes the working directory to an open directory.

Parameters
fdthe directory's descriptor
Returns
0, or a negative errno: -EBADF, -ENOTDIR, -EACCES

Definition at line 1523 of file sys_file.c.

References cwd_set(), fd_file(), FILE_SOCKET, file::flags, LOG_DEBUG, file::ref, sys_fchdir(), and vfs_close().

Referenced by sys_fchdir().

◆ sys_fchmod()

long sys_fchmod ( int fd,
mode_t mode )

Implements fchmod(): changes an open file's permissions.

Parameters
fdthe descriptor
modethe new permissions
Returns
0, or a negative errno: -EBADF, -EINVAL, -EPERM

Definition at line 1172 of file sys_file.c.

References curproc, fd_vnode(), LOG_DEBUG, vnode::mode, PROC_UIO, sys_fchmod(), and vfs_chmod().

Referenced by sys_fchmod().

◆ sys_fchmodat()

long sys_fchmodat ( int dirfd,
const char * path,
mode_t mode,
int flags )

Implements fchmodat(): chmod(), with the path relative to a directory.

Parameters
dirfdthe directory, or AT_FDCWD
paththe file's path
modethe new permissions
flags0 (AT_SYMLINK_NOFOLLOW isn't supported)
Returns
0, or a negative errno

Definition at line 1145 of file sys_file.c.

References do_fchmodat(), uio::flags, LOG_DEBUG, and sys_fchmodat().

Referenced by sys_fchmodat().

◆ sys_fchown()

long sys_fchown ( int fd,
uid_t owner,
gid_t group )

Implements fchown(): changes an open file's owner and group.

Parameters
fdthe descriptor
ownerthe new owner, or -1
groupthe new group, or -1
Returns
0, or a negative errno: -EBADF, -EINVAL, -EPERM

Definition at line 1301 of file sys_file.c.

References curproc, fd_vnode(), LOG_DEBUG, PROC_UIO, sys_fchown(), and vfs_chown().

Referenced by sys_fchown().

◆ sys_fchownat()

long sys_fchownat ( int dirfd,
const char * path,
uid_t owner,
gid_t group,
int flags )

Implements fchownat(): chown(), with the path relative to a directory.

Parameters
dirfdthe directory, or AT_FDCWD
paththe file's path
ownerthe new owner, or -1
groupthe new group, or -1
flagsAT_SYMLINK_NOFOLLOW for a symbolic link's own
Returns
0, or a negative errno

Definition at line 1286 of file sys_file.c.

References do_fchownat(), uio::flags, LOG_DEBUG, and sys_fchownat().

Referenced by sys_fchownat().

◆ sys_fcntl()

long sys_fcntl ( int fd,
int cmd,
uintptr_t arg )

Implements fcntl(): duplicates a descriptor, or reads and sets the descriptor's flags (FD_CLOEXEC) or the open file's status flags.

Parameters
fdthe descriptor
cmdF_DUPFD, F_DUPFD_CLOEXEC, F_GETFD, F_SETFD, F_GETFL or F_SETFL
argthe command's argument
Returns
what the command returns, or a negative errno: -EBADF, -EINVAL, -EMFILE

Definition at line 876 of file sys_file.c.

References curproc, fd_file(), FDS_COUNT, file_ref(), FILE_SOCKET, file::flags, LOG_DEBUG, proc_fd_install(), and sys_fcntl().

Referenced by sys_fcntl().

◆ sys_flock()

long sys_flock ( int fd,
int op )

Implements flock(): takes or releases an advisory lock on an open file.

Parameters
fdthe descriptor
opLOCK_SH, LOCK_EX or LOCK_UN, with LOCK_NB to not wait
Returns
0, or a negative errno: -EBADF, -EWOULDBLOCK, -EINTR, ...

Definition at line 1490 of file sys_file.c.

References fd_file(), LOG_DEBUG, sys_flock(), and vfs_file_flock().

Referenced by sys_flock().

◆ sys_fork()

long sys_fork ( void )

Implements fork(): makes a child process, a copy of the caller.

Returns
the child's process ID in the parent (the child gets 0), or a negative errno: -ENOMEM, -EAGAIN

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().

◆ sys_fstat()

long sys_fstat ( int fildes,
struct aquila_stat * buf )

Implements fstat(): an open file's attributes.

A socket only reports its type.

Parameters
fildesthe descriptor
bufwhere to put them
Returns
0, or a negative errno: -EBADF, -EFAULT

Definition at line 103 of file sys_file.c.

References fd_file(), FILE_SOCKET, file::flags, LOG_DEBUG, memset(), sys_fstat(), and vfs_stat().

Referenced by sys_fstat().

◆ sys_fstatat()

long sys_fstatat ( int dirfd,
const char * path,
struct aquila_stat * buf,
int flags )

Implements fstatat(): stat(), with the path relative to a directory.

Parameters
dirfdthe directory, or AT_FDCWD
paththe file's path
bufwhere to put its attributes
flagsAT_SYMLINK_NOFOLLOW for a symbolic link's own
Returns
0, or a negative errno

Definition at line 520 of file sys_file.c.

References do_fstatat(), LOG_DEBUG, and sys_fstatat().

Referenced by sys_fstatat().

◆ sys_ftruncate()

long sys_ftruncate ( int fildes,
off_t len )

Implements ftruncate(): sets an open file's size.

Parameters
fildesthe descriptor, open for writing
lenthe new size
Returns
0, or a negative errno: -EBADF, -EINVAL, ...

Definition at line 1065 of file sys_file.c.

References fd_file(), file::flags, LOG_DEBUG, sys_ftruncate(), and vfs_file_trunc().

Referenced by sys_ftruncate().

◆ sys_getcwd()

long sys_getcwd ( char * buf,
size_t size )

Implements getcwd(): the working directory's path.

Parameters
bufwhere to put it
sizethe room at buf
Returns
0, or a negative errno: -EINVAL, -ERANGE if it doesn't fit, -ENOMEM, -EFAULT

Definition at line 985 of file sys_file.c.

References curproc, kfree(), kmalloc(), LOG_DEBUG, MIN, NULL, vnode::size, sys_getcwd(), UPATH_MAX, and vfs_vnode_path().

Referenced by sys_getcwd().

◆ sys_getgid()

long sys_getgid ( void )

Implements getgid().

Returns
the calling process's group ID

Definition at line 498 of file sys_proc.c.

References curproc, LOG_DEBUG, and sys_getgid().

Referenced by sys_getgid().

◆ sys_getpeername()

long sys_getpeername ( int fd,
struct sockaddr * addr,
socklen_t * len )

Implements getpeername(): the address of a socket's peer.

Parameters
fdthe socket
addrwhere to put the address
lenthe room at addr, set to the address's size
Returns
0, or a negative errno: -EBADF, -ENOTCONN, -EFAULT

Definition at line 412 of file sys_net.c.

References LOG_DEBUG, socket_name(), and sys_getpeername().

Referenced by sys_getpeername().

◆ sys_getpgrp()

long sys_getpgrp ( void )

Implements getpgrp().

Returns
the calling process's process group ID

Definition at line 683 of file sys_proc.c.

References curproc, LOG_DEBUG, and sys_getpgrp().

Referenced by sys_getpgrp().

◆ sys_getpid()

long sys_getpid ( void )

Implements getpid().

Returns
the calling process's ID

Definition at line 100 of file sys_proc.c.

References curproc, LOG_DEBUG, and sys_getpid().

Referenced by sys_getpid().

◆ sys_getppid()

long sys_getppid ( void )

Implements getppid().

Returns
the parent's process ID, or 0 if there is none

Definition at line 670 of file sys_proc.c.

References curproc, LOG_DEBUG, and sys_getppid().

Referenced by sys_getppid().

◆ sys_getrandom()

long sys_getrandom ( void * buf,
size_t len,
unsigned flags )

Implements getrandom() (and the C library's getentropy()): fills a buffer with random bytes.

Parameters
bufthe buffer
lenits size
flagsnot used
Returns
how many bytes were written, or -EFAULT

Definition at line 698 of file sys_proc.c.

References memset(), MIN, random_get(), sys_getrandom(), and uaccess_check().

Referenced by sys_getrandom().

◆ sys_getsockname()

long sys_getsockname ( int fd,
struct sockaddr * addr,
socklen_t * len )

Implements getsockname(): a socket's local address.

Parameters
fdthe socket
addrwhere to put the address
lenthe room at addr, set to the address's size
Returns
0, or a negative errno: -EBADF, -ENOTSOCK, -EFAULT

Definition at line 398 of file sys_net.c.

References LOG_DEBUG, socket_name(), and sys_getsockname().

Referenced by sys_getsockname().

◆ sys_getsockopt()

long sys_getsockopt ( int fd,
int level,
int name,
void * val,
socklen_t * len )

Implements getsockopt(): reads a socket option.

Parameters
fdthe socket
levelSOL_SOCKET, or a protocol's level
namethe option
valwhere to put its value
lenthe room at val, set to the value's size
Returns
0, or a negative errno: -EBADF, -ENOPROTOOPT, -EINVAL, -EFAULT

Definition at line 429 of file sys_net.c.

References fd_file(), LOG_DEBUG, memset(), MIN, socket_getsockopt(), and sys_getsockopt().

Referenced by sys_getsockopt().

◆ sys_gettimeofday()

long sys_gettimeofday ( struct timeval * tv,
struct timezone * tz )

Implements gettimeofday(): the time of day.

Parameters
tvwhere to put the time, or NULL
tzwhere to put the time zone, or NULL
Returns
0, or -EFAULT

Definition at line 85 of file sys_signal.c.

References gettimeofday(), LOG_DEBUG, and sys_gettimeofday().

Referenced by sys_gettimeofday().

◆ sys_getuid()

long sys_getuid ( void )

Implements getuid().

Returns
the calling process's user ID

Definition at line 487 of file sys_proc.c.

References curproc, LOG_DEBUG, and sys_getuid().

Referenced by sys_getuid().

◆ sys_ioctl()

long sys_ioctl ( int fd,
int request,
void * argp )

Implements ioctl(): a device's, a socket's, or a terminal's request.

FIONBIO, which sets the descriptor's O_NONBLOCK, works on any file.

Parameters
fdthe descriptor
requestthe request
argpits argument, in user memory
Returns
what the request returns, or a negative errno: -EBADF, -ENOTTY for a request the file doesn't know, -EFAULT

Definition at line 622 of file sys_file.c.

References fd_file(), FILE_SOCKET, file::flags, LOG_DEBUG, socket_ioctl(), sys_ioctl(), and vfs_file_ioctl().

Referenced by sys_ioctl().

◆ sys_isatty()

long sys_isatty ( int fildes)

Says whether a descriptor refers to a character device, the only kind of file that can be a terminal.

(The C library's isatty() asks the device with TCGETS instead.)

Parameters
fildesthe descriptor
Returns
1, -ENOTTY, or -EBADF

Definition at line 137 of file sys_file.c.

References fd_file(), FILE_SOCKET, file::flags, LOG_DEBUG, and sys_isatty().

Referenced by sys_isatty().

◆ sys_kill()

long sys_kill ( pid_t pid,
int sig )

Implements kill(): sends a signal to a process or a process group.

Parameters
pidwhom to: a process if > 0, the caller's process group if 0, every process but init and the caller if -1, or process group -pid if < -1
sigthe signal, or 0 to only check that the target exists
Returns
0, -EINVAL for a bad signal, or -ESRCH if there is no such process or group

Definition at line 19 of file sys_signal.c.

References LOG_DEBUG, signal_send(), and sys_kill().

Referenced by sys_kill().

◆ sys_lchown()

long sys_lchown ( const char * path,
uid_t owner,
gid_t group )

Implements lchown(): chown() of a symbolic link itself.

Parameters
paththe link's path
ownerthe new owner, or -1
groupthe new group, or -1
Returns
0, or a negative errno

Definition at line 1322 of file sys_file.c.

References do_fchownat(), LOG_DEBUG, and sys_lchown().

Referenced by sys_lchown().

◆ sys_link()

long sys_link ( const char * oldpath,
const char * newpath )

Implements link(): a new name for a file.

Parameters
oldpaththe file's path
newpaththe new name
Returns
0, or a negative errno: -ENOENT, -EEXIST, -EPERM, -EXDEV, -EACCES, ...

Definition at line 188 of file sys_file.c.

References do_linkat(), LOG_DEBUG, and sys_link().

Referenced by sys_link().

◆ sys_linkat()

long sys_linkat ( int olddirfd,
const char * oldpath,
int newdirfd,
const char * newpath,
int flags )

Implements linkat(): link(), with paths relative to directories.

Parameters
olddirfdthe directory oldpath is relative to, or AT_FDCWD
oldpaththe file's path
newdirfdthe directory newpath is relative to, or AT_FDCWD
newpaththe new name
flagsAT_SYMLINK_FOLLOW to link what a symbolic link points to
Returns
0, or a negative errno

Definition at line 205 of file sys_file.c.

References do_linkat(), uio::flags, LOG_DEBUG, and sys_linkat().

Referenced by sys_linkat().

◆ sys_listen()

long sys_listen ( int fd,
int backlog )

Implements listen(): makes a socket accept connections.

Parameters
fdthe socket
backloghow many connections may wait to be accepted
Returns
0, or a negative errno: -EBADF, -EINVAL, -EOPNOTSUPP

Definition at line 221 of file sys_net.c.

References fd_file(), LOG_DEBUG, socket_listen(), and sys_listen().

Referenced by sys_listen().

◆ sys_lseek()

long sys_lseek ( int fildes,
off_t offset,
int whence )

Implements lseek(): moves an open file's offset.

Parameters
fildesthe descriptor
offsetthe offset
whenceSEEK_SET, SEEK_CUR or SEEK_END
Returns
the new offset, or a negative errno: -EBADF, -ESPIPE (a socket, a pipe, a terminal), -EINVAL

Definition at line 221 of file sys_file.c.

References fd_file(), FILE_SOCKET, file::flags, LOG_DEBUG, file::offset, sys_lseek(), and vfs_file_lseek().

Referenced by sys_lseek().

◆ sys_lstat()

long sys_lstat ( const char * path,
struct aquila_stat * buf )

Implements lstat(): a file's attributes, a symbolic link's own.

Parameters
paththe file's path
bufwhere to put them
Returns
0, or a negative errno

Definition at line 1052 of file sys_file.c.

References do_fstatat(), LOG_DEBUG, and sys_lstat().

Referenced by sys_lstat().

◆ sys_mkdir()

long sys_mkdir ( const char * path,
mode_t mode )

Implements mkdir(): makes a directory.

Parameters
pathits path
modeits permissions (less the umask)
Returns
0, or a negative errno: -EEXIST, -ENOENT, -EACCES, ...

Definition at line 797 of file sys_file.c.

References do_mknodat(), LOG_DEBUG, and sys_mkdir().

Referenced by sys_mkdir().

◆ sys_mknod()

long sys_mknod ( const char * path,
uint32_t mode,
uint32_t dev )

Implements mknod(): makes a file, a directory, a FIFO, or (only root) a device file.

Parameters
pathits path
modeits type and permissions
deva device file's device number
Returns
0, or a negative errno: -EEXIST, -EPERM, -EINVAL, ...

Definition at line 1023 of file sys_file.c.

References do_mknodat(), LOG_DEBUG, vnode::mode, and sys_mknod().

Referenced by sys_mknod().

◆ sys_mknodat()

long sys_mknodat ( int dirfd,
const char * path,
uint32_t mode,
uint32_t dev )

Implements mknodat(): mknod(), with the path relative to a directory.

Parameters
dirfdthe directory, or AT_FDCWD
paththe new file's path
modeits type and permissions
deva device file's device number
Returns
0, or a negative errno

Definition at line 1039 of file sys_file.c.

References do_mknodat(), LOG_DEBUG, vnode::mode, and sys_mknodat().

Referenced by sys_mknodat().

◆ sys_mmap()

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.

Parameters
uargsthe arguments, in user memory: the address, length, protection, flags, descriptor and offset
retwhere to put the mapping's address
Returns
0, or a negative errno: -EBADF, -EINVAL, -ENODEV, -ENOMEM, -EFAULT

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().

◆ sys_mount()

long sys_mount ( struct aquila_mount_args * args)

Implements mount(): mounts a file system on a directory.

Only root may.

Parameters
argsthe arguments, in user memory: the file system's type, the directory, flags, and the data (the device and the options)
Returns
0, or a negative errno: -EPERM (not root), -ENOENT, -ENODEV, -EFAULT, ...

Definition at line 706 of file sys_file.c.

References curproc, kfree(), LOG_DEBUG, NULL, PROC_UIO, sys_mount(), upath_get(), and vfs_mount().

Referenced by sys_mount().

◆ sys_munmap()

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.

Parameters
addrthe mapping's address
lenits length
Returns
0, or -EINVAL if no mapping has that address and 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().

◆ sys_nanosleep()

long sys_nanosleep ( const struct aquila_timespec * req,
struct aquila_timespec * rem )

Implements nanosleep(): sleeps for a time.

A stop doesn't change the deadline: the call is restarted until the same time.

Parameters
reqhow long to sleep
remwhere to put the time left if a signal ends the sleep, or NULL
Returns
0, -EINTR if a handler ran, -EINVAL for a bad time, or -EFAULT

Definition at line 242 of file sys_signal.c.

References arch_rtime_ns(), curthread, ERESTARTNOHAND, LOG_DEBUG, sched_sleep(), and sys_nanosleep().

Referenced by sys_nanosleep().

◆ sys_open()

long sys_open ( const char * path,
int oflags,
mode_t mode )

Implements open(): opens a file on a new descriptor, creating it with O_CREAT.

Parameters
paththe file's path
oflagsO_* flags
modethe new file's permissions, with O_CREAT (less the umask)
Returns
the descriptor, or a negative errno: -ENOENT, -EACCES, -EEXIST, -EMFILE, -ENOTDIR, -ELOOP, ...

Definition at line 424 of file sys_file.c.

References do_openat(), LOG_DEBUG, and sys_open().

Referenced by sys_open().

◆ sys_openat()

long sys_openat ( int dirfd,
const char * path,
int oflags,
mode_t mode )

Implements openat(): open(), with the path relative to a directory.

Parameters
dirfdthe directory, or AT_FDCWD
paththe file's path
oflagsO_* flags
modethe new file's permissions, with O_CREAT
Returns
the descriptor, or a negative errno

Definition at line 439 of file sys_file.c.

References do_openat(), LOG_DEBUG, and sys_openat().

Referenced by sys_openat().

◆ sys_pipe()

long sys_pipe ( int fd[2])

Implements pipe(): makes a pipe, its read end and its write end open on two new descriptors.

Parameters
fdwhere to put the two descriptors
Returns
0, or a negative errno: -EMFILE, -ENOMEM, -EFAULT

Definition at line 810 of file sys_file.c.

References curproc, file_new(), kfree(), LOG_DEBUG, NULL, pipefs_pipe(), proc_fd_close(), proc_fd_get(), proc_fd_install(), proc_fd_release(), sys_pipe(), and uaccess_check().

Referenced by sys_pipe().

◆ sys_poll()

long sys_poll ( struct pollfd * fds,
nfds_t nfds,
int timeout_ms )

Implements poll(): waits until one of the descriptors can be read or written, or the timeout passes, and says which can.

Parameters
fdsthe descriptors and the events wanted, in user memory; their revents are set
nfdshow many there are
timeout_msthe timeout in ms, or -1 for none
Returns
how many descriptors have events (0 on timeout), or a negative errno: -EINVAL, -ENOMEM, -EFAULT, or -EINTR

Definition at line 198 of file sys_poll.c.

References curthread, ERESTARTNOHAND, fd_peek(), fd_ready(), fd_watch(), FDS_COUNT, kfree(), kmalloc(), LOG_DEBUG, NULL, poll_deadline(), poll_unregister(), sched_wait(), and sys_poll().

Referenced by sys_poll().

◆ sys_read()

long sys_read ( int fildes,
void * buf,
size_t nbytes )

Implements read().

Parameters
fildesthe descriptor
bufwhere to put the data
nbyteshow much to read, at most
Returns
how many bytes were read (0 at the end), or a negative errno: -EBADF, -EFAULT, -EAGAIN, -EINTR, ...

Definition at line 454 of file sys_file.c.

References fd_file(), iobuf_init(), LOG_DEBUG, sys_read(), uaccess_check(), and vfs_file_read().

Referenced by sys_read().

◆ sys_readdir()

long sys_readdir ( int fd,
struct dirent * dirent )

Reads a directory's next entry, for the C library's readdir().

Parameters
fdthe directory's descriptor
direntwhere to put the entry
Returns
a positive number if there was an entry, 0 at the end, or a negative errno: -EBADF, -ENOTDIR, -EFAULT

Definition at line 667 of file sys_file.c.

References fd_file(), FILE_SOCKET, file::flags, LOG_DEBUG, memset(), sys_readdir(), and vfs_file_readdir().

Referenced by sys_readdir().

◆ sys_readlinkat()

long sys_readlinkat ( int dirfd,
const char * upath,
char * buf,
size_t size )

Implements readlinkat(): what a symbolic link points to (not NUL-terminated).

Parameters
dirfdthe directory upath is relative to, or AT_FDCWD
upaththe link's path
bufwhere to put the target
sizethe room at buf; a longer target is cut
Returns
the target's length, or a negative errno: -EINVAL (not a link), -ENOENT, -EFAULT, ...

Definition at line 1426 of file sys_file.c.

References at_uio(), kfree(), kmalloc(), LOG_DEBUG, MIN, NULL, sys_readlinkat(), uaccess_check(), upath_get(), UPATH_MAX, and vfs_readlink().

Referenced by sys_readlinkat().

◆ sys_reboot()

long sys_reboot ( unsigned cmd)

Implements reboot(): restarts, halts or powers off the machine, or sets what Ctrl+Alt+Del does.

Only root may.

Parameters
cmdthe command (RB_*)
Returns
0 for the Ctrl+Alt+Del commands, -EPERM, or -EINVAL; the others don't return

Definition at line 740 of file sys_proc.c.

References curproc, kernel_reboot(), LOG_DEBUG, and sys_reboot().

Referenced by sys_reboot().

◆ sys_recv()

long sys_recv ( struct aquila_socket_io_args * us)

Implements recv() and recvfrom().

Parameters
usthe arguments, in user memory: the socket, the buffer, the flags, and where recvfrom() puts the sender's address
Returns
how many bytes were received (0 at the end), or a negative errno: -EBADF, -EFAULT, -EAGAIN, -ENOTCONN, ...

Definition at line 313 of file sys_net.c.

References fd_file(), fd::flags, iobuf_init(), LOG_DEBUG, memset(), NULL, ksockaddr::sa, sockaddr_copyout(), sockaddr_room(), socket_recv(), sys_recv(), and uaccess_check().

Referenced by sys_recv().

◆ sys_renameat()

long sys_renameat ( int olddirfd,
const char * oldpath,
int newdirfd,
const char * newpath )

Implements renameat() (and rename()): moves a file to another name, replacing what was there.

Parameters
olddirfdthe directory oldpath is relative to, or AT_FDCWD
oldpaththe file's path
newdirfdthe directory newpath is relative to, or AT_FDCWD
newpathits new path
Returns
0, or a negative errno: -ENOENT, -EXDEV, -EISDIR, -ENOTEMPTY, -EINVAL, ...

Definition at line 1464 of file sys_file.c.

References at_path(), kfree(), LOG_DEBUG, NULL, sys_renameat(), and vfs_rename().

Referenced by sys_renameat().

◆ sys_rmdir()

long sys_rmdir ( const char * path)

Implements rmdir(): removes an empty directory.

Parameters
paththe directory's path
Returns
0, or a negative errno: -ENOTEMPTY, -ENOTDIR, -EBUSY, ...

Definition at line 1383 of file sys_file.c.

References do_unlinkat(), LOG_DEBUG, and sys_rmdir().

Referenced by sys_rmdir().

◆ sys_sbrk()

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).

Parameters
incrhow many bytes to add (or take off, if negative)
Returns
the old end of the heap, or (uintptr_t) -1 if the heap can't change that much

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().

◆ sys_select()

long sys_select ( struct aquila_select_args * args)

Implements select() and pselect(): waits until a descriptor of the sets can be read or written, or the timeout passes, and says which can.

Exceptional conditions are never reported.

Parameters
argsthe arguments, in user memory: nfds, the read, write and except sets, the timeout, and pselect()'s signal mask
Returns
how many descriptors are ready (0 on timeout), or a negative errno: -EBADF, -EINVAL, -EFAULT, or -EINTR

Definition at line 68 of file sys_poll.c.

References curproc, curthread, ERESTARTNOHAND, FD_ADD, FD_BIT, fd_peek(), fd_ready(), FD_SETSIZE, fd_watch(), LOG_DEBUG, poll_deadline(), poll_unregister(), sched_wait(), SIG_UNMASKABLE, sys_select(), timeval::tv_sec, and timeval::tv_usec.

Referenced by sys_select().

◆ sys_send()

long sys_send ( struct aquila_socket_io_args * us)

Implements send() and sendto().

A send on a connection that can't send anymore also raises SIGPIPE, unless MSG_NOSIGNAL is set.

Parameters
usthe arguments, in user memory: the socket, the data, the flags, and sendto()'s destination
Returns
how many bytes were sent, or a negative errno: -EBADF, -EFAULT, -EPIPE, -EAGAIN, -EMSGSIZE, ...

Definition at line 249 of file sys_net.c.

References curproc, fd_file(), fd::flags, iobuf_init(), LOG_DEBUG, memset(), NULL, ksockaddr::sa, signal_proc_send(), sockaddr_copyin(), socket_send(), sys_send(), and uaccess_check().

Referenced by sys_send().

◆ sys_setgid()

long sys_setgid ( gid_t gid)

Implements setgid(): sets the process's group ID.

Root may set any ID, other users only their own.

Parameters
gidthe group ID
Returns
0, or -EPERM

Definition at line 470 of file sys_proc.c.

References curproc, LOG_DEBUG, and sys_setgid().

Referenced by sys_setgid().

◆ sys_sethostname()

long sys_sethostname ( const char * name,
size_t len )

Implements sethostname().

Only root may.

Parameters
namethe host name (not NUL-terminated)
lenits length
Returns
0, or a negative errno: -EPERM, -EINVAL if it's too long, -EFAULT

Definition at line 793 of file sys_proc.c.

References curproc, LOG_DEBUG, memcpy(), nodename, and sys_sethostname().

Referenced by sys_sethostname().

◆ sys_setitimer()

long sys_setitimer ( int which,
const struct aquila_itimer * new,
struct aquila_itimer * old )

Implements setitimer(): sets the real time timer, which sends SIGALRM, and reads the old one.

Parameters
whichAQUILA_ITIMER_REAL (the only timer supported)
newthe new timer, or NULL to only read the old one
oldwhere to put the old timer, or NULL
Returns
0, -EINVAL for another timer, or -EFAULT

Definition at line 201 of file sys_signal.c.

References curproc, LOG_DEBUG, sched_alarm(), sched_alarm_get(), and sys_setitimer().

Referenced by sys_setitimer().

◆ sys_setpgid()

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.

Parameters
pidthe process, or 0 for the caller
pgidthe group's ID, or 0 for the process's own ID (a new group)
Returns
0, or a negative errno: -EINVAL, -ESRCH, -EPERM, -ENOMEM

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().

◆ sys_setsid()

long sys_setsid ( void )

Implements setsid(): makes the calling process the leader of a new session and process group.

Returns
the new session's ID (the caller's process ID), or a negative errno: -EPERM for a process group leader, -ENOMEM

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().

◆ sys_setsockopt()

long sys_setsockopt ( int fd,
int level,
int name,
const void * val,
socklen_t len )

Implements setsockopt(): sets a socket option.

Parameters
fdthe socket
levelSOL_SOCKET, or a protocol's level
namethe option
valits value
lenthe value's size
Returns
0, or a negative errno: -EBADF, -ENOPROTOOPT, -EINVAL, -EPERM, -EFAULT

Definition at line 470 of file sys_net.c.

References fd_file(), LOG_DEBUG, MIN, socket_setsockopt(), and sys_setsockopt().

Referenced by sys_setsockopt().

◆ sys_setuid()

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.

Parameters
uidthe user ID
Returns
0, or -EPERM

Definition at line 451 of file sys_proc.c.

References curproc, LOG_DEBUG, and sys_setuid().

Referenced by sys_setuid().

◆ sys_shutdown()

long sys_shutdown ( int fd,
int how )

Implements shutdown(): shuts down reading, writing or both on a socket, which stays open.

Parameters
fdthe socket
howSHUT_RD, SHUT_WR or SHUT_RDWR
Returns
0, or a negative errno: -EBADF, -ENOTSOCK, -ENOTCONN, -EINVAL

Definition at line 501 of file sys_net.c.

References fd_file(), LOG_DEBUG, socket_shutdown_dir(), and sys_shutdown().

Referenced by sys_shutdown().

◆ sys_sigaction()

long sys_sigaction ( int sig,
const struct aquila_sigaction * act,
struct aquila_sigaction * oact )

Implements sigaction(): reads a signal's action, and sets a new one.

Parameters
sigthe signal
actthe new action, or NULL to leave it
oactwhere to put the old action, or NULL
Returns
0, -EINVAL for a bad signal (or catching SIGKILL or SIGSTOP), or -EFAULT

Definition at line 37 of file sys_signal.c.

References curproc, LOG_DEBUG, SIG_DFL, SIG_IGN, SIG_MAX, signal_action_set(), sys_sigaction(), and uaccess_check().

Referenced by sys_sigaction().

◆ sys_sigmask()

long sys_sigmask ( int how,
const sigset_t * set,
sigset_t * oldset )

Implements sigprocmask(): reads and changes the process's signal mask.

SIGKILL and SIGSTOP can't be blocked.

Parameters
howSIG_BLOCK, SIG_UNBLOCK or SIG_SETMASK
setthe signals, or NULL to leave the mask
oldsetwhere to put the old mask, or NULL
Returns
0, -EINVAL for a bad how, or -EFAULT

Definition at line 108 of file sys_signal.c.

References curproc, LOG_DEBUG, SIG_UNMASKABLE, and sys_sigmask().

Referenced by sys_sigmask().

◆ sys_sigreturn()

long sys_sigreturn ( void )

Implements sigreturn(): a signal handler returns, and the registers and signal mask that its frame saved are restored.

The kernel's signal code page calls it when a handler returns.

Returns
0, which syscall_dispatch() ignores: the registers are the frame's

Definition at line 182 of file sys_signal.c.

References arch_sigreturn(), LOG_DEBUG, and sys_sigreturn().

Referenced by sys_sigreturn().

◆ sys_sigsuspend()

long sys_sigsuspend ( const sigset_t * set)

Implements sigsuspend(): replaces the signal mask and waits for a signal.

The old mask comes back once a handler has run.

Parameters
setthe mask to wait with
Returns
-EINTR once a handler has run (it is restarted after a stop), or -EFAULT

Definition at line 146 of file sys_signal.c.

References curproc, curthread, ERESTARTNOHAND, LOG_DEBUG, thread::sig_oldmask, thread::sig_oldmask_set, SIG_UNMASKABLE, sys_sigsuspend(), and waitq_sleep().

Referenced by sys_sigsuspend().

◆ sys_socket()

long sys_socket ( int domain,
int type,
int protocol )

Implements socket(): makes a socket, open on a new descriptor.

Parameters
domainAF_UNIX or AF_INET
typeSOCK_STREAM or SOCK_DGRAM
protocolthe protocol, or 0 for the type's default
Returns
the descriptor, or a negative errno: -EMFILE, -ENOMEM, -EAFNOSUPPORT, -EPROTONOSUPPORT

Definition at line 19 of file sys_net.c.

References curproc, file_new(), kfree(), LOG_DEBUG, proc_fd_get(), proc_fd_install(), proc_fd_release(), socket_create(), and sys_socket().

Referenced by sys_socket().

◆ sys_stat()

long sys_stat ( const char * path,
struct aquila_stat * buf )

Implements stat(): a file's attributes, following a symbolic link.

Parameters
paththe file's path
bufwhere to put them
Returns
0, or a negative errno: -ENOENT, -EACCES, -EFAULT, ...

Definition at line 504 of file sys_file.c.

References do_fstatat(), LOG_DEBUG, and sys_stat().

Referenced by sys_stat().

◆ sys_symlinkat()

long sys_symlinkat ( const char * utarget,
int dirfd,
const char * upath )

Implements symlinkat(): makes a symbolic link.

Parameters
utargetwhat it points to
dirfdthe directory upath is relative to, or AT_FDCWD
upaththe link's path
Returns
0, or a negative errno: -EEXIST, -ENOENT, -EACCES, ...

Definition at line 1397 of file sys_file.c.

References at_uio(), kfree(), LOG_DEBUG, NULL, sys_symlinkat(), upath_get(), and vfs_symlink().

Referenced by sys_symlinkat().

◆ sys_sync()

long sys_sync ( void )

Implements sync(): writes out what the devices' caches hold.

Returns
0, or a negative errno from a device

Definition at line 1508 of file sys_file.c.

References kdev_sync(), LOG_DEBUG, and sys_sync().

Referenced by sys_sync().

◆ sys_sysconf()

long sys_sysconf ( int name)

Implements sysconf(): not supported; the C library answers it.

Parameters
namethe variable
Returns
-ENOSYS

Definition at line 659 of file sys_proc.c.

References LOG_DEBUG, and sys_sysconf().

Referenced by sys_sysconf().

◆ sys_thread_create()

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.

Parameters
__uthreadthe arguments, in user memory: the thread's stack, the C library's start, the thread's function and its argument
Returns
the new thread's ID, or a negative errno: -EFAULT, -ENOMEM

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().

◆ sys_thread_exit()

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.

Parameters
value_ptrthe value that thread_join() returns
Returns
nothing: it doesn't return

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().

◆ sys_thread_join()

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()).

Parameters
tidthe thread's ID
value_ptrwhere to put the value it ended with, or NULL
Returns
the thread's ID, or a negative errno: -ESRCH (no such thread, or joined already), -EDEADLK (the caller itself), -EINTR, -EFAULT

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().

◆ sys_thread_self()

long sys_thread_self ( void )

Returns the calling thread's ID, for pthread_self().

Returns
the thread's ID

Definition at line 727 of file sys_proc.c.

References curthread, and sys_thread_self().

Referenced by sys_thread_self().

◆ sys_times()

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).

Parameters
bufwhere to put them
Returns
the real time since boot, in ticks, or -EFAULT

Definition at line 148 of file sys_proc.c.

References arch_rtime_ns(), curproc, LOG_DEBUG, sys_times(), and tick.

Referenced by sys_times().

◆ sys_umask()

long sys_umask ( mode_t mask)

Implements umask(): sets the permissions that new files don't get.

Parameters
maskthe new mask
Returns
the old mask

Definition at line 1089 of file sys_file.c.

References curproc, LOG_DEBUG, and sys_umask().

Referenced by sys_umask().

◆ sys_uname()

long sys_uname ( struct utsname * name)

Implements uname(): the system's name, release, version and machine, and the host name.

Parameters
namewhere to put them
Returns
0, or -EFAULT

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().

◆ sys_unlink()

long sys_unlink ( const char * path)

Implements unlink(): removes a name of a file (not a directory's).

Parameters
paththe name
Returns
0, or a negative errno: -ENOENT, -EISDIR, -EACCES, ...

Definition at line 553 of file sys_file.c.

References do_unlinkat(), LOG_DEBUG, and sys_unlink().

Referenced by sys_unlink().

◆ sys_unlinkat()

long sys_unlinkat ( int dirfd,
const char * path,
int flags )

Implements unlinkat(): unlink(), or rmdir() with AT_REMOVEDIR, with the path relative to a directory.

Parameters
dirfdthe directory, or AT_FDCWD
paththe name
flagsAT_REMOVEDIR to remove a directory
Returns
0, or a negative errno

Definition at line 568 of file sys_file.c.

References do_unlinkat(), uio::flags, LOG_DEBUG, and sys_unlinkat().

Referenced by sys_unlinkat().

◆ sys_utimensat()

long sys_utimensat ( int dirfd,
const char * path,
const struct aquila_timespec times[2],
int flags )

Implements utimensat() (and futimens()): sets a file's access and modification times.

Parameters
dirfdthe directory path is relative to, or AT_FDCWD; with a NULL path, the file itself (futimens())
paththe file's path, or NULL
timesthe two times, or NULL for now
flagsAT_SYMLINK_NOFOLLOW for a symbolic link's own
Returns
0, or a negative errno: -EINVAL, -EFAULT, -ENOENT, -EPERM, ...

Definition at line 1340 of file sys_file.c.

References at_lookup(), curproc, fd_vnode(), uio::flags, LOG_DEBUG, NULL, PROC_UIO, sys_utimensat(), vfs_close(), and vfs_utimens().

Referenced by sys_utimensat().

◆ sys_waitpid()

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.

Parameters
pidwhich 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_locwhere to put its status, or NULL
optionsWNOHANG, WUNTRACED, WCONTINUED
Returns
the child's process ID, 0 if WNOHANG and none is ready, or a negative errno: -ECHILD, -EINTR, -EFAULT

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().

◆ sys_write()

long sys_write ( int fd,
void * buf,
size_t nbytes )

Implements write().

Writing to a pipe that no one reads also raises SIGPIPE.

Parameters
fdthe descriptor
bufthe data
nbyteshow much to write
Returns
how many bytes were written, or a negative errno: -EBADF, -EFAULT, -EPIPE, -EAGAIN, -ENOSPC, ...

Definition at line 584 of file sys_file.c.

References curproc, fd_file(), iobuf_init(), LOG_DEBUG, signal_proc_send(), sys_write(), uaccess_check(), and vfs_file_write().

Referenced by sys_write().

◆ upath_get()

int upath_get ( const char * upath,
char ** path )

Copies a path from user memory into a new kernel buffer.

Parameters
upaththe path, in user memory
pathset to the kernel's copy, which the caller frees with kfree(); NULL on failure
Returns
0, -ENOMEM if there was no memory for the copy, -EFAULT if upath is a bad address, or -ENAMETOOLONG if the path is longer than UPATH_MAX

Definition at line 46 of file syscall.c.

References kfree(), kmalloc(), NULL, upath_get(), and UPATH_MAX.

Referenced by at_lookup(), at_path(), do_mknodat(), do_openat(), do_unlinkat(), sys_chdir(), sys_execve(), sys_mount(), sys_readlinkat(), sys_symlinkat(), and upath_get().