@@ -7049,7 +7049,7 @@ index 000000000..2bada9736
70497049+ }
70507050diff --git a/libgloss/libsysbase/fpathconf.c b/libgloss/libsysbase/fpathconf.c
70517051new file mode 100644
7052- index 000000000..453f64870
7052+ index 000000000..9cba92a72
70537053--- /dev/null
70547054+++ b/libgloss/libsysbase/fpathconf.c
70557055@@ -0,0 +1,30 @@
@@ -7069,7 +7069,7 @@ index 000000000..453f64870
70697069+ struct _reent *r = _REENT;
70707070+
70717071+ if ( NULL == handle ) {
7072- + errno = EINVAL ;
7072+ + errno = EBADF ;
70737073+ return ret;
70747074+ }
70757075+
@@ -7085,10 +7085,10 @@ index 000000000..453f64870
70857085+ }
70867086diff --git a/libgloss/libsysbase/fstat.c b/libgloss/libsysbase/fstat.c
70877087new file mode 100644
7088- index 000000000..32267b828
7088+ index 000000000..94924d802
70897089--- /dev/null
70907090+++ b/libgloss/libsysbase/fstat.c
7091- @@ -0,0 +1,32 @@
7091+ @@ -0,0 +1,35 @@
70927092+ #include "config.h"
70937093+ #include <_ansi.h>
70947094+ #include <_syslist.h>
@@ -7108,7 +7108,10 @@ index 000000000..32267b828
71087108+ if(fileDesc!=-1) {
71097109+ handle = __get_handle(fileDesc);
71107110+
7111- + if ( NULL == handle ) return ret;
7111+ + if ( NULL == handle ) {
7112+ + errno = EBADF;
7113+ + return ret;
7114+ + }
71127115+
71137116+ dev = handle->device;
71147117+
@@ -7123,7 +7126,7 @@ index 000000000..32267b828
71237126+ }
71247127diff --git a/libgloss/libsysbase/fsync.c b/libgloss/libsysbase/fsync.c
71257128new file mode 100644
7126- index 000000000..fb06cb6d1
7129+ index 000000000..e63e3762b
71277130--- /dev/null
71287131+++ b/libgloss/libsysbase/fsync.c
71297132@@ -0,0 +1,34 @@
@@ -7147,7 +7150,7 @@ index 000000000..fb06cb6d1
71477150+ handle = __get_handle(fileDesc);
71487151+
71497152+ if ( NULL == handle ) {
7150- + errno = EINVAL ;
7153+ + errno = EBADF ;
71517154+ return ret;
71527155+ }
71537156+
@@ -7163,7 +7166,7 @@ index 000000000..fb06cb6d1
71637166+ }
71647167diff --git a/libgloss/libsysbase/ftruncate.c b/libgloss/libsysbase/ftruncate.c
71657168new file mode 100644
7166- index 000000000..0cd7d0fc4
7169+ index 000000000..94b4a3761
71677170--- /dev/null
71687171+++ b/libgloss/libsysbase/ftruncate.c
71697172@@ -0,0 +1,34 @@
@@ -7187,7 +7190,7 @@ index 000000000..0cd7d0fc4
71877190+ handle = __get_handle(fileDesc);
71887191+
71897192+ if ( NULL == handle ) {
7190- + r->_errno = EINVAL ;
7193+ + r->_errno=EBADF ;
71917194+ return ret;
71927195+ }
71937196+
@@ -7732,10 +7735,10 @@ index 000000000..d7a988359
77327735+
77337736diff --git a/libgloss/libsysbase/lseek.c b/libgloss/libsysbase/lseek.c
77347737new file mode 100644
7735- index 000000000..39ef385b1
7738+ index 000000000..c5568e338
77367739--- /dev/null
77377740+++ b/libgloss/libsysbase/lseek.c
7738- @@ -0,0 +1,35 @@
7741+ @@ -0,0 +1,38 @@
77397742+ #include "config.h"
77407743+ #include <_ansi.h>
77417744+ #include <_syslist.h>
@@ -7757,7 +7760,10 @@ index 000000000..39ef385b1
77577760+
77587761+ handle = __get_handle(fileDesc);
77597762+
7760- + if ( NULL == handle ) return ret;
7763+ + if ( NULL == handle ) {
7764+ + r->_errno=EBADF;
7765+ + return ret;
7766+ + }
77617767+
77627768+ dev = handle->device;
77637769+
@@ -7941,10 +7947,10 @@ index 000000000..a696c9ab9
79417947+ }
79427948diff --git a/libgloss/libsysbase/read.c b/libgloss/libsysbase/read.c
79437949new file mode 100644
7944- index 000000000..9c548d830
7950+ index 000000000..30505c7b6
79457951--- /dev/null
79467952+++ b/libgloss/libsysbase/read.c
7947- @@ -0,0 +1,32 @@
7953+ @@ -0,0 +1,35 @@
79487954+ #include "config.h"
79497955+ #include <_ansi.h>
79507956+ #include <_syslist.h>
@@ -7964,7 +7970,10 @@ index 000000000..9c548d830
79647970+ if(fileDesc!=-1) {
79657971+ handle = __get_handle(fileDesc);
79667972+
7967- + if ( NULL == handle ) return ret;
7973+ + if ( NULL == handle ) {
7974+ + r->_errno=EBADF;
7975+ + return ret;
7976+ + }
79687977+
79697978+ dev = handle->device;
79707979+
@@ -8919,10 +8928,10 @@ index 000000000..2c2998250
89198928+ #endif /* __WARNING_H__ */
89208929diff --git a/libgloss/libsysbase/write.c b/libgloss/libsysbase/write.c
89218930new file mode 100644
8922- index 000000000..04198e854
8931+ index 000000000..baf0d6ae5
89238932--- /dev/null
89248933+++ b/libgloss/libsysbase/write.c
8925- @@ -0,0 +1,31 @@
8934+ @@ -0,0 +1,34 @@
89268935+ #include "config.h"
89278936+ #include <_ansi.h>
89288937+ #include <_syslist.h>
@@ -8942,7 +8951,10 @@ index 000000000..04198e854
89428951+ if(fileDesc!=-1) {
89438952+ handle = __get_handle(fileDesc);
89448953+
8945- + if ( NULL == handle ) return ret;
8954+ + if ( NULL == handle ) {
8955+ + r->_errno=EBADF;
8956+ + return ret;
8957+ + }
89468958+
89478959+ dev = handle->device;
89488960+
@@ -9019,11 +9031,11 @@ index ef5038e68..32a1d5e0b 100644
90199031 .stab 0 : { *(.stab) }
90209032diff --git a/libgloss/rs6000/crtmain.c b/libgloss/rs6000/crtmain.c
90219033new file mode 100644
9022- index 000000000..bd25d775d
9034+ index 000000000..7f8850624
90239035--- /dev/null
90249036+++ b/libgloss/rs6000/crtmain.c
9025- @@ -0,0 +1,18 @@
9026- + #include <unistd .h>
9037+ @@ -0,0 +1,20 @@
9038+ + #include <stdlib .h>
90279039+
90289040+ struct __argv {
90299041+ int argvMagic; //!< argv magic number, set to 0x5f617267 ('_arg') if valid
@@ -9037,10 +9049,28 @@ index 000000000..bd25d775d
90379049+ void __init();
90389050+ void SYS_PreMain();
90399051+
9052+ + int main(int argc, char **argv);
9053+ +
90409054+ void __crtmain() {
90419055+ SYS_PreMain();
90429056+ exit ( main(__system_argv->argc,__system_argv->argv) );
90439057+ }
9058+ diff --git a/libgloss/rs6000/mbx-print.c b/libgloss/rs6000/mbx-print.c
9059+ index 64472ee68..5a16e1ab7 100644
9060+ --- a/libgloss/rs6000/mbx-print.c
9061+ +++ b/libgloss/rs6000/mbx-print.c
9062+ @@ -15,7 +15,10 @@
9063+
9064+ /*
9065+ * print -- do a raw print of a string
9066+ - */
9067+ + */
9068+ +
9069+ + #include <unistd.h>
9070+ +
9071+ void
9072+ print (ptr)
9073+ char *ptr;
90449074diff --git a/libgloss/rs6000/mbx.ld b/libgloss/rs6000/mbx.ld
90459075index cedf4e867..99d849e90 100644
90469076--- a/libgloss/rs6000/mbx.ld
@@ -9053,6 +9083,77 @@ index cedf4e867..99d849e90 100644
90539083 /* These are needed for ELF backends which have not yet been
90549084 converted to the new style linker. */
90559085 .stab 0 : { *(.stab) }
9086+ diff --git a/libgloss/rs6000/mvme-print.c b/libgloss/rs6000/mvme-print.c
9087+ index 8d195424e..bae0eaf7c 100644
9088+ --- a/libgloss/rs6000/mvme-print.c
9089+ +++ b/libgloss/rs6000/mvme-print.c
9090+ @@ -17,6 +17,10 @@
9091+ * write -- write some bytes to the output device.
9092+ */
9093+
9094+ + void __outln( char *ptr, char *q);
9095+ + void __outstr( char *ptr, char *q);
9096+ + void __pcrlf();
9097+ +
9098+ int
9099+ write (fd, ptr, len)
9100+ int fd;
9101+ diff --git a/libgloss/rs6000/sim-abort.c b/libgloss/rs6000/sim-abort.c
9102+ index e1b59cf19..faeb93153 100644
9103+ --- a/libgloss/rs6000/sim-abort.c
9104+ +++ b/libgloss/rs6000/sim-abort.c
9105+ @@ -14,6 +14,9 @@
9106+ * they apply.
9107+ */
9108+
9109+ + #include <unistd.h>
9110+ + #include <stdlib.h>
9111+ +
9112+ void abort(void)
9113+ {
9114+ write (2, "Abort called.\n", sizeof("Abort called.\n")-1);
9115+ diff --git a/libgloss/rs6000/sim-inbyte.c b/libgloss/rs6000/sim-inbyte.c
9116+ index 787b68976..44b273dff 100644
9117+ --- a/libgloss/rs6000/sim-inbyte.c
9118+ +++ b/libgloss/rs6000/sim-inbyte.c
9119+ @@ -14,6 +14,8 @@
9120+ * they apply.
9121+ */
9122+
9123+ + #include <unistd.h>
9124+ +
9125+ int
9126+ inbyte ()
9127+ {
9128+ diff --git a/libgloss/rs6000/sim-print.c b/libgloss/rs6000/sim-print.c
9129+ index c0b9adced..911d8f4a2 100644
9130+ --- a/libgloss/rs6000/sim-print.c
9131+ +++ b/libgloss/rs6000/sim-print.c
9132+ @@ -15,7 +15,10 @@
9133+
9134+ /*
9135+ * print -- do a raw print of a string
9136+ - */
9137+ + */
9138+ +
9139+ + #include <unistd.h>
9140+ +
9141+ void
9142+ print (ptr)
9143+ char *ptr;
9144+ diff --git a/libgloss/rs6000/sim-sbrk.c b/libgloss/rs6000/sim-sbrk.c
9145+ index 5c8bd6522..9cf7de25d 100644
9146+ --- a/libgloss/rs6000/sim-sbrk.c
9147+ +++ b/libgloss/rs6000/sim-sbrk.c
9148+ @@ -17,6 +17,8 @@
9149+ extern char _end[];
9150+ static char *curbrk = _end;
9151+
9152+ + int brk(char *curbrk);
9153+ +
9154+ char *
9155+ sbrk (incr)
9156+ int incr;
90569157diff --git a/libgloss/rs6000/xilinx.ld b/libgloss/rs6000/xilinx.ld
90579158index 75b2a12b6..40a4a1e4b 100644
90589159--- a/libgloss/rs6000/xilinx.ld
@@ -9337,24 +9438,27 @@ index fa3e26879..4da1a374e 100644
93379438 __END_DECLS
93389439
93399440diff --git a/newlib/libc/include/sys/config.h b/newlib/libc/include/sys/config.h
9340- index 5dcc77a80..c53fce983 100644
9441+ index 5dcc77a80..fdf232649 100644
93419442--- a/newlib/libc/include/sys/config.h
93429443+++ b/newlib/libc/include/sys/config.h
9343- @@ -4,8 +4,18 @@
9444+ @@ -4,8 +4,21 @@
93449445 #include <machine/ieeefp.h> /* floating point macros */
93459446 #include <sys/features.h> /* POSIX defs */
93469447
93479448- #ifdef __aarch64__
93489449+ #ifdef __DEVKITARM__
93499450+ #define __DYNAMIC_REENT__
9451+ + #define MALLOC_ALIGNMENT_THRESHOLD 32
93509452+ #endif
93519453+
93529454+ #ifdef __DEVKITA64__
93539455 #define MALLOC_ALIGNMENT 16
9456+ + #define MALLOC_ALIGNMENT_THRESHOLD 32
93549457+ #define __DYNAMIC_REENT__
93559458+ #endif
93569459+
93579460+ #ifdef __DEVKITPPC__
9461+ + #define MALLOC_ALIGNMENT_THRESHOLD 64
93589462+ #define __BUFSIZ__ 32768
93599463+ #define __DYNAMIC_REENT__
93609464 #endif
@@ -10121,7 +10225,7 @@ index 8664dc3e5..dbaba0264 100644
1012110225 fp->_r -= resid;
1012210226 fp->_p += resid;
1012310227diff --git a/newlib/libc/stdio/makebuf.c b/newlib/libc/stdio/makebuf.c
10124- index b9c75bbf8..d748d5dc8 100644
10228+ index b9c75bbf8..bc65acc2a 100644
1012510229--- a/newlib/libc/stdio/makebuf.c
1012610230+++ b/newlib/libc/stdio/makebuf.c
1012710231@@ -19,6 +19,7 @@
@@ -10132,12 +10236,15 @@ index b9c75bbf8..d748d5dc8 100644
1013210236 #include <sys/stat.h>
1013310237 #include <sys/types.h>
1013410238 #include <sys/unistd.h>
10135- @@ -50,7 +51,7 @@ __smakebuf_r (struct _reent *ptr,
10239+ @@ -50,7 +51,11 @@ __smakebuf_r (struct _reent *ptr,
1013610240 return;
1013710241 }
1013810242 flags = __swhatbuf_r (ptr, fp, &size, &couldbetty);
10139- - if ((p = _malloc_r (ptr, size)) == NULL)
10140- + if ((p = _memalign_r (ptr, 64, size)) == NULL)
10243+ + #ifdef MALLOC_ALIGNMENT_THRESHOLD
10244+ + if ((p = _memalign_r (ptr, MALLOC_ALIGNMENT_THRESHOLD, size)) == NULL)
10245+ + #else
10246+ if ((p = _malloc_r (ptr, size)) == NULL)
10247+ + #endif
1014110248 {
1014210249 if (!(fp->_flags & __SSTR))
1014310250 {
@@ -10277,18 +10384,20 @@ index 710440389..985e720bf 100644
1027710384
1027810385 #endif /* _WANT_REGISTER_FINI */
1027910386diff --git a/newlib/libc/stdlib/malloc.c b/newlib/libc/stdlib/malloc.c
10280- index f5ac29208..3f21ea154 100644
10387+ index f5ac29208..7d016a653 100644
1028110388--- a/newlib/libc/stdlib/malloc.c
1028210389+++ b/newlib/libc/stdlib/malloc.c
10283- @@ -161,7 +161,10 @@ Supporting OS subroutines required: <<sbrk>>. */
10390+ @@ -161,7 +161,12 @@ Supporting OS subroutines required: <<sbrk>>. */
1028410391 void *
1028510392 malloc (size_t nbytes) /* get a block */
1028610393 {
1028710394- return _malloc_r (_REENT, nbytes);
10288- + if (nbytes < 64)
10289- + return _malloc_r (_REENT, nbytes);
10395+ + #ifdef MALLOC_ALIGNMENT_THRESHOLD
10396+ + if (nbytes >= MALLOC_ALIGNMENT_THRESHOLD)
10397+ + return _memalign_r (_REENT, MALLOC_ALIGNMENT_THRESHOLD, nbytes);
1029010398+ else
10291- + return _memalign_r (_REENT, 64, nbytes);
10399+ + #endif
10400+ + return _malloc_r (_REENT, nbytes);
1029210401 }
1029310402
1029410403 void
0 commit comments