Fennix  1.0.0
Full Documentation
syscalls.h File Reference

Go to the source code of this file.

Macros

#define scarg   __UINTPTR_TYPE__
 
#define __SYS_NULL   ((void *)0)
 NULL pointer. More...
 
#define call_api_version(version)   syscall1(SYS_API_VERSION, (scarg)version)
 Set syscall version. More...
 
#define call_read(fd, buf, count)   syscall3(SYS_READ, (scarg)fd, (scarg)buf, (scarg)count)
 Read from a file descriptor. More...
 
#define call_pread(fd, buf, count, offset)   syscall4(SYS_PREAD, (scarg)fd, (scarg)buf, (scarg)count, (scarg)offset)
 Read from a file descriptor. More...
 
#define call_write(fd, buf, count)   syscall3(SYS_WRITE, (scarg)fd, (scarg)buf, (scarg)count)
 Write to a file descriptor. More...
 
#define call_pwrite(fd, buf, count, offset)   syscall4(SYS_PWRITE, (scarg)fd, (scarg)buf, (scarg)count, (scarg)offset)
 Write to a file descriptor. More...
 
#define call_open(pathname, flags, mode)   syscall3(SYS_OPEN, (scarg)pathname, (scarg)flags, (scarg)mode)
 Open a file. More...
 
#define call_close(fd)   syscall1(SYS_CLOSE, fd)
 Close a file descriptor. More...
 
#define call_ioctl(fd, request, argp)   syscall3(SYS_IOCTL, (scarg)fd, (scarg)request, (scarg)argp)
 Control a device. More...
 
#define call_stat(pathname, statbuf)   syscall2(SYS_STAT, (scarg)pathname, (scarg)statbuf)
 Retrieve file status. More...
 
#define call_fstat(fd, statbuf)   syscall2(SYS_FSTAT, (scarg)fd, (scarg)statbuf)
 Retrieve file status for an open file descriptor. More...
 
#define call_lstat(pathname, statbuf)   syscall2(SYS_LSTAT, (scarg)pathname, (scarg)statbuf)
 Retrieve file status with symbolic link resolution. More...
 
#define call_access(pathname, mode)   syscall2(SYS_ACCESS, (scarg)pathname, (scarg)mode)
 Check a file's accessibility. More...
 
#define call_truncate(pathname, length)   syscall2(SYS_TRUNCATE, (scarg)pathname, (scarg)length)
 Change the size of a file. More...
 
#define call_ftruncate(fd, length)   syscall2(SYS_FTRUNCATE, (scarg)fd, (scarg)length)
 Change the size of a file referred by a file descriptor. More...
 
#define call_tell(fd)   syscall1(SYS_TELL, (scarg)fd)
 Get the current file offset. More...
 
#define call_seek(fd, offset, whence)   syscall3(SYS_SEEK, (scarg)fd, (scarg)offset, (scarg)whence)
 Set the file offset. More...
 
#define call_exit(status)   syscall1(SYS_EXIT, (scarg)status)
 Terminate the calling process. More...
 
#define call_fork()   syscall0(SYS_FORK)
 Create a child process. More...
 
#define call_execve(pathname, argv, envp)   syscall3(SYS_EXECVE, (scarg)pathname, (scarg)argv, (scarg)envp)
 Execute a program. More...
 
#define call_getpid()   syscall0(SYS_GETPID)
 Get the process ID of the calling process. More...
 
#define call_getppid()   syscall0(SYS_GETPPID)
 Get the parent process ID. More...
 
#define call_waitpid(pid, wstatus, options)   syscall3(SYS_WAITPID, (scarg)pid, (scarg)wstatus, (scarg)options)
 Wait for a child process to change state. More...
 
#define call_kill(pid, sig)   syscall2(SYS_KILL, (scarg)pid, (scarg)sig)
 Send a signal to a process. More...
 
#define call_prctl(option, arg1, arg2, arg3, arg4)   syscall5(SYS_PRCTL, (scarg)option, (scarg)arg1, (scarg)arg2, (scarg)arg3, (scarg)arg4)
 Process/Thread Control. More...
 
#define call_brk(end_data)   syscall1(SYS_BRK, (scarg)end_data)
 Set the program break. More...
 
#define call_mmap(addr, length, prot, flags, fd, offset)   syscall6(SYS_MMAP, (scarg)addr, (scarg)length, (scarg)prot, (scarg)flags, (scarg)fd, (scarg)offset)
 Map files or devices into memory. More...
 
#define call_munmap(addr, length)   syscall2(SYS_MUNMAP, (scarg)addr, (scarg)length)
 Unmap a mapped memory region. More...
 
#define call_mprotect(addr, length, prot)   syscall3(SYS_MPROTECT, (scarg)addr, (scarg)length, (scarg)prot)
 Change memory protection. More...
 
#define call_madvise(addr, length, advice)   syscall3(SYS_MADVISE, (scarg)addr, (scarg)length, (scarg)advice)
 Provide advice about memory usage. More...
 
#define call_pipe(pipefd)   syscall1(SYS_PIPE, (scarg)pipefd)
 Create a pipe. More...
 
#define call_dup(oldfd)   syscall1(SYS_DUP, (scarg)oldfd)
 Duplicate a file descriptor. More...
 
#define call_dup2(oldfd, newfd)   syscall2(SYS_DUP2, (scarg)oldfd, (scarg)newfd)
 Duplicate a file descriptor to a specific value. More...
 
#define call_socket(domain, type, protocol)   syscall3(SYS_SOCKET, (scarg)domain, (scarg)type, (scarg)protocol)
 Create an endpoint for communication. More...
 
#define call_bind(sockfd, addr, addrlen)   syscall3(SYS_BIND, (scarg)sockfd, (scarg)addr, (scarg)addrlen)
 Bind a socket to a local address. More...
 
#define call_connect(sockfd, addr, addrlen)   syscall3(SYS_CONNECT, (scarg)sockfd, (scarg)addr, (scarg)addrlen)
 Connect to a remote address. More...
 
#define call_listen(sockfd, backlog)   syscall2(SYS_LISTEN, (scarg)sockfd, (scarg)backlog)
 Listen for incoming connections on a socket. More...
 
#define call_accept(sockfd, addr, addrlen)   syscall3(SYS_ACCEPT, (scarg)sockfd, (scarg)addr, (scarg)addrlen)
 Accept an incoming connection on a socket. More...
 
#define call_send(sockfd, buf, len, flags)   syscall4(SYS_SEND, (scarg)sockfd, (scarg)buf, (scarg)len, (scarg)flags)
 Send data on a socket. More...
 
#define call_recv(sockfd, buf, len, flags)   syscall4(SYS_RECV, (scarg)sockfd, (scarg)buf, (scarg)len, (scarg)flags)
 Receive data on a socket. More...
 
#define call_shutdown(sockfd, how)   syscall2(SYS_SHUTDOWN, (scarg)sockfd, (scarg)how)
 Shut down part of a full-duplex connection. More...
 
#define call_time(t)   syscall1(SYS_TIME, t)
 Get the current time. More...
 
#define call_clock_gettime(clockid, tp)   syscall2(SYS_CLOCK_GETTIME, (scarg)clockid, (scarg)tp)
 Get the current time of a specific clock. More...
 
#define call_clock_settime(clockid, tp)   syscall2(SYS_CLOCK_SETTIME, (scarg)clockid, (scarg)tp)
 Set the current time of a specific clock. More...
 
#define call_nanosleep(req, rem)   syscall2(SYS_NANOSLEEP, (scarg)req, (scarg)rem)
 Sleep for a specified time. More...
 
#define call_getcwd(buf, size)   syscall2(SYS_GETCWD, (scarg)buf, (scarg)size)
 Get the current working directory. More...
 
#define call_chdir(path)   syscall1(SYS_CHDIR, (scarg)path)
 Change the current working directory. More...
 
#define call_mkdir(path, mode)   syscall2(SYS_MKDIR, (scarg)path, (scarg)mode)
 Create a new directory. More...
 
#define call_rmdir(path)   syscall1(SYS_RMDIR, (scarg)path)
 Remove an empty directory. More...
 
#define call_unlink(pathname)   syscall1(SYS_UNLINK, (scarg)pathname)
 Remove a file. More...
 
#define call_rename(oldpath, newpath)   syscall2(SYS_RENAME, (scarg)oldpath, (scarg)newpath)
 Rename a file or directory. More...
 

Typedefs

typedef int __SYS_clockid_t
 
typedef unsigned int __SYS_socklen_t
 

Enumerations

enum  syscall_mmap_flags_t {
  __SYS_PROT_READ = 0x1 , __SYS_PROT_WRITE = 0x2 , __SYS_PROT_EXEC = 0x4 , __SYS_PROT_NONE = 0x0 ,
  __SYS_MAP_SHARED = 0x1 , __SYS_MAP_PRIVATE = 0x2 , __SYS_MAP_FIXED = 0x4 , __SYS_MAP_ANONYMOUS = 0x8 ,
  __SYS_MAP_ANON = __SYS_MAP_ANONYMOUS
}
 
enum  syscall_open_flags_t {
  __SYS_O_RDONLY = 0x1 , __SYS_O_WRONLY = 0x2 , __SYS_O_RDWR = 0x3 , __SYS_O_APPEND = 0x4 ,
  __SYS_O_CREAT = 0x8 , __SYS_O_DSYNC = 0x10 , __SYS_O_EXCL = 0x20 , __SYS_O_NOCTTY = 0x40 ,
  __SYS_O_NONBLOCK = 0x80 , __SYS_O_RSYNC = 0x100 , __SYS_O_SYNC = 0x200 , __SYS_O_TRUNC = 0x400
}
 
enum  syscall_access_flags_t { __SYS_F_OK = 0 , __SYS_R_OK = 1 , __SYS_W_OK = 2 , __SYS_X_OK = 3 }
 
enum  syscall_prctl_options_t { __SYS_GET_GS = 0 , __SYS_SET_GS = 1 , __SYS_GET_FS = 2 , __SYS_SET_FS = 3 }
 
enum  syscall_seek_whence_t { __SYS_SEEK_SET = 0 , __SYS_SEEK_CUR = 1 , __SYS_SEEK_END = 2 }
 
enum  syscall_signal_t {
  __SYS_SIGNULL = 0 , __SYS_SIGABRT = 1 , __SYS_SIGALRM = 2 , __SYS_SIGBUS = 3 ,
  __SYS_SIGCHLD = 4 , __SYS_SIGCONT = 5 , __SYS_SIGFPE = 6 , __SYS_SIGHUP = 7 ,
  __SYS_SIGILL = 8 , __SYS_SIGINT = 9 , __SYS_SIGKILL = 10 , __SYS_SIGPIPE = 11 ,
  __SYS_SIGQUIT = 12 , __SYS_SIGSEGV = 13 , __SYS_SIGSTOP = 14 , __SYS_SIGTERM = 15 ,
  __SYS_SIGTSTP = 16 , __SYS_SIGTTIN = 17 , __SYS_SIGTTOU = 18 , __SYS_SIGUSR1 = 19 ,
  __SYS_SIGUSR2 = 20 , __SYS_SIGPOLL = 21 , __SYS_SIGPROF = 22 , __SYS_SIGSYS = 23 ,
  __SYS_SIGTRAP = 24 , __SYS_SIGURG = 25 , __SYS_SIGVTALRM = 26 , __SYS_SIGXCPU = 27 ,
  __SYS_SIGXFSZ = 28 , __SYS_SIGCOMP1 = 29 , __SYS_SIGCOMP2 = 30 , __SYS_SIGCOMP3 = 31 ,
  __SYS_SIGRTMIN = 32 , __SYS_SIGRT_1 = 33 , __SYS_SIGRT_2 = 34 , __SYS_SIGRT_3 = 35 ,
  __SYS_SIGRT_4 = 36 , __SYS_SIGRT_5 = 37 , __SYS_SIGRT_6 = 38 , __SYS_SIGRT_7 = 39 ,
  __SYS_SIGRT_8 = 40 , __SYS_SIGRT_9 = 41 , __SYS_SIGRT_10 = 42 , __SYS_SIGRT_11 = 43 ,
  __SYS_SIGRT_12 = 44 , __SYS_SIGRT_13 = 45 , __SYS_SIGRT_14 = 46 , __SYS_SIGRT_15 = 47 ,
  __SYS_SIGRT_16 = 48 , __SYS_SIGRT_17 = 49 , __SYS_SIGRT_18 = 50 , __SYS_SIGRT_19 = 51 ,
  __SYS_SIGRT_20 = 52 , __SYS_SIGRT_21 = 53 , __SYS_SIGRT_22 = 54 , __SYS_SIGRT_23 = 55 ,
  __SYS_SIGRT_24 = 56 , __SYS_SIGRT_25 = 57 , __SYS_SIGRT_26 = 58 , __SYS_SIGRT_27 = 59 ,
  __SYS_SIGRT_28 = 60 , __SYS_SIGRT_29 = 61 , __SYS_SIGRT_30 = 62 , __SYS_SIGRT_31 = 63 ,
  __SYS_SIGRTMAX = 64 , __SYS_SIGNAL_MAX = __SYS_SIGRTMAX
}
 
