PatchworkOS
Loading...
Searching...
No Matches
syscalls.h File Reference
#include <kernel/cpu/syscalls.h>
#include <errno.h>
#include <stdarg.h>
#include <stdint.h>
#include <sys/io.h>
#include <sys/proc.h>
#include <time.h>

Go to the source code of this file.

Macros

#define _SYSCALL0(retType, num)
 
#define _SYSCALL1(retType, num, type1, arg1)
 
#define _SYSCALL2(retType, num, type1, arg1, type2, arg2)
 
#define _SYSCALL3(retType, num, type1, arg1, type2, arg2, type3, arg3)
 
#define _SYSCALL4(retType, num, type1, arg1, type2, arg2, type3, arg3, type4, arg4)
 
#define _SYSCALL5(retType, num, type1, arg1, type2, arg2, type3, arg3, type4, arg4, type5, arg5)
 
#define _SYSCALL6(retType, num, type1, arg1, type2, arg2, type3, arg3, type4, arg4, type5, arg5, type6, arg6)
 

Functions

static _NORETURN void _syscall_process_exit (uint64_t status)
 
static _NORETURN void _syscall_thread_exit (void)
 
static pid_t _syscall_spawn (const char **argv, const spawn_fd_t *fds, const char *cwd, spawn_attr_t *attr)
 
static uint64_t _syscall_nanosleep (clock_t nanoseconds)
 
static errno_t _syscall_errno (void)
 
static pid_t _syscall_getpid (void)
 
static tid_t _syscall_gettid (void)
 
static clock_t _syscall_uptime (void)
 
static time_t _syscall_unix_epoch (void)
 
static fd_t _syscall_open (const char *path)
 
static uint64_t _syscall_open2 (const char *path, fd_t fds[2])
 
static uint64_t _syscall_close (fd_t fd)
 
static uint64_t _syscall_read (fd_t fd, void *buffer, uint64_t count)
 
static uint64_t _syscall_write (fd_t fd, const void *buffer, uint64_t count)
 
static uint64_t _syscall_seek (fd_t fd, int64_t offset, seek_origin_t origin)
 
static uint64_t _syscall_ioctl (fd_t fd, uint64_t request, void *argp, uint64_t size)
 
static uint64_t _syscall_chdir (const char *path)
 
static uint64_t _syscall_poll (pollfd_t *fds, uint64_t amount, clock_t timeout)
 
static uint64_t _syscall_stat (const char *path, stat_t *info)
 
static void * _syscall_mmap (fd_t fd, void *address, uint64_t length, prot_t prot)
 
static uint64_t _syscall_munmap (void *address, uint64_t length)
 
static uint64_t _syscall_mprotect (void *address, uint64_t length, prot_t prot)
 
static uint64_t _syscall_getdents (fd_t fd, dirent_t *buffer, uint64_t count)
 
static tid_t _syscall_thread_create (void *entry, void *arg)
 
static void _syscall_yield (void)
 
static fd_t _syscall_dup (fd_t oldFd)
 
static fd_t _syscall_dup2 (fd_t oldFd, fd_t newFd)
 
static uint64_t _syscall_futex (atomic_uint64_t *addr, uint64_t val, futex_op_t op, clock_t timeout)
 
static uint64_t _syscall_remove (const char *path)
 
static uint64_t _syscall_link (const char *oldPath, const char *newPath)
 
static uint64_t _syscall_share (key_t *key, fd_t fd, clock_t timeout)
 
static fd_t _syscall_claim (key_t *key)
 
static uint64_t _syscall_bind (fd_t source, const char *mountpoint)
 

Macro Definition Documentation

◆ _SYSCALL0

#define _SYSCALL0 (   retType,
  num 
)
Value:
({ \
register retType ret asm("rax"); \
asm volatile("syscall\n" : "=a"(ret) : "a"(num) : "rcx", "r11", "memory"); \
ret; \
})

Definition at line 12 of file syscalls.h.

◆ _SYSCALL1

#define _SYSCALL1 (   retType,
  num,
  type1,
  arg1 
)
Value:
({ \
register retType ret asm("rax"); \
register type1 _a1 asm("rdi") = (arg1); \
asm volatile("syscall\n" : "=a"(ret) : "a"(num), "r"(_a1) : "rcx", "r11", "memory"); \
ret; \
})

