@@ -46,7 +46,7 @@ index f38d5298e..db6b33ab8 100644
4646 AC_SUBST(AS)
4747diff --git a/libgloss/libsysbase/Makefile.in b/libgloss/libsysbase/Makefile.in
4848new file mode 100644
49- index 000000000..183f9acc7
49+ index 000000000..bd69599a8
5050--- /dev/null
5151+++ b/libgloss/libsysbase/Makefile.in
5252@@ -0,0 +1,148 @@
@@ -121,8 +121,8 @@ index 000000000..183f9acc7
121121+ isatty.o kill.o link.o lseek.o lstat.o nanosleep.o open.o read.o sbrk.o sleep.o stat.o usleep.o times.o \
122122+ unlink.o wait.o write.o _exit.o malloc_vars.o \
123123+ chdir.o mkdir.o rename.o build_argv.o statvfs.o \
124- + flock.o syscall_support.o handle_manager.o truncate.o ftruncate.o dirent.o fsync.o \
125- + fchmod.o chmod.o rmdir.o utime.o scandir.o
124+ + flock.o handle_manager.o truncate.o ftruncate.o dirent.o fsync.o \
125+ + fchmod.o chmod.o rmdir.o utime.o scandir.o syscall_support.o
126126+
127127+ # Object files specific to particular targets.
128128+ EVALOBJS = ${OBJS}
@@ -143,10 +143,10 @@ index 000000000..183f9acc7
143143+ AR_FLAGS = qc
144144+
145145+ .c.o:
146- + $(CC) $(CFLAGS_FOR_TARGET) -O2 $(INCLUDES) -c $(CFLAGS) $<
146+ + $(CC) $(CFLAGS_FOR_TARGET) -D_BUILDING_LIBSYSBASE - O2 $(INCLUDES) -c $(CFLAGS) $<
147147+
148148+ .C.o:
149- + $(CC) $(CFLAGS_FOR_TARGET) -O2 $(INCLUDES) -c $(CFLAGS) $<
149+ + $(CC) $(CFLAGS_FOR_TARGET) -D_BUILDING_LIBSYSBASE - O2 $(INCLUDES) -c $(CFLAGS) $<
150150+ .s.o:
151151+ $(AS) $(ASFLAGS_FOR_TARGET) $(INCLUDES) $(ASFLAGS) -o $*.o $<
152152+
@@ -200,7 +200,7 @@ index 000000000..183f9acc7
200200+ $(SHELL) config.status --recheck
201201diff --git a/libgloss/libsysbase/_exit.c b/libgloss/libsysbase/_exit.c
202202new file mode 100644
203- index 000000000..e5cb5a9ed
203+ index 000000000..6effb1105
204204--- /dev/null
205205+++ b/libgloss/libsysbase/_exit.c
206206@@ -0,0 +1,17 @@
@@ -215,8 +215,8 @@ index 000000000..e5cb5a9ed
215215+ void _exit(int rc)
216216+ {
217217+
218- + if ( __syscalls. exit ) {
219- + __syscalls.exit (rc);
218+ + if ( __has_syscall( exit) ) {
219+ + __syscall_exit (rc);
220220+ }
221221+
222222+ while(1);
@@ -903,7 +903,7 @@ index 000000000..3668b5801
903903+
904904diff --git a/libgloss/libsysbase/clocks.c b/libgloss/libsysbase/clocks.c
905905new file mode 100644
906- index 000000000..01cfee469
906+ index 000000000..b36b5c079
907907--- /dev/null
908908+++ b/libgloss/libsysbase/clocks.c
909909@@ -0,0 +1,34 @@
@@ -913,8 +913,8 @@ index 000000000..01cfee469
913913+
914914+ int clock_gettime(clockid_t clock_id, struct timespec *tp)
915915+ {
916- + if ( __syscalls. clock_gettime ) {
917- + return __syscalls.clock_gettime (clock_id, tp);
916+ + if ( __has_syscall( clock_gettime) ) {
917+ + return __syscall_clock_gettime (clock_id, tp);
918918+ } else {
919919+ errno = ENOSYS;
920920+ return -1;
@@ -923,8 +923,8 @@ index 000000000..01cfee469
923923+
924924+ int clock_settime(clockid_t clock_id, const struct timespec *tp)
925925+ {
926- + if ( __syscalls. clock_settime ) {
927- + return __syscalls.clock_settime (clock_id, tp);
926+ + if ( __has_syscall( clock_settime) ) {
927+ + return __syscall_clock_settime (clock_id, tp);
928928+ } else {
929929+ errno = ENOSYS;
930930+ return -1;
@@ -933,8 +933,8 @@ index 000000000..01cfee469
933933+
934934+ int clock_getres (clockid_t clock_id, struct timespec *res)
935935+ {
936- + if ( __syscalls. clock_getres ) {
937- + return __syscalls.clock_getres (clock_id, res);
936+ + if ( __has_syscall( clock_getres) ) {
937+ + return __syscall_clock_getres (clock_id, res);
938938+ } else {
939939+ errno = ENOSYS;
940940+ return -1;
@@ -5938,7 +5938,7 @@ index 000000000..ec3b84037
59385938+
59395939diff --git a/libgloss/libsysbase/gettod.c b/libgloss/libsysbase/gettod.c
59405940new file mode 100644
5941- index 000000000..11dc528fa
5941+ index 000000000..ee8947f51
59425942--- /dev/null
59435943+++ b/libgloss/libsysbase/gettod.c
59445944@@ -0,0 +1,26 @@
@@ -5961,7 +5961,7 @@ index 000000000..11dc528fa
59615961+ struct _reent *ptr = _REENT;
59625962+ #endif
59635963+
5964- + if ( __syscalls. gettod_r ) return __syscalls.gettod_r (ptr, ptimeval, ptimezone);
5964+ + if ( __has_syscall( gettod_r) ) return __syscall_gettod_r (ptr, ptimeval, ptimezone);
59655965+
59665966+ ptr->_errno = ENOSYS;
59675967+ return -1;
@@ -6518,7 +6518,7 @@ index 000000000..b4fcbd3d7
65186518+ }
65196519diff --git a/libgloss/libsysbase/nanosleep.c b/libgloss/libsysbase/nanosleep.c
65206520new file mode 100644
6521- index 000000000..3c96fc61b
6521+ index 000000000..a233b9df6
65226522--- /dev/null
65236523+++ b/libgloss/libsysbase/nanosleep.c
65246524@@ -0,0 +1,14 @@
@@ -6528,8 +6528,8 @@ index 000000000..3c96fc61b
65286528+
65296529+ int nanosleep(const struct timespec *req, struct timespec *rem)
65306530+ {
6531- + if ( __syscalls. nanosleep ) {
6532- + return __syscalls.nanosleep (req, rem);
6531+ + if ( __has_syscall( nanosleep) ) {
6532+ + return __syscall_nanosleep (req, rem);
65336533+ } else {
65346534+ *rem = *req;
65356535+ errno = ENOSYS;
@@ -6711,7 +6711,7 @@ index 000000000..2692a2997
67116711+ }
67126712diff --git a/libgloss/libsysbase/sbrk.c b/libgloss/libsysbase/sbrk.c
67136713new file mode 100644
6714- index 000000000..e2bdb9edc
6714+ index 000000000..83d922d85
67156715--- /dev/null
67166716+++ b/libgloss/libsysbase/sbrk.c
67176717@@ -0,0 +1,26 @@
@@ -6731,8 +6731,8 @@ index 000000000..e2bdb9edc
67316731+ #endif
67326732+
67336733+
6734- + if ( __syscalls. sbrk_r ) {
6735- + return __syscalls.sbrk_r (ptr, incr);
6734+ + if ( __has_syscall( sbrk_r) ) {
6735+ + return __syscall_sbrk_r (ptr, incr);
67366736+ } else {
67376737+
67386738+ ptr->_errno = ENOMEM;
@@ -6922,75 +6922,57 @@ index 000000000..84e221340
69226922+ }
69236923diff --git a/libgloss/libsysbase/syscall_support.c b/libgloss/libsysbase/syscall_support.c
69246924new file mode 100644
6925- index 000000000..f02714764
6925+ index 000000000..39e75fd0b
69266926--- /dev/null
69276927+++ b/libgloss/libsysbase/syscall_support.c
6928- @@ -0,0 +1,67 @@
6928+ @@ -0,0 +1,49 @@
69296929+ #include <sys/iosupport.h>
69306930+
6931- + //---------------------------------------------------------------------------------
6932- + __syscalls_t __syscalls = {
6933- + //---------------------------------------------------------------------------------
6934- + NULL, // sbrk
6935- + NULL, // lock_init
6936- + NULL, // lock_close
6937- + NULL, // lock_release
6938- + NULL, // lock_acquire
6939- + NULL, // malloc_lock
6940- + NULL, // malloc_unlock
6941- + NULL, // exit
6942- + NULL, // gettod_r
6943- + NULL, // clock_gettime
6944- + NULL, // clock_settime
6945- + NULL, // clock_getres
6946- + NULL // nanosleep
6947- + };
6948- +
69496931+ int __libc_lock_init(int *lock,int recursive) {
69506932+
6951- + if ( __syscalls. lock_init ) {
6952- + return __syscalls.lock_init (lock, recursive);
6933+ + if ( __has_syscall( lock_init) ) {
6934+ + return __syscall_lock_init (lock, recursive);
69536935+ }
69546936+
69556937+ return 0;
69566938+ }
69576939+
69586940+ int __libc_lock_close( int *lock ) {
69596941+
6960- + if ( __syscalls. lock_close) {
6961- + return __syscalls.lock_close (lock);
6942+ + if ( __has_syscall( lock_close) ) {
6943+ + return __syscall_lock_close (lock);
69626944+ }
69636945+
69646946+ return 0;
69656947+ }
69666948+
69676949+ int __libc_lock_release( int *lock ) {
69686950+
6969- + if ( __syscalls. lock_release) {
6970- + return __syscalls.lock_release (lock);
6951+ + if ( __has_syscall( lock_release) ) {
6952+ + return __syscall_lock_release (lock);
69716953+ }
69726954+
69736955+ return 0;
69746956+ }
69756957+
69766958+ int __libc_lock_acquire( int *lock ) {
69776959+
6978- + if ( __syscalls. lock_acquire) {
6979- + return __syscalls.lock_acquire (lock);
6960+ + if ( __has_syscall( lock_acquire) ) {
6961+ + return __syscall_lock_acquire (lock);
69806962+ }
69816963+
69826964+ return 0;
69836965+ }
69846966+
69856967+ void __malloc_lock( struct _reent *ptr ) {
6986- + if ( __syscalls. malloc_lock) {
6987- + __syscalls.malloc_lock (ptr);
6968+ + if ( __has_syscall( malloc_lock) ) {
6969+ + __syscall_malloc_lock (ptr);
69886970+ }
69896971+ }
69906972+
69916973+ void __malloc_unlock( struct _reent *ptr ) {
6992- + if ( __syscalls. malloc_unlock) {
6993- + __syscalls.malloc_unlock (ptr);
6974+ + if ( __has_syscall( malloc_unlock) ) {
6975+ + __syscall_malloc_unlock (ptr);
69946976+ }
69956977+ }
69966978diff --git a/libgloss/libsysbase/times.c b/libgloss/libsysbase/times.c
@@ -7486,10 +7468,10 @@ index 218807178..c9efd7d03 100644
74867468 #ifdef __rtems__
74877469diff --git a/newlib/libc/include/sys/iosupport.h b/newlib/libc/include/sys/iosupport.h
74887470new file mode 100644
7489- index 000000000..8b6d8da30
7471+ index 000000000..9bec9e473
74907472--- /dev/null
74917473+++ b/newlib/libc/include/sys/iosupport.h
7492- @@ -0,0 +1,108 @@
7474+ @@ -0,0 +1,117 @@
74937475+ //---------------------------------------------------------------------------------
74947476+ #ifndef __iosupp_h__
74957477+ #define __iosupp_h__
@@ -7524,6 +7506,7 @@ index 000000000..8b6d8da30
75247506+ void *dirStruct;
75257507+ } DIR_ITER;
75267508+
7509+ +
75277510+ typedef struct {
75287511+ const char *name;
75297512+ size_t structSize;
@@ -7562,23 +7545,31 @@ index 000000000..8b6d8da30
75627545+
75637546+ extern const devoptab_t *devoptab_list[];
75647547+
7565- + typedef struct {
7566- + void *(*sbrk_r) (struct _reent *ptr, ptrdiff_t incr);
7567- + int (*lock_init) (int *lock,int recursive);
7568- + int (*lock_close) (int *lock);
7569- + int (*lock_release) (int *lock);
7570- + int (*lock_acquire) (int *lock);
7571- + void (*malloc_lock) (struct _reent *ptr);
7572- + void (*malloc_unlock) (struct _reent *ptr);
7573- + void (*exit) ( int rc );
7574- + int (*gettod_r) (struct _reent *ptr, struct timeval *tp, struct timezone *tz);
7575- + int (*clock_gettime)(clockid_t clock_id, struct timespec *tp);
7576- + int (*clock_settime)(clockid_t clock_id, const struct timespec *tp);
7577- + int (*clock_getres)(clockid_t clock_id, struct timespec *res);
7578- + int (*nanosleep)(const struct timespec *req, struct timespec *rem);
7579- + } __syscalls_t;
7580- +
7581- + extern __syscalls_t __syscalls;
7548+ + #ifdef _BUILDING_LIBSYSBASE
7549+ + #define __SYSCALL(_name) __attribute__((weak)) __syscall_##_name
7550+ + #define __has_syscall(_name) (&__syscall_##_name)
7551+ + #else
7552+ + #define __SYSCALL(_name) __syscall_##_name
7553+ + #endif
7554+ +
7555+ + void *__SYSCALL(sbrk_r) (struct _reent *ptr, ptrdiff_t incr);
7556+ + int __SYSCALL(lock_init) (int *lock,int recursive);
7557+ +
7558+ + int __SYSCALL(lock_close) (int *lock);
7559+ + int __SYSCALL(lock_release) (int *lock);
7560+ + int __SYSCALL(lock_acquire) (int *lock);
7561+ + void __SYSCALL(malloc_lock) (struct _reent *ptr);
7562+ + void __SYSCALL(malloc_unlock) (struct _reent *ptr);
7563+ +
7564+ + void __SYSCALL(exit)(int rc);
7565+ +
7566+ + int __SYSCALL(gettod_r)(struct _reent *ptr, struct timeval *tp, struct timezone *tz);
7567+ + int __SYSCALL(clock_gettime)(clockid_t clock_id, struct timespec *tp);
7568+ + int __SYSCALL(clock_settime)(clockid_t clock_id, const struct timespec *tp);
7569+ + int __SYSCALL(clock_getres)(clockid_t clock_id, struct timespec *res);
7570+ + int __SYSCALL(nanosleep)(const struct timespec *req, struct timespec *rem);
7571+ +
7572+ + #undef __SYSCALL
75827573+
75837574+ int AddDevice( const devoptab_t* device);
75847575+ int FindDevice(const char* name);
@@ -8105,21 +8096,37 @@ index 022992b8d..bdf4c7bb0 100644
81058096 fp->_flags = flags;
81068097 fp->_cookie = (void *) fp;
81078098diff --git a/newlib/libc/stdio/fread.c b/newlib/libc/stdio/fread.c
8108- index b358d2b4a..9cab2180e 100644
8099+ index b358d2b4a..95493cd66 100644
81098100--- a/newlib/libc/stdio/fread.c
81108101+++ b/newlib/libc/stdio/fread.c
8111- @@ -225,7 +225,31 @@ _fread_r (struct _reent * ptr,
8102+ @@ -187,7 +187,6 @@ _fread_r (struct _reent * ptr,
8103+ int rc = 0;
8104+ /* save fp buffering state */
8105+ void *old_base = fp->_bf._base;
8106+ - void * old_p = fp->_p;
8107+ int old_size = fp->_bf._size;
8108+ /* allow __refill to use user's buffer */
8109+ fp->_bf._base = (unsigned char *) p;
8110+ @@ -197,7 +196,7 @@ _fread_r (struct _reent * ptr,
8111+ /* restore fp buffering back to original state */
8112+ fp->_bf._base = old_base;
8113+ fp->_bf._size = old_size;
8114+ - fp->_p = old_p;
8115+ + fp->_p = old_base;
8116+ resid -= fp->_r;
8117+ p += fp->_r;
8118+ fp->_r = 0;
8119+ @@ -225,7 +224,30 @@ _fread_r (struct _reent * ptr,
81128120 /* fp->_r = 0 ... done in __srefill */
81138121 p += r;
81148122 resid -= r;
81158123- if (__srefill_r (ptr, fp))
81168124+ int rc = 0;
81178125+
8118- + if (resid>BUFSIZ )
8126+ + if (resid>fp->_bf._size )
81198127+ {
81208128+ /* save fp buffering state */
81218129+ void *old_base = fp->_bf._base;
8122- + void * old_p = fp->_p;
81238130+ int old_size = fp->_bf._size;
81248131+ /* allow __refill to use user's buffer */
81258132+ fp->_bf._base = (unsigned char *) p;
@@ -8129,7 +8136,7 @@ index b358d2b4a..9cab2180e 100644
81298136+ /* restore fp buffering back to original state */
81308137+ fp->_bf._base = old_base;
81318138+ fp->_bf._size = old_size;
8132- + fp->_p = old_p ;
8139+ + fp->_p = old_base ;
81338140+ resid -= fp->_r;
81348141+ p += fp->_r;
81358142+ fp->_r = 0;
0 commit comments