enum  syscall_signal_disposition_t {
  __SYS_SIG_TERM = 0 , __SYS_SIG_IGN = 1 , __SYS_SIG_CONT = 2 , __SYS_SIG_STOP = 3 ,
  __SYS_SIG_CORE = 4
}
 
enum  syscall_signal_actions_t { __SYS_SIG_BLOCK = 0 , __SYS_SIG_UNBLOCK = 1 , __SYS_SIG_SETMASK = 2 }
 
enum  syscall_signal_action_flags_t {
  __SYS_SA_NOCLDSTOP = 1 , __SYS_SA_ONSTACK = 0x08000000 , __SYS_SA_RESETHAND = 0x80000000 , __SYS_SA_RESTART = 0x10000000 ,
  __SYS_SA_SIGINFO = 4 , __SYS_SA_NOCLDWAIT = 2 , __SYS_SA_NODEFER = 0x40000000
}
 
enum  syscall_signal_action_disposition_t { __SYS_SIG_ERR = -1 , __SYS_SIG_DFL = 0 , ___SYS_SIG_IGN = 1 }
 
enum  syscall_clockid_t { __SYS_CLOCK_MONOTONIC = 1 , __SYS_CLOCK_PROCESS_CPUTIME_ID = 2 , __SYS_CLOCK_REALTIME = 3 , __SYS_CLOCK_THREAD_CPUTIME_ID = 4 }
 
enum  syscalls_t {
  SYS_API_VERSION = 0 , SYS_READ = 100 , SYS_PREAD , SYS_WRITE ,
  SYS_PWRITE , SYS_OPEN , SYS_CLOSE , SYS_IOCTL ,
  SYS_STAT = 200 , SYS_FSTAT , SYS_LSTAT , SYS_ACCESS ,
  SYS_TRUNCATE , SYS_FTRUNCATE , SYS_TELL , SYS_SEEK ,
  SYS_EXIT = 300 , SYS_FORK , SYS_EXECVE , SYS_GETPID ,
  SYS_GETPPID , SYS_WAITPID , SYS_KILL , SYS_PRCTL ,
  SYS_BRK = 400 , SYS_MMAP , SYS_MUNMAP , SYS_MPROTECT ,
  SYS_MADVISE , SYS_PIPE = 500 , SYS_DUP , SYS_DUP2 ,
  SYS_SOCKET , SYS_BIND , SYS_CONNECT , SYS_LISTEN ,
  SYS_ACCEPT , SYS_SEND , SYS_RECV , SYS_SHUTDOWN ,
  SYS_TIME = 600 , SYS_CLOCK_GETTIME , SYS_CLOCK_SETTIME , SYS_NANOSLEEP ,
  SYS_GETCWD = 700 , SYS_CHDIR , SYS_MKDIR , SYS_RMDIR ,
  SYS_UNLINK , SYS_RENAME , SYS_MAX
}
 List of syscalls. More...
 

Functions

static scarg syscall0 (scarg syscall)
 Syscall wrapper with 0 arguments. More...
 
static scarg syscall1 (scarg syscall, scarg arg1)
 Syscall wrapper with 1 argument. More...
 
static scarg syscall2 (scarg syscall, scarg arg1, scarg arg2)
 Syscall wrapper with 2 arguments. More...
 
static scarg syscall3 (scarg syscall, scarg arg1, scarg arg2, scarg arg3)
 Syscall wrapper with 3 arguments. More...
 
static scarg syscall4 (scarg syscall, scarg arg1, scarg arg2, scarg arg3, scarg arg4)
 Syscall wrapper with 4 arguments. More...
 
static scarg syscall5 (scarg syscall, scarg arg1, scarg arg2, scarg arg3, scarg arg4, scarg arg5)
 Syscall wrapper with 5 arguments. More...
 
static scarg syscall6 (scarg syscall, scarg arg1, scarg arg2, scarg arg3, scarg arg4, scarg arg5, scarg arg6)
 Syscall wrapper with 6 arguments. More...
 
 _Static_assert ((int) __SYS_SIG_IGN==(int) ___SYS_SIG_IGN, "SIG_IGN values do not match")
 

Macro Definition Documentation

◆ __SYS_NULL

#define __SYS_NULL   ((void *)0)

NULL pointer.

This is a pointer to address 0, which is reserved and cannot be dereferenced.

Note
This macro is defined only for this documentation.

Definition at line 187 of file syscalls.h.

◆ call_accept

#define call_accept (   sockfd,
  addr,
  addrlen 
)    syscall3(SYS_ACCEPT, (scarg)sockfd, (scarg)addr, (scarg)addrlen)

Accept an incoming connection on a socket.

int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);

Accepts an incoming connection on a listening socket, creating a new socket for communication.

Parameters
sockfdSocket file descriptor
addrClient address
addrlenLength of the address
Returns
  • New socket file descriptor on success
  • EINVAL if parameters are invalid

Definition at line 1527 of file syscalls.h.

◆ call_access

#define call_access (   pathname,
  mode 
)    syscall2(SYS_ACCESS, (scarg)pathname, (scarg)mode)

Check a file's accessibility.

int access(const char *pathname, int mode);

Checks if the calling process can access the file specified by pathname according to the specified mode.

Parameters
pathnamePath to the file
modeAccessibility check mode
Supported values:
Returns
  • EOK on success
  • EACCES if access is denied
  • ENOENT if the file does not exist
See also
syscall_access_flags_t

Definition at line 1446 of file syscalls.h.

◆ call_api_version

#define call_api_version (   version)    syscall1(SYS_API_VERSION, (scarg)version)

Set syscall version.

int api_version(int version);

This syscall is used to set the version of the list. To prevent applications from breaking on major changes, this should be called at the very beginning of the program.

Parameters
versionThe version of the syscall list of which the program was compiled with
Returns
  • EOK on success
  • EINVAL if the requested version is invalid
Note
If this syscall is not used, the latest version will be used.

Definition at line 1409 of file syscalls.h.

◆ call_bind

#define call_bind (   sockfd,
  addr,
  addrlen 
)    syscall3(SYS_BIND, (scarg)sockfd, (scarg)addr, (scarg)addrlen)

Bind a socket to a local address.

int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen);

Binds a socket to a local address so it can listen for incoming connections.

Parameters
sockfdSocket file descriptor
addrAddress to bind to
addrlenLength of the address
Returns
  • EOK on success
  • EINVAL if the socket is invalid

Definition at line 1518 of file syscalls.h.

◆ call_brk

#define call_brk (   end_data)    syscall1(SYS_BRK, (scarg)end_data)

Set the program break.

int brk(void *end_data);

Increases or decreases the program’s data space, ending at end_data.

Parameters
end_dataNew program break location
Returns
  • EOK on success
  • ENOMEM if memory allocation fails

Definition at line 1489 of file syscalls.h.

◆ call_chdir

#define call_chdir (   path)    syscall1(SYS_CHDIR, (scarg)path)

Change the current working directory.

int chdir(const char *path);

Changes the current working directory to the specified path.

Parameters
pathNew directory path
Returns
  • EOK on success
  • ENOENT if the directory does not exist
  • EACCES if permission is denied

Definition at line 1558 of file syscalls.h.

◆ call_clock_gettime

#define call_clock_gettime (   clockid,
  tp 
)    syscall2(SYS_CLOCK_GETTIME, (scarg)clockid, (scarg)tp)

Get the current time of a specific clock.

int clock_gettime(clockid_t clockid, struct timespec *tp);

Retrieves the current time for the specified clock (CLOCK_REALTIME, CLOCK_MONOTONIC, etc.).

Parameters
clockidClock ID to query
tpPointer to store the time
Returns
  • EOK on success
  • EINVAL if parameters are invalid

Definition at line 1544 of file syscalls.h.

◆ call_clock_settime

#define call_clock_settime (   clockid,
  tp 
)    syscall2(SYS_CLOCK_SETTIME, (scarg)clockid, (scarg)tp)

Set the current time of a specific clock.

int clock_settime(clockid_t clockid, const struct timespec *tp);

Sets the time for the specified clock (CLOCK_REALTIME, CLOCK_MONOTONIC, etc.).

Parameters
clockidClock ID to set
tpPointer to the time value
Returns
  • EOK on success
  • EINVAL if parameters are invalid

Definition at line 1547 of file syscalls.h.

◆ call_close

#define call_close (   fd)    syscall1(SYS_CLOSE, fd)

Close a file descriptor.

int close(int fd);

Closes the file descriptor fd, releasing its resources.

Parameters
fdFile descriptor to close
Returns
  • EOK on success
  • EBADF if fd is not a valid file descriptor

Definition at line 1429 of file syscalls.h.

◆ call_connect

#define call_connect (   sockfd,
  addr,
  addrlen 
)    syscall3(SYS_CONNECT, (scarg)sockfd, (scarg)addr, (scarg)addrlen)

Connect to a remote address.

int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);

Connects a socket to a remote address.

Parameters
sockfdSocket file descriptor
addrRemote address to connect to
addrlenLength of the address
Returns
  • EOK on success
  • EINVAL if parameters are invalid

Definition at line 1521 of file syscalls.h.

◆ call_dup

#define call_dup (   oldfd)    syscall1(SYS_DUP, (scarg)oldfd)

Duplicate a file descriptor.

int dup(int oldfd);

Duplicates the file descriptor oldfd, returning the new file descriptor.

Parameters
oldfdFile descriptor to duplicate
Returns
  • New file descriptor on success
  • EBADF if oldfd is invalid

Definition at line 1509 of file syscalls.h.

◆ call_dup2

#define call_dup2 (   oldfd,
  newfd 
)    syscall2(SYS_DUP2, (scarg)oldfd, (scarg)newfd)

Duplicate a file descriptor to a specific value.

int dup2(int oldfd, int newfd);

Duplicates oldfd to newfd. If newfd is already open, it will be closed first.

Parameters
oldfdFile descriptor to duplicate
newfdFile descriptor to duplicate oldfd to
Returns
  • newfd on success
  • EBADF if oldfd is invalid
  • EINVAL if newfd is invalid

Definition at line 1512 of file syscalls.h.

◆ call_execve

#define call_execve (   pathname,
  argv,
  envp 
)    syscall3(SYS_EXECVE, (scarg)pathname, (scarg)argv, (scarg)envp)

