miniOS
x86_64 hobby kernel with SMP, VFS, and POSIX process model
Loading...
Searching...
No Matches
syscalls.c File Reference
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/select.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <poll.h>
#include <stdio.h>
#include <time.h>
#include <termios.h>
#include <signal.h>
#include <dirent.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <miniOS/syscall.h>
#include <errno.h>
#include <stddef.h>
#include <stdint.h>
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
Include dependency graph for syscalls.c:

Classes

struct  __dirstream
struct  sysinfo

Macros

#define DIR_BUF_SIZE   4096
#define DNS_PORT   53
#define DNS_TIMEOUT_MS   5000
#define DNS_BUF_SIZE   512
#define DNS_NAME_MAX   256
#define DNS_MAX_CHAIN   8

Typedefs

typedef void(* _miniOS_sighandler_t) (int)

Functions

static long inline_syscall (long nr, long arg1, long arg2, long arg3)
static long inline_syscall6 (long nr, long arg1, long arg2, long arg3, long arg4, long arg5, long arg6)
void * _sbrk (ptrdiff_t incr)
void * sbrk (ptrdiff_t incr)
ssize_t _write (int fd, const void *buf, size_t count)
ssize_t write (int fd, const void *buf, size_t count)
ssize_t _read (int fd, void *buf, size_t count)
ssize_t read (int fd, void *buf, size_t count)
int _open (const char *path, int flags,...)
int open (const char *path, int flags,...)
int _close (int fd)
int close (int fd)
off_t _lseek (int fd, off_t offset, int whence)
off_t lseek (int fd, off_t offset, int whence)
void _exit (int code)
void exit (int code)
int _fstat (int fd, struct stat *st)
int fstat (int fd, struct stat *st)
int _stat (const char *path, struct stat *st)
int stat (const char *path, struct stat *st)
pid_t _getpid (void)
pid_t getpid (void)
pid_t getppid (void)
pid_t setsid (void)
int setpgid (pid_t pid, pid_t pgid)
int kill (pid_t pid, int sig)
pid_t fork (void)
int exec (const char *path)
int execve (const char *path, char *const *argv, char *const *envp)
int execv (const char *path, char *const *argv)
static const char * _find_colon (const char *s)
static const char * _find_slash (const char *s)
int execvp (const char *file, char *const *argv)
pid_t waitpid (pid_t pid, int *status, int options)
pid_t _libc_wait (int *status)
int pipe (int fds[2])
int dup (int oldfd)
int dup2 (int oldfd, int newfd)
int _ioctl (int fd, unsigned long request, void *arg)
int ioctl (int fd, unsigned long request,...)
long getdents (int fd, void *buf, unsigned int count)
void * mmap (void *addr, size_t len, int prot, int flags, int fd, long offset)
int munmap (void *addr, size_t len)
int mount (const char *source, const char *target, const char *fstype, unsigned long flags, const void *data)
int umount (const char *target)
int mkdir (const char *path, mode_t mode)
int rmdir (const char *path)
int unlink (const char *path)
int access (const char *path, int mode)
_miniOS_sighandler_t signal (int sig, _miniOS_sighandler_t handler)
int sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
int chdir (const char *path)
char * getcwd (char *buf, size_t size)
int poll (struct pollfd *fds, unsigned int nfds, int timeout)
int select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
int fcntl (int fd, int cmd,...)
int lstat (const char *path, struct stat *st)
ssize_t readlink (const char *path, char *buf, size_t bufsiz)
unsigned int sleep (unsigned int seconds)
int nanosleep (const struct timespec *req, struct timespec *rem)
unsigned alarm (unsigned seconds)
int setitimer (int which, const struct itimerval *new_value, struct itimerval *old_value)
int tcsetpgrp (int fd, pid_t pgrp)
pid_t tcgetpgrp (int fd)
unsigned int if_nametoindex (const char *ifname)
char * if_indextoname (unsigned int ifindex, char *ifname)
struct if_nameindex * if_nameindex (void)
void if_freenameindex (struct if_nameindex *ptr)
int clock_gettime (clockid_t clockid, struct timespec *tp)
int sched_getcpu (void)
int fchdir (int fd)
int chroot (const char *path)
int settimeofday (const struct timeval *tv, const struct timezone *tz)
int setuid (unsigned int uid)
int setgid (unsigned int gid)
int seteuid (unsigned int euid)
int setegid (unsigned int egid)
int setgroups (int size, const unsigned int *list)
int vfork (void)
int link (const char *oldpath, const char *newpath)
int socket (int domain, int type, int protocol)
int bind (int sockfd, const struct sockaddr *addr, socklen_t addrlen)
int listen (int sockfd, int backlog)
ssize_t sendto (int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen)
int ttyname_r (int fd, char *buf, size_t buflen)
char * realpath (const char *path, char *resolved)
DIR * opendir (const char *path)
struct dirent * readdir (DIR *dirp)
int closedir (DIR *dirp)
void rewinddir (DIR *dirp)
int connect (int fd, const struct sockaddr *addr, socklen_t addrlen)
ssize_t recvfrom (int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen)
ssize_t recv (int sockfd, void *buf, size_t len, int flags)
int setsockopt (int fd, int level, int optname, const void *optval, socklen_t optlen)
int getsockopt (int fd, int level, int optname, void *optval, socklen_t *optlen)
int getsockname (int fd, struct sockaddr *addr, socklen_t *addrlen)
int getpeername (int fd, struct sockaddr *addr, socklen_t *addrlen)
int shutdown (int sockfd, int how)
int accept (int sockfd, struct sockaddr *addr, socklen_t *addrlen)
static int streq (const char *a, const char *b)
static char * dup_cstr (const char *src)
static int parse_ipv4_octet (const char **cpp, unsigned *out)
in_addr_t inet_addr (const char *cp)
int inet_aton (const char *cp, struct in_addr *inp)
char * inet_ntoa (struct in_addr in)
static int parse_numeric_service (const char *service, int socktype, int *out_port)
struct servent * getservbyname (const char *name, const char *proto)
static uint32_t dns_read_nameserver (void)
static int dns_encode_name (const char *name, uint8_t *out, int outlen)
static int dns_decode_name (const uint8_t *pkt, int pktlen, int off, char *out, int outlen)
static int dns_nameeq (const char *a, const char *b)
static int resolve_ipv4_hostname (const char *node, struct in_addr *out_addr)
struct hostent * gethostbyname (const char *name)
int getaddrinfo (const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res)
void freeaddrinfo (struct addrinfo *res)
int getnameinfo (const struct sockaddr *addr, unsigned int addrlen, char *host, unsigned int hostlen, char *serv, unsigned int servlen, int flags)
int prctl (int option,...)
int sysinfo (struct sysinfo *info)

