Fennix  1.0.0
Full Documentation
Loading...
Searching...
No Matches
syscalls.h File Reference

Go to the source code of this file.

Macros

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

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.
 
static scarg syscall1 (scarg syscall, scarg arg1)
 Syscall wrapper with 1 argument.
 
static scarg syscall2 (scarg syscall, scarg arg1, scarg arg2)
 Syscall wrapper with 2 arguments.
 
static scarg syscall3 (scarg syscall, scarg arg1, scarg arg2, scarg arg3)
 Syscall wrapper with 3 arguments.
 
static scarg syscall4 (scarg syscall, scarg arg1, scarg arg2, scarg arg3, scarg arg4)
 Syscall wrapper with 4 arguments.
 
static scarg syscall5 (scarg syscall, scarg arg1, scarg arg2, scarg arg3, scarg arg4, scarg arg5)
 Syscall wrapper with 5 arguments.
 
static scarg syscall6 (scarg syscall, scarg arg1, scarg arg2, scarg arg3, scarg arg4, scarg arg5, scarg arg6)
 Syscall wrapper with 6 arguments.
 

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 229 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 1569 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 1488 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 1451 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 1560 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 1531 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 1600 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 1586 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 1589 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 1471 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 1563 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 1551 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 1554 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 1511 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 1505 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 1508 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 1482 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 1494 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 1597 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 1514 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 1517 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 1474 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 1523 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 1566 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 1485 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 1543 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 1603 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 1534 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 1540 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 1537 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 1592 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 1468 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 1548 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:270

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 1526 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 1459 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 1465 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 1456 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 1575 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 1612 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 1606 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 1500 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 1572 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 1578 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 1557 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 1479 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 1497 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 1583 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 1491 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 1609 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 1520 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 1462 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 453 of file syscalls.h.

◆ __SYS_socklen_t

typedef unsigned int __SYS_socklen_t

Definition at line 454 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 261 of file syscalls.h.

