The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
syscall_internal.h File Reference

Go to the source code of this file.

Macros

#define AT_FDCWD   (-100)
#define AT_SYMLINK_NOFOLLOW   0x100
#define AT_REMOVEDIR   0x200
#define AT_SYMLINK_FOLLOW   0x400
#define AT_EACCESS   0x200

Typedefs

typedef uintptr_t syscall_arg_t
 one syscall argument or return value: pointer-width, so a user address passes through unchanged.
typedef intptr_t syscall_ret_t
 syscall function pointer type.
typedef syscall_ret_t(*) syscall_fn_t(struct registers *regs)

Functions

int32_t resolve_user_path (const char *user_path, char *resolved, uint32_t size)
 copy a path string in from user memory and resolve it against the current process's cwd.
int32_t resolve_user_path_at (int32_t dirfd, const char *user_path, char *resolved, uint32_t size, bool follow)
 as resolve_user_path, with a relative path taken in the directory open as dirfd (AT_FDCWD: the working directory).
int32_t set_new_owner (const char *path, uint32_t mode)
 give a file the caller has just created its mode (taken through the umask) and the caller's effective user and group as owner.
syscall_ret_t sys_write (struct registers *regs)
 SYS_write: write bytes to a file descriptor.
syscall_ret_t sys_read (struct registers *regs)
 SYS_read: read bytes from a file descriptor.
syscall_ret_t sys_open (struct registers *regs)
syscall_ret_t sys_flock (struct registers *regs)
 SYS_flock: an advisory lock on a whole file (kernel/vfs/flock.h).
syscall_ret_t sys_openat (struct registers *regs)
 SYS_openat: open relative to a directory.
syscall_ret_t sys_close (struct registers *regs)
 SYS_close: close an open file descriptor.
syscall_ret_t sys_lseek (struct registers *regs)
 SYS_lseek: set the file offset.
syscall_ret_t sys_ftruncate (struct registers *regs)
 SYS_ftruncate: cut or grow an open file to a length.
syscall_ret_t sys_dup2 (struct registers *regs)
 SYS_dup2: make new_fd another descriptor for old_fd's open file.
syscall_ret_t sys_pipe (struct registers *regs)
 SYS_pipe: create a pipe (pair of connected file descriptors).
syscall_ret_t sys_stat (struct registers *regs)
 SYS_stat: get file metadata.
syscall_ret_t sys_mkdir (struct registers *regs)
 SYS_mkdir: create a directory.
syscall_ret_t sys_unlink (struct registers *regs)
 SYS_unlink: remove a file.
syscall_ret_t sys_rmdir (struct registers *regs)
 SYS_rmdir: remove a directory.
syscall_ret_t sys_fstatat (struct registers *regs)
 SYS_fstatat: stat a path relative to a directory.
syscall_ret_t sys_renameat (struct registers *regs)
 SYS_renameat: rename, each path relative to its own directory.
syscall_ret_t sys_faccessat (struct registers *regs)
 SYS_faccessat: access, relative to a directory.
syscall_ret_t sys_mkdirat (struct registers *regs)
 SYS_mkdirat: mkdir relative to a directory.
syscall_ret_t sys_unlinkat (struct registers *regs)
 SYS_unlinkat: remove a file or (AT_REMOVEDIR) a directory, relative to a directory.
syscall_ret_t sys_symlinkat (struct registers *regs)
 SYS_symlinkat: make a symbolic link.
syscall_ret_t sys_readlinkat (struct registers *regs)
 SYS_readlinkat: read the target of a symbolic link.
syscall_ret_t sys_linkat (struct registers *regs)
 SYS_linkat: give a file one more name (a hard link).
syscall_ret_t sys_utimensat (struct registers *regs)
 SYS_utimensat: set a file's access and modification times.
syscall_ret_t sys_mknodat (struct registers *regs)
 SYS_mknodat: make a named pipe, a device node or an empty file.
syscall_ret_t sys_chroot (struct registers *regs)
 SYS_chroot: make a directory the caller's root: its paths start there, and ".." stops there (root only).
syscall_ret_t sys_clone (struct registers *regs)
 SYS_clone: make a thread of the current process.
syscall_ret_t sys_exit_group (struct registers *regs)
 SYS_exit_group: end every thread of the current process.
syscall_ret_t sys_gettid (struct registers *regs)
 SYS_gettid: the calling thread's id (the pid for a single thread).
syscall_ret_t sys_tgkill (struct registers *regs)
 SYS_tgkill: send a signal to one thread.
syscall_ret_t sys_set_tls (struct registers *regs)
 SYS_set_tls: set the calling thread's thread pointer, which user code reaches its thread-local storage through (fs:0 on x86_64, gs:0 on i686).
syscall_ret_t sys_futex (struct registers *regs)
 SYS_futex: args: uaddr (an aligned 32-bit word), op, val, timeout.
syscall_ret_t sys_getdents (struct registers *regs)
 SYS_getdents: read directory entries.
syscall_ret_t sys_poll (struct registers *regs)
 SYS_poll: wait until one of a set of descriptors is ready.
syscall_ret_t sys_getuid (struct registers *regs)
syscall_ret_t sys_geteuid (struct registers *regs)
syscall_ret_t sys_getgid (struct registers *regs)
syscall_ret_t sys_getegid (struct registers *regs)
syscall_ret_t sys_setuid (struct registers *regs)
 SYS_setuid: args: EBX = uid.
syscall_ret_t sys_setgid (struct registers *regs)
 SYS_setgid: args: EBX = gid.
syscall_ret_t sys_seteuid (struct registers *regs)
syscall_ret_t sys_setegid (struct registers *regs)
syscall_ret_t sys_chmod (struct registers *regs)
 SYS_chmod: args: path, mode (07777 bits).