Variables

static char * _brk_ptr
int h_errno
char ** environ
static struct servent g_service
static char * g_service_aliases [] = { NULL }
static struct hostent g_hostent
static char * g_hostent_aliases [] = { NULL }
static char * g_hostent_addr_list [] = { NULL, NULL }
static struct in_addr g_hostent_addr
static char g_hostent_name [256]

Macro Definition Documentation

◆ DIR_BUF_SIZE

#define DIR_BUF_SIZE   4096

◆ DNS_BUF_SIZE

#define DNS_BUF_SIZE   512

◆ DNS_MAX_CHAIN

#define DNS_MAX_CHAIN   8

◆ DNS_NAME_MAX

#define DNS_NAME_MAX   256

◆ DNS_PORT

#define DNS_PORT   53

◆ DNS_TIMEOUT_MS

#define DNS_TIMEOUT_MS   5000

Typedef Documentation

◆ _miniOS_sighandler_t

typedef void(* _miniOS_sighandler_t) (int)

Function Documentation

◆ _close()

int _close ( int fd)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _exit()

void _exit ( int code)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _find_colon()

const char * _find_colon ( const char * s)
static
Here is the caller graph for this function:

◆ _find_slash()

const char * _find_slash ( const char * s)
static
Here is the caller graph for this function:

◆ _fstat()

int _fstat ( int fd,
struct stat * st )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _getpid()

pid_t _getpid ( void )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _ioctl()

int _ioctl ( int fd,
unsigned long request,
void * arg )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _libc_wait()

pid_t _libc_wait ( int * status)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _lseek()

off_t _lseek ( int fd,
off_t offset,
int whence )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _open()

int _open ( const char * path,
int flags,
... )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _read()

ssize_t _read ( int fd,
void * buf,
size_t count )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _sbrk()

void * _sbrk ( ptrdiff_t incr)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _stat()

int _stat ( const char * path,
struct stat * st )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _write()

ssize_t _write ( int fd,
const void * buf,
size_t count )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ accept()

int accept ( int sockfd,
struct sockaddr * addr,
socklen_t * addrlen )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ access()

int access ( const char * path,
int mode )
Here is the call graph for this function:

◆ alarm()

unsigned alarm ( unsigned seconds)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ bind()

int bind ( int sockfd,
const struct sockaddr * addr,
socklen_t addrlen )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ chdir()

int chdir ( const char * path)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ chroot()

int chroot ( const char * path)
Here is the call graph for this function:

◆ clock_gettime()

int clock_gettime ( clockid_t clockid,
struct timespec * tp )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ close()

int close ( int fd)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ closedir()

int closedir ( DIR * dirp)
Here is the call graph for this function:

◆ connect()

int connect ( int fd,
const struct sockaddr * addr,
socklen_t addrlen )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dns_decode_name()

int dns_decode_name ( const uint8_t * pkt,
int pktlen,
int off,
char * out,
int outlen )
static
Here is the caller graph for this function:

◆ dns_encode_name()

int dns_encode_name ( const char * name,
uint8_t * out,
int outlen )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dns_nameeq()

int dns_nameeq ( const char * a,
const char * b )
static
Here is the caller graph for this function:

◆ dns_read_nameserver()

uint32_t dns_read_nameserver ( void )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dup()

int dup ( int oldfd)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dup2()

int dup2 ( int oldfd,
int newfd )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dup_cstr()

char * dup_cstr ( const char * src)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ exec()

int exec ( const char * path)
Here is the call graph for this function:

◆ execv()

int execv ( const char * path,
char *const * argv )
Here is the call graph for this function:

◆ execve()

int execve ( const char * path,
char *const * argv,
char *const * envp )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ execvp()

int execvp ( const char * file,
char *const * argv )
Here is the call graph for this function:

◆ exit()

void exit ( int code)
Here is the call graph for this function:

◆ fchdir()

int fchdir ( int fd)
Here is the call graph for this function:

◆ fcntl()

int fcntl ( int fd,
int cmd,
... )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fork()

pid_t fork ( void )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ freeaddrinfo()

void freeaddrinfo ( struct addrinfo * res)

◆ fstat()

int fstat ( int fd,
struct stat * st )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getaddrinfo()

int getaddrinfo ( const char * node,
const char * service,
const struct addrinfo * hints,
struct addrinfo ** res )
Here is the call graph for this function:

◆ getcwd()

char * getcwd ( char * buf,
size_t size )
Here is the call graph for this function:

◆ getdents()

long getdents ( int fd,
void * buf,
unsigned int count )
Here is the call graph for this function:

◆ gethostbyname()

struct hostent * gethostbyname ( const char * name)
Here is the call graph for this function:

◆ getnameinfo()

int getnameinfo ( const struct sockaddr * addr,
unsigned int addrlen,
char * host,
unsigned int hostlen,
char * serv,
unsigned int servlen,
int flags )
Here is the call graph for this function:

◆ getpeername()

