AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
syscalls.h
Go to the documentation of this file.
1#ifndef _SYS_SYSCALLS_H
2#define _SYS_SYSCALLS_H
3
4/*
5 * Every system call's handler, sys_<name>(), with its own argument types
6 * and a long result (a negative result is an errno), grouped by the file
7 * it is in. sys/syscall.c's table calls them through SYSCALLn(). This
8 * header is private to sys/; the handlers' comments are in their files.
9 */
10
11#include <core/system.h>
12#include <aquila/syscall.h>
13#include <core/panic.h>
14#include <core/string.h>
15#include <core/arch.h>
16#include <core/time.h>
17
18#include <sys/proc.h>
19#include <sys/sched.h>
20#include <sys/signal.h>
21#include <sys/binfmt.h>
22#include <sys/uaccess.h>
23#include <sys/syscall.h>
24
25#include <fs/iobuf.h>
26
27#include <net/socket.h>
28
29#include <aquila/errno.h>
30#include <aquila/dirent.h>
31#include <aquila/utsname.h>
32#include <aquila/fcntl.h>
33#include <aquila/mman.h>
34#include <aquila/time.h>
35#include <aquila/ioctl.h>
36#include <aquila/wait.h>
37#include <aquila/poll.h>
38#include <aquila/un.h>
39
40#include <fs/devpts.h>
41#include <fs/pipe.h>
42#include <fs/stat.h>
43
44#include <mm/vm.h>
45#include <sys/reboot.h>
46#include <dev/random.h>
47
48
49LOGGER_DECLARE(syscall_log)
50
51/* syscall.c: what several kinds of calls share */
52struct file *fd_file(int fd);
53/* the longest path a call takes, with its NUL (as newlib's PATH_MAX) */
54#define UPATH_MAX 1024
55int upath_get(const char *upath, char **path);
56
57/* sys_file.c: files, their names and attributes, directories, mounts and
58 * locks */
59long sys_close(int fildes);
60long sys_fstat(int fildes, struct aquila_stat *buf);
61long sys_isatty(int fildes);
62long sys_link(const char *oldpath, const char *newpath);
63long sys_linkat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath, int flags);
64long sys_lseek(int fildes, off_t offset, int whence);
65long sys_open(const char *path, int oflags, mode_t mode);
66long sys_openat(int dirfd, const char *path, int oflags, mode_t mode);
67long sys_read(int fildes, void *buf, size_t nbytes);
68long sys_stat(const char *path, struct aquila_stat *buf);
69long sys_fstatat(int dirfd, const char *path, struct aquila_stat *buf, int flags);
70long sys_unlink(const char *path);
71long sys_unlinkat(int dirfd, const char *path, int flags);
72long sys_write(int fd, void *buf, size_t nbytes);
73long sys_ioctl(int fd, int request, void *argp);
74long sys_readdir(int fd, struct dirent *dirent);
75long sys_mount(struct aquila_mount_args *args);
76long sys_mkdir(const char *path, mode_t mode);
77long sys_pipe(int fd[2]);
78long sys_fcntl(int fd, int cmd, uintptr_t arg);
79long sys_chdir(const char *upath);
80long sys_getcwd(char *buf, size_t size);
81long sys_mknod(const char *path, uint32_t mode, uint32_t dev);
82long sys_mknodat(int dirfd, const char *path, uint32_t mode, uint32_t dev);
83long sys_lstat(const char *path, struct aquila_stat *buf);
84long sys_ftruncate(int fildes, off_t len);
85long sys_umask(mode_t mask);
86long sys_chmod(const char *path, mode_t mode);
87long sys_fchmodat(int dirfd, const char *path, mode_t mode, int flags);
88long sys_fchmod(int fd, mode_t mode);
89long sys_access(const char *path, int mode);
90long sys_faccessat(int dirfd, const char *path, int mode, int flags);
91long sys_chown(const char *path, uid_t owner, gid_t group);
92long sys_fchownat(int dirfd, const char *path, uid_t owner, gid_t group, int flags);
93long sys_fchown(int fd, uid_t owner, gid_t group);
94long sys_lchown(const char *path, uid_t owner, gid_t group);
95long sys_utimensat(int dirfd, const char *path, const struct aquila_timespec times[2], int flags);
96long sys_rmdir(const char *path);
97long sys_symlinkat(const char *utarget, int dirfd, const char *upath);
98long sys_readlinkat(int dirfd, const char *upath, char *buf, size_t size);
99long sys_renameat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath);
100long sys_flock(int fd, int op);
101long sys_sync(void);
102long sys_fchdir(int fd);
103
104/* sys_proc.c: processes and threads, their IDs and groups, memory, and
105 * the machine */
106long sys_exit(int code);
107long sys_execve(const char *path, char * const argp[], char * const envp[]);
108long sys_fork(void);
109long sys_getpid(void);
110long sys_sbrk(ptrdiff_t incr);
111long sys_times(struct aquila_tms *buf);
112long sys_waitpid(int pid, int *stat_loc, int options);
113long sys_uname(struct utsname *name);
114long sys_thread_create(struct aquila_thread_args *__uthread);
115long sys_thread_exit(void *value_ptr);
116long sys_thread_join(int tid, void **value_ptr);
117long sys_setpgid(pid_t pid, pid_t pgid);
118long sys_setuid(uid_t uid);
119long sys_setgid(gid_t gid);
120long sys_getuid(void);
121long sys_getgid(void);
122long sys_mmap(struct aquila_mmap_args *uargs, void **ret);
123long sys_munmap(void *addr, size_t len);
124long sys_sysconf(int name);
125long sys_getppid(void);
126long sys_getpgrp(void);
127long sys_getrandom(void *buf, size_t len, unsigned flags __unused);
128long sys_thread_self(void);
129long sys_reboot(unsigned cmd);
130long sys_setsid(void);
131long sys_sethostname(const char *name, size_t len);
132
133/* sys_signal.c: signals, timers, sleeping and the clocks */
134long sys_kill(pid_t pid, int sig);
135long sys_sigaction(int sig, const struct aquila_sigaction *act, struct aquila_sigaction *oact);
136long sys_gettimeofday(struct timeval *tv, struct timezone *tz);
137long sys_sigmask(int how, const sigset_t *set, sigset_t *oldset);
138long sys_sigsuspend(const sigset_t *set);
139long sys_sigreturn(void);
140long sys_setitimer(int which, const struct aquila_itimer *new, struct aquila_itimer *old);
141long sys_nanosleep(const struct aquila_timespec *req, struct aquila_timespec *rem);
142long sys_clock_gettime(int clock, struct aquila_timespec *ts);
143
144/* sys_net.c: sockets */
145long sys_socket(int domain, int type, int protocol);
146long sys_accept(int fd, const struct sockaddr *addr, socklen_t *len);
147long sys_bind(int fd, const struct sockaddr *addr, socklen_t len);
148long sys_connect(int fd, const struct sockaddr *addr, socklen_t len);
149long sys_listen(int fd, int backlog);
150long sys_send(struct aquila_socket_io_args *us);
151long sys_recv(struct aquila_socket_io_args *us);
152long sys_getsockname(int fd, struct sockaddr *addr, socklen_t *len);
153long sys_getpeername(int fd, struct sockaddr *addr, socklen_t *len);
154long sys_getsockopt(int fd, int level, int name, void *val, socklen_t *len);
155long sys_setsockopt(int fd, int level, int name, const void *val, socklen_t len);
156long sys_shutdown(int fd, int how);
157
158/* sys_poll.c: select() and poll(), waiting for any of several descriptors */
159long sys_select(struct aquila_select_args *args);
160long sys_poll(struct pollfd *fds, nfds_t nfds, int timeout_ms);
161
162#endif /* ! _SYS_SYSCALLS_H */
static uint32_t clock
Definition arp.c:37
#define LOGGER_DECLARE(name)
Definition printk.h:42
__SIZE_TYPE__ uintptr_t
Definition stddef.h:12
unsigned int uint32_t
Definition stddef.h:22
__PTRDIFF_TYPE__ ptrdiff_t
Definition stddef.h:10
A device driver: its operations, any of which may be NULL.
Definition dev.h:28
A file descriptor: the open file it refers to (fs/file.c, shared with the descriptors that dup() and ...
Definition proc.h:47
An open file (POSIX's "open file description", fs/file.c).
Definition vfs.h:157
off_t offset
Definition vfs.h:163
int flags
Definition vfs.h:164
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...
Definition syscall.c:22
int upath_get(const char *upath, char **path)
Copies a path from user memory into a new kernel buffer.
Definition syscall.c:46
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.
Definition sys_file.c:1340
long sys_mkdir(const char *path, mode_t mode)
Implements mkdir(): makes a directory.
Definition sys_file.c:797
long sys_access(const char *path, int mode)
Implements access(): says whether the process may read, write or execute a file.
Definition sys_file.c:1220
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...
Definition sys_file.c:876
long sys_linkat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath, int flags)
Implements linkat(): link(), with paths relative to directories.
Definition sys_file.c:205
long sys_ioctl(int fd, int request, void *argp)
Implements ioctl(): a device's, a socket's, or a terminal's request.
Definition sys_file.c:622
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.
Definition sys_file.c:1286
long sys_umask(mode_t mask)
Implements umask(): sets the permissions that new files don't get.
Definition sys_file.c:1089
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.
Definition sys_file.c:424
long sys_chdir(const char *upath)
Implements chdir(): changes the working directory.
Definition sys_file.c:956
long sys_flock(int fd, int op)
Implements flock(): takes or releases an advisory lock on an open file.
Definition sys_file.c:1490
long sys_symlinkat(const char *utarget, int dirfd, const char *upath)
Implements symlinkat(): makes a symbolic link.
Definition sys_file.c:1397
long sys_close(int fildes)
Implements close(): frees a descriptor.
Definition sys_file.c:86
long sys_lseek(int fildes, off_t offset, int whence)
Implements lseek(): moves an open file's offset.
Definition sys_file.c:221
long sys_sync(void)
Implements sync(): writes out what the devices' caches hold.
Definition sys_file.c:1508
long sys_pipe(int fd[2])
Implements pipe(): makes a pipe, its read end and its write end open on two new descriptors.
Definition sys_file.c:810
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.
Definition sys_file.c:1464
long sys_fstatat(int dirfd, const char *path, struct aquila_stat *buf, int flags)
Implements fstatat(): stat(), with the path relative to a directory.
Definition sys_file.c:520
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.
Definition sys_file.c:568
long sys_lchown(const char *path, uid_t owner, gid_t group)
Implements lchown(): chown() of a symbolic link itself.
Definition sys_file.c:1322
long sys_ftruncate(int fildes, off_t len)
Implements ftruncate(): sets an open file's size.
Definition sys_file.c:1065
long sys_readlinkat(int dirfd, const char *upath, char *buf, size_t size)
Implements readlinkat(): what a symbolic link points to (not NUL-terminated).
Definition sys_file.c:1426
long sys_write(int fd, void *buf, size_t nbytes)
Implements write().
Definition sys_file.c:584
long sys_readdir(int fd, struct dirent *dirent)
Reads a directory's next entry, for the C library's readdir().
Definition sys_file.c:667
long sys_isatty(int fildes)
Says whether a descriptor refers to a character device, the only kind of file that can be a terminal.
Definition sys_file.c:137
long sys_fchmod(int fd, mode_t mode)
Implements fchmod(): changes an open file's permissions.
Definition sys_file.c:1172
long sys_getcwd(char *buf, size_t size)
Implements getcwd(): the working directory's path.
Definition sys_file.c:985
long sys_read(int fildes, void *buf, size_t nbytes)
Implements read().
Definition sys_file.c:454
long sys_chown(const char *path, uid_t owner, gid_t group)
Implements chown(): changes a file's owner and group.
Definition sys_file.c:1269
long sys_chmod(const char *path, mode_t mode)
Implements chmod(): changes a file's permissions.
Definition sys_file.c:1129
long sys_fchmodat(int dirfd, const char *path, mode_t mode, int flags)
Implements fchmodat(): chmod(), with the path relative to a directory.
Definition sys_file.c:1145
long sys_mknodat(int dirfd, const char *path, uint32_t mode, uint32_t dev)
Implements mknodat(): mknod(), with the path relative to a directory.
Definition sys_file.c:1039
long sys_fchown(int fd, uid_t owner, gid_t group)
Implements fchown(): changes an open file's owner and group.
Definition sys_file.c:1301
long sys_lstat(const char *path, struct aquila_stat *buf)
Implements lstat(): a file's attributes, a symbolic link's own.
Definition sys_file.c:1052
long sys_stat(const char *path, struct aquila_stat *buf)
Implements stat(): a file's attributes, following a symbolic link.
Definition sys_file.c:504
long sys_openat(int dirfd, const char *path, int oflags, mode_t mode)
Implements openat(): open(), with the path relative to a directory.
Definition sys_file.c:439
long sys_link(const char *oldpath, const char *newpath)
Implements link(): a new name for a file.
Definition sys_file.c:188
long sys_faccessat(int dirfd, const char *path, int mode, int flags)
Implements faccessat(): access(), with the path relative to a directory.
Definition sys_file.c:1236
long sys_rmdir(const char *path)
Implements rmdir(): removes an empty directory.
Definition sys_file.c:1383
long sys_fchdir(int fd)
Implements fchdir(): changes the working directory to an open directory.
Definition sys_file.c:1523
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.
Definition sys_file.c:1023
long sys_unlink(const char *path)
Implements unlink(): removes a name of a file (not a directory's).
Definition sys_file.c:553
long sys_mount(struct aquila_mount_args *args)
Implements mount(): mounts a file system on a directory.
Definition sys_file.c:706
long sys_fstat(int fildes, struct aquila_stat *buf)
Implements fstat(): an open file's attributes.
Definition sys_file.c:103
long sys_getpeername(int fd, struct sockaddr *addr, socklen_t *len)
Implements getpeername(): the address of a socket's peer.
Definition sys_net.c:412
long sys_getsockname(int fd, struct sockaddr *addr, socklen_t *len)
Implements getsockname(): a socket's local address.
Definition sys_net.c:398
long sys_connect(int fd, const struct sockaddr *addr, socklen_t len)
Implements connect(): connects a socket to a peer.
Definition sys_net.c:192
long sys_socket(int domain, int type, int protocol)
Implements socket(): makes a socket, open on a new descriptor.
Definition sys_net.c:19
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.
Definition sys_net.c:97
long sys_getsockopt(int fd, int level, int name, void *val, socklen_t *len)
Implements getsockopt(): reads a socket option.
Definition sys_net.c:429
long sys_recv(struct aquila_socket_io_args *us)
Implements recv() and recvfrom().
Definition sys_net.c:313
long sys_send(struct aquila_socket_io_args *us)
Implements send() and sendto().
Definition sys_net.c:249
long sys_shutdown(int fd, int how)
Implements shutdown(): shuts down reading, writing or both on a socket, which stays open.
Definition sys_net.c:501
long sys_setsockopt(int fd, int level, int name, const void *val, socklen_t len)
Implements setsockopt(): sets a socket option.
Definition sys_net.c:470
long sys_listen(int fd, int backlog)
Implements listen(): makes a socket accept connections.
Definition sys_net.c:221
long sys_bind(int fd, const struct sockaddr *addr, socklen_t len)
Implements bind(): gives a socket its local address.
Definition sys_net.c:161
long sys_select(struct aquila_select_args *args)
Implements select() and pselect(): waits until a descriptor of the sets can be read or written,...
Definition sys_poll.c:68
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,...
Definition sys_poll.c:198
long sys_setuid(uid_t uid)
Implements setuid(): sets the process's user ID.
Definition sys_proc.c:451
long sys_uname(struct utsname *name)
Implements uname(): the system's name, release, version and machine, and the host name.
Definition sys_proc.c:259
long sys_thread_self(void)
Returns the calling thread's ID, for pthread_self().
Definition sys_proc.c:727
long sys_setgid(gid_t gid)
Implements setgid(): sets the process's group ID.
Definition sys_proc.c:470
long sys_getgid(void)
Implements getgid().
Definition sys_proc.c:498
long sys_getpid(void)
Implements getpid().
Definition sys_proc.c:100
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...
Definition sys_proc.c:418
long sys_getpgrp(void)
Implements getpgrp().
Definition sys_proc.c:683
long sys_sethostname(const char *name, size_t len)
Implements sethostname().
Definition sys_proc.c:793
long sys_thread_exit(void *value_ptr)
Ends the calling thread (for pthread_exit()).
Definition sys_proc.c:325
long sys_getrandom(void *buf, size_t len, unsigned flags)
Implements getrandom() (and the C library's getentropy()): fills a buffer with random bytes.
Definition sys_proc.c:698
long sys_fork(void)
Implements fork(): makes a child process, a copy of the caller.
Definition sys_proc.c:76
long sys_setsid(void)
Implements setsid(): makes the calling process the leader of a new session and process group.
Definition sys_proc.c:758
long sys_munmap(void *addr, size_t len)
Implements munmap(): removes a mapping.
Definition sys_proc.c:622
long sys_mmap(struct aquila_mmap_args *uargs, void **ret)
Implements mmap(): maps anonymous memory or a file into the calling process.
Definition sys_proc.c:514
long sys_sbrk(ptrdiff_t incr)
Implements sbrk(): grows or shrinks the heap.
Definition sys_proc.c:114
long sys_times(struct aquila_tms *buf)
Implements times(): the CPU times of the process and of its children that it waited for,...
Definition sys_proc.c:148
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.
Definition sys_proc.c:286
long sys_getppid(void)
Implements getppid().
Definition sys_proc.c:670
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...
Definition sys_proc.c:181
long sys_reboot(unsigned cmd)
Implements reboot(): restarts, halts or powers off the machine, or sets what Ctrl+Alt+Del does.
Definition sys_proc.c:740
long sys_getuid(void)
Implements getuid().
Definition sys_proc.c:487
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()).
Definition sys_proc.c:367
long sys_execve(const char *path, char *const argp[], char *const envp[])
Implements execve(): runs another program in the calling process.
Definition sys_proc.c:42
long sys_sysconf(int name)
Implements sysconf(): not supported; the C library answers it.
Definition sys_proc.c:659
long sys_exit(int code)
Implements _exit(): ends the calling process.
Definition sys_proc.c:16
long sys_sigreturn(void)
Implements sigreturn(): a signal handler returns, and the registers and signal mask that its frame sa...
Definition sys_signal.c:182
long sys_clock_gettime(int clock, struct aquila_timespec *ts)
Implements clock_gettime(): reads a clock.
Definition sys_signal.c:293
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.
Definition sys_signal.c:201
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.
Definition sys_signal.c:37
long sys_kill(pid_t pid, int sig)
Implements kill(): sends a signal to a process or a process group.
Definition sys_signal.c:19
long sys_gettimeofday(struct timeval *tv, struct timezone *tz)
Implements gettimeofday(): the time of day.
Definition sys_signal.c:85
long sys_nanosleep(const struct aquila_timespec *req, struct aquila_timespec *rem)
Implements nanosleep(): sleeps for a time.
Definition sys_signal.c:242
long sys_sigmask(int how, const sigset_t *set, sigset_t *oldset)
Implements sigprocmask(): reads and changes the process's signal mask.
Definition sys_signal.c:108
long sys_sigsuspend(const sigset_t *set)
Implements sigsuspend(): replaces the signal mask and waits for a signal.
Definition sys_signal.c:146
static void options(const struct tcp_hdr *th, size_t hlen, struct seg *s)
Reads a segment's options; the only one used is the MSS.
Definition tcp_input.c:36
int pid_t
Definition types.h:8
unsigned long sigset_t
Definition types.h:27
long int off_t
Definition types.h:10
uint32_t gid_t
Definition types.h:21
uint32_t uid_t
Definition types.h:20
uint32_t mode_t
Definition types.h:15