syscall_ret_t sys_fchmod (struct registers *regs)
 SYS_fchmod: args: EBX = fd, ECX = mode.
syscall_ret_t sys_chown (struct registers *regs)
 SYS_chown: args: path, uid, gid (-1 keeps one).
syscall_ret_t sys_fchmodat (struct registers *regs)
 SYS_fchmodat: args: dirfd, path, mode, flags (AT_SYMLINK_NOFOLLOW is refused: a link has no mode of its own, as on Linux).
syscall_ret_t sys_fchownat (struct registers *regs)
 SYS_fchownat: args: dirfd, path, uid, gid, flags (AT_SYMLINK_NOFOLLOW).
syscall_ret_t sys_fchown (struct registers *regs)
 SYS_fchown: args: fd, uid, gid.
syscall_ret_t sys_umask (struct registers *regs)
 SYS_umask: args: EBX = mask.
syscall_ret_t sys_clock_gettime (struct registers *regs)
 SYS_clock_gettime: read a clock.
syscall_ret_t sys_clock_settime (struct registers *regs)
 SYS_clock_settime: set the realtime clock (root only).
syscall_ret_t sys_nanosleep (struct registers *regs)
 SYS_nanosleep: sleep for a time span.
syscall_ret_t sys_times (struct registers *regs)
 SYS_times: the CPU time of the calling process and its reaped children.
syscall_ret_t sys_kill (struct registers *regs)
 SYS_kill: send a signal.
syscall_ret_t sys_sigaction (struct registers *regs)
 SYS_sigaction: read and change what a process does with a signal.
syscall_ret_t sys_sigprocmask (struct registers *regs)
 SYS_sigprocmask: read and change the blocked mask.
syscall_ret_t sys_sigreturn (struct registers *regs)
 SYS_sigreturn: return from a signal handler (called by the restorer).
syscall_ret_t sys_sigpending (struct registers *regs)
 SYS_sigpending: the signals that are pending and blocked.
syscall_ret_t sys_sigsuspend (struct registers *regs)
 SYS_sigsuspend: wait for a signal with a temporary mask.
syscall_ret_t sys_alarm (struct registers *regs)
 SYS_alarm: send SIGALRM after a number of seconds (0 cancels).
syscall_ret_t sys_exit (struct registers *regs)
 SYS_exit: terminate the current process.
syscall_ret_t sys_exec (struct registers *regs)
 SYS_exec: start an ELF binary as a child process (spawn, not execve).