Definition at line 19 of file syscalls.h.

◆ _SYSCALL2

#define _SYSCALL2 (   retType,
  num,
  type1,
  arg1,
  type2,
  arg2 
)
Value:
({ \
register retType ret asm("rax"); \
register type1 _a1 asm("rdi") = (arg1); \
register type2 _a2 asm("rsi") = (arg2); \
asm volatile("syscall\n" : "=a"(ret) : "a"(num), "r"(_a1), "r"(_a2) : "rcx", "r11", "memory"); \
ret; \
})

Definition at line 27 of file syscalls.h.

◆ _SYSCALL3

#define _SYSCALL3 (   retType,
  num,
  type1,
  arg1,
  type2,
  arg2,
  type3,
  arg3 
)
Value:
({ \
register retType ret asm("rax"); \
register type1 _a1 asm("rdi") = (arg1); \
register type2 _a2 asm("rsi") = (arg2); \
register type3 _a3 asm("rdx") = (arg3); \
asm volatile("syscall\n" : "=a"(ret) : "a"(num), "r"(_a1), "r"(_a2), "r"(_a3) : "rcx", "r11", "memory"); \
ret; \
})

Definition at line 36 of file syscalls.h.

◆ _SYSCALL4

#define _SYSCALL4 (   retType,
  num,
  type1,
  arg1,
  type2,
  arg2,
  type3,
  arg3,
  type4,
  arg4 
)
Value:
({ \
register retType ret asm("rax"); \
register type1 _a1 asm("rdi") = (arg1); \
register type2 _a2 asm("rsi") = (arg2); \
register type3 _a3 asm("rdx") = (arg3); \
register type4 _a4 asm("r10") = (arg4); \
asm volatile("syscall\n" \
: "=a"(ret) \
: "a"(num), "r"(_a1), "r"(_a2), "r"(_a3), "r"(_a4) \
: "rcx", "r11", "memory"); \
ret; \
})

Definition at line 46 of file syscalls.h.

◆ _SYSCALL5

#define _SYSCALL5 (   retType,
  num,
  type1,
  arg1,
  type2,
  arg2,
  type3,
  arg3,
  type4,
  arg4,
  type5,
  arg5 
)
Value:
({ \
register retType ret asm("rax"); \
register type1 _a1 asm("rdi") = (arg1); \
register type2 _a2 asm("rsi") = (arg2); \
register type3 _a3 asm("rdx") = (arg3); \
register type4 _a4 asm("r10") = (arg4); \
register type5 _a5 asm("r8") = (arg5); \
asm volatile("syscall\n" \
: "=a"(ret) \
: "a"(num), "r"(_a1), "r"(_a2), "r"(_a3), "r"(_a4), "r"(_a5) \
: "rcx", "r11", "memory"); \
ret; \
})

Definition at line 60 of file syscalls.h.

◆ _SYSCALL6

#define _SYSCALL6 (   retType,
  num,
  type1,
  arg1,
  type2,
  arg2,
  type3,
  arg3,
  type4,
  arg4,
  type5,
  arg5,
  type6,
  arg6 
)
Value:
({ \
register retType ret asm("rax"); \
register type1 _a1 asm("rdi") = (arg1); \
register type2 _a2 asm("rsi") = (arg2); \
register type3 _a3 asm("rdx") = (arg3); \
register type4 _a4 asm("r10") = (arg4); \
register type5 _a5 asm("r8") = (arg5); \
register type6 _a6 asm("r9") = (arg6); \
asm volatile("syscall\n" \
: "=a"(ret) \
: "a"(num), "r"(_a1), "r"(_a2), "r"(_a3), "r"(_a4), "r"(_a5), "r"(_a6) \
: "rcx", "r11", "memory"); \
ret; \
})

Definition at line 75 of file syscalls.h.

Function Documentation

◆ _syscall_bind()

static uint64_t _syscall_bind ( fd_t  source,
const char *  mountpoint 
)
inlinestatic

Definition at line 258 of file syscalls.h.

