From 8c067173d2f3b0b2c1690da3a9c12f065191b528 Mon Sep 17 00:00:00 2001 From: "Ian D. Scott" Date: Wed, 27 Jul 2016 10:49:53 -0700 Subject: [PATCH] Use patches for modifying binutils/gcc/newlib I made an exception for the newlib backend, since it is a substantial amount of code and consists entirely of new files not in the original newlib source. So I gave it a directory called newlib-redox-backend. --- binutils-redox.patch | 63 +++ gcc-redox.patch | 129 ++++++ libc.sh | 31 +- newlib-redox-backend/Makefile.am | 50 +++ newlib-redox-backend/common.c | 65 +++ newlib-redox-backend/common.h | 50 +++ newlib-redox-backend/configure.in | 7 + newlib-redox-backend/crt0.c | 14 + newlib-redox-backend/file.c | 78 ++++ newlib-redox-backend/folder.c | 54 +++ newlib-redox-backend/include/arpa/inet.h | 4 + newlib-redox-backend/include/endian.h | 127 ++++++ newlib-redox-backend/include/netinet/in.h | 17 + newlib-redox-backend/include/time.h | 292 ++++++++++++ newlib-redox-backend/process.c | 92 ++++ newlib-redox-backend/sys/dirent.h | 23 + newlib-redox-backend/sys/ioctl.h | 6 + newlib-redox-backend/sys/stat.h | 191 ++++++++ newlib-redox-backend/sys/termios.h | 4 + newlib-redox-backend/sys/unistd.h | 519 ++++++++++++++++++++++ newlib-redox-backend/sys/utime.h | 14 + newlib-redox-backend/time.c | 24 + newlib-redox-backend/unimpl.c | 104 +++++ newlib-redox.patch | 56 +++ 24 files changed, 1996 insertions(+), 18 deletions(-) create mode 100644 binutils-redox.patch create mode 100644 gcc-redox.patch create mode 100644 newlib-redox-backend/Makefile.am create mode 100644 newlib-redox-backend/common.c create mode 100644 newlib-redox-backend/common.h create mode 100644 newlib-redox-backend/configure.in create mode 100644 newlib-redox-backend/crt0.c create mode 100644 newlib-redox-backend/file.c create mode 100644 newlib-redox-backend/folder.c create mode 100644 newlib-redox-backend/include/arpa/inet.h create mode 100644 newlib-redox-backend/include/endian.h create mode 100644 newlib-redox-backend/include/netinet/in.h create mode 100644 newlib-redox-backend/include/time.h create mode 100644 newlib-redox-backend/process.c create mode 100644 newlib-redox-backend/sys/dirent.h create mode 100644 newlib-redox-backend/sys/ioctl.h create mode 100644 newlib-redox-backend/sys/stat.h create mode 100644 newlib-redox-backend/sys/termios.h create mode 100644 newlib-redox-backend/sys/unistd.h create mode 100644 newlib-redox-backend/sys/utime.h create mode 100644 newlib-redox-backend/time.c create mode 100644 newlib-redox-backend/unimpl.c create mode 100644 newlib-redox.patch diff --git a/binutils-redox.patch b/binutils-redox.patch new file mode 100644 index 0000000000000..2fce8536aca65 --- /dev/null +++ b/binutils-redox.patch @@ -0,0 +1,63 @@ +diff -rupN binutils/bfd/config.bfd binutils-redox/bfd/config.bfd +--- binutils/bfd/config.bfd 2014-10-14 00:32:02.000000000 -0700 ++++ binutils-redox/bfd/config.bfd 2016-07-26 08:45:31.210878318 -0700 +@@ -633,6 +633,11 @@ case "${targ}" in + targ_selvecs="i386_aout_linux_vec i386_pei_vec" + targ64_selvecs="x86_64_elf64_vec x86_64_elf32_vec x86_64_pei_vec l1om_elf64_vec k1om_elf64_vec" + ;; ++ i[3-7]86-*-redox*) ++ targ_defvec=i386_elf32_vec ++ targ_selvecs= ++ targ64_selvecs=x86_64_elf64_vec ++ ;; + i[3-7]86-*-nacl*) + targ_defvec=i386_elf32_nacl_vec + targ_selvecs="arm_elf32_nacl_be_vec arm_elf32_nacl_le_vec" +@@ -676,6 +681,11 @@ case "${targ}" in + targ_selvecs="i386_elf32_vec x86_64_elf32_vec i386_aout_linux_vec i386_pei_vec x86_64_pei_vec l1om_elf64_vec k1om_elf64_vec" + want64=true + ;; ++ x86_64-*-redox*) ++ targ_defvec=x86_64_elf64_vec ++ targ_selvecs=i386_elf32_vec ++ want64=true ++ ;; + x86_64-*-nacl*) + targ_defvec=x86_64_elf32_nacl_vec + targ_selvecs="i386_elf32_nacl_vec x86_64_elf64_nacl_vec arm_elf32_nacl_be_vec arm_elf32_nacl_le_vec" +diff -rupN binutils/config.sub binutils-redox/config.sub +--- binutils/config.sub 2014-10-14 00:32:02.000000000 -0700 ++++ binutils-redox/config.sub 2016-07-26 08:45:31.210878318 -0700 +@@ -1376,7 +1376,7 @@ case $os in + | -chorusos* | -chorusrdb* | -cegcc* \ + | -cygwin* | -msys* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ + | -mingw32* | -mingw64* | -linux-gnu* | -linux-android* \ +- | -linux-newlib* | -linux-musl* | -linux-uclibc* \ ++ | -linux-newlib* | -linux-musl* | -linux-uclibc* | -redox* \ + | -uxpv* | -beos* | -mpeix* | -udk* | -moxiebox* \ + | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \ + | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \ +diff -rupN binutils/gas/configure.tgt binutils-redox/gas/configure.tgt +--- binutils/gas/configure.tgt 2014-10-14 00:32:03.000000000 -0700 ++++ binutils-redox/gas/configure.tgt 2016-07-26 08:45:31.210878318 -0700 +@@ -238,6 +238,7 @@ case ${generic_target} in + case ${cpu}-${os} in + x86_64*-linux-gnux32) arch=x86_64:32 ;; + esac ;; ++ i386-*-redox*) fmt=elf ;; + i386-*-lynxos*) fmt=elf em=lynx ;; + i386-*-sysv[45]*) fmt=elf ;; + i386-*-solaris*) fmt=elf em=solaris ;; +diff -rupN binutils/ld/configure.tgt binutils-redox/ld/configure.tgt +--- binutils/ld/configure.tgt 2014-10-14 00:32:04.000000000 -0700 ++++ binutils-redox/ld/configure.tgt 2016-07-26 08:45:31.210878318 -0700 +@@ -249,6 +249,9 @@ x86_64-*-linux-*) targ_emul=elf_x86_64 + targ_extra_libpath="elf_i386 elf32_x86_64 elf_l1om elf_k1om" + tdir_i386linux=`echo ${targ_alias}aout | sed -e 's/x86_64/i386/'` + tdir_elf_i386=`echo ${targ_alias} | sed -e 's/x86_64/i386/'` ;; ++i[3-7]86-*-redox*) targ_emul=elf_i386 ;; ++x86_64-*-redox*) targ_emul=elf_x86_64 ++ targ_extra_emuls=elf_i386 ;; + i[3-7]86-*-sysv[45]*) targ_emul=elf_i386 ;; + i[3-7]86-*-solaris2*) targ_emul=elf_i386_sol2 + targ_extra_emuls="elf_i386_ldso elf_i386 elf_x86_64_sol2 elf_x86_64 elf_l1om elf_k1om" diff --git a/gcc-redox.patch b/gcc-redox.patch new file mode 100644 index 0000000000000..2a47afa1fb0c6 --- /dev/null +++ b/gcc-redox.patch @@ -0,0 +1,129 @@ +diff -rupN gcc/config.sub gcc-redox/config.sub +--- gcc/config.sub 2010-05-25 06:22:07.000000000 -0700 ++++ gcc-redox/config.sub 2016-07-27 10:20:38.442230579 -0700 +@@ -1309,7 +1309,7 @@ case $os in + | -chorusos* | -chorusrdb* | -cegcc* \ + | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ + | -mingw32* | -linux-gnu* | -linux-android* \ +- | -linux-newlib* | -linux-uclibc* \ ++ | -linux-newlib* | -linux-uclibc* | -redox* \ + | -uxpv* | -beos* | -mpeix* | -udk* \ + | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \ + | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \ +diff -rupN gcc/fixincludes/mkfixinc.sh gcc-redox/fixincludes/mkfixinc.sh +--- gcc/fixincludes/mkfixinc.sh 2010-03-28 09:40:50.000000000 -0700 ++++ gcc-redox/fixincludes/mkfixinc.sh 2016-07-27 10:20:38.445563930 -0700 +@@ -15,6 +15,8 @@ case $machine in + i?86-moss-msdos* | \ + i?86-*-pe | \ + i?86-*-cygwin* | \ ++ i?86-*-redox* | \ ++ x86_64-*-redox* | \ + i?86-*-mingw32* | \ + x86_64-*-mingw32* | \ + i?86-*-interix* | \ +diff -rupN gcc/gcc/config/redox.h gcc-redox/gcc/config/redox.h +--- gcc/gcc/config/redox.h 1969-12-31 16:00:00.000000000 -0800 ++++ gcc-redox/gcc/config/redox.h 2016-07-27 10:20:38.445563930 -0700 +@@ -0,0 +1,17 @@ ++#undef TARGET_REDOX ++#define TARGET_REDOX 1 ++ ++#define LIB_SPEC "-lc -lg -lm" ++ ++#undef NO_IMPLICIT_EXTERN_C ++#define NO_IMPLICIT_EXTERN_C 1 ++ ++#undef TARGET_OS_CPP_BUILTINS ++#define TARGET_OS_CPP_BUILTINS() \ ++ do { \ ++ builtin_define ("__redox__"); \ ++ builtin_define ("__unix__"); \ ++ builtin_assert ("system=redox"); \ ++ builtin_assert ("system=unix"); \ ++ builtin_assert ("system=posix"); \ ++ } while(0); +diff -rupN gcc/gcc/config.gcc gcc-redox/gcc/config.gcc +--- gcc/gcc/config.gcc 2013-03-06 09:40:07.000000000 -0800 ++++ gcc-redox/gcc/config.gcc 2016-07-27 10:20:38.445563930 -0700 +@@ -617,6 +617,11 @@ case ${target} in + ;; + esac + ;; ++*-*-redox*) ++ gas=yes ++ gnu_ld=yes ++ default_use_cxa_atexit=yes ++ ;; + *-*-netbsd*) + tmake_file="t-slibgcc-elf-ver t-libc-ok t-netbsd t-libgcc-pic" + gas=yes +@@ -1316,6 +1321,12 @@ x86_64-*-linux* | x86_64-*-kfreebsd*-gnu + esac + tmake_file="${tmake_file} i386/t-linux64 i386/t-crtstuff i386/t-crtpc i386/t-crtfm t-dfprules" + ;; ++i[34567]86-*-redox*) ++ tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h i386/i386elf.h redox.h" ++ ;; ++x86_64-*-redox*) ++ tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h i386/i386elf.h i386/x86-64.h redox.h" ++ ;; + i[34567]86-pc-msdosdjgpp*) + xm_file=i386/xm-djgpp.h + tm_file="dbxcoff.h ${tm_file} i386/unix.h i386/bsd.h i386/gas.h i386/djgpp.h i386/djgpp-stdint.h" +diff -rupN gcc/gcc/cp/cfns.h gcc-redox/gcc/cp/cfns.h +--- gcc/gcc/cp/cfns.h 2009-04-21 12:03:23.000000000 -0700 ++++ gcc-redox/gcc/cp/cfns.h 2016-07-27 10:20:38.445563930 -0700 +@@ -53,6 +53,9 @@ __inline + static unsigned int hash (const char *, unsigned int); + #ifdef __GNUC__ + __inline ++#ifdef __GNUC_STDC_INLINE__ ++__attribute__ ((__gnu_inline__)) ++#endif + #endif + const char * libc_name_p (const char *, unsigned int); + /* maximum key range = 391, duplicates = 0 */ +@@ -96,7 +99,7 @@ hash (register const char *str, register + 400, 400, 400, 400, 400, 400, 400, 400, 400, 400, + 400, 400, 400, 400, 400, 400, 400 + }; +- register int hval = len; ++ register int hval = (int)len; + + switch (hval) + { +diff -rupN gcc/libgcc/config.host gcc-redox/libgcc/config.host +--- gcc/libgcc/config.host 2011-11-23 14:15:54.000000000 -0800 ++++ gcc-redox/libgcc/config.host 2016-07-27 10:20:38.445563930 -0700 +@@ -296,6 +296,14 @@ x86_64-*-linux* | x86_64-*-kfreebsd*-gnu + extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o" + tmake_file="${tmake_file} i386/t-crtpc i386/t-crtfm" + ;; ++i[34567]86-*-redox*) ++ extra_parts="$extra_parts crtbegin.o crtend.o" ++ tmake_file="$tmake_file i386/t-crtstuff t-crtstuff-pic t-libgcc-pic" ++ ;; ++x86_64-*-redox*) ++ extra_parts="$extra_parts crtbegin.o crtend.o" ++ tmake_file="$tmake_file i386/t-crtstuff t-crtstuff-pic t-libgcc-pic" ++ ;; + i[34567]86-pc-msdosdjgpp*) + ;; + i[34567]86-*-lynxos*) +diff -rupN gcc/libstdc++-v3/crossconfig.m4 gcc-redox/libstdc++-v3/crossconfig.m4 +--- gcc/libstdc++-v3/crossconfig.m4 2011-02-03 23:26:57.000000000 -0800 ++++ gcc-redox/libstdc++-v3/crossconfig.m4 2016-07-27 10:20:38.445563930 -0700 +@@ -150,6 +150,12 @@ case "${host}" in + GCC_CHECK_TLS + AM_ICONV + ;; ++ *-redox*) ++ GLIBCXX_CHECK_COMPILER_FEATURES ++ GLIBCXX_CHECK_LINKER_FEATURES ++ GLIBCXX_CHECK_MATH_SUPPORT ++ GLIBCXX_CHECK_STDLIB_SUPPORT ++ ;; + *-mingw32*) + GLIBCXX_CHECK_LINKER_FEATURES + GLIBCXX_CHECK_MATH_SUPPORT diff --git a/libc.sh b/libc.sh index 89cc7a6519eec..68444477ff2fb 100755 --- a/libc.sh +++ b/libc.sh @@ -26,12 +26,10 @@ function binutils { curl "ftp://sourceware.org/pub/binutils/snapshots/${BINUTILS}.tar.bz2" -o "${BINUTILS}.tar.bz2" fi - if [ ! -d "${BINUTILS}" ] - then - tar xf "${BINUTILS}.tar.bz2" - fi + rm -rf "${BINUTILS}" + tar xf "${BINUTILS}.tar.bz2" - cp -r ../../binutils-redox/* "${BINUTILS}" + patch -p1 -d "${BINUTILS}" < ../../binutils-redox.patch rm -rf "build-${BINUTILS}" mkdir "build-${BINUTILS}" @@ -51,15 +49,13 @@ function gcc_freestanding { curl "http://ftp.gnu.org/gnu/gcc/${GCC}/${GCC}.tar.bz2" -o "${GCC}.tar.bz2" fi - if [ ! -d "${GCC}" ] - then - tar xf "${GCC}.tar.bz2" - pushd "${GCC}" - ./contrib/download_prerequisites - popd - fi + rm -rf "${GCC}" + tar xf "${GCC}.tar.bz2" + pushd "${GCC}" + ./contrib/download_prerequisites + popd - cp -r ../../gcc-redox/* "${GCC}" + patch -p1 -d "${GCC}" < ../../gcc-redox.patch pushd "${GCC}/libstdc++-v3" autoconf2.64 @@ -85,12 +81,11 @@ function newlib { curl "ftp://sourceware.org/pub/newlib/${NEWLIB}.tar.gz" -o "${NEWLIB}.tar.gz" fi - if [ ! -d "${NEWLIB}" ] - then - tar xf "${NEWLIB}.tar.gz" - fi + rm -rf ${NEWLIB} + tar xf "${NEWLIB}.tar.gz" - cp -r ../../newlib-redox/* "${NEWLIB}" + patch -p1 -d "${NEWLIB}" < ../../newlib-redox.patch + cp -r ../../newlib-redox-backend "${NEWLIB}/newlib/libc/sys/redox" pushd "${NEWLIB}/newlib/libc/sys" aclocal-1.11 -I ../.. diff --git a/newlib-redox-backend/Makefile.am b/newlib-redox-backend/Makefile.am new file mode 100644 index 0000000000000..d063c2c9299c4 --- /dev/null +++ b/newlib-redox-backend/Makefile.am @@ -0,0 +1,50 @@ +AUTOMAKE_OPTIONS = cygnus +INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS) +AM_CCASFLAGS = $(INCLUDES) + +noinst_LIBRARIES = lib.a + +if MAY_SUPPLY_SYSCALLS +extra_objs = \ + common.o \ + file.o \ + folder.o \ + process.o \ + time.o \ + unimpl.o +else +extra_objs = +endif + +lib_a_SOURCES = +lib_a_LIBADD = $(extra_objs) +EXTRA_lib_a_SOURCES = \ + common.c \ + file.c \ + folder.c \ + process.c \ + time.c \ + unimpl.c \ + crt0.c +lib_a_DEPENDENCIES = $(extra_objs) +lib_a_CCASFLAGS = $(AM_CCASFLAGS) +lib_a_CFLAGS = $(AM_CFLAGS) + +if MAY_SUPPLY_SYSCALLS +all: crt0.o +endif + +ACLOCAL_AMFLAGS = -I ../../.. +CONFIG_STATUS_DEPENDENCIES = $(newlib_basedir)/configure.host + +include $(srcdir)/../../../Makefile.shared + +install-data-local: + $(mkinstalldirs) $(DESTDIR)$(tooldir)/include/arpa; \ + for i in $(srcdir)/include/arpa/*.h; do \ + $(INSTALL_DATA) $$i $(DESTDIR)$(tooldir)/include/arpa/`basename $$i`; \ + done; \ + $(mkinstalldirs) $(DESTDIR)$(tooldir)/include/netinet; \ + for i in $(srcdir)/include/netinet/*.h; do \ + $(INSTALL_DATA) $$i $(DESTDIR)$(tooldir)/include/netinet/`basename $$i`; \ + done; diff --git a/newlib-redox-backend/common.c b/newlib-redox-backend/common.c new file mode 100644 index 0000000000000..4760d1c61bec2 --- /dev/null +++ b/newlib-redox-backend/common.c @@ -0,0 +1,65 @@ +#include "common.h" + +extern int errno; + +#define demux(a) { \ + if(a >= (uint)(-4096)){ \ + errno = -(int)a; \ + a = (uint)-1; \ + } \ + return (int)a; \ +} + +int syscall0(uint a){ + asm volatile("int $0x80" + : "=a"(a) + : "a"(a) + : "memory"); + + demux(a) +} + +int syscall1(uint a, uint b){ + asm volatile("int $0x80" + : "=a"(a) + : "a"(a), "b"(b) + : "memory"); + + demux(a) +} + +int syscall2(uint a, uint b, uint c){ + asm volatile("int $0x80" + : "=a"(a) + : "a"(a), "b"(b), "c"(c) + : "memory"); + + demux(a) +} + +int syscall3(uint a, uint b, uint c, uint d){ + asm volatile("int $0x80" + : "=a"(a) + : "a"(a), "b"(b), "c"(c), "d"(d) + : "memory"); + + demux(a) +} + +int syscall4(uint a, uint b, uint c, uint d, uint e){ + asm volatile("int $0x80" + : "=a"(a) + : "a"(a), "b"(b), "c"(c), "d"(d), "S"(e) + : "memory"); + + demux(a) +} + +int syscall5(uint a, uint b, uint c, uint d, uint e, uint f){ + asm volatile("int $0x80" + : "=a"(a) + : "a"(a), "b"(b), "c"(c), "d"(d), "S"(e), "D"(f) + : "memory"); + + demux(a) +} diff --git a/newlib-redox-backend/common.h b/newlib-redox-backend/common.h new file mode 100644 index 0000000000000..e1599f51e4815 --- /dev/null +++ b/newlib-redox-backend/common.h @@ -0,0 +1,50 @@ +/* note these headers are all provided by newlib - you don't need to provide them */ +#include +#include +#include +#include +#include +#include +#include + +#include +#undef errno +extern int errno; + +#define SYS_BRK 45 +#define SYS_CHDIR 12 +#define SYS_CLONE 120 + #define CLONE_VM 0x100 + #define CLONE_FS 0x200 + #define CLONE_FILES 0x400 + #define CLONE_VFORK 0x4000 +#define SYS_CLOSE 6 +#define SYS_CLOCK_GETTIME 265 +#define SYS_DUP 41 +#define SYS_EXECVE 11 +#define SYS_EXIT 1 +#define SYS_FPATH 928 +#define SYS_FSTAT 28 +#define SYS_FSYNC 118 +#define SYS_FTRUNCATE 93 +#define SYS_GETPID 20 +#define SYS_LINK 9 +#define SYS_LSEEK 19 +#define SYS_MKDIR 39 +#define SYS_NANOSLEEP 162 +#define SYS_OPEN 5 +#define SYS_PIPE2 331 +#define SYS_READ 3 +#define SYS_RMDIR 84 +#define SYS_STAT 18 +#define SYS_UNLINK 10 +#define SYS_WAITPID 7 +#define SYS_WRITE 4 +#define SYS_YIELD 158 + +int syscall0(uint a); +int syscall1(uint a, uint b); +int syscall2(uint a, uint b, uint c); +int syscall3(uint a, uint b, uint c, uint d); +int syscall4(uint a, uint b, uint c, uint d, uint e); +int syscall5(uint a, uint b, uint c, uint d, uint e, uint f); diff --git a/newlib-redox-backend/configure.in b/newlib-redox-backend/configure.in new file mode 100644 index 0000000000000..9e153483138d0 --- /dev/null +++ b/newlib-redox-backend/configure.in @@ -0,0 +1,7 @@ +AC_PREREQ(2.59) +AC_INIT([newlib], [NEWLIB_VERSION]) +AC_CONFIG_SRCDIR([crt0.c]) +AC_CONFIG_AUX_DIR(../../../..) +NEWLIB_CONFIGURE(../../..) +AC_CONFIG_FILES([Makefile]) +AC_OUTPUT diff --git a/newlib-redox-backend/crt0.c b/newlib-redox-backend/crt0.c new file mode 100644 index 0000000000000..fc5e25e136282 --- /dev/null +++ b/newlib-redox-backend/crt0.c @@ -0,0 +1,14 @@ +extern char ** environ; +extern void exit(int code); +extern int main(int argc, char ** argv, char ** envp); + +void _start(int args) { + asm volatile("xchgw %bx, %bx"); + + int * params = &args-1; + int argc = *params; + char ** argv = (char **)(params + 1); + environ = argv+argc+1; + + exit(main(argc, argv, environ)); +} diff --git a/newlib-redox-backend/file.c b/newlib-redox-backend/file.c new file mode 100644 index 0000000000000..3315ee932b3f1 --- /dev/null +++ b/newlib-redox-backend/file.c @@ -0,0 +1,78 @@ +#include "common.h" + +int chdir(const char *path){ + return syscall1(SYS_CHDIR, (uint)path); +} + +int close(int file){ + return syscall1(SYS_CLOSE, (uint)file); +} + +int dup(int file){ + return syscall1(SYS_DUP, (uint)file); +} + +int fpath(int file, char * buf, int len) { + return syscall2(SYS_FPATH, (uint)buf, (uint)len); +} + +int fstat(int file, struct stat *st) { + return syscall2(SYS_FSTAT, (uint)file, (uint)st); +} + +int fsync(int file) { + return syscall1(SYS_FSYNC, (uint)file); +} + +int ftruncate(int file, off_t len){ + return syscall2(SYS_FTRUNCATE, (uint)file, (uint)len); +} + +int lseek(int file, int ptr, int dir) { + return syscall3(SYS_LSEEK, (uint)file, (uint)ptr, (uint)dir); +} + +//TODO: Actually implement lstat, it currently just calls stat +int lstat(const char *__restrict path, struct stat *__restrict sbuf) { + return syscall2(SYS_STAT, (uint)path, (uint)sbuf); +} + +int link(const char *old, const char *new) { + return syscall2(SYS_LINK, (uint)old, (uint)new); +} + +int mkdir(const char * path, mode_t mode) { + return syscall2(SYS_MKDIR, (uint)path, (uint)mode); +} + +int open(const char *file, int flags, ...) { + return syscall3(SYS_OPEN, (uint)file, (uint)flags, 0); +} + +int pipe(int pipefd[2]) { + return syscall2(SYS_PIPE2, (uint)pipefd, 0); +} + +int pipe2(int pipefd[2], int flags) { + return syscall2(SYS_PIPE2, (uint)pipefd, (uint)flags); +} + +int read(int file, char *ptr, int len) { + return syscall3(SYS_READ, (uint)file, (uint)ptr, (uint)len); +} + +int rmdir(const char * path){ + return syscall1(SYS_RMDIR, (uint)path); +} + +int stat(const char *__restrict path, struct stat *__restrict sbuf) { + return syscall2(SYS_STAT, (uint)path, (uint)sbuf); +} + +int unlink(const char *name) { + return syscall1(SYS_UNLINK, (uint)name); +} + +int write(int file, const char *ptr, int len) { + return syscall3(SYS_WRITE, (uint)file, (uint)ptr, (uint)len); +} diff --git a/newlib-redox-backend/folder.c b/newlib-redox-backend/folder.c new file mode 100644 index 0000000000000..a739374e3b209 --- /dev/null +++ b/newlib-redox-backend/folder.c @@ -0,0 +1,54 @@ +#include "common.h" + +#include + +DIR *opendir(const char * path) { + int fd = open(path, O_RDONLY); + + if(fd >= 0){ + DIR * dir = (DIR *)calloc(sizeof(DIR), 1); + dir->dd_fd = fd; + return dir; + } + + return NULL; +} + +struct dirent *readdir(DIR * dir){ + if(dir){ + //TODO: Speed improvements + int i; + for(i = 0; i < 4096; ++i){ + if(read(dir->dd_fd, &(dir->dd_ent.d_name[i]), 1) > 0){ + if(dir->dd_ent.d_name[i] == '\n'){ + break; + } + }else{ + break; + } + } + dir->dd_ent.d_name[i] = '\0'; + + if(i > 0){ + return &(dir->dd_ent); + } + } + + return NULL; +} + +void rewinddir(DIR * dir){ + if(dir){ + lseek(dir->dd_fd, 0, 0); + } +} + +int closedir(DIR * dir){ + if(dir){ + close(dir->dd_fd); + free(dir); + return 0; + } + + return -1; +} diff --git a/newlib-redox-backend/include/arpa/inet.h b/newlib-redox-backend/include/arpa/inet.h new file mode 100644 index 0000000000000..bdfc357167d10 --- /dev/null +++ b/newlib-redox-backend/include/arpa/inet.h @@ -0,0 +1,4 @@ +#ifndef _ARPA_INET_H_ +#define _ARPA_INET_H_ + +#endif diff --git a/newlib-redox-backend/include/endian.h b/newlib-redox-backend/include/endian.h new file mode 100644 index 0000000000000..f5a8aafc71def --- /dev/null +++ b/newlib-redox-backend/include/endian.h @@ -0,0 +1,127 @@ +/* + * Copyright (c) 1987, 1991 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)endian.h 7.8 (Berkeley) 4/3/91 + * $Id$ + */ + +#ifndef _MACHINE_ENDIAN_H_ +#define _MACHINE_ENDIAN_H_ + +/* + * Define the order of 32-bit words in 64-bit words. + */ +#define _QUAD_HIGHWORD 1 +#define _QUAD_LOWWORD 0 + +/* + * Definitions for byte order, according to byte significance from low + * address to high. + */ + +#ifndef LITTLE_ENDIAN +#define LITTLE_ENDIAN 1234 /* LSB first: i386, vax */ +#endif + +#ifndef BIG_ENDIAN +#define BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net */ +#endif + +#ifndef PDP_ENDIAN +#define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long */ +#endif + +#ifndef BYTE_ORDER +#define BYTE_ORDER LITTLE_ENDIAN +#endif + +#ifndef KERNEL +#include +#endif + +#include + +__BEGIN_DECLS +unsigned long htonl __P((unsigned long)); +unsigned short htons __P((unsigned short)); +unsigned long ntohl __P((unsigned long)); +unsigned short ntohs __P((unsigned short)); +__END_DECLS + +#define __word_swap_long(x) \ +__extension__ ({ register u_long __X = (x); \ + __asm ("rorl $16, %1" \ + : "=r" (__X) \ + : "0" (__X)); \ + __X; }) + +#if defined(KERNEL) && (defined(I486_CPU) || defined(I586_CPU) || defined(I686_CPU)) && !defined(I386_CPU) + +#define __byte_swap_long(x) \ +__extension__ ({ register u_long __X = (x); \ + __asm ("bswap %0" \ + : "=r" (__X) \ + : "0" (__X)); \ + __X; }) +#else + +#define __byte_swap_long(x) \ +__extension__ ({ register u_long __X = (x); \ + __asm ("xchgb %h1, %b1\n\trorl $16, %1\n\txchgb %h1, %b1" \ + : "=q" (__X) \ + : "0" (__X)); \ + __X; }) +#endif + +#define __byte_swap_word(x) \ +__extension__ ({ register u_short __X = (x); \ + __asm ("xchgb %h1, %b1" \ + : "=q" (__X) \ + : "0" (__X)); \ + __X; }) + +/* + * Macros for network/external number representation conversion. + */ +#ifdef __GNUC__ +#define ntohl __byte_swap_long +#define ntohs __byte_swap_word +#define htonl __byte_swap_long +#define htons __byte_swap_word +#endif + +#define NTOHL(x) ((x) = ntohl((u_long)(x))) +#define NTOHS(x) ((x) = ntohs((u_short)(x))) +#define HTONL(x) ((x) = htonl((u_long)(x))) +#define HTONS(x) ((x) = htons((u_short)(x))) + +#endif /* !_MACHINE_ENDIAN_H_ */ diff --git a/newlib-redox-backend/include/netinet/in.h b/newlib-redox-backend/include/netinet/in.h new file mode 100644 index 0000000000000..ee9febd63474e --- /dev/null +++ b/newlib-redox-backend/include/netinet/in.h @@ -0,0 +1,17 @@ +#ifndef _NETINET_IN_H_ +#define _NETINET_IN_H_ +/* Standard well-defined IP protocols. */ +enum { + IPPROTO_IP = 0, /* Dummy protocol for TCP. */ +#define IPPROTO_IP IPPROTO_IP + IPPROTO_ICMP = 1, /* Internet Control Message Protocol. */ +#define IPPROTO_ICMP IPPROTO_ICMP + IPPROTO_TCP = 6, /* Transmission Control Protocol. */ +#define IPPROTO_TCP IPPROTO_TCP + IPPROTO_UDP = 17, /* User Datagram Protocol. */ +#define IPPROTO_UDP IPPROTO_UDP + IPPROTO_RAW = 255, /* Raw IP packets. */ +#define IPPROTO_RAW IPPROTO_RAW + IPPROTO_MAX +}; +#endif diff --git a/newlib-redox-backend/include/time.h b/newlib-redox-backend/include/time.h new file mode 100644 index 0000000000000..3fb229b290006 --- /dev/null +++ b/newlib-redox-backend/include/time.h @@ -0,0 +1,292 @@ +/* + * time.h + * + * Struct and function declarations for dealing with time. + */ + +#ifndef _TIME_H_ +#define _TIME_H_ + +#include "_ansi.h" +#include + +#define __need_size_t +#define __need_NULL +#include + +/* Get _CLOCKS_PER_SEC_ */ +#include + +#ifndef _CLOCKS_PER_SEC_ +#define _CLOCKS_PER_SEC_ 1000 +#endif + +#define CLOCKS_PER_SEC _CLOCKS_PER_SEC_ +#define CLK_TCK CLOCKS_PER_SEC + +#include +#include + +_BEGIN_STD_C + +struct tm +{ + int tm_sec; + int tm_min; + int tm_hour; + int tm_mday; + int tm_mon; + int tm_year; + int tm_wday; + int tm_yday; + int tm_isdst; +#ifdef __TM_GMTOFF + long __TM_GMTOFF; +#endif +#ifdef __TM_ZONE + const char *__TM_ZONE; +#endif +}; + +clock_t _EXFUN(clock, (void)); +double _EXFUN(difftime, (time_t _time2, time_t _time1)); +time_t _EXFUN(mktime, (struct tm *_timeptr)); +time_t _EXFUN(time, (time_t *_timer)); +#ifndef _REENT_ONLY +char *_EXFUN(asctime, (const struct tm *_tblock)); +char *_EXFUN(ctime, (const time_t *_time)); +struct tm *_EXFUN(gmtime, (const time_t *_timer)); +struct tm *_EXFUN(localtime,(const time_t *_timer)); +#endif +size_t _EXFUN(strftime, (char *__restrict _s, + size_t _maxsize, const char *__restrict _fmt, + const struct tm *__restrict _t)); + +char *_EXFUN(asctime_r, (const struct tm *__restrict, + char *__restrict)); +char *_EXFUN(ctime_r, (const time_t *, char *)); +struct tm *_EXFUN(gmtime_r, (const time_t *__restrict, + struct tm *__restrict)); +struct tm *_EXFUN(localtime_r, (const time_t *__restrict, + struct tm *__restrict)); + +_END_STD_C + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef __STRICT_ANSI__ +char *_EXFUN(strptime, (const char *__restrict, + const char *__restrict, + struct tm *__restrict)); +_VOID _EXFUN(tzset, (_VOID)); +_VOID _EXFUN(_tzset_r, (struct _reent *)); + +typedef struct __tzrule_struct +{ + char ch; + int m; + int n; + int d; + int s; + time_t change; + long offset; /* Match type of _timezone. */ +} __tzrule_type; + +typedef struct __tzinfo_struct +{ + int __tznorth; + int __tzyear; + __tzrule_type __tzrule[2]; +} __tzinfo_type; + +__tzinfo_type *_EXFUN (__gettzinfo, (_VOID)); + +/* getdate functions */ + +#ifdef HAVE_GETDATE +#ifndef _REENT_ONLY +#define getdate_err (*__getdate_err()) +int *_EXFUN(__getdate_err,(_VOID)); + +struct tm * _EXFUN(getdate, (const char *)); +/* getdate_err is set to one of the following values to indicate the error. + 1 the DATEMSK environment variable is null or undefined, + 2 the template file cannot be opened for reading, + 3 failed to get file status information, + 4 the template file is not a regular file, + 5 an error is encountered while reading the template file, + 6 memory allication failed (not enough memory available), + 7 there is no line in the template that matches the input, + 8 invalid input specification */ +#endif /* !_REENT_ONLY */ + +/* getdate_r returns the error code as above */ +int _EXFUN(getdate_r, (const char *, struct tm *)); +#endif /* HAVE_GETDATE */ + +/* defines for the opengroup specifications Derived from Issue 1 of the SVID. */ +extern __IMPORT long _timezone; +extern __IMPORT int _daylight; +extern __IMPORT char *_tzname[2]; + +/* POSIX defines the external tzname being defined in time.h */ +#ifndef tzname +#define tzname _tzname +#endif +#endif /* !__STRICT_ANSI__ */ + +#ifdef __cplusplus +} +#endif + +#include + +#ifdef __CYGWIN__ +#include +#endif /*__CYGWIN__*/ + +#if defined(_POSIX_TIMERS) + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Clocks, P1003.1b-1993, p. 263 */ + +int _EXFUN(clock_settime, (clockid_t clock_id, const struct timespec *tp)); +int _EXFUN(clock_gettime, (clockid_t clock_id, struct timespec *tp)); +int _EXFUN(clock_getres, (clockid_t clock_id, struct timespec *res)); + +/* Create a Per-Process Timer, P1003.1b-1993, p. 264 */ + +int _EXFUN(timer_create, + (clockid_t clock_id, + struct sigevent *__restrict evp, + timer_t *__restrict timerid)); + +/* Delete a Per_process Timer, P1003.1b-1993, p. 266 */ + +int _EXFUN(timer_delete, (timer_t timerid)); + +/* Per-Process Timers, P1003.1b-1993, p. 267 */ + +int _EXFUN(timer_settime, + (timer_t timerid, int flags, + const struct itimerspec *__restrict value, + struct itimerspec *__restrict ovalue)); +int _EXFUN(timer_gettime, (timer_t timerid, struct itimerspec *value)); +int _EXFUN(timer_getoverrun, (timer_t timerid)); + +#ifdef __cplusplus +} +#endif +#endif /* _POSIX_TIMERS */ + +//Moved out of ifdef +/* High Resolution Sleep, P1003.1b-1993, p. 269 */ + +int _EXFUN(nanosleep, (const struct timespec *rqtp, struct timespec *rmtp)); + +#if defined(_POSIX_CLOCK_SELECTION) + +#ifdef __cplusplus +extern "C" { +#endif + +int _EXFUN(clock_nanosleep, + (clockid_t clock_id, int flags, const struct timespec *rqtp, + struct timespec *rmtp)); + +#ifdef __cplusplus +} +#endif + +#endif /* _POSIX_CLOCK_SELECTION */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* CPU-time Clock Attributes, P1003.4b/D8, p. 54 */ + +/* values for the clock enable attribute */ + +#define CLOCK_ENABLED 1 /* clock is enabled, i.e. counting execution time */ +#define CLOCK_DISABLED 0 /* clock is disabled */ + +/* values for the pthread cputime_clock_allowed attribute */ + +#define CLOCK_ALLOWED 1 /* If a thread is created with this value a */ + /* CPU-time clock attached to that thread */ + /* shall be accessible. */ +#define CLOCK_DISALLOWED 0 /* If a thread is created with this value, the */ + /* thread shall not have a CPU-time clock */ + /* accessible. */ + +/* Manifest Constants, P1003.1b-1993, p. 262 */ + +#define CLOCK_REALTIME (clockid_t)1 + +/* Flag indicating time is "absolute" with respect to the clock + associated with a time. */ + +#define TIMER_ABSTIME 4 + +/* Manifest Constants, P1003.4b/D8, p. 55 */ + +#if defined(_POSIX_CPUTIME) + +/* When used in a clock or timer function call, this is interpreted as + the identifier of the CPU_time clock associated with the PROCESS + making the function call. */ + +#define CLOCK_PROCESS_CPUTIME_ID (clockid_t)2 + +#endif + +#if defined(_POSIX_THREAD_CPUTIME) + +/* When used in a clock or timer function call, this is interpreted as + the identifier of the CPU_time clock associated with the THREAD + making the function call. */ + +#define CLOCK_THREAD_CPUTIME_ID (clockid_t)3 + +#endif + +#if defined(_POSIX_MONOTONIC_CLOCK) + +/* The identifier for the system-wide monotonic clock, which is defined + * as a clock whose value cannot be set via clock_settime() and which + * cannot have backward clock jumps. */ + +#define CLOCK_MONOTONIC (clockid_t)4 + +#endif + +#if defined(_POSIX_CPUTIME) + +/* Accessing a Process CPU-time CLock, P1003.4b/D8, p. 55 */ + +int _EXFUN(clock_getcpuclockid, (pid_t pid, clockid_t *clock_id)); + +#endif /* _POSIX_CPUTIME */ + +#if defined(_POSIX_CPUTIME) || defined(_POSIX_THREAD_CPUTIME) + +/* CPU-time Clock Attribute Access, P1003.4b/D8, p. 56 */ + +int _EXFUN(clock_setenable_attr, (clockid_t clock_id, int attr)); +int _EXFUN(clock_getenable_attr, (clockid_t clock_id, int *attr)); + +#endif /* _POSIX_CPUTIME or _POSIX_THREAD_CPUTIME */ + +#ifdef __cplusplus +} +#endif + +#endif /* _TIME_H_ */ diff --git a/newlib-redox-backend/process.c b/newlib-redox-backend/process.c new file mode 100644 index 0000000000000..ea2728352c5c7 --- /dev/null +++ b/newlib-redox-backend/process.c @@ -0,0 +1,92 @@ +#include "common.h" + +int clone() { + return syscall1(SYS_CLONE, CLONE_VM | CLONE_FS | CLONE_FILES); +} + +void _exit(int code){ + syscall1(SYS_EXIT, (uint)code); +} + +int _execve(const char *name, const char **argv, const char **env) { + return syscall3(SYS_EXECVE, (uint)name, (uint)argv, (uint)env); +} + +int fork() { + return syscall1(SYS_CLONE, 0); +} + +char * getcwd(char * buf, size_t size) { + char * cwd = NULL; + + int file = open("", O_RDONLY); + if(file >= 0){ + if(!buf){ + if(size == 0){ + size = 4096; + } + buf = (char *)calloc(size, 1); + + if(fpath(file, buf, size) >= 0){ + cwd = buf; + }else{ + free(buf); + } + }else{ + memset(buf, 0, size); + if(fpath(file, buf, size) >= 0){ + cwd = buf; + } + } + close(file); + } + + return cwd; +} + + +pid_t getpid() { + return syscall0(SYS_GETPID); +} + +void * sbrk(ptrdiff_t increment){ + char * curr_brk = (char *)syscall1(SYS_BRK, 0); + char * new_brk = (char *)syscall1(SYS_BRK, (uint)(curr_brk + increment)); + if (new_brk != curr_brk + increment){ + return (void *) -1; + } + return curr_brk; +} + +int sched_yield() { + return syscall0(SYS_YIELD); +} + +int _system(char * s){ + int pid = vfork(); + if(pid == 0) { + execl("/bin/sh", "-c", s, (char *)0); + exit(100); + } else if (pid < 0) { + return -1; + } else { + int status = 0; + int rc = waitpid(pid, &status, 0); + if (rc < 0) { + return -1; + } + return status; + } +} + +pid_t vfork() { + return syscall1(SYS_CLONE, CLONE_VM | CLONE_VFORK); +} + +pid_t wait(int * status) { + return waitpid(-1, status, 0); +} + +pid_t waitpid(pid_t pid, int * status, int options) { + return syscall3(SYS_WAITPID, (uint)pid, (uint)status, (uint)options); +} diff --git a/newlib-redox-backend/sys/dirent.h b/newlib-redox-backend/sys/dirent.h new file mode 100644 index 0000000000000..b3d643ddc3236 --- /dev/null +++ b/newlib-redox-backend/sys/dirent.h @@ -0,0 +1,23 @@ +#ifndef _SYS_DIRENT_H +#define _SYS_DIRENT_H + +struct dirent { + char d_name[4096]; +}; + +typedef struct { + int dd_fd; /* directory file */ + struct dirent dd_ent; +} DIR; + + +#define __dirfd(dir) (dir)->dd_fd + +/* --- redundant --- */ + +DIR *opendir(const char *); +struct dirent *readdir(DIR *); +void rewinddir(DIR *); +int closedir(DIR *); + +#endif diff --git a/newlib-redox-backend/sys/ioctl.h b/newlib-redox-backend/sys/ioctl.h new file mode 100644 index 0000000000000..1fc413030c04b --- /dev/null +++ b/newlib-redox-backend/sys/ioctl.h @@ -0,0 +1,6 @@ +#ifndef _SYS_IOCTL_H_ +#define _SYS_IOCTL_H_ + +int ioctl(int fd,int request,...); + +#endif diff --git a/newlib-redox-backend/sys/stat.h b/newlib-redox-backend/sys/stat.h new file mode 100644 index 0000000000000..274c60d150d9e --- /dev/null +++ b/newlib-redox-backend/sys/stat.h @@ -0,0 +1,191 @@ +#ifndef _SYS_STAT_H +#define _SYS_STAT_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <_ansi.h> +#include +#include +#include +#include + +/* dj's stat defines _STAT_H_ */ +#ifndef _STAT_H_ + +/* It is intended that the layout of this structure not change when the + sizes of any of the basic types change (short, int, long) [via a compile + time option]. */ + +#ifdef __CYGWIN__ +#include +#ifdef _COMPILING_NEWLIB +#define stat64 stat +#endif +#else +struct stat +{ + dev_t st_dev; + ino_t st_ino; + mode_t st_mode; + nlink_t st_nlink; + uid_t st_uid; + gid_t st_gid; + dev_t st_rdev; + off_t st_size; +#if defined(__rtems__) + struct timespec st_atim; + struct timespec st_mtim; + struct timespec st_ctim; + blksize_t st_blksize; + blkcnt_t st_blocks; +#else + /* SysV/sco doesn't have the rest... But Solaris, eabi does. */ +#if defined(__svr4__) && !defined(__PPC__) && !defined(__sun__) + time_t st_atime; + time_t st_mtime; + time_t st_ctime; +#else + time_t st_atime; + long st_spare1; + time_t st_mtime; + long st_spare2; + time_t st_ctime; + long st_spare3; + long st_blksize; + long st_blocks; + long st_spare4[2]; +#endif +#endif +}; + +#if defined(__rtems__) +#define st_atime st_atim.tv_sec +#define st_ctime st_ctim.tv_sec +#define st_mtime st_mtim.tv_sec +#endif + +#endif + +#define _IFMT 0170000 /* type of file */ +#define _IFDIR 0040000 /* directory */ +#define _IFCHR 0020000 /* character special */ +#define _IFBLK 0060000 /* block special */ +#define _IFREG 0100000 /* regular */ +#define _IFLNK 0120000 /* symbolic link */ +#define _IFSOCK 0140000 /* socket */ +#define _IFIFO 0010000 /* fifo */ + +#define S_BLKSIZE 1024 /* size of a block */ + +#define S_ISUID 0004000 /* set user id on execution */ +#define S_ISGID 0002000 /* set group id on execution */ +#define S_ISVTX 0001000 /* save swapped text even after use */ +#ifndef _POSIX_SOURCE +#define S_IREAD 0000400 /* read permission, owner */ +#define S_IWRITE 0000200 /* write permission, owner */ +#define S_IEXEC 0000100 /* execute/search permission, owner */ +#define S_ENFMT 0002000 /* enforcement-mode locking */ +#endif /* !_POSIX_SOURCE */ + +#define S_IFMT _IFMT +#define S_IFDIR _IFDIR +#define S_IFCHR _IFCHR +#define S_IFBLK _IFBLK +#define S_IFREG _IFREG +#define S_IFLNK _IFLNK +#define S_IFSOCK _IFSOCK +#define S_IFIFO _IFIFO + +#ifdef _WIN32 +/* The Windows header files define _S_ forms of these, so we do too + for easier portability. */ +#define _S_IFMT _IFMT +#define _S_IFDIR _IFDIR +#define _S_IFCHR _IFCHR +#define _S_IFIFO _IFIFO +#define _S_IFREG _IFREG +#define _S_IREAD 0000400 +#define _S_IWRITE 0000200 +#define _S_IEXEC 0000100 +#endif + +#define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR) +#define S_IRUSR 0000400 /* read permission, owner */ +#define S_IWUSR 0000200 /* write permission, owner */ +#define S_IXUSR 0000100/* execute/search permission, owner */ +#define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP) +#define S_IRGRP 0000040 /* read permission, group */ +#define S_IWGRP 0000020 /* write permission, grougroup */ +#define S_IXGRP 0000010/* execute/search permission, group */ +#define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH) +#define S_IROTH 0000004 /* read permission, other */ +#define S_IWOTH 0000002 /* write permission, other */ +#define S_IXOTH 0000001/* execute/search permission, other */ + +#ifndef _POSIX_SOURCE +#define ACCESSPERMS (S_IRWXU | S_IRWXG | S_IRWXO) /* 0777 */ +#define ALLPERMS (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO) /* 07777 */ +#define DEFFILEMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) /* 0666 */ +#endif + +#define S_ISBLK(m) (((m)&_IFMT) == _IFBLK) +#define S_ISCHR(m) (((m)&_IFMT) == _IFCHR) +#define S_ISDIR(m) (((m)&_IFMT) == _IFDIR) +#define S_ISFIFO(m) (((m)&_IFMT) == _IFIFO) +#define S_ISREG(m) (((m)&_IFMT) == _IFREG) +#define S_ISLNK(m) (((m)&_IFMT) == _IFLNK) +#define S_ISSOCK(m) (((m)&_IFMT) == _IFSOCK) + +#if defined(__CYGWIN__) +/* Special tv_nsec values for futimens(2) and utimensat(2). */ +#define UTIME_NOW -2L +#define UTIME_OMIT -1L +#endif + +int _EXFUN(chmod,( const char *__path, mode_t __mode )); +int _EXFUN(fchmod,(int __fd, mode_t __mode)); +int _EXFUN(fstat,( int __fd, struct stat *__sbuf )); +int _EXFUN(mkdir,( const char *_path, mode_t __mode )); +int _EXFUN(mkfifo,( const char *__path, mode_t __mode )); +int _EXFUN(stat,( const char *__restrict __path, struct stat *__restrict __sbuf )); +mode_t _EXFUN(umask,( mode_t __mask )); + +int _EXFUN(lstat,( const char *__restrict __path, struct stat *__restrict __buf )); +//int _EXFUN(mknod,( const char *__path, mode_t __mode, dev_t __dev )); + +#if (__POSIX_VISIBLE >= 200809 || defined (__CYGWIN__)) && !defined(__INSIDE_CYGWIN__) +int _EXFUN(fchmodat, (int, const char *, mode_t, int)); +#endif +#if (__BSD_VISIBLE || __POSIX_VISIBLE >= 200809 || defined (__CYGWIN__)) && !defined(__INSIDE_CYGWIN__) +int _EXFUN(fstatat, (int, const char *__restrict , struct stat *__restrict, int)); +int _EXFUN(mkdirat, (int, const char *, mode_t)); +int _EXFUN(mkfifoat, (int, const char *, mode_t)); +#endif +#if (__BSD_VISIBLE || __XSI_VISIBLE >= 700 || defined (__CYGWIN__)) && !defined(__INSIDE_CYGWIN__) +int _EXFUN(mknodat, (int, const char *, mode_t, dev_t)); +#endif +#if (__BSD_VISIBLE || __POSIX_VISIBLE >= 200809 || defined (__CYGWIN__)) && !defined(__INSIDE_CYGWIN__) +int _EXFUN(utimensat, (int, const char *, const struct timespec *, int)); +int _EXFUN(futimens, (int, const struct timespec *)); +#endif + +/* Provide prototypes for most of the _ names that are + provided in newlib for some compilers. */ +#ifdef _COMPILING_NEWLIB +int _EXFUN(_fstat,( int __fd, struct stat *__sbuf )); +int _EXFUN(_stat,( const char *__restrict __path, struct stat *__restrict __sbuf )); +int _EXFUN(_mkdir,( const char *_path, mode_t __mode )); +#ifdef __LARGE64_FILES +struct stat64; +int _EXFUN(_stat64,( const char *__restrict __path, struct stat64 *__restrict __sbuf )); +int _EXFUN(_fstat64,( int __fd, struct stat64 *__sbuf )); +#endif +#endif + +#endif /* !_STAT_H_ */ +#ifdef __cplusplus +} +#endif +#endif /* _SYS_STAT_H */ diff --git a/newlib-redox-backend/sys/termios.h b/newlib-redox-backend/sys/termios.h new file mode 100644 index 0000000000000..5f6b4e8a6f3c4 --- /dev/null +++ b/newlib-redox-backend/sys/termios.h @@ -0,0 +1,4 @@ +#ifndef _SYS_TERMIOS_H_ +#define _SYS_TERMIOS_H_ + +#endif diff --git a/newlib-redox-backend/sys/unistd.h b/newlib-redox-backend/sys/unistd.h new file mode 100644 index 0000000000000..a35665dbd3328 --- /dev/null +++ b/newlib-redox-backend/sys/unistd.h @@ -0,0 +1,519 @@ +#ifndef _SYS_UNISTD_H +#define _SYS_UNISTD_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <_ansi.h> +#define __need_size_t +#define __need_ptrdiff_t +#include +#include +#include +#include + +extern char **environ; + +void _EXFUN(_exit, (int __status ) _ATTRIBUTE ((__noreturn__))); + +int _EXFUN(access,(const char *__path, int __amode )); +unsigned _EXFUN(alarm, (unsigned __secs )); +int _EXFUN(chdir, (const char *__path )); +int _EXFUN(chmod, (const char *__path, mode_t __mode )); +#if !defined(__INSIDE_CYGWIN__) +int _EXFUN(chown, (const char *__path, uid_t __owner, gid_t __group )); +#endif +#if defined(__CYGWIN__) || defined(__rtems__) +int _EXFUN(chroot, (const char *__path )); +#endif +int _EXFUN(close, (int __fildes )); +#if defined(__CYGWIN__) +size_t _EXFUN(confstr, (int __name, char *__buf, size_t __len)); +#endif +char * _EXFUN(ctermid, (char *__s )); +char * _EXFUN(cuserid, (char *__s )); +#if defined(__CYGWIN__) +int _EXFUN(daemon, (int nochdir, int noclose)); +#endif +int _EXFUN(dup, (int __fildes )); +int _EXFUN(dup2, (int __fildes, int __fildes2 )); +#if defined(__CYGWIN__) +int _EXFUN(dup3, (int __fildes, int __fildes2, int flags)); +int _EXFUN(eaccess, (const char *__path, int __mode)); +void _EXFUN(endusershell, (void)); +int _EXFUN(euidaccess, (const char *__path, int __mode)); +#endif +int _EXFUN(execl, (const char *__path, const char *, ... )); +int _EXFUN(execle, (const char *__path, const char *, ... )); +int _EXFUN(execlp, (const char *__file, const char *, ... )); +#if defined(__CYGWIN__) +int _EXFUN(execlpe, (const char *__file, const char *, ... )); +#endif +int _EXFUN(execv, (const char *__path, char * const __argv[] )); +int _EXFUN(execve, (const char *__path, char * const __argv[], char * const __envp[] )); +int _EXFUN(execvp, (const char *__file, char * const __argv[] )); +#if defined(__CYGWIN__) +int _EXFUN(execvpe, (const char *__file, char * const __argv[], char * const __envp[] )); +#endif +#if __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE || defined(__CYGWIN__) +int _EXFUN(faccessat, (int __dirfd, const char *__path, int __mode, int __flags)); +#endif +#if defined(__CYGWIN__) || defined(__rtems__) || defined(__SPU__) +int _EXFUN(fchdir, (int __fildes)); +#endif +int _EXFUN(fchmod, (int __fildes, mode_t __mode )); +#if !defined(__INSIDE_CYGWIN__) +int _EXFUN(fchown, (int __fildes, uid_t __owner, gid_t __group )); +#endif +#if __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE || defined(__CYGWIN__) +int _EXFUN(fchownat, (int __dirfd, const char *__path, uid_t __owner, gid_t __group, int __flags)); +#endif +#if defined(__CYGWIN__) +int _EXFUN(fexecve, (int __fd, char * const __argv[], char * const __envp[] )); +#endif +pid_t _EXFUN(fork, (void )); +long _EXFUN(fpathconf, (int __fd, int __name )); +int _EXFUN(fsync, (int __fd)); +int _EXFUN(fdatasync, (int __fd)); +#if defined(__CYGWIN__) +char * _EXFUN(get_current_dir_name, (void)); +#endif +char * _EXFUN(getcwd, (char *__buf, size_t __size )); +#if defined(__CYGWIN__) +int _EXFUN(getdomainname ,(char *__name, size_t __len)); +#endif +#if !defined(__INSIDE_CYGWIN__) +gid_t _EXFUN(getegid, (void )); +uid_t _EXFUN(geteuid, (void )); +gid_t _EXFUN(getgid, (void )); +#endif +int _EXFUN(getgroups, (int __gidsetsize, gid_t __grouplist[] )); +#if defined(__CYGWIN__) +long _EXFUN(gethostid, (void)); +#endif +char * _EXFUN(getlogin, (void )); +#if defined(_POSIX_THREAD_SAFE_FUNCTIONS) +int _EXFUN(getlogin_r, (char *name, size_t namesize) ); +#endif +char * _EXFUN(getpass, (const char *__prompt)); +int _EXFUN(getpagesize, (void)); +#if defined(__CYGWIN__) +int _EXFUN(getpeereid, (int, uid_t *, gid_t *)); +#endif +pid_t _EXFUN(getpgid, (pid_t)); +pid_t _EXFUN(getpgrp, (void )); +pid_t _EXFUN(getpid, (void )); +pid_t _EXFUN(getppid, (void )); +#if defined(__CYGWIN__) || defined(__rtems__) +pid_t _EXFUN(getsid, (pid_t)); +#endif +#if !defined(__INSIDE_CYGWIN__) +uid_t _EXFUN(getuid, (void )); +#endif +#ifdef __CYGWIN__ +char * _EXFUN(getusershell, (void)); +char * _EXFUN(getwd, (char *__buf )); +int _EXFUN(iruserok, (unsigned long raddr, int superuser, const char *ruser, const char *luser)); +#endif +int _EXFUN(isatty, (int __fildes )); +#if __BSD_VISIBLE +int _EXFUN(issetugid, (void)); +#endif +#if !defined(__INSIDE_CYGWIN__) +int _EXFUN(lchown, (const char *__path, uid_t __owner, gid_t __group )); +#endif +int _EXFUN(link, (const char *__path1, const char *__path2 )); +#if __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE || defined(__CYGWIN__) +int _EXFUN(linkat, (int __dirfd1, const char *__path1, int __dirfd2, const char *__path2, int __flags )); +#endif +int _EXFUN(nice, (int __nice_value )); +#if !defined(__INSIDE_CYGWIN__) +off_t _EXFUN(lseek, (int __fildes, off_t __offset, int __whence )); +#endif +#if defined(__SPU__) || defined(__CYGWIN__) +#define F_ULOCK 0 +#define F_LOCK 1 +#define F_TLOCK 2 +#define F_TEST 3 +int _EXFUN(lockf, (int __fd, int __cmd, off_t __len)); +#endif +long _EXFUN(pathconf, (const char *__path, int __name )); +int _EXFUN(pause, (void )); +#ifdef __CYGWIN__ +int _EXFUN(pthread_atfork, (void (*)(void), void (*)(void), void (*)(void))); +#endif +int _EXFUN(pipe, (int __fildes[2] )); +#ifdef __CYGWIN__ +int _EXFUN(pipe2, (int __fildes[2], int flags)); +#endif +ssize_t _EXFUN(pread, (int __fd, void *__buf, size_t __nbytes, off_t __offset)); +ssize_t _EXFUN(pwrite, (int __fd, const void *__buf, size_t __nbytes, off_t __offset)); +_READ_WRITE_RETURN_TYPE _EXFUN(read, (int __fd, void *__buf, size_t __nbyte )); +#if defined(__CYGWIN__) +int _EXFUN(rresvport, (int *__alport)); +int _EXFUN(revoke, (char *__path)); +#endif +int _EXFUN(rmdir, (const char *__path )); +#if defined(__CYGWIN__) +int _EXFUN(ruserok, (const char *rhost, int superuser, const char *ruser, const char *luser)); +#endif +void * _EXFUN(sbrk, (ptrdiff_t __incr)); +#if !defined(__INSIDE_CYGWIN__) +#if defined(__CYGWIN__) || defined(__rtems__) +int _EXFUN(setegid, (gid_t __gid )); +int _EXFUN(seteuid, (uid_t __uid )); +#endif +int _EXFUN(setgid, (gid_t __gid )); +#endif +#if defined(__CYGWIN__) +int _EXFUN(setgroups, (int ngroups, const gid_t *grouplist )); +#endif +#if __BSD_VISIBLE || (defined(_XOPEN_SOURCE) && __XSI_VISIBLE < 500) +int _EXFUN(sethostname, (const char *, size_t)); +#endif +int _EXFUN(setpgid, (pid_t __pid, pid_t __pgid )); +int _EXFUN(setpgrp, (void )); +#if defined(__CYGWIN__) && !defined(__INSIDE_CYGWIN__) +int _EXFUN(setregid, (gid_t __rgid, gid_t __egid)); +int _EXFUN(setreuid, (uid_t __ruid, uid_t __euid)); +#endif +pid_t _EXFUN(setsid, (void )); +#if !defined(__INSIDE_CYGWIN__) +int _EXFUN(setuid, (uid_t __uid )); +#endif +#if defined(__CYGWIN__) +void _EXFUN(setusershell, (void)); +#endif +unsigned _EXFUN(sleep, (unsigned int __seconds )); +void _EXFUN(swab, (const void *__restrict, void *__restrict, ssize_t)); +long _EXFUN(sysconf, (int __name )); +pid_t _EXFUN(tcgetpgrp, (int __fildes )); +int _EXFUN(tcsetpgrp, (int __fildes, pid_t __pgrp_id )); +char * _EXFUN(ttyname, (int __fildes )); +#if defined(__CYGWIN__) || defined(__rtems__) +int _EXFUN(ttyname_r, (int, char *, size_t)); +#endif +int _EXFUN(unlink, (const char *__path )); +int _EXFUN(usleep, (useconds_t __useconds)); +int _EXFUN(vhangup, (void )); +_READ_WRITE_RETURN_TYPE _EXFUN(write, (int __fd, const void *__buf, size_t __nbyte )); + +#ifdef __CYGWIN__ +# define __UNISTD_GETOPT__ +# include +# undef __UNISTD_GETOPT__ +#else +extern char *optarg; /* getopt(3) external variables */ +extern int optind, opterr, optopt; +int getopt(int, char * const [], const char *); +extern int optreset; /* getopt(3) external variable */ +#endif + +#ifndef _POSIX_SOURCE +pid_t _EXFUN(vfork, (void )); +#endif /* _POSIX_SOURCE */ + +#ifdef _COMPILING_NEWLIB +/* Provide prototypes for most of the _ names that are + provided in newlib for some compilers. */ +int _EXFUN(_close, (int __fildes )); +pid_t _EXFUN(_fork, (void )); +pid_t _EXFUN(_getpid, (void )); +int _EXFUN(_isatty, (int __fildes )); +int _EXFUN(_link, (const char *__path1, const char *__path2 )); +_off_t _EXFUN(_lseek, (int __fildes, _off_t __offset, int __whence )); +#ifdef __LARGE64_FILES +_off64_t _EXFUN(_lseek64, (int __filedes, _off64_t __offset, int __whence )); +#endif +_READ_WRITE_RETURN_TYPE _EXFUN(_read, (int __fd, void *__buf, size_t __nbyte )); +void * _EXFUN(_sbrk, (ptrdiff_t __incr)); +int _EXFUN(_unlink, (const char *__path )); +_READ_WRITE_RETURN_TYPE _EXFUN(_write, (int __fd, const void *__buf, size_t __nbyte )); +int _EXFUN(_execve, (const char *__path, char * const __argv[], char * const __envp[] )); +#endif + +#if defined(__CYGWIN__) || defined(__rtems__) || defined(__aarch64__) || defined (__arm__) || defined(__redox__) || defined(__sh__) || defined(__SPU__) +#if !defined(__INSIDE_CYGWIN__) +int _EXFUN(ftruncate, (int __fd, off_t __length)); +int _EXFUN(truncate, (const char *, off_t __length)); +#endif +#endif + +#if defined(__CYGWIN__) || defined(__rtems__) +int _EXFUN(getdtablesize, (void)); +int _EXFUN(setdtablesize, (int)); +useconds_t _EXFUN(ualarm, (useconds_t __useconds, useconds_t __interval)); +#if !(defined (_WINSOCK_H) || defined (_WINSOCKAPI_) || defined (__USE_W32_SOCKETS)) +/* winsock[2].h defines as __stdcall, and with int as 2nd arg */ + int _EXFUN(gethostname, (char *__name, size_t __len)); +#endif +char * _EXFUN(mktemp, (char *)); +#endif + +#if defined(__CYGWIN__) || defined(__SPU__) || defined(__rtems__) +void _EXFUN(sync, (void)); +#endif + +ssize_t _EXFUN(readlink, (const char *__restrict __path, + char *__restrict __buf, size_t __buflen)); +#if __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE || defined(__CYGWIN__) +ssize_t _EXFUN(readlinkat, (int __dirfd1, const char *__restrict __path, + char *__restrict __buf, size_t __buflen)); +#endif +int _EXFUN(symlink, (const char *__name1, const char *__name2)); +#if __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE || defined(__CYGWIN__) +int _EXFUN(symlinkat, (const char *, int, const char *)); +int _EXFUN(unlinkat, (int, const char *, int)); +#endif + +#define F_OK 0 +#define R_OK 4 +#define W_OK 2 +#define X_OK 1 + +# define SEEK_SET 0 +# define SEEK_CUR 1 +# define SEEK_END 2 + +#include + +#define STDIN_FILENO 0 /* standard input file descriptor */ +#define STDOUT_FILENO 1 /* standard output file descriptor */ +#define STDERR_FILENO 2 /* standard error file descriptor */ + +/* + * sysconf values per IEEE Std 1003.1, 2008 Edition + */ + +#define _SC_ARG_MAX 0 +#define _SC_CHILD_MAX 1 +#define _SC_CLK_TCK 2 +#define _SC_NGROUPS_MAX 3 +#define _SC_OPEN_MAX 4 +#define _SC_JOB_CONTROL 5 +#define _SC_SAVED_IDS 6 +#define _SC_VERSION 7 +#define _SC_PAGESIZE 8 +#define _SC_PAGE_SIZE _SC_PAGESIZE +/* These are non-POSIX values we accidentally introduced in 2000 without + guarding them. Keeping them unguarded for backward compatibility. */ +#define _SC_NPROCESSORS_CONF 9 +#define _SC_NPROCESSORS_ONLN 10 +#define _SC_PHYS_PAGES 11 +#define _SC_AVPHYS_PAGES 12 +/* End of non-POSIX values. */ +#define _SC_MQ_OPEN_MAX 13 +#define _SC_MQ_PRIO_MAX 14 +#define _SC_RTSIG_MAX 15 +#define _SC_SEM_NSEMS_MAX 16 +#define _SC_SEM_VALUE_MAX 17 +#define _SC_SIGQUEUE_MAX 18 +#define _SC_TIMER_MAX 19 +#define _SC_TZNAME_MAX 20 +#define _SC_ASYNCHRONOUS_IO 21 +#define _SC_FSYNC 22 +#define _SC_MAPPED_FILES 23 +#define _SC_MEMLOCK 24 +#define _SC_MEMLOCK_RANGE 25 +#define _SC_MEMORY_PROTECTION 26 +#define _SC_MESSAGE_PASSING 27 +#define _SC_PRIORITIZED_IO 28 +#define _SC_REALTIME_SIGNALS 29 +#define _SC_SEMAPHORES 30 +#define _SC_SHARED_MEMORY_OBJECTS 31 +#define _SC_SYNCHRONIZED_IO 32 +#define _SC_TIMERS 33 +#define _SC_AIO_LISTIO_MAX 34 +#define _SC_AIO_MAX 35 +#define _SC_AIO_PRIO_DELTA_MAX 36 +#define _SC_DELAYTIMER_MAX 37 +#define _SC_THREAD_KEYS_MAX 38 +#define _SC_THREAD_STACK_MIN 39 +#define _SC_THREAD_THREADS_MAX 40 +#define _SC_TTY_NAME_MAX 41 +#define _SC_THREADS 42 +#define _SC_THREAD_ATTR_STACKADDR 43 +#define _SC_THREAD_ATTR_STACKSIZE 44 +#define _SC_THREAD_PRIORITY_SCHEDULING 45 +#define _SC_THREAD_PRIO_INHERIT 46 +/* _SC_THREAD_PRIO_PROTECT was _SC_THREAD_PRIO_CEILING in early drafts */ +#define _SC_THREAD_PRIO_PROTECT 47 +#define _SC_THREAD_PRIO_CEILING _SC_THREAD_PRIO_PROTECT +#define _SC_THREAD_PROCESS_SHARED 48 +#define _SC_THREAD_SAFE_FUNCTIONS 49 +#define _SC_GETGR_R_SIZE_MAX 50 +#define _SC_GETPW_R_SIZE_MAX 51 +#define _SC_LOGIN_NAME_MAX 52 +#define _SC_THREAD_DESTRUCTOR_ITERATIONS 53 +#define _SC_ADVISORY_INFO 54 +#define _SC_ATEXIT_MAX 55 +#define _SC_BARRIERS 56 +#define _SC_BC_BASE_MAX 57 +#define _SC_BC_DIM_MAX 58 +#define _SC_BC_SCALE_MAX 59 +#define _SC_BC_STRING_MAX 60 +#define _SC_CLOCK_SELECTION 61 +#define _SC_COLL_WEIGHTS_MAX 62 +#define _SC_CPUTIME 63 +#define _SC_EXPR_NEST_MAX 64 +#define _SC_HOST_NAME_MAX 65 +#define _SC_IOV_MAX 66 +#define _SC_IPV6 67 +#define _SC_LINE_MAX 68 +#define _SC_MONOTONIC_CLOCK 69 +#define _SC_RAW_SOCKETS 70 +#define _SC_READER_WRITER_LOCKS 71 +#define _SC_REGEXP 72 +#define _SC_RE_DUP_MAX 73 +#define _SC_SHELL 74 +#define _SC_SPAWN 75 +#define _SC_SPIN_LOCKS 76 +#define _SC_SPORADIC_SERVER 77 +#define _SC_SS_REPL_MAX 78 +#define _SC_SYMLOOP_MAX 79 +#define _SC_THREAD_CPUTIME 80 +#define _SC_THREAD_SPORADIC_SERVER 81 +#define _SC_TIMEOUTS 82 +#define _SC_TRACE 83 +#define _SC_TRACE_EVENT_FILTER 84 +#define _SC_TRACE_EVENT_NAME_MAX 85 +#define _SC_TRACE_INHERIT 86 +#define _SC_TRACE_LOG 87 +#define _SC_TRACE_NAME_MAX 88 +#define _SC_TRACE_SYS_MAX 89 +#define _SC_TRACE_USER_EVENT_MAX 90 +#define _SC_TYPED_MEMORY_OBJECTS 91 +#define _SC_V7_ILP32_OFF32 92 +#define _SC_V6_ILP32_OFF32 _SC_V7_ILP32_OFF32 +#define _SC_XBS5_ILP32_OFF32 _SC_V7_ILP32_OFF32 +#define _SC_V7_ILP32_OFFBIG 93 +#define _SC_V6_ILP32_OFFBIG _SC_V7_ILP32_OFFBIG +#define _SC_XBS5_ILP32_OFFBIG _SC_V7_ILP32_OFFBIG +#define _SC_V7_LP64_OFF64 94 +#define _SC_V6_LP64_OFF64 _SC_V7_LP64_OFF64 +#define _SC_XBS5_LP64_OFF64 _SC_V7_LP64_OFF64 +#define _SC_V7_LPBIG_OFFBIG 95 +#define _SC_V6_LPBIG_OFFBIG _SC_V7_LPBIG_OFFBIG +#define _SC_XBS5_LPBIG_OFFBIG _SC_V7_LPBIG_OFFBIG +#define _SC_XOPEN_CRYPT 96 +#define _SC_XOPEN_ENH_I18N 97 +#define _SC_XOPEN_LEGACY 98 +#define _SC_XOPEN_REALTIME 99 +#define _SC_STREAM_MAX 100 +#define _SC_PRIORITY_SCHEDULING 101 +#define _SC_XOPEN_REALTIME_THREADS 102 +#define _SC_XOPEN_SHM 103 +#define _SC_XOPEN_STREAMS 104 +#define _SC_XOPEN_UNIX 105 +#define _SC_XOPEN_VERSION 106 +#define _SC_2_CHAR_TERM 107 +#define _SC_2_C_BIND 108 +#define _SC_2_C_DEV 109 +#define _SC_2_FORT_DEV 110 +#define _SC_2_FORT_RUN 111 +#define _SC_2_LOCALEDEF 112 +#define _SC_2_PBS 113 +#define _SC_2_PBS_ACCOUNTING 114 +#define _SC_2_PBS_CHECKPOINT 115 +#define _SC_2_PBS_LOCATE 116 +#define _SC_2_PBS_MESSAGE 117 +#define _SC_2_PBS_TRACK 118 +#define _SC_2_SW_DEV 119 +#define _SC_2_UPE 120 +#define _SC_2_VERSION 121 +#define _SC_THREAD_ROBUST_PRIO_INHERIT 122 +#define _SC_THREAD_ROBUST_PRIO_PROTECT 123 +#define _SC_XOPEN_UUCP 124 + +/* + * pathconf values per IEEE Std 1003.1, 2008 Edition + */ + +#define _PC_LINK_MAX 0 +#define _PC_MAX_CANON 1 +#define _PC_MAX_INPUT 2 +#define _PC_NAME_MAX 3 +#define _PC_PATH_MAX 4 +#define _PC_PIPE_BUF 5 +#define _PC_CHOWN_RESTRICTED 6 +#define _PC_NO_TRUNC 7 +#define _PC_VDISABLE 8 +#define _PC_ASYNC_IO 9 +#define _PC_PRIO_IO 10 +#define _PC_SYNC_IO 11 +#define _PC_FILESIZEBITS 12 +#define _PC_2_SYMLINKS 13 +#define _PC_SYMLINK_MAX 14 +#define _PC_ALLOC_SIZE_MIN 15 +#define _PC_REC_INCR_XFER_SIZE 16 +#define _PC_REC_MAX_XFER_SIZE 17 +#define _PC_REC_MIN_XFER_SIZE 18 +#define _PC_REC_XFER_ALIGN 19 +#define _PC_TIMESTAMP_RESOLUTION 20 +#ifdef __CYGWIN__ +/* Ask for POSIX permission bits support. */ +#define _PC_POSIX_PERMISSIONS 90 +/* Ask for full POSIX permission support including uid/gid settings. */ +#define _PC_POSIX_SECURITY 91 +#endif + +/* + * confstr values per IEEE Std 1003.1, 2004 Edition + */ + +#ifdef __CYGWIN__ /* Only defined on Cygwin for now. */ +#define _CS_PATH 0 +#define _CS_POSIX_V7_ILP32_OFF32_CFLAGS 1 +#define _CS_POSIX_V6_ILP32_OFF32_CFLAGS _CS_POSIX_V7_ILP32_OFF32_CFLAGS +#define _CS_XBS5_ILP32_OFF32_CFLAGS _CS_POSIX_V7_ILP32_OFF32_CFLAGS +#define _CS_POSIX_V7_ILP32_OFF32_LDFLAGS 2 +#define _CS_POSIX_V6_ILP32_OFF32_LDFLAGS _CS_POSIX_V7_ILP32_OFF32_LDFLAGS +#define _CS_XBS5_ILP32_OFF32_LDFLAGS _CS_POSIX_V7_ILP32_OFF32_LDFLAGS +#define _CS_POSIX_V7_ILP32_OFF32_LIBS 3 +#define _CS_POSIX_V6_ILP32_OFF32_LIBS _CS_POSIX_V7_ILP32_OFF32_LIBS +#define _CS_XBS5_ILP32_OFF32_LIBS _CS_POSIX_V7_ILP32_OFF32_LIBS +#define _CS_XBS5_ILP32_OFF32_LINTFLAGS 4 +#define _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS 5 +#define _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS +#define _CS_XBS5_ILP32_OFFBIG_CFLAGS _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS +#define _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS 6 +#define _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS +#define _CS_XBS5_ILP32_OFFBIG_LDFLAGS _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS +#define _CS_POSIX_V7_ILP32_OFFBIG_LIBS 7 +#define _CS_POSIX_V6_ILP32_OFFBIG_LIBS _CS_POSIX_V7_ILP32_OFFBIG_LIBS +#define _CS_XBS5_ILP32_OFFBIG_LIBS _CS_POSIX_V7_ILP32_OFFBIG_LIBS +#define _CS_XBS5_ILP32_OFFBIG_LINTFLAGS 8 +#define _CS_POSIX_V7_LP64_OFF64_CFLAGS 9 +#define _CS_POSIX_V6_LP64_OFF64_CFLAGS _CS_POSIX_V7_LP64_OFF64_CFLAGS +#define _CS_XBS5_LP64_OFF64_CFLAGS _CS_POSIX_V7_LP64_OFF64_CFLAGS +#define _CS_POSIX_V7_LP64_OFF64_LDFLAGS 10 +#define _CS_POSIX_V6_LP64_OFF64_LDFLAGS _CS_POSIX_V7_LP64_OFF64_LDFLAGS +#define _CS_XBS5_LP64_OFF64_LDFLAGS _CS_POSIX_V7_LP64_OFF64_LDFLAGS +#define _CS_POSIX_V7_LP64_OFF64_LIBS 11 +#define _CS_POSIX_V6_LP64_OFF64_LIBS _CS_POSIX_V7_LP64_OFF64_LIBS +#define _CS_XBS5_LP64_OFF64_LIBS _CS_POSIX_V7_LP64_OFF64_LIBS +#define _CS_XBS5_LP64_OFF64_LINTFLAGS 12 +#define _CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS 13 +#define _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS _CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS +#define _CS_XBS5_LPBIG_OFFBIG_CFLAGS _CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS +#define _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS 14 +#define _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS +#define _CS_XBS5_LPBIG_OFFBIG_LDFLAGS _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS +#define _CS_POSIX_V7_LPBIG_OFFBIG_LIBS 15 +#define _CS_POSIX_V6_LPBIG_OFFBIG_LIBS _CS_POSIX_V7_LPBIG_OFFBIG_LIBS +#define _CS_XBS5_LPBIG_OFFBIG_LIBS _CS_POSIX_V7_LPBIG_OFFBIG_LIBS +#define _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS 16 +#define _CS_POSIX_V7_WIDTH_RESTRICTED_ENVS 17 +#define _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS _CS_POSIX_V7_WIDTH_RESTRICTED_ENVS +#define _CS_XBS5_WIDTH_RESTRICTED_ENVS _CS_POSIX_V7_WIDTH_RESTRICTED_ENVS +#define _CS_POSIX_V7_THREADS_CFLAGS 18 +#define _CS_POSIX_V7_THREADS_LDFLAGS 19 +#define _CS_V7_ENV 20 +#define _CS_V6_ENV _CS_V7_ENV +#endif + +#ifdef __cplusplus +} +#endif +#endif /* _SYS_UNISTD_H */ diff --git a/newlib-redox-backend/sys/utime.h b/newlib-redox-backend/sys/utime.h new file mode 100644 index 0000000000000..7499cfe7ea98a --- /dev/null +++ b/newlib-redox-backend/sys/utime.h @@ -0,0 +1,14 @@ +#ifndef _SYS_UTIME_H +#define _SYS_UTIME_H 1 + +#include + +struct utimbuf + { + time_t actime; /* Access time. */ + time_t modtime; /* Modification time. */ + }; + +int _EXFUN(utime, (const char *__file, const struct utimbuf *__times)); + +#endif /* _SYS_UTIME_H */ diff --git a/newlib-redox-backend/time.c b/newlib-redox-backend/time.c new file mode 100644 index 0000000000000..e1d126eae261d --- /dev/null +++ b/newlib-redox-backend/time.c @@ -0,0 +1,24 @@ +#include "common.h" + +int clock_gettime(clockid_t clk_id, struct timespec * tp){ + return syscall2(SYS_CLOCK_GETTIME, (uint)clk_id, (uint)tp); +} + +int gettimeofday(struct timeval *__restrict tv, void *__restrict tz){ + if(tv){ + struct timespec tp; + if(clock_gettime(CLOCK_REALTIME, &tp) == 0){ + tv->tv_sec = tp.tv_sec; + tv->tv_usec = tp.tv_nsec / 1000; + } else { + return -1; + } + } else { + errno = EFAULT; + return -1; + } +} + +int nanosleep(const struct timespec * req, struct timespec * rem){ + return syscall2(SYS_NANOSLEEP, (uint)req, (uint)rem); +} diff --git a/newlib-redox-backend/unimpl.c b/newlib-redox-backend/unimpl.c new file mode 100644 index 0000000000000..63611c69b2062 --- /dev/null +++ b/newlib-redox-backend/unimpl.c @@ -0,0 +1,104 @@ +#include "common.h" + +#include + +#define UNIMPL(error) { \ + errno = error; \ + fprintf(stderr, "unimplemented: %s: %s\n", __func__, strerror(error)); \ + return -1; \ +} + +int access(const char * path, int amode){ + //All permissions granted, if file exists + struct stat sbuf; + return stat(path, &sbuf); +} + +int chmod(const char * path, mode_t mode) { + UNIMPL(EACCES); +} + +int chown(const char *path, uid_t owner, gid_t group) { + UNIMPL(EACCES); +} + +int dup2(int oldfd, int newfd) { + UNIMPL(EBADF); +} + +int fcntl(int file, int cmd, ...){ + UNIMPL(EACCES); +} + +struct hostent * gethostbyname(const char * name) { + return (struct hostent *) NULL; +} + +int getdtablesize() { + return 65536; +} + +struct group * getgrnam(const char * name){ + return (struct group *) NULL; +} + +struct group * getgrgid(gid_t gid){ + return (struct group *) NULL; +} + +struct passwd * getpwnam(const char * name){ + return (struct passwd *) NULL; +} + +struct passwd * getpwuid(uid_t uid){ + return (struct passwd *) NULL; +} + +gid_t getegid() { + return 0; +} + +uid_t geteuid() { + return 0; +} + +gid_t getgid() { + return 0; +} + +uid_t getuid() { + return 0; +} + +int ioctl(int file, int request, ...) { + UNIMPL(EINVAL); +} + +int kill(int pid, int sig) { + UNIMPL(EINVAL); +} + +int setgid(gid_t gid) { + UNIMPL(EINVAL); +} + +int setuid(uid_t uid) { + UNIMPL(EINVAL); +} + +long sysconf(int name) { + UNIMPL(EINVAL); +} + +clock_t times(struct tms * buf) { + UNIMPL(EINVAL); +} + +mode_t umask(mode_t mask) { + //All permissions granted + return 0777; +} + +int utime(const char * filename, const struct utimbuf * times) { + UNIMPL(EACCES); +} diff --git a/newlib-redox.patch b/newlib-redox.patch new file mode 100644 index 0000000000000..27244a446236e --- /dev/null +++ b/newlib-redox.patch @@ -0,0 +1,56 @@ +diff -rupNZ newlib/config.sub newlib-redox/config.sub +--- newlib/config.sub 2015-08-24 10:09:16.000000000 -0700 ++++ newlib-redox/config.sub 2016-07-27 10:24:29.683667766 -0700 +@@ -1385,7 +1385,7 @@ case $os in + | -chorusos* | -chorusrdb* | -cegcc* \ + | -cygwin* | -msys* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ + | -mingw32* | -mingw64* | -linux-gnu* | -linux-android* \ +- | -linux-newlib* | -linux-musl* | -linux-uclibc* \ ++ | -linux-newlib* | -linux-musl* | -linux-uclibc* | -redox* \ + | -uxpv* | -beos* | -mpeix* | -udk* | -moxiebox* \ + | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \ + | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \ +diff -rupNZ newlib/newlib/configure.host newlib-redox/newlib/configure.host +--- newlib/newlib/configure.host 2015-08-24 10:09:16.000000000 -0700 ++++ newlib-redox/newlib/configure.host 2016-07-27 10:24:29.683667766 -0700 +@@ -448,6 +448,14 @@ case "${host}" in + sys_dir=rdos + newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES" + ;; ++ i[3-7]86-*-redox*) ++ sys_dir=redox ++ posix_dir=posix ++ unix_dir=unix ++ newlib_cflags="${newlib_cflags} -D_I386MACH_ALLOW_HW_INTERRUPTS" ++ newlib_cflags="${newlib_cflags} -DHAVE_NANOSLEEP -DHAVE_OPENDIR -DHAVE_SYSTEM" ++ newlib_cflags="${newlib_cflags} -D_NO_GETCWD -D_NO_GETLOGIN -D_NO_GETPWENT -D_NO_GETUT -D_NO_GETPASS -D_NO_POPEN -D_NO_SIGSET -D_NO_TTYNAME -D_NO_WORDEXP" ++ ;; + i[34567]86-*-sco*) + sys_dir=sysvi386 + unix_dir=unix +diff -rupNZ newlib/newlib/libc/include/sys/config.h newlib-redox/newlib/libc/include/sys/config.h +--- newlib/newlib/libc/include/sys/config.h 2015-08-24 10:09:16.000000000 -0700 ++++ newlib-redox/newlib/libc/include/sys/config.h 2016-07-27 10:24:29.687001123 -0700 +@@ -94,9 +94,9 @@ + #define HAVE_GETDATE + #define _HAVE_SYSTYPES + #define _READ_WRITE_RETURN_TYPE _ssize_t +-#define __LARGE64_FILES 1 ++//#define __LARGE64_FILES 1 + /* we use some glibc header files so turn on glibc large file feature */ +-#define _LARGEFILE64_SOURCE 1 ++//#define _LARGEFILE64_SOURCE 1 + #endif + #endif + +diff -rupNZ newlib/newlib/libc/sys/configure.in newlib-redox/newlib/libc/sys/configure.in +--- newlib/newlib/libc/sys/configure.in 2015-08-24 10:09:16.000000000 -0700 ++++ newlib-redox/newlib/libc/sys/configure.in 2016-07-27 10:24:29.687001123 -0700 +@@ -36,6 +36,7 @@ if test -n "${sys_dir}"; then + netware) AC_CONFIG_SUBDIRS(netware) ;; + or1k) AC_CONFIG_SUBDIRS(or1k) ;; + rdos) AC_CONFIG_SUBDIRS(rdos) ;; ++ redox) AC_CONFIG_SUBDIRS(redox) ;; + rtems) AC_CONFIG_SUBDIRS(rtems) ;; + sh) AC_CONFIG_SUBDIRS(sh) ;; + sparc64) AC_CONFIG_SUBDIRS(sparc64) ;;