syscall_ret_t sys_getpid (struct registers *regs)
 SYS_getpid: return the current process ID (the thread group's id).
syscall_ret_t sys_waitpid (struct registers *regs)
 SYS_waitpid: wait for a child process to exit and reap it.
syscall_ret_t sys_sbrk (struct registers *regs)
syscall_ret_t sys_mmap (struct registers *regs)
syscall_ret_t sys_munmap (struct registers *regs)
syscall_ret_t sys_mprotect (struct registers *regs)
syscall_ret_t sys_fork (struct registers *regs)
 SYS_fork: create a child process that is a copy of the caller.
syscall_ret_t sys_execve (struct registers *regs)
 SYS_execve: replace the calling process's program with a new one.
syscall_ret_t sys_getppid (struct registers *regs)
 SYS_getppid: return the parent's pid, or 0 if the parent has exited.
syscall_ret_t sys_sched_yield (struct registers *regs)
 SYS_sched_yield: let other ready processes run first.
syscall_ret_t sys_setpgid (struct registers *regs)
 SYS_setpgid: move a process into a process group.
syscall_ret_t sys_getpgid (struct registers *regs)
 SYS_getpgid: the process group of a process (pid 0: the caller).
syscall_ret_t sys_setsid (struct registers *regs)
 SYS_setsid: start a new session, with the caller as the leader of it and of a new process group, and no controlling terminal.
syscall_ret_t sys_getpriority (struct registers *regs)
 SYS_getpriority: the nice value of processes.
syscall_ret_t sys_setpriority (struct registers *regs)
 SYS_setpriority: set the nice value (-20 to 19) of processes; it sets the length of their time slice.
syscall_ret_t sys_getsid (struct registers *regs)
 SYS_getsid: the session of a process (pid 0: the caller).
syscall_ret_t sys_fcntl (struct registers *regs)
 SYS_fcntl: control an open file descriptor.
syscall_ret_t sys_fstat (struct registers *regs)
 SYS_fstat: get the metadata of an open file.
syscall_ret_t sys_rename (struct registers *regs)
 SYS_rename: rename a file or directory.
syscall_ret_t sys_access (struct registers *regs)
 SYS_access: check that a file exists and may be accessed.
syscall_ret_t sys_pread (struct registers *regs)
 SYS_pread: read at an offset without moving the file offset.
syscall_ret_t sys_pwrite (struct registers *regs)
 SYS_pwrite: write at an offset without moving the file offset.
syscall_ret_t sys_fsync (struct registers *regs)
 SYS_fsync: write an open file's data to disk.
syscall_ret_t sys_reboot (struct registers *regs)
 SYS_reboot: restart (RB_AUTOBOOT) or turn off (RB_POWER_OFF) the machine.
syscall_ret_t sys_uname (struct registers *regs)
 SYS_uname: the name of the system, its release and version, and the machine.
syscall_ret_t sys_sethostname (struct registers *regs)
 SYS_sethostname: set the host name (root only).
syscall_ret_t sys_shm_create (struct registers *regs)
 SYS_shm_create: make a shared memory object (kernel/memory/shm.h).
syscall_ret_t sys_getcwd (struct registers *regs)
 SYS_getcwd: copy the current working directory into a user buffer.
syscall_ret_t sys_chdir (struct registers *regs)
 SYS_chdir: change the current working directory.
syscall_ret_t sys_ioctl (struct registers *regs)
 SYS_ioctl: issue a device-control request on an open file descriptor.
syscall_ret_t sys_socket (struct registers *regs)
 SYS_socket: make an unconnected socket.
syscall_ret_t sys_bind (struct registers *regs)
 SYS_bind: give a socket a name.
syscall_ret_t sys_listen (struct registers *regs)
 SYS_listen: let a bound socket take connections.
syscall_ret_t sys_accept (struct registers *regs)
 SYS_accept: take the next connection of a listening socket (accept4).
syscall_ret_t sys_connect (struct registers *regs)
 SYS_connect: connect to the listening socket with a name.
syscall_ret_t sys_socketpair (struct registers *regs)
 SYS_socketpair: make two connected sockets.
syscall_ret_t sys_sendmsg (struct registers *regs)
 SYS_sendmsg: send data, and pass open files with SCM_RIGHTS.
syscall_ret_t sys_getsockname (struct registers *regs)
 SYS_getsockname: the local address of a socket.
syscall_ret_t sys_getpeername (struct registers *regs)
 SYS_getpeername: the address a socket is connected to.
syscall_ret_t sys_setsockopt (struct registers *regs)
 SYS_setsockopt: set a socket option (an int value).
syscall_ret_t sys_getsockopt (struct registers *regs)
 SYS_getsockopt: read a socket option (an int value).
syscall_ret_t sys_shutdown (struct registers *regs)
 SYS_shutdown: stop the reading or the writing on a socket.
syscall_ret_t sys_getrandom (struct registers *regs)
 SYS_getrandom: random bytes.
syscall_ret_t sys_recvmsg (struct registers *regs)
 SYS_recvmsg: receive data, and the files passed with it.
syscall_ret_t sys_pollkey (struct registers *regs)
 SYS_pollkey: non-blocking keyboard poll for interactive graphics programs.

Macro Definition Documentation

◆ AT_FDCWD

#define AT_FDCWD   (-100)

◆ AT_SYMLINK_NOFOLLOW

#define AT_SYMLINK_NOFOLLOW   0x100

◆ AT_REMOVEDIR

#define AT_REMOVEDIR   0x200

◆ AT_SYMLINK_FOLLOW

#define AT_SYMLINK_FOLLOW   0x400

◆ AT_EACCESS

#define AT_EACCESS   0x200

Typedef Documentation

◆ syscall_arg_t

one syscall argument or return value: pointer-width, so a user address passes through unchanged.

handlers cast arguments to what they mean.

◆ syscall_ret_t

syscall function pointer type.

a handler reads its arguments with syscall_arg and returns its result; the dispatcher puts the result in REG_RESULT (EAX or RAX).

◆ syscall_fn_t

typedef syscall_ret_t(*) syscall_fn_t(struct registers *regs)

Function Documentation

◆ resolve_user_path()

int32_t resolve_user_path ( const char * user_path,
char * resolved,
uint32_t size )

copy a path string in from user memory and resolve it against the current process's cwd.

Parameters
user_paththe user's path pointer.
resolvedreceives the absolute path.
sizesize of resolved.
Returns
0, or a negative errno (EFAULT for a bad pointer, EINVAL for a path too long or unresolvable).

◆ resolve_user_path_at()

int32_t resolve_user_path_at ( int32_t dirfd,
const char * user_path,
char * resolved,
uint32_t size,
bool follow )

as resolve_user_path, with a relative path taken in the directory open as dirfd (AT_FDCWD: the working directory).

the symbolic links along the path are replaced by their targets.

Parameters
followalso the last name, when it is a link (stat, open); not for the calls that act on the name itself (unlink, rename, lstat).
Returns
0, or -EFAULT, -ENAMETOOLONG, -ENOENT (an empty path), -EBADF, -ENOTDIR (dirfd is no directory), or -ELOOP.

◆ set_new_owner()

int32_t set_new_owner ( const char * path,
uint32_t mode )

give a file the caller has just created its mode (taken through the umask) and the caller's effective user and group as owner.

Parameters
paththe new file's absolute path.
modethe permission bits asked for.
Returns
0, or a negative errno.

◆ sys_write()

syscall_ret_t sys_write ( struct registers * regs)

SYS_write: write bytes to a file descriptor.

args: EBX = fd, ECX = buffer pointer, EDX = count. returns number of bytes written, or negative errno on error.

◆ sys_read()

syscall_ret_t sys_read ( struct registers * regs)

SYS_read: read bytes from a file descriptor.

args: EBX = fd, ECX = buffer pointer, EDX = count. returns number of bytes read (0 at end of file), or negative errno.

◆ sys_open()

syscall_ret_t sys_open ( struct registers * regs)

◆ sys_flock()

syscall_ret_t sys_flock ( struct registers * regs)

SYS_flock: an advisory lock on a whole file (kernel/vfs/flock.h).

args: fd, operation (LOCK_SH or LOCK_EX, with LOCK_NB; or LOCK_UN). returns 0, or a negative errno (EWOULDBLOCK, EINTR, EBADF, EINVAL).

◆ sys_openat()

syscall_ret_t sys_openat ( struct registers * regs)

SYS_openat: open relative to a directory.

args: dirfd (AT_FDCWD: the working directory), path, flags, mode.

◆ sys_close()

syscall_ret_t sys_close ( struct registers * regs)

SYS_close: close an open file descriptor.

args: EBX = fd. returns 0 on success, negative errno on failure.

◆ sys_lseek()

syscall_ret_t sys_lseek ( struct registers * regs)

SYS_lseek: set the file offset.

args: fd, offset (low, high: syscall_arg_offset), whence (0=SET, 1=CUR, 2=END), and a pointer to an int64_t that receives the new offset (on i686 the return value is too small for it). returns 0, or negative errno (ESPIPE for a pipe or the console, EINVAL for a bad whence or a negative result).

◆ sys_ftruncate()

syscall_ret_t sys_ftruncate ( struct registers * regs)

SYS_ftruncate: cut or grow an open file to a length.

args: fd, length (low, high: syscall_arg_offset; the new bytes read as zeros). the offset stays. returns 0, or a negative errno (EINVAL: a negative length, or a file not open for writing; EFBIG: longer than the filesystem allows).

◆ sys_dup2()

syscall_ret_t sys_dup2 ( struct registers * regs)

SYS_dup2: make new_fd another descriptor for old_fd's open file.

args: EBX = old_fd, ECX = new_fd. if new_fd is already open, it is closed first. the new descriptor does not have FD_CLOEXEC. returns new_fd on success, negative errno on failure.

◆ sys_pipe()

syscall_ret_t sys_pipe ( struct registers * regs)

SYS_pipe: create a pipe (pair of connected file descriptors).

args: EBX = pointer to int[2] array (receives [read_fd, write_fd]). returns 0 on success, negative errno on failure.

◆ sys_stat()

syscall_ret_t sys_stat ( struct registers * regs)

SYS_stat: get file metadata.

args: path, struct stat pointer (kernel/vfs/stat.h). returns 0 on success, negative errno on failure.

◆ sys_mkdir()

syscall_ret_t sys_mkdir ( struct registers * regs)

SYS_mkdir: create a directory.

args: path, mode. returns 0 on success, negative errno on failure.

◆ sys_unlink()

syscall_ret_t sys_unlink ( struct registers * regs)

SYS_unlink: remove a file.

args: path. returns 0 on success, negative errno on failure.

◆ sys_rmdir()

syscall_ret_t sys_rmdir ( struct registers * regs)

SYS_rmdir: remove a directory.

args: path. returns 0 on success, negative errno on failure.

◆ sys_fstatat()

syscall_ret_t sys_fstatat ( struct registers * regs)

SYS_fstatat: stat a path relative to a directory.

args: dirfd, path, struct stat pointer, flags (AT_SYMLINK_NOFOLLOW).

◆ sys_renameat()

syscall_ret_t sys_renameat ( struct registers * regs)

SYS_renameat: rename, each path relative to its own directory.

args: old dirfd, old path, new dirfd, new path.

◆ sys_faccessat()

syscall_ret_t sys_faccessat ( struct registers * regs)

SYS_faccessat: access, relative to a directory.

args: dirfd, path, mode, flags (AT_EACCESS).

◆ sys_mkdirat()

syscall_ret_t sys_mkdirat ( struct registers * regs)

SYS_mkdirat: mkdir relative to a directory.

args: dirfd, path, mode.

◆ sys_unlinkat()

syscall_ret_t sys_unlinkat ( struct registers * regs)

SYS_unlinkat: remove a file or (AT_REMOVEDIR) a directory, relative to a directory.

args: dirfd, path, flags.

◆ sys_symlinkat()

syscall_ret_t sys_symlinkat ( struct registers * regs)

SYS_symlinkat: make a symbolic link.

args: target (the path the link points at; it need not exist), dirfd, path of the new link. the link belongs to the caller's effective user and group. returns 0, or a negative errno (EEXIST, ENOENT, EACCES, ENAMETOOLONG).

◆ sys_readlinkat()

syscall_ret_t sys_readlinkat ( struct registers * regs)

SYS_readlinkat: read the target of a symbolic link.

args: dirfd, path, buffer, buffer size. returns the bytes put in the buffer (no NUL; a longer target is cut), or a negative errno (EINVAL: not a link).

◆ sys_linkat()

syscall_ret_t sys_linkat ( struct registers * regs)

SYS_linkat: give a file one more name (a hard link).

args: old dirfd, old path, new dirfd, new path, flags (AT_SYMLINK_FOLLOW: link to what a symbolic link points at, not the link itself). returns 0, or a negative errno (EXDEV across mounts, EPERM for a directory, EEXIST, EMLINK).

◆ sys_utimensat()

syscall_ret_t sys_utimensat ( struct registers * regs)

SYS_utimensat: set a file's access and modification times.

args: dirfd, path (NULL: the file open as dirfd, which is futimens), times (two timespecs, access then modification; NULL: both now), flags (AT_SYMLINK_NOFOLLOW). a tv_nsec of UTIME_NOW takes the time now; UTIME_OMIT keeps the time. returns 0, or a negative errno (EPERM, EACCES, EINVAL, ENOENT, EBADF).

◆ sys_mknodat()

syscall_ret_t sys_mknodat ( struct registers * regs)

SYS_mknodat: make a named pipe, a device node or an empty file.

args: dirfd, path, mode (S_IFIFO, S_IFCHR, S_IFBLK or S_IFREG, with the permission bits, taken through the umask), the device number. a device node needs root. it opens with ENXIO: the devices are in /dev. returns 0, or a negative errno (EEXIST, EPERM, EINVAL, EACCES).

◆ sys_chroot()

syscall_ret_t sys_chroot ( struct registers * regs)

SYS_chroot: make a directory the caller's root: its paths start there, and ".." stops there (root only).

the working directory stays; a tool then changes it to "/". args: path. returns 0, or a negative errno (EPERM, ENOTDIR, ENOENT, EACCES).

◆ sys_clone()

syscall_ret_t sys_clone ( struct registers * regs)

SYS_clone: make a thread of the current process.

args: flags, the new thread's user stack pointer, parent_tid, child_tid, tls. only a thread can be made: flags must have CLONE_VM, FS, FILES, SIGHAND and THREAD (fork makes a process). SETTLS gives the thread tls as its thread pointer (else it has the caller's). PARENT_SETTID and CHILD_SETTID write the new thread's id to parent_tid and child_tid; CHILD_CLEARTID makes the kernel write 0 there when the thread ends. SYSVSEM is accepted and has no effect. returns the new thread's id in the caller and 0 in the thread; -EINVAL for other flags or no stack, -EFAULT for a bad tid address, -EAGAIN if the process table or the memory ran out.