Execute a program.

int execve(const char *pathname, char *const argv[], char *const envp[]);

Replaces the current process image with a new process image specified by pathname.

Parameters
pathnamePath to the executable file
argvArgument vector
envpEnvironment variables
Returns
  • Does not return on success
  • ENOENT if the file does not exist
  • EACCES if permissions are insufficient

Definition at line 1469 of file syscalls.h.

◆ call_exit

#define call_exit (   status)    syscall1(SYS_EXIT, (scarg)status)

Terminate the calling process.

void exit(int status);

Terminates the calling process with the specified status. The status code is made available to the parent process.

Parameters
statusExit status code
Returns
This function does not return.

Definition at line 1463 of file syscalls.h.

◆ call_fork

#define call_fork ( )    syscall0(SYS_FORK)

Create a child process.

pid_t fork(void);

Creates a new process by duplicating the calling process. The child process has its own copy of the parent's address space.

Returns
  • 0 to the child process
  • PID of the child to the parent process
  • ENOMEM if memory is insufficient

Definition at line 1466 of file syscalls.h.

◆ call_fstat

#define call_fstat (   fd,
  statbuf 
)    syscall2(SYS_FSTAT, (scarg)fd, (scarg)statbuf)

Retrieve file status for an open file descriptor.

int fstat(int fd, struct stat *statbuf);

Gets the status of the file referred to by fd.

Parameters
fdFile descriptor
statbufBuffer to store file status
Returns
  • EOK on success
  • EBADF if fd is not a valid file descriptor
  • EFAULT if statbuf is outside accessible address space

Definition at line 1440 of file syscalls.h.

◆ call_ftruncate

#define call_ftruncate (   fd,
  length 
)    syscall2(SYS_FTRUNCATE, (scarg)fd, (scarg)length)

Change the size of a file referred by a file descriptor.

int ftruncate(int fd, off_t length);

Sets the size of the file referred to by fd to length.

Parameters
fdFile descriptor
lengthDesired file length
Returns

Definition at line 1452 of file syscalls.h.

◆ call_getcwd

#define call_getcwd (   buf,
  size 
)    syscall2(SYS_GETCWD, (scarg)buf, (scarg)size)

Get the current working directory.

char *getcwd(char *buf, size_t size);

Retrieves the current working directory.

Parameters
bufBuffer to store the directory path
sizeSize of the buffer
Returns

Definition at line 1555 of file syscalls.h.

◆ call_getpid

#define call_getpid ( )    syscall0(SYS_GETPID)

Get the process ID of the calling process.

pid_t getpid(void);

Returns the process ID of the calling process.

Returns
  • Process ID on success

Definition at line 1472 of file syscalls.h.

◆ call_getppid

#define call_getppid ( )    syscall0(SYS_GETPPID)

Get the parent process ID.

pid_t getppid(void);

Returns the parent process ID of the calling process.

Returns
  • Parent process ID on success

Definition at line 1475 of file syscalls.h.

◆ call_ioctl

#define call_ioctl (   fd,
  request,
  argp 
)    syscall3(SYS_IOCTL, (scarg)fd, (scarg)request, (scarg)argp)

Control a device.

int ioctl(int fd, unsigned long request, void *argp);

Manipulates the underlying parameters of a device.

Parameters
fdFile descriptor referring to the device
requestDevice-specific request code
argpArgument for the request
Returns
  • EOK on success
  • EBADF if fd is not valid
  • EINVAL if the request is invalid

Definition at line 1432 of file syscalls.h.

◆ call_kill

#define call_kill (   pid,
  sig 
)    syscall2(SYS_KILL, (scarg)pid, (scarg)sig)

Send a signal to a process.

int kill(pid_t pid, int sig);

Sends the signal sig to the process specified by pid.

Parameters
pidProcess ID
sigSignal to send
Returns
  • EOK on success
  • ESRCH if the process does not exist
  • EINVAL if sig is invalid

Definition at line 1481 of file syscalls.h.

◆ call_listen

#define call_listen (   sockfd,
  backlog 
)    syscall2(SYS_LISTEN, (scarg)sockfd, (scarg)backlog)

Listen for incoming connections on a socket.

int listen(int sockfd, int backlog);

Sets a socket to listen for incoming connections, specifying the backlog queue size.

Parameters
sockfdSocket file descriptor
backlogNumber of pending connections to allow
Returns
  • EOK on success
  • EINVAL if parameters are invalid

Definition at line 1524 of file syscalls.h.

◆ call_lstat

#define call_lstat (   pathname,
  statbuf 
)    syscall2(SYS_LSTAT, (scarg)pathname, (scarg)statbuf)

Retrieve file status with symbolic link resolution.

int lstat(const char *pathname, struct stat *statbuf);

Gets the status of the file specified by pathname, but does not follow symbolic links.

Parameters
pathnamePath to the file
statbufBuffer to store file status
Returns
  • EOK on success
  • ENOENT if the file does not exist
  • EACCES if permissions are insufficient

Definition at line 1443 of file syscalls.h.

◆ call_madvise

#define call_madvise (   addr,
  length,
  advice 
)    syscall3(SYS_MADVISE, (scarg)addr, (scarg)length, (scarg)advice)

Provide advice about memory usage.

int madvise(void *addr, size_t length, int advice);

Provides advice to the kernel about the expected behavior of the memory region starting at addr for length, such as whether it will be accessed randomly or sequentially.

Parameters
addrStart address of the memory region
lengthLength of the memory region
adviceDesired advice (e.g., MADV_DONTNEED, MADV_SEQUENTIAL)
Returns
  • EOK on success
  • EINVAL if the parameters are invalid

Definition at line 1501 of file syscalls.h.

◆ call_mkdir

#define call_mkdir (   path,
  mode 
)    syscall2(SYS_MKDIR, (scarg)path, (scarg)mode)

Create a new directory.

int mkdir(const char *path, mode_t mode);

Creates a new directory at path with the specified permissions.

Parameters
pathPath to the new directory
modeDirectory permissions
Returns
  • EOK on success
  • EEXIST if the directory already exists
  • EACCES if permission is denied

Definition at line 1561 of file syscalls.h.

◆ call_mmap

#define call_mmap (   addr,
  length,
  prot,
  flags,
  fd,
  offset 
)    syscall6(SYS_MMAP, (scarg)addr, (scarg)length, (scarg)prot, (scarg)flags, (scarg)fd, (scarg)offset)

Map files or devices into memory.

void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset);

Maps a file or device into memory. This can be used for memory-mapped I/O or for sharing memory between processes.

Parameters
addrDesired starting address of the mapping (NULL for automatic allocation)
lengthLength of the mapping
protDesired memory protection
Supported values:
flagsMapping options
Supported values:
fdFile descriptor for the file to map
offsetOffset in the file to start the mapping
Returns
There are several possible return values:
See also
syscall_mmap_flags_t

Definition at line 1492 of file syscalls.h.

◆ call_mprotect

#define call_mprotect (   addr,
  length,
  prot 
)    syscall3(SYS_MPROTECT, (scarg)addr, (scarg)length, (scarg)prot)

Change memory protection.

int mprotect(void *addr, size_t length, int prot);

Sets the protection on the memory region starting at addr for length.

Parameters
addrStart address of the memory region
lengthLength of the memory region
protDesired memory protection (e.g., PROT_READ, PROT_WRITE)
Returns
  • EOK on success
  • EACCES if protection cannot be set

Definition at line 1498 of file syscalls.h.

◆ call_munmap

#define call_munmap (   addr,
  length 
)    syscall2(SYS_MUNMAP, (scarg)addr, (scarg)length)

Unmap a mapped memory region.

int munmap(void *addr, size_t length);

Unmaps a previously mapped memory region, making the memory available for reuse.

Parameters
addrStart address of the memory region
lengthLength of the memory region to unmap
Returns
  • EOK on success
  • EINVAL if the address or length is invalid
  • EFAULT if the memory region is not currently mapped

Definition at line 1495 of file syscalls.h.

◆ call_nanosleep

#define call_nanosleep (   req,
  rem 
)    syscall2(SYS_NANOSLEEP, (scarg)req, (scarg)rem)

Sleep for a specified time.

int nanosleep(const struct timespec *req, struct timespec *rem);

Suspends the execution of the calling thread for the specified time duration.

Parameters
reqPointer to timespec specifying the time to sleep
remPointer to store remaining time if interrupted
Returns
  • EOK on success
  • EINTR if interrupted by a signal

Definition at line 1550 of file syscalls.h.

◆ call_open

#define call_open (   pathname,
  flags,
  mode 
)    syscall3(SYS_OPEN, (scarg)pathname, (scarg)flags, (scarg)mode)

Open a file.

int open(const char *pathname, int flags, mode_t mode);

Opens the file specified by pathname.

Parameters
pathnamePath to the file
flagsFlags for file access mode
Supported values:
modePermissions for newly created file (if applicable)
Returns
  • File descriptor on success
  • ENOENT if the file does not exist
  • EACCES if permissions are insufficient
See also
syscall_open_flags_t

Definition at line 1426 of file syscalls.h.

◆ call_pipe

#define call_pipe (   pipefd)    syscall1(SYS_PIPE, (scarg)pipefd)

Create a pipe.

int pipe(int pipefd[2]);

Creates a pipe, returning two file descriptors in pipefd. One is for reading, and the other is for writing.

Parameters
pipefdArray to store the two file descriptors
Returns
  • EOK on success
  • EMFILE if the process has too many open file descriptors

Definition at line 1506 of file syscalls.h.

◆ call_prctl

#define call_prctl (   option,
  arg1,
  arg2,
  arg3,
  arg4 
)    syscall5(SYS_PRCTL, (scarg)option, (scarg)arg1, (scarg)arg2, (scarg)arg3, (scarg)arg4)

Process/Thread Control.

int prctl(syscall_prctl_options_t option, unsigned long arg1, unsigned long arg2, unsigned long arg3, unsigned long arg4);
syscall_prctl_options_t
Definition: syscalls.h:228

Perform various operations on a process or thread.

Parameters
optionOperation to perform
arg1Argument 1
arg2Argument 2
arg3Argument 3
arg4Argument 4
Returns
  • EOK on success
  • EINVAL if the operation is invalid
  • EFAULT if one of the arguments is invalid

Definition at line 1484 of file syscalls.h.

◆ call_pread

#define call_pread (   fd,
  buf,
  count,
  offset 
)    syscall4(SYS_PREAD, (scarg)fd, (scarg)buf, (scarg)count, (scarg)offset)

Read from a file descriptor.

ssize_t sys_pread(int fildes, void *buf, size_t nbyte, off_t offset);

Reads up to count bytes from the file descriptor fd into the buffer starting at buf.

Parameters
fdFile descriptor to read from
bufBuffer where data will be stored
countMaximum number of bytes to read
offsetOffset in the file
Returns
  • Number of bytes read on success
  • 0 if the end of file is reached
  • EFAULT if the buffer is outside accessible address space
  • EBADF if fd is not a valid file descriptor

Definition at line 1417 of file syscalls.h.

◆ call_pwrite

#define call_pwrite (   fd,
  buf,
  count,
  offset 
)    syscall4(SYS_PWRITE, (scarg)fd, (scarg)buf, (scarg)count, (scarg)offset)

Write to a file descriptor.

ssize_t sys_pwrite(int fildes, const void *buf, size_t nbyte, off_t offset);

Writes up to count bytes from the buffer starting at buf to the file descriptor fd.

Parameters
fdFile descriptor to write to
bufBuffer containing data to write
countNumber of bytes to write
offsetOffset in the file
Returns
  • Number of bytes written on success
  • EFAULT if the buffer is outside accessible address space
  • EBADF if fd is not a valid file descriptor

