build: use jinx in the build system

now uses jinx to build a cross toolchain, mlibc, bash and the kernel. also made scheduler temporarily run /usr/bin/bash instead of /sbin/init
This commit is contained in:
Matheus
2022-09-15 17:47:05 -03:00
parent 9e1ae1ff36
commit fa37e32ed9
30 changed files with 1009 additions and 31 deletions
+48
View File
@@ -0,0 +1,48 @@
diff -ru bash-5.1/externs.h bash-5.1-patched/externs.h
--- bash-5.1/externs.h 2020-05-27 11:36:41.000000000 -0300
+++ bash-5.1-patched/externs.h 2022-08-20 18:54:03.346557110 -0300
@@ -290,7 +290,7 @@
#endif /* !HAVE_GETDTABLESIZE */
#if !defined (HAVE_GETHOSTNAME)
-extern int gethostname PARAMS((char *, int));
+extern int gethostname PARAMS((char *, size_t));
#endif /* !HAVE_GETHOSTNAME */
extern int getmaxgroups PARAMS((void));
diff -ru bash-5.1/subst.c bash-5.1-patched/subst.c
--- bash-5.1/subst.c 2020-11-16 12:33:15.000000000 -0300
+++ bash-5.1-patched/subst.c 2022-08-20 19:06:46.039884500 -0300
@@ -32,6 +32,7 @@
#endif
#include <signal.h>
#include <errno.h>
+#include <limits.h>
#if defined (HAVE_UNISTD_H)
# include <unistd.h>
diff -ru bash-5.1/support/config.sub bash-5.1-patched/support/config.sub
--- bash-5.1/support/config.sub 2020-11-18 16:40:12.000000000 -0300
+++ bash-5.1-patched/support/config.sub 2022-08-20 18:20:06.006572931 -0300
@@ -1720,7 +1720,7 @@
| skyos* | haiku* | rdos* | toppers* | drops* | es* \
| onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \
| midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \
- | nsk* | powerunix* | genode* | zvmoe* | qnx* | emx*)
+ | nsk* | powerunix* | genode* | zvmoe* | qnx* | emx* | astral*)
;;
# This one is extra strict with allowed versions
sco3.2v2 | sco3.2v[4-9]* | sco5v6*)
diff -ru bash-5.1/support/shobj-conf bash-5.1-patched/support/shobj-conf
--- bash-5.1/support/shobj-conf 2019-12-13 11:51:17.000000000 -0300
+++ bash-5.1-patched/support/shobj-conf 2022-09-14 21:09:42.592996760 -0300
@@ -79,6 +79,9 @@
SHOBJ_LDFLAGS='-shared -bglobalized -unres_symbols ignore'
;;
+astral*-*gcc*)
+ SHOBJ_CFLAGS=-fpic
+ ;;
sunos4*-*gcc*)
SHOBJ_CFLAGS=-fpic
SHOBJ_LD=/usr/bin/ld
+162
View File
@@ -0,0 +1,162 @@
diff -ruN binutils-2.39/bfd/config.bfd binutils-2.39-patched/bfd/config.bfd
--- binutils-2.39/bfd/config.bfd 2022-07-08 06:46:47.000000000 -0300
+++ binutils-2.39-patched/bfd/config.bfd 2022-08-07 18:29:37.305269269 -0300
@@ -695,6 +695,11 @@
targ_selvecs="i386_elf32_vec"
want64=true
;;
+ x86_64-*-astral*)
+ targ_defvec=x86_64_elf64_vec
+ targ_selvecs=i386_elf32_vec
+ want64=true
+ ;;
x86_64-*-netbsd* | x86_64-*-openbsd*)
targ_defvec=x86_64_elf64_vec
targ_selvecs="i386_elf32_vec iamcu_elf32_vec i386_coff_vec i386_pei_vec x86_64_pe_vec x86_64_pei_vec"
diff -ruN binutils-2.39/config.sub binutils-2.39-patched/config.sub
--- binutils-2.39/config.sub 2022-07-08 06:46:47.000000000 -0300
+++ binutils-2.39-patched/config.sub 2022-08-07 18:26:48.218610095 -0300
@@ -1754,7 +1754,7 @@
| onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \
| midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \
| nsk* | powerunix* | genode* | zvmoe* | qnx* | emx* | zephyr* \
- | fiwix* )
+ | fiwix* | astral* )
;;
# This one is extra strict with allowed versions
sco3.2v2 | sco3.2v[4-9]* | sco5v6*)
diff -ruN binutils-2.39/gas/configure.tgt binutils-2.39-patched/gas/configure.tgt
--- binutils-2.39/gas/configure.tgt 2022-07-08 06:46:47.000000000 -0300
+++ binutils-2.39-patched/gas/configure.tgt 2022-08-07 18:31:46.391930215 -0300
@@ -221,6 +221,7 @@
h8300-*-elf) fmt=elf ;;
h8300-*-linux*) fmt=elf em=linux ;;
+ i386-*-astral*) fmt=elf ;;
i386-*-beospe*) fmt=coff em=pe ;;
i386-*-beos*) fmt=elf ;;
i386-*-elfiamcu) fmt=elf arch=iamcu ;;
diff -ruN binutils-2.39/ld/configure.tgt binutils-2.39-patched/ld/configure.tgt
--- binutils-2.39/ld/configure.tgt 2022-07-29 04:37:48.000000000 -0300
+++ binutils-2.39-patched/ld/configure.tgt 2022-08-07 18:34:19.615256758 -0300
@@ -986,6 +986,10 @@
;;
visium-*-elf) targ_emul=elf32visium
;;
+x86_64-*-astral*)
+ targ_emul=elf_x86_64_astral
+ targ_extra_emuls="elf_i386_astral elf_x86_64 elf_i386"
+ ;;
x86_64-*-rdos*) targ_emul=elf64rdos
;;
x86_64-*-cloudabi*) targ_emul=elf_x86_64_cloudabi
diff -ruN binutils-2.39/ld/emulparams/elf_i386_astral.sh binutils-2.39-patched/ld/emulparams/elf_i386_astral.sh
--- binutils-2.39/ld/emulparams/elf_i386_astral.sh 1969-12-31 21:00:00.000000000 -0300
+++ binutils-2.39-patched/ld/emulparams/elf_i386_astral.sh 2022-08-07 19:16:14.135145355 -0300
@@ -0,0 +1,4 @@
+source_sh ${srcdir}/emulparams/elf_i386.sh
+TEXT_START_ADDR=0x10000000
+GENERATE_SHLIB_SCRIPT=yes
+GENERATE_PIE_SCRIPT=yes
diff -ruN binutils-2.39/ld/emulparams/elf_x86_64_astral.sh binutils-2.39-patched/ld/emulparams/elf_x86_64_astral.sh
--- binutils-2.39/ld/emulparams/elf_x86_64_astral.sh 1969-12-31 21:00:00.000000000 -0300
+++ binutils-2.39-patched/ld/emulparams/elf_x86_64_astral.sh 2022-08-07 18:36:20.838584720 -0300
@@ -0,0 +1,4 @@
+source_sh ${srcdir}/emulparams/elf_x86_64.sh
+TEXT_START_ADDR=0x10000000
+GENERATE_SHLIB_SCRIPT=yes
+GENERATE_PIE_SCRIPT=yes
diff -ruN binutils-2.39/ld/Makefile.am binutils-2.39-patched/ld/Makefile.am
--- binutils-2.39/ld/Makefile.am 2022-07-08 06:46:48.000000000 -0300
+++ binutils-2.39-patched/ld/Makefile.am 2022-08-07 19:17:46.965141264 -0300
@@ -275,6 +275,7 @@
eelf32xtensa.c \
eelf32z80.c \
eelf_i386.c \
+ eelf_i386_astral.c \
eelf_i386_be.c \
eelf_i386_fbsd.c \
eelf_i386_haiku.c \
@@ -453,6 +454,7 @@
eelf64tilegx_be.c \
eelf_mipsel_haiku.c \
eelf_x86_64.c \
+ eelf_x86_64_astral.c \
eelf_x86_64_cloudabi.c \
eelf_x86_64_fbsd.c \
eelf_x86_64_haiku.c \
@@ -766,6 +768,7 @@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf32xtensa.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf32z80.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_i386.Pc@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_i386_astral.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_i386_be.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_i386_fbsd.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_i386_haiku.Pc@am__quote@
@@ -941,6 +944,7 @@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64tilegx_be.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_mipsel_haiku.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64.Pc@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_astral.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_cloudabi.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_fbsd.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_haiku.Pc@am__quote@
diff -ruN binutils-2.39/ld/Makefile.in binutils-2.39-patched/ld/Makefile.in
--- binutils-2.39/ld/Makefile.in 2022-08-05 06:56:53.000000000 -0300
+++ binutils-2.39-patched/ld/Makefile.in 2022-08-07 19:17:51.741807718 -0300
@@ -529,6 +529,7 @@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
+runstatedir = @runstatedir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@
@@ -772,6 +773,7 @@
eelf32xtensa.c \
eelf32z80.c \
eelf_i386.c \
+ eelf_i386_astral.c \
eelf_i386_be.c \
eelf_i386_fbsd.c \
eelf_i386_haiku.c \
@@ -949,6 +951,7 @@
eelf64tilegx_be.c \
eelf_mipsel_haiku.c \
eelf_x86_64.c \
+ eelf_x86_64_astral.c \
eelf_x86_64_cloudabi.c \
eelf_x86_64_fbsd.c \
eelf_x86_64_haiku.c \
@@ -1441,6 +1444,7 @@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64tilegx.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64tilegx_be.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_i386.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_i386_astral.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_i386_be.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_i386_fbsd.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_i386_haiku.Po@am__quote@
@@ -1451,6 +1455,7 @@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_mipsel_haiku.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_s390.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_astral.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_cloudabi.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_fbsd.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_haiku.Po@am__quote@
@@ -2432,6 +2437,7 @@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf32xtensa.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf32z80.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_i386.Pc@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_i386_astral.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_i386_be.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_i386_fbsd.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_i386_haiku.Pc@am__quote@
@@ -2607,6 +2613,7 @@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64tilegx_be.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_mipsel_haiku.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64.Pc@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_astral.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_cloudabi.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_fbsd.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_haiku.Pc@am__quote@
+109
View File
@@ -0,0 +1,109 @@
diff -ruN gcc-12.1.0/config.sub gcc-12.1.0-patched/config.sub
--- gcc-12.1.0/config.sub 2022-05-06 04:30:56.000000000 -0300
+++ gcc-12.1.0-patched/config.sub 2022-09-14 19:57:47.513031678 -0300
@@ -1749,7 +1749,7 @@
| onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \
| midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \
| nsk* | powerunix* | genode* | zvmoe* | qnx* | emx* | zephyr* \
- | fiwix* )
+ | fiwix* | astral* )
;;
# This one is extra strict with allowed versions
sco3.2v2 | sco3.2v[4-9]* | sco5v6*)
diff -ruN gcc-12.1.0/fixincludes/mkfixinc.sh gcc-12.1.0-patched/fixincludes/mkfixinc.sh
--- gcc-12.1.0/fixincludes/mkfixinc.sh 2022-05-06 04:30:56.000000000 -0300
+++ gcc-12.1.0-patched/fixincludes/mkfixinc.sh 2022-09-14 19:59:55.153030645 -0300
@@ -11,6 +11,8 @@
# Check for special fix rules for particular targets
case $machine in
+ *-astral* | \
+ *-*-astral* | \
i?86-*-cygwin* | \
i?86-*-mingw32* | \
x86_64-*-mingw32* | \
diff -ruN gcc-12.1.0/gcc/config/astral.h gcc-12.1.0-patched/gcc/config/astral.h
--- gcc-12.1.0/gcc/config/astral.h 1969-12-31 21:00:00.000000000 -0300
+++ gcc-12.1.0-patched/gcc/config/astral.h 2022-09-14 19:58:16.803031441 -0300
@@ -0,0 +1,24 @@
+#undef TARGET_ASTRAL
+#define TARGET_ASTRAL 1
+
+#undef LIB_SPEC
+#define LIB_SPEC "-lc"
+
+#undef LINK_SPEC
+#define LINK_SPEC "%{shared:-shared} %{static:-static} %{!shared: %{!static: %{rdynamic:-export-dynamic}}} %{!dynamic-linker:-dynamic-linker /usr/lib/ld.so}"
+
+#undef STARTFILE_SPEC
+#define STARTFILE_SPEC "crt0.o%s crti.o%s crtbegin.o%s"
+
+#undef ENDFILE_SPEC
+#define ENDFILE_SPEC "crtend.o%s crtn.o%s"
+
+#undef TARGET_OS_CPP_BUILTINS
+#define TARGET_OS_CPP_BUILTINS() \
+ do { \
+ builtin_define ("__astral__"); \
+ builtin_define ("__unix__"); \
+ builtin_assert ("system=astral"); \
+ builtin_assert ("system=unix"); \
+ builtin_assert ("system=posix"); \
+ } while(0);
diff -ruN gcc-12.1.0/gcc/config.gcc gcc-12.1.0-patched/gcc/config.gcc
--- gcc-12.1.0/gcc/config.gcc 2022-05-06 04:30:56.000000000 -0300
+++ gcc-12.1.0-patched/gcc/config.gcc 2022-09-14 19:57:58.466364923 -0300
@@ -773,6 +773,12 @@
tmake_file="${tmake_file} t-dragonfly"
target_has_targetdm=yes
;;
+*-*-astral*)
+ gas=yes
+ gnu_ld=yes
+ default_use_cxa_atexit=yes
+ use_gcc_stdint=provide
+ ;;
*-*-freebsd*)
# This is the generic ELF configuration of FreeBSD. Later
# machine-specific sections may refine and add to this
@@ -1087,6 +1093,9 @@
esac
case ${target} in
+x86_64-*-astral*)
+ tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h glibc-stdint.h i386/i386elf.h i386/x86-64.h astral.h"
+ ;;
aarch64*-*-elf | aarch64*-*-fuchsia* | aarch64*-*-rtems*)
tm_file="${tm_file} dbxelf.h elfos.h newlib-stdint.h"
tm_file="${tm_file} aarch64/aarch64-elf.h aarch64/aarch64-errata.h aarch64/aarch64-elf-raw.h"
diff -ruN gcc-12.1.0/libgcc/config.host gcc-12.1.0-patched/libgcc/config.host
--- gcc-12.1.0/libgcc/config.host 2022-05-06 04:30:59.000000000 -0300
+++ gcc-12.1.0-patched/libgcc/config.host 2022-09-14 19:59:26.003030881 -0300
@@ -751,6 +751,10 @@
;;
x86_64-*-openbsd*)
;;
+x86_64-*-astral*)
+ extra_parts="$extra_parts crti.o crtbegin.o crtend.o crtn.o"
+ tmake_file="$tmake_file i386/t-crtstuff t-crtstuff-pic t-libgcc-pic"
+ ;;
i[34567]86-*-linux*)
extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o"
tmake_file="${tmake_file} i386/t-crtpc t-crtfm i386/t-crtstuff t-dfprules"
diff -ruN gcc-12.1.0/libstdc++-v3/crossconfig.m4 gcc-12.1.0-patched/libstdc++-v3/crossconfig.m4
--- gcc-12.1.0/libstdc++-v3/crossconfig.m4 2022-05-06 04:31:00.000000000 -0300
+++ gcc-12.1.0-patched/libstdc++-v3/crossconfig.m4 2022-09-14 19:58:39.359697928 -0300
@@ -8,7 +8,12 @@
arm*-*-symbianelf*)
# This is a freestanding configuration; there is nothing to do here.
;;
-
+ *-astral*)
+ GLIBCXX_CHECK_COMPILER_FEATURES
+ GLIBCXX_CHECK_LINKER_FEATURES
+ GLIBCXX_CHECK_MATH_SUPPORT
+ GLIBCXX_CHECK_STDLIB_SUPPORT
+ ;;
avr*-*-*)
AC_DEFINE(HAVE_ACOSF)
AC_DEFINE(HAVE_ASINF)
+11
View File
@@ -0,0 +1,11 @@
--- gcc-12.1.0/libgcc/libgcov.h 2022-05-06 04:30:59.000000000 -0300
+++ gcc-12.1.0-patched/libgcc/libgcov.h 2022-09-15 17:13:09.406451175 -0300
@@ -25,6 +25,8 @@
#ifndef GCC_LIBGCOV_H
#define GCC_LIBGCOV_H
+#include <stdint.h>
+
/* work around the poisoned malloc/calloc in system.h. */
#ifndef xmalloc
#define xmalloc malloc
+13
View File
@@ -0,0 +1,13 @@
--- mlibc-2.3.0/meson.build 2022-06-20 06:58:47.000000000 -0300
+++ mlibc-2.3.0-patched/meson.build 2022-09-14 17:04:01.893118263 -0300
@@ -142,6 +142,10 @@
rtdl_include_dirs += include_directories('sysdeps/dripos/include')
libc_include_dirs += include_directories('sysdeps/dripos/include')
subdir('sysdeps/dripos')
+elif host_machine.system() == 'astral'
+ rtdl_include_dirs += include_directories('sysdeps/astral/include')
+ libc_include_dirs += include_directories('sysdeps/astral/include')
+ subdir('sysdeps/astral')
else
error('No sysdeps defined for OS: ' + host_machine.system())
endif
+11
View File
@@ -0,0 +1,11 @@
diff --no-dereference -ruN mlibc-2.3.0/options/ansi/generic/string-stubs.cpp mlibc-2.3.0-patched/options/ansi/generic/string-stubs.cpp
--- mlibc-2.3.0/options/ansi/generic/string-stubs.cpp 2022-06-20 06:58:47.000000000 -0300
+++ mlibc-2.3.0-patched/options/ansi/generic/string-stubs.cpp 2022-09-14 17:05:03.059784408 -0300
@@ -391,7 +391,6 @@
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__
+345
View File
@@ -0,0 +1,345 @@
diff -ruN --no-dereference mlibc-2.3.0/sysdeps/astral/crt-x86_64/crt0.S mlibc-fixed/sysdeps/astral/crt-x86_64/crt0.S
--- mlibc-2.3.0/sysdeps/astral/crt-x86_64/crt0.S 1969-12-31 21:00:00.000000000 -0300
+++ mlibc-fixed/sysdeps/astral/crt-x86_64/crt0.S 2022-09-15 10:41:51.696638158 -0300
@@ -0,0 +1,7 @@
+
+.section .text
+.global _start
+_start:
+ mov $main, %rdi
+ call __mlibc_entry
+
diff -ruN --no-dereference mlibc-2.3.0/sysdeps/astral/generic/astral.cpp mlibc-fixed/sysdeps/astral/generic/astral.cpp
--- mlibc-2.3.0/sysdeps/astral/generic/astral.cpp 1969-12-31 21:00:00.000000000 -0300
+++ mlibc-fixed/sysdeps/astral/generic/astral.cpp 2022-09-15 10:41:51.696638158 -0300
@@ -0,0 +1,6 @@
+#include <astral/syscall.h>
+
+int arch_ctl(int func, void* arg){
+ long ret;
+ return syscall(SYSCALL_ARCH_CTL, &ret, func, (uint64_t)arg);
+}
diff -ruN --no-dereference mlibc-2.3.0/sysdeps/astral/generic/entry.cpp mlibc-fixed/sysdeps/astral/generic/entry.cpp
--- mlibc-2.3.0/sysdeps/astral/generic/entry.cpp 1969-12-31 21:00:00.000000000 -0300
+++ mlibc-fixed/sysdeps/astral/generic/entry.cpp 2022-09-15 10:41:51.696638158 -0300
@@ -0,0 +1,34 @@
+
+#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[])) {
+ auto result = main_fn(__mlibc_stack_data.argc, __mlibc_stack_data.argv, environ);
+ exit(result);
+}
+
diff -ruN --no-dereference mlibc-2.3.0/sysdeps/astral/generic/generic.cpp mlibc-fixed/sysdeps/astral/generic/generic.cpp
--- mlibc-2.3.0/sysdeps/astral/generic/generic.cpp 1969-12-31 21:00:00.000000000 -0300
+++ mlibc-fixed/sysdeps/astral/generic/generic.cpp 2022-09-15 10:41:51.696638158 -0300
@@ -0,0 +1,167 @@
+#include <bits/ensure.h>
+#include <mlibc/debug.hpp>
+#include <mlibc/all-sysdeps.hpp>
+#include <errno.h>
+#include <astral/syscall.h>
+#include <astral/archctl.h>
+
+#define STUB_ONLY { __ensure(!"STUB_ONLY function was called"); __builtin_unreachable(); }
+
+namespace mlibc {
+
+ // stub
+
+ uid_t sys_getuid(){
+ return 0;
+ }
+
+ // stub
+
+ gid_t sys_getgid(){
+ return 0;
+ }
+
+ // stub
+
+ uid_t sys_geteuid(){
+ return 0;
+ }
+
+ // stub
+
+ gid_t sys_getegid(){
+ return 0;
+ }
+
+ // stub
+
+ pid_t sys_getpid(){
+ return 1;
+ }
+
+ // stub
+
+ pid_t sys_getppid(){
+ return 1;
+ }
+
+ // stub
+
+ int sys_getpgid(pid_t pid, pid_t* pgid){
+ *pgid = 1;
+ return 0;
+ }
+
+ // stub
+
+ int sys_clock_get(int clock, time_t *secs, long *nanos){
+ *secs = 0;
+ *nanos = 0;
+ return 0;
+ }
+
+ // stub
+
+ int sys_ioctl(int fd, unsigned long request, void *arg, int *result){
+ 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;
+ }
+
+
+ void sys_libc_log(const char *message){
+ long ret;
+ syscall(SYSCALL_LIBC_LOG, &ret, (uint64_t)message);
+ }
+
+ [[noreturn]] void sys_libc_panic(){
+ for(;;);
+ sys_libc_log("LIBC PANIC!");
+ sys_exit(1);
+ }
+
+
+
+ [[noreturn]] void sys_exit(int status){
+ sys_libc_log("libc: Program requested exit");
+ while(1);
+ }
+
+ 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_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){
+ return sys_vm_map(NULL, size, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, 0, 0, pointer);
+ }
+ int sys_anon_free(void* pointer, size_t size){
+ sys_libc_log("libc: sys_anon_free is not implemented");
+ return 0;
+ }
+
+ 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_read(int fd, void* buff, size_t count, ssize_t *bytes_read){
+ return syscall(SYSCALL_READ, bytes_read, fd, (uint64_t)buff, count);
+ }
+ 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);
+ }
+ int sys_seek(int fd, off_t offset, int whence, off_t *new_offset){
+ return syscall(SYSCALL_LSEEK, new_offset, fd, offset, whence);
+ }
+
+ int sys_close(int fd){
+ long ret;
+ return syscall(SYSCALL_CLOSE, &ret, fd);
+ }
+
+
+ [[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, (uint64_t)path, (uint64_t)statbuf);
+ default:
+ sys_libc_log("libc: sys_stat: Unknown fsfd target");
+ 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) STUB_ONLY
+
+ int sys_isatty(int fd){
+ long ret;
+ return syscall(SYSCALL_ISATTY, &ret, fd);
+ }
+
+} // namespace mlibc
+
diff -ruN --no-dereference mlibc-2.3.0/sysdeps/astral/include/astral/archctl.h mlibc-fixed/sysdeps/astral/include/astral/archctl.h
--- mlibc-2.3.0/sysdeps/astral/include/astral/archctl.h 1969-12-31 21:00:00.000000000 -0300
+++ mlibc-fixed/sysdeps/astral/include/astral/archctl.h 2022-09-15 10:41:51.696638158 -0300
@@ -0,0 +1,11 @@
+#ifndef _ASTRAL_SYSCALL_ARCHCTL_INCLUDE
+#define _ASTRAL_SYSCALL_ARCHCTL_INCLUDE
+
+#include <astral/syscall.h>
+
+#define ARCH_CTL_GSBASE 0
+#define ARCH_CTL_FSBASE 1
+
+int arch_ctl(int func, void* arg);
+
+#endif
diff -ruN --no-dereference mlibc-2.3.0/sysdeps/astral/include/astral/syscall.h mlibc-fixed/sysdeps/astral/include/astral/syscall.h
--- mlibc-2.3.0/sysdeps/astral/include/astral/syscall.h 1969-12-31 21:00:00.000000000 -0300
+++ mlibc-fixed/sysdeps/astral/include/astral/syscall.h 2022-09-15 10:41:51.696638158 -0300
@@ -0,0 +1,37 @@
+#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
+
+#include <stddef.h>
+#include <stdint.h>
+
+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 -ruN --no-dereference mlibc-2.3.0/sysdeps/astral/meson.build mlibc-fixed/sysdeps/astral/meson.build
--- mlibc-2.3.0/sysdeps/astral/meson.build 1969-12-31 21:00:00.000000000 -0300
+++ mlibc-fixed/sysdeps/astral/meson.build 2022-09-15 10:41:51.696638158 -0300
@@ -0,0 +1,55 @@
+
+rtdl_sources += files(
+ 'generic/generic.cpp',
+ 'generic/astral.cpp',
+)
+
+libc_sources += files(
+ 'generic/entry.cpp',
+ 'generic/astral.cpp',
+ 'generic/generic.cpp',
+)
+
+if not no_headers
+ install_headers(
+ 'include/abi-bits/abi.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/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/access.h',
+ 'include/abi-bits/wait.h',
+ 'include/abi-bits/utsname.h',
+ 'include/abi-bits/limits.h',
+ subdir: 'abi-bits'
+ )
+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
+