◆ sys_exit_group()

syscall_ret_t sys_exit_group ( struct registers * regs)

SYS_exit_group: end every thread of the current process.

arg: the exit code. never returns.

◆ sys_gettid()

syscall_ret_t sys_gettid ( struct registers * regs)

SYS_gettid: the calling thread's id (the pid for a single thread).

◆ sys_tgkill()

syscall_ret_t sys_tgkill ( struct registers * regs)

SYS_tgkill: send a signal to one thread.

args: the thread group (pid), the thread's id, the signal (0 only checks that the thread exists). SIGCONT continues the whole process, as for kill. returns 0, or -ESRCH, -EINVAL.

◆ sys_set_tls()

syscall_ret_t sys_set_tls ( struct registers * regs)

SYS_set_tls: set the calling thread's thread pointer, which user code reaches its thread-local storage through (fs:0 on x86_64, gs:0 on i686).

arg: the address. returns 0.

◆ sys_futex()

syscall_ret_t sys_futex ( struct registers * regs)

SYS_futex: args: uaddr (an aligned 32-bit word), op, val, timeout.

FUTEX_WAIT sleeps while *uaddr == val, for at most *timeout (a relative struct timespec; NULL: no limit). FUTEX_WAKE wakes at most val threads and returns how many it woke. FUTEX_PRIVATE_FLAG may be set: every futex is private to its process here. returns as above, -EINVAL (a bad address or time), -ENOSYS (another op).