Definition at line 1423 of file syscalls.h.

◆ call_read

#define call_read (   fd,
  buf,
  count 
)    syscall3(SYS_READ, (scarg)fd, (scarg)buf, (scarg)count)

Read from a file descriptor.

ssize_t sys_read(int fildes, void *buf, size_t nbyte);

Reads up to count bytes from the file descriptor fd into the buffer starting at buf.

Parameters
fdFile descriptor to read from
bufBuffer where data will be stored
countMaximum number of bytes to read
Returns
  • Number of bytes read on success
  • 0 if the end of file is reached
  • EFAULT if the buffer is outside accessible address space
  • EBADF if fd is not a valid file descriptor

Definition at line 1414 of file syscalls.h.

◆ call_recv

#define call_recv (   sockfd,
  buf,
  len,
  flags 
)    syscall4(SYS_RECV, (scarg)sockfd, (scarg)buf, (scarg)len, (scarg)flags)

Receive data on a socket.

ssize_t recv(int sockfd, void *buf, size_t len, int flags);

Receives data from a socket.

Parameters
sockfdSocket file descriptor
bufBuffer to store received data
lenMaximum number of bytes to receive
flagsFlags for the receive operation
Returns
  • Number of bytes received on success
  • EINVAL if parameters are invalid

Definition at line 1533 of file syscalls.h.

◆ call_rename

#define call_rename (   oldpath,
  newpath 
)    syscall2(SYS_RENAME, (scarg)oldpath, (scarg)newpath)

Rename a file or directory.

int rename(const char *oldpath, const char *newpath);

Renames a file or directory from oldpath to newpath.

Parameters
oldpathCurrent name of the file or directory
newpathNew name of the file or directory
Returns
  • EOK on success
  • EEXIST if the target exists
  • EACCES if permission is denied

Definition at line 1570 of file syscalls.h.

◆ call_rmdir

#define call_rmdir (   path)    syscall1(SYS_RMDIR, (scarg)path)

Remove an empty directory.

int rmdir(const char *path);

Removes the empty directory specified by path.

Parameters
pathPath to the directory
Returns

Definition at line 1564 of file syscalls.h.

◆ call_seek

#define call_seek (   fd,
  offset,
  whence 
)    syscall3(SYS_SEEK, (scarg)fd, (scarg)offset, (scarg)whence)

Set the file offset.

off_t seek(int fd, off_t offset, int whence);

Sets the file offset for the file referred to by fd to the specified offset according to the directive whence.

Parameters
fdFile descriptor
offsetOffset to set
whenceDirective for setting the offset
Supported values:
Returns
  • New file offset on success
  • EBADF if fd is not a valid file descriptor
  • EINVAL if whence is invalid

Definition at line 1458 of file syscalls.h.

◆ call_send

#define call_send (   sockfd,
  buf,
  len,
  flags 
)    syscall4(SYS_SEND, (scarg)sockfd, (scarg)buf, (scarg)len, (scarg)flags)

Send data on a socket.

ssize_t send(int sockfd, const void *buf, size_t len, int flags);

Sends data through a socket.

Parameters
sockfdSocket file descriptor
bufData to send
lenLength of the data
flagsFlags for the send operation
Returns
  • Number of bytes sent on success
  • EINVAL if parameters are invalid

Definition at line 1530 of file syscalls.h.

◆ call_shutdown

#define call_shutdown (   sockfd,
  how 
)    syscall2(SYS_SHUTDOWN, (scarg)sockfd, (scarg)how)

Shut down part of a full-duplex connection.

int shutdown(int sockfd, int how);

Shuts down part of a full-duplex connection on a socket.

Parameters
sockfdSocket file descriptor
howDetermines which operations to shut down (e.g., SHUT_RD, SHUT_WR)
Returns
  • EOK on success
  • EINVAL if parameters are invalid

Definition at line 1536 of file syscalls.h.

◆ call_socket

#define call_socket (   domain,
  type,
  protocol 
)    syscall3(SYS_SOCKET, (scarg)domain, (scarg)type, (scarg)protocol)

Create an endpoint for communication.

int socket(int domain, int type, int protocol);

Creates an endpoint for communication, returning a socket file descriptor.

Parameters
domainCommunication domain (e.g., AF_INET for IPv4)
typeType of socket (e.g., SOCK_STREAM for TCP)
protocolProtocol to use (e.g., IPPROTO_TCP)
Returns
  • Socket file descriptor on success
  • EINVAL if parameters are invalid

Definition at line 1515 of file syscalls.h.

◆ call_stat

#define call_stat (   pathname,
  statbuf 
)    syscall2(SYS_STAT, (scarg)pathname, (scarg)statbuf)

Retrieve file status.

int stat(const char *pathname, struct stat *statbuf);

Gets the status of the file specified by pathname.

Parameters
pathnamePath to the file
statbufBuffer to store file status
Returns
  • EOK on success
  • ENOENT if the file does not exist
  • EACCES if permissions are insufficient

Definition at line 1437 of file syscalls.h.

◆ call_tell

#define call_tell (   fd)    syscall1(SYS_TELL, (scarg)fd)

Get the current file offset.

off_t tell(int fd);

Returns the current file offset for the file referred to by fd.

Parameters
fdFile descriptor
Returns
  • Current file offset on success
  • EBADF if fd is not a valid file descriptor

Definition at line 1455 of file syscalls.h.

◆ call_time

#define call_time (   t)    syscall1(SYS_TIME, t)

Get the current time.

time_t time(time_t *t);

Retrieves the current calendar time as the number of seconds since the epoch.

Parameters
tPointer to store the time (optional)
Returns
  • Current time in seconds on success
  • __SYS_NULL if t is NULL

Definition at line 1541 of file syscalls.h.

◆ call_truncate

#define call_truncate (   pathname,
  length 
)    syscall2(SYS_TRUNCATE, (scarg)pathname, (scarg)length)

Change the size of a file.

int truncate(const char *pathname, off_t length);

Sets the size of the file specified by pathname to length. If the file is shorter, it is extended and the extended part is zero-filled.

Parameters
pathnamePath to the file
lengthDesired file length
Returns
  • EOK on success
  • EINVAL if length is invalid
  • EACCES if permissions are insufficient

Definition at line 1449 of file syscalls.h.

◆ call_unlink

#define call_unlink (   pathname)    syscall1(SYS_UNLINK, (scarg)pathname)

Remove a file.

int unlink(const char *pathname);

Removes the file specified by pathname.

Parameters
pathnamePath to the file
Returns
  • EOK on success
  • ENOENT if the file does not exist
  • EACCES if permission is denied

Definition at line 1567 of file syscalls.h.

◆ call_waitpid

#define call_waitpid (   pid,
  wstatus,
  options 
)    syscall3(SYS_WAITPID, (scarg)pid, (scarg)wstatus, (scarg)options)

Wait for a child process to change state.

pid_t waitpid(pid_t pid, int *wstatus, int options);

Waits for the child process specified by pid to change state.

Parameters
pidProcess ID to wait for
wstatusPointer to store the status information
optionsOptions for waiting behavior
Returns
  • Process ID of the child on success
  • ECHILD if no child processes exist

Definition at line 1478 of file syscalls.h.

◆ call_write

#define call_write (   fd,
  buf,
  count 
)    syscall3(SYS_WRITE, (scarg)fd, (scarg)buf, (scarg)count)

Write to a file descriptor.

ssize_t sys_write(int fildes, const void *buf, size_t nbyte);

Writes up to count bytes from the buffer starting at buf to the file descriptor fd.

Parameters
fdFile descriptor to write to
bufBuffer containing data to write
countNumber of bytes to write
Returns
  • Number of bytes written on success
  • EFAULT if the buffer is outside accessible address space
  • EBADF if fd is not a valid file descriptor
  • EPIPE if writing to a pipe with no reader

Definition at line 1420 of file syscalls.h.

◆ scarg

#define scarg   __UINTPTR_TYPE__

Definition at line 23 of file syscalls.h.

Typedef Documentation

◆ __SYS_clockid_t

typedef int __SYS_clockid_t

Definition at line 411 of file syscalls.h.

◆ __SYS_socklen_t

typedef unsigned int __SYS_socklen_t

Definition at line 412 of file syscalls.h.

Enumeration Type Documentation

◆ syscall_access_flags_t

Enumerator
__SYS_F_OK 
__SYS_R_OK 
__SYS_W_OK 
__SYS_X_OK 

Definition at line 219 of file syscalls.h.

