AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
syscall.c File Reference

System calls: what the architecture calls when user mode makes one (syscall_dispatch()), the table of them, and the helpers that several kinds of calls share, for the user memory and descriptors they take. More...

#include "syscalls.h"

Go to the source code of this file.

Macros

#define SYSCALL_ARGS   uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, uintptr_t a5
#define SYSCALL0(name)
#define SYSCALL1(name, t1)
#define SYSCALL2(name, t1, t2)
#define SYSCALL3(name, t1, t2, t3)
#define SYSCALL4(name, t1, t2, t3, t4)
#define SYSCALL5(name, t1, t2, t3, t4, t5)

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.
void syscall_dispatch (unsigned long nr, uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, uintptr_t a5)
 Runs a system call that the current thread made from user mode.

Variables

static int syscall_log_level = LOG_NONE
const syscall_t syscall_table []
const size_t syscall_cnt = sizeof(syscall_table)/sizeof(syscall_table[0])

Detailed Description

System calls: what the architecture calls when user mode makes one (syscall_dispatch()), the table of them, and the helpers that several kinds of calls share, for the user memory and descriptors they take.

The calls themselves are in sys_file.c, sys_proc.c, sys_signal.c, sys_net.c and sys_poll.c, and syscalls.h lists them all.

Definition in file syscall.c.

Macro Definition Documentation

◆ SYSCALL0

#define SYSCALL0 ( name)
Value:
static long sys_##name##_entry(SYSCALL_ARGS) \
{ return sys_##name(); }
#define SYSCALL_ARGS
Definition syscall.c:81

Definition at line 84 of file syscall.c.

◆ SYSCALL1

#define SYSCALL1 ( name,
t1 )
Value:
static long sys_##name##_entry(SYSCALL_ARGS) \
{ return sys_##name((t1) a1); }

Definition at line 87 of file syscall.c.

◆ SYSCALL2

#define SYSCALL2 ( name,
t1,
t2 )
Value:
static long sys_##name##_entry(SYSCALL_ARGS) \
{ return sys_##name((t1) a1, (t2) a2); }

Definition at line 90 of file syscall.c.

◆ SYSCALL3

#define SYSCALL3 ( name,
t1,
t2,
t3 )
Value:
static long sys_##name##_entry(SYSCALL_ARGS) \
{ return sys_##name((t1) a1, (t2) a2, (t3) a3); }

Definition at line 93 of file syscall.c.

◆ SYSCALL4

#define SYSCALL4 ( name,
t1,
t2,
t3,
t4 )
Value:
static long sys_##name##_entry(SYSCALL_ARGS) \
{ return sys_##name((t1) a1, (t2) a2, (t3) a3, (t4) a4); }

Definition at line 96 of file syscall.c.

◆ SYSCALL5

#define SYSCALL5 ( name,
t1,
t2,
t3,
t4,
t5 )
Value:
static long sys_##name##_entry(SYSCALL_ARGS) \
{ return sys_##name((t1) a1, (t2) a2, (t3) a3, (t4) a4, (t5) a5); }

Definition at line 99 of file syscall.c.

◆ SYSCALL_ARGS

#define SYSCALL_ARGS   uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, uintptr_t a5

Definition at line 81 of file syscall.c.

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

◆ syscall_dispatch()

void syscall_dispatch ( unsigned long nr,
uintptr_t a1,
uintptr_t a2,
uintptr_t a3,
uintptr_t a4,
uintptr_t a5 )

Runs a system call that the current thread made from user mode.

The architecture's arch_syscall() calls it with the number and the arguments, as they came in registers.

The call's result is set as the thread's result to return to user mode (arch_syscall_return()), except for sigreturn's: its registers are the ones it restored from the signal frame. A call that doesn't return (exit, or an execve that worked) doesn't come back here.

Parameters
nrthe system call's number (SYS_*)
a1its first argument
a2its second argument
a3its third argument
a4its fourth argument
a5its fifth argument

Definition at line 313 of file syscall.c.

References arch_syscall_return(), curproc, curthread, printk(), syscall_cnt, syscall_dispatch(), syscall_table, and thread_files_release().

Referenced by arch_syscall(), arch_syscall(), and syscall_dispatch().

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

Variable Documentation

◆ syscall_cnt

const size_t syscall_cnt = sizeof(syscall_table)/sizeof(syscall_table[0])

Definition at line 293 of file syscall.c.

Referenced by syscall_dispatch().

◆ syscall_log_level

int syscall_log_level = LOG_NONE
static

Definition at line 11 of file syscall.c.

◆ syscall_table

const syscall_t syscall_table[]

Definition at line 197 of file syscall.c.

Referenced by syscall_dispatch().