◆ sys_getdents()

syscall_ret_t sys_getdents ( struct registers * regs)

SYS_getdents: read directory entries.

args: EBX = fd of an open directory, ECX = buffer, EDX = buffer size. fills the buffer with as many whole records (kernel/vfs/dirent.h) as fit. returns the bytes written, 0 at the end of the directory, or a negative errno (EINVAL if the buffer cannot hold the next record, ENOTDIR if fd is not a directory).

◆ sys_poll()

syscall_ret_t sys_poll ( struct registers * regs)

SYS_poll: wait until one of a set of descriptors is ready.

args: EBX = struct pollfd array, ECX = count (at most 64), EDX = timeout in milliseconds (negative: no limit, 0: do not wait). returns the number of descriptors with events, 0 on timeout, or a negative errno.

◆ sys_getuid()

syscall_ret_t sys_getuid ( struct registers * regs)

◆ sys_geteuid()

syscall_ret_t sys_geteuid ( struct registers * regs)

◆ sys_getgid()

syscall_ret_t sys_getgid ( struct registers * regs)

◆ sys_getegid()

syscall_ret_t sys_getegid ( struct registers * regs)

◆ sys_setuid()

syscall_ret_t sys_setuid ( struct registers * regs)

SYS_setuid: args: EBX = uid.

returns 0 or -EPERM.

◆ sys_setgid()

syscall_ret_t sys_setgid ( struct registers * regs)

SYS_setgid: args: EBX = gid.

returns 0 or -EPERM. root's check is on the effective user id, so set the group before giving up root.

◆ sys_seteuid()

syscall_ret_t sys_seteuid ( struct registers * regs)

◆ sys_setegid()

syscall_ret_t sys_setegid ( struct registers * regs)

◆ sys_chmod()

syscall_ret_t sys_chmod ( struct registers * regs)

SYS_chmod: args: path, mode (07777 bits).

only the owner or root. returns 0 or a negative errno.

◆ sys_fchmod()

syscall_ret_t sys_fchmod ( struct registers * regs)

SYS_fchmod: args: EBX = fd, ECX = mode.

like chmod, on an open file.

◆ sys_chown()

syscall_ret_t sys_chown ( struct registers * regs)

SYS_chown: args: path, uid, gid (-1 keeps one).

returns 0 or a negative errno (see owner_change).

◆ sys_fchmodat()

syscall_ret_t sys_fchmodat ( struct registers * regs)

SYS_fchmodat: args: dirfd, path, mode, flags (AT_SYMLINK_NOFOLLOW is refused: a link has no mode of its own, as on Linux).

◆ sys_fchownat()

syscall_ret_t sys_fchownat ( struct registers * regs)

SYS_fchownat: args: dirfd, path, uid, gid, flags (AT_SYMLINK_NOFOLLOW).

◆ sys_fchown()

syscall_ret_t sys_fchown ( struct registers * regs)

SYS_fchown: args: fd, uid, gid.

like chown, on an open file.

◆ sys_umask()

syscall_ret_t sys_umask ( struct registers * regs)

SYS_umask: args: EBX = mask.

returns the old mask.

◆ sys_clock_gettime()

syscall_ret_t sys_clock_gettime ( struct registers * regs)

SYS_clock_gettime: read a clock.

args: EBX = clock id (CLOCK_*), ECX = struct timespec * out. returns 0, or -EINVAL for an unknown clock, -EFAULT.

◆ sys_clock_settime()

syscall_ret_t sys_clock_settime ( struct registers * regs)

SYS_clock_settime: set the realtime clock (root only).

args: clock id (CLOCK_REALTIME only), struct timespec *. the clock keeps whole seconds; the battery-backed clock (RTC) is not written, so the next boot reads its old time again. returns 0, or -EPERM, -EINVAL (another clock, a bad time), -EFAULT.

◆ sys_nanosleep()

syscall_ret_t sys_nanosleep ( struct registers * regs)

SYS_nanosleep: sleep for a time span.

