From 41f32837152c76d4825d7b1dda3e81cb6c638ed3 Mon Sep 17 00:00:00 2001 From: Matheus Date: Sun, 7 May 2023 22:33:25 -0300 Subject: [PATCH] recipes related to mlibc and a hello world init --- patches/mlibc/jinx-working-patch.patch | 571 +++---------------------- recipes/cxxshim | 19 + recipes/frigg | 18 + recipes/init | 22 + recipes/mlibc | 19 + source-recipes/cxxshim | 9 + source-recipes/frigg | 9 + source-recipes/init | 7 + tools/init/Makefile | 13 + tools/init/init | Bin 0 -> 4280 bytes tools/init/main.c | 6 + tools/init/main.o | Bin 0 -> 1352 bytes 12 files changed, 180 insertions(+), 513 deletions(-) create mode 100644 recipes/cxxshim create mode 100644 recipes/frigg create mode 100644 recipes/init create mode 100644 recipes/mlibc create mode 100644 source-recipes/cxxshim create mode 100644 source-recipes/frigg create mode 100644 source-recipes/init create mode 100644 tools/init/Makefile create mode 100755 tools/init/init create mode 100644 tools/init/main.c create mode 100644 tools/init/main.o diff --git a/patches/mlibc/jinx-working-patch.patch b/patches/mlibc/jinx-working-patch.patch index ae0ba1a7..21c39988 100644 --- a/patches/mlibc/jinx-working-patch.patch +++ b/patches/mlibc/jinx-working-patch.patch @@ -1,8 +1,8 @@ diff --git mlibc-clean/abis/linux/in.h mlibc-workdir/abis/linux/in.h -index 3618abf..b1c02c7 100644 +index bb5b6ef..bd2f740 100644 --- mlibc-clean/abis/linux/in.h +++ mlibc-workdir/abis/linux/in.h -@@ -67,6 +67,9 @@ struct ipv6_mreq { +@@ -88,6 +88,9 @@ struct group_req { #define IPPORT_RESERVED 1024 @@ -13,10 +13,10 @@ index 3618abf..b1c02c7 100644 #define IPPROTO_HOPOPTS 0 #define IPPROTO_ICMP 1 diff --git mlibc-clean/meson.build mlibc-workdir/meson.build -index 1605b31..b436ca5 100644 +index 2261926..03b6260 100644 --- mlibc-clean/meson.build +++ mlibc-workdir/meson.build -@@ -135,6 +135,10 @@ elif host_machine.system() == 'dripos' +@@ -153,6 +153,10 @@ elif host_machine.system() == 'dripos' rtdl_include_dirs += include_directories('sysdeps/dripos/include') libc_include_dirs += include_directories('sysdeps/dripos/include') subdir('sysdeps/dripos') @@ -28,17 +28,17 @@ index 1605b31..b436ca5 100644 error('No sysdeps defined for OS: ' + host_machine.system()) endif diff --git mlibc-clean/options/ansi/generic/string-stubs.cpp mlibc-workdir/options/ansi/generic/string-stubs.cpp -index 80f1afd..0f1b4ba 100644 +index d03e342..8558b81 100644 --- mlibc-clean/options/ansi/generic/string-stubs.cpp +++ mlibc-workdir/options/ansi/generic/string-stubs.cpp -@@ -400,7 +400,6 @@ char *strerror(int e) { +@@ -402,7 +402,6 @@ char *strerror(int e) { case ENOPROTOOPT: s = "Protocol not available (ENOPROTOOPT)"; break; case ENOTEMPTY: s = "Directory not empty (ENOTEMPTY)"; break; case ENOTRECOVERABLE: s = "Sate not recoverable (ENOTRECOVERABLE)"; break; - case ENOTSUP: s = "Operation not supported (ENOTSUP)"; break; case ENOTTY: s = "Inappropriate ioctl for device (ENOTTY)"; break; case EOVERFLOW: s = "Value too large for defined datatype (EOVERFLOW)"; break; - #ifndef __linux__ + #if EOPNOTSUPP != ENOTSUP diff --git mlibc-clean/options/glibc/generic/execinfo.cpp mlibc-workdir/options/glibc/generic/execinfo.cpp index 3474615..e034881 100644 --- mlibc-clean/options/glibc/generic/execinfo.cpp @@ -71,23 +71,13 @@ index 0000000..0a0a4a0 + diff --git mlibc-workdir/sysdeps/astral/generic/astral.cpp mlibc-workdir/sysdeps/astral/generic/astral.cpp new file mode 100644 -index 0000000..2410961 ---- /dev/null -+++ mlibc-workdir/sysdeps/astral/generic/astral.cpp -@@ -0,0 +1,6 @@ -+#include -+ -+int arch_ctl(int func, void* arg){ -+ long ret; -+ return syscall(SYSCALL_ARCH_CTL, &ret, func, (uint64_t)arg); -+} +index 0000000..e69de29 diff --git mlibc-workdir/sysdeps/astral/generic/entry.cpp mlibc-workdir/sysdeps/astral/generic/entry.cpp new file mode 100644 -index 0000000..ee7a794 +index 0000000..e5b087a --- /dev/null +++ mlibc-workdir/sysdeps/astral/generic/entry.cpp -@@ -0,0 +1,34 @@ -+ +@@ -0,0 +1,33 @@ +#include +#include +#include @@ -123,10 +113,10 @@ index 0000000..ee7a794 + diff --git mlibc-workdir/sysdeps/astral/generic/generic.cpp mlibc-workdir/sysdeps/astral/generic/generic.cpp new file mode 100644 -index 0000000..e6c404a +index 0000000..4486461 --- /dev/null +++ mlibc-workdir/sysdeps/astral/generic/generic.cpp -@@ -0,0 +1,530 @@ +@@ -0,0 +1,133 @@ +#include +#include +#include @@ -139,460 +129,82 @@ index 0000000..e6c404a +#include +#include + -+#define STUB_ONLY { __ensure(!"STUB_ONLY function was called"); __builtin_unreachable(); } -+ +namespace mlibc { + + // stub + -+ int sys_setuid(uid_t id){ ++ int sys_setuid(uid_t id) { + return 0; + } + + // stub + -+ int sys_setgid(gid_t id){ ++ int sys_setgid(gid_t id) { + return 0; + } + + // stub + -+ uid_t sys_getuid(){ ++ uid_t sys_getuid() { + return 0; + } + + // stub + -+ gid_t sys_getgid(){ ++ gid_t sys_getgid() { + return 0; + } + + // stub + -+ uid_t sys_geteuid(){ ++ uid_t sys_geteuid() { + return 0; + } + + // stub + -+ gid_t sys_getegid(){ ++ gid_t sys_getegid() { + return 0; + } + + // stub + -+ pid_t sys_getppid(){ ++ pid_t sys_getppid() { + return 1; + } + + // stub + -+ int sys_getpgid(pid_t pid, pid_t* pgid){ ++ int sys_getpgid(pid_t pid, pid_t* pgid) { + *pgid = 1; + return 0; + } + -+ // stub -+ -+ int sys_setpgid(pid_t pid, pid_t pgid){ -+ return ENOSYS; -+ } -+ -+ // stub -+ -+ int sys_sigaction(int, const struct sigaction *__restrict, -+ struct sigaction *__restrict){ -+ return ENOSYS; -+ } -+ -+ // stub -+ -+ int sys_sigprocmask(int how, const sigset_t *__restrict set, sigset_t *__restrict retrieve){ -+ return ENOSYS; -+ } -+ -+ // stub -+ -+ int sys_ttyname(int fd, char *buf, size_t size) { -+ return ENOSYS; -+ } -+ -+ // stub -+ -+ #define ASTRALHOSTNAME "astral" -+ -+ int sys_gethostname(char *buffer, size_t bufsize){ -+ -+ memcpy(buffer, ASTRALHOSTNAME, strlen(ASTRALHOSTNAME)); -+ -+ return 0; -+ -+ } -+ -+ // stub -+ -+ int sys_uname(struct utsname *buf){ -+ -+ memcpy(buf->sysname, "Astral", 7); -+ memcpy(buf->nodename, ASTRALHOSTNAME, strlen(ASTRALHOSTNAME)+1); -+ memcpy(buf->version, "0.0.2", 6); -+ memcpy(buf->release, "Astral 0.0.2", 13); -+ memcpy(buf->machine, "x86_64", 7); -+ memcpy(buf->domainname, ASTRALHOSTNAME, strlen(ASTRALHOSTNAME)+1); -+ -+ return 0; -+ -+ } -+ -+ // astral doesn't check for permissions yet -+ -+ int sys_faccessat(int dirfd, const char *pathname, int mode, int flags){ -+ -+ struct stat buff; -+ -+ return sys_stat(fsfd_target::fd_path, dirfd, pathname, 0, &buff); -+ -+ } -+ -+ -+ // stub -+ -+ int sys_access(const char *path, int mode){ -+ return sys_faccessat(AT_FDCWD, path, mode, 0); -+ } -+ -+ // for now no caching is implemented so just return 0 -+ -+ [[gnu::weak]] int sys_fsync(int fd){ -+ return 0; -+ } -+ -+ [[noreturn]] void sys_thread_exit(){ -+ syscall(SYSCALL_THREADEXIT, nullptr); -+ } -+ extern "C" void __mlibc_thread_entry(); -+ -+ -+ #ifndef MLIBC_BUILDING_RTDL -+ -+ int sys_clone(void *tcb, pid_t *pid_out, void *stack){ ++ void sys_libc_log(const char *message) { + long ret; -+ long err = syscall(SYSCALL_NEWTHREAD, &ret, (uintptr_t)__mlibc_thread_entry, (uintptr_t)stack); -+ *pid_out = ret; -+ return err; -+ } -+ -+ #endif -+ -+ int sys_msg_recv(int fd, struct msghdr *hdr, int flags, ssize_t *length){ -+ long ret; -+ long err = syscall(SYSCALL_RECVMSG, &ret, fd, (uintptr_t)hdr, flags); -+ *length = ret; -+ return err; -+ } -+ -+ int sys_linkat(int olddirfd, const char *old_path, int newdirfd, const char *new_path, int flags){ -+ long ret; -+ return syscall(SYSCALL_LINKAT, &ret, olddirfd, (uintptr_t)old_path, newdirfd, (uintptr_t) new_path, flags); -+ } -+ -+ [[gnu::weak]] int sys_link(const char *old_path, const char *new_path){ -+ return sys_linkat(AT_FDCWD, old_path, AT_FDCWD, new_path, 0); -+ } -+ -+ int sys_sleep(time_t *secs, long *nanos){ -+ struct timespec ts; -+ ts.tv_sec = *secs; -+ ts.tv_nsec = *nanos; -+ long ret; -+ long err = syscall(SYSCALL_NANOSLEEP, &ret, (uintptr_t)&ts, (uintptr_t)&ts); -+ *secs = ts.tv_sec; -+ *nanos = ts.tv_nsec; -+ return err; -+ } -+ -+ int sys_accept(int fd, int *newfd, struct sockaddr *addr_ptr, socklen_t *addr_length){ -+ long ret; -+ long err = syscall(SYSCALL_ACCEPT, &ret, fd, (uint64_t)addr_ptr, (uint64_t)addr_length); -+ *newfd = ret; -+ return err; -+ } -+ -+ int sys_connect(int fd, const struct sockaddr *addr_ptr, socklen_t addr_length){ -+ long ret; -+ return syscall(SYSCALL_CONNECT, &ret, fd, (uintptr_t)addr_ptr, addr_length); -+ } -+ -+ int sys_listen(int fd, int backlog){ -+ long ret; -+ return syscall(SYSCALL_LISTEN, &ret, fd, backlog); -+ } -+ -+ -+ int sys_bind(int fd, const struct sockaddr *addr_ptr, socklen_t addr_length){ -+ long ret; -+ return syscall(SYSCALL_BIND, &ret, fd, (uintptr_t)addr_ptr, addr_length); -+ } -+ -+ int sys_socket(int family, int type, int protocol, int *fd){ -+ long ret; -+ long err = syscall(SYSCALL_SOCKET, &ret, family, type, protocol); -+ *fd = ret; -+ return err; -+ } -+ -+ int sys_clock_get(int clock, time_t *secs, long *nanos){ -+ struct timespec ret; -+ long retv; -+ long err = syscall(SYSCALL_CLOCK_GETTIME, &retv, clock, (uint64_t)&ret); -+ *secs = ret.tv_sec; -+ *nanos = ret.tv_nsec; -+ return err; -+ } -+ -+ int sys_chroot(const char* path){ -+ long ret; -+ return syscall(SYSCALL_CHROOT, &ret, (uintptr_t)path); -+ } -+ -+ int sys_openat(int dirfd, const char *path, int flags, mode_t mode, int *fd){ -+ long ret; -+ long err = syscall(SYSCALL_OPENAT, &ret, dirfd, (uintptr_t)path, flags, mode); -+ *fd = ret; -+ return err; -+ } -+ -+ int sys_fchmod(int fd, mode_t mode){ -+ long ret; -+ return syscall(SYSCALL_FCHMOD, &ret, fd, mode); -+ } -+ -+ int sys_fchmodat(int fd, const char *pathname, mode_t mode, int flags){ -+ long ret; -+ return syscall(SYSCALL_FCHMODAT, &ret, fd, (uintptr_t)pathname, mode, flags); -+ } -+ -+ int sys_chmod(const char *pathname, mode_t mode){ -+ return sys_fchmodat(AT_FDCWD, pathname, mode, 0); -+ } -+ -+ -+ int sys_poll(struct pollfd *fds, nfds_t count, int timeout, int *num_events){ -+ long ret; -+ int err = syscall(SYSCALL_POLL, &ret, (uint64_t)fds, count, timeout); -+ *num_events = ret; -+ return err; -+ } -+ -+ // pselect is emulated by poll for now (will turn that into ppoll later) -+ -+#ifndef MLIBC_BUILDING_RTDL -+ -+ int sys_pselect(int num_fds, fd_set *read_set, fd_set *write_set, -+ fd_set *except_set, const struct timespec *timeout, const sigset_t *sigmask, int *num_events){ -+ -+ pollfd* fds = (pollfd*)malloc(num_fds*sizeof(pollfd)); -+ -+ if(!fds) -+ return ENOMEM; -+ -+ for(int fd = 0; fd < num_fds; ++fd){ -+ short events; -+ if(read_set && FD_ISSET(fd, read_set)){ -+ events |= POLLIN; -+ } -+ if(write_set && FD_ISSET(fd, write_set)){ -+ events |= POLLOUT; -+ } -+ if(except_set && FD_ISSET(fd, except_set)){ -+ events |= POLLPRI; -+ } -+ -+ -+ if(events){ -+ fds[fd].fd = fd; -+ fds[fd].events = events; -+ fds[fd].revents = 0; -+ } -+ else{ -+ fds[fd].fd = -1; -+ } -+ } -+ -+ -+ int time = timeout->tv_sec * 1000 + timeout->tv_nsec / 1000000; -+ -+ int err = sys_poll(fds, num_fds, time, num_events); -+ -+ if(err){ -+ free(fds); -+ return err; -+ } -+ -+ for(int fd = 0; fd < num_fds; ++fd){ -+ if(read_set && (fds[fd].revents & POLLIN) == 0) -+ FD_CLR(fd, read_set); -+ -+ if(write_set && (fds[fd].revents & POLLOUT) == 0) -+ FD_CLR(fd, write_set); -+ -+ if(except_set && (fds[fd].revents & POLLPRI) == 0) -+ FD_CLR(fd, except_set); -+ } -+ -+ return 0; -+ } -+ -+#endif -+ -+ int sys_umask(mode_t mask, mode_t* old){ -+ long ret; -+ long err = syscall(SYSCALL_UMASK, &ret, mask); -+ *old = ret; -+ return err; -+ } -+ -+ int sys_mkdirat(int dirfd, const char* path, mode_t mode){ -+ long res; -+ return syscall(SYSCALL_MKDIRAT, &res, dirfd, (uint64_t)path, mode); -+ } -+ -+ int sys_mkdir(const char* path, mode_t mode){ -+ long res; -+ return syscall(SYSCALL_MKDIR, &res, (uint64_t)path, mode); -+ } -+ -+ int sys_pipe(int *fds, int flags){ -+ long res; -+ int err = syscall(SYSCALL_PIPE2, &res, flags); -+ fds[0] = res & 0xFFFFFFFF; -+ fds[1] = (res >> 32) & 0xFFFFFFFF; -+ return err; -+ } -+ -+ int sys_tcgetattr(int fd, struct termios *attr){ -+ int res; -+ return sys_ioctl(fd, TCGETS, (void*)attr, &res); -+ } -+ -+ int sys_tcsetattr(int fd, int act, const struct termios *attr){ -+ int res; -+ return sys_ioctl(fd, TCSETS, (void*)attr, &res); -+ } -+ -+ int sys_ioctl(int fd, unsigned long request, void *arg, int *result){ -+ long res; -+ int ret = syscall(SYSCALL_IOCTL, &res, fd, request, (uint64_t)arg); -+ *result = res; -+ return ret; -+ } -+ -+ -+ int sys_read_entries(int handle, void *buffer, size_t max_size, size_t *bytes_read){ -+ -+ return syscall(SYSCALL_GETDIRENT, (long*)bytes_read, handle, (uint64_t)buffer, max_size); -+ -+ } -+ -+ -+ int sys_open_dir(const char *path, int *handle){ -+ return sys_open(path, O_RDONLY | O_DIRECTORY, 0, handle); -+ } -+ -+ pid_t sys_getpid(){ -+ long ret; -+ syscall(SYSCALL_GETPID, &ret); -+ return ret; -+ } -+ -+ int sys_chdir(const char* path){ -+ long ret; -+ return syscall(SYSCALL_CHDIR, &ret, (uint64_t)path); -+ } -+ -+ int sys_fcntl(int fd, int request, va_list args, int *result){ -+ long ret; -+ // all currently supported requests only have one arg -+ -+ long arg = va_arg(args, uint64_t); -+ -+ long err = syscall(SYSCALL_FCNTL, &ret, fd, request, arg); -+ *result = ret; -+ return err; -+ } -+ -+ int sys_dup(int fd, int flags, int* newfd){ -+ long ret; -+ long err = syscall(SYSCALL_DUP, &ret, fd); -+ *newfd = ret; -+ return err; -+ } -+ -+ int sys_dup2(int fd, int flags, int newfd){ -+ long ret; -+ return syscall(SYSCALL_DUP2, &ret, fd, newfd); -+ } -+ -+ int sys_waitpid(pid_t pid, int *status, int flags, struct rusage *ru, pid_t *ret_pid){ -+ long ret; -+ long err = syscall(SYSCALL_WAITPID, &ret, pid, (uint64_t)status, flags); -+ *ret_pid = ret; -+ return err; -+ } -+ -+ -+ int sys_execve(const char* name, char* const argv[], char* const envp[]){ -+ long ret; -+ return syscall(SYSCALL_EXECVE, &ret, (uint64_t)name, (uint64_t)argv, (uint64_t)envp); -+ } -+ -+ int sys_fork(pid_t* child){ -+ long ret; -+ long err = syscall(SYSCALL_FORK, &ret); -+ *child = (int)ret; -+ return err; -+ } -+ -+ void sys_libc_log(const char *message){ -+ size_t len = strlen(message); -+ char str[len+1]; -+ memcpy(str, message, len); -+ str[len] = '\n'; -+ long ret; -+ sys_write(2, str, len+1, &ret); ++ syscall(SYSCALL_PRINT, &ret, (uint64_t)message); + } + + [[noreturn]] void sys_libc_panic(){ -+ sys_libc_log("libc: panic"); -+ sys_exit(1); ++ sys_libc_log("mlibc: panic"); ++ for (;;) ; + } + -+ -+ [[noreturn]] void sys_exit(int status){ -+ syscall(SYSCALL_EXIT, NULL, status); ++ [[noreturn]] void sys_exit(int status) { ++ sys_libc_log("mlibc: program requested exit"); ++ sys_libc_panic(); + __builtin_unreachable(); + } + -+ int sys_tcb_set(void* pointer){ -+ return arch_ctl(ARCH_CTL_FSBASE, pointer); -+ } -+ [[gnu::weak]] int sys_futex_tid(){ -+ long ret; -+ syscall(SYSCALL_GETTID, &ret); -+ return ret; ++ int sys_tcb_set(void *pointer) { ++ return ENOSYS; + } + -+ #define FUTEX_WAIT 0 -+ #define FUTEX_WAKE 1 -+ -+ -+ int sys_futex_wait(int *pointer, int expected, const struct timespec *time){ -+ long ret; -+ return syscall(SYSCALL_FUTEX, &ret, (uintptr_t)pointer, FUTEX_WAIT, expected, (uintptr_t)time); ++ int sys_futex_wait(int *pointer, int expected, const struct timespec *time) { ++ return ENOSYS; + } -+ int sys_futex_wake(int *pointer){ -+ long ret; -+ return syscall(SYSCALL_FUTEX, &ret, (uintptr_t)pointer, FUTEX_WAKE, 0xFFFFFFFF, NULL); ++ int sys_futex_wake(int *pointer) { ++ return ENOSYS; + } + + @@ -603,63 +215,44 @@ index 0000000..e6c404a + return sys_vm_unmap(pointer, size); + } + -+ int sys_open(const char* pathname, int flags, mode_t mode, int* fd){ -+ long ret; -+ long err = syscall(SYSCALL_OPEN, &ret, (uint64_t)pathname, flags, mode); -+ *fd = (int)ret; -+ return err; ++ int sys_open(const char* pathname, int flags, mode_t mode, int* fd) { ++ return ENOSYS; + }; + int sys_read(int fd, void* buff, size_t count, ssize_t *bytes_read){ -+ return syscall(SYSCALL_READ, bytes_read, fd, (uint64_t)buff, count); ++ return ENOSYS; + } + int sys_write(int fd, const void* buff, size_t count, ssize_t *bytes_written){ -+ return syscall(SYSCALL_WRITE, bytes_written, fd, (uint64_t)buff, count); ++ return ENOSYS; + } + int sys_seek(int fd, off_t offset, int whence, off_t *new_offset){ -+ return syscall(SYSCALL_LSEEK, new_offset, fd, offset, whence); ++ return ENOSYS; + } + -+ int sys_close(int fd){ -+ long ret; -+ return syscall(SYSCALL_CLOSE, &ret, fd); ++ int sys_close(int fd) { ++ return ENOSYS; + } + -+ -+ [[gnu::weak]] int sys_stat(fsfd_target fsfdt, int fd, const char* path, int flags, struct stat *statbuf){ -+ long ret; -+ switch(fsfdt){ -+ case fsfd_target::path: -+ return syscall(SYSCALL_STAT, &ret, (uint64_t)path, (uint64_t)statbuf); -+ case fsfd_target::fd: -+ return syscall(SYSCALL_FSTAT, &ret, fd, (uint64_t)statbuf); -+ case fsfd_target::fd_path: -+ return syscall(SYSCALL_FSTATAT, &ret, fd, (uint64_t)path, (uint64_t)statbuf, flags); -+ default: -+ mlibc::infoLogger() << "libc: stat: Unknown fsfd_target: " << (int)fsfdt << frg::endlog; -+ return ENOSYS; -+ } ++ int sys_vm_map(void *hint, size_t size, int prot, int flags, int fd, off_t offset, void** window){ ++ return ENOSYS; + } + -+ int sys_vm_map(void *hint, size_t size, int prot, int flags, int fd, off_t offset, void** window){ -+ long ret = syscall(SYSCALL_MMAP, (int64_t*)window, (uint64_t)hint, size, prot, flags, fd, offset); -+ return ret; -+ } -+ -+ int sys_vm_unmap(void* pointer, size_t size){ -+ long ret; -+ return syscall(SYSCALL_MUNMAP, &ret, (uint64_t)pointer, size); ++ int sys_vm_unmap(void* pointer, size_t size) { ++ return ENOSYS; + } + -+ int sys_isatty(int fd){ -+ long ret; -+ return syscall(SYSCALL_ISATTY, &ret, fd); ++ int sys_isatty(int fd) { ++ return ENOSYS; ++ } ++ ++ int sys_clock_get(int clock, time_t *secs, long *nanos) { ++ return ENOSYS; + } + +} // namespace mlibc + diff --git mlibc-workdir/sysdeps/astral/include/astral/archctl.h mlibc-workdir/sysdeps/astral/include/astral/archctl.h new file mode 100644 -index 0000000..f181400 +index 0000000..990eca0 --- /dev/null +++ mlibc-workdir/sysdeps/astral/include/astral/archctl.h @@ -0,0 +1,11 @@ @@ -671,89 +264,42 @@ index 0000000..f181400 +#define ARCH_CTL_GSBASE 0 +#define ARCH_CTL_FSBASE 1 + -+int arch_ctl(int func, void* arg); ++int arch_ctl(int func, void *arg); + +#endif diff --git mlibc-workdir/sysdeps/astral/include/astral/syscall.h mlibc-workdir/sysdeps/astral/include/astral/syscall.h new file mode 100644 -index 0000000..12d7d44 +index 0000000..2b6ae3a --- /dev/null +++ mlibc-workdir/sysdeps/astral/include/astral/syscall.h -@@ -0,0 +1,71 @@ +@@ -0,0 +1,24 @@ +#ifndef _SYSCALL_H_INCLUDE +#define _SYSCALL_H_INCLUDE + -+#define SYSCALL_LIBC_LOG 0 -+#define SYSCALL_MMAP 1 -+#define SYSCALL_ARCH_CTL 2 -+#define SYSCALL_GETTID 3 -+#define SYSCALL_OPEN 4 -+#define SYSCALL_READ 5 -+#define SYSCALL_LSEEK 6 -+#define SYSCALL_CLOSE 7 -+#define SYSCALL_ISATTY 8 -+#define SYSCALL_WRITE 9 -+#define SYSCALL_STAT 10 -+#define SYSCALL_FSTAT 11 -+#define SYSCALL_FORK 12 -+#define SYSCALL_EXECVE 13 -+#define SYSCALL_WAITPID 14 -+#define SYSCALL_EXIT 15 -+#define SYSCALL_DUP 16 -+#define SYSCALL_DUP2 17 -+#define SYSCALL_FCNTL 18 -+#define SYSCALL_GETPID 19 -+#define SYSCALL_GETDIRENT 20 -+#define SYSCALL_IOCTL 21 -+#define SYSCALL_CHDIR 22 -+#define SYSCALL_FSTATAT 23 -+#define SYSCALL_PIPE2 24 -+#define SYSCALL_MKDIR 25 -+#define SYSCALL_MUNMAP 26 -+#define SYSCALL_UMASK 27 -+#define SYSCALL_POLL 28 -+#define SYSCALL_FCHMODAT 29 -+#define SYSCALL_OPENAT 30 -+#define SYSCALL_CHROOT 31 -+#define SYSCALL_MKDIRAT 32 -+#define SYSCALL_CLOCK_GETTIME 33 -+#define SYSCALL_SOCKET 34 -+#define SYSCALL_BIND 35 -+#define SYSCALL_LISTEN 36 -+#define SYSCALL_CONNECT 37 -+#define SYSCALL_ACCEPT 38 -+#define SYSCALL_NANOSLEEP 39 -+#define SYSCALL_FCHMOD 40 -+#define SYSCALL_LINKAT 41 -+#define SYSCALL_RECVMSG 42 -+#define SYSCALL_FUTEX 43 -+#define SYSCALL_NEWTHREAD 44 -+#define SYSCALL_THREADEXIT 45 ++#define SYSCALL_PRINT 0 + +#include +#include + -+static long syscall(long func, long* ret, uint64_t p1 = 0, uint64_t p2 = 0, uint64_t p3 = 0, uint64_t p4 = 0, uint64_t p5 = 0, uint64_t p6 = 0){ -+ ++static long syscall(long func, long* ret, uint64_t p1 = 0, uint64_t p2 = 0, uint64_t p3 = 0, uint64_t p4 = 0, uint64_t p5 = 0, uint64_t p6 = 0) { + volatile long err; + + register uint64_t r4 asm("r10") = p4; + register uint64_t r5 asm("r8") = p5; + register uint64_t r6 asm("r9") = p6; -+ ++ + asm volatile("syscall" + : "=a"(*ret), "=d"(err) + : "a"(func), "D"(p1), "S"(p2), "d"(p3), "r"(r4), + "r"(r5), "r"(r6) + : "memory", "rcx", "r11"); + return err; -+ +} + +#endif diff --git mlibc-workdir/sysdeps/astral/meson.build mlibc-workdir/sysdeps/astral/meson.build new file mode 100644 -index 0000000..f45b716 +index 0000000..8a3f4d7 --- /dev/null +++ mlibc-workdir/sysdeps/astral/meson.build @@ -0,0 +1,67 @@ @@ -824,7 +370,6 @@ index 0000000..f45b716 + install_dir: get_option('libdir') + ) +endif -+ diff --git mlibc-workdir/sysdeps/astral/threading/x86_64-thread-entry.S mlibc-workdir/sysdeps/astral/threading/x86_64-thread-entry.S new file mode 100644 index 0000000..4cb3ae0 diff --git a/recipes/cxxshim b/recipes/cxxshim new file mode 100644 index 00000000..fd1b315d --- /dev/null +++ b/recipes/cxxshim @@ -0,0 +1,19 @@ +name=cxxshim +from_source=cxxshim +revision=1 +hostdeps="xgcc xbinutils" +imagedeps="meson ninja base-devel" + + +configure() { + meson --cross-file ${base_dir}/util/crossfile --prefix=${prefix} -Dinstall_headers=true ${source_dir} +} + +build() { + ninja +} + +install() { + DESTDIR=${dest_dir} ninja install +} + diff --git a/recipes/frigg b/recipes/frigg new file mode 100644 index 00000000..1e84cc89 --- /dev/null +++ b/recipes/frigg @@ -0,0 +1,18 @@ +name=frigg +from_source=frigg +revision=1 +hostdeps="xgcc xbinutils" +imagedeps="meson ninja base-devel" + +configure() { + meson --cross-file ${base_dir}/util/crossfile --prefix=${prefix} -Dbuild_tests=disabled ${source_dir} +} + +build() { + ninja +} + +install() { + DESTDIR=${dest_dir} ninja install +} + diff --git a/recipes/init b/recipes/init new file mode 100644 index 00000000..d154fffe --- /dev/null +++ b/recipes/init @@ -0,0 +1,22 @@ +name=init +revision=1 +from_source=init +imagedeps="base-devel" +hostdeps="xbinutils xgcc" +deps="mlibc" + +configure() { + true +} + +build() { + + make -C ${source_dir} -j ${parallelism} + +} + +install() { + + make -C ${source_dir} install DESTDIR=${dest_dir} + +} diff --git a/recipes/mlibc b/recipes/mlibc new file mode 100644 index 00000000..d22e4a5d --- /dev/null +++ b/recipes/mlibc @@ -0,0 +1,19 @@ +name=mlibc +from_source=mlibc +revision=1 +hostdeps="xgcc xbinutils pkgconfig" +deps="cxxshim frigg linux-headers" +imagedeps="meson ninja git base-devel binutils" + +configure() { + meson --cross-file ${base_dir}/util/crossfile -Dlinux_kernel_headers=${sysroot_dir}/${prefix}/include --prefix=${prefix} ${source_dir} +} + +build() { + ninja +} + +install() { + DESTDIR=${dest_dir} ninja install +} + diff --git a/source-recipes/cxxshim b/source-recipes/cxxshim new file mode 100644 index 00000000..39d8b3c9 --- /dev/null +++ b/source-recipes/cxxshim @@ -0,0 +1,9 @@ +name=cxxshim +version=1abc678c17a8b54bf9497065443c1d4b292accb9 +source_method=tarball +tarball_url="https://github.com/managarm/cxxshim/archive/${version}.tar.gz" +tarball_sha512=5455acb3854ab163523c02da1651a8d94eb804e48bb43a6ecbb75cf6f9b2bd857aa21f5c0316865a4f16406566c62a660d605603cc7335abf63983575957b7de + +regenerate() { + true +} diff --git a/source-recipes/frigg b/source-recipes/frigg new file mode 100644 index 00000000..5aa9433e --- /dev/null +++ b/source-recipes/frigg @@ -0,0 +1,9 @@ +name=frigg +version=b3ac9595b278240cf5b67e9c349a9787a82ce02b +source_method=tarball +tarball_url="https://github.com/managarm/frigg/archive/${version}.tar.gz" +tarball_sha512=1e5b225122d73ed01a1274598fc8a441204d1451650b0bba2b207f9e810312b6c4c19026340d85118663a7013cc471b1cc913668c843a037b73da65c23269c41 + +regenerate() { + true +} diff --git a/source-recipes/init b/source-recipes/init new file mode 100644 index 00000000..5adc712c --- /dev/null +++ b/source-recipes/init @@ -0,0 +1,7 @@ +name=init +version=0 +source_dir="tools/init" + +regenerate() { + true +} diff --git a/tools/init/Makefile b/tools/init/Makefile new file mode 100644 index 00000000..22b5aa2f --- /dev/null +++ b/tools/init/Makefile @@ -0,0 +1,13 @@ +.phony: all install +CC=x86_64-astral-gcc +LD=x86_64-astral-gcc +all: init + +install: + cp init "$(DESTDIR)/init" + +init: main.o + $(LD) $(LDFLAGS) -o $@ $^ + +main.o: main.c + $(CC) -c $(CFLAGS) -o $@ $< diff --git a/tools/init/init b/tools/init/init new file mode 100755 index 0000000000000000000000000000000000000000..c29fded44fbd792d599002624d3072149430832e GIT binary patch literal 4280 zcmcImU2GIp6h6D#pM}zPQP2jAEC@+4IJBS%l>pstx1DNf8`>rsZHDdcY`bQEn%P-t zO;oUosYFwa4;0FnHj;eJGAFWAU-f|4O&HTN+nKWr=fkb|6EmA*$bZJ z0dB}Z9Mz9L?PrFi5*^Zz$OKKE5{pxi3) zn~)Dd(EX0C>qOBmfMH}Yw}fHlY-~ zk$L_4^;z7EN>9yR2x9{JA$r^QU!XAh8*}!$%S4nGQnT}^l-9WIb?Q*#T~hX^?kJd9 z*00<-qF-4F=)PNY9*mEQyU^lhKscC)Z+H3xlq&Zo~*e~F%v(x$I4$Y&I!?WT2Wu?1)7Cb0hUBu;!W z^GE5&=OWKvt9}j5d?WMTd|dm7hcC6`oRt?X*M4*yS*pj7joUhLF$1avIN;}i15U4$ z?ES-NICzn^ygvOyP}!Ak=x3rUn0Sy(ip%<$k(ICKSM#4={OxY3bQPD`%w+O=!YA@p zCb=De_7{oorDNcm4EeThs145ISKNu*L-+*ItAz|2LR}3_Pc_z^2%dx^TMj)73;X;lrCq< zGVAm|k>FfZ|9VG-M;PT8Y+`*gqd0u@5%oV^9vq+fcbFX-Z&}beXtSeyuhY= z_F2p~GcSAeW#rYko;WjXPyZ-3p@m*3Ypuh3s&4~);+gM9im!tYJoEh&c^Y@YGwwX{ zmDU;Qiu^ao`=9~qo0BKmk$jJj4;n%Cu_E!cgwIBQ$Xy@de^z`w(1|D z?c(?op8NrSm4aQwDwMz~8y)IDX7u(94jBe&o%d)l-RL?NIT|xMV%q@A}4M!Yx)iF|eExu=3Mng|HH~C3 zo1KFE=nH1T#$S}Pi1l@FBr)}-WZSPk{J_C@40QHb7>p7(L#YQ9yA~rDdfR0lW{wa zkV^t+g{iC^A4Rk+2gjwA&fzjmfHod4jDwb(%Au))wgsAHX5!jJ#s*D|rP<~rw$%Wd zl~*HZ=D4Aj3p6!zbfyJRG2+>D0<^Kb?Zj~GFE@63VY!n0Bc)Y*8*9%t-x1R3hgkjX`VS9Y2a3#guw2=K`V) z^|!HuILTk`8)5bz5J$$aM|bWEtM>}&7XLj$F!FM!oQWb`zCD{L7?2-|6QlboJ(9ot l|Lc&G+?6B02B-t&X&KN_-EmpP8&+livwYz`D~4p=hj literal 0 HcmV?d00001 diff --git a/tools/init/main.c b/tools/init/main.c new file mode 100644 index 00000000..6cc468f9 --- /dev/null +++ b/tools/init/main.c @@ -0,0 +1,6 @@ +#include + +int main() { + printf("Hello, world!\n"); + return 0; +} diff --git a/tools/init/main.o b/tools/init/main.o new file mode 100644 index 0000000000000000000000000000000000000000..51ead24046595c25ca2441d511ca3291a45144ad GIT binary patch literal 1352 zcmbVL!D`z;5FOcV>ZY-A-5d(Z!8x^suv9*U6oQIL<3kCh5Yj_Sk!=MRtT;$Ab#loq zq&I&;KOujRLcgWZYwv;NJ$Z*HvU;rR9NCiFNLi6e>DKpB z*ORI&NhcT%N9)b+qiEP)1HX64War19zqIbJFTZ7{-QH}z+}YiG)pT3NHLsaj<_0(? zAH|u}ot33Wl_?spg5x3@+}_seXQfVcp#uTq|9~?;kbl=j=`u1!D9gh+nmrmBKAizv z6{|j{1`+z-4oxpLax_k2tI^N3h**857!#a`-LI}^Xu>C`EvKH{One+BepgJKL^C^3 zF9{}zn7*I*V!ClGCK@rI(lsu^VCWl)!1z%zJ`&R#g<)`rsx%i2z8*w=7-ak1(_cXy z&tM@}@8x0*sm)>y0l7Qxj@ZL0Lcab5L_E9u)~};CE;s-wbaqizyAkt zgx;fBG=G=gAi+D~sleJ#wn6&SfaCq)z0rT+xz+8$QmQ&jOV>Kjl(1IkR{I$|ecrz; zCN|i}lJK>^())0V=0CR$bWYCCTCG>Us5hT|!3~(sj68v5pM3peaQU-miD&!gzrUp^ SN%0hWQT