summaryrefslogtreecommitdiff
path: root/userland/libc/include
diff options
context:
space:
mode:
Diffstat (limited to 'userland/libc/include')
-rw-r--r--userland/libc/include/arpa/inet.h0
-rw-r--r--userland/libc/include/assert.h10
-rw-r--r--userland/libc/include/byteswap.h0
-rw-r--r--userland/libc/include/ctype.h14
-rw-r--r--userland/libc/include/dirent.h28
-rw-r--r--userland/libc/include/endian.h2
-rw-r--r--userland/libc/include/err.h0
-rw-r--r--userland/libc/include/errno.h87
-rw-r--r--userland/libc/include/fcntl.h12
-rw-r--r--userland/libc/include/fnmatch.h0
-rw-r--r--userland/libc/include/glob.h10
-rw-r--r--userland/libc/include/grp.h0
-rw-r--r--userland/libc/include/input.h9
-rw-r--r--userland/libc/include/inttypes.h19
-rw-r--r--userland/libc/include/langinfo.h0
-rw-r--r--userland/libc/include/libgen.h6
-rw-r--r--userland/libc/include/limits.h4
-rw-r--r--userland/libc/include/locale.h0
-rw-r--r--userland/libc/include/math.h0
-rw-r--r--userland/libc/include/net/if.h0
-rw-r--r--userland/libc/include/netdb.h0
-rw-r--r--userland/libc/include/netinet/in.h0
-rw-r--r--userland/libc/include/netinet/tcp.h0
-rw-r--r--userland/libc/include/paths.h0
-rw-r--r--userland/libc/include/poll.h17
-rw-r--r--userland/libc/include/pty.h6
-rw-r--r--userland/libc/include/pwd.h0
-rw-r--r--userland/libc/include/regex.h0
-rw-r--r--userland/libc/include/sched.h0
-rw-r--r--userland/libc/include/setjmp.h14
-rw-r--r--userland/libc/include/signal.h9
-rw-r--r--userland/libc/include/socket.h41
-rw-r--r--userland/libc/include/stdio.h116
-rw-r--r--userland/libc/include/stdlib.h32
-rw-r--r--userland/libc/include/string.h29
-rw-r--r--userland/libc/include/strings.h0
-rw-r--r--userland/libc/include/sys/ioctl.h10
-rw-r--r--userland/libc/include/sys/mman.h15
-rw-r--r--userland/libc/include/sys/mount.h0
-rw-r--r--userland/libc/include/sys/resource.h0
-rw-r--r--userland/libc/include/sys/socket.h0
-rw-r--r--userland/libc/include/sys/stat.h31
-rw-r--r--userland/libc/include/sys/statvfs.h0
-rw-r--r--userland/libc/include/sys/syscall.h0
-rw-r--r--userland/libc/include/sys/time.h41
-rw-r--r--userland/libc/include/sys/times.h0
-rw-r--r--userland/libc/include/sys/types.h28
-rw-r--r--userland/libc/include/sys/ucontext.h0
-rw-r--r--userland/libc/include/sys/un.h0
-rw-r--r--userland/libc/include/sys/utsname.h0
-rw-r--r--userland/libc/include/sys/wait.h0
-rw-r--r--userland/libc/include/syscall.h150
-rw-r--r--userland/libc/include/syslog.h0
-rw-r--r--userland/libc/include/termios.h0
-rw-r--r--userland/libc/include/time.h35
-rw-r--r--userland/libc/include/ubsan.h79
-rw-r--r--userland/libc/include/unistd.h24
-rw-r--r--userland/libc/include/utime.h0
-rw-r--r--userland/libc/include/wchar.h0
-rw-r--r--userland/libc/include/wctype.h0
60 files changed, 878 insertions, 0 deletions
diff --git a/userland/libc/include/arpa/inet.h b/userland/libc/include/arpa/inet.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/userland/libc/include/arpa/inet.h
diff --git a/userland/libc/include/assert.h b/userland/libc/include/assert.h
new file mode 100644
index 0000000..a009e5f
--- /dev/null
+++ b/userland/libc/include/assert.h
@@ -0,0 +1,10 @@
+#ifndef ASSERT_H
+#define ASSERT_H
+
+#define assert(expr) \
+ { \
+ if (!(expr)) \
+ aFailed(__FILE__, __LINE__); \
+ }
+void aFailed(char *f, int l);
+#endif
diff --git a/userland/libc/include/byteswap.h b/userland/libc/include/byteswap.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/userland/libc/include/byteswap.h
diff --git a/userland/libc/include/ctype.h b/userland/libc/include/ctype.h
new file mode 100644
index 0000000..7c8c311
--- /dev/null
+++ b/userland/libc/include/ctype.h
@@ -0,0 +1,14 @@
+#ifndef CTYPE_H
+#define CTYPE_H
+
+int isspace(int c);
+int isascii(int c);
+int toupper(int c);
+int tolower(int c);
+int isdigit(int c);
+int isalpha(int c);
+int isxdigit(int c);
+int ispunct(int c);
+int isalnum(int c);
+int isprint(int c);
+#endif
diff --git a/userland/libc/include/dirent.h b/userland/libc/include/dirent.h
new file mode 100644
index 0000000..f190a7c
--- /dev/null
+++ b/userland/libc/include/dirent.h
@@ -0,0 +1,28 @@
+#ifndef DIRENT_H
+#define DIRENT_H
+#include <fcntl.h>
+#include <limits.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+struct dirent {
+ ino_t d_ino; // File serial number.
+ char d_name[PATH_MAX]; // Filename string of entry.
+};
+
+typedef struct {
+ int fd;
+ struct dirent internal_direntry;
+ int dir_num;
+} DIR;
+
+DIR *opendir(const char *dirname);
+struct dirent *readdir(DIR *dir);
+int closedir(DIR *dirp);
+int alphasort(const struct dirent **d1, const struct dirent **d2);
+int scandir(const char *dir, struct dirent ***namelist,
+ int (*sel)(const struct dirent *),
+ int (*compar)(const struct dirent **, const struct dirent **));
+#endif
diff --git a/userland/libc/include/endian.h b/userland/libc/include/endian.h
new file mode 100644
index 0000000..f265a67
--- /dev/null
+++ b/userland/libc/include/endian.h
@@ -0,0 +1,2 @@
+#define LITTLE_ENDIAN 0
+#define BYTE_ORDER LITTLE_ENDIAN
diff --git a/userland/libc/include/err.h b/userland/libc/include/err.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/userland/libc/include/err.h
diff --git a/userland/libc/include/errno.h b/userland/libc/include/errno.h
new file mode 100644
index 0000000..ec9a25e
--- /dev/null
+++ b/userland/libc/include/errno.h
@@ -0,0 +1,87 @@
+#ifndef ERRNO_H
+#define ERRNO_H
+// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html
+#define E2BIG 1 // Argument list too long.
+#define EACCES 2 // Permission denied.
+#define EADDRINUSE 3 // Address in use.
+#define EADDRNOTAVAIL 4 // Address not available.
+#define EAFNOSUPPORT 5 // Address family not supported.
+#define EAGAIN 6 // Resource unavailable, try again.
+#define EALREADY 7 // Connection already in progress.
+#define EBADF 8 // Bad file descriptor.
+#define EBADMSG 9 // Bad message.
+#define EBUSY 10 // Device or resource busy.
+#define ECANCELED 11 // Operation canceled.
+#define ECHILD 12 // No child processes.
+#define ECONNABORTED 13 // Connection aborted.
+#define ECONNREFUSED 14 // Connection refused.
+#define ECONNRESET 15 // Connection reset.
+#define EDEADLK 16 // Resource deadlock would occur.
+#define EDESTADDRREQ 17 // Destination address required.
+#define EDOM 18 // Mathematics argument out of domain of function.
+#define EDQUOT 19 // Reserved.
+#define EEXIST 20 // File exists.
+#define EFAULT 21 // Bad address.
+#define EFBIG 22 // File too large.
+#define EHOSTUNREACH 23 // Host is unreachable.
+#define EIDRM 24 // Identifier removed.
+#define EILSEQ 25 // Illegal byte sequence.
+#define EINPROGRESS 26 // Operation in progress.
+#define EINTR 27 // Interrupted function.
+#define EINVAL 28 // Invalid argument.
+#define EIO 29 // I/O error.
+#define EISCONN 30 // Socket is connected.
+#define EISDIR 31 // Is a directory.
+#define ELOOP 32 // Too many levels of symbolic links.
+#define EMFILE 33 // File descriptor value too large.
+#define EMLINK 34 // Too many links.
+#define EMSGSIZE 35 // Message too large.
+#define EMULTIHOP 36 // Reserved.
+#define ENAMETOOLONG 37 // Filename too long.
+#define ENETDOWN 38 // Network is down.
+#define ENETRESET 39 // Connection aborted by network.
+#define ENETUNREACH 40 // Network unreachable.
+#define ENFILE 41 // Too many files open in system.
+#define ENOBUFS 42 // No buffer space available.
+#define ENODATA 43 // No message is available on the STREAM head read queue.
+#define ENODEV 44 // No such device.
+#define ENOENT 45 // No such file or directory.
+#define ENOEXEC 46 // Executable file format error.
+#define ENOLCK 47 // No locks available.
+#define ENOLINK 48 // Reserved.
+#define ENOMEM 49 // Not enough space.
+#define ENOMSG 50 // No message of the desired type.
+#define ENOPROTOOPT 51 // Protocol not available.
+#define ENOSPC 52 // No space left on device.
+#define ENOSR 53 // No STREAM resources.
+#define ENOSTR 54 // Not a STREAM.
+#define ENOSYS 55 // Functionality not supported.
+#define ENOTCONN 56 // The socket is not connected.
+#define ENOTDIR 57 // Not a directory or a symbolic link to a directory.
+#define ENOTEMPTY 58 // Directory not empty.
+#define ENOTRECOVERABLE 59 // State not recoverable.
+#define ENOTSOCK 60 // Not a socket.
+#define ENOTSUP 61 // Not supported (may be the same value as.
+#define ENOTTY 62 // Inappropriate I/O control operation.
+#define ENXIO 63 // No such device or address.
+#define EOPNOTSUPP ENOTSUP // Operation not supported on socket.
+#define EOVERFLOW 65 // Value too large to be stored in data type.
+#define EOWNERDEAD 66 // Previous owner died.
+#define EPERM 67 // Operation not permitted.
+#define EPIPE 68 // Broken pipe.
+#define EPROTO 69 // Protocol error.
+#define EPROTONOSUPPORT 70 // Protocol not supported.
+#define EPROTOTYPE 71 // Protocol wrong type for socket.
+#define ERANGE 72 // Result too large.
+#define EROFS 73 // Read-only file system.
+#define ESPIPE 74 // Invalid seek.
+#define ESRCH 75 // No such process.
+#define ESTALE 76 // Reserved.
+#define ETIME 77 // Stream ioctl() timeout.
+#define ETIMEDOUT 78 // Connection timed out.
+#define ETXTBSY 79 // Text file busy.
+#define EWOULDBLOCK EAGAIN // Operation would block.
+#define EXDEV 81 // Cross-device link.
+
+extern int errno;
+#endif
diff --git a/userland/libc/include/fcntl.h b/userland/libc/include/fcntl.h
new file mode 100644
index 0000000..7f0906d
--- /dev/null
+++ b/userland/libc/include/fcntl.h
@@ -0,0 +1,12 @@
+// FIXME: Is there some standard value for this?
+#define O_NONBLOCK (1 << 0)
+#define O_READ (1 << 1)
+#define O_WRITE (1 << 2)
+#define O_CREAT (1 << 3)
+#define O_TRUNC (1 << 4)
+
+#define O_RDONLY O_READ
+#define O_WRONLY O_WRITE
+#define O_RDWR (O_WRITE | O_READ)
+
+int open(const char *file, int flags, int mode);
diff --git a/userland/libc/include/fnmatch.h b/userland/libc/include/fnmatch.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/userland/libc/include/fnmatch.h
diff --git a/userland/libc/include/glob.h b/userland/libc/include/glob.h
new file mode 100644
index 0000000..f9e9c57
--- /dev/null
+++ b/userland/libc/include/glob.h
@@ -0,0 +1,10 @@
+#ifndef GLOB_H
+#define GLOB_H
+#include <stddef.h>
+
+typedef struct {
+ size_t gl_pathc; // Count of paths matched by pattern.
+ char **gl_pathv; // Pointer to a list of matched pathnames
+ size_t gl_offs; // Slots to reserve at the beginning of gl_pathv.
+} glob_t;
+#endif
diff --git a/userland/libc/include/grp.h b/userland/libc/include/grp.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/userland/libc/include/grp.h
diff --git a/userland/libc/include/input.h b/userland/libc/include/input.h
new file mode 100644
index 0000000..a6602f5
--- /dev/null
+++ b/userland/libc/include/input.h
@@ -0,0 +1,9 @@
+#ifndef INPUT_H
+#define INPUT_H
+#include <stdint.h>
+
+struct input_event {
+ uint16_t key;
+ uint8_t status;
+};
+#endif
diff --git a/userland/libc/include/inttypes.h b/userland/libc/include/inttypes.h
new file mode 100644
index 0000000..adde7c8
--- /dev/null
+++ b/userland/libc/include/inttypes.h
@@ -0,0 +1,19 @@
+#include <stdint.h>
+
+// FIXME: These are not correct
+#define PRId8 "d"
+#define PRId16 "d"
+#define PRId32 "d"
+#define PRId64 "d"
+#define PRIu8 "d"
+#define PRIu16 "d"
+#define PRIu32 "d"
+#define PRIu64 "d"
+#define PRIx8 "x"
+#define PRIx16 "x"
+#define PRIx32 "x"
+#define PRIx64 "x"
+#define PRIX8 "x"
+#define PRIX16 "x"
+#define PRIX32 "x"
+#define PRIX64 "x"
diff --git a/userland/libc/include/langinfo.h b/userland/libc/include/langinfo.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/userland/libc/include/langinfo.h
diff --git a/userland/libc/include/libgen.h b/userland/libc/include/libgen.h
new file mode 100644
index 0000000..16dc3ed
--- /dev/null
+++ b/userland/libc/include/libgen.h
@@ -0,0 +1,6 @@
+#ifndef LIBGEN_H
+#define LIBGEN_H
+
+char *basename(char *path);
+char *dirname(char *path);
+#endif
diff --git a/userland/libc/include/limits.h b/userland/libc/include/limits.h
new file mode 100644
index 0000000..6d0abe0
--- /dev/null
+++ b/userland/libc/include/limits.h
@@ -0,0 +1,4 @@
+#define PATH_MAX 256
+#define FILENAME_MAX PATH_MAX
+#define ULONG_MAX 0xFFFFFFFFUL
+#define LONG_MAX 2147483647
diff --git a/userland/libc/include/locale.h b/userland/libc/include/locale.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/userland/libc/include/locale.h
diff --git a/userland/libc/include/math.h b/userland/libc/include/math.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/userland/libc/include/math.h
diff --git a/userland/libc/include/net/if.h b/userland/libc/include/net/if.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/userland/libc/include/net/if.h
diff --git a/userland/libc/include/netdb.h b/userland/libc/include/netdb.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/userland/libc/include/netdb.h
diff --git a/userland/libc/include/netinet/in.h b/userland/libc/include/netinet/in.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/userland/libc/include/netinet/in.h
diff --git a/userland/libc/include/netinet/tcp.h b/userland/libc/include/netinet/tcp.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/userland/libc/include/netinet/tcp.h
diff --git a/userland/libc/include/paths.h b/userland/libc/include/paths.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/userland/libc/include/paths.h
diff --git a/userland/libc/include/poll.h b/userland/libc/include/poll.h
new file mode 100644
index 0000000..e3c6d8d
--- /dev/null
+++ b/userland/libc/include/poll.h
@@ -0,0 +1,17 @@
+#ifndef POLL_H
+#define POLL_H
+#include <stddef.h>
+
+#define POLLIN (1 << 0)
+#define POLLPRI (1 << 1)
+#define POLLOUT (1 << 2)
+#define POLLHUP (1 << 3)
+
+struct pollfd {
+ int fd;
+ short events;
+ short revents;
+};
+
+int poll(struct pollfd *fds, size_t nfds, int timeout);
+#endif
diff --git a/userland/libc/include/pty.h b/userland/libc/include/pty.h
new file mode 100644
index 0000000..b8ce978
--- /dev/null
+++ b/userland/libc/include/pty.h
@@ -0,0 +1,6 @@
+#ifndef PTY_H
+#define PTY_H
+int openpty(int *amaster, int *aslave, char *name,
+ /*const struct termios*/ void *termp,
+ /*const struct winsize*/ void *winp);
+#endif
diff --git a/userland/libc/include/pwd.h b/userland/libc/include/pwd.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/userland/libc/include/pwd.h
diff --git a/userland/libc/include/regex.h b/userland/libc/include/regex.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/userland/libc/include/regex.h
diff --git a/userland/libc/include/sched.h b/userland/libc/include/sched.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/userland/libc/include/sched.h
diff --git a/userland/libc/include/setjmp.h b/userland/libc/include/setjmp.h
new file mode 100644
index 0000000..ea15cf3
--- /dev/null
+++ b/userland/libc/include/setjmp.h
@@ -0,0 +1,14 @@
+#ifndef SETJMP_H
+#define SETJMP_H
+typedef unsigned long __jmp_buf[6];
+typedef struct __jmp_buf_tag {
+ __jmp_buf __jb;
+ unsigned long __fl;
+ unsigned long __ss[128/sizeof(long)];
+} jmp_buf[1];
+typedef jmp_buf sigjmp_buf;
+
+void _longjmp(jmp_buf, int);
+void longjmp(jmp_buf, int);
+void siglongjmp(sigjmp_buf, int);
+#endif
diff --git a/userland/libc/include/signal.h b/userland/libc/include/signal.h
new file mode 100644
index 0000000..2e6566d
--- /dev/null
+++ b/userland/libc/include/signal.h
@@ -0,0 +1,9 @@
+#ifndef SIGNAL_H
+#define SIGNAL_H
+#define SIGHUP 0
+#define SIGINT 1
+#define SIGWINCH 2
+#define SIGQUIT 3
+#define SIG_IGN 4
+typedef int sig_atomic_t;
+#endif // SIGNAL_H
diff --git a/userland/libc/include/socket.h b/userland/libc/include/socket.h
new file mode 100644
index 0000000..5e86b45
--- /dev/null
+++ b/userland/libc/include/socket.h
@@ -0,0 +1,41 @@
+#include <stddef.h>
+#include <stdint.h>
+
+#define AF_UNIX 0
+#define AF_LOCAL AF_UNIX
+
+#define INADDR_ANY 0
+
+typedef struct {
+ int domain;
+ int type;
+ int protocol;
+
+ // UNIX socket
+ char *path;
+ int incoming_fd;
+} SOCKET;
+
+typedef struct {
+ char *path;
+ SOCKET *s;
+} OPEN_UNIX_SOCKET;
+
+typedef uint32_t in_addr_t;
+typedef uint16_t in_port_t;
+typedef unsigned int sa_family_t;
+typedef uint32_t socklen_t;
+
+struct sockaddr {
+ sa_family_t sa_family; /* Address family */
+ char *sa_data; /* Socket address */
+};
+
+struct sockaddr_un {
+ sa_family_t sun_family; /* Address family */
+ char *sun_path; /* Socket pathname */
+};
+
+int socket(int domain, int type, int protocol);
+int accept(int socket, struct sockaddr *address, socklen_t *address_len);
+int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
diff --git a/userland/libc/include/stdio.h b/userland/libc/include/stdio.h
new file mode 100644
index 0000000..014e2ac
--- /dev/null
+++ b/userland/libc/include/stdio.h
@@ -0,0 +1,116 @@
+#ifndef STDIO_H
+#define STDIO_H
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdint.h>
+
+// FIXME: Most of these should probably not be here. But I am too lazy
+// to fix it right now. This is futures mees problem to deal wth.
+
+#define EOF (-1)
+
+#define SEEK_SET 0
+#define SEEK_CUR 1
+#define SEEK_END 2
+
+#define BUFSIZ 4096
+
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/setvbuf.html
+#define _IOFBF 1 // shall cause input/output to be fully buffered.
+#define _IOLBF 2 // shall cause input/output to be line buffered.
+#define _IONBF 3 // shall cause input/output to be unbuffered.
+
+typedef long fpos_t;
+
+typedef struct __IO_FILE FILE;
+struct __IO_FILE {
+ size_t (*write)(FILE *, const unsigned char *, size_t);
+ size_t (*read)(FILE *, unsigned char *, size_t);
+ int (*seek)(FILE *, long, int);
+ long offset_in_file;
+ int buffered_char;
+ int has_buffered_char;
+ int fd;
+ uint8_t is_eof;
+ uint8_t has_error;
+ uint64_t file_size;
+ void *cookie;
+};
+
+size_t write_fd(FILE *f, const unsigned char *s, size_t l);
+size_t read_fd(FILE *f, unsigned char *s, size_t l);
+int seek_fd(FILE *stream, long offset, int whence);
+
+typedef struct {
+ int fd;
+} FILE_FD_COOKIE;
+
+extern FILE __stdin_FILE;
+extern FILE __stdout_FILE;
+extern FILE __stderr_FILE;
+
+#define stdin (&__stdin_FILE)
+#define stdout (&__stdout_FILE)
+//#define stderr (&__stderr_FILE)
+#define stderr (&__stdout_FILE)
+
+typedef int mode_t;
+
+void perror(const char *s);
+
+int putchar(int c);
+int puts(const char *s);
+int brk(void *addr);
+void *sbrk(intptr_t increment);
+int write(int fd, const char *buf, size_t count);
+int pwrite(int fd, const char *buf, size_t count, size_t offset);
+int printf(const char *format, ...);
+int pread(int fd, void *buf, size_t count, size_t offset);
+int read(int fd, void *buf, size_t count);
+int fork(void);
+int memcmp(const void *s1, const void *s2, size_t n);
+int wait(int *stat_loc);
+void exit(int status);
+void *memcpy(void *dest, const void *src, uint32_t n);
+int shm_open(const char *name, int oflag, mode_t mode);
+int dprintf(int fd, const char *format, ...);
+int vdprintf(int fd, const char *format, va_list ap);
+int vprintf(const char *format, va_list ap);
+int snprintf(char *str, size_t size, const char *format, ...);
+int vsnprintf(char *str, size_t size, const char *format, va_list ap);
+int vfprintf(FILE *f, const char *fmt, va_list ap);
+int fgetc(FILE *stream);
+int getchar(void);
+#define getc(_a) fgetc(_a)
+size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
+size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
+FILE *fopen(const char *pathname, const char *mode);
+int fclose(FILE *stream);
+int fseek(FILE *stream, long offset, int whence);
+int fprintf(FILE *f, const char *fmt, ...);
+int atoi(const char *str);
+long strtol(const char *nptr, char **endptr, int base);
+char *strchr(const char *s, int c);
+char *strcat(char *s1, const char *s2);
+char *fgets(char *s, int n, FILE *stream);
+FILE *tmpfile(void);
+int feof(FILE *stream);
+int fscanf(FILE *stream, const char *format, ...);
+int ungetc(int c, FILE *stream);
+long ftell(FILE *stream);
+int fputc(int c, FILE *stream);
+int remove(const char *path);
+int ferror(FILE *stream);
+int fputs(const char *s, FILE *stream);
+int fflush(FILE *stream);
+int setvbuf(FILE *stream, char *restrict buf, int type, size_t size);
+int fileno(FILE *stream);
+int putc(int c, FILE *stream);
+int vsprintf(char *str, const char *format, va_list ap);
+int sprintf(char *str, const char *format, ...);
+FILE *open_memstream(char **bufp, size_t *sizep);
+int fsetpos(FILE *stream, const fpos_t *pos);
+int fgetpos(FILE *restrict stream, fpos_t *restrict pos);
+char *tmpnam(char *s);
+int rename(const char *old, const char *new);
+#endif
diff --git a/userland/libc/include/stdlib.h b/userland/libc/include/stdlib.h
new file mode 100644
index 0000000..c88f2f3
--- /dev/null
+++ b/userland/libc/include/stdlib.h
@@ -0,0 +1,32 @@
+#ifndef STDLIB_H
+#define STDLIB_H
+#include <limits.h>
+#include <stddef.h>
+#define RAND_MAX (UINT32_MAX)
+#define EXIT_SUCCESS 0
+#define EXIT_FAILURE 1
+
+typedef size_t size_t; // only for 32 bit
+
+void *malloc(size_t s);
+void *calloc(size_t nelem, size_t elsize);
+void *realloc(void *ptr, size_t size);
+void free(void *p);
+char *getenv(const char *name);
+int rand(void);
+void srand(unsigned int seed);
+unsigned long strtoul(const char *restrict str, char **restrict endptr,
+ int base);
+long strtol(const char *str, char **restrict endptr, int base);
+void abort(void);
+int abs(int i);
+void qsort(void *base, size_t nel, size_t width,
+ int (*compar)(const void *, const void *));
+int atexit(void (*func)(void));
+int mkstemp(char *template);
+long double strtold(const char *restrict nptr, char **restrict endptr);
+int system(const char *command);
+double atof(const char *str);
+double strtod(const char *restrict nptr, char **restrict endptr);
+int atoi(const char *str);
+#endif
diff --git a/userland/libc/include/string.h b/userland/libc/include/string.h
new file mode 100644
index 0000000..0c61efa
--- /dev/null
+++ b/userland/libc/include/string.h
@@ -0,0 +1,29 @@
+#ifndef STRING_H
+#define STRING_H
+#include <stddef.h>
+#include <stdint.h>
+
+char *strerror(int errnum);
+void *memset(void *s, int c, size_t n);
+void *memcpy(void *dest, const void *src, uint32_t n);
+int strcmp(const char *s1, const char *s2);
+char *strcpy(char *dest, const char *src);
+size_t strlen(const char *s);
+size_t strnlen(const char *s, size_t maxlen);
+int sscanf(const char *s, const char *restrict format, ...);
+char *strrchr(const char *s, int c);
+int strncmp(const char *s1, const char *s2, size_t n);
+char *strncpy(char *s1, const char *s2, size_t n);
+size_t *strlcpy(char *s1, const char *s2, size_t n);
+size_t strcspn(const char *s1, const char *s2);
+char *strpbrk(const char *s1, const char *s2);
+size_t strspn(const char *s1, const char *s2);
+void *memmove(void *s1, const void *s2, size_t n);
+char *strdup(const char *s);
+char *strndup(const char *s, size_t size);
+char *strstr(const char *s1, const char *s2);
+int strncasecmp(const char *s1, const char *s2, size_t n);
+int strcasecmp(const char *s1, const char *s2);
+char *strtok(char *restrict s, const char *restrict sep);
+char *strcat(char *restrict s1, const char *restrict s2);
+#endif
diff --git a/userland/libc/include/strings.h b/userland/libc/include/strings.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/userland/libc/include/strings.h
diff --git a/userland/libc/include/sys/ioctl.h b/userland/libc/include/sys/ioctl.h
new file mode 100644
index 0000000..a373a4b
--- /dev/null
+++ b/userland/libc/include/sys/ioctl.h
@@ -0,0 +1,10 @@
+#ifndef IOCTL_H
+#define IOCTL_H
+#define TIOCGWINSZ 0
+struct winsize {
+ unsigned short ws_row;
+ unsigned short ws_col;
+ unsigned short ws_xpixel;
+ unsigned short ws_ypixel;
+};
+#endif // IOCTL_H
diff --git a/userland/libc/include/sys/mman.h b/userland/libc/include/sys/mman.h
new file mode 100644
index 0000000..7dfe29a
--- /dev/null
+++ b/userland/libc/include/sys/mman.h
@@ -0,0 +1,15 @@
+#ifndef MMAP_H
+#define MMAP_H
+#include <stdint.h>
+#include <stddef.h>
+
+#define PROT_READ (1 << 0)
+#define PROT_WRITE (1 << 1)
+
+#define MAP_PRIVATE (1 << 0)
+#define MAP_ANONYMOUS (1<< 1)
+#define MAP_SHARED (1<< 2)
+
+void *mmap(void *addr, size_t length, int prot, int flags, int fd,
+ size_t offset);
+#endif
diff --git a/userland/libc/include/sys/mount.h b/userland/libc/include/sys/mount.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/userland/libc/include/sys/mount.h
diff --git a/userland/libc/include/sys/resource.h b/userland/libc/include/sys/resource.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/userland/libc/include/sys/resource.h
diff --git a/userland/libc/include/sys/socket.h b/userland/libc/include/sys/socket.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/userland/libc/include/sys/socket.h
diff --git a/userland/libc/include/sys/stat.h b/userland/libc/include/sys/stat.h
new file mode 100644
index 0000000..178d014
--- /dev/null
+++ b/userland/libc/include/sys/stat.h
@@ -0,0 +1,31 @@
+#ifndef STAT_H
+#define STAT_H
+#include <sys/types.h>
+#include <time.h>
+
+struct stat {
+ dev_t st_dev; // Device ID of device containing file.
+ ino_t st_ino; // File serial number.
+ mode_t st_mode; // Mode of file (see below).
+ nlink_t st_nlink; // Number of hard links to the file.
+ uid_t st_uid; // User ID of file.
+ gid_t st_gid; // Group ID of file.
+ dev_t st_rdev; // Device ID (if file is character or block special).
+ off_t st_size; // For regular files, the file size in bytes.
+ // For symbolic links, the length in bytes of the
+ // pathname contained in the symbolic link.
+ // For a shared memory object, the length in bytes.
+ // For a typed memory object, the length in bytes.
+ // For other file types, the use of this field is
+ // unspecified.
+ struct timespec st_atime; // Last data access timestamp.
+ struct timespec st_mtime; // Last data modification timestamp.
+ struct timespec st_ctime; // Last file status change timestamp.
+ blksize_t st_blksize; // A file system-specific preferred I/O block size
+ // for this object. In some file system types, this
+ // may vary from file to file.
+ blkcnt_t st_blocks; // Number of blocks allocated for this object.
+};
+int stat(const char *path, struct stat *buf);
+int mkdir(const char *path, mode_t mode);
+#endif
diff --git a/userland/libc/include/sys/statvfs.h b/userland/libc/include/sys/statvfs.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/userland/libc/include/sys/statvfs.h
diff --git a/userland/libc/include/sys/syscall.h b/userland/libc/include/sys/syscall.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/userland/libc/include/sys/syscall.h
diff --git a/userland/libc/include/sys/time.h b/userland/libc/include/sys/time.h
new file mode 100644
index 0000000..a675d9e
--- /dev/null
+++ b/userland/libc/include/sys/time.h
@@ -0,0 +1,41 @@
+#ifndef TIME_H
+#define TIME_H
+#include <stddef.h>
+#include <sys/types.h>
+#include <time.h>
+
+#define CLOCK_REALTIME 0
+
+struct tm {
+ int tm_sec;
+ int tm_min;
+ int tm_hour;
+ int tm_mday;
+ int tm_mon;
+ int tm_year;
+ int tm_wday;
+ int tm_yday;
+ int tm_isdst;
+ long __tm_gmtoff;
+ const char *__tm_zone;
+};
+
+typedef int clockid_t;
+struct timespec {
+ time_t tv_sec; // Seconds.
+ long tv_nsec; // Nanoseconds.
+};
+
+struct timeval {
+ time_t tv_sec;
+ suseconds_t tv_usec;
+};
+
+time_t time(time_t *tloc);
+int clock_gettime(clockid_t clock_id, struct timespec *tp);
+struct tm *localtime(const time_t *timer);
+struct tm *gmtime(const time_t *timer);
+size_t strftime(char *restrict s, size_t maxsize, const char *restrict format,
+ const struct tm *restrict timeptr);
+int gettimeofday(struct timeval *tp, void *tzp);
+#endif
diff --git a/userland/libc/include/sys/times.h b/userland/libc/include/sys/times.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/userland/libc/include/sys/times.h
diff --git a/userland/libc/include/sys/types.h b/userland/libc/include/sys/types.h
new file mode 100644
index 0000000..48c57f9
--- /dev/null
+++ b/userland/libc/include/sys/types.h
@@ -0,0 +1,28 @@
+#ifndef TYPES_H
+#define TYPES_H
+typedef unsigned int ino_t;
+
+typedef int mode_t;
+
+typedef int nlink_t;
+typedef int uid_t;
+typedef int gid_t;
+typedef int id_t;
+
+typedef int blkcnt_t;
+typedef int off_t;
+
+typedef int dev_t;
+typedef unsigned int fsblkcnt_t;
+typedef unsigned int fsfilcnt_t;
+typedef unsigned int ino_t;
+//typedef unsigned int size_t;
+
+typedef int blksize_t;
+typedef int pid_t;
+typedef int ssize_t;
+
+//typedef int clock_t;
+typedef int time_t;
+typedef unsigned int suseconds_t;
+#endif
diff --git a/userland/libc/include/sys/ucontext.h b/userland/libc/include/sys/ucontext.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/userland/libc/include/sys/ucontext.h
diff --git a/userland/libc/include/sys/un.h b/userland/libc/include/sys/un.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/userland/libc/include/sys/un.h
diff --git a/userland/libc/include/sys/utsname.h b/userland/libc/include/sys/utsname.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/userland/libc/include/sys/utsname.h
diff --git a/userland/libc/include/sys/wait.h b/userland/libc/include/sys/wait.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/userland/libc/include/sys/wait.h
diff --git a/userland/libc/include/syscall.h b/userland/libc/include/syscall.h
new file mode 100644
index 0000000..caa7779
--- /dev/null
+++ b/userland/libc/include/syscall.h
@@ -0,0 +1,150 @@
+#ifndef SYSCALL_H
+#define SYSCALL_H
+#include "socket.h"
+#include <stddef.h>
+#include <stdint.h>
+#include <sys/types.h>
+
+#define SYS_OPEN 0
+#define SYS_READ 1
+#define SYS_WRITE 2
+#define SYS_PREAD 3
+#define SYS_PWRITE 4
+#define SYS_FORK 5
+#define SYS_EXEC 6
+#define SYS_GETPID 7
+#define SYS_EXIT 8
+#define SYS_WAIT 9
+#define SYS_BRK 10
+#define SYS_SBRK 11
+#define SYS_PIPE 12
+#define SYS_DUP2 13
+#define SYS_CLOSE 14
+#define SYS_OPENPTY 15
+#define SYS_POLL 16
+#define SYS_MMAP 17
+#define SYS_ACCEPT 18
+#define SYS_BIND 19
+#define SYS_SOCKET 20
+#define SYS_SHM_OPEN 21
+#define SYS_FTRUNCATE 22
+#define SYS_STAT 23
+#define SYS_MSLEEP 24
+#define SYS_UPTIME 25
+
+int syscall(uint32_t eax, uint32_t ebx, uint32_t ecx, uint32_t edx,
+ uint32_t esi, uint32_t edi);
+int s_syscall(int sys);
+
+extern int errno;
+#define RC_ERRNO(_rc) \
+ { \
+ int c = _rc; \
+ if (c < 0) { \
+ errno = -(c); \
+ return -1; \
+ } \
+ return c; \
+ }
+
+typedef int mode_t;
+
+typedef struct SYS_OPEN_PARAMS {
+ const char *file;
+ int flags;
+ int mode;
+} __attribute__((packed)) SYS_OPEN_PARAMS;
+
+typedef struct SYS_PREAD_PARAMS {
+ int fd;
+ void *buf;
+ size_t count;
+ size_t offset;
+} __attribute__((packed)) SYS_PREAD_PARAMS;
+
+typedef struct SYS_READ_PARAMS {
+ int fd;
+ void *buf;
+ size_t count;
+} __attribute__((packed)) SYS_READ_PARAMS;
+
+typedef struct SYS_PWRITE_PARAMS {
+ int fd;
+ const void *buf;
+ size_t count;
+ size_t offset;
+} __attribute__((packed)) SYS_PWRITE_PARAMS;
+
+typedef struct SYS_WRITE_PARAMS {
+ int fd;
+ const void *buf;
+ size_t count;
+} __attribute__((packed)) SYS_WRITE_PARAMS;
+
+typedef struct SYS_EXEC_PARAMS {
+ const char *path;
+ char **argv;
+} __attribute__((packed)) SYS_EXEC_PARAMS;
+
+typedef struct SYS_DUP2_PARAMS {
+ int org_fd;
+ int new_fd;
+} __attribute__((packed)) SYS_DUP2_PARAMS;
+
+typedef struct SYS_OPENPTY_PARAMS {
+ int *amaster;
+ int *aslave;
+ char *name;
+ /*const struct termios*/ void *termp;
+ /*const struct winsize*/ void *winp;
+} __attribute__((packed)) SYS_OPENPTY_PARAMS;
+
+typedef struct SYS_POLL_PARAMS {
+ struct pollfd *fds;
+ size_t nfds;
+ int timeout;
+} __attribute__((packed)) SYS_POLL_PARAMS;
+
+typedef struct SYS_MMAP_PARAMS {
+ void *addr;
+ size_t length;
+ int prot;
+ int flags;
+ int fd;
+ size_t offset;
+} __attribute__((packed)) SYS_MMAP_PARAMS;
+
+typedef struct SYS_SOCKET_PARAMS {
+ int domain;
+ int type;
+ int protocol;
+} __attribute__((packed)) SYS_SOCKET_PARAMS;
+
+typedef struct SYS_BIND_PARAMS {
+ int sockfd;
+ const struct sockaddr *addr;
+ socklen_t addrlen;
+} __attribute__((packed)) SYS_BIND_PARAMS;
+
+typedef struct SYS_ACCEPT_PARAMS {
+ int socket;
+ struct sockaddr *address;
+ socklen_t *address_len;
+} __attribute__((packed)) SYS_ACCEPT_PARAMS;
+
+typedef struct SYS_SHM_OPEN_PARAMS {
+ const char *name;
+ int oflag;
+ mode_t mode;
+} __attribute__((packed)) SYS_SHM_OPEN_PARAMS;
+
+typedef struct SYS_FTRUNCATE_PARAMS {
+ int fildes;
+ size_t length;
+} __attribute__((packed)) SYS_FTRUNCATE_PARAMS;
+
+typedef struct SYS_STAT_PARAMS {
+ const char *pathname;
+ struct stat *statbuf;
+} __attribute__((packed)) SYS_STAT_PARAMS;
+#endif
diff --git a/userland/libc/include/syslog.h b/userland/libc/include/syslog.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/userland/libc/include/syslog.h
diff --git a/userland/libc/include/termios.h b/userland/libc/include/termios.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/userland/libc/include/termios.h
diff --git a/userland/libc/include/time.h b/userland/libc/include/time.h
new file mode 100644
index 0000000..567e9ef
--- /dev/null
+++ b/userland/libc/include/time.h
@@ -0,0 +1,35 @@
+#ifndef TIME_H
+#define TIME_H
+#include <sys/types.h>
+#include <stddef.h>
+
+#define CLOCK_REALTIME 0
+
+struct tm {
+ int tm_sec;
+ int tm_min;
+ int tm_hour;
+ int tm_mday;
+ int tm_mon;
+ int tm_year;
+ int tm_wday;
+ int tm_yday;
+ int tm_isdst;
+ long __tm_gmtoff;
+ const char *__tm_zone;
+};
+
+typedef int clockid_t;
+struct timespec {
+ time_t tv_sec; // Seconds.
+ long tv_nsec; // Nanoseconds.
+};
+
+time_t time(time_t *tloc);
+int clock_gettime(clockid_t clock_id, struct timespec *tp);
+struct tm *localtime(const time_t *timer);
+struct tm *gmtime(const time_t *timer);
+size_t strftime(char *restrict s, size_t maxsize,
+ const char *restrict format, const struct tm *restrict timeptr);
+char *ctime_r(const time_t *clock, char *buf);
+#endif
diff --git a/userland/libc/include/ubsan.h b/userland/libc/include/ubsan.h
new file mode 100644
index 0000000..dac5407
--- /dev/null
+++ b/userland/libc/include/ubsan.h
@@ -0,0 +1,79 @@
+#include <stdint.h>
+
+enum { type_kind_int = 0, type_kind_float = 1, type_unknown = 0xffff };
+
+struct type_descriptor {
+ uint16_t type_kind;
+ uint16_t type_info;
+ char type_name[1];
+};
+
+struct source_location {
+ const char *file_name;
+ union {
+ unsigned long reported;
+ struct {
+ uint32_t line;
+ uint32_t column;
+ };
+ };
+};
+
+struct OverflowData {
+ struct source_location location;
+ struct type_descriptor *type;
+};
+
+struct type_mismatch_data {
+ struct source_location location;
+ struct type_descriptor *type;
+ unsigned long alignment;
+ unsigned char type_check_kind;
+};
+
+struct type_mismatch_data_v1 {
+ struct source_location location;
+ struct type_descriptor *type;
+ unsigned char log_alignment;
+ unsigned char type_check_kind;
+};
+
+struct type_mismatch_data_common {
+ struct source_location *location;
+ struct type_descriptor *type;
+ unsigned long alignment;
+ unsigned char type_check_kind;
+};
+
+struct nonnull_arg_data {
+ struct source_location location;
+ struct source_location attr_location;
+ int arg_index;
+};
+
+struct OutOfBoundsData {
+ struct source_location location;
+ struct type_descriptor *array_type;
+ struct type_descriptor *index_type;
+};
+
+struct ShiftOutOfBoundsData {
+ struct source_location location;
+ struct type_descriptor *lhs_type;
+ struct type_descriptor *rhs_type;
+};
+
+struct unreachable_data {
+ struct source_location location;
+};
+
+struct invalid_value_data {
+ struct source_location location;
+ struct type_descriptor *type;
+};
+
+struct alignment_assumption_data {
+ struct source_location location;
+ struct source_location assumption_location;
+ struct type_descriptor *type;
+};
diff --git a/userland/libc/include/unistd.h b/userland/libc/include/unistd.h
new file mode 100644
index 0000000..e43dc33
--- /dev/null
+++ b/userland/libc/include/unistd.h
@@ -0,0 +1,24 @@
+#ifndef UNISTD_H
+#define UNISTD_H
+#include <stddef.h>
+#include <stdint.h>
+#include <sys/types.h>
+
+#define STDIN_FILENO 0
+
+extern int opterr, optind, optopt;
+extern char *optarg;
+
+int close(int fildes);
+int ftruncate(int fildes, uint64_t length);
+int execv(char *path, char **argv);
+int pipe(int fd[2]);
+int dup2(int org_fd, int new_fd);
+int getopt(int argc, char *const argv[], const char *optstring);
+pid_t getpid(void);
+int unlink(const char *path);
+int execvp(const char *file, char *const argv[]);
+void _exit(int status);
+void msleep(uint32_t ms); // not standard
+uint32_t uptime(void); // not standard
+#endif
diff --git a/userland/libc/include/utime.h b/userland/libc/include/utime.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/userland/libc/include/utime.h
diff --git a/userland/libc/include/wchar.h b/userland/libc/include/wchar.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/userland/libc/include/wchar.h
diff --git a/userland/libc/include/wctype.h b/userland/libc/include/wctype.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/userland/libc/include/wctype.h