220 {
221  __SYS_F_OK = 0,
222  __SYS_R_OK = 1,
223  __SYS_W_OK = 2,
224  __SYS_X_OK = 3
syscall_access_flags_t
Definition: syscalls.h:220
@ __SYS_X_OK
Definition: syscalls.h:224
@ __SYS_R_OK
Definition: syscalls.h:222
@ __SYS_F_OK
Definition: syscalls.h:221
@ __SYS_W_OK
Definition: syscalls.h:223

◆ syscall_clockid_t

Enumerator
__SYS_CLOCK_MONOTONIC 
__SYS_CLOCK_PROCESS_CPUTIME_ID 
__SYS_CLOCK_REALTIME 
__SYS_CLOCK_THREAD_CPUTIME_ID 

Definition at line 397 of file syscalls.h.

398 {
syscall_clockid_t
Definition: syscalls.h:398
@ __SYS_CLOCK_PROCESS_CPUTIME_ID
Definition: syscalls.h:400
@ __SYS_CLOCK_REALTIME
Definition: syscalls.h:401
@ __SYS_CLOCK_THREAD_CPUTIME_ID
Definition: syscalls.h:402
@ __SYS_CLOCK_MONOTONIC
Definition: syscalls.h:399

◆ syscall_mmap_flags_t

Enumerator
__SYS_PROT_READ 
__SYS_PROT_WRITE 
__SYS_PROT_EXEC 
__SYS_PROT_NONE 
__SYS_MAP_SHARED 
__SYS_MAP_PRIVATE 
__SYS_MAP_FIXED 
__SYS_MAP_ANONYMOUS 
__SYS_MAP_ANON 

Definition at line 189 of file syscalls.h.

190 {
191  __SYS_PROT_READ = 0x1,
192  __SYS_PROT_WRITE = 0x2,
193  __SYS_PROT_EXEC = 0x4,
194  __SYS_PROT_NONE = 0x0,
195 
196  __SYS_MAP_SHARED = 0x1,
197  __SYS_MAP_PRIVATE = 0x2,
198  __SYS_MAP_FIXED = 0x4,
199  __SYS_MAP_ANONYMOUS = 0x8,
syscall_mmap_flags_t
Definition: syscalls.h:190
@ __SYS_MAP_ANON
Definition: syscalls.h:200
@ __SYS_PROT_NONE
Definition: syscalls.h:194
@ __SYS_PROT_READ
Definition: syscalls.h:191
@ __SYS_MAP_FIXED
Definition: syscalls.h:198
@ __SYS_MAP_SHARED
Definition: syscalls.h:196
@ __SYS_PROT_EXEC
Definition: syscalls.h:193
@ __SYS_PROT_WRITE
Definition: syscalls.h:192
@ __SYS_MAP_PRIVATE
Definition: syscalls.h:197
@ __SYS_MAP_ANONYMOUS
Definition: syscalls.h:199

◆ syscall_open_flags_t

Enumerator
__SYS_O_RDONLY 
__SYS_O_WRONLY 
__SYS_O_RDWR 
__SYS_O_APPEND 
__SYS_O_CREAT 
__SYS_O_DSYNC 
__SYS_O_EXCL 
__SYS_O_NOCTTY 
__SYS_O_NONBLOCK 
__SYS_O_RSYNC 
__SYS_O_SYNC 
__SYS_O_TRUNC 

Definition at line 203 of file syscalls.h.

204 {
205  __SYS_O_RDONLY = 0x1,
206  __SYS_O_WRONLY = 0x2,
207  __SYS_O_RDWR = 0x3,
208  __SYS_O_APPEND = 0x4,
209  __SYS_O_CREAT = 0x8,
210  __SYS_O_DSYNC = 0x10,
211  __SYS_O_EXCL = 0x20,
212  __SYS_O_NOCTTY = 0x40,
213  __SYS_O_NONBLOCK = 0x80,
214  __SYS_O_RSYNC = 0x100,
215  __SYS_O_SYNC = 0x200,
216  __SYS_O_TRUNC = 0x400
syscall_open_flags_t
Definition: syscalls.h:204
@ __SYS_O_RDWR
Definition: syscalls.h:207
@ __SYS_O_DSYNC
Definition: syscalls.h:210
@ __SYS_O_NONBLOCK
Definition: syscalls.h:213
@ __SYS_O_RDONLY
Definition: syscalls.h:205
@ __SYS_O_RSYNC
Definition: syscalls.h:214
@ __SYS_O_WRONLY
Definition: syscalls.h:206
@ __SYS_O_NOCTTY
Definition: syscalls.h:212
@ __SYS_O_EXCL
Definition: syscalls.h:211
@ __SYS_O_APPEND
Definition: syscalls.h:208
@ __SYS_O_SYNC
Definition: syscalls.h:215
@ __SYS_O_TRUNC
Definition: syscalls.h:216
@ __SYS_O_CREAT
Definition: syscalls.h:209

◆ syscall_prctl_options_t

Enumerator
__SYS_GET_GS 
__SYS_SET_GS 
__SYS_GET_FS 
__SYS_SET_FS 

Definition at line 227 of file syscalls.h.

228 {
229  __SYS_GET_GS = 0,
230  __SYS_SET_GS = 1,
231  __SYS_GET_FS = 2,
232  __SYS_SET_FS = 3,
@ __SYS_GET_FS
Definition: syscalls.h:231
@ __SYS_SET_GS
Definition: syscalls.h:230
@ __SYS_GET_GS
Definition: syscalls.h:229
@ __SYS_SET_FS
Definition: syscalls.h:232

◆ syscall_seek_whence_t

Enumerator
__SYS_SEEK_SET 
__SYS_SEEK_CUR 
__SYS_SEEK_END 

Definition at line 238 of file syscalls.h.

239 {
240  __SYS_SEEK_SET = 0,
241  __SYS_SEEK_CUR = 1,
242  __SYS_SEEK_END = 2
syscall_seek_whence_t
Definition: syscalls.h:239
@ __SYS_SEEK_CUR
Definition: syscalls.h:241
@ __SYS_SEEK_SET
Definition: syscalls.h:240
@ __SYS_SEEK_END
Definition: syscalls.h:242

◆ syscall_signal_action_disposition_t

Enumerator
__SYS_SIG_ERR 
__SYS_SIG_DFL 
___SYS_SIG_IGN 

Definition at line 390 of file syscalls.h.

391 {
392  __SYS_SIG_ERR = -1,
393  __SYS_SIG_DFL = 0,
394  ___SYS_SIG_IGN = 1
syscall_signal_action_disposition_t
Definition: syscalls.h:391
@ __SYS_SIG_ERR
Definition: syscalls.h:392
@ ___SYS_SIG_IGN
Definition: syscalls.h:394
@ __SYS_SIG_DFL
Definition: syscalls.h:393

◆ syscall_signal_action_flags_t

Enumerator
__SYS_SA_NOCLDSTOP 
__SYS_SA_ONSTACK 
__SYS_SA_RESETHAND 
__SYS_SA_RESTART 
__SYS_SA_SIGINFO 
__SYS_SA_NOCLDWAIT 
__SYS_SA_NODEFER 

Definition at line 379 of file syscalls.h.

380 {
381  __SYS_SA_NOCLDSTOP = 1,
382  __SYS_SA_ONSTACK = 0x08000000,
383  __SYS_SA_RESETHAND = 0x80000000,
384  __SYS_SA_RESTART = 0x10000000,
385  __SYS_SA_SIGINFO = 4,
386  __SYS_SA_NOCLDWAIT = 2,
387  __SYS_SA_NODEFER = 0x40000000,
syscall_signal_action_flags_t
Definition: syscalls.h:380
@ __SYS_SA_SIGINFO
Definition: syscalls.h:385
@ __SYS_SA_RESTART
Definition: syscalls.h:384
@ __SYS_SA_RESETHAND
Definition: syscalls.h:383
@ __SYS_SA_ONSTACK
Definition: syscalls.h:382
@ __SYS_SA_NODEFER
Definition: syscalls.h:387
@ __SYS_SA_NOCLDSTOP
Definition: syscalls.h:381
@ __SYS_SA_NOCLDWAIT
Definition: syscalls.h:386

◆ syscall_signal_actions_t

Enumerator
__SYS_SIG_BLOCK 
__SYS_SIG_UNBLOCK 
__SYS_SIG_SETMASK 

Definition at line 372 of file syscalls.h.

373 {
374  __SYS_SIG_BLOCK = 0,
375  __SYS_SIG_UNBLOCK = 1,
syscall_signal_actions_t
Definition: syscalls.h:373
@ __SYS_SIG_UNBLOCK
Definition: syscalls.h:375
@ __SYS_SIG_SETMASK
Definition: syscalls.h:376
@ __SYS_SIG_BLOCK
Definition: syscalls.h:374

◆ syscall_signal_disposition_t

Enumerator
__SYS_SIG_TERM 

Terminate the process.

__SYS_SIG_IGN 

Ignore the signal.

__SYS_SIG_CONT 

Continue the process.

__SYS_SIG_STOP 

Stop the process.

__SYS_SIG_CORE 

Dump core.

Definition at line 355 of file syscalls.h.

356 {
358  __SYS_SIG_TERM = 0,
360  __SYS_SIG_IGN = 1,
362  __SYS_SIG_CONT = 2,
364  __SYS_SIG_STOP = 3,
366  __SYS_SIG_CORE = 4
syscall_signal_disposition_t
Definition: syscalls.h:356
@ __SYS_SIG_TERM
Definition: syscalls.h:358
@ __SYS_SIG_STOP
Definition: syscalls.h:364
@ __SYS_SIG_CORE
Definition: syscalls.h:366
@ __SYS_SIG_CONT
Definition: syscalls.h:362
@ __SYS_SIG_IGN
Definition: syscalls.h:360

◆ syscall_signal_t

Enumerator
__SYS_SIGNULL 
__SYS_SIGABRT 
__SYS_SIGALRM 
__SYS_SIGBUS 
__SYS_SIGCHLD 
__SYS_SIGCONT 
__SYS_SIGFPE 
__SYS_SIGHUP 
__SYS_SIGILL 
__SYS_SIGINT 
__SYS_SIGKILL 
__SYS_SIGPIPE 
__SYS_SIGQUIT 
__SYS_SIGSEGV 
__SYS_SIGSTOP 
__SYS_SIGTERM 
__SYS_SIGTSTP 
__SYS_SIGTTIN 
__SYS_SIGTTOU 
__SYS_SIGUSR1 
__SYS_SIGUSR2 
__SYS_SIGPOLL 
__SYS_SIGPROF 
__SYS_SIGSYS 
__SYS_SIGTRAP 
__SYS_SIGURG 
__SYS_SIGVTALRM 
__SYS_SIGXCPU 
__SYS_SIGXFSZ 
__SYS_SIGCOMP1 

Reserved These are just to match Linux's signal numbers.

__SYS_SIGCOMP2 
__SYS_SIGCOMP3 
__SYS_SIGRTMIN 
__SYS_SIGRT_1 
__SYS_SIGRT_2 
__SYS_SIGRT_3 
__SYS_SIGRT_4 
__SYS_SIGRT_5 
__SYS_SIGRT_6 
__SYS_SIGRT_7 
__SYS_SIGRT_8 
__SYS_SIGRT_9 
__SYS_SIGRT_10 
__SYS_SIGRT_11 
__SYS_SIGRT_12 
__SYS_SIGRT_13 
__SYS_SIGRT_14 
__SYS_SIGRT_15 
__SYS_SIGRT_16 
__SYS_SIGRT_17 
__SYS_SIGRT_18 
__SYS_SIGRT_19 
__SYS_SIGRT_20 
__SYS_SIGRT_21 
__SYS_SIGRT_22 
__SYS_SIGRT_23 
__SYS_SIGRT_24 
__SYS_SIGRT_25 
__SYS_SIGRT_26 
__SYS_SIGRT_27 
__SYS_SIGRT_28 
__SYS_SIGRT_29 
__SYS_SIGRT_30 
__SYS_SIGRT_31 
__SYS_SIGRTMAX 
__SYS_SIGNAL_MAX 

Definition at line 245 of file syscalls.h.

246 {
247  __SYS_SIGNULL = 0,
248  /* Process abort signal. */
249  __SYS_SIGABRT = 1,
250  /* Alarm clock. */
251  __SYS_SIGALRM = 2,
252  /* Access to an undefined portion of a memory object. */
253  __SYS_SIGBUS = 3,
254  /* Child process terminated, stopped, or continued. */
255  __SYS_SIGCHLD = 4,
256  /* Continue executing, if stopped. */
257  __SYS_SIGCONT = 5,
258  /* Erroneous arithmetic operation. */
259  __SYS_SIGFPE = 6,
260  /* Hangup. */
261  __SYS_SIGHUP = 7,
262  /* Illegal instruction. */
263  __SYS_SIGILL = 8,
264  /* Terminal interrupt signal. */
265  __SYS_SIGINT = 9,
266  /* Kill (cannot be caught or ignored). */
267  __SYS_SIGKILL = 10,
268  /* Write on a pipe with no one to read it. */
269  __SYS_SIGPIPE = 11,
270  /* Terminal quit signal. */
271  __SYS_SIGQUIT = 12,
272  /* Invalid memory reference. */
273  __SYS_SIGSEGV = 13,
274  /* Stop executing (cannot be caught or ignored). */
275  __SYS_SIGSTOP = 14,
276  /* Termination signal. */
277  __SYS_SIGTERM = 15,
278  /* Terminal stop signal. */
279  __SYS_SIGTSTP = 16,
280  /* Background process attempting read. */
281  __SYS_SIGTTIN = 17,
282  /* Background process attempting write. */
283  __SYS_SIGTTOU = 18,
284  /* User-defined signal 1. */
285  __SYS_SIGUSR1 = 19,
286  /* User-defined signal 2. */
287  __SYS_SIGUSR2 = 20,
288  /* Pollable event. */
289  __SYS_SIGPOLL = 21,
290  /* Profiling timer expired. */
291  __SYS_SIGPROF = 22,
292  /* Bad system call. */
293  __SYS_SIGSYS = 23,
294  /* Trace/breakpoint trap. */
295  __SYS_SIGTRAP = 24,
296  /* High bandwidth data is available at a socket. */
297  __SYS_SIGURG = 25,
298  /* Virtual timer expired. */
299  __SYS_SIGVTALRM = 26,
300  /* CPU time limit exceeded. */
301  __SYS_SIGXCPU = 27,
302  /* File size limit exceeded. */
303  __SYS_SIGXFSZ = 28,
304 
309  __SYS_SIGCOMP1 = 29,
310  __SYS_SIGCOMP2 = 30,
311  __SYS_SIGCOMP3 = 31,
312 
313  /* Real-time signals. */
314  __SYS_SIGRTMIN = 32,
315  __SYS_SIGRT_1 = 33,
316  __SYS_SIGRT_2 = 34,
317  __SYS_SIGRT_3 = 35,
318  __SYS_SIGRT_4 = 36,
319  __SYS_SIGRT_5 = 37,
320  __SYS_SIGRT_6 = 38,
321  __SYS_SIGRT_7 = 39,
322  __SYS_SIGRT_8 = 40,
323  __SYS_SIGRT_9 = 41,
324  __SYS_SIGRT_10 = 42,
325  __SYS_SIGRT_11 = 43,
326  __SYS_SIGRT_12 = 44,
327  __SYS_SIGRT_13 = 45,
328  __SYS_SIGRT_14 = 46,
329  __SYS_SIGRT_15 = 47,
330  __SYS_SIGRT_16 = 48,
331  __SYS_SIGRT_17 = 49,
332  __SYS_SIGRT_18 = 50,
333  __SYS_SIGRT_19 = 51,
334  __SYS_SIGRT_20 = 52,
335  __SYS_SIGRT_21 = 53,
336  __SYS_SIGRT_22 = 54,
337  __SYS_SIGRT_23 = 55,
338  __SYS_SIGRT_24 = 56,
339  __SYS_SIGRT_25 = 57,
340  __SYS_SIGRT_26 = 58,
341  __SYS_SIGRT_27 = 59,
342  __SYS_SIGRT_28 = 60,
343  __SYS_SIGRT_29 = 61,
344  __SYS_SIGRT_30 = 62,
345  __SYS_SIGRT_31 = 63,
346  __SYS_SIGRTMAX = 64,
347 
348  /* Maximum signal number. */
syscall_signal_t
Definition: syscalls.h:246
@ __SYS_SIGRTMAX
Definition: syscalls.h:346
@ __SYS_SIGRT_11
Definition: syscalls.h:325
@ __SYS_SIGRT_7
Definition: syscalls.h:321
@ __SYS_SIGTTIN
Definition: syscalls.h:281
@ __SYS_SIGUSR1
Definition: syscalls.h:285
@ __SYS_SIGTSTP
Definition: syscalls.h:279
@ __SYS_SIGTERM
Definition: syscalls.h:277
@ __SYS_SIGPOLL
Definition: syscalls.h:289
@ __SYS_SIGFPE
Definition: syscalls.h:259
@ __SYS_SIGKILL
Definition: syscalls.h:267
@ __SYS_SIGCOMP3
Definition: syscalls.h:311
@ __SYS_SIGRT_29
Definition: syscalls.h:343
@ __SYS_SIGRT_9
Definition: syscalls.h:323
@ __SYS_SIGRT_1
Definition: syscalls.h:315
@ __SYS_SIGRT_23
Definition: syscalls.h:337
@ __SYS_SIGQUIT
Definition: syscalls.h:271
@ __SYS_SIGURG
Definition: syscalls.h:297
@ __SYS_SIGRT_15
Definition: syscalls.h:329
@ __SYS_SIGBUS
Definition: syscalls.h:253
@ __SYS_SIGTRAP
Definition: syscalls.h:295
@ __SYS_SIGRT_3
Definition: syscalls.h:317
@ __SYS_SIGRT_13
Definition: syscalls.h:327
@ __SYS_SIGCOMP1
Definition: syscalls.h:309
@ __SYS_SIGRT_4
Definition: syscalls.h:318
@ __SYS_SIGRT_24
Definition: syscalls.h:338
@ __SYS_SIGRT_17
Definition: syscalls.h:331
@ __SYS_SIGNULL
Definition: syscalls.h:247
@ __SYS_SIGCOMP2
Definition: syscalls.h:310
@ __SYS_SIGABRT
Definition: syscalls.h:249
@ __SYS_SIGRT_5
Definition: syscalls.h:319
@ __SYS_SIGTTOU
Definition: syscalls.h:283
@ __SYS_SIGNAL_MAX
Definition: syscalls.h:349
@ __SYS_SIGALRM
Definition: syscalls.h:251
@ __SYS_SIGRT_28
Definition: syscalls.h:342
@ __SYS_SIGXFSZ
Definition: syscalls.h:303
@ __SYS_SIGINT
Definition: syscalls.h:265
@ __SYS_SIGSEGV
Definition: syscalls.h:273
@ __SYS_SIGVTALRM
Definition: syscalls.h:299
@ __SYS_SIGCONT
Definition: syscalls.h:257
@ __SYS_SIGRT_30
Definition: syscalls.h:344
@ __SYS_SIGSTOP
Definition: syscalls.h:275
@ __SYS_SIGRT_25
Definition: syscalls.h:339
@ __SYS_SIGRT_12
Definition: syscalls.h:326
@ __SYS_SIGHUP
Definition: syscalls.h:261
@ __SYS_SIGRTMIN
Definition: syscalls.h:314
@ __SYS_SIGPIPE
Definition: syscalls.h:269
@ __SYS_SIGXCPU
Definition: syscalls.h:301
@ __SYS_SIGRT_20
Definition: syscalls.h:334
@ __SYS_SIGRT_10
Definition: syscalls.h:324
@ __SYS_SIGRT_26
Definition: syscalls.h:340
@ __SYS_SIGRT_31
Definition: syscalls.h:345
@ __SYS_SIGRT_16
Definition: syscalls.h:330
@ __SYS_SIGRT_14
Definition: syscalls.h:328
@ __SYS_SIGRT_18
Definition: syscalls.h:332
@ __SYS_SIGRT_8
Definition: syscalls.h:322
@ __SYS_SIGRT_2
Definition: syscalls.h:316
@ __SYS_SIGSYS
Definition: syscalls.h:293
@ __SYS_SIGRT_21
Definition: syscalls.h:335
@ __SYS_SIGRT_22
Definition: syscalls.h:336
@ __SYS_SIGCHLD
Definition: syscalls.h:255
@ __SYS_SIGRT_19
Definition: syscalls.h:333
@ __SYS_SIGRT_27
Definition: syscalls.h:341
@ __SYS_SIGPROF
Definition: syscalls.h:291
@ __SYS_SIGILL
Definition: syscalls.h:263
@ __SYS_SIGUSR2
Definition: syscalls.h:287
@ __SYS_SIGRT_6
Definition: syscalls.h:320

◆ syscalls_t

enum syscalls_t

List of syscalls.

This list contains all the syscalls of the Fennix Kernel API.

Enumerator
SYS_API_VERSION 

Set syscall version.

int api_version(int version);

This syscall is used to set the version of the list. To prevent applications from breaking on major changes, this should be called at the very beginning of the program.

Parameters
versionThe version of the syscall list of which the program was compiled with
Returns
  • EOK on success
  • EINVAL if the requested version is invalid
Note
If this syscall is not used, the latest version will be used.
SYS_READ 

Read from a file descriptor.

ssize_t sys_read(int fildes, void *buf, size_t nbyte);

Reads up to count bytes from the file descriptor fd into the buffer starting at buf.

Parameters
fdFile descriptor to read from
bufBuffer where data will be stored
countMaximum number of bytes to read
Returns
  • Number of bytes read on success
  • 0 if the end of file is reached
  • EFAULT if the buffer is outside accessible address space
  • EBADF if fd is not a valid file descriptor
SYS_PREAD 

Read from a file descriptor.

ssize_t sys_pread(int fildes, void *buf, size_t nbyte, off_t offset);

Reads up to count bytes from the file descriptor fd into the buffer starting at buf.

Parameters
fdFile descriptor to read from
bufBuffer where data will be stored
countMaximum number of bytes to read
offsetOffset in the file
Returns
  • Number of bytes read on success
  • 0 if the end of file is reached
  • EFAULT if the buffer is outside accessible address space
  • EBADF if fd is not a valid file descriptor
SYS_WRITE 

Write to a file descriptor.

ssize_t sys_write(int fildes, const void *buf, size_t nbyte);

Writes up to count bytes from the buffer starting at buf to the file descriptor fd.

Parameters
fdFile descriptor to write to
bufBuffer containing data to write
countNumber of bytes to write
Returns
  • Number of bytes written on success
  • EFAULT if the buffer is outside accessible address space
  • EBADF if fd is not a valid file descriptor
  • EPIPE if writing to a pipe with no reader
SYS_PWRITE 

Write to a file descriptor.

ssize_t sys_pwrite(int fildes, const void *buf, size_t nbyte, off_t offset);

Writes up to count bytes from the buffer starting at buf to the file descriptor fd.

Parameters
fdFile descriptor to write to
bufBuffer containing data to write
countNumber of bytes to write
offsetOffset in the file
Returns
  • Number of bytes written on success
  • EFAULT if the buffer is outside accessible address space
  • EBADF if fd is not a valid file descriptor
SYS_OPEN 

Open a file.

int open(const char *pathname, int flags, mode_t mode);

Opens the file specified by pathname.

Parameters
pathnamePath to the file
flagsFlags for file access mode
Supported values:
modePermissions for newly created file (if applicable)
Returns
  • File descriptor on success
  • ENOENT if the file does not exist
  • EACCES if permissions are insufficient
See also
syscall_open_flags_t
SYS_CLOSE 

Close a file descriptor.

int close(int fd);

Closes the file descriptor fd, releasing its resources.

Parameters
fdFile descriptor to close
Returns
  • EOK on success
  • EBADF if fd is not a valid file descriptor
SYS_IOCTL 

Control a device.

int ioctl(int fd, unsigned long request, void *argp);

Manipulates the underlying parameters of a device.

Parameters
fdFile descriptor referring to the device
requestDevice-specific request code
argpArgument for the request
Returns
  • EOK on success
  • EBADF if fd is not valid
  • EINVAL if the request is invalid
SYS_STAT 

Retrieve file status.

int stat(const char *pathname, struct stat *statbuf);

Gets the status of the file specified by pathname.

Parameters
pathnamePath to the file
statbufBuffer to store file status
Returns
  • EOK on success
  • ENOENT if the file does not exist
  • EACCES if permissions are insufficient
SYS_FSTAT 

Retrieve file status for an open file descriptor.

int fstat(int fd, struct stat *statbuf);

Gets the status of the file referred to by fd.

Parameters
fdFile descriptor
statbufBuffer to store file status
Returns
  • EOK on success
  • EBADF if fd is not a valid file descriptor
  • EFAULT if statbuf is outside accessible address space
SYS_LSTAT 

Retrieve file status with symbolic link resolution.

int lstat(const char *pathname, struct stat *statbuf);

Gets the status of the file specified by pathname, but does not follow symbolic links.

Parameters
pathnamePath to the file
statbufBuffer to store file status
Returns
  • EOK on success
  • ENOENT if the file does not exist
  • EACCES if permissions are insufficient
SYS_ACCESS 

Check a file's accessibility.

int access(const char *pathname, int mode);

Checks if the calling process can access the file specified by pathname according to the specified mode.

Parameters
pathnamePath to the file
modeAccessibility check mode
Supported values:
Returns
  • EOK on success
  • EACCES if access is denied
  • ENOENT if the file does not exist
See also
syscall_access_flags_t
SYS_TRUNCATE 

Change the size of a file.

int truncate(const char *pathname, off_t length);

Sets the size of the file specified by pathname to length. If the file is shorter, it is extended and the extended part is zero-filled.

Parameters
pathnamePath to the file
lengthDesired file length
Returns
  • EOK on success
  • EINVAL if length is invalid
  • EACCES if permissions are insufficient
SYS_FTRUNCATE 

Change the size of a file referred by a file descriptor.

int ftruncate(int fd, off_t length);

Sets the size of the file referred to by fd to length.

Parameters
fdFile descriptor
lengthDesired file length
Returns
SYS_TELL 

Get the current file offset.

off_t tell(int fd);

Returns the current file offset for the file referred to by fd.

Parameters
fdFile descriptor
Returns
  • Current file offset on success
  • EBADF if fd is not a valid file descriptor
SYS_SEEK 

Set the file offset.

off_t seek(int fd, off_t offset, int whence);

Sets the file offset for the file referred to by fd to the specified offset according to the directive whence.

Parameters
fdFile descriptor
offsetOffset to set
whenceDirective for setting the offset
Supported values:
Returns
  • New file offset on success
  • EBADF if fd is not a valid file descriptor
  • EINVAL if whence is invalid
SYS_EXIT 

Terminate the calling process.

void exit(int status);

Terminates the calling process with the specified status. The status code is made available to the parent process.

Parameters
statusExit status code
Returns
This function does not return.
SYS_FORK 

Create a child process.

pid_t fork(void);

Creates a new process by duplicating the calling process. The child process has its own copy of the parent's address space.

Returns
  • 0 to the child process
  • PID of the child to the parent process
  • ENOMEM if memory is insufficient
SYS_EXECVE 

Execute a program.

int execve(const char *pathname, char *const argv[], char *const envp[]);

Replaces the current process image with a new process image specified by pathname.

Parameters
pathnamePath to the executable file
argvArgument vector
envpEnvironment variables
Returns
  • Does not return on success
  • ENOENT if the file does not exist
  • EACCES if permissions are insufficient
SYS_GETPID 

Get the process ID of the calling process.

pid_t getpid(void);

Returns the process ID of the calling process.

Returns
  • Process ID on success
SYS_GETPPID 

Get the parent process ID.

pid_t getppid(void);

Returns the parent process ID of the calling process.

Returns
  • Parent process ID on success
SYS_WAITPID 

Wait for a child process to change state.

pid_t waitpid(pid_t pid, int *wstatus, int options);

Waits for the child process specified by pid to change state.

Parameters
pidProcess ID to wait for
wstatusPointer to store the status information
optionsOptions for waiting behavior
Returns
  • Process ID of the child on success
  • ECHILD if no child processes exist
SYS_KILL 

Send a signal to a process.

int kill(pid_t pid, int sig);

Sends the signal sig to the process specified by pid.

Parameters
pidProcess ID
sigSignal to send
Returns
  • EOK on success
  • ESRCH if the process does not exist
  • EINVAL if sig is invalid
SYS_PRCTL 

Process/Thread Control.

int prctl(syscall_prctl_options_t option, unsigned long arg1, unsigned long arg2, unsigned long arg3, unsigned long arg4);

Perform various operations on a process or thread.

Parameters
optionOperation to perform
arg1Argument 1
arg2Argument 2
arg3Argument 3
arg4Argument 4
Returns
  • EOK on success
  • EINVAL if the operation is invalid
  • EFAULT if one of the arguments is invalid
SYS_BRK 

Set the program break.

int brk(void *end_data);

Increases or decreases the program’s data space, ending at end_data.

Parameters
end_dataNew program break location
Returns
  • EOK on success
  • ENOMEM if memory allocation fails
SYS_MMAP 

Map files or devices into memory.

void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset);

Maps a file or device into memory. This can be used for memory-mapped I/O or for sharing memory between processes.

Parameters
addrDesired starting address of the mapping (NULL for automatic allocation)
lengthLength of the mapping
protDesired memory protection
Supported values:
flagsMapping options
Supported values:
fdFile descriptor for the file to map
offsetOffset in the file to start the mapping
Returns
There are several possible return values:
See also
syscall_mmap_flags_t
SYS_MUNMAP 

Unmap a mapped memory region.

int munmap(void *addr, size_t length);

Unmaps a previously mapped memory region, making the memory available for reuse.

Parameters
addrStart address of the memory region
lengthLength of the memory region to unmap
Returns
  • EOK on success
  • EINVAL if the address or length is invalid
  • EFAULT if the memory region is not currently mapped
SYS_MPROTECT 

Change memory protection.

int mprotect(void *addr, size_t length, int prot);

Sets the protection on the memory region starting at addr for length.

Parameters
addrStart address of the memory region
lengthLength of the memory region
protDesired memory protection (e.g., PROT_READ, PROT_WRITE)
Returns
  • EOK on success
  • EACCES if protection cannot be set
SYS_MADVISE 

Provide advice about memory usage.

int madvise(void *addr, size_t length, int advice);

Provides advice to the kernel about the expected behavior of the memory region starting at addr for length, such as whether it will be accessed randomly or sequentially.

Parameters
addrStart address of the memory region
lengthLength of the memory region
adviceDesired advice (e.g., MADV_DONTNEED, MADV_SEQUENTIAL)
Returns
  • EOK on success
  • EINVAL if the parameters are invalid
SYS_PIPE 

Create a pipe.

int pipe(int pipefd[2]);

Creates a pipe, returning two file descriptors in pipefd. One is for reading, and the other is for writing.

Parameters
pipefdArray to store the two file descriptors
Returns
  • EOK on success
  • EMFILE if the process has too many open file descriptors
SYS_DUP 

Duplicate a file descriptor.

int dup(int oldfd);

Duplicates the file descriptor oldfd, returning the new file descriptor.

Parameters
oldfdFile descriptor to duplicate
Returns
  • New file descriptor on success
  • EBADF if oldfd is invalid
SYS_DUP2 

Duplicate a file descriptor to a specific value.

int dup2(int oldfd, int newfd);

Duplicates oldfd to newfd. If newfd is already open, it will be closed first.

Parameters
oldfdFile descriptor to duplicate
newfdFile descriptor to duplicate oldfd to
Returns
  • newfd on success
  • EBADF if oldfd is invalid
  • EINVAL if newfd is invalid
SYS_SOCKET 

Create an endpoint for communication.

int socket(int domain, int type, int protocol);

Creates an endpoint for communication, returning a socket file descriptor.

Parameters
domainCommunication domain (e.g., AF_INET for IPv4)
typeType of socket (e.g., SOCK_STREAM for TCP)
protocolProtocol to use (e.g., IPPROTO_TCP)
Returns
  • Socket file descriptor on success
  • EINVAL if parameters are invalid
SYS_BIND 

Bind a socket to a local address.

int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen);

Binds a socket to a local address so it can listen for incoming connections.

Parameters
sockfdSocket file descriptor
addrAddress to bind to
addrlenLength of the address
Returns
  • EOK on success
  • EINVAL if the socket is invalid
SYS_CONNECT 

Connect to a remote address.

int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);

Connects a socket to a remote address.

Parameters
sockfdSocket file descriptor
addrRemote address to connect to
addrlenLength of the address
Returns
  • EOK on success
  • EINVAL if parameters are invalid
SYS_LISTEN 

Listen for incoming connections on a socket.

int listen(int sockfd, int backlog);

Sets a socket to listen for incoming connections, specifying the backlog queue size.

Parameters
sockfdSocket file descriptor
backlogNumber of pending connections to allow
Returns
  • EOK on success
  • EINVAL if parameters are invalid
SYS_ACCEPT 

Accept an incoming connection on a socket.

int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);

Accepts an incoming connection on a listening socket, creating a new socket for communication.

Parameters
sockfdSocket file descriptor
addrClient address
addrlenLength of the address
Returns
  • New socket file descriptor on success
  • EINVAL if parameters are invalid
SYS_SEND 

Send data on a socket.

ssize_t send(int sockfd, const void *buf, size_t len, int flags);

Sends data through a socket.

Parameters
sockfdSocket file descriptor
bufData to send
lenLength of the data
flagsFlags for the send operation
Returns
  • Number of bytes sent on success
  • EINVAL if parameters are invalid
SYS_RECV 

Receive data on a socket.

ssize_t recv(int sockfd, void *buf, size_t len, int flags);

Receives data from a socket.

Parameters
sockfdSocket file descriptor
bufBuffer to store received data
lenMaximum number of bytes to receive
flagsFlags for the receive operation
Returns
  • Number of bytes received on success
  • EINVAL if parameters are invalid
SYS_SHUTDOWN 

Shut down part of a full-duplex connection.

int shutdown(int sockfd, int how);

Shuts down part of a full-duplex connection on a socket.

Parameters
sockfdSocket file descriptor
howDetermines which operations to shut down (e.g., SHUT_RD, SHUT_WR)
Returns
  • EOK on success
  • EINVAL if parameters are invalid
SYS_TIME 

Get the current time.

time_t time(time_t *t);

Retrieves the current calendar time as the number of seconds since the epoch.

Parameters
tPointer to store the time (optional)
Returns
  • Current time in seconds on success
  • __SYS_NULL if t is NULL
SYS_CLOCK_GETTIME 

Get the current time of a specific clock.

int clock_gettime(clockid_t clockid, struct timespec *tp);

Retrieves the current time for the specified clock (CLOCK_REALTIME, CLOCK_MONOTONIC, etc.).

Parameters
clockidClock ID to query
tpPointer to store the time
Returns
  • EOK on success
  • EINVAL if parameters are invalid
SYS_CLOCK_SETTIME 

Set the current time of a specific clock.

int clock_settime(clockid_t clockid, const struct timespec *tp);

Sets the time for the specified clock (CLOCK_REALTIME, CLOCK_MONOTONIC, etc.).

Parameters
clockidClock ID to set
tpPointer to the time value
Returns
  • EOK on success
  • EINVAL if parameters are invalid
SYS_NANOSLEEP 

Sleep for a specified time.

int nanosleep(const struct timespec *req, struct timespec *rem);

Suspends the execution of the calling thread for the specified time duration.

Parameters
reqPointer to timespec specifying the time to sleep
remPointer to store remaining time if interrupted
Returns
  • EOK on success
  • EINTR if interrupted by a signal
SYS_GETCWD 

Get the current working directory.

char *getcwd(char *buf, size_t size);

Retrieves the current working directory.

Parameters
bufBuffer to store the directory path
sizeSize of the buffer
Returns
SYS_CHDIR 

Change the current working directory.

int chdir(const char *path);

Changes the current working directory to the specified path.

Parameters
pathNew directory path
Returns
  • EOK on success
  • ENOENT if the directory does not exist
  • EACCES if permission is denied
SYS_MKDIR 

Create a new directory.

int mkdir(const char *path, mode_t mode);

Creates a new directory at path with the specified permissions.

Parameters
pathPath to the new directory
modeDirectory permissions
Returns
  • EOK on success
  • EEXIST if the directory already exists
  • EACCES if permission is denied
SYS_RMDIR 

Remove an empty directory.

int rmdir(const char *path);

Removes the empty directory specified by path.

Parameters
pathPath to the directory
Returns
SYS_UNLINK 

Remove a file.

int unlink(const char *pathname);

Removes the file specified by pathname.

Parameters
pathnamePath to the file
Returns
  • EOK on success
  • ENOENT if the file does not exist
  • EACCES if permission is denied
SYS_RENAME 

Rename a file or directory.

int rename(const char *oldpath, const char *newpath);

Renames a file or directory from oldpath to newpath.

Parameters
oldpathCurrent name of the file or directory
newpathNew name of the file or directory
Returns
  • EOK on success
  • EEXIST if the target exists
  • EACCES if permission is denied
SYS_MAX 

Max number of syscalls.

This is used to determine the size of the syscalls_t array.

syscalls_t syscalls[SYS_MAX];
Note
This must be the last element in the list

Definition at line 420 of file syscalls.h.

421 {
422  /* Initialization */
423 
444  SYS_API_VERSION = 0,
445 
446  /* I/O */
447 
468  SYS_READ = 100,
490  SYS_PREAD,
511  SYS_WRITE,
532  SYS_PWRITE,
566  SYS_OPEN,
582  SYS_CLOSE,
601  SYS_IOCTL,
602 
603  /* File Status */
604 
622  SYS_STAT = 200,
640  SYS_FSTAT,
659  SYS_LSTAT,
685  SYS_ACCESS,
704  SYS_TRUNCATE,
738  SYS_TELL,
762  SYS_SEEK,
763 
764  /* Process Control */
765 
780  SYS_EXIT = 300,
796  SYS_FORK,
816  SYS_EXECVE,
829  SYS_GETPID,
842  SYS_GETPPID,
860  SYS_WAITPID,
878  SYS_KILL,
899  SYS_PRCTL,
900 
901  /* Memory */
902 
918  SYS_BRK = 400,
961  SYS_MMAP,
979  SYS_MUNMAP,
997  SYS_MPROTECT,
1016  SYS_MADVISE,
1017 
1018  /* Communication */
1019 
1036  SYS_PIPE = 500,
1052  SYS_DUP,
1070  SYS_DUP2,
1088  SYS_SOCKET,
1106  SYS_BIND,
1124  SYS_CONNECT,
1141  SYS_LISTEN,
1159  SYS_ACCEPT,
1178  SYS_SEND,
1197  SYS_RECV,
1214  SYS_SHUTDOWN,
1215 
1216  /* Time */
1217 
1233  SYS_TIME = 600,
1284  SYS_NANOSLEEP,
1285 
1286  /* Miscellaneous */
1287 
1304  SYS_GETCWD = 700,
1321  SYS_CHDIR,
1339  SYS_MKDIR,
1355  SYS_RMDIR,
1372  SYS_UNLINK,
1390  SYS_RENAME,
1391 
1403  SYS_MAX
1404 } syscalls_t;
syscalls_t
List of syscalls.
Definition: syscalls.h:421
@ SYS_UNLINK
Remove a file.
Definition: syscalls.h:1372
@ SYS_MMAP
Map files or devices into memory.
Definition: syscalls.h:961
@ SYS_SHUTDOWN
Shut down part of a full-duplex connection.
Definition: syscalls.h:1214
@ SYS_RECV
Receive data on a socket.
Definition: syscalls.h:1197
@ SYS_MAX
Max number of syscalls.
Definition: syscalls.h:1403
@ SYS_STAT
Retrieve file status.
Definition: syscalls.h:622
@ SYS_WRITE
Write to a file descriptor.
Definition: syscalls.h:511
@ SYS_NANOSLEEP
Sleep for a specified time.
Definition: syscalls.h:1284
@ SYS_TELL
Get the current file offset.
Definition: syscalls.h:738
@ SYS_TRUNCATE
Change the size of a file.
Definition: syscalls.h:704
@ SYS_PIPE
Create a pipe.
Definition: syscalls.h:1036
@ SYS_RMDIR
Remove an empty directory.
Definition: syscalls.h:1355
@ SYS_READ
Read from a file descriptor.
Definition: syscalls.h:468
@ SYS_GETPPID
Get the parent process ID.
Definition: syscalls.h:842
@ SYS_CLOSE
Close a file descriptor.
Definition: syscalls.h:582
@ SYS_MADVISE
Provide advice about memory usage.
Definition: syscalls.h:1016
@ SYS_EXECVE
Execute a program.
Definition: syscalls.h:816
@ SYS_LISTEN
Listen for incoming connections on a socket.
Definition: syscalls.h:1141
@ SYS_WAITPID
Wait for a child process to change state.
Definition: syscalls.h:860
@ SYS_BRK
Set the program break.
Definition: syscalls.h:918
@ SYS_MUNMAP
Unmap a mapped memory region.
Definition: syscalls.h:979
@ SYS_EXIT
Terminate the calling process.
Definition: syscalls.h:780
@ SYS_OPEN
Open a file.
Definition: syscalls.h:566
@ SYS_CONNECT
Connect to a remote address.
Definition: syscalls.h:1124
@ SYS_IOCTL
Control a device.
Definition: syscalls.h:601
@ SYS_PREAD
Read from a file descriptor.
Definition: syscalls.h:490
@ SYS_RENAME
Rename a file or directory.
Definition: syscalls.h:1390
@ SYS_GETPID
Get the process ID of the calling process.
Definition: syscalls.h:829
@ SYS_FSTAT
Retrieve file status for an open file descriptor.
Definition: syscalls.h:640
@ SYS_PWRITE
Write to a file descriptor.
Definition: syscalls.h:532
@ SYS_BIND
Bind a socket to a local address.
Definition: syscalls.h:1106
@ SYS_TIME
Get the current time.
Definition: syscalls.h:1233
@ SYS_DUP
Duplicate a file descriptor.
Definition: syscalls.h:1052
@ SYS_SOCKET
Create an endpoint for communication.
Definition: syscalls.h:1088
@ SYS_CLOCK_SETTIME
Set the current time of a specific clock.
Definition: syscalls.h:1267
@ SYS_API_VERSION
Set syscall version.
Definition: syscalls.h:444
@ SYS_FORK
Create a child process.
Definition: syscalls.h:796
@ SYS_SEND
Send data on a socket.
Definition: syscalls.h:1178
@ SYS_PRCTL
Process/Thread Control.
Definition: syscalls.h:899
@ SYS_LSTAT
Retrieve file status with symbolic link resolution.
Definition: syscalls.h:659
@ SYS_DUP2
Duplicate a file descriptor to a specific value.
Definition: syscalls.h:1070
@ SYS_KILL
Send a signal to a process.
Definition: syscalls.h:878
@ SYS_MPROTECT
Change memory protection.
Definition: syscalls.h:997
@ SYS_MKDIR
Create a new directory.
Definition: syscalls.h:1339
@ SYS_CHDIR
Change the current working directory.
Definition: syscalls.h:1321
@ SYS_ACCEPT
Accept an incoming connection on a socket.
Definition: syscalls.h:1159
@ SYS_FTRUNCATE
Change the size of a file referred by a file descriptor.
Definition: syscalls.h:722
@ SYS_SEEK
Set the file offset.
Definition: syscalls.h:762
@ SYS_GETCWD
Get the current working directory.
Definition: syscalls.h:1304
@ SYS_CLOCK_GETTIME
Get the current time of a specific clock.
Definition: syscalls.h:1250
@ SYS_ACCESS
Check a file's accessibility.
Definition: syscalls.h:685

Function Documentation

◆ _Static_assert()

_Static_assert ( (int)  __SYS_SIG_IGN = =(int) ___SYS_SIG_IGN,
"SIG_IGN values do not match"   
)

◆ syscall0()

static scarg syscall0 ( scarg  syscall)
inlinestatic

Syscall wrapper with 0 arguments.

This wrapper is used to call syscalls with 0 arguments

Parameters
syscallsyscalls_t
Returns
The return value of the syscall

Definition at line 33 of file syscalls.h.

34 {
35  scarg ret;
36  __asm__ __volatile__("syscall"
37  : "=a"(ret)
38  : "a"(syscall)
39  : "rcx", "r11", "memory");
40  return ret;
41 }
#define scarg
Definition: syscalls.h:23

References scarg.

◆ syscall1()

static scarg syscall1 ( scarg  syscall,
scarg  arg1 
)
inlinestatic

Syscall wrapper with 1 argument.

This wrapper is used to call syscalls with 1 argument

Parameters
syscallsyscalls_t
arg1Argument 1
Returns
The return value of the syscall

Definition at line 52 of file syscalls.h.

53 {
54  scarg ret;
55  __asm__ __volatile__("syscall"
56  : "=a"(ret)
57  : "a"(syscall), "D"(arg1)
58  : "rcx", "r11", "memory");
59  return ret;
60 }

References scarg.

◆ syscall2()

static scarg syscall2 ( scarg  syscall,
scarg  arg1,
scarg  arg2 
)
inlinestatic

Syscall wrapper with 2 arguments.

This wrapper is used to call syscalls with 2 arguments

Parameters
syscallsyscalls_t
arg1Argument 1
arg2Argument 2
Returns
The return value of the syscall

Definition at line 72 of file syscalls.h.

73 {
74  scarg ret;
75  __asm__ __volatile__("syscall"
76  : "=a"(ret)
77  : "a"(syscall), "D"(arg1), "S"(arg2)
78  : "rcx", "r11", "memory");
79  return ret;
80 }

References scarg.

◆ syscall3()

static scarg syscall3 ( scarg  syscall,
scarg  arg1,
scarg  arg2,
scarg  arg3 
)
inlinestatic

Syscall wrapper with 3 arguments.

This wrapper is used to call syscalls with 3 arguments

Parameters
syscallsyscalls_t
arg1Argument 1
arg2Argument 2
arg3Argument 3
Returns
The return value of the syscall

Definition at line 93 of file syscalls.h.

94 {
95  scarg ret;
96  __asm__ __volatile__("syscall"
97  : "=a"(ret)
98  : "a"(syscall), "D"(arg1), "S"(arg2), "d"(arg3)
99  : "rcx", "r11", "memory");
100  return ret;
101 }

References scarg.

◆ syscall4()

static scarg syscall4 ( scarg  syscall,
scarg  arg1,
scarg  arg2,
scarg  arg3,
scarg  arg4 
)
inlinestatic

Syscall wrapper with 4 arguments.

This wrapper is used to call syscalls with 4 arguments

Parameters
syscallsyscalls_t
arg1Argument 1
arg2Argument 2
arg3Argument 3
arg4Argument 4
Returns
The return value of the syscall

Definition at line 115 of file syscalls.h.

116 {
117  scarg ret;
118  register scarg r10 __asm__("r10") = arg4;
119  __asm__ __volatile__("syscall"
120  : "=a"(ret)
121  : "a"(syscall), "D"(arg1), "S"(arg2), "d"(arg3), "r"(r10)
122  : "rcx", "r11", "memory");
123  return ret;
124 }

References scarg.

◆ syscall5()

static scarg syscall5 ( scarg  syscall,
scarg  arg1,
scarg  arg2,
scarg  arg3,
scarg  arg4,
scarg  arg5 
)
inlinestatic

Syscall wrapper with 5 arguments.

This wrapper is used to call syscalls with 5 arguments

Parameters
syscallsyscalls_t
arg1Argument 1
arg2Argument 2
arg3Argument 3
arg4Argument 4
arg5Argument 5
Returns
The return value of the syscall

Definition at line 139 of file syscalls.h.

140 {
141  scarg ret;
142  register scarg r10 __asm__("r10") = arg4;
143  register scarg r8 __asm__("r8") = arg5;
144  __asm__ __volatile__("syscall"
145  : "=a"(ret)
146  : "a"(syscall), "D"(arg1), "S"(arg2), "d"(arg3), "r"(r10), "r"(r8)
147  : "rcx", "r11", "memory");
148  return ret;
149 }

References scarg.

◆ syscall6()

static scarg syscall6 ( scarg  syscall,
scarg  arg1,
scarg  arg2,
scarg  arg3,
scarg  arg4,
scarg  arg5,
scarg  arg6 
)
inlinestatic

Syscall wrapper with 6 arguments.

This wrapper is used to call syscalls with 6 arguments

Parameters
syscallsyscalls_t
arg1Argument 1
arg2Argument 2
arg3Argument 3
arg4Argument 4
arg5Argument 5
arg6Argument 6
Returns
The return value of the syscall

Definition at line 165 of file syscalls.h.

166 {
167  scarg ret;
168  register scarg r10 __asm__("r10") = arg4;
169  register scarg r8 __asm__("r8") = arg5;
170  register scarg r9 __asm__("r9") = arg6;
171  __asm__ __volatile__("syscall"
172  : "=a"(ret)
173  : "a"(syscall), "D"(arg1), "S"(arg2), "d"(arg3), "r"(r10), "r"(r8), "r"(r9)
174  : "rcx", "r11", "memory");
175  return ret;
176 }

References scarg.