diff --git a/.github/workflows/detect-bad-ifs.yml b/.github/workflows/detect-bad-ifs.yml new file mode 100644 index 0000000000..c738d29558 --- /dev/null +++ b/.github/workflows/detect-bad-ifs.yml @@ -0,0 +1,17 @@ +name: Detect ifdef/defined (mis)use + +on: [push, pull_request] + +jobs: + find-misuse: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - run: | + printf '(^#ifn?def[[:space:]]+|defined[[:space:]]*[(][[:space:]]*)((%s)([^_A-Za-z0-9]|$))\0' \ + "$(printf '%s' "$(awk '/#mesondefine/ { print $2 }' mlibc-config.h.in)" | tr '\n' '|')" \ + | { ! xargs -0I '{}' grep --color=always -PR '{}' \ + || { echo 'found misuse'; exit 1; }; } + + +# vim: set sw=2 : diff --git a/abis/wivos/seek-whence.h b/abis/wivos/seek-whence.h new file mode 100644 index 0000000000..ad8f468d77 --- /dev/null +++ b/abis/wivos/seek-whence.h @@ -0,0 +1,8 @@ +#ifndef _ABIBITS_SEEK_WHENCE_H +#define _ABIBITS_SEEK_WHENCE_H + +#define SEEK_CUR 1 +#define SEEK_END 2 +#define SEEK_SET 0 + +#endif // _ABIBITS_SEEK_WHENCE_H diff --git a/meson.build b/meson.build index b629f39761..8f0f409c80 100644 --- a/meson.build +++ b/meson.build @@ -256,6 +256,10 @@ elif host_machine.system() == 'dripos' rtld_include_dirs += include_directories('sysdeps/dripos/include') libc_include_dirs += include_directories('sysdeps/dripos/include') subdir('sysdeps/dripos') +elif host_machine.system() == 'wivos' + rtld_include_dirs += include_directories('sysdeps/wivos/include') + libc_include_dirs += include_directories('sysdeps/wivos/include') + subdir('sysdeps/wivos') elif host_machine.system() == 'astral' rtld_include_dirs += include_directories('sysdeps/astral/include') libc_include_dirs += include_directories('sysdeps/astral/include') diff --git a/options/posix/include/sched.h b/options/posix/include/sched.h index 5d745dda29..4c99291593 100644 --- a/options/posix/include/sched.h +++ b/options/posix/include/sched.h @@ -41,6 +41,10 @@ int sched_getparam(pid_t __pid, struct sched_param *__param); #endif /* !__MLIBC_ABI_ONLY */ +#if __MLIBC_LINUX_OPTION +#include +#endif + #ifdef __cplusplus } #endif diff --git a/subprojects/frigg.wrap b/subprojects/frigg.wrap index 89c7ccb0ee..839a8ee503 100644 --- a/subprojects/frigg.wrap +++ b/subprojects/frigg.wrap @@ -1,4 +1,4 @@ [wrap-git] directory = frigg url = https://github.com/managarm/frigg.git -revision = master +revision = f68684d2a600322a3a81c2ba1ea529fd37b6623a diff --git a/sysdeps/ironclad/crt-x86_64/crt0.S b/sysdeps/ironclad/crt-x86_64/crt0.S index ecf7740474..722add88ec 100644 --- a/sysdeps/ironclad/crt-x86_64/crt0.S +++ b/sysdeps/ironclad/crt-x86_64/crt0.S @@ -6,3 +6,5 @@ _start: call __mlibc_entry .section .note.GNU-stack,"",%progbits +.section .note.GNU-stack,"",%progbits + diff --git a/sysdeps/ironclad/include/abi-bits/ioctls.h b/sysdeps/ironclad/include/abi-bits/ioctls.h index d532c47097..595106b6fd 120000 --- a/sysdeps/ironclad/include/abi-bits/ioctls.h +++ b/sysdeps/ironclad/include/abi-bits/ioctls.h @@ -1 +1 @@ -../../../../abis/ironclad/ioctls.h \ No newline at end of file +../../../../abis/linux/ioctls.h \ No newline at end of file diff --git a/sysdeps/wivos/crt-x86_64/crt0.S b/sysdeps/wivos/crt-x86_64/crt0.S new file mode 100644 index 0000000000..62298e3708 --- /dev/null +++ b/sysdeps/wivos/crt-x86_64/crt0.S @@ -0,0 +1,10 @@ +.section .text + +.global _start +_start: + mov $main, %rdi + call __mlibc_entry + +.size _start, . - _start +.section .note.GNU-stack,"",%progbits + diff --git a/sysdeps/wivos/generic/entry.cpp b/sysdeps/wivos/generic/entry.cpp new file mode 100644 index 0000000000..288aaf3d1d --- /dev/null +++ b/sysdeps/wivos/generic/entry.cpp @@ -0,0 +1,76 @@ +#include +#include +#include +#include +#include +#include +#include + +extern "C" void __dlapi_enter(uintptr_t *); + +extern char **environ; + +struct GPRState { + uint64_t ds; + uint64_t es; + uint64_t rax; + uint64_t rbx; + uint64_t rcx; + uint64_t rdx; + uint64_t rsi; + uint64_t rdi; + uint64_t rbp; + uint64_t r8; + uint64_t r9; + uint64_t r10; + uint64_t r11; + uint64_t r12; + uint64_t r13; + uint64_t r14; + uint64_t r15; + uint64_t err; + uint64_t rip; + uint64_t cs; + uint64_t rflags; + uint64_t rsp; + uint64_t ss; +}; + +namespace mlibc { + [[noreturn]] int sys_sigreturn(void *context, sigset_t old_mask) { + (void)context; + (void)old_mask; + //TODO + while(1); + //__syscall(30, context, old_mask); + //__builtin_unreachable(); + } +} + +static void __mlibc_sigentry(int which, siginfo_t *siginfo, + void (*sa)(int, siginfo_t *, void *), + GPRState *ret_context, sigset_t prev_mask) { + switch ((uintptr_t)sa) { + // DFL + case (uintptr_t)(-2): + mlibc::infoLogger() << "mlibc: Unhandled signal " << which << frg::endlog; + mlibc::sys_exit(128 + which); + // IGN + case (uintptr_t)(-3): + break; + default: + sa(which, siginfo, NULL); + break; + } + + mlibc::sys_sigreturn(ret_context, prev_mask); + + __builtin_unreachable(); +} + +extern "C" void __mlibc_entry(uintptr_t *entry_stack, int (*main_fn)(int argc, char *argv[], char *env[])) { + __dlapi_enter(entry_stack); + + auto result = main_fn(mlibc::entry_stack.argc, mlibc::entry_stack.argv, environ); + exit(result); +} diff --git a/sysdeps/wivos/generic/generic.cpp b/sysdeps/wivos/generic/generic.cpp new file mode 100644 index 0000000000..9e2f4e983a --- /dev/null +++ b/sysdeps/wivos/generic/generic.cpp @@ -0,0 +1,141 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#define STUB_ONLY { \ + __ensure(!"STUB_ONLY function was called"); \ + __builtin_unreachable(); \ +} + +namespace mlibc { + void sys_libc_log(const char *message) { + syscall1(SYS_DEBUG, (uint64_t)message); + } + + [[noreturn]] void sys_libc_panic() { + sys_libc_log("mlibc Panic"); + while(1); + } + + int sys_tcb_set(void *pointer) { + return syscall1(SYS_TCB_SET, (uint64_t)pointer); + } + + int sys_futex_wait(int *pointer, int expected, const struct timespec *time) STUB_ONLY + int sys_futex_wake(int *pointer) STUB_ONLY + + int sys_anon_allocate(size_t size, void **pointer) { + *pointer = (void *)syscall2(SYS_ALLOC, (uint64_t)0, size / page_size); + + return 0; + } + + int sys_anon_free(void *pointer, size_t size) { //Stub, for now we don't free + (void)pointer; (void)size; + return 0; + } + + int sys_open(const char *pathname, int flags, mode_t mode, int *fd) { + int ret = syscall2(SYS_OPEN, (uint64_t)pathname, flags); + if(ret < 0) return -1; //TODO: Errno + + *fd = ret; + return 0; + } + int sys_read(int fd, void *buf, size_t count, ssize_t *bytes_read) { + ssize_t retValue = syscall3(SYS_READ, fd, (uint64_t)buf, count); + if(retValue < 0) { + if(bytes_read) *bytes_read = 0; + return -1; //TODO: Errno + } + + if(bytes_read) *bytes_read = (size_t)retValue; + return 0; + } + int sys_seek(int fd, off_t offset, int whence, off_t *new_offset) { + size_t retValue = syscall3(SYS_SEEK, fd, (uint64_t)offset, whence); + if(retValue < 0) return -1; //TODO: Errno + + *new_offset = retValue; + return 0; + } + int sys_close(int fd) { + int ret = syscall1(SYS_CLOSE, (uint64_t)fd); + if(ret < 0) return -1; //TODO: Errno + + return 0; + } + + // mlibc assumes that anonymous memory returned by sys_vm_map() is zeroed by the kernel / whatever is behind the sysdeps + int sys_vm_map(void *hint, size_t size, int prot, int flags, int fd, off_t offset, void **window) { + __ensure(flags & MAP_ANONYMOUS); + + size_t pageCount = (size + page_size - 1) / page_size; + size_t resValue = syscall2(SYS_ALLOC, (uint64_t)hint, pageCount); + if(!resValue) return -1; + + *window = (void *)resValue; + return 0; + } + int sys_vm_unmap(void *pointer, size_t size) STUB_ONLY + + [[noreturn]] void sys_exit(int status) STUB_ONLY + + int sys_write(int fd, const void *buf, size_t count, ssize_t *bytes_written) { + size_t retValue = syscall3(SYS_WRITE, fd, (uint64_t)buf, count); + if(retValue < 0) { + if(bytes_written) *bytes_written = 0; + return -1; //TODO: Errno + } + + if(bytes_written) *bytes_written = retValue; + return 0; + } + + int sys_clock_get(int clock, time_t *secs, long *nanos) STUB_ONLY + + int sys_fork(pid_t *child) { + pid_t pid = syscall0(SYS_FORK); + if(pid < 0) { + //errno = pid; + return -1; + } + + *child = pid; + return 0; + } + + int sys_ioctl(int fd, uint64_t request, void *arg, int *result) { + sc_qword_t ret = syscall3(SYS_IOCTL, fd, request, (sc_qword_t)arg); + + if ((int64_t)ret < 0) + return ret; + + *result = (int32_t)(int64_t)ret; + return 0; + } + + int sys_isatty(int fd) { + struct winsize ws; + int ret; + + if (!sys_ioctl(fd, TIOCGWINSZ, &ws, &ret)) + return 0; + + return ENOTTY; + } + + int sys_execve(const char *path, char *const argv[], char *const envp[]){ + sc_qword_t ret = syscall3(SYS_EXECVE, (sc_qword_t)path, (sc_qword_t)argv, (sc_qword_t)envp); + + return (int)ret; + } +}; \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/access.h b/sysdeps/wivos/include/abi-bits/access.h new file mode 120000 index 0000000000..cb83931670 --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/access.h @@ -0,0 +1 @@ +../../../../abis/linux/access.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/auxv.h b/sysdeps/wivos/include/abi-bits/auxv.h new file mode 120000 index 0000000000..c43f878641 --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/auxv.h @@ -0,0 +1 @@ +../../../../abis/linux/auxv.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/blkcnt_t.h b/sysdeps/wivos/include/abi-bits/blkcnt_t.h new file mode 120000 index 0000000000..0b0ec270d7 --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/blkcnt_t.h @@ -0,0 +1 @@ +../../../../abis/linux/blkcnt_t.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/blksize_t.h b/sysdeps/wivos/include/abi-bits/blksize_t.h new file mode 120000 index 0000000000..7dc8d7cfa6 --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/blksize_t.h @@ -0,0 +1 @@ +../../../../abis/linux/blksize_t.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/clockid_t.h b/sysdeps/wivos/include/abi-bits/clockid_t.h new file mode 120000 index 0000000000..6a42da56aa --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/clockid_t.h @@ -0,0 +1 @@ +../../../../abis/linux/clockid_t.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/dev_t.h b/sysdeps/wivos/include/abi-bits/dev_t.h new file mode 120000 index 0000000000..bca881e92c --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/dev_t.h @@ -0,0 +1 @@ +../../../../abis/linux/dev_t.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/epoll.h b/sysdeps/wivos/include/abi-bits/epoll.h new file mode 120000 index 0000000000..eb4b76dcfc --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/epoll.h @@ -0,0 +1 @@ +../../../../abis/linux/epoll.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/errno.h b/sysdeps/wivos/include/abi-bits/errno.h new file mode 120000 index 0000000000..6e507deff2 --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/errno.h @@ -0,0 +1 @@ +../../../../abis/linux/errno.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/fcntl.h b/sysdeps/wivos/include/abi-bits/fcntl.h new file mode 120000 index 0000000000..463e2c9545 --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/fcntl.h @@ -0,0 +1 @@ +../../../../abis/linux/fcntl.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/fsblkcnt_t.h b/sysdeps/wivos/include/abi-bits/fsblkcnt_t.h new file mode 120000 index 0000000000..898dfb2f32 --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/fsblkcnt_t.h @@ -0,0 +1 @@ +../../../../abis/linux/fsblkcnt_t.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/fsfilcnt_t.h b/sysdeps/wivos/include/abi-bits/fsfilcnt_t.h new file mode 120000 index 0000000000..791755c9c8 --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/fsfilcnt_t.h @@ -0,0 +1 @@ +../../../../abis/linux/fsfilcnt_t.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/gid_t.h b/sysdeps/wivos/include/abi-bits/gid_t.h new file mode 120000 index 0000000000..abce6d69ad --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/gid_t.h @@ -0,0 +1 @@ +../../../../abis/linux/gid_t.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/in.h b/sysdeps/wivos/include/abi-bits/in.h new file mode 120000 index 0000000000..418d1d5c04 --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/in.h @@ -0,0 +1 @@ +../../../../abis/linux/in.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/ino_t.h b/sysdeps/wivos/include/abi-bits/ino_t.h new file mode 120000 index 0000000000..4c20aca26a --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/ino_t.h @@ -0,0 +1 @@ +../../../../abis/linux/ino_t.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/inotify.h b/sysdeps/wivos/include/abi-bits/inotify.h new file mode 120000 index 0000000000..b5cb28237a --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/inotify.h @@ -0,0 +1 @@ +../../../../abis/linux/inotify.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/ioctls.h b/sysdeps/wivos/include/abi-bits/ioctls.h new file mode 120000 index 0000000000..595106b6fd --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/ioctls.h @@ -0,0 +1 @@ +../../../../abis/linux/ioctls.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/limits.h b/sysdeps/wivos/include/abi-bits/limits.h new file mode 120000 index 0000000000..6c88db2ed6 --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/limits.h @@ -0,0 +1 @@ +../../../../abis/linux/limits.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/mode_t.h b/sysdeps/wivos/include/abi-bits/mode_t.h new file mode 120000 index 0000000000..5d78fdfc3b --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/mode_t.h @@ -0,0 +1 @@ +../../../../abis/linux/mode_t.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/mqueue.h b/sysdeps/wivos/include/abi-bits/mqueue.h new file mode 120000 index 0000000000..fa87b078ad --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/mqueue.h @@ -0,0 +1 @@ +../../../../abis/linux/mqueue.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/msg.h b/sysdeps/wivos/include/abi-bits/msg.h new file mode 120000 index 0000000000..f402b49306 --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/msg.h @@ -0,0 +1 @@ +../../../../abis/linux/msg.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/nlink_t.h b/sysdeps/wivos/include/abi-bits/nlink_t.h new file mode 120000 index 0000000000..bb3b625c32 --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/nlink_t.h @@ -0,0 +1 @@ +../../../../abis/linux/nlink_t.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/packet.h b/sysdeps/wivos/include/abi-bits/packet.h new file mode 120000 index 0000000000..998ef1ab03 --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/packet.h @@ -0,0 +1 @@ +../../../../abis/linux/packet.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/pid_t.h b/sysdeps/wivos/include/abi-bits/pid_t.h new file mode 120000 index 0000000000..baa90f6af6 --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/pid_t.h @@ -0,0 +1 @@ +../../../../abis/linux/pid_t.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/poll.h b/sysdeps/wivos/include/abi-bits/poll.h new file mode 120000 index 0000000000..8ea6a0a39c --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/poll.h @@ -0,0 +1 @@ +../../../../abis/linux/poll.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/ptrace.h b/sysdeps/wivos/include/abi-bits/ptrace.h new file mode 120000 index 0000000000..b2517b2cf1 --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/ptrace.h @@ -0,0 +1 @@ +../../../../abis/linux/ptrace.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/reboot.h b/sysdeps/wivos/include/abi-bits/reboot.h new file mode 120000 index 0000000000..77013a4162 --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/reboot.h @@ -0,0 +1 @@ +../../../../abis/linux/reboot.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/resource.h b/sysdeps/wivos/include/abi-bits/resource.h new file mode 120000 index 0000000000..88d74025fa --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/resource.h @@ -0,0 +1 @@ +../../../../abis/linux/resource.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/seek-whence.h b/sysdeps/wivos/include/abi-bits/seek-whence.h new file mode 120000 index 0000000000..df7bccf02c --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/seek-whence.h @@ -0,0 +1 @@ +../../../../abis/linux/seek-whence.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/shm.h b/sysdeps/wivos/include/abi-bits/shm.h new file mode 120000 index 0000000000..067d8c4fa5 --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/shm.h @@ -0,0 +1 @@ +../../../../abis/linux/shm.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/signal.h b/sysdeps/wivos/include/abi-bits/signal.h new file mode 120000 index 0000000000..709546b101 --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/signal.h @@ -0,0 +1 @@ +../../../../abis/vinix/signal.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/socket.h b/sysdeps/wivos/include/abi-bits/socket.h new file mode 120000 index 0000000000..f1dc016e6d --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/socket.h @@ -0,0 +1 @@ +../../../../abis/linux/socket.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/socklen_t.h b/sysdeps/wivos/include/abi-bits/socklen_t.h new file mode 120000 index 0000000000..41f3b11f38 --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/socklen_t.h @@ -0,0 +1 @@ +../../../../abis/linux/socklen_t.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/stat.h b/sysdeps/wivos/include/abi-bits/stat.h new file mode 120000 index 0000000000..1f63b41fdf --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/stat.h @@ -0,0 +1 @@ +../../../../abis/linux/stat.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/statfs.h b/sysdeps/wivos/include/abi-bits/statfs.h new file mode 120000 index 0000000000..e3d202f538 --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/statfs.h @@ -0,0 +1 @@ +../../../../abis/linux/statfs.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/statvfs.h b/sysdeps/wivos/include/abi-bits/statvfs.h new file mode 120000 index 0000000000..d0bdd40859 --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/statvfs.h @@ -0,0 +1 @@ +../../../../abis/lyre/statvfs.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/statx.h b/sysdeps/wivos/include/abi-bits/statx.h new file mode 120000 index 0000000000..8702a1d000 --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/statx.h @@ -0,0 +1 @@ +../../../../abis/linux/statx.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/suseconds_t.h b/sysdeps/wivos/include/abi-bits/suseconds_t.h new file mode 120000 index 0000000000..9ed659770e --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/suseconds_t.h @@ -0,0 +1 @@ +../../../../abis/linux/suseconds_t.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/termios.h b/sysdeps/wivos/include/abi-bits/termios.h new file mode 120000 index 0000000000..ee8f0b091a --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/termios.h @@ -0,0 +1 @@ +../../../../abis/linux/termios.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/time.h b/sysdeps/wivos/include/abi-bits/time.h new file mode 120000 index 0000000000..2a02625743 --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/time.h @@ -0,0 +1 @@ +../../../../abis/linux/time.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/uid_t.h b/sysdeps/wivos/include/abi-bits/uid_t.h new file mode 120000 index 0000000000..b306777852 --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/uid_t.h @@ -0,0 +1 @@ +../../../../abis/linux/uid_t.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/utsname.h b/sysdeps/wivos/include/abi-bits/utsname.h new file mode 120000 index 0000000000..b28575474a --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/utsname.h @@ -0,0 +1 @@ +../../../../abis/linux/utsname.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/vm-flags.h b/sysdeps/wivos/include/abi-bits/vm-flags.h new file mode 120000 index 0000000000..bbe258cff1 --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/vm-flags.h @@ -0,0 +1 @@ +../../../../abis/linux/vm-flags.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/wait.h b/sysdeps/wivos/include/abi-bits/wait.h new file mode 120000 index 0000000000..feb2840c5e --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/wait.h @@ -0,0 +1 @@ +../../../../abis/linux/wait.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/xattr.h b/sysdeps/wivos/include/abi-bits/xattr.h new file mode 120000 index 0000000000..66412d7061 --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/xattr.h @@ -0,0 +1 @@ +../../../../abis/linux/xattr.h \ No newline at end of file diff --git a/sysdeps/wivos/include/wivos/syscall.h b/sysdeps/wivos/include/wivos/syscall.h new file mode 100644 index 0000000000..21a39f24e3 --- /dev/null +++ b/sysdeps/wivos/include/wivos/syscall.h @@ -0,0 +1,111 @@ +#ifndef SYSCALL_H +#define SYSCALL_H + +#include +#include + +#define SYS_DEBUG 0x0 +#define SYS_READ 0x1 +#define SYS_WRITE 0x2 +#define SYS_OPEN 0x3 +#define SYS_CLOSE 0x4 +#define SYS_ALLOC 0x5 +#define SYS_SEEK 0x6 +#define SYS_TCB_SET 0x7 +#define SYS_FORK 0x8 +#define SYS_IOCTL 0x9 +#define SYS_EXECVE 0xA + +// Invalid syscall used to trigger a log error in the kernel (as a hint) +// so, that we can implement the syscall in the kernel. +#define UNIMPLEMENTED(FUNCTION_NAME) \ + { \ + sys_libc_log("Unimplemented syscall: " FUNCTION_NAME); \ + sys_exit(1); \ + __builtin_unreachable(); \ + } + +extern "C" { +using sc_qword_t = uint64_t; + +static sc_qword_t syscall0(int sc) { + sc_qword_t ret; + asm volatile("syscall" : "=a"(ret) : "a"(sc) : "rcx", "r11", "memory"); + return ret; +} + +static sc_qword_t syscall1(int sc, uint64_t arg1) { + sc_qword_t ret; + asm volatile("syscall" + : "=a"(ret) + : "a"(sc), "D"(arg1) + : "rcx", "r11", "memory"); + return ret; +} + +static sc_qword_t syscall2(int sc, sc_qword_t arg1, sc_qword_t arg2) { + sc_qword_t ret; + asm volatile("syscall" + : "=a"(ret) + : "a"(sc), "D"(arg1), "S"(arg2) + : "rcx", "r11", "memory"); + return ret; +} + +static sc_qword_t syscall3(int sc, sc_qword_t arg1, sc_qword_t arg2, + sc_qword_t arg3) { + sc_qword_t ret; + asm volatile("syscall" + : "=a"(ret) + : "a"(sc), "D"(arg1), "S"(arg2), "d"(arg3) + : "rcx", "r11", "memory"); + return ret; +} + +static sc_qword_t syscall4(int sc, sc_qword_t arg1, sc_qword_t arg2, + sc_qword_t arg3, sc_qword_t arg4) { + sc_qword_t ret; + + register sc_qword_t arg4_reg asm("r10") = arg4; + + asm volatile("syscall" + : "=a"(ret) + : "a"(sc), "D"(arg1), "S"(arg2), "d"(arg3), "r"(arg4_reg) + : "rcx", "r11", "memory"); + return ret; +} + +static sc_qword_t syscall5(int sc, sc_qword_t arg1, sc_qword_t arg2, + sc_qword_t arg3, sc_qword_t arg4, sc_qword_t arg5) { + sc_qword_t ret; + + register sc_qword_t arg4_reg asm("r10") = arg4; + register sc_qword_t arg5_reg asm("r8") = arg5; + + asm volatile("syscall" + : "=a"(ret) + : "a"(sc), "D"(arg1), "S"(arg2), "d"(arg3), "r"(arg4_reg), + "r"(arg5_reg) + : "rcx", "r11", "memory"); + return ret; +} + +static sc_qword_t syscall6(int sc, sc_qword_t arg1, sc_qword_t arg2, + sc_qword_t arg3, sc_qword_t arg4, sc_qword_t arg5, + sc_qword_t arg6) { + sc_qword_t ret; + + register sc_qword_t arg4_reg asm("r10") = arg4; + register sc_qword_t arg5_reg asm("r8") = arg5; + register sc_qword_t arg6_reg asm("r9") = arg6; + + asm volatile("syscall" + : "=a"(ret) + : "a"(sc), "D"(arg1), "S"(arg2), "d"(arg3), "r"(arg4_reg), + "r"(arg5_reg), "r"(arg6_reg) + : "rcx", "r11", "memory"); + return ret; +} +} // extern "C" + +#endif \ No newline at end of file diff --git a/sysdeps/wivos/meson.build b/sysdeps/wivos/meson.build new file mode 100644 index 0000000000..48dc92f45a --- /dev/null +++ b/sysdeps/wivos/meson.build @@ -0,0 +1,82 @@ + +sysdep_supported_options = { + 'posix': true, + 'linux': false, + 'glibc': true, + 'bsd': true, +} + +rtld_sources += files( + 'generic/generic.cpp' +) + +libc_sources += files( + 'generic/entry.cpp', + 'generic/generic.cpp' +) + +if not no_headers + install_headers( + '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/statx.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/access.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/wivos/syscall.h', + subdir: 'wivos' + ) +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') + ) +endif \ No newline at end of file