aboutsummaryrefslogtreecommitdiff
path: root/lib/mlibc/sysdeps/ironclad
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-03-07 17:28:00 -0500
committerIan Moffett <ian@osmora.org>2024-03-07 17:28:32 -0500
commitbd5969fc876a10b18613302db7087ef3c40f18e1 (patch)
tree7c2b8619afe902abf99570df2873fbdf40a4d1a1 /lib/mlibc/sysdeps/ironclad
parenta95b38b1b92b172e6cc4e8e56a88a30cc65907b0 (diff)
lib: Add mlibc
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'lib/mlibc/sysdeps/ironclad')
-rw-r--r--lib/mlibc/sysdeps/ironclad/crt-x86_64/crt0.S9
-rw-r--r--lib/mlibc/sysdeps/ironclad/crt-x86_64/crti.S11
-rw-r--r--lib/mlibc/sysdeps/ironclad/crt-x86_64/crtn.S9
-rw-r--r--lib/mlibc/sysdeps/ironclad/generic/entry.cpp35
-rw-r--r--lib/mlibc/sysdeps/ironclad/generic/generic.cpp1266
-rw-r--r--lib/mlibc/sysdeps/ironclad/generic/mac.cpp32
-rw-r--r--lib/mlibc/sysdeps/ironclad/generic/mntent.cpp97
-rw-r--r--lib/mlibc/sysdeps/ironclad/generic/mount.cpp20
-rw-r--r--lib/mlibc/sysdeps/ironclad/generic/ptrace.cpp9
-rw-r--r--lib/mlibc/sysdeps/ironclad/generic/pty.cpp41
-rw-r--r--lib/mlibc/sysdeps/ironclad/generic/reboot.cpp9
-rw-r--r--lib/mlibc/sysdeps/ironclad/generic/sched2.cpp20
-rw-r--r--lib/mlibc/sysdeps/ironclad/generic/thread.S9
-rw-r--r--lib/mlibc/sysdeps/ironclad/generic/thread.cpp54
-rw-r--r--lib/mlibc/sysdeps/ironclad/generic/utmpx.cpp76
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/access.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/auxv.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/blkcnt_t.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/blksize_t.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/clockid_t.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/dev_t.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/epoll.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/errno.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/fcntl.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/fsblkcnt_t.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/fsfilcnt_t.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/gid_t.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/in.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/ino_t.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/inotify.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/ioctls.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/limits.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/mode_t.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/mqueue.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/msg.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/nlink_t.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/packet.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/pid_t.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/poll.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/ptrace.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/reboot.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/resource.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/seek-whence.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/shm.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/signal.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/socket.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/socklen_t.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/stat.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/statfs.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/statvfs.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/suseconds_t.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/termios.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/time.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/uid_t.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/utsname.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/vm-flags.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/wait.h1
l---------lib/mlibc/sysdeps/ironclad/include/abi-bits/xattr.h1
-rw-r--r--lib/mlibc/sysdeps/ironclad/include/asm/ioctls.h102
-rw-r--r--lib/mlibc/sysdeps/ironclad/include/linux/fb.h397
-rw-r--r--lib/mlibc/sysdeps/ironclad/include/mntent.h46
-rw-r--r--lib/mlibc/sysdeps/ironclad/include/pty.h16
-rw-r--r--lib/mlibc/sysdeps/ironclad/include/sys/ironclad_devices.h44
-rw-r--r--lib/mlibc/sysdeps/ironclad/include/sys/mac.h46
-rw-r--r--lib/mlibc/sysdeps/ironclad/include/sys/mount.h24
-rw-r--r--lib/mlibc/sysdeps/ironclad/include/sys/ptrace.h23
-rw-r--r--lib/mlibc/sysdeps/ironclad/include/sys/reboot.h16
-rw-r--r--lib/mlibc/sysdeps/ironclad/include/sys/sched2.h24
-rw-r--r--lib/mlibc/sysdeps/ironclad/include/sys/syscall.h187
-rw-r--r--lib/mlibc/sysdeps/ironclad/include/utmpx.h63
-rw-r--r--lib/mlibc/sysdeps/ironclad/meson.build125
71 files changed, 2853 insertions, 0 deletions
diff --git a/lib/mlibc/sysdeps/ironclad/crt-x86_64/crt0.S b/lib/mlibc/sysdeps/ironclad/crt-x86_64/crt0.S
new file mode 100644
index 0000000..18d109e
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/crt-x86_64/crt0.S
@@ -0,0 +1,9 @@
+
+.section .text
+.global _start
+_start:
+ mov $main, %rdi
+ call __mlibc_entry
+
+.section .note.GNU-stack,"",%progbits
+
diff --git a/lib/mlibc/sysdeps/ironclad/crt-x86_64/crti.S b/lib/mlibc/sysdeps/ironclad/crt-x86_64/crti.S
new file mode 100644
index 0000000..911b078
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/crt-x86_64/crti.S
@@ -0,0 +1,11 @@
+.section .init
+.global _init
+_init:
+ push %rax
+
+.section .fini
+.global _fini
+_fini:
+ push %rax
+.section .note.GNU-stack,"",%progbits
+
diff --git a/lib/mlibc/sysdeps/ironclad/crt-x86_64/crtn.S b/lib/mlibc/sysdeps/ironclad/crt-x86_64/crtn.S
new file mode 100644
index 0000000..0187e50
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/crt-x86_64/crtn.S
@@ -0,0 +1,9 @@
+.section .init
+ pop %rax
+ ret
+
+.section .fini
+ pop %rax
+ ret
+.section .note.GNU-stack,"",%progbits
+
diff --git a/lib/mlibc/sysdeps/ironclad/generic/entry.cpp b/lib/mlibc/sysdeps/ironclad/generic/entry.cpp
new file mode 100644
index 0000000..2b8b914
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/generic/entry.cpp
@@ -0,0 +1,35 @@
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <bits/ensure.h>
+#include <mlibc/elf/startup.h>
+
+// defined by the POSIX library
+void __mlibc_initLocale();
+
+extern "C" uintptr_t *__dlapi_entrystack();
+
+extern char **environ;
+static mlibc::exec_stack_data __mlibc_stack_data;
+
+struct LibraryGuard {
+ LibraryGuard();
+};
+
+static LibraryGuard guard;
+
+LibraryGuard::LibraryGuard() {
+ __mlibc_initLocale();
+
+ // Parse the exec() stack.
+ mlibc::parse_exec_stack(__dlapi_entrystack(), &__mlibc_stack_data);
+ mlibc::set_startup_data(__mlibc_stack_data.argc, __mlibc_stack_data.argv,
+ __mlibc_stack_data.envp);
+}
+
+extern "C" void __mlibc_entry(int (*main_fn)(int argc, char *argv[], char *env[])) {
+ // TODO: call __dlapi_enter, otherwise static builds will break (see Linux sysdeps)
+ auto result = main_fn(__mlibc_stack_data.argc, __mlibc_stack_data.argv, environ);
+ exit(result);
+}
+
diff --git a/lib/mlibc/sysdeps/ironclad/generic/generic.cpp b/lib/mlibc/sysdeps/ironclad/generic/generic.cpp
new file mode 100644
index 0000000..3d15365
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/generic/generic.cpp
@@ -0,0 +1,1266 @@
+#include <mlibc-config.h>
+#include <bits/ensure.h>
+#include <mlibc/debug.hpp>
+#include <mlibc/all-sysdeps.hpp>
+#include <errno.h>
+#include <dirent.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <asm/ioctls.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <sys/syscall.h>
+#include <sys/ironclad_devices.h>
+#include <sched.h>
+#include <sys/mman.h>
+#include <unistd.h>
+#include <sys/file.h>
+#include <mlibc/tcb.hpp>
+
+namespace mlibc {
+
+void sys_libc_log(const char *message) {
+ ssize_t unused;
+ char new_line = '\n';
+ sys_write(2, message, strlen(message), &unused);
+ sys_write(2, &new_line, 1, &unused);
+}
+
+void sys_libc_panic() {
+ ssize_t unused;
+ char const *message = "mlibc panicked unrecoverably\n";
+ sys_write(2, message, strlen(message), &unused);
+ sys_exit(1);
+}
+
+void sys_exit(int status) {
+ int ret, errno;
+ SYSCALL1(SYSCALL_EXIT, status);
+ __builtin_unreachable();
+}
+
+int sys_tcb_set(void *pointer) {
+ int ret, errno;
+ SYSCALL2(SYSCALL_ARCH_PRCTL, 1, pointer);
+ return errno;
+}
+
+int sys_thread_getname(void *tcb, char *name, size_t size) {
+ int ret, errno;
+ auto t = reinterpret_cast<Tcb *>(tcb);
+ SYSCALL3(SYSCALL_GETTIDID, t->tid, name, size);
+ return errno;
+}
+
+int sys_thread_setname(void *tcb, const char *name) {
+ int ret, errno;
+ size_t len = strlen(name);
+ auto t = reinterpret_cast<Tcb *>(tcb);
+ SYSCALL3(SYSCALL_SETTIDID, t->tid, name, len);
+ return errno;
+}
+
+int sys_open(const char *path, int flags, mode_t mode, int *fd) {
+ return sys_openat(AT_FDCWD, path, flags, mode, fd);
+}
+
+int sys_openat(int dirfd, const char *path, int flags, mode_t mode, int *fd) {
+ int ret, errno;
+
+ int path_len = strlen (path);
+ SYSCALL4(SYSCALL_OPEN, dirfd, path, path_len, flags);
+ if (ret != -1 && (flags & O_EXCL)) {
+ SYSCALL1(SYSCALL_CLOSE, ret);
+ return EEXIST;
+ }
+
+ if (ret == -1 && (flags & O_CREAT)) {
+ SYSCALL5(SYSCALL_MAKENODE, AT_FDCWD, path, path_len, mode, 0);
+ if (ret == -1) {
+ return errno;
+ }
+ SYSCALL4(SYSCALL_OPEN, AT_FDCWD, path, path_len, flags);
+ } else if (ret != -1 && (flags & O_TRUNC)) {
+ // If the file cannot be truncated, dont sweat it, some software
+ // depends on some things being truncate-able that ironclad does not
+ // allow. For example, some devices.
+ sys_ftruncate(ret, 0);
+ } else if (ret != -1 && (flags & O_DIRECTORY)) {
+ struct stat st;
+ sys_stat(fsfd_target::fd, ret, NULL, 0, &st);
+ if (!S_ISDIR (st.st_mode)) {
+ ret = -1;
+ errno = ENOTDIR;
+ }
+ }
+
+ *fd = ret;
+ return errno;
+}
+
+int sys_open_dir(const char *path, int *handle) {
+ return sys_open(path, O_RDONLY | O_DIRECTORY, 0660, handle);
+}
+
+int sys_read_entries(int handle, void *buffer, size_t max_size, size_t *bytes_read) {
+ size_t ret;
+ int errno;
+ SYSCALL3(SYSCALL_GETDENTS, handle, buffer, max_size);
+ if (errno != 0) {
+ return errno;
+ } else {
+ *bytes_read = ret;
+ return 0;
+ }
+}
+
+void sys_thread_exit() {
+ int ret, errno;
+ SYSCALL0(SYSCALL_EXIT_THREAD);
+ __builtin_unreachable();
+}
+
+int sys_close(int fd) {
+ int ret, errno;
+ SYSCALL1(SYSCALL_CLOSE, fd);
+ return errno;
+}
+
+void sys_sync() {
+ int ret, errno;
+ SYSCALL0(SYSCALL_SYNC);
+ if (ret != 0) {
+ sys_libc_log("mlibc: sync failed");
+ }
+}
+
+int sys_fsync(int fd) {
+ int ret, errno;
+ SYSCALL2(SYSCALL_FSYNC, fd, 0);
+ return errno;
+}
+
+int sys_fdatasync(int fd) {
+ int ret, errno;
+ SYSCALL2(SYSCALL_FSYNC, fd, 1);
+ return errno;
+}
+
+int sys_read(int fd, void *buf, size_t count, ssize_t *bytes_read) {
+ ssize_t ret;
+ int errno;
+ SYSCALL3(SYSCALL_READ, fd, buf, count);
+ *bytes_read = ret;
+ return errno;
+}
+
+int sys_write(int fd, const void *buf, size_t count, ssize_t *bytes_written) {
+ ssize_t ret;
+ int errno;
+ SYSCALL3(SYSCALL_WRITE, fd, buf, count);
+ *bytes_written = ret;
+ return errno;
+}
+
+int sys_pread(int fd, void *buf, size_t n, off_t off, ssize_t *bytes_read) {
+ ssize_t ret;
+ int errno;
+ SYSCALL4(SYSCALL_PREAD, fd, buf, n, off);
+ *bytes_read = ret;
+ return errno;
+}
+
+int sys_pwrite(int fd, const void *buf, size_t n, off_t off, ssize_t *bytes_written) {
+ ssize_t ret;
+ int errno;
+ SYSCALL4(SYSCALL_WRITE, fd, buf, n, off);
+ *bytes_written = ret;
+ return errno;
+}
+
+int sys_seek(int fd, off_t offset, int whence, off_t *new_offset) {
+ ssize_t ret;
+ int errno;
+ SYSCALL3(SYSCALL_SEEK, fd, offset, whence);
+ *new_offset = ret;
+ return errno;
+}
+
+int sys_ftruncate (int fd, size_t size) {
+ int ret, errno;
+ SYSCALL2(SYSCALL_TRUNCATE, fd, size);
+ return errno;
+}
+
+int sys_flock(int fd, int options) {
+ // XXX: Shouldnt this use F_SETLKW and F_SETLK only when LOCK_NB ?
+ struct flock lock;
+ lock.l_whence = SEEK_SET;
+ lock.l_start = 0;
+ lock.l_len = (off_t)((uint64_t)-1);
+ lock.l_pid = sys_getpid();
+
+ switch (options & ~(LOCK_NB)) {
+ case LOCK_SH:
+ lock.l_type = F_RDLCK;
+ break;
+ case LOCK_EX:
+ lock.l_type = F_WRLCK;
+ break;
+ case LOCK_UN:
+ lock.l_type = F_UNLCK;
+ break;
+ default:
+ return -1;
+ }
+
+ int ret, errno;
+ SYSCALL3(SYSCALL_FCNTL, fd, F_SETLK, &lock);
+ return errno;
+}
+
+int sys_getpriority(int which, id_t who, int *value) {
+ int ret, errno;
+ SYSCALL2(SYSCALL_GETPRIO, which, who);
+ *value = ret;
+ return errno;
+}
+
+int sys_setpriority(int which, id_t who, int value) {
+ int ret, errno;
+ SYSCALL3(SYSCALL_SETPRIO, which, who, value);
+ return errno;
+}
+
+int sys_getrusage(int scope, struct rusage *usage) {
+ int ret, errno;
+ SYSCALL2(SYSCALL_GETRUSAGE, scope, usage);
+
+ // Ironclad returns nanoseconds instead of microseconds for usage, so we
+ // have to compensate for that.
+ usage->ru_utime.tv_usec = usage->ru_utime.tv_usec / 1000;
+ usage->ru_stime.tv_usec = usage->ru_stime.tv_usec / 1000;
+
+ return errno;
+}
+
+int sys_anon_allocate(size_t size, void **pointer) {
+ return sys_vm_map(NULL, size, PROT_READ | PROT_WRITE, MAP_ANON, 0, 0, pointer);
+}
+
+int sys_anon_free(void *pointer, size_t size) {
+ return sys_vm_unmap(pointer, size);
+}
+
+int sys_vm_map(void *hint, size_t size, int prot, int flags, int fd, off_t offset, void **window) {
+ void *ret;
+ int errno;
+ SYSCALL6(SYSCALL_MMAP, hint, size, prot, flags, fd, offset);
+ *window = ret;
+ return errno;
+}
+
+int sys_getsockopt(int fd, int layer, int number, void *__restrict buffer, socklen_t *__restrict size) {
+ int ret, errno;
+ SYSCALL5(SYSCALL_GETSOCKOPT, fd, layer, number, buffer, size);
+ return errno;
+}
+
+int sys_setsockopt(int fd, int layer, int number, const void *buffer, socklen_t size) {
+ int ret, errno;
+ SYSCALL5(SYSCALL_SETSOCKOPT, fd, layer, number, buffer, size);
+ return errno;
+}
+
+int sys_vm_unmap(void *pointer, size_t size) {
+ int ret;
+ int errno;
+ SYSCALL2(SYSCALL_MUNMAP, pointer, size);
+ if (ret != 0) {
+ return errno;
+ } else {
+ return 0;
+ }
+}
+
+int sys_getcwd(char *buf, size_t size) {
+ buf[0] = '/';
+ buf[1] = '\0';
+ return 0;
+}
+
+int sys_vm_protect(void *pointer, size_t size, int prot) {
+ int ret;
+ int errno;
+ SYSCALL3(SYSCALL_MPROTECT, pointer, size, prot);
+ if (ret != 0) {
+ return errno;
+ }
+ return 0;
+}
+
+int sys_getsid(pid_t pid, pid_t *sid) {
+ // STUB.
+ return 0;
+}
+
+pid_t sys_getpid() {
+ pid_t ret;
+ int errno;
+ SYSCALL0(SYSCALL_GETPID);
+ return ret;
+}
+
+pid_t sys_getppid() {
+ pid_t ret;
+ int errno;
+ SYSCALL0(SYSCALL_GETPPID);
+ return ret;
+}
+
+int sys_getgroups(size_t size, const gid_t *list, int *retval) {
+ int ret, errno;
+ SYSCALL2(SYSCALL_GETGROUPS, size, list);
+ *retval = ret;
+ return errno;
+}
+
+int sys_setgroups(size_t size, const gid_t *list) {
+ int ret, errno;
+ SYSCALL2(SYSCALL_SETGROUPS, size, list);
+ return errno;
+}
+
+int sys_sigaction(int signum, const struct sigaction *act, struct sigaction *oldact) {
+ return 0;
+}
+
+int sys_ptrace(long req, pid_t pid, void *addr, void *data, long *out) {
+ int ret, errno;
+ SYSCALL4(SYSCALL_PTRACE, req, pid, addr, data);
+ *out = (long)ret;
+ return errno;
+}
+
+int sys_fcntl(int fd, int request, va_list args, int *result) {
+ int ret, errno;
+ SYSCALL3(SYSCALL_FCNTL, fd, request, va_arg(args, uint64_t));
+ *result = ret;
+ return errno;
+}
+
+int sys_sigprocmask(int how, const sigset_t *__restrict set, sigset_t *__restrict retrieve) {
+ return 0;
+}
+
+int sys_isatty(int fd) {
+ struct termios t;
+ if (sys_tcgetattr(fd, &t) == 0) {
+ return 0;
+ } else {
+ return ENOTTY;
+ }
+}
+
+int sys_getpgid(pid_t pid, pid_t *pgid) {
+ (void)pid;
+ // FIXME: Stub needed by mlibc.
+ *pgid = 0;
+ return 0;
+}
+
+int sys_execve(const char *path, char *const argv[], char *const envp[]) {
+ int ret, errno, argv_len, envp_len;
+ for (argv_len = 0; argv[argv_len] != NULL; argv_len++);
+ for (envp_len = 0; envp[envp_len] != NULL; envp_len++);
+
+ size_t path_len = strlen (path);
+ SYSCALL6(SYSCALL_EXEC, path, path_len, argv, argv_len, envp, envp_len);
+
+ if (ret == -1) {
+ return errno;
+ }
+
+ return 0;
+}
+
+int sys_fork(pid_t *child) {
+ pid_t ret;
+ int errno;
+
+ SYSCALL6(SYSCALL_CLONE, 0, 0, 0, 0, 0, 1);
+
+ if (ret == -1) {
+ return errno;
+ }
+
+ if (child != NULL) {
+ *child = ret;
+ }
+
+ return 0;
+}
+
+int sys_getrlimit(int resource, struct rlimit *limit) {
+ uint64_t ret, errno;
+ SYSCALL1(SYSCALL_GETRLIMIT, resource);
+ limit->rlim_cur = ret;
+ limit->rlim_max = ret;
+ return errno;
+}
+
+int sys_setrlimit(int resource, const struct rlimit *limit) {
+ int ret, errno;
+ SYSCALL2(SYSCALL_SETRLIMIT, resource, limit->rlim_cur);
+ return errno;
+}
+
+int sys_waitpid(pid_t pid, int *status, int flags, struct rusage *ru, pid_t *ret_pid) {
+ pid_t ret;
+ int errno;
+
+ if(ru) {
+ mlibc::infoLogger() << "mlibc: struct rusage in sys_waitpid is unsupported" << frg::endlog;
+ return ENOSYS;
+ }
+
+ SYSCALL3(SYSCALL_WAIT, pid, status, flags);
+
+ if (ret == -1) {
+ return errno;
+ }
+
+ *ret_pid = ret;
+ return errno;
+}
+
+int sys_uname(struct utsname *buf) {
+ int ret, errno;
+
+ SYSCALL3(SYSCALL_SYSCONF, 10, buf, sizeof(struct utsname));
+
+ if (ret == -1) {
+ return errno;
+ }
+
+ return 0;
+}
+
+
+
+int sys_setpgid(pid_t pid, pid_t pgid) {
+ (void)pid;
+ (void)pgid;
+ return 0;
+}
+
+int sys_ttyname(int fd, char *buff, size_t size) {
+ int ret, errno;
+ SYSCALL3(SYSCALL_TTYNAME, fd, buff, size);
+ return errno;
+}
+
+int sys_sethostname(const char *buff, size_t size) {
+ int ret, errno;
+
+ SYSCALL2(SYSCALL_SETHOSTNAME, buff, size);
+
+ if (ret == -1) {
+ return errno;
+ }
+
+ return 0;
+}
+
+int sys_chdir(const char *buff) {
+ int ret, errno;
+
+ size_t buff_len = strlen(buff);
+ SYSCALL4(SYSCALL_OPEN, AT_FDCWD, buff, buff_len, O_RDONLY);
+ if (ret == -1) {
+ return ENOENT;
+ }
+
+ SYSCALL1(SYSCALL_CHDIR, ret);
+
+ if (ret == -1) {
+ return errno;
+ }
+
+ return 0;
+}
+
+int sys_fchdir(int fd) {
+ int ret, errno;
+
+ SYSCALL1(SYSCALL_CHDIR, fd);
+
+ if (ret == -1) {
+ return errno;
+ }
+
+ return 0;
+}
+
+int sys_ioctl(int fd, unsigned long request, void *arg, int *result) {
+ int ret, errno;
+
+ if (request == TIOCGPGRP) {
+ *result = 0;
+ return 0;
+ } else if (request == TIOCSPGRP) {
+ return 0;
+ }
+
+ SYSCALL3(SYSCALL_IOCTL, fd, request, arg);
+
+ if (ret == -1) {
+ return errno;
+ }
+
+ *result = ret;
+ return 0;
+}
+
+void sys_yield(void) {
+ int ret, errno;
+ SYSCALL0(SYSCALL_SCHED_YIELD);
+}
+
+int sys_kill(int pid, int sig) {
+ int ret, errno;
+ if (sig == SIGKILL) {
+ SYSCALL1(SYSCALL_ACTUALLY_KILL, pid);
+ } else {
+ SYSCALL2(SYSCALL_SEND_SIGNAL, pid, sig);
+ }
+
+ return errno;
+}
+
+int sys_dup(int fd, int flags, int *newfd) {
+ int ret, errno;
+ if (flags & O_CLOEXEC) {
+ SYSCALL3(SYSCALL_FCNTL, fd, F_DUPFD_CLOEXEC, 0);
+ } else {
+ SYSCALL3(SYSCALL_FCNTL, fd, F_DUPFD, 0);
+ }
+ *newfd = ret;
+ return errno;
+}
+
+int sys_dup2(int fd, int flags, int newfd) {
+ int ret = sys_close(newfd);
+ if (ret != 0 && ret != EBADFD) {
+ return EBADFD;
+ }
+
+ int errno;
+ if (flags & O_CLOEXEC) {
+ SYSCALL3(SYSCALL_FCNTL, fd, F_DUPFD_CLOEXEC, newfd);
+ } else {
+ SYSCALL3(SYSCALL_FCNTL, fd, F_DUPFD, newfd);
+ }
+
+ if (ret != -1 && ret != newfd) {
+ return EBADFD;
+ } else {
+ return errno;
+ }
+}
+
+int sys_tcgetattr(int fd, struct termios *attr) {
+ int ret;
+
+ if (int r = sys_ioctl(fd, TCGETS, attr, &ret) != 0) {
+ return r;
+ }
+
+ return 0;
+}
+
+int sys_tcsetattr(int fd, int optional_action, const struct termios *attr) {
+ int ret;
+
+ switch (optional_action) {
+ case TCSANOW:
+ optional_action = TCSETS; break;
+ case TCSADRAIN:
+ optional_action = TCSETSW; break;
+ case TCSAFLUSH:
+ optional_action = TCSETSF; break;
+ default:
+ __ensure(!"Unsupported tcsetattr");
+ }
+
+ if (int r = sys_ioctl(fd, optional_action, (void *)attr, &ret) != 0) {
+ return r;
+ }
+
+ return 0;
+}
+
+int sys_tcflow(int fd, int action) {
+ int ret;
+ return sys_ioctl(fd, TCXONC, &action, &ret);
+}
+
+int sys_tcflush(int fd, int action) {
+ int ret;
+ return sys_ioctl(fd, TCFLSH, &action, &ret);
+}
+
+int sys_access(const char *path, int mode) {
+ int ret, errno;
+ size_t len = strlen(path);
+ SYSCALL5(SYSCALL_ACCESS, AT_FDCWD, path, len, mode, 0);
+ return errno;
+}
+
+int sys_faccessat(int dirfd, const char *pathname, int mode, int flags) {
+ int ret, errno;
+ size_t len = strlen(pathname);
+ SYSCALL5(SYSCALL_ACCESS, dirfd, pathname, len, mode, flags);
+ return errno;
+}
+
+struct futex_item {
+ uint64_t addr;
+ uint32_t expected;
+ uint32_t flags;
+};
+
+int sys_futex_wait(int *pointer, int expected, const struct timespec *time) {
+ int ret, errno;
+ struct futex_item item = {.addr = (uint64_t)pointer, .expected = expected, .flags = 0};
+ if (time == NULL) {
+ struct timespec t = {(time_t)-1, (time_t)-1};
+ SYSCALL4(SYSCALL_FUTEX, 0b01, &item, 1, &t);
+ } else {
+ SYSCALL4(SYSCALL_FUTEX, 0b01, &item, 1, time);
+ }
+ return errno;
+}
+
+int sys_futex_wake(int *pointer) {
+ int ret, errno;
+ struct futex_item item = {.addr = (uint64_t)pointer, .expected = 0, .flags = 0};
+ struct timespec t = {(time_t)-1, (time_t)-1};
+ SYSCALL4(SYSCALL_FUTEX, 0b10, &item, 1, &t);
+ return errno;
+}
+
+int sys_pipe(int *fds, int flags) {
+ int ret, errno;
+ SYSCALL2(SYSCALL_PIPE, fds, flags);
+ return errno;
+}
+
+int sys_getentropy(void *buffer, size_t length) {
+ ssize_t ret;
+ int errno;
+ SYSCALL2(SYSCALL_GETRANDOM, buffer, length);
+ return errno;
+}
+
+int sys_mkdir(const char *path, mode_t mode) {
+ return sys_mkdirat(AT_FDCWD, path, mode);
+}
+
+int sys_mkdirat(int dirfd, const char *path, mode_t mode) {
+ int ret, errno;
+ size_t path_len = strlen (path);
+ SYSCALL5(SYSCALL_MAKENODE, dirfd, path, path_len, S_IFDIR | mode, 0);
+ return errno;
+}
+
+int sys_rmdir(const char* path){
+ int ret, errno;
+ size_t path_len = strlen (path);
+ SYSCALL3(SYSCALL_UNLINK, AT_FDCWD, path, path_len);
+ return errno;
+}
+
+int sys_unlinkat(int fd, const char *path, int flags) {
+ int ret, errno;
+ size_t path_len = strlen (path);
+ SYSCALL3(SYSCALL_UNLINK, fd, path, path_len);
+ return errno;
+}
+
+int sys_link(const char* srcpath, const char* destpath) {
+ int ret, errno;
+ size_t src_len = strlen (srcpath);
+ size_t dst_len = strlen (destpath);
+ SYSCALL6(SYSCALL_LINK, AT_FDCWD, srcpath, src_len, AT_FDCWD, destpath, dst_len);
+ return errno;
+}
+
+int sys_socket(int domain, int type, int protocol, int *fd) {
+ int ret, errno;
+ SYSCALL3(SYSCALL_SOCKET, domain, type, protocol);
+ if (ret != -1) {
+ *fd = ret;
+ return 0;
+ } else {
+ return errno;
+ }
+}
+
+uid_t sys_getuid() {
+ uint64_t ret, errno;
+ SYSCALL0(SYSCALL_GETUID);
+ return (uid_t)ret;
+}
+
+uid_t sys_geteuid() {
+ uint64_t ret, errno;
+ SYSCALL0(SYSCALL_GETEUID);
+ return (uid_t)ret;
+}
+
+int sys_setuid(uid_t uid) {
+ int ret, errno;
+ SYSCALL2(SYSCALL_SETUIDS, uid, uid);
+ return ret;
+}
+
+int sys_seteuid(uid_t euid) {
+ int ret, errno;
+ SYSCALL2(SYSCALL_SETUIDS, ((uint64_t)-1), euid);
+ return ret;
+}
+
+int sys_setreuid(uid_t ruid, uid_t euid) {
+ int ret, errno;
+ SYSCALL2(SYSCALL_SETUIDS, ruid, euid);
+ return ret;
+}
+
+gid_t sys_getgid() {
+ uint64_t ret, errno;
+ SYSCALL0(SYSCALL_GETGID);
+ return (gid_t)ret;
+}
+
+gid_t sys_getegid() {
+ return sys_getgid();
+}
+
+int sys_setgid(gid_t gid) {
+ int ret, errno;
+ SYSCALL2(SYSCALL_SETGIDS, gid, gid);
+ return ret;
+}
+
+int sys_setegid(gid_t egid) {
+ int ret, errno;
+ SYSCALL2(SYSCALL_SETGIDS, ((uint64_t)-1), egid);
+ return ret;
+}
+
+int sys_setregid(gid_t rgid, gid_t egid) {
+ int ret, errno;
+ SYSCALL2(SYSCALL_SETGIDS, rgid, egid);
+ return ret;
+}
+
+int sys_setsid(pid_t *sid) {
+ return 0;
+}
+
+#ifndef MLIBC_BUILDING_RTDL
+
+extern "C" void __mlibc_thread_entry();
+
+int sys_clone(void *tcb, pid_t *tid_out, void *stack) {
+ int ret, errno;
+ SYSCALL6(SYSCALL_CLONE, (uintptr_t)__mlibc_thread_entry, 0, stack, 0b10, tcb, 1);
+
+ if (ret == -1) {
+ return errno;
+ }
+
+ *tid_out = (pid_t)ret;
+ return 0;
+}
+
+int sys_prepare_stack(void **stack, void *entry, void *arg, void *tcb, size_t *stack_size, size_t *guard_size) {
+ // TODO guard
+
+ mlibc::infoLogger() << "mlibc: sys_prepare_stack() does not setup a guard!" << frg::endlog;
+
+ *guard_size = 0;
+ *stack_size = *stack_size ? *stack_size : 0x400000;
+
+ if (!*stack) {
+ *stack = (void *)((char *)mmap(NULL, *stack_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0) + *stack_size);
+ if (*stack == MAP_FAILED) {
+ return errno;
+ }
+ }
+
+ void **stack_it = (void **)*stack;
+
+ *--stack_it = arg;
+ *--stack_it = tcb;
+ *--stack_it = entry;
+
+ *stack = (void *)stack_it;
+
+ return 0;
+}
+
+int sys_clock_getres(int clock, time_t *secs, long *nanos) {
+ struct timespec time;
+ int ret, errno;
+ SYSCALL3(SYSCALL_CLOCK, 0, clock, &time);
+ *secs = time.tv_sec;
+ *nanos = time.tv_nsec;
+ return errno;
+}
+
+int sys_clock_get(int clock, time_t *secs, long *nanos) {
+ struct timespec time;
+ int ret, errno;
+ SYSCALL3(SYSCALL_CLOCK, 1, clock, &time);
+ *secs = time.tv_sec;
+ *nanos = time.tv_nsec;
+ return errno;
+}
+
+int sys_clock_set(int clock, time_t secs, long nanos) {
+ struct timespec time = {.tv_sec = secs, .tv_nsec = nanos };
+ int ret, errno;
+ SYSCALL3(SYSCALL_CLOCK, 2, clock, &time);
+ return errno;
+}
+
+int sys_bind(int fd, const struct sockaddr *addr_ptr, socklen_t addrlen) {
+ int ret, errno;
+ SYSCALL3(SYSCALL_BIND, fd, addr_ptr, addrlen);
+ return errno;
+}
+
+int sys_connect(int fd, const struct sockaddr *addr_ptr, socklen_t addrlen) {
+ int ret, errno;
+ SYSCALL3(SYSCALL_CONNECT, fd, addr_ptr, addrlen);
+ return errno;
+}
+
+int sys_listen(int fd, int backlog) {
+ int ret, errno;
+ SYSCALL2(SYSCALL_LISTEN, fd, backlog);
+ return errno;
+}
+
+int sys_accept(int fd, int *newfd, struct sockaddr *addr_ptr, socklen_t *addr_length, int flags) {
+ int ret, errno;
+ SYSCALL4(SYSCALL_ACCEPT, fd, addr_ptr, addr_length, flags);
+ *newfd = ret;
+ return errno;
+}
+
+
+int sys_sockname(int fd, struct sockaddr *addr_ptr, socklen_t max_addr_length, socklen_t *actual_length) {
+ int ret, errno;
+ SYSCALL3(SYSCALL_GETSOCKNAME, fd, addr_ptr, &max_addr_length);
+ *actual_length = max_addr_length;
+ return errno;
+}
+
+int sys_peername(int fd, struct sockaddr *addr_ptr, socklen_t max_addr_length, socklen_t *actual_length) {
+ int ret, errno;
+ SYSCALL3(SYSCALL_GETPEERNAME, fd, addr_ptr, &max_addr_length);
+ *actual_length = max_addr_length;
+ return errno;
+}
+
+int sys_shutdown(int sockfd, int how) {
+ int ret, errno;
+ SYSCALL2(SYSCALL_SHUTDOWN, sockfd, how);
+ return errno;
+}
+
+int sys_setitimer(int which, const struct itimerval *new_value, struct itimerval *old_value) {
+ return ENOSYS;
+}
+
+int sys_msg_recv(int fd, struct msghdr *hdr, int flags, ssize_t *length) {
+ if (hdr->msg_control != NULL) {
+ // mlibc::infoLogger() << "mlibc: recv() msg_control not supported!" << frg::endlog;
+ }
+
+ int ret;
+ size_t count = 0;
+ int errno;
+
+ for (int i = 0; i < hdr->msg_iovlen; i++) {
+ SYSCALL6(SYSCALL_RECVFROM, fd, hdr->msg_iov->iov_base, hdr->msg_iov->iov_len,
+ hdr->msg_flags, hdr->msg_name, hdr->msg_namelen);
+ if (ret == -1) {
+ return errno;
+ }
+ count += ret;
+ }
+
+ *length = count;
+ return 0;
+}
+
+int sys_msg_send(int fd, const struct msghdr *hdr, int flags, ssize_t *length) {
+ if (hdr->msg_control != NULL) {
+ // mlibc::infoLogger() << "mlibc: recv() msg_control not supported!" << frg::endlog;
+ }
+
+ int ret;
+ size_t count = 0;
+ int errno;
+
+ for (int i = 0; i < hdr->msg_iovlen; i++) {
+ SYSCALL6(SYSCALL_SENDTO, fd, hdr->msg_iov->iov_base, hdr->msg_iov->iov_len,
+ hdr->msg_flags, hdr->msg_name, hdr->msg_namelen);
+ if (ret == -1) {
+ return errno;
+ }
+ count += ret;
+ }
+
+ *length = count;
+ return 0;
+}
+
+
+int sys_ppoll(struct pollfd *fds, int nfds, const struct timespec *timeout, const sigset_t *sigmask, int *num_events) {
+ // XXX: Ironclad has no sigprogmask so this is basically a weird ppoll poll
+ // chimeral abomination.
+ int ret, errno;
+ if (timeout == NULL) {
+ struct timespec t = {.tv_sec = (time_t)-1, .tv_nsec = (time_t)-1};
+ SYSCALL3(SYSCALL_POLL, fds, nfds, &t);
+ } else {
+ SYSCALL3(SYSCALL_POLL, fds, nfds, timeout);
+ }
+ if (ret == -1) {
+ return errno;
+ }
+
+ *num_events = ret;
+ return errno;
+}
+
+int sys_poll(struct pollfd *fds, nfds_t count, int timeout, int *num_events) {
+ struct timespec ts;
+ ts.tv_sec = timeout / 1000;
+ ts.tv_nsec = (timeout % 1000) * 1000000;
+ return sys_ppoll(fds, count, timeout == -1 ? NULL : &ts, NULL, num_events);
+}
+
+int sys_pselect(int nfds, fd_set *read_set, fd_set *write_set,
+ fd_set *except_set, const struct timespec *timeout,
+ const sigset_t *sigmask, int *num_events) {
+ struct pollfd *fds = (struct pollfd *)calloc(nfds, sizeof(struct pollfd));
+ if (fds == NULL) {
+ return ENOMEM;
+ }
+
+ for (int i = 0; i < nfds; i++) {
+ struct pollfd *fd = &fds[i];
+
+ if (read_set && FD_ISSET(i, read_set)) {
+ fd->events |= POLLIN;
+ }
+ if (write_set && FD_ISSET(i, write_set)) {
+ fd->events |= POLLOUT;
+ }
+ if (except_set && FD_ISSET(i, except_set)) {
+ fd->events |= POLLPRI;
+ }
+
+ if (!fd->events) {
+ fd->fd = -1;
+ continue;
+ }
+ fd->fd = i;
+ }
+
+ int ret = sys_ppoll(fds, nfds, timeout, sigmask, num_events);
+ if (ret != 0) {
+ free(fds);
+ return ret;
+ }
+
+ fd_set res_read_set, res_write_set, res_except_set;
+ FD_ZERO(&res_read_set);
+ FD_ZERO(&res_write_set);
+ FD_ZERO(&res_except_set);
+
+ for (int i = 0; i < nfds; i++) {
+ struct pollfd *fd = &fds[i];
+
+ if (read_set && FD_ISSET(i, read_set) && (fd->revents & (POLLIN | POLLERR | POLLHUP)) != 0) {
+ FD_SET(i, &res_read_set);
+ }
+ if (write_set && FD_ISSET(i, write_set) && (fd->revents & (POLLOUT | POLLERR | POLLHUP)) != 0) {
+ FD_SET(i, &res_write_set);
+ }
+ if (except_set && FD_ISSET(i, except_set) && (fd->revents & POLLPRI) != 0) {
+ FD_SET(i, &res_except_set);
+ }
+ }
+
+ free(fds);
+ if (read_set) {
+ *read_set = res_read_set;
+ }
+ if (write_set) {
+ *write_set = res_write_set;
+ }
+ if (except_set) {
+ *except_set = res_except_set;
+ }
+
+ return 0;
+}
+
+int sys_sleep(time_t *secs, long *nanos) {
+ struct timespec time = {.tv_sec = *secs, .tv_nsec = *nanos};
+ struct timespec rem = {.tv_sec = 0, .tv_nsec = 0};
+
+ int ret, errno;
+ SYSCALL4(SYSCALL_CLOCK_NANOSLEEP, CLOCK_MONOTONIC, 0, &time, &rem);
+ *secs = rem.tv_sec;
+ *nanos = rem.tv_nsec;
+ return errno;
+}
+
+int sys_gethostname(char *buffer, size_t bufsize) {
+ struct utsname buf;
+ if (uname(&buf)) {
+ return -1;
+ }
+
+ strncpy(buffer, buf.nodename, bufsize);
+ return 0;
+}
+
+int sys_utimensat(int dirfd, const char *pathname, const struct timespec times[2], int flags) {
+ int ret, errno;
+ if (pathname == NULL) {
+ pathname = "";
+ flags |= AT_EMPTY_PATH;
+ }
+
+ size_t path_len = strlen (pathname);
+ if (times == NULL) {
+ time_t secs;
+ long nsec;
+ ret = sys_clock_get(CLOCK_REALTIME, &secs, &nsec);
+ if (ret) {
+ return ret;
+ }
+ struct timespec times2[2] = {0, 0};
+ times2[0].tv_sec = secs;
+ times2[0].tv_nsec = nsec;
+ times2[1].tv_sec = secs;
+ times2[1].tv_nsec = nsec;
+ SYSCALL5(SYSCALL_UTIMES, dirfd, pathname, path_len, &times2[0], flags);
+ } else {
+ SYSCALL5(SYSCALL_UTIMES, dirfd, pathname, path_len, times, flags);
+ }
+
+ return errno;
+}
+
+int sys_sysconf(int num, long *rret) {
+ long ret, errno;
+ SYSCALL3(SYSCALL_SYSCONF, num, 0, 0);
+ *rret = ret;
+ return errno;
+}
+
+int sys_stat(fsfd_target fsfdt, int fd, const char *path, int flags, struct stat *statbuf) {
+ int ret, errno;
+ (void)flags;
+
+ switch (fsfdt) {
+ case fsfd_target::fd: {
+ SYSCALL5(SYSCALL_STAT, fd, "", 0, statbuf, AT_EMPTY_PATH);
+ break;
+ }
+ case fsfd_target::path: {
+ size_t len = strlen(path);
+ SYSCALL5(SYSCALL_STAT, AT_FDCWD, path, len, statbuf, flags);
+ break;
+ }
+ case fsfd_target::fd_path: {
+ size_t len = strlen(path);
+ SYSCALL5(SYSCALL_STAT, fd, path, len, statbuf, flags);
+ break;
+ }
+ default: {
+ __ensure(!"stat: Invalid fsfdt");
+ __builtin_unreachable();
+ }
+ }
+
+ return errno;
+}
+
+int sys_chmod(const char *pathname, mode_t mode) {
+ int ret, errno;
+ size_t len = strlen(pathname);
+ SYSCALL5(SYSCALL_FCHMOD, AT_FDCWD, pathname, len, mode, 0);
+ return errno;
+}
+
+int sys_fchmodat(int fd, const char *pathname, mode_t mode, int flags) {
+ int ret, errno;
+ size_t len = strlen(pathname);
+ SYSCALL5(SYSCALL_FCHMOD, fd, pathname, len, mode, flags);
+ return errno;
+}
+
+int sys_fchmod(int fd, mode_t mode) {
+ int ret, errno;
+ SYSCALL5(SYSCALL_FCHMOD, fd, "", 0, mode, AT_EMPTY_PATH);
+ return errno;
+}
+
+int sys_chown(const char *pathname, uid_t uid, gid_t gid) {
+ int ret, errno;
+ size_t len = strlen(pathname);
+ SYSCALL6(SYSCALL_FCHOWN, AT_FDCWD, pathname, len, uid, gid, 0);
+ return errno;
+}
+
+int sys_fchownat(int fd, const char *pathname, uid_t uid, gid_t gid, int flags) {
+ int ret, errno;
+ size_t len = strlen(pathname);
+ SYSCALL6(SYSCALL_FCHOWN, fd, pathname, len, uid, gid, flags);
+ return errno;
+}
+
+int sys_fchown(int fd, uid_t uid, gid_t gid) {
+ int ret, errno;
+ SYSCALL6(SYSCALL_FCHOWN, fd, "", 0, uid, gid, AT_EMPTY_PATH);
+ return errno;
+}
+
+int sys_umask(mode_t mode, mode_t *old) {
+ mode_t ret;
+ int errno;
+ SYSCALL1(SYSCALL_UMASK, mode);
+ *old = (mode_t)ret;
+ return errno;
+}
+
+int sys_fadvise(int fd, off_t offset, off_t length, int advice) {
+ int ret, errno;
+ SYSCALL4(SYSCALL_FADVISE, fd, offset, length, advice);
+ return errno;
+}
+
+int sys_readlink(const char *path, void *buffer, size_t max_size, ssize_t *length) {
+ ssize_t ret;
+ int errno;
+ size_t path_len = strlen(path);
+ SYSCALL5(SYSCALL_READLINK, AT_FDCWD, path, path_len, buffer, max_size);
+ if (ret == -1) {
+ return errno;
+ } else {
+ *length = ret;
+ return 0;
+ }
+}
+
+int sys_rename(const char *path, const char *new_path) {
+ int ret;
+ int errno;
+ size_t old_len = strlen(path);
+ size_t new_len = strlen(new_path);
+ SYSCALL7(SYSCALL_RENAME, AT_FDCWD, path, old_len, AT_FDCWD, new_path, new_len, 0);
+ return errno;
+}
+
+int sys_renameat(int olddirfd, const char *old_path, int newdirfd, const char *new_path) {
+ int ret;
+ int errno;
+ size_t old_len = strlen(old_path);
+ size_t new_len = strlen(new_path);
+ SYSCALL7(SYSCALL_RENAME, olddirfd, old_path, old_len, newdirfd, new_path, new_len, 0);
+ return errno;
+}
+
+int sys_mknodat(int dirfd, const char *path, mode_t mode, dev_t dev) {
+ int ret;
+ int errno;
+ size_t len = strlen(path);
+ SYSCALL5(SYSCALL_MAKENODE, dirfd, path, len, mode, dev);
+ return errno;
+}
+
+#define SC_LIST_MOUNTS 9
+struct mountinfo {
+ uint32_t type;
+ uint32_t flags;
+ char source[20];
+ uint32_t source_length;
+ char location[20];
+ uint32_t location_length;
+ uint64_t block_size;
+ uint64_t fragment_size;
+ uint64_t size_in_fragments;
+ uint64_t free_blocks;
+ uint64_t free_blocks_user;
+ uint64_t inode_count;
+ uint64_t free_inodes;
+ uint64_t free_inodes_user;
+ uint64_t max_filename;
+};
+
+#include <sys/mount.h>
+
+int sys_fstatvfs(int fd, struct statvfs *out) {
+ return sys_statvfs("/", out);
+}
+
+int sys_statvfs(const char *path, struct statvfs *out) {
+ long ret, errno;
+ struct mountinfo *buffer = (mountinfo *)malloc(5 * sizeof(struct mountinfo));
+ SYSCALL3(SYSCALL_SYSCONF, SC_LIST_MOUNTS, buffer, 5 * sizeof(struct mountinfo));
+ if (errno) {
+ free(buffer);
+ return errno;
+ } else if (ret > 5) {
+ free(buffer);
+ return 1;
+ }
+
+ for (int i = 0; i < ret; i++) {
+ if (!strncmp(path, buffer[i].location, buffer[i].location_length)) {
+ out->f_bsize = buffer[i].block_size;
+ out->f_frsize = buffer[i].fragment_size;
+ out->f_blocks = buffer[i].size_in_fragments;
+ out->f_bfree = buffer[i].free_blocks;
+ out->f_bavail = buffer[i].free_blocks_user;
+ out->f_files = buffer[i].inode_count;
+ out->f_ffree = buffer[i].free_inodes;
+ out->f_favail = buffer[i].free_inodes_user;
+ out->f_fsid = 0;
+ out->f_flag = buffer[i].flags;
+ out->f_namemax = buffer[i].max_filename;
+ if (buffer[i].type == MNT_EXT) {
+ strcpy(out->f_basetype, "ext");
+ } else {
+ strcpy(out->f_basetype, "fat");
+ }
+ return 0;
+ }
+ }
+
+ return EINVAL;
+}
+#endif
+} // namespace mlibc
diff --git a/lib/mlibc/sysdeps/ironclad/generic/mac.cpp b/lib/mlibc/sysdeps/ironclad/generic/mac.cpp
new file mode 100644
index 0000000..12b63d8
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/generic/mac.cpp
@@ -0,0 +1,32 @@
+#include <sys/syscall.h>
+#include <sys/mac.h>
+#include <errno.h>
+#include <string.h>
+
+extern "C" {
+
+unsigned long get_mac_capabilities(void) {
+ int ret;
+ SYSCALL0(SYSCALL_GET_MAC_CAPABILITIES);
+ return ret;
+}
+
+int set_mac_capabilities(unsigned long request) {
+ int ret;
+ SYSCALL1(SYSCALL_SET_MAC_CAPABILITIES, request);
+ return ret;
+}
+
+int add_mac_permissions(const char *path, int flags) {
+ int ret;
+ SYSCALL3(SYSCALL_ADD_MAC_PERMISSIONS, path, strlen(path), flags);
+ return ret;
+}
+
+int set_mac_enforcement(unsigned long enforcement) {
+ int ret;
+ SYSCALL1(SYSCALL_SET_MAC_ENFORCEMENT, enforcement);
+ return ret;
+}
+
+}
diff --git a/lib/mlibc/sysdeps/ironclad/generic/mntent.cpp b/lib/mlibc/sysdeps/ironclad/generic/mntent.cpp
new file mode 100644
index 0000000..d064af3
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/generic/mntent.cpp
@@ -0,0 +1,97 @@
+#include <errno.h>
+#include <mntent.h>
+#include <stdio.h>
+#include <limits.h>
+#include <string.h>
+#include <bits/ensure.h>
+
+namespace {
+
+char *internal_buf;
+size_t internal_bufsize;
+
+}
+
+#define SENTINEL (char *)&internal_buf
+
+FILE *setmntent(const char *name, const char *mode) {
+ return fopen(name, mode);
+}
+
+struct mntent *getmntent(FILE *f) {
+ static struct mntent mnt;
+ return getmntent_r(f, &mnt, SENTINEL, 0);
+}
+
+int addmntent(FILE *f, const struct mntent *mnt) {
+ if(fseek(f, 0, SEEK_END)) {
+ return 1;
+ }
+ return fprintf(f, "%s\t%s\t%s\t%s\t%d\t%d\n",
+ mnt->mnt_fsname, mnt->mnt_dir, mnt->mnt_type, mnt->mnt_opts,
+ mnt->mnt_freq, mnt->mnt_passno) < 0;
+}
+
+int endmntent(FILE *f) {
+ if(f) {
+ fclose(f);
+ }
+ return 1;
+}
+
+char *hasmntopt(const struct mntent *mnt, const char *opt) {
+ return strstr(mnt->mnt_opts, opt);
+}
+
+/* Adapted from musl */
+struct mntent *getmntent_r(FILE *f, struct mntent *mnt, char *linebuf, int buflen) {
+ int n[8];
+ bool use_internal = (linebuf == SENTINEL);
+ int len;
+ size_t i;
+
+ mnt->mnt_freq = 0;
+ mnt->mnt_passno = 0;
+
+ do {
+ if(use_internal) {
+ getline(&internal_buf, &internal_bufsize, f);
+ linebuf = internal_buf;
+ } else {
+ fgets(linebuf, buflen, f);
+ }
+ if(feof(f) || ferror(f)) {
+ return 0;
+ }
+ if(!strchr(linebuf, '\n')) {
+ fscanf(f, "%*[^\n]%*[\n]");
+ errno = ERANGE;
+ return 0;
+ }
+
+ len = strlen(linebuf);
+ if(len > INT_MAX) {
+ continue;
+ }
+
+ for(i = 0; i < sizeof n / sizeof *n; i++) {
+ n[i] = len;
+ }
+
+ sscanf(linebuf, " %n%*s%n %n%*s%n %n%*s%n %n%*s%n %d %d",
+ n, n + 1, n + 2, n + 3, n + 4, n + 5, n + 6, n + 7,
+ &mnt->mnt_freq, &mnt->mnt_passno);
+ } while(linebuf[n[0]] == '#' || n[1] == len);
+
+ linebuf[n[1]] = 0;
+ linebuf[n[3]] = 0;
+ linebuf[n[5]] = 0;
+ linebuf[n[7]] = 0;
+
+ mnt->mnt_fsname = linebuf + n[0];
+ mnt->mnt_dir = linebuf + n[2];
+ mnt->mnt_type = linebuf + n[4];
+ mnt->mnt_opts = linebuf + n[6];
+
+ return mnt;
+}
diff --git a/lib/mlibc/sysdeps/ironclad/generic/mount.cpp b/lib/mlibc/sysdeps/ironclad/generic/mount.cpp
new file mode 100644
index 0000000..feb6e4c
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/generic/mount.cpp
@@ -0,0 +1,20 @@
+#include <errno.h>
+#include <sys/mount.h>
+#include <bits/ensure.h>
+#include <sys/syscall.h>
+#include <string.h>
+
+int mount(const char *source, const char *target, int type, int flags) {
+ int ret;
+ size_t source_len = strlen(source);
+ size_t target_len = strlen(target);
+ SYSCALL6(SYSCALL_MOUNT, source, source_len, target, target_len, type, flags);
+ return ret;
+}
+
+int umount(const char *target, int flags) {
+ int ret;
+ size_t target_len = strlen(target);
+ SYSCALL3(SYSCALL_UMOUNT, target, target_len, flags);
+ return ret;
+}
diff --git a/lib/mlibc/sysdeps/ironclad/generic/ptrace.cpp b/lib/mlibc/sysdeps/ironclad/generic/ptrace.cpp
new file mode 100644
index 0000000..58a8dd2
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/generic/ptrace.cpp
@@ -0,0 +1,9 @@
+#include <sys/syscall.h>
+#include <errno.h>
+#include <sys/ptrace.h>
+
+int ptrace(int request, pid_t pid, void *addr, void *data) {
+ int ret;
+ SYSCALL4(SYSCALL_PTRACE, request, pid, addr, data);
+ return ret;
+}
diff --git a/lib/mlibc/sysdeps/ironclad/generic/pty.cpp b/lib/mlibc/sysdeps/ironclad/generic/pty.cpp
new file mode 100644
index 0000000..1626e4b
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/generic/pty.cpp
@@ -0,0 +1,41 @@
+#include <asm/ioctls.h>
+#include <bits/ensure.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <pty.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/syscall.h>
+#include <sys/ioctl.h>
+
+int openpty(int *mfd, int *sfd, char *name, const struct termios *ios, const struct winsize *win) {
+ int ret;
+ int fds[2];
+ SYSCALL1(SYSCALL_OPENPTY, fds);
+ if (errno) {
+ return -1;
+ }
+ *mfd = fds[0];
+ *sfd = fds[1];
+
+ if (name != NULL) {
+ ret = ttyname_r(*mfd, name, (size_t)-1);
+ if (ret) {
+ return -1;
+ }
+ }
+ if (ios != NULL) {
+ ret = tcsetattr(*mfd, TCSANOW, ios);
+ if (ret) {
+ return -1;
+ }
+ }
+ if (win != NULL) {
+ ret = ioctl(*mfd, TIOCGWINSZ, win);
+ if (ret) {
+ return -1;
+ }
+ }
+ return ret;
+}
diff --git a/lib/mlibc/sysdeps/ironclad/generic/reboot.cpp b/lib/mlibc/sysdeps/ironclad/generic/reboot.cpp
new file mode 100644
index 0000000..45e8f03
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/generic/reboot.cpp
@@ -0,0 +1,9 @@
+#include <errno.h>
+#include <sys/reboot.h>
+#include <sys/syscall.h>
+
+int reboot(int what) {
+ int ret, errno;
+ SYSCALL2(SYSCALL_REBOOT, what, 0);
+ return ret;
+}
diff --git a/lib/mlibc/sysdeps/ironclad/generic/sched2.cpp b/lib/mlibc/sysdeps/ironclad/generic/sched2.cpp
new file mode 100644
index 0000000..9699517
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/generic/sched2.cpp
@@ -0,0 +1,20 @@
+#include <sys/syscall.h>
+#include <sys/sched2.h>
+#include <errno.h>
+#include <string.h>
+
+extern "C" {
+
+int get_thread_sched(void) {
+ return 0;
+}
+
+int set_thread_sched(int flags) {
+ return 0;
+}
+
+int set_deadlines(int runtime, int period) {
+ return 0;
+}
+
+}
diff --git a/lib/mlibc/sysdeps/ironclad/generic/thread.S b/lib/mlibc/sysdeps/ironclad/generic/thread.S
new file mode 100644
index 0000000..47ab6a9
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/generic/thread.S
@@ -0,0 +1,9 @@
+.section .text
+.global __mlibc_thread_entry
+__mlibc_thread_entry:
+ pop %rdi
+ pop %rsi
+ pop %rdx
+ call __mlibc_thread_trampoline
+
+.section .note.GNU-stack,"",%progbits
diff --git a/lib/mlibc/sysdeps/ironclad/generic/thread.cpp b/lib/mlibc/sysdeps/ironclad/generic/thread.cpp
new file mode 100644
index 0000000..1b2f040
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/generic/thread.cpp
@@ -0,0 +1,54 @@
+#include <sys/mman.h>
+#include <mlibc/debug.hpp>
+#include <errno.h>
+#include <mlibc/all-sysdeps.hpp>
+#include <bits/ensure.h>
+#include <mlibc/tcb.hpp>
+
+extern "C" void __mlibc_thread_trampoline(void *(*fn)(void *), Tcb *tcb, void *arg) {
+ while (__atomic_load_n(&tcb->tid, __ATOMIC_RELAXED) == 0) {
+ mlibc::sys_futex_wait(&tcb->tid, 0, nullptr);
+ }
+
+ tcb->invokeThreadFunc(reinterpret_cast<void *>(fn), arg);
+
+ __atomic_store_n(&tcb->didExit, 1, __ATOMIC_RELEASE);
+ mlibc::sys_futex_wake(&tcb->didExit);
+
+ mlibc::sys_thread_exit();
+}
+
+#define DEFAULT_STACK 0x20000
+
+namespace mlibc {
+ int sys_prepare_stack(void **stack, void *entry, void *arg, void *tcb, size_t *stack_size, size_t *guard_size, void **stack_base) {
+ // TODO guard
+
+ mlibc::infoLogger() << "mlibc: sys_prepare_stack() does not setup a guard!" << frg::endlog;
+
+ *guard_size = 0;
+
+ *stack_size = *stack_size ? *stack_size : DEFAULT_STACK;
+
+ if (!*stack) {
+ *stack_base = mmap(NULL, *stack_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+ if (*stack_base == MAP_FAILED) {
+ return errno;
+ }
+ } else {
+ *stack_base = *stack;
+ }
+
+ *stack = (void *)((char *)*stack_base + *stack_size);
+
+ void **stack_it = (void **)*stack;
+
+ *--stack_it = arg;
+ *--stack_it = tcb;
+ *--stack_it = entry;
+
+ *stack = (void *)stack_it;
+
+ return 0;
+ }
+}
diff --git a/lib/mlibc/sysdeps/ironclad/generic/utmpx.cpp b/lib/mlibc/sysdeps/ironclad/generic/utmpx.cpp
new file mode 100644
index 0000000..ec74e22
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/generic/utmpx.cpp
@@ -0,0 +1,76 @@
+#include <bits/ensure.h>
+#include <stddef.h>
+#include <errno.h>
+#include <utmpx.h>
+#include <stdio.h>
+#include <time.h>
+#include <paths.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+int utmpx_file = -1;
+
+void updwtmpx(const char *, const struct utmpx *) {
+ // Empty as musl does
+}
+
+void endutxent(void) {
+ if (utmpx_file >= 0) {
+ close(utmpx_file);
+ }
+}
+
+void setutxent(void) {
+ if (utmpx_file < 0) {
+ utmpx_file = open(UTMPX_FILE, O_RDWR | O_CREAT, 0755);
+ } else {
+ lseek(utmpx_file, 0, SEEK_SET);
+ }
+}
+
+struct utmpx returned;
+
+struct utmpx *getutxent(void) {
+ if (utmpx_file < 0) {
+ setutxent();
+ if (utmpx_file < 0) {
+ return NULL;
+ }
+ }
+
+ if (read(utmpx_file, &returned, sizeof(struct utmpx)) != sizeof(struct utmpx)) {
+ return NULL;
+ }
+
+ return &returned;
+}
+
+struct utmpx *pututxline(const struct utmpx *added) {
+ if (utmpx_file < 0) {
+ setutxent();
+ if (utmpx_file < 0) {
+ return NULL;
+ }
+ }
+
+ lseek(utmpx_file, 0, SEEK_END);
+ if (write(utmpx_file, added, sizeof(struct utmpx)) != sizeof(struct utmpx)) {
+ return NULL;
+ }
+
+ return (struct utmpx *)added;
+}
+
+int utmpxname(const char *path) {
+ if (utmpx_file > 0) {
+ close(utmpx_file);
+ }
+
+ utmpx_file = open(path, O_RDWR | O_CREAT, 0755);
+ if (utmpx_file > 0) {
+ lseek(utmpx_file, 0, SEEK_END);
+ return 1;
+ } else {
+ return 0;
+ }
+}
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/access.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/access.h
new file mode 120000
index 0000000..8f0556a
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/access.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/access.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/auxv.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/auxv.h
new file mode 120000
index 0000000..f9be899
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/auxv.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/auxv.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/blkcnt_t.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/blkcnt_t.h
new file mode 120000
index 0000000..02c7cf3
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/blkcnt_t.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/blkcnt_t.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/blksize_t.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/blksize_t.h
new file mode 120000
index 0000000..1745393
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/blksize_t.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/blksize_t.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/clockid_t.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/clockid_t.h
new file mode 120000
index 0000000..b05d507
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/clockid_t.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/clockid_t.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/dev_t.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/dev_t.h
new file mode 120000
index 0000000..e403f5b
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/dev_t.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/dev_t.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/epoll.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/epoll.h
new file mode 120000
index 0000000..0364554
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/epoll.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/epoll.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/errno.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/errno.h
new file mode 120000
index 0000000..ec9b8f6
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/errno.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/errno.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/fcntl.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/fcntl.h
new file mode 120000
index 0000000..c60789c
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/fcntl.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/fcntl.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/fsblkcnt_t.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/fsblkcnt_t.h
new file mode 120000
index 0000000..c5e0d6a
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/fsblkcnt_t.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/fsblkcnt_t.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/fsfilcnt_t.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/fsfilcnt_t.h
new file mode 120000
index 0000000..b8925b8
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/fsfilcnt_t.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/fsfilcnt_t.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/gid_t.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/gid_t.h
new file mode 120000
index 0000000..1ee9676
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/gid_t.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/gid_t.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/in.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/in.h
new file mode 120000
index 0000000..e10e010
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/in.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/in.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/ino_t.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/ino_t.h
new file mode 120000
index 0000000..8da8d60
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/ino_t.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/ino_t.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/inotify.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/inotify.h
new file mode 120000
index 0000000..95578b0
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/inotify.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/inotify.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/ioctls.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/ioctls.h
new file mode 120000
index 0000000..d532c47
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/ioctls.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/ioctls.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/limits.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/limits.h
new file mode 120000
index 0000000..9f4938c
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/limits.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/limits.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/mode_t.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/mode_t.h
new file mode 120000
index 0000000..47764b7
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/mode_t.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/mode_t.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/mqueue.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/mqueue.h
new file mode 120000
index 0000000..394c37d
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/mqueue.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/mqueue.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/msg.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/msg.h
new file mode 120000
index 0000000..7c59866
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/msg.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/msg.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/nlink_t.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/nlink_t.h
new file mode 120000
index 0000000..a5c8e25
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/nlink_t.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/nlink_t.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/packet.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/packet.h
new file mode 120000
index 0000000..5a7a333
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/packet.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/packet.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/pid_t.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/pid_t.h
new file mode 120000
index 0000000..36e4068
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/pid_t.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/pid_t.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/poll.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/poll.h
new file mode 120000
index 0000000..156ddd9
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/poll.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/poll.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/ptrace.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/ptrace.h
new file mode 120000
index 0000000..1260bf7
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/ptrace.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/ptrace.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/reboot.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/reboot.h
new file mode 120000
index 0000000..23c9af3
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/reboot.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/reboot.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/resource.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/resource.h
new file mode 120000
index 0000000..e950420
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/resource.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/resource.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/seek-whence.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/seek-whence.h
new file mode 120000
index 0000000..fbd0a8f
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/seek-whence.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/seek-whence.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/shm.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/shm.h
new file mode 120000
index 0000000..f20c4fc
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/shm.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/shm.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/signal.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/signal.h
new file mode 120000
index 0000000..ae8aa10
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/signal.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/signal.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/socket.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/socket.h
new file mode 120000
index 0000000..5ddea1c
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/socket.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/socket.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/socklen_t.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/socklen_t.h
new file mode 120000
index 0000000..7db34a4
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/socklen_t.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/socklen_t.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/stat.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/stat.h
new file mode 120000
index 0000000..a307c32
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/stat.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/stat.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/statfs.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/statfs.h
new file mode 120000
index 0000000..bc1f622
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/statfs.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/statfs.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/statvfs.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/statvfs.h
new file mode 120000
index 0000000..e0b90f0
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/statvfs.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/statvfs.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/suseconds_t.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/suseconds_t.h
new file mode 120000
index 0000000..88197dd
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/suseconds_t.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/suseconds_t.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/termios.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/termios.h
new file mode 120000
index 0000000..a6bacb3
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/termios.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/termios.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/time.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/time.h
new file mode 120000
index 0000000..fa8e486
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/time.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/time.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/uid_t.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/uid_t.h
new file mode 120000
index 0000000..1aebbe3
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/uid_t.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/uid_t.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/utsname.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/utsname.h
new file mode 120000
index 0000000..0a5dbc8
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/utsname.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/utsname.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/vm-flags.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/vm-flags.h
new file mode 120000
index 0000000..6dc4788
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/vm-flags.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/vm-flags.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/wait.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/wait.h
new file mode 120000
index 0000000..a87457d
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/wait.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/wait.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/abi-bits/xattr.h b/lib/mlibc/sysdeps/ironclad/include/abi-bits/xattr.h
new file mode 120000
index 0000000..99e5aa3
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/abi-bits/xattr.h
@@ -0,0 +1 @@
+../../../../abis/ironclad/xattr.h \ No newline at end of file
diff --git a/lib/mlibc/sysdeps/ironclad/include/asm/ioctls.h b/lib/mlibc/sysdeps/ironclad/include/asm/ioctls.h
new file mode 100644
index 0000000..aa9f0b4
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/asm/ioctls.h
@@ -0,0 +1,102 @@
+#ifndef _ASM_IOCTLS_H
+#define _ASM_IOCTLS_H
+
+// List of all the IOCTLs supported, for further explanation on the meanings
+// please refer to documentation. If you did not get any, good luck!
+// Some IOCTL codes may be the same, in which case the device they are used in
+// gives them meaning. Cross-device IOCTLs have more distinct values.
+
+#define PS2MOUSE_2_1_SCALING 1
+#define PS2MOUSE_1_1_SCALING 2
+#define PS2MOUSE_SET_RES 3
+#define PS2MOUSE_SET_SAMPLE_RATE 4
+#define RTC_RD_TIME 1
+#define RTC_SET_TIME 2
+#define FIOQSIZE 0x5460
+#define TCGETS 0x5401
+#define TCSETS 0x5402
+#define TCSETSW 0x5403
+#define TCSETSF 0x5404
+#define TCGETA 0x5405
+#define TCSETA 0x5406
+#define TCSETAW 0x5407
+#define TCSETAF 0x5408
+#define TCSBRK 0x5409
+#define TCXONC 0x540A
+#define TCFLSH 0x540B
+#define TIOCEXCL 0x540C
+#define TIOCNXCL 0x540D
+#define TIOCSCTTY 0x540E
+#define TIOCGPGRP 0x540F
+#define TIOCSPGRP 0x5410
+#define TIOCOUTQ 0x5411
+#define TIOCSTI 0x5412
+#define TIOCGWINSZ 0x5413
+#define TIOCSWINSZ 0x5414
+#define TIOCMGET 0x5415
+#define TIOCMBIS 0x5416
+#define TIOCMBIC 0x5417
+#define TIOCMSET 0x5418
+#define TIOCGSOFTCAR 0x5419
+#define TIOCSSOFTCAR 0x541A
+#define FIONREAD 0x541B
+#define TIOCINQ FIONREAD
+#define TIOCLINUX 0x541C
+#define TIOCCONS 0x541D
+#define TIOCGSERIAL 0x541E
+#define TIOCSSERIAL 0x541F
+#define TIOCPKT 0x5420
+#define FIONBIO 0x5421
+#define TIOCNOTTY 0x5422
+#define TIOCSETD 0x5423
+#define TIOCGETD 0x5424
+#define TCSBRKP 0x5425
+#define TIOCSBRK 0x5427
+#define TIOCCBRK 0x5428
+#define TIOCGSID 0x5429
+#define TCGETS2 3
+#define TCSETS2 3
+#define TCSETSW2 3
+#define TCSETSF2 3
+#define TIOCGRS485 0x542E
+#define TIOCSRS485 0x542F
+#define TIOCGPTN 3
+#define TIOCSPTLCK 3
+#define TIOCGDEV 3
+#define TCGETX 0x5432
+#define TCSETX 0x5433
+#define TCSETXF 0x5434
+#define TCSETXW 0x5435
+#define TIOCSIG 0x36
+#define TIOCVHANGUP 0x5437
+#define TIOCGPKT 3
+#define TIOCGPTLCK 3
+#define TIOCGEXCL 3
+#define TIOCGPTPEER 3
+#define TIOCGISO7816 3
+#define TIOCSISO7816 3
+#define FIONCLEX 0x5450
+#define FIOCLEX 0x5451
+#define FIOASYNC 0x5452
+#define TIOCSERCONFIG 0x5453
+#define TIOCSERGWILD 0x5454
+#define TIOCSERSWILD 0x5455
+#define TIOCGLCKTRMIOS 0x5456
+#define TIOCSLCKTRMIOS 0x5457
+#define TIOCSERGSTRUCT 0x5458
+#define TIOCSERGETLSR 0x5459
+#define TIOCSERGETMULTI 0x545A
+#define TIOCSERSETMULTI 0x545B
+#define TIOCMIWAIT 0x545C
+#define TIOCGICOUNT 0x545D
+#define TIOCPKT_DATA 0
+#define TIOCPKT_FLUSHREAD 1
+#define TIOCPKT_FLUSHWRITE 2
+#define TIOCPKT_STOP 4
+#define TIOCPKT_START 8
+#define TIOCPKT_NOSTOP 16
+#define TIOCPKT_DOSTOP 32
+#define TIOCPKT_IOCTL 64
+#define TIOCSER_TEMT 0x01
+
+#endif /* _ASM_IOCTLS_H */
diff --git a/lib/mlibc/sysdeps/ironclad/include/linux/fb.h b/lib/mlibc/sysdeps/ironclad/include/linux/fb.h
new file mode 100644
index 0000000..563ce82
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/linux/fb.h
@@ -0,0 +1,397 @@
+#ifndef _SYS_FB_H
+#define _SYS_FB_H
+
+#include <stddef.h>
+
+/* Definitions of frame buffers */
+
+#define FB_MAX 32 /* sufficient for now */
+
+/* ioctls
+ 0x46 is 'F' */
+#define FBIOGET_VSCREENINFO 0x4600
+#define FBIOPUT_VSCREENINFO 0x4601
+#define FBIOGET_FSCREENINFO 0x4602
+#define FBIOGETCMAP 0x4604
+#define FBIOPUTCMAP 0x4605
+#define FBIOPAN_DISPLAY 0x4606
+#define FBIO_CURSOR _IOWR('F', 0x08, struct fb_cursor)
+/* 0x4607-0x460B are defined below */
+/* #define FBIOGET_MONITORSPEC 0x460C */
+/* #define FBIOPUT_MONITORSPEC 0x460D */
+/* #define FBIOSWITCH_MONIBIT 0x460E */
+#define FBIOGET_CON2FBMAP 0x460F
+#define FBIOPUT_CON2FBMAP 0x4610
+#define FBIOBLANK 0x4611 /* arg: 0 or vesa level + 1 */
+#define FBIOGET_VBLANK _IOR('F', 0x12, struct fb_vblank)
+#define FBIO_ALLOC 0x4613
+#define FBIO_FREE 0x4614
+#define FBIOGET_GLYPH 0x4615
+#define FBIOGET_HWCINFO 0x4616
+#define FBIOPUT_MODEINFO 0x4617
+#define FBIOGET_DISPINFO 0x4618
+
+#define FB_TYPE_PACKED_PIXELS 0 /* Packed Pixels */
+#define FB_TYPE_PLANES 1 /* Non interleaved planes */
+#define FB_TYPE_INTERLEAVED_PLANES 2 /* Interleaved planes */
+#define FB_TYPE_TEXT 3 /* Text/attributes */
+#define FB_TYPE_VGA_PLANES 4 /* EGA/VGA planes */
+#define FB_TYPE_FOURCC 5 /* Type identified by a V4L2 FOURCC */
+
+#define FB_AUX_TEXT_MDA 0 /* Monochrome text */
+#define FB_AUX_TEXT_CGA 1 /* CGA/EGA/VGA Color text */
+#define FB_AUX_TEXT_S3_MMIO 2 /* S3 MMIO fasttext */
+#define FB_AUX_TEXT_MGA_STEP16 3 /* MGA Millenium I: text, attr, 14 reserved bytes */
+#define FB_AUX_TEXT_MGA_STEP8 4 /* other MGAs: text, attr, 6 reserved bytes */
+#define FB_AUX_TEXT_SVGA_GROUP 8 /* 8-15: SVGA tileblit compatible modes */
+#define FB_AUX_TEXT_SVGA_MASK 7 /* lower three bits says step */
+#define FB_AUX_TEXT_SVGA_STEP2 8 /* SVGA text mode: text, attr */
+#define FB_AUX_TEXT_SVGA_STEP4 9 /* SVGA text mode: text, attr, 2 reserved bytes */
+#define FB_AUX_TEXT_SVGA_STEP8 10 /* SVGA text mode: text, attr, 6 reserved bytes */
+#define FB_AUX_TEXT_SVGA_STEP16 11 /* SVGA text mode: text, attr, 14 reserved bytes */
+#define FB_AUX_TEXT_SVGA_LAST 15 /* reserved up to 15 */
+
+#define FB_AUX_VGA_PLANES_VGA4 0 /* 16 color planes (EGA/VGA) */
+#define FB_AUX_VGA_PLANES_CFB4 1 /* CFB4 in planes (VGA) */
+#define FB_AUX_VGA_PLANES_CFB8 2 /* CFB8 in planes (VGA) */
+
+#define FB_VISUAL_MONO01 0 /* Monochr. 1=Black 0=White */
+#define FB_VISUAL_MONO10 1 /* Monochr. 1=White 0=Black */
+#define FB_VISUAL_TRUECOLOR 2 /* True color */
+#define FB_VISUAL_PSEUDOCOLOR 3 /* Pseudo color (like atari) */
+#define FB_VISUAL_DIRECTCOLOR 4 /* Direct color */
+#define FB_VISUAL_STATIC_PSEUDOCOLOR 5 /* Pseudo color readonly */
+#define FB_VISUAL_FOURCC 6 /* Visual identified by a V4L2 FOURCC */
+
+#define FB_ACCEL_NONE 0 /* no hardware accelerator */
+#define FB_ACCEL_ATARIBLITT 1 /* Atari Blitter */
+#define FB_ACCEL_AMIGABLITT 2 /* Amiga Blitter */
+#define FB_ACCEL_S3_TRIO64 3 /* Cybervision64 (S3 Trio64) */
+#define FB_ACCEL_NCR_77C32BLT 4 /* RetinaZ3 (NCR 77C32BLT) */
+#define FB_ACCEL_S3_VIRGE 5 /* Cybervision64/3D (S3 ViRGE) */
+#define FB_ACCEL_ATI_MACH64GX 6 /* ATI Mach 64GX family */
+#define FB_ACCEL_DEC_TGA 7 /* DEC 21030 TGA */
+#define FB_ACCEL_ATI_MACH64CT 8 /* ATI Mach 64CT family */
+#define FB_ACCEL_ATI_MACH64VT 9 /* ATI Mach 64CT family VT class */
+#define FB_ACCEL_ATI_MACH64GT 10 /* ATI Mach 64CT family GT class */
+#define FB_ACCEL_SUN_CREATOR 11 /* Sun Creator/Creator3D */
+#define FB_ACCEL_SUN_CGSIX 12 /* Sun cg6 */
+#define FB_ACCEL_SUN_LEO 13 /* Sun leo/zx */
+#define FB_ACCEL_IMS_TWINTURBO 14 /* IMS Twin Turbo */
+#define FB_ACCEL_3DLABS_PERMEDIA2 15 /* 3Dlabs Permedia 2 */
+#define FB_ACCEL_MATROX_MGA2064W 16 /* Matrox MGA2064W (Millenium) */
+#define FB_ACCEL_MATROX_MGA1064SG 17 /* Matrox MGA1064SG (Mystique) */
+#define FB_ACCEL_MATROX_MGA2164W 18 /* Matrox MGA2164W (Millenium II) */
+#define FB_ACCEL_MATROX_MGA2164W_AGP 19 /* Matrox MGA2164W (Millenium II) */
+#define FB_ACCEL_MATROX_MGAG100 20 /* Matrox G100 (Productiva G100) */
+#define FB_ACCEL_MATROX_MGAG200 21 /* Matrox G200 (Myst, Mill, ...) */
+#define FB_ACCEL_SUN_CG14 22 /* Sun cgfourteen */
+#define FB_ACCEL_SUN_BWTWO 23 /* Sun bwtwo */
+#define FB_ACCEL_SUN_CGTHREE 24 /* Sun cgthree */
+#define FB_ACCEL_SUN_TCX 25 /* Sun tcx */
+#define FB_ACCEL_MATROX_MGAG400 26 /* Matrox G400 */
+#define FB_ACCEL_NV3 27 /* nVidia RIVA 128 */
+#define FB_ACCEL_NV4 28 /* nVidia RIVA TNT */
+#define FB_ACCEL_NV5 29 /* nVidia RIVA TNT2 */
+#define FB_ACCEL_CT_6555x 30 /* C&T 6555x */
+#define FB_ACCEL_3DFX_BANSHEE 31 /* 3Dfx Banshee */
+#define FB_ACCEL_ATI_RAGE128 32 /* ATI Rage128 family */
+#define FB_ACCEL_IGS_CYBER2000 33 /* CyberPro 2000 */
+#define FB_ACCEL_IGS_CYBER2010 34 /* CyberPro 2010 */
+#define FB_ACCEL_IGS_CYBER5000 35 /* CyberPro 5000 */
+#define FB_ACCEL_SIS_GLAMOUR 36 /* SiS 300/630/540 */
+#define FB_ACCEL_3DLABS_PERMEDIA3 37 /* 3Dlabs Permedia 3 */
+#define FB_ACCEL_ATI_RADEON 38 /* ATI Radeon family */
+#define FB_ACCEL_I810 39 /* Intel 810/815 */
+#define FB_ACCEL_SIS_GLAMOUR_2 40 /* SiS 315, 650, 740 */
+#define FB_ACCEL_SIS_XABRE 41 /* SiS 330 ("Xabre") */
+#define FB_ACCEL_I830 42 /* Intel 830M/845G/85x/865G */
+#define FB_ACCEL_NV_10 43 /* nVidia Arch 10 */
+#define FB_ACCEL_NV_20 44 /* nVidia Arch 20 */
+#define FB_ACCEL_NV_30 45 /* nVidia Arch 30 */
+#define FB_ACCEL_NV_40 46 /* nVidia Arch 40 */
+#define FB_ACCEL_XGI_VOLARI_V 47 /* XGI Volari V3XT, V5, V8 */
+#define FB_ACCEL_XGI_VOLARI_Z 48 /* XGI Volari Z7 */
+#define FB_ACCEL_OMAP1610 49 /* TI OMAP16xx */
+#define FB_ACCEL_TRIDENT_TGUI 50 /* Trident TGUI */
+#define FB_ACCEL_TRIDENT_3DIMAGE 51 /* Trident 3DImage */
+#define FB_ACCEL_TRIDENT_BLADE3D 52 /* Trident Blade3D */
+#define FB_ACCEL_TRIDENT_BLADEXP 53 /* Trident BladeXP */
+#define FB_ACCEL_CIRRUS_ALPINE 53 /* Cirrus Logic 543x/544x/5480 */
+#define FB_ACCEL_NEOMAGIC_NM2070 90 /* NeoMagic NM2070 */
+#define FB_ACCEL_NEOMAGIC_NM2090 91 /* NeoMagic NM2090 */
+#define FB_ACCEL_NEOMAGIC_NM2093 92 /* NeoMagic NM2093 */
+#define FB_ACCEL_NEOMAGIC_NM2097 93 /* NeoMagic NM2097 */
+#define FB_ACCEL_NEOMAGIC_NM2160 94 /* NeoMagic NM2160 */
+#define FB_ACCEL_NEOMAGIC_NM2200 95 /* NeoMagic NM2200 */
+#define FB_ACCEL_NEOMAGIC_NM2230 96 /* NeoMagic NM2230 */
+#define FB_ACCEL_NEOMAGIC_NM2360 97 /* NeoMagic NM2360 */
+#define FB_ACCEL_NEOMAGIC_NM2380 98 /* NeoMagic NM2380 */
+#define FB_ACCEL_PXA3XX 99 /* PXA3xx */
+
+#define FB_ACCEL_SAVAGE4 0x80 /* S3 Savage4 */
+#define FB_ACCEL_SAVAGE3D 0x81 /* S3 Savage3D */
+#define FB_ACCEL_SAVAGE3D_MV 0x82 /* S3 Savage3D-MV */
+#define FB_ACCEL_SAVAGE2000 0x83 /* S3 Savage2000 */
+#define FB_ACCEL_SAVAGE_MX_MV 0x84 /* S3 Savage/MX-MV */
+#define FB_ACCEL_SAVAGE_MX 0x85 /* S3 Savage/MX */
+#define FB_ACCEL_SAVAGE_IX_MV 0x86 /* S3 Savage/IX-MV */
+#define FB_ACCEL_SAVAGE_IX 0x87 /* S3 Savage/IX */
+#define FB_ACCEL_PROSAVAGE_PM 0x88 /* S3 ProSavage PM133 */
+#define FB_ACCEL_PROSAVAGE_KM 0x89 /* S3 ProSavage KM133 */
+#define FB_ACCEL_S3TWISTER_P 0x8a /* S3 Twister */
+#define FB_ACCEL_S3TWISTER_K 0x8b /* S3 TwisterK */
+#define FB_ACCEL_SUPERSAVAGE 0x8c /* S3 Supersavage */
+#define FB_ACCEL_PROSAVAGE_DDR 0x8d /* S3 ProSavage DDR */
+#define FB_ACCEL_PROSAVAGE_DDRK 0x8e /* S3 ProSavage DDR-K */
+
+#define FB_ACCEL_PUV3_UNIGFX 0xa0 /* PKUnity-v3 Unigfx */
+
+#define FB_CAP_FOURCC 1 /* Device supports FOURCC-based formats */
+
+struct fb_fix_screeninfo {
+ char id[16]; /* identification string eg "TT Builtin" */
+ unsigned long smem_start; /* Start of frame buffer mem */
+ /* (physical address) */
+ uint32_t smem_len; /* Length of frame buffer mem */
+ uint32_t type; /* see FB_TYPE_* */
+ uint32_t type_aux; /* Interleave for interleaved Planes */
+ uint32_t visual; /* see FB_VISUAL_* */
+ uint16_t xpanstep; /* zero if no hardware panning */
+ uint16_t ypanstep; /* zero if no hardware panning */
+ uint16_t ywrapstep; /* zero if no hardware ywrap */
+ uint32_t line_length; /* length of a line in bytes */
+ unsigned long mmio_start; /* Start of Memory Mapped I/O */
+ /* (physical address) */
+ uint32_t mmio_len; /* Length of Memory Mapped I/O */
+ uint32_t accel; /* Indicate to driver which */
+ /* specific chip/card we have */
+ uint16_t capabilities; /* see FB_CAP_* */
+ uint16_t reserved[2]; /* Reserved for future compatibility */
+};
+
+/* Interpretation of offset for color fields: All offsets are from the right,
+ * inside a "pixel" value, which is exactly 'bits_per_pixel' wide (means: you
+ * can use the offset as right argument to <<). A pixel afterwards is a bit
+ * stream and is written to video memory as that unmodified.
+ *
+ * For pseudocolor: offset and length should be the same for all color
+ * components. Offset specifies the position of the least significant bit
+ * of the palette index in a pixel value. Length indicates the number
+ * of available palette entries (i.e. # of entries = 1 << length).
+ */
+struct fb_bitfield {
+ uint32_t offset; /* beginning of bitfield */
+ uint32_t length; /* length of bitfield */
+ uint32_t msb_right; /* != 0 : Most significant bit is */
+ /* right */
+};
+
+#define FB_NONSTD_HAM 1 /* Hold-And-Modify (HAM) */
+#define FB_NONSTD_REV_PIX_IN_B 2 /* order of pixels in each byte is reversed */
+
+#define FB_ACTIVATE_NOW 0 /* set values immediately (or vbl)*/
+#define FB_ACTIVATE_NXTOPEN 1 /* activate on next open */
+#define FB_ACTIVATE_TEST 2 /* don't set, round up impossible */
+#define FB_ACTIVATE_MASK 15
+ /* values */
+#define FB_ACTIVATE_VBL 16 /* activate values on next vbl */
+#define FB_CHANGE_CMAP_VBL 32 /* change colormap on vbl */
+#define FB_ACTIVATE_ALL 64 /* change all VCs on this fb */
+#define FB_ACTIVATE_FORCE 128 /* force apply even when no change*/
+#define FB_ACTIVATE_INV_MODE 256 /* invalidate videomode */
+#define FB_ACTIVATE_KD_TEXT 512 /* for KDSET vt ioctl */
+
+#define FB_ACCELF_TEXT 1 /* (OBSOLETE) see fb_info.flags and vc_mode */
+
+#define FB_SYNC_HOR_HIGH_ACT 1 /* horizontal sync high active */
+#define FB_SYNC_VERT_HIGH_ACT 2 /* vertical sync high active */
+#define FB_SYNC_EXT 4 /* external sync */
+#define FB_SYNC_COMP_HIGH_ACT 8 /* composite sync high active */
+#define FB_SYNC_BROADCAST 16 /* broadcast video timings */
+ /* vtotal = 144d/288n/576i => PAL */
+ /* vtotal = 121d/242n/484i => NTSC */
+#define FB_SYNC_ON_GREEN 32 /* sync on green */
+
+#define FB_VMODE_NONINTERLACED 0 /* non interlaced */
+#define FB_VMODE_INTERLACED 1 /* interlaced */
+#define FB_VMODE_DOUBLE 2 /* double scan */
+#define FB_VMODE_ODD_FLD_FIRST 4 /* interlaced: top line first */
+#define FB_VMODE_MASK 255
+
+#define FB_VMODE_YWRAP 256 /* ywrap instead of panning */
+#define FB_VMODE_SMOOTH_XPAN 512 /* smooth xpan possible (internally used) */
+#define FB_VMODE_CONUPDATE 512 /* don't update x/yoffset */
+
+/*
+ * Display rotation support
+ */
+#define FB_ROTATE_UR 0
+#define FB_ROTATE_CW 1
+#define FB_ROTATE_UD 2
+#define FB_ROTATE_CCW 3
+
+#define PICOS2KHZ(a) (1000000000UL/(a))
+#define KHZ2PICOS(a) (1000000000UL/(a))
+
+struct fb_var_screeninfo {
+ uint32_t xres; /* visible resolution */
+ uint32_t yres;
+ uint32_t xres_virtual; /* virtual resolution */
+ uint32_t yres_virtual;
+ uint32_t xoffset; /* offset from virtual to visible */
+ uint32_t yoffset; /* resolution */
+
+ uint32_t bits_per_pixel; /* guess what */
+ uint32_t grayscale; /* 0 = color, 1 = grayscale, */
+ /* >1 = FOURCC */
+ struct fb_bitfield red; /* bitfield in fb mem if true color, */
+ struct fb_bitfield green; /* else only length is significant */
+ struct fb_bitfield blue;
+ struct fb_bitfield transp; /* transparency */
+
+ uint32_t nonstd; /* != 0 Non standard pixel format */
+
+ uint32_t activate; /* see FB_ACTIVATE_* */
+
+ uint32_t height; /* height of picture in mm */
+ uint32_t width; /* width of picture in mm */
+
+ uint32_t accel_flags; /* (OBSOLETE) see fb_info.flags */
+
+ /* Timing: All values in pixclocks, except pixclock (of course) */
+ uint32_t pixclock; /* pixel clock in ps (pico seconds) */
+ uint32_t left_margin; /* time from sync to picture */
+ uint32_t right_margin; /* time from picture to sync */
+ uint32_t upper_margin; /* time from sync to picture */
+ uint32_t lower_margin;
+ uint32_t hsync_len; /* length of horizontal sync */
+ uint32_t vsync_len; /* length of vertical sync */
+ uint32_t sync; /* see FB_SYNC_* */
+ uint32_t vmode; /* see FB_VMODE_* */
+ uint32_t rotate; /* angle we rotate counter clockwise */
+ uint32_t colorspace; /* colorspace for FOURCC-based modes */
+ uint32_t reserved[4]; /* Reserved for future compatibility */
+};
+
+struct fb_cmap {
+ uint32_t start; /* First entry */
+ uint32_t len; /* Number of entries */
+ uint16_t *red; /* Red values */
+ uint16_t *green;
+ uint16_t *blue;
+ uint16_t *transp; /* transparency, can be NULL */
+};
+
+struct fb_con2fbmap {
+ uint32_t console;
+ uint32_t framebuffer;
+};
+
+/* VESA Blanking Levels */
+#define VESA_NO_BLANKING 0
+#define VESA_VSYNC_SUSPEND 1
+#define VESA_HSYNC_SUSPEND 2
+#define VESA_POWERDOWN 3
+
+
+enum {
+ /* screen: unblanked, hsync: on, vsync: on */
+ FB_BLANK_UNBLANK = VESA_NO_BLANKING,
+
+ /* screen: blanked, hsync: on, vsync: on */
+ FB_BLANK_NORMAL = VESA_NO_BLANKING + 1,
+
+ /* screen: blanked, hsync: on, vsync: off */
+ FB_BLANK_VSYNC_SUSPEND = VESA_VSYNC_SUSPEND + 1,
+
+ /* screen: blanked, hsync: off, vsync: on */
+ FB_BLANK_HSYNC_SUSPEND = VESA_HSYNC_SUSPEND + 1,
+
+ /* screen: blanked, hsync: off, vsync: off */
+ FB_BLANK_POWERDOWN = VESA_POWERDOWN + 1
+};
+
+#define FB_VBLANK_VBLANKING 0x001 /* currently in a vertical blank */
+#define FB_VBLANK_HBLANKING 0x002 /* currently in a horizontal blank */
+#define FB_VBLANK_HAVE_VBLANK 0x004 /* vertical blanks can be detected */
+#define FB_VBLANK_HAVE_HBLANK 0x008 /* horizontal blanks can be detected */
+#define FB_VBLANK_HAVE_COUNT 0x010 /* global retrace counter is available */
+#define FB_VBLANK_HAVE_VCOUNT 0x020 /* the vcount field is valid */
+#define FB_VBLANK_HAVE_HCOUNT 0x040 /* the hcount field is valid */
+#define FB_VBLANK_VSYNCING 0x080 /* currently in a vsync */
+#define FB_VBLANK_HAVE_VSYNC 0x100 /* verical syncs can be detected */
+
+struct fb_vblank {
+ uint32_t flags; /* FB_VBLANK flags */
+ uint32_t count; /* counter of retraces since boot */
+ uint32_t vcount; /* current scanline position */
+ uint32_t hcount; /* current scandot position */
+ uint32_t reserved[4]; /* reserved for future compatibility */
+};
+
+/* Internal HW accel */
+#define ROP_COPY 0
+#define ROP_XOR 1
+
+struct fb_copyarea {
+ uint32_t dx;
+ uint32_t dy;
+ uint32_t width;
+ uint32_t height;
+ uint32_t sx;
+ uint32_t sy;
+};
+
+struct fb_fillrect {
+ uint32_t dx; /* screen-relative */
+ uint32_t dy;
+ uint32_t width;
+ uint32_t height;
+ uint32_t color;
+ uint32_t rop;
+};
+
+struct fb_image {
+ uint32_t dx; /* Where to place image */
+ uint32_t dy;
+ uint32_t width; /* Size of image */
+ uint32_t height;
+ uint32_t fg_color; /* Only used when a mono bitmap */
+ uint32_t bg_color;
+ uint8_t depth; /* Depth of the image */
+ const char *data; /* Pointer to image data */
+ struct fb_cmap cmap; /* color map info */
+};
+
+/*
+ * hardware cursor control
+ */
+
+#define FB_CUR_SETIMAGE 0x01
+#define FB_CUR_SETPOS 0x02
+#define FB_CUR_SETHOT 0x04
+#define FB_CUR_SETCMAP 0x08
+#define FB_CUR_SETSHAPE 0x10
+#define FB_CUR_SETSIZE 0x20
+#define FB_CUR_SETALL 0xFF
+
+struct fbcurpos {
+ uint16_t x, y;
+};
+
+struct fb_cursor {
+ uint16_t set; /* what to set */
+ uint16_t enable; /* cursor on/off */
+ uint16_t rop; /* bitop operation */
+ const char *mask; /* cursor mask bits */
+ struct fbcurpos hot; /* cursor hot spot */
+ struct fb_image image; /* Cursor image */
+};
+
+/* Settings for the generic backlight code */
+#define FB_BACKLIGHT_LEVELS 128
+#define FB_BACKLIGHT_MAX 0xFF
+
+
+#endif /* _SYS_FB_H */
diff --git a/lib/mlibc/sysdeps/ironclad/include/mntent.h b/lib/mlibc/sysdeps/ironclad/include/mntent.h
new file mode 100644
index 0000000..e5e49e7
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/mntent.h
@@ -0,0 +1,46 @@
+#ifndef _MNTENT_H
+#define _MNTENT_H
+
+#include <stdio.h>
+
+// TODO: Refer to _PATH_MOUNTED
+#define MOUNTED "/etc/mtab"
+
+/* Generic mount options */
+#define MNTOPT_DEFAULTS "defaults" /* Use all default options. */
+#define MNTOPT_RO "ro" /* Read only. */
+#define MNTOPT_RW "rw" /* Read/write. */
+#define MNTOPT_SUID "suid" /* Set uid allowed. */
+#define MNTOPT_NOSUID "nosuid" /* No set uid allowed. */
+#define MNTOPT_NOAUTO "noauto" /* Do not auto mount. */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct mntent {
+ char *mnt_fsname;
+ char *mnt_dir;
+ char *mnt_type;
+ char *mnt_opts;
+ int mnt_freq;
+ int mnt_passno;
+};
+
+FILE *setmntent(const char *, const char *);
+
+struct mntent *getmntent(FILE *);
+
+int addmntent(FILE *, const struct mntent *);
+
+int endmntent(FILE *);
+
+char *hasmntopt(const struct mntent *, const char *);
+
+struct mntent *getmntent_r(FILE *, struct mntent *, char *, int);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // _MNTENT_H
diff --git a/lib/mlibc/sysdeps/ironclad/include/pty.h b/lib/mlibc/sysdeps/ironclad/include/pty.h
new file mode 100644
index 0000000..0468b46
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/pty.h
@@ -0,0 +1,16 @@
+#ifndef _PTY_H
+#define _PTY_H
+
+#include <termios.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int openpty(int *mfd, int *sfd, char *name, const struct termios *ios, const struct winsize *win);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // _PTY_H
diff --git a/lib/mlibc/sysdeps/ironclad/include/sys/ironclad_devices.h b/lib/mlibc/sysdeps/ironclad/include/sys/ironclad_devices.h
new file mode 100644
index 0000000..74f47f8
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/sys/ironclad_devices.h
@@ -0,0 +1,44 @@
+#ifndef _SYS_IRONCLAD_DEVICES_H
+#define _SYS_IRONCLAD_DEVICES_H
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <sys/types.h>
+#include <asm/ioctls.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define PS2MOUSE_2_1_SCALING 1
+#define PS2MOUSE_1_1_SCALING 2
+#define PS2MOUSE_SET_RES 3
+#define PS2MOUSE_SET_SAMPLE_RATE 4
+
+struct ironclad_mouse_data {
+ int x_variation;
+ int y_variation;
+ bool is_left;
+ bool is_right;
+};
+
+#define RTC_RD_TIME 1
+#define RTC_SET_TIME 2
+
+struct rtc_time {
+ int tm_sec;
+ int tm_min;
+ int tm_hour;
+ int tm_mday;
+ int tm_mon;
+ int tm_year;
+ int tm_wday; /* unused */
+ int tm_yday; /* unused */
+ int tm_isdst; /* unused */
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // _SYS_IRONCLAD_DEVICES_H
diff --git a/lib/mlibc/sysdeps/ironclad/include/sys/mac.h b/lib/mlibc/sysdeps/ironclad/include/sys/mac.h
new file mode 100644
index 0000000..d4cf76d
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/sys/mac.h
@@ -0,0 +1,46 @@
+#ifndef _SYS_MAC_H
+#define _SYS_MAC_H
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <sys/types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define MAC_CAP_SCHED 0b00000000001
+#define MAC_CAP_SPAWN 0b00000000010
+#define MAC_CAP_ENTROPY 0b00000000100
+#define MAC_CAP_SYS_MEM 0b00000001000
+#define MAC_CAP_USE_NET 0b00000010000
+#define MAC_CAP_SYS_NET 0b00000100000
+#define MAC_CAP_SYS_MNT 0b00001000000
+#define MAC_CAP_SYS_PWR 0b00010000000
+#define MAC_CAP_PTRACE 0b00100000000
+#define MAC_CAP_SETUID 0b01000000000
+#define MAC_CAP_SYS_MAC 0b10000000000
+#define MAC_CAP_CLOCK 0b100000000000
+#define MAC_CAP_SIGNALALL 0b1000000000000
+unsigned long get_mac_capabilities(void);
+int set_mac_capabilities(unsigned long request);
+
+#define MAC_PERM_CONTENTS 0b0000001
+#define MAC_PERM_READ 0b0000010
+#define MAC_PERM_WRITE 0b0000100
+#define MAC_PERM_EXEC 0b0001000
+#define MAC_PERM_APPEND 0b0010000
+#define MAC_PERM_FLOCK 0b0100000
+#define MAC_PERM_DEV 0b1000000
+int add_mac_permissions(const char *path, int flags);
+
+#define MAC_DENY 0b001
+#define MAC_DENY_AND_SCREAM 0b010
+#define MAC_KILL 0b100
+int set_mac_enforcement(unsigned long enforcement);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // _SYS_MAC_H
diff --git a/lib/mlibc/sysdeps/ironclad/include/sys/mount.h b/lib/mlibc/sysdeps/ironclad/include/sys/mount.h
new file mode 100644
index 0000000..51263fa
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/sys/mount.h
@@ -0,0 +1,24 @@
+#ifndef _SYS_MOUNT_H
+#define _SYS_MOUNT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define MNT_EXT 1
+#define MNT_FAT 2
+
+#define MS_RDONLY 0b001
+#define MS_REMOUNT 0b010
+#define MS_RELATIME 0b100
+
+#define MNT_FORCE 1
+
+int mount(const char *source, const char *target, int type, int flags);
+int umount(const char *target, int flags);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // _SYS_MOUNT_H
diff --git a/lib/mlibc/sysdeps/ironclad/include/sys/ptrace.h b/lib/mlibc/sysdeps/ironclad/include/sys/ptrace.h
new file mode 100644
index 0000000..3993753
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/sys/ptrace.h
@@ -0,0 +1,23 @@
+#ifndef _SYS_PTRACE_H
+#define _SYS_PTRACE_H
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <sys/types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define PTRACE_ATTACH 1
+#define PTRACE_DETACH 2
+#define PTRACE_CONT 3
+#define PTRACE_SYSCALL 4
+#define PTRACE_GETREGS 5
+int ptrace(int request, pid_t pid, void *addr, void *data);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // _SYS_PTRACE_H
diff --git a/lib/mlibc/sysdeps/ironclad/include/sys/reboot.h b/lib/mlibc/sysdeps/ironclad/include/sys/reboot.h
new file mode 100644
index 0000000..c2dbbf2
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/sys/reboot.h
@@ -0,0 +1,16 @@
+#ifndef _SYS_REBOOT_H
+#define _SYS_REBOOT_H
+
+#include <abi-bits/reboot.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int reboot(int arg);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // _SYS_REBOOT_H
diff --git a/lib/mlibc/sysdeps/ironclad/include/sys/sched2.h b/lib/mlibc/sysdeps/ironclad/include/sys/sched2.h
new file mode 100644
index 0000000..caeb86a
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/sys/sched2.h
@@ -0,0 +1,24 @@
+#ifndef _SYS_SCHED2_H
+#define _SYS_SCHED2_H
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <sys/types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define THREAD_RT 0b0001
+#define THREAD_MONO 0b0010
+#define THREAD_MLOCK 0b0100
+#define THREAD_BANNED 0b1000
+int get_thread_sched(void);
+int set_thread_sched(int flags);
+int set_deadlines(int runtime, int period);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // _SYS_SCHED2_H
diff --git a/lib/mlibc/sysdeps/ironclad/include/sys/syscall.h b/lib/mlibc/sysdeps/ironclad/include/sys/syscall.h
new file mode 100644
index 0000000..01ab016
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/sys/syscall.h
@@ -0,0 +1,187 @@
+#ifndef _SYS_SYSCALL_H
+#define _SYS_SYSCALL_H
+
+#include <stddef.h>
+
+#define SYSCALL0(NUM) ({ \
+ asm volatile ("syscall" \
+ : "=a"(ret), "=d"(errno) \
+ : "a"(NUM) \
+ : "rcx", "r11", "memory"); \
+})
+
+#define SYSCALL1(NUM, ARG0) ({ \
+ asm volatile ("syscall" \
+ : "=a"(ret), "=d"(errno) \
+ : "a"(NUM), "D"(ARG0) \
+ : "rcx", "r11", "memory"); \
+})
+
+#define SYSCALL2(NUM, ARG0, ARG1) ({ \
+ asm volatile ("syscall" \
+ : "=a"(ret), "=d"(errno) \
+ : "a"(NUM), "D"(ARG0), "S"(ARG1) \
+ : "rcx", "r11", "memory"); \
+})
+
+#define SYSCALL3(NUM, ARG0, ARG1, ARG2) ({ \
+ asm volatile ("syscall" \
+ : "=a"(ret), "=d"(errno) \
+ : "a"(NUM), "D"(ARG0), "S"(ARG1), "d"(ARG2) \
+ : "rcx", "r11", "memory"); \
+})
+
+#define SYSCALL4(NUM, ARG0, ARG1, ARG2, ARG3) ({ \
+ register __typeof(ARG3) arg_r12 asm("r12") = ARG3; \
+ asm volatile ("syscall" \
+ : "=a"(ret), "=d"(errno) \
+ : "a"(NUM), "D"(ARG0), "S"(ARG1), "d"(ARG2), \
+ "r"(arg_r12) \
+ : "rcx", "r11", "memory"); \
+})
+
+#define SYSCALL5(NUM, ARG0, ARG1, ARG2, ARG3, ARG4) ({ \
+ register __typeof(ARG3) arg_r12 asm("r12") = ARG3; \
+ register __typeof(ARG4) arg_r8 asm("r8") = ARG4; \
+ asm volatile ("syscall" \
+ : "=a"(ret), "=d"(errno) \
+ : "a"(NUM), "D"(ARG0), "S"(ARG1), "d"(ARG2), \
+ "r"(arg_r12), "r"(arg_r8) \
+ : "rcx", "r11", "memory"); \
+})
+
+#define SYSCALL6(NUM, ARG0, ARG1, ARG2, ARG3, ARG4, ARG5) ({ \
+ register __typeof(ARG3) arg_r12 asm("r12") = ARG3; \
+ register __typeof(ARG4) arg_r8 asm("r8") = ARG4; \
+ register __typeof(ARG5) arg_r9 asm("r9") = ARG5; \
+ asm volatile ("syscall" \
+ : "=a"(ret), "=d"(errno) \
+ : "a"(NUM), "D"(ARG0), "S"(ARG1), "d"(ARG2), \
+ "r"(arg_r12), "r"(arg_r8), "r"(arg_r9) \
+ : "rcx", "r11", "memory"); \
+})
+
+#define SYSCALL6(NUM, ARG0, ARG1, ARG2, ARG3, ARG4, ARG5) ({ \
+ register __typeof(ARG3) arg_r12 asm("r12") = ARG3; \
+ register __typeof(ARG4) arg_r8 asm("r8") = ARG4; \
+ register __typeof(ARG5) arg_r9 asm("r9") = ARG5; \
+ asm volatile ("syscall" \
+ : "=a"(ret), "=d"(errno) \
+ : "a"(NUM), "D"(ARG0), "S"(ARG1), "d"(ARG2), \
+ "r"(arg_r12), "r"(arg_r8), "r"(arg_r9) \
+ : "rcx", "r11", "memory"); \
+})
+
+#define SYSCALL7(NUM, ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6) ({ \
+ register __typeof(ARG3) arg_r12 asm("r12") = ARG3; \
+ register __typeof(ARG4) arg_r8 asm("r8") = ARG4; \
+ register __typeof(ARG5) arg_r9 asm("r9") = ARG5; \
+ register __typeof(ARG6) arg_r10 asm("r10") = ARG6; \
+ asm volatile ("syscall" \
+ : "=a"(ret), "=d"(errno) \
+ : "a"(NUM), "D"(ARG0), "S"(ARG1), "d"(ARG2), \
+ "r"(arg_r12), "r"(arg_r8), "r"(arg_r9), "r"(arg_r10) \
+ : "rcx", "r11", "memory"); \
+})
+
+#define SYSCALL_EXIT 0
+#define SYSCALL_ARCH_PRCTL 1
+#define SYSCALL_OPEN 2
+#define SYSCALL_CLOSE 3
+#define SYSCALL_READ 4
+#define SYSCALL_WRITE 5
+#define SYSCALL_SEEK 6
+#define SYSCALL_MMAP 7
+#define SYSCALL_MUNMAP 8
+#define SYSCALL_GETPID 9
+#define SYSCALL_GETPPID 10
+#define SYSCALL_EXEC 11
+#define SYSCALL_CLONE 12
+#define SYSCALL_WAIT 13
+#define SYSCALL_SOCKET 14
+#define SYSCALL_SETHOSTNAME 15
+#define SYSCALL_UNLINK 16
+#define SYSCALL_STAT 17
+#define SYSCALL_GETCWD 18
+#define SYSCALL_CHDIR 19
+#define SYSCALL_IOCTL 20
+#define SYSCALL_SCHED_YIELD 21
+#define SYSCALL_DELETE_TCLUSTER 22
+#define SYSCALL_PIPE 23
+#define SYSCALL_GETUID 24
+#define SYSCALL_RENAME 25
+#define SYSCALL_SYSCONF 26
+#define SYSCALL_SPAWN 27
+#define SYSCALL_GETTID 28
+#define SYSCALL_MANAGE_TCLUSTER 29
+#define SYSCALL_FCNTL 30
+#define SYSCALL_EXIT_THREAD 31
+#define SYSCALL_GETRANDOM 32
+#define SYSCALL_MPROTECT 33
+#define SYSCALL_SYNC 34
+#define SYSCALL_SET_MAC_CAPABILITIES 35
+#define SYSCALL_GET_MAC_CAPABILITIES 36
+#define SYSCALL_ADD_MAC_PERMISSIONS 37
+#define SYSCALL_SET_MAC_ENFORCEMENT 38
+#define SYSCALL_MOUNT 39
+#define SYSCALL_UMOUNT 40
+#define SYSCALL_READLINK 41
+#define SYSCALL_GETDENTS 42
+#define SYSCALL_MAKENODE 43
+#define SYSCALL_TRUNCATE 44
+#define SYSCALL_BIND 45
+#define SYSCALL_SYMLINK 46
+#define SYSCALL_CONNECT 47
+#define SYSCALL_OPENPTY 48
+#define SYSCALL_FSYNC 49
+#define SYSCALL_LINK 50
+#define SYSCALL_PTRACE 51
+#define SYSCALL_LISTEN 52
+#define SYSCALL_ACCEPT 53
+#define SYSCALL_GETRLIMIT 54
+#define SYSCALL_SETRLIMIT 55
+#define SYSCALL_ACCESS 56
+#define SYSCALL_POLL 57
+#define SYSCALL_GETEUID 58
+#define SYSCALL_SETUIDS 59
+#define SYSCALL_FCHMOD 60
+#define SYSCALL_UMASK 61
+#define SYSCALL_REBOOT 62
+#define SYSCALL_FCHOWN 63
+#define SYSCALL_PREAD 64
+#define SYSCALL_PWRITE 65
+#define SYSCALL_GETSOCKNAME 66
+#define SYSCALL_GETPEERNAME 67
+#define SYSCALL_SHUTDOWN 68
+#define SYSCALL_FUTEX 69
+#define SYSCALL_CLOCK 70
+#define SYSCALL_CLOCK_NANOSLEEP 71
+#define SYSCALL_GETRUSAGE 72
+#define SYSCALL_RECVFROM 73
+#define SYSCALL_SENDTO 74
+#define SYSCALL_CONFIG_NETINTER 75
+#define SYSCALL_UTIMES 76
+#define SYSCALL_CREATE_TCLUSTER 77
+#define SYSCALL_SWITCH_TCLUSTER 78
+#define SYSCALL_ACTUALLY_KILL 79
+#define SYSCALL_SIGNALPOST 80
+#define SYSCALL_SEND_SIGNAL 81
+#define SYSCALL_GETPRIO 82
+#define SYSCALL_SETPRIO 83
+#define SYSCALL_GETGID 84
+#define SYSCALL_GETEGID 85
+#define SYSCALL_SETGIDS 86
+#define SYSCALL_GETGROUPS 87
+#define SYSCALL_SETGROUPS 88
+#define SYSCALL_TTYNAME 89
+#define SYSCALL_FADVISE 90
+#define SYSCALL_SHMAT 91
+#define SYSCALL_SHMCTL 92
+#define SYSCALL_SHMDT 93
+#define SYSCALL_SHMGET 94
+#define SYSCALL_GETSOCKOPT 95
+#define SYSCALL_SETSOCKOPT 96
+#define SYSCALL_GETTIDID 97
+#define SYSCALL_SETTIDID 98
+
+#endif // _SYS_SYSCALL_H
diff --git a/lib/mlibc/sysdeps/ironclad/include/utmpx.h b/lib/mlibc/sysdeps/ironclad/include/utmpx.h
new file mode 100644
index 0000000..2d7d3e1
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/include/utmpx.h
@@ -0,0 +1,63 @@
+
+#ifndef _UTMPX_H
+#define _UTMPX_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <abi-bits/pid_t.h>
+#include <bits/posix/timeval.h>
+
+#define UTMPX_FILE "/var/run/utmp"
+#define WTMPX_FILE "/var/run/wtmp"
+
+// Struct definition taken from musl
+struct utmpx {
+ short ut_type;
+ short __ut_pad1;
+ pid_t ut_pid;
+ char ut_line[32];
+ char ut_id[4];
+ char ut_user[32];
+ char ut_host[256];
+ struct {
+ short __e_termination;
+ short __e_exit;
+ } ut_exit;
+ int ut_session, __ut_pad2;
+ struct timeval ut_tv;
+ unsigned ut_addr_v6[4];
+ char __unused[20];
+};
+
+#ifndef __MLIBC_ABI_ONLY
+
+void updwtmpx(const char *, const struct utmpx *);
+int utmpxname(const char *);
+struct utmpx *pututxline(const struct utmpx *);
+struct utmpx *getutxent(void);
+void setutxent(void);
+void endutxent(void);
+
+#endif /* !__MLIBC_ABI_ONLY */
+
+#define EMPTY 0
+#define RUN_LVL 1
+#define BOOT_TIME 2
+#define NEW_TIME 3
+#define OLD_TIME 4
+#define INIT_PROCESS 5
+#define LOGIN_PROCESS 6
+#define USER_PROCESS 7
+#define DEAD_PROCESS 8
+
+#define __UT_HOSTSIZE 256
+#define __UT_NAMESIZE 32
+#define __UT_LINESIZE 32
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // _UTMPX_H
diff --git a/lib/mlibc/sysdeps/ironclad/meson.build b/lib/mlibc/sysdeps/ironclad/meson.build
new file mode 100644
index 0000000..a23203c
--- /dev/null
+++ b/lib/mlibc/sysdeps/ironclad/meson.build
@@ -0,0 +1,125 @@
+
+rtdl_sources += files(
+ 'generic/generic.cpp'
+)
+
+libc_sources += files(
+ 'generic/entry.cpp',
+ 'generic/ptrace.cpp',
+ 'generic/generic.cpp',
+ 'generic/mntent.cpp',
+ 'generic/mount.cpp',
+ 'generic/reboot.cpp',
+ 'generic/pty.cpp',
+ 'generic/thread.cpp',
+ 'generic/mac.cpp',
+ 'generic/sched2.cpp',
+ 'generic/thread.S',
+ 'generic/utmpx.cpp'
+)
+
+if not no_headers
+ install_headers(
+ 'include/abi-bits/access.h',
+ 'include/abi-bits/auxv.h',
+ 'include/abi-bits/seek-whence.h',
+ 'include/abi-bits/vm-flags.h',
+ 'include/abi-bits/errno.h',
+ 'include/abi-bits/fcntl.h',
+ 'include/abi-bits/in.h',
+ 'include/abi-bits/reboot.h',
+ 'include/abi-bits/resource.h',
+ 'include/abi-bits/stat.h',
+ 'include/abi-bits/signal.h',
+ 'include/abi-bits/socket.h',
+ 'include/abi-bits/termios.h',
+ 'include/abi-bits/time.h',
+ 'include/abi-bits/blkcnt_t.h',
+ 'include/abi-bits/blksize_t.h',
+ 'include/abi-bits/dev_t.h',
+ 'include/abi-bits/gid_t.h',
+ 'include/abi-bits/ino_t.h',
+ 'include/abi-bits/mode_t.h',
+ 'include/abi-bits/nlink_t.h',
+ 'include/abi-bits/pid_t.h',
+ 'include/abi-bits/uid_t.h',
+ 'include/abi-bits/wait.h',
+ 'include/abi-bits/limits.h',
+ 'include/abi-bits/utsname.h',
+ 'include/abi-bits/ptrace.h',
+ 'include/abi-bits/poll.h',
+ 'include/abi-bits/epoll.h',
+ 'include/abi-bits/packet.h',
+ 'include/abi-bits/inotify.h',
+ 'include/abi-bits/clockid_t.h',
+ 'include/abi-bits/shm.h',
+ 'include/abi-bits/mqueue.h',
+ 'include/abi-bits/suseconds_t.h',
+ 'include/abi-bits/fsfilcnt_t.h',
+ 'include/abi-bits/fsblkcnt_t.h',
+ 'include/abi-bits/socklen_t.h',
+ 'include/abi-bits/statfs.h',
+ 'include/abi-bits/statvfs.h',
+ 'include/abi-bits/ioctls.h',
+ 'include/abi-bits/xattr.h',
+ 'include/abi-bits/msg.h',
+ subdir: 'abi-bits',
+ follow_symlinks: true
+ )
+ install_headers(
+ 'include/sys/sched2.h',
+ 'include/sys/ironclad_devices.h',
+ 'include/sys/mac.h',
+ 'include/sys/syscall.h',
+ 'include/sys/reboot.h',
+ 'include/sys/mount.h',
+ 'include/sys/ptrace.h',
+ subdir: 'sys'
+ )
+
+ install_headers(
+ 'include/asm/ioctls.h',
+ subdir: 'asm'
+ )
+
+ install_headers(
+ 'include/linux/fb.h',
+ subdir: 'linux'
+ )
+
+ install_headers(
+ 'include/mntent.h',
+ 'include/pty.h',
+ 'include/utmpx.h'
+ )
+endif
+
+if not headers_only
+ crt = custom_target('crt0',
+ build_by_default: true,
+ command: c_compiler.cmd_array() + ['-c', '-o', '@OUTPUT@', '@INPUT@'],
+ input: 'crt-x86_64/crt0.S',
+ output: 'crt0.o',
+ install: true,
+ install_dir: get_option('libdir')
+ )
+
+ custom_target('crti',
+ build_by_default: true,
+ command: c_compiler.cmd_array() + ['-c', '-o', '@OUTPUT@', '@INPUT@'],
+ input: 'crt-x86_64/crti.S',
+ output: 'crti.o',
+ install: true,
+ install_dir: get_option('libdir')
+ )
+
+ custom_target('crtn',
+ build_by_default: true,
+ command: c_compiler.cmd_array() + ['-c', '-o', '@OUTPUT@', '@INPUT@'],
+ input: 'crt-x86_64/crtn.S',
+ output: 'crtn.o',
+ install: true,
+ install_dir: get_option('libdir')
+ )
+endif
+