args: EBX = const struct timespec * span, ECX = struct timespec * left (may be NULL). the sleep ends at the first timer tick after the span (10 ms steps). a signal ends it early: -EINTR, with the time left in *left. returns 0, or -EINTR, -EINVAL (a negative span or nanoseconds out of range), -EFAULT.

◆ sys_times()

syscall_ret_t sys_times ( struct registers * regs)

SYS_times: the CPU time of the calling process and its reaped children.

args: EBX = struct tms * out (may be NULL). returns the ticks since boot (clock_t, TIMER_HZ per second).

◆ sys_kill()

syscall_ret_t sys_kill ( struct registers * regs)

SYS_kill: send a signal.

args: EBX = pid: a process (> 0), the caller's process group (0), every process but init (-1), or the process group -pid (< -1); ECX = signal (0 only checks that the target exists). returns 0, or -ESRCH, -EINVAL.

◆ sys_sigaction()

syscall_ret_t sys_sigaction ( struct registers * regs)

SYS_sigaction: read and change what a process does with a signal.

args: EBX = signal, ECX = new action (ksigaction_t, may be NULL), EDX = old action out (may be NULL). SIGKILL and SIGSTOP cannot be changed. returns 0 or a negative errno.

◆ sys_sigprocmask()

syscall_ret_t sys_sigprocmask ( struct registers * regs)

SYS_sigprocmask: read and change the blocked mask.

args: EBX = how (SIG_BLOCK, SIG_UNBLOCK, SIG_SETMASK), ECX = set (uint32_t *, may be NULL), EDX = old set out (may be NULL). returns 0 or a negative errno.

◆ sys_sigreturn()

syscall_ret_t sys_sigreturn ( struct registers * regs)

SYS_sigreturn: return from a signal handler (called by the restorer).

restores the registers and mask saved in the handler's frame; the result is the interrupted code's EAX.

◆ sys_sigpending()

syscall_ret_t sys_sigpending ( struct registers * regs)

SYS_sigpending: the signals that are pending and blocked.

args: EBX = uint32_t * out.

◆ sys_sigsuspend()

syscall_ret_t sys_sigsuspend ( struct registers * regs)

SYS_sigsuspend: wait for a signal with a temporary mask.

args: EBX = uint32_t * mask. the mask is in place until a signal comes; after its handler (or its default action) the old mask is back. always returns -EINTR.

◆ sys_alarm()

syscall_ret_t sys_alarm ( struct registers * regs)

SYS_alarm: send SIGALRM after a number of seconds (0 cancels).

returns the seconds that were left of the previous alarm (rounded up).

◆ sys_exit()

syscall_ret_t sys_exit ( struct registers * regs)

SYS_exit: terminate the current process.

arg: EBX = exit code. never returns: the process becomes a zombie until its parent reaps it.

◆ sys_exec()

syscall_ret_t sys_exec ( struct registers * regs)

SYS_exec: start an ELF binary as a child process (spawn, not execve).

args: EBX = path string pointer, ECX = argv array pointer (may be NULL). returns the child's PID, or negative errno on failure.

◆ sys_getpid()

syscall_ret_t sys_getpid ( struct registers * regs)