int getpeername ( int fd,
struct sockaddr * addr,
socklen_t * addrlen )
Here is the call graph for this function:

◆ getpid()

pid_t getpid ( void )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getppid()

pid_t getppid ( void )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getservbyname()

struct servent * getservbyname ( const char * name,
const char * proto )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getsockname()

int getsockname ( int fd,
struct sockaddr * addr,
socklen_t * addrlen )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getsockopt()

int getsockopt ( int fd,
int level,
int optname,
void * optval,
socklen_t * optlen )
Here is the call graph for this function:

◆ if_freenameindex()

void if_freenameindex ( struct if_nameindex * ptr)
Here is the call graph for this function:

◆ if_indextoname()

char * if_indextoname ( unsigned int ifindex,
char * ifname )
Here is the call graph for this function:

◆ if_nameindex()

struct if_nameindex * if_nameindex ( void )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ if_nametoindex()

unsigned int if_nametoindex ( const char * ifname)

◆ inet_addr()

in_addr_t inet_addr ( const char * cp)
Here is the call graph for this function:

◆ inet_aton()

int inet_aton ( const char * cp,
struct in_addr * inp )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ inet_ntoa()

char * inet_ntoa ( struct in_addr in)
Here is the caller graph for this function:

◆ inline_syscall()

long inline_syscall ( long nr,
long arg1,
long arg2,
long arg3 )
inlinestatic

◆ inline_syscall6()

long inline_syscall6 ( long nr,
long arg1,
long arg2,
long arg3,
long arg4,
long arg5,
long arg6 )
inlinestatic
Here is the caller graph for this function:

◆ ioctl()

int ioctl ( int fd,
unsigned long request,
... )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kill()

int kill ( pid_t pid,
int sig )
Here is the call graph for this function:

◆ link()

int link ( const char * oldpath,
const char * newpath )
Here is the call graph for this function:

◆ listen()

int listen ( int sockfd,
int backlog )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lseek()

off_t lseek ( int fd,
off_t offset,
int whence )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lstat()

int lstat ( const char * path,
struct stat * st )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mkdir()

int mkdir ( const char * path,
mode_t mode )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mmap()

void * mmap ( void * addr,
size_t len,
int prot,
int flags,
int fd,
long offset )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mount()

int mount ( const char * source,
const char * target,
const char * fstype,
unsigned long flags,
const void * data )
Here is the call graph for this function:

◆ munmap()

int munmap ( void * addr,
size_t len )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ nanosleep()

int nanosleep ( const struct timespec * req,
struct timespec * rem )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ open()

int open ( const char * path,
int flags,
... )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ opendir()

DIR * opendir ( const char * path)
Here is the call graph for this function:

◆ parse_ipv4_octet()

int parse_ipv4_octet ( const char ** cpp,
unsigned * out )
static
Here is the caller graph for this function:

◆ parse_numeric_service()

int parse_numeric_service ( const char * service,
int socktype,
int * out_port )
static
Here is the caller graph for this function:

◆ pipe()

int pipe ( int fds[2])
Here is the call graph for this function:
Here is the caller graph for this function:

◆ poll()

int poll ( struct pollfd * fds,
unsigned int nfds,
int timeout )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ prctl()

int prctl ( int option,
... )

◆ read()

ssize_t read ( int fd,
void * buf,
size_t count )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ readdir()

struct dirent * readdir ( DIR * dirp)
Here is the call graph for this function:

◆ readlink()

ssize_t readlink ( const char * path,
char * buf,
size_t bufsiz )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ realpath()

char * realpath ( const char * path,
char * resolved )
Here is the call graph for this function:

◆ recv()

ssize_t recv ( int sockfd,
void * buf,
size_t len,
int flags )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ recvfrom()

ssize_t recvfrom ( int sockfd,
void * buf,
size_t len,
int flags,
struct sockaddr * src_addr,
socklen_t * addrlen )
Here is the caller graph for this function:

◆ resolve_ipv4_hostname()

int resolve_ipv4_hostname ( const char * node,
struct in_addr * out_addr )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rewinddir()

void rewinddir ( DIR * dirp)
Here is the call graph for this function:

◆ rmdir()

int rmdir ( const char * path)
Here is the call graph for this function:

◆ sbrk()

void * sbrk ( ptrdiff_t incr)
Here is the call graph for this function:

◆ sched_getcpu()

int sched_getcpu ( void )
Here is the call graph for this function:

◆ select()

int select ( int nfds,
fd_set * readfds,
fd_set * writefds,
fd_set * exceptfds,
struct timeval * timeout )
Here is the call graph for this function:

◆ sendto()

ssize_t sendto ( int sockfd,
const void * buf,
size_t len,
int flags,
const struct sockaddr * dest_addr,
socklen_t addrlen )
Here is the caller graph for this function:

◆ setegid()

int setegid ( unsigned int egid)
Here is the call graph for this function:

◆ seteuid()

int seteuid ( unsigned int euid)
Here is the call graph for this function:

◆ setgid()

int setgid ( unsigned int gid)
Here is the call graph for this function:

◆ setgroups()

int setgroups ( int size,
const unsigned int * list )
Here is the call graph for this function:

◆ setitimer()

int setitimer ( int which,
const struct itimerval * new_value,
struct itimerval * old_value )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setpgid()

int setpgid ( pid_t pid,
pid_t pgid )
Here is the call graph for this function:

◆ setsid()

pid_t setsid ( void )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setsockopt()

int setsockopt ( int fd,
int level,
int optname,
const void * optval,
socklen_t optlen )
Here is the call graph for this function:

◆ settimeofday()

int settimeofday ( const struct timeval * tv,
const struct timezone * tz )
Here is the call graph for this function:

◆ setuid()

int setuid ( unsigned int uid)
Here is the call graph for this function:

◆ shutdown()

int shutdown ( int sockfd,
int how )
Here is the call graph for this function:

◆ sigaction()

int sigaction ( int sig,
const struct sigaction * act,
struct sigaction * oact )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ signal()

_miniOS_sighandler_t signal ( int sig,
_miniOS_sighandler_t handler )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sleep()

unsigned int sleep ( unsigned int seconds)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ socket()

int socket ( int domain,
int type,
int protocol )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ stat()

int stat ( const char * path,
struct stat * st )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ streq()

int streq ( const char * a,
const char * b )
static
Here is the caller graph for this function:

◆ sysinfo()

int sysinfo ( struct sysinfo * info)
Here is the call graph for this function:

◆ tcgetpgrp()

pid_t tcgetpgrp ( int fd)
Here is the call graph for this function:

◆ tcsetpgrp()

int tcsetpgrp ( int fd,
pid_t pgrp )
Here is the call graph for this function:

◆ ttyname_r()

int ttyname_r ( int fd,
char * buf,
size_t buflen )

◆ umount()

int umount ( const char * target)
Here is the call graph for this function:

◆ unlink()

int unlink ( const char * path)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfork()

int vfork ( void )
Here is the call graph for this function:

◆ waitpid()

pid_t waitpid ( pid_t pid,
int * status,
int options )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write()

ssize_t write ( int fd,
const void * buf,
size_t count )
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ _brk_ptr

char* _brk_ptr
static

◆ environ

char** environ
extern

◆ g_hostent

struct hostent g_hostent
static

◆ g_hostent_addr

struct in_addr g_hostent_addr
static

◆ g_hostent_addr_list

char* g_hostent_addr_list[] = { NULL, NULL }
static

◆ g_hostent_aliases

char* g_hostent_aliases[] = { NULL }
static

◆ g_hostent_name

char g_hostent_name[256]
static

◆ g_service

struct servent g_service
static

◆ g_service_aliases

char* g_service_aliases[] = { NULL }
static

◆ h_errno

int h_errno