262{
263 __SYS_F_OK = 0,
264 __SYS_R_OK = 1,
265 __SYS_W_OK = 2,
266 __SYS_X_OK = 3
syscall_access_flags_t
Definition syscalls.h:262
@ __SYS_X_OK
Definition syscalls.h:266
@ __SYS_R_OK
Definition syscalls.h:264
@ __SYS_F_OK
Definition syscalls.h:263
@ __SYS_W_OK
Definition syscalls.h:265

◆ syscall_clockid_t

Enumerator
__SYS_CLOCK_MONOTONIC 
__SYS_CLOCK_PROCESS_CPUTIME_ID 
__SYS_CLOCK_REALTIME 
__SYS_CLOCK_THREAD_CPUTIME_ID 

Definition at line 439 of file syscalls.h.

440{
syscall_clockid_t
Definition syscalls.h:440
@ __SYS_CLOCK_PROCESS_CPUTIME_ID
Definition syscalls.h:442
@ __SYS_CLOCK_REALTIME
Definition syscalls.h:443
@ __SYS_CLOCK_THREAD_CPUTIME_ID
Definition syscalls.h:444
@ __SYS_CLOCK_MONOTONIC
Definition syscalls.h:441

◆ 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 231 of file syscalls.h.

232{
233 __SYS_PROT_READ = 0x1,
234 __SYS_PROT_WRITE = 0x2,
235 __SYS_PROT_EXEC = 0x4,
236 __SYS_PROT_NONE = 0x0,
237
238 __SYS_MAP_SHARED = 0x1,
239 __SYS_MAP_PRIVATE = 0x2,
240 __SYS_MAP_FIXED = 0x4,
syscall_mmap_flags_t
Definition syscalls.h:232
@ __SYS_MAP_ANON
Definition syscalls.h:242
@ __SYS_PROT_NONE
Definition syscalls.h:236
@ __SYS_PROT_READ
Definition syscalls.h:233
@ __SYS_MAP_FIXED
Definition syscalls.h:240
@ __SYS_MAP_SHARED
Definition syscalls.h:238
@ __SYS_PROT_EXEC
Definition syscalls.h:235
@ __SYS_PROT_WRITE
Definition syscalls.h:234
@ __SYS_MAP_PRIVATE
Definition syscalls.h:239
@ __SYS_MAP_ANONYMOUS
Definition syscalls.h:241

◆ 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 245 of file syscalls.h.

246{
247 __SYS_O_RDONLY = 0x1,
248 __SYS_O_WRONLY = 0x2,
249 __SYS_O_RDWR = 0x3,
250 __SYS_O_APPEND = 0x4,
251 __SYS_O_CREAT = 0x8,
252 __SYS_O_DSYNC = 0x10,
253 __SYS_O_EXCL = 0x20,
254 __SYS_O_NOCTTY = 0x40,
255 __SYS_O_NONBLOCK = 0x80,
256 __SYS_O_RSYNC = 0x100,
257 __SYS_O_SYNC = 0x200,
258 __SYS_O_TRUNC = 0x400
syscall_open_flags_t
Definition syscalls.h:246
@ __SYS_O_RDWR
Definition syscalls.h:249
@ __SYS_O_DSYNC
Definition syscalls.h:252
@ __SYS_O_NONBLOCK
Definition syscalls.h:255
@ __SYS_O_RDONLY
Definition syscalls.h:247
@ __SYS_O_RSYNC
Definition syscalls.h:256
@ __SYS_O_WRONLY
Definition syscalls.h:248
@ __SYS_O_NOCTTY
Definition syscalls.h:254
@ __SYS_O_EXCL
Definition syscalls.h:253
@ __SYS_O_APPEND
Definition syscalls.h:250
@ __SYS_O_SYNC
Definition syscalls.h:257
@ __SYS_O_TRUNC
Definition syscalls.h:258
@ __SYS_O_CREAT
Definition syscalls.h:251

◆ syscall_prctl_options_t

Enumerator
__SYS_GET_GS 
__SYS_SET_GS 
__SYS_GET_FS 
__SYS_SET_FS 

Definition at line 269 of file syscalls.h.

270{
271 __SYS_GET_GS = 0,
272 __SYS_SET_GS = 1,
273 __SYS_GET_FS = 2,
274 __SYS_SET_FS = 3,
@ __SYS_GET_FS
Definition syscalls.h:273
@ __SYS_SET_GS
Definition syscalls.h:272
@ __SYS_GET_GS
Definition syscalls.h:271
@ __SYS_SET_FS
Definition syscalls.h:274

◆ syscall_seek_whence_t

Enumerator
__SYS_SEEK_SET 
__SYS_SEEK_CUR 
__SYS_SEEK_END 

Definition at line 280 of file syscalls.h.

281{
282 __SYS_SEEK_SET = 0,
283 __SYS_SEEK_CUR = 1,
syscall_seek_whence_t
Definition syscalls.h:281
@ __SYS_SEEK_CUR
Definition syscalls.h:283
@ __SYS_SEEK_SET
Definition syscalls.h:282
@ __SYS_SEEK_END
Definition syscalls.h:284

◆ syscall_signal_action_disposition_t

Enumerator
__SYS_SIG_ERR 
__SYS_SIG_DFL 
___SYS_SIG_IGN 

Definition at line 432 of file syscalls.h.

433{
434 __SYS_SIG_ERR = -1,
435 __SYS_SIG_DFL = 0,
syscall_signal_action_disposition_t
Definition syscalls.h:433
@ __SYS_SIG_ERR
Definition syscalls.h:434
@ ___SYS_SIG_IGN
Definition syscalls.h:436
@ __SYS_SIG_DFL
Definition syscalls.h:435

◆ 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 421 of file syscalls.h.

422{
424 __SYS_SA_ONSTACK = 0x08000000,
425 __SYS_SA_RESETHAND = 0x80000000,
426 __SYS_SA_RESTART = 0x10000000,
429 __SYS_SA_NODEFER = 0x40000000,
syscall_signal_action_flags_t
Definition syscalls.h:422
@ __SYS_SA_SIGINFO
Definition syscalls.h:427
@ __SYS_SA_RESTART
Definition syscalls.h:426
@ __SYS_SA_RESETHAND
Definition syscalls.h:425
@ __SYS_SA_ONSTACK
Definition syscalls.h:424
@ __SYS_SA_NODEFER
Definition syscalls.h:429
@ __SYS_SA_NOCLDSTOP
Definition syscalls.h:423
@ __SYS_SA_NOCLDWAIT
Definition syscalls.h:428

◆ syscall_signal_actions_t

Enumerator
__SYS_SIG_BLOCK 
__SYS_SIG_UNBLOCK 
__SYS_SIG_SETMASK 

Definition at line 414 of file syscalls.h.

415{
416 __SYS_SIG_BLOCK = 0,
syscall_signal_actions_t
Definition syscalls.h:415
@ __SYS_SIG_UNBLOCK
Definition syscalls.h:417
@ __SYS_SIG_SETMASK
Definition syscalls.h:418
@ __SYS_SIG_BLOCK
Definition syscalls.h:416

◆ 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 397 of file syscalls.h.

398{
400 __SYS_SIG_TERM = 0,
402 __SYS_SIG_IGN = 1,
404 __SYS_SIG_CONT = 2,
406 __SYS_SIG_STOP = 3,
syscall_signal_disposition_t
Definition syscalls.h:398
@ __SYS_SIG_TERM
Definition syscalls.h:400
@ __SYS_SIG_STOP
Definition syscalls.h:406
@ __SYS_SIG_CORE
Definition syscalls.h:408
@ __SYS_SIG_CONT
Definition syscalls.h:404
@ __SYS_SIG_IGN
Definition syscalls.h:402

◆ 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 287 of file syscalls.h.

288{
289 __SYS_SIGNULL = 0,
290 /* Process abort signal. */
291 __SYS_SIGABRT = 1,
292 /* Alarm clock. */
293 __SYS_SIGALRM = 2,
294 /* Access to an undefined portion of a memory object. */
295 __SYS_SIGBUS = 3,
296 /* Child process terminated, stopped, or continued. */
297 __SYS_SIGCHLD = 4,
298 /* Continue executing, if stopped. */
299 __SYS_SIGCONT = 5,
300 /* Erroneous arithmetic operation. */
301 __SYS_SIGFPE = 6,
302 /* Hangup. */
303 __SYS_SIGHUP = 7,
304 /* Illegal instruction. */
305 __SYS_SIGILL = 8,
306 /* Terminal interrupt signal. */
307 __SYS_SIGINT = 9,
308 /* Kill (cannot be caught or ignored). */
309 __SYS_SIGKILL = 10,
310 /* Write on a pipe with no one to read it. */
311 __SYS_SIGPIPE = 11,
312 /* Terminal quit signal. */
313 __SYS_SIGQUIT = 12,
314 /* Invalid memory reference. */
315 __SYS_SIGSEGV = 13,
316 /* Stop executing (cannot be caught or ignored). */
317 __SYS_SIGSTOP = 14,
318 /* Termination signal. */
319 __SYS_SIGTERM = 15,
320 /* Terminal stop signal. */
321 __SYS_SIGTSTP = 16,
322 /* Background process attempting read. */
323 __SYS_SIGTTIN = 17,
324 /* Background process attempting write. */
325 __SYS_SIGTTOU = 18,
326 /* User-defined signal 1. */
327 __SYS_SIGUSR1 = 19,
328 /* User-defined signal 2. */
329 __SYS_SIGUSR2 = 20,
330 /* Pollable event. */
331 __SYS_SIGPOLL = 21,
332 /* Profiling timer expired. */
333 __SYS_SIGPROF = 22,
334 /* Bad system call. */
335 __SYS_SIGSYS = 23,
336 /* Trace/breakpoint trap. */
337 __SYS_SIGTRAP = 24,
338 /* High bandwidth data is available at a socket. */
339 __SYS_SIGURG = 25,
340 /* Virtual timer expired. */
341 __SYS_SIGVTALRM = 26,
342 /* CPU time limit exceeded. */
343 __SYS_SIGXCPU = 27,
344 /* File size limit exceeded. */
345 __SYS_SIGXFSZ = 28,
346
351 __SYS_SIGCOMP1 = 29,
352 __SYS_SIGCOMP2 = 30,
353 __SYS_SIGCOMP3 = 31,
354
355 /* Real-time signals. */
356 __SYS_SIGRTMIN = 32,
357 __SYS_SIGRT_1 = 33,
358 __SYS_SIGRT_2 = 34,
359 __SYS_SIGRT_3 = 35,
360 __SYS_SIGRT_4 = 36,
361 __SYS_SIGRT_5 = 37,
362 __SYS_SIGRT_6 = 38,
363 __SYS_SIGRT_7 = 39,
364 __SYS_SIGRT_8 = 40,
365 __SYS_SIGRT_9 = 41,
366 __SYS_SIGRT_10 = 42,
367 __SYS_SIGRT_11 = 43,
368 __SYS_SIGRT_12 = 44,
369 __SYS_SIGRT_13 = 45,
370 __SYS_SIGRT_14 = 46,
371 __SYS_SIGRT_15 = 47,
372 __SYS_SIGRT_16 = 48,
373 __SYS_SIGRT_17 = 49,
374 __SYS_SIGRT_18 = 50,
375 __SYS_SIGRT_19 = 51,
376 __SYS_SIGRT_20 = 52,
377 __SYS_SIGRT_21 = 53,
378 __SYS_SIGRT_22 = 54,
379 __SYS_SIGRT_23 = 55,
380 __SYS_SIGRT_24 = 56,
381 __SYS_SIGRT_25 = 57,
382 __SYS_SIGRT_26 = 58,
383 __SYS_SIGRT_27 = 59,
384 __SYS_SIGRT_28 = 60,
385 __SYS_SIGRT_29 = 61,
386 __SYS_SIGRT_30 = 62,
387 __SYS_SIGRT_31 = 63,
388 __SYS_SIGRTMAX = 64,
389
390 /* Maximum signal number. */
syscall_signal_t
Definition syscalls.h:288
@ __SYS_SIGRTMAX
Definition syscalls.h:388
@ __SYS_SIGRT_11
Definition syscalls.h:367
@ __SYS_SIGRT_7
Definition syscalls.h:363
@ __SYS_SIGTTIN
Definition syscalls.h:323
@ __SYS_SIGUSR1
Definition syscalls.h:327
@ __SYS_SIGTSTP
Definition syscalls.h:321
@ __SYS_SIGTERM
Definition syscalls.h:319
@ __SYS_SIGPOLL
Definition syscalls.h:331
@ __SYS_SIGFPE
Definition syscalls.h:301
@ __SYS_SIGKILL
Definition syscalls.h:309
@ __SYS_SIGCOMP3
Definition syscalls.h:353
@ __SYS_SIGRT_29
Definition syscalls.h:385
@ __SYS_SIGRT_9
Definition syscalls.h:365
@ __SYS_SIGRT_1
Definition syscalls.h:357
@ __SYS_SIGRT_23
Definition syscalls.h:379
@ __SYS_SIGQUIT
Definition syscalls.h:313
@ __SYS_SIGURG
Definition syscalls.h:339
@ __SYS_SIGRT_15
Definition syscalls.h:371
@ __SYS_SIGBUS
Definition syscalls.h:295
@ __SYS_SIGTRAP
Definition syscalls.h:337
@ __SYS_SIGRT_3
Definition syscalls.h:359
@ __SYS_SIGRT_13
Definition syscalls.h:369
@ __SYS_SIGCOMP1
Definition syscalls.h:351
@ __SYS_SIGRT_4
Definition syscalls.h:360
@ __SYS_SIGRT_24
Definition syscalls.h:380
@ __SYS_SIGRT_17
Definition syscalls.h:373
@ __SYS_SIGNULL
Definition syscalls.h:289
@ __SYS_SIGCOMP2
Definition syscalls.h:352
@ __SYS_SIGABRT
Definition syscalls.h:291
@ __SYS_SIGRT_5
Definition syscalls.h:361
@ __SYS_SIGTTOU
Definition syscalls.h:325
@ __SYS_SIGNAL_MAX
Definition syscalls.h:391
@ __SYS_SIGALRM
Definition syscalls.h:293
@ __SYS_SIGRT_28
Definition syscalls.h:384
@ __SYS_SIGXFSZ
Definition syscalls.h:345
@ __SYS_SIGINT
Definition syscalls.h:307
@ __SYS_SIGSEGV
Definition syscalls.h:315
@ __SYS_SIGVTALRM
Definition syscalls.h:341
@ __SYS_SIGCONT
Definition syscalls.h:299
@ __SYS_SIGRT_30
Definition syscalls.h:386
@ __SYS_SIGSTOP
Definition syscalls.h:317
@ __SYS_SIGRT_25
Definition syscalls.h:381
@ __SYS_SIGRT_12
Definition syscalls.h:368
@ __SYS_SIGHUP
Definition syscalls.h:303
@ __SYS_SIGRTMIN
Definition syscalls.h:356
@ __SYS_SIGPIPE
Definition syscalls.h:311
@ __SYS_SIGXCPU
Definition syscalls.h:343
@ __SYS_SIGRT_20
Definition syscalls.h:376
@ __SYS_SIGRT_10
Definition syscalls.h:366
@ __SYS_SIGRT_26
Definition syscalls.h:382
@ __SYS_SIGRT_31
Definition syscalls.h:387
@ __SYS_SIGRT_16
Definition syscalls.h:372
@ __SYS_SIGRT_14
Definition syscalls.h:370
@ __SYS_SIGRT_18
Definition syscalls.h:374
@ __SYS_SIGRT_8
Definition syscalls.h:364
@ __SYS_SIGRT_2
Definition syscalls.h:358
@ __SYS_SIGSYS
Definition syscalls.h:335
@ __SYS_SIGRT_21
Definition syscalls.h:377
@ __SYS_SIGRT_22
Definition syscalls.h:378
@ __SYS_SIGCHLD
Definition syscalls.h:297
@ __SYS_SIGRT_19
Definition syscalls.h:375
@ __SYS_SIGRT_27
Definition syscalls.h:383
@ __SYS_SIGPROF
Definition syscalls.h:333
@ __SYS_SIGILL
Definition syscalls.h:305
@ __SYS_SIGUSR2
Definition syscalls.h:329
@ __SYS_SIGRT_6
Definition syscalls.h:362

◆ 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 462 of file syscalls.h.

463{
464 /* Initialization */
465
486 SYS_API_VERSION = 0,
487
488 /* I/O */
489
510 SYS_READ = 100,
532 SYS_PREAD,
553 SYS_WRITE,
608 SYS_OPEN,
624 SYS_CLOSE,
643 SYS_IOCTL,
644
645 /* File Status */
646
664 SYS_STAT = 200,
682 SYS_FSTAT,
701 SYS_LSTAT,
780 SYS_TELL,
804 SYS_SEEK,
805
806 /* Process Control */
807
822 SYS_EXIT = 300,
838 SYS_FORK,
920 SYS_KILL,
941 SYS_PRCTL,
942
943 /* Memory */
944
960 SYS_BRK = 400,
1003 SYS_MMAP,
1021 SYS_MUNMAP,
1059
1060 /* Communication */
1061
1078 SYS_PIPE = 500,
1094 SYS_DUP,
1112 SYS_DUP2,
1130 SYS_SOCKET,
1148 SYS_BIND,
1183 SYS_LISTEN,
1201 SYS_ACCEPT,
1220 SYS_SEND,
1239 SYS_RECV,
1257
1258 /* Time */
1259
1275 SYS_TIME = 600,
1327
1328 /* Miscellaneous */
1329
1346 SYS_GETCWD = 700,
1363 SYS_CHDIR,
1381 SYS_MKDIR,
1397 SYS_RMDIR,
1414 SYS_UNLINK,
1432 SYS_RENAME,
1433
1445 SYS_MAX
1446} syscalls_t;
syscalls_t
List of syscalls.
Definition syscalls.h:463
@ SYS_UNLINK
Remove a file.
Definition syscalls.h:1414
@ SYS_MMAP
Map files or devices into memory.
Definition syscalls.h:1003
@ SYS_SHUTDOWN
Shut down part of a full-duplex connection.
Definition syscalls.h:1256
@ SYS_RECV
Receive data on a socket.
Definition syscalls.h:1239
@ SYS_MAX
Max number of syscalls.
Definition syscalls.h:1445
@ SYS_STAT
Retrieve file status.
Definition syscalls.h:664
@ SYS_WRITE
Write to a file descriptor.
Definition syscalls.h:553
@ SYS_NANOSLEEP
Sleep for a specified time.
Definition syscalls.h:1326
@ SYS_TELL
Get the current file offset.
Definition syscalls.h:780
@ SYS_TRUNCATE
Change the size of a file.
Definition syscalls.h:746
@ SYS_PIPE
Create a pipe.
Definition syscalls.h:1078
@ SYS_RMDIR
Remove an empty directory.
Definition syscalls.h:1397
@ SYS_READ
Read from a file descriptor.
Definition syscalls.h:510
@ SYS_GETPPID
Get the parent process ID.
Definition syscalls.h:884
@ SYS_CLOSE
Close a file descriptor.
Definition syscalls.h:624
@ SYS_MADVISE
Provide advice about memory usage.
Definition syscalls.h:1058
@ SYS_EXECVE
Execute a program.
Definition syscalls.h:858
@ SYS_LISTEN
Listen for incoming connections on a socket.
Definition syscalls.h:1183
@ SYS_WAITPID
Wait for a child process to change state.
Definition syscalls.h:902
@ SYS_BRK
Set the program break.
Definition syscalls.h:960
@ SYS_MUNMAP
Unmap a mapped memory region.
Definition syscalls.h:1021
@ SYS_EXIT
Terminate the calling process.
Definition syscalls.h:822
@ SYS_OPEN
Open a file.
Definition syscalls.h:608
@ SYS_CONNECT
Connect to a remote address.
Definition syscalls.h:1166
@ SYS_IOCTL
Control a device.
Definition syscalls.h:643
@ SYS_PREAD
Read from a file descriptor.
Definition syscalls.h:532
@ SYS_RENAME
Rename a file or directory.
Definition syscalls.h:1432
@ SYS_GETPID
Get the process ID of the calling process.
Definition syscalls.h:871
@ SYS_FSTAT
Retrieve file status for an open file descriptor.
Definition syscalls.h:682
@ SYS_PWRITE
Write to a file descriptor.
Definition syscalls.h:574
@ SYS_BIND
Bind a socket to a local address.
Definition syscalls.h:1148
@ SYS_TIME
Get the current time.
Definition syscalls.h:1275
@ SYS_DUP
Duplicate a file descriptor.
Definition syscalls.h:1094
@ SYS_SOCKET
Create an endpoint for communication.
Definition syscalls.h:1130
@ SYS_CLOCK_SETTIME
Set the current time of a specific clock.
Definition syscalls.h:1309
@ SYS_API_VERSION
Set syscall version.
Definition syscalls.h:486
@ SYS_FORK
Create a child process.
Definition syscalls.h:838
@ SYS_SEND
Send data on a socket.
Definition syscalls.h:1220
@ SYS_PRCTL
Process/Thread Control.
Definition syscalls.h:941
@ SYS_LSTAT
Retrieve file status with symbolic link resolution.
Definition syscalls.h:701
@ SYS_DUP2
Duplicate a file descriptor to a specific value.
Definition syscalls.h:1112
@ SYS_KILL
Send a signal to a process.
Definition syscalls.h:920
@ SYS_MPROTECT
Change memory protection.
Definition syscalls.h:1039
@ SYS_MKDIR
Create a new directory.
Definition syscalls.h:1381
@ SYS_CHDIR
Change the current working directory.
Definition syscalls.h:1363
@ SYS_ACCEPT
Accept an incoming connection on a socket.
Definition syscalls.h:1201
@ SYS_FTRUNCATE
Change the size of a file referred by a file descriptor.
Definition syscalls.h:764
@ SYS_SEEK
Set the file offset.
Definition syscalls.h:804
@ SYS_GETCWD
Get the current working directory.
Definition syscalls.h:1346
@ SYS_CLOCK_GETTIME
Get the current time of a specific clock.
Definition syscalls.h:1292
@ SYS_ACCESS
Check a file's accessibility.
Definition syscalls.h:727

Function Documentation

◆ 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#if defined(__amd64__)
37 __asm__ __volatile__("syscall"
38 : "=a"(ret)
39 : "a"(syscall)
40 : "rcx", "r11", "memory");
41#elif defined(__i386__)
42#warning "i386 syscall wrapper not implemented"
43#else
44#error "Unsupported architecture"
45#endif
46 return ret;
47}
#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 58 of file syscalls.h.

59{
60 scarg ret;
61#if defined(__amd64__)
62 __asm__ __volatile__("syscall"
63 : "=a"(ret)
64 : "a"(syscall), "D"(arg1)
65 : "rcx", "r11", "memory");
66#elif defined(__i386__)
67#warning "i386 syscall wrapper not implemented"
68#else
69#error "Unsupported architecture"
70#endif
71 return ret;
72}

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 84 of file syscalls.h.

85{
86 scarg ret;
87#if defined(__amd64__)
88 __asm__ __volatile__("syscall"
89 : "=a"(ret)
90 : "a"(syscall), "D"(arg1), "S"(arg2)
91 : "rcx", "r11", "memory");
92#elif defined(__i386__)
93#warning "i386 syscall wrapper not implemented"
94#else
95#error "Unsupported architecture"
96#endif
97 return ret;
98}

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 111 of file syscalls.h.

112{
113 scarg ret;
114#if defined(__amd64__)
115 __asm__ __volatile__("syscall"
116 : "=a"(ret)
117 : "a"(syscall), "D"(arg1), "S"(arg2), "d"(arg3)
118 : "rcx", "r11", "memory");
119#elif defined(__i386__)
120#warning "i386 syscall wrapper not implemented"
121#else
122#error "Unsupported architecture"
123#endif
124 return ret;
125}

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 139 of file syscalls.h.

140{
141 scarg ret;
142#if defined(__amd64__)
143 register scarg r10 __asm__("r10") = arg4;
144 __asm__ __volatile__("syscall"
145 : "=a"(ret)
146 : "a"(syscall), "D"(arg1), "S"(arg2), "d"(arg3), "r"(r10)
147 : "rcx", "r11", "memory");
148#elif defined(__i386__)
149#warning "i386 syscall wrapper not implemented"
150#else
151#error "Unsupported architecture"
152#endif
153 return ret;
154}

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 169 of file syscalls.h.

170{
171 scarg ret;
172#if defined(__amd64__)
173 register scarg r10 __asm__("r10") = arg4;
174 register scarg r8 __asm__("r8") = arg5;
175 __asm__ __volatile__("syscall"
176 : "=a"(ret)
177 : "a"(syscall), "D"(arg1), "S"(arg2), "d"(arg3), "r"(r10), "r"(r8)
178 : "rcx", "r11", "memory");
179#elif defined(__i386__)
180#warning "i386 syscall wrapper not implemented"
181#else
182#error "Unsupported architecture"
183#endif
184 return ret;
185}

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 201 of file syscalls.h.

202{
203 scarg ret;
204#if defined(__amd64__)
205 register scarg r10 __asm__("r10") = arg4;
206 register scarg r8 __asm__("r8") = arg5;
207 register scarg r9 __asm__("r9") = arg6;
208 __asm__ __volatile__("syscall"
209 : "=a"(ret)
210 : "a"(syscall), "D"(arg1), "S"(arg2), "d"(arg3), "r"(r10), "r"(r8), "r"(r9)
211 : "rcx", "r11", "memory");
212#elif defined(__i386__)
213#warning "i386 syscall wrapper not implemented"
214#else
215#error "Unsupported architecture"
216#endif
217 return ret;
218}

References scarg.