SYS_getpid: return the current process ID (the thread group's id).

◆ sys_waitpid()

syscall_ret_t sys_waitpid ( struct registers * regs)

SYS_waitpid: wait for a child process to exit and reap it.

args: EBX = pid (a child's pid, or -1 for any child), ECX = int *status (may be NULL; receives the wait status, wait_status.h), EDX = options (WNOHANG). with WUNTRACED a stopped child and with WCONTINUED a continued one is reported (once) too, without reaping it. returns the child's pid; 0 with WNOHANG when no matching child has anything to report yet; -ECHILD if there is no matching child; -EINVAL for a pid of 0 or below -1 (process groups come later); -EFAULT for a bad status pointer (the child is reaped anyway).

◆ sys_sbrk()

syscall_ret_t sys_sbrk ( struct registers * regs)

◆ sys_mmap()

syscall_ret_t sys_mmap ( struct registers * regs)

◆ sys_munmap()

syscall_ret_t sys_munmap ( struct registers * regs)

◆ sys_mprotect()

syscall_ret_t sys_mprotect ( struct registers * regs)

◆ sys_fork()

syscall_ret_t sys_fork ( struct registers * regs)

SYS_fork: create a child process that is a copy of the caller.

returns the child's PID in the parent and 0 in the child, or a negative errno.

no arguments. returns the child's PID in the parent, 0 in the child (set up by process_fork), or -ENOMEM.

◆ sys_execve()

syscall_ret_t sys_execve ( struct registers * regs)

SYS_execve: replace the calling process's program with a new one.

SYS_execve: replace the calling process's program.

SYS_execve: replace the calling process's program with a new one.

args: EBX = path, ECX = argv, EDX = envp (both NULL-terminated, may be NULL). on success it does not return: the syscall frame now enters the new program (exec_replace). returns a negative errno on failure, with the old program still running.

◆ sys_getppid()

syscall_ret_t sys_getppid ( struct registers * regs)

SYS_getppid: return the parent's pid, or 0 if the parent has exited.

◆ sys_sched_yield()

syscall_ret_t sys_sched_yield ( struct registers * regs)

SYS_sched_yield: let other ready processes run first.

returns 0.

◆ sys_setpgid()

syscall_ret_t sys_setpgid ( struct registers * regs)

SYS_setpgid: move a process into a process group.

args: EBX = pid (0: the caller; else the caller or one of its children), ECX = pgid (0: the target's own pid, a new group). the group must be new or exist in the caller's session. returns 0, or -ESRCH, -EPERM, -EINVAL.

◆ sys_getpgid()

syscall_ret_t sys_getpgid ( struct registers * regs)

SYS_getpgid: the process group of a process (pid 0: the caller).

◆ sys_setsid()

syscall_ret_t sys_setsid ( struct registers * regs)

SYS_setsid: start a new session, with the caller as the leader of it and of a new process group, and no controlling terminal.

returns the new session id, or -EPERM if the caller leads a group.

◆ sys_getpriority()

syscall_ret_t sys_getpriority ( struct registers * regs)

SYS_getpriority: the nice value of processes.

args: which (PRIO_PROCESS, PRIO_PGRP, PRIO_USER), who (0: the caller's). returns 20 - nice of the one with the most CPU (1 to 40, never negative), or a negative errno (ESRCH: none, EINVAL).

◆ sys_setpriority()

syscall_ret_t sys_setpriority ( struct registers * regs)

SYS_setpriority: set the nice value (-20 to 19) of processes; it sets the length of their time slice.

only root may lower it. args: which, who (as getpriority), the nice value. returns 0, or a negative errno (ESRCH, EPERM, EACCES, EINVAL).

◆ sys_getsid()

syscall_ret_t sys_getsid ( struct registers * regs)

SYS_getsid: the session of a process (pid 0: the caller).

◆ sys_fcntl()

syscall_ret_t sys_fcntl ( struct registers * regs)

SYS_fcntl: control an open file descriptor.

args: EBX = fd, ECX = command, EDX = argument. F_DUPFD / F_DUPFD_CLOEXEC: duplicate to the lowest free fd >= argument F_GETFD / F_SETFD: the descriptor flags (FD_CLOEXEC) F_GETFL / F_SETFL: the description's status flags; only O_APPEND and O_NONBLOCK can be changed returns the command's result, or a negative errno.

◆ sys_fstat()

syscall_ret_t sys_fstat ( struct registers * regs)

SYS_fstat: get the metadata of an open file.

args: EBX = fd, ECX = struct stat pointer. returns 0 on success, negative errno on failure.

◆ sys_rename()

syscall_ret_t sys_rename ( struct registers * regs)

SYS_rename: rename a file or directory.

args: old path, new path (same filesystem). returns 0 on success, negative errno on failure (EXDEV across mounts).

◆ sys_access()

syscall_ret_t sys_access ( struct registers * regs)

SYS_access: check that a file exists and may be accessed.

args: path, mode (F_OK, or R_OK | W_OK | X_OK). returns 0, or a negative errno (ENOENT, EACCES).

◆ sys_pread()

syscall_ret_t sys_pread ( struct registers * regs)

SYS_pread: read at an offset without moving the file offset.

args: fd, buffer, count, offset (low, high: syscall_arg_offset). returns bytes read, or negative errno (ESPIPE for a pipe or the console).

◆ sys_pwrite()

syscall_ret_t sys_pwrite ( struct registers * regs)

SYS_pwrite: write at an offset without moving the file offset.

args: fd, buffer, count, offset (low, high: syscall_arg_offset). returns bytes written, or negative errno (EINVAL with O_APPEND).

◆ sys_fsync()

syscall_ret_t sys_fsync ( struct registers * regs)

SYS_fsync: write an open file's data to disk.

args: EBX = fd. ext2 writes through to the disk at once (there is no cache), so this only checks the descriptor. returns 0 or -EBADF.

◆ sys_reboot()

syscall_ret_t sys_reboot ( struct registers * regs)

SYS_reboot: restart (RB_AUTOBOOT) or turn off (RB_POWER_OFF) the machine.

only root (effective user 0) may. the disk writes are already done: the block cache writes through. returns -EPERM for other users and -EINVAL for another value; it does not return for root.

◆ sys_uname()

syscall_ret_t sys_uname ( struct registers * regs)

SYS_uname: the name of the system, its release and version, and the machine.

args: the user's struct utsname. returns 0, or a negative errno.

◆ sys_sethostname()

syscall_ret_t sys_sethostname ( struct registers * regs)

SYS_sethostname: set the host name (root only).

args: the name, its length (at most 64 bytes, no NUL needed). returns 0, or -EPERM, -EINVAL (too long), -EFAULT.

◆ sys_shm_create()

syscall_ret_t sys_shm_create ( struct registers * regs)

SYS_shm_create: make a shared memory object (kernel/memory/shm.h).

args: EBX = size in bytes (rounded up to pages), ECX = fd flags (FD_CLOEXEC). returns the new fd (open read-write; map it with mmap), or -EINVAL, -ENOMEM, -EMFILE.

◆ sys_getcwd()

syscall_ret_t sys_getcwd ( struct registers * regs)

SYS_getcwd: copy the current working directory into a user buffer.

args: EBX = buffer pointer, ECX = buffer size. returns 0 on success, negative errno on failure.

◆ sys_chdir()

syscall_ret_t sys_chdir ( struct registers * regs)

SYS_chdir: change the current working directory.

args: EBX = path string pointer. returns 0 on success, negative errno on failure.

◆ sys_ioctl()

syscall_ret_t sys_ioctl ( struct registers * regs)

SYS_ioctl: issue a device-control request on an open file descriptor.

args: EBX = fd, ECX = request code, EDX = argument (usually a user pointer). only file-backed fds carry a filesystem that can service ioctls; devfs device nodes forward to the backing device. everything else is -ENOTTY. returns 0 (or a request-specific value) on success, negative errno on error.

note: the arg pointer is request-specific, so its size is only known to the device handler; this layer passes it through and the handler validates it.

◆ sys_socket()

syscall_ret_t sys_socket ( struct registers * regs)

SYS_socket: make an unconnected socket.

args: domain (AF_UNIX or AF_INET), type (SOCK_STREAM; for AF_INET also SOCK_DGRAM; with SOCK_NONBLOCK and SOCK_CLOEXEC), protocol (0; for AF_INET also IPPROTO_TCP, IPPROTO_UDP or IPPROTO_ICMP). returns the new fd, or -EAFNOSUPPORT, -EPROTONOSUPPORT, -ENOMEM, -EMFILE.

◆ sys_bind()

syscall_ret_t sys_bind ( struct registers * regs)

SYS_bind: give a socket a name.

args: fd, const struct sockaddr_un *, addrlen. returns 0, or -EBADF, -ENOTSOCK, -EINVAL, -EADDRINUSE, -EFAULT.

◆ sys_listen()

syscall_ret_t sys_listen ( struct registers * regs)

SYS_listen: let a bound socket take connections.

args: fd, backlog (AF_UNIX: 0 or more than 16 means 16; AF_INET: at most TCP_BACKLOG_MAX). returns 0, or -EBADF, -ENOTSOCK, -EINVAL, -EOPNOTSUPP (a datagram socket).

◆ sys_accept()

syscall_ret_t sys_accept ( struct registers * regs)

SYS_accept: take the next connection of a listening socket (accept4).

args: fd, struct sockaddr * (or NULL), socklen_t *addrlen (or NULL), flags (SOCK_NONBLOCK, SOCK_CLOEXEC). AF_INET: the peer's sockaddr_in. AF_UNIX: the peer has no name, so only sun_family is filled in and *addrlen becomes 2. returns the new fd, or -EAGAIN, -EINVAL, -EBADF, -ENOTSOCK, -EFAULT, -EMFILE, -ENOMEM.

◆ sys_connect()

syscall_ret_t sys_connect ( struct registers * regs)

SYS_connect: connect to the listening socket with a name.

args: fd, const struct sockaddr_un *, addrlen. returns 0, or -ECONNREFUSED (no one listens there, or the backlog is full), -EISCONN, -EBADF, -ENOTSOCK, -EINVAL, -EFAULT.

◆ sys_socketpair()

syscall_ret_t sys_socketpair ( struct registers * regs)

SYS_socketpair: make two connected sockets.

args: domain, type, protocol (as for socket), int sv[2]. returns 0, or a negative errno.

◆ sys_sendmsg()

syscall_ret_t sys_sendmsg ( struct registers * regs)

SYS_sendmsg: send data, and pass open files with SCM_RIGHTS.

args: fd, const struct msghdr *, flags (MSG_DONTWAIT, MSG_NOSIGNAL). the files go with the first byte sent, so a message that passes files must have some data. msg_name is ignored (the socket is connected). returns the bytes sent, or -EPIPE (and SIGPIPE, unless MSG_NOSIGNAL), -EAGAIN, -ENOTCONN, -EBADF, -ENOTSOCK, -EINVAL, -EFAULT, -ENOMEM.

◆ sys_getsockname()

syscall_ret_t sys_getsockname ( struct registers * regs)

SYS_getsockname: the local address of a socket.

args: fd, struct sockaddr *, socklen_t *addrlen. returns 0, or -EBADF, -ENOTSOCK, -EFAULT.

◆ sys_getpeername()

syscall_ret_t sys_getpeername ( struct registers * regs)

SYS_getpeername: the address a socket is connected to.

args: fd, struct sockaddr *, socklen_t *addrlen. returns 0, or -ENOTCONN, -EBADF, -ENOTSOCK, -EFAULT.

◆ sys_setsockopt()

syscall_ret_t sys_setsockopt ( struct registers * regs)

SYS_setsockopt: set a socket option (an int value).

args: fd, level, name, const void *value, socklen_t length. a Unix socket takes the SOL_SOCKET options and keeps none of them. returns 0, or -ENOPROTOOPT, -EINVAL, -EBADF, -ENOTSOCK, -EFAULT.

◆ sys_getsockopt()

syscall_ret_t sys_getsockopt ( struct registers * regs)

SYS_getsockopt: read a socket option (an int value).

args: fd, level, name, void *value, socklen_t *length. returns 0, or -ENOPROTOOPT, -EINVAL, -EBADF, -ENOTSOCK, -EFAULT.

◆ sys_shutdown()

syscall_ret_t sys_shutdown ( struct registers * regs)

SYS_shutdown: stop the reading or the writing on a socket.

args: fd, how (SHUT_RD, SHUT_WR, SHUT_RDWR). returns 0, or -EINVAL, -EOPNOTSUPP (a Unix socket), -EBADF, -ENOTSOCK.

◆ sys_getrandom()

syscall_ret_t sys_getrandom ( struct registers * regs)

SYS_getrandom: random bytes.

args: buf, length, flags (GRND_NONBLOCK, GRND_RANDOM, GRND_INSECURE). waits until the generator is seeded, unless GRND_NONBLOCK or GRND_INSECURE. returns the bytes given, or -EAGAIN, -EINVAL, -EFAULT, -EINTR.

◆ sys_recvmsg()

syscall_ret_t sys_recvmsg ( struct registers * regs)

SYS_recvmsg: receive data, and the files passed with it.

args: fd, struct msghdr *, flags (MSG_DONTWAIT, MSG_CMSG_CLOEXEC). the files come as one SCM_RIGHTS control message. files that do not fit in msg_control (or in the fd table) are closed, and msg_flags gets MSG_CTRUNC. msg_namelen becomes 0 (the peer has no name). returns the bytes received (0 at the end of the stream), or -EAGAIN, -ENOTCONN, -EBADF, -ENOTSOCK, -EINVAL, -EFAULT.

◆ sys_pollkey()

syscall_ret_t sys_pollkey ( struct registers * regs)

SYS_pollkey: non-blocking keyboard poll for interactive graphics programs.

returns the next pending character-key (a "kbhit"-style peek+consume), or 0 if no key is waiting. special keys (arrows etc.) are consumed and reported as 0 so they don't stall the caller. takes no arguments.