References _SYSCALL2, and SYS_BIND.

Referenced by bind().

◆ _syscall_chdir()

static uint64_t _syscall_chdir ( const char *  path)
inlinestatic

Definition at line 178 of file syscalls.h.

References _SYSCALL1, and SYS_CHDIR.

Referenced by chdir().

◆ _syscall_claim()

static fd_t _syscall_claim ( key_t key)
inlinestatic

Definition at line 253 of file syscalls.h.

References _SYSCALL1, and SYS_CLAIM.

Referenced by claim().

◆ _syscall_close()

static uint64_t _syscall_close ( fd_t  fd)
inlinestatic

Definition at line 153 of file syscalls.h.

References _SYSCALL1, and SYS_CLOSE.

Referenced by close().

◆ _syscall_dup()

static fd_t _syscall_dup ( fd_t  oldFd)
inlinestatic

Definition at line 223 of file syscalls.h.

References _SYSCALL1, and SYS_DUP.

Referenced by dup().

◆ _syscall_dup2()

static fd_t _syscall_dup2 ( fd_t  oldFd,
fd_t  newFd 
)
inlinestatic

Definition at line 228 of file syscalls.h.

References _SYSCALL2, and SYS_DUP2.

Referenced by dup2().

◆ _syscall_errno()

◆ _syscall_futex()

static uint64_t _syscall_futex ( atomic_uint64_t *  addr,
uint64_t  val,
futex_op_t  op,
clock_t  timeout 
)
inlinestatic

Definition at line 233 of file syscalls.h.

References _SYSCALL4, and SYS_FUTEX.

Referenced by futex().

◆ _syscall_getdents()

static uint64_t _syscall_getdents ( fd_t  fd,
dirent_t buffer,
uint64_t  count 
)
inlinestatic

Definition at line 208 of file syscalls.h.

References _SYSCALL3, buffer, count, and SYS_GETDENTS.

Referenced by getdents().

◆ _syscall_getpid()

static pid_t _syscall_getpid ( void  )
inlinestatic

Definition at line 123 of file syscalls.h.

References _SYSCALL0, and SYS_GETPID.

Referenced by getpid().

◆ _syscall_gettid()

static tid_t _syscall_gettid ( void  )
inlinestatic

Definition at line 128 of file syscalls.h.

References _SYSCALL0, and SYS_GETTID.

Referenced by _threading_init(), and gettid().

◆ _syscall_ioctl()

static uint64_t _syscall_ioctl ( fd_t  fd,
uint64_t  request,
void *  argp,
uint64_t  size 
)
inlinestatic

Definition at line 173 of file syscalls.h.

References _SYSCALL4, and SYS_IOCTL.

Referenced by ioctl().

◆ _syscall_link()

static uint64_t _syscall_link ( const char *  oldPath,
const char *  newPath 
)
inlinestatic

Definition at line 243 of file syscalls.h.

References _SYSCALL2, and SYS_LINK.

Referenced by link(), and rename().

◆ _syscall_mmap()

static void * _syscall_mmap ( fd_t  fd,
void *  address,
uint64_t  length,
prot_t  prot 
)
inlinestatic

Definition at line 193 of file syscalls.h.

References _SYSCALL4, address, and SYS_MMAP.

Referenced by mmap().

◆ _syscall_mprotect()

static uint64_t _syscall_mprotect ( void *  address,
uint64_t  length,
prot_t  prot 
)
inlinestatic

Definition at line 203 of file syscalls.h.

References _SYSCALL3, address, and SYS_MPROTECT.

Referenced by mprotect().

◆ _syscall_munmap()

static uint64_t _syscall_munmap ( void *  address,
uint64_t  length 
)
inlinestatic

Definition at line 198 of file syscalls.h.

References _SYSCALL2, address, and SYS_MUNMAP.

Referenced by munmap().

◆ _syscall_nanosleep()

static uint64_t _syscall_nanosleep ( clock_t  nanoseconds)
inlinestatic

Definition at line 113 of file syscalls.h.

References _SYSCALL1, and SYS_NANOSLEEP.

Referenced by nanosleep().

◆ _syscall_open()

static fd_t _syscall_open ( const char *  path)
inlinestatic

Definition at line 143 of file syscalls.h.

References _SYSCALL1, and SYS_OPEN.

Referenced by open().

◆ _syscall_open2()

static uint64_t _syscall_open2 ( const char *  path,
fd_t  fds[2] 
)
inlinestatic

Definition at line 148 of file syscalls.h.

References _SYSCALL2, and SYS_OPEN2.

Referenced by open2().

◆ _syscall_poll()

static uint64_t _syscall_poll ( pollfd_t fds,
uint64_t  amount,
clock_t  timeout 
)
inlinestatic

Definition at line 183 of file syscalls.h.

References _SYSCALL3, and SYS_POLL.

Referenced by poll().

◆ _syscall_process_exit()

static _NORETURN void _syscall_process_exit ( uint64_t  status)
inlinestatic

Definition at line 91 of file syscalls.h.

References _SYSCALL1, and SYS_PROCESS_EXIT.

Referenced by exit().

◆ _syscall_read()

static uint64_t _syscall_read ( fd_t  fd,
void *  buffer,
uint64_t  count 
)
inlinestatic

Definition at line 158 of file syscalls.h.

References _SYSCALL3, buffer, count, and SYS_READ.

Referenced by read().

◆ _syscall_remove()

static uint64_t _syscall_remove ( const char *  path)
inlinestatic

Definition at line 238 of file syscalls.h.

References _SYSCALL1, and SYS_REMOVE.

Referenced by remove(), rename(), unlink(), and vremovef().

◆ _syscall_seek()

static uint64_t _syscall_seek ( fd_t  fd,
int64_t  offset,
seek_origin_t  origin 
)
inlinestatic

Definition at line 168 of file syscalls.h.

References _SYSCALL3, and SYS_SEEK.

Referenced by seek().

◆ _syscall_share()

static uint64_t _syscall_share ( key_t key,
fd_t  fd,
clock_t  timeout 
)
inlinestatic

Definition at line 248 of file syscalls.h.

References _SYSCALL3, and SYS_SHARE.

Referenced by share().

◆ _syscall_spawn()

static pid_t _syscall_spawn ( const char **  argv,
const spawn_fd_t fds,
const char *  cwd,
spawn_attr_t attr 
)
inlinestatic

Definition at line 107 of file syscalls.h.

References _SYSCALL4, and SYS_SPAWN.

Referenced by spawn().

◆ _syscall_stat()

static uint64_t _syscall_stat ( const char *  path,
stat_t info 
)
inlinestatic

Definition at line 188 of file syscalls.h.

References _SYSCALL2, info, and SYS_STAT.

Referenced by stat().

◆ _syscall_thread_create()

static tid_t _syscall_thread_create ( void *  entry,
void *  arg 
)
inlinestatic

Definition at line 213 of file syscalls.h.

References _SYSCALL2, and SYS_THREAD_CREATE.

Referenced by _thread_new().

◆ _syscall_thread_exit()

static _NORETURN void _syscall_thread_exit ( void  )
inlinestatic

Definition at line 99 of file syscalls.h.

References _SYSCALL0, and SYS_THREAD_EXIT.

Referenced by thrd_exit().

◆ _syscall_unix_epoch()

static time_t _syscall_unix_epoch ( void  )
inlinestatic

Definition at line 138 of file syscalls.h.

References _SYSCALL0, and SYS_UNIX_EPOCH.

Referenced by time().

◆ _syscall_uptime()

static clock_t _syscall_uptime ( void  )
inlinestatic

Definition at line 133 of file syscalls.h.

References _SYSCALL0, and SYS_UPTIME.

Referenced by uptime().

◆ _syscall_write()

static uint64_t _syscall_write ( fd_t  fd,
const void *  buffer,
uint64_t  count 
)
inlinestatic

Definition at line 163 of file syscalls.h.

References _SYSCALL3, buffer, count, and SYS_WRITE.

Referenced by write().

◆ _syscall_yield()

static void _syscall_yield ( void  )
inlinestatic

Definition at line 218 of file syscalls.h.

References _SYSCALL0, and SYS_YIELD.

Referenced by thrd_yield().