From 6436a1e9390e7ba81aa71a9fa238545b2ef894ed Mon Sep 17 00:00:00 2001 From: Damian Date: Wed, 17 Jun 2020 22:21:21 -0300 Subject: [PATCH 1/3] Fix access() sysLv2FsAccess() crashes and halts the system :-( this is a workaround that doesn't use the lv2 syscall --- ppu/librt/access.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/ppu/librt/access.c b/ppu/librt/access.c index acad11c0..44a7211f 100644 --- a/ppu/librt/access.c +++ b/ppu/librt/access.c @@ -5,9 +5,78 @@ #include #include #include +/* #include #include +*/ +#include +#include + + +int _access(const char *fn, int flags, int* _errno) +{ + struct stat s; + *_errno = 0; + + /* Did the pass us the right flags? */ + if ( (flags != F_OK) && (flags != R_OK) && (flags != W_OK) && (flags != X_OK) ) { + /* Nope. */ + *_errno = EINVAL; + return -1; + } + + if (stat(fn, &s)) { + /* return -1 because the file does not exist or pathname is too long. */ + return -1; + } + + if (flags == F_OK) { + /* We know the file exists because stat didn't fail. */ + return 0; + } + + if (flags & W_OK) { + /* Do we have write permission to the file? */ + if (s.st_mode & S_IWRITE) { + /* We do. */ + return 0; + } + + /* Nope. */ + *_errno = EACCES; + return -1; + } + + if (flags & R_OK) { + /* Do we have read permission to the file? */ + if (s.st_mode & S_IREAD) { + /* We do. */ + return 0; + } + + /* Nope. */ + *_errno = EACCES; + return -1; + } + + if (flags & X_OK) { + /* Do we have executable permission to the file? */ + if (s.st_mode & S_IEXEC) { + /* We do. */ + return 0; + } + + /* Nope. */ + *_errno = EACCES; + return -1; + } + + /* We should never reach this, ever...in case we do though, lets return -1. */ + /* and set errno to ENOSYS (Function not implemented */ + *_errno = ENOSYS; + return -1; +} int _DEFUN(__librt_access_r,(r,path,amode), @@ -15,5 +84,9 @@ _DEFUN(__librt_access_r,(r,path,amode), const char *path _AND int amode) { +/* + Lv2 syscall 816 (sys_fs_access) crashes, so we use a standard implementation return lv2errno_r(r,sysLv2FsAccess(path,amode)); +*/ + return _access(path,amode,&r->_errno); } From 12da52b5dcd1cace824f1f00d6b70ad6f4c9f036 Mon Sep 17 00:00:00 2001 From: Damian Date: Sat, 20 Jun 2020 22:37:35 -0300 Subject: [PATCH 2/3] Clean-up by definition, the runtime library shouldn't reset errno to 0. --- ppu/librt/access.c | 1 - 1 file changed, 1 deletion(-) diff --git a/ppu/librt/access.c b/ppu/librt/access.c index 44a7211f..c43cc4e0 100644 --- a/ppu/librt/access.c +++ b/ppu/librt/access.c @@ -17,7 +17,6 @@ int _access(const char *fn, int flags, int* _errno) { struct stat s; - *_errno = 0; /* Did the pass us the right flags? */ if ( (flags != F_OK) && (flags != R_OK) && (flags != W_OK) && (flags != X_OK) ) { From 3211903ddf58cac2260a390bc358b9909bd097bf Mon Sep 17 00:00:00 2001 From: Damian Parrino Date: Tue, 23 Jun 2020 12:11:39 -0300 Subject: [PATCH 3/3] Remove sysLv2FsAccess + remove access.c --- ppu/crt/crt1.c | 2 - ppu/include/sys/file.h | 6 --- ppu/librt/Makefile | 2 +- ppu/librt/access.c | 91 ------------------------------------------ 4 files changed, 1 insertion(+), 100 deletions(-) delete mode 100644 ppu/librt/access.c diff --git a/ppu/crt/crt1.c b/ppu/crt/crt1.c index 278f680a..dd8eaa37 100644 --- a/ppu/crt/crt1.c +++ b/ppu/crt/crt1.c @@ -37,7 +37,6 @@ extern void __librt_seekdir_r(struct _reent *r,DIR *dirp,long int loc); extern int __librt_rmdir_r(struct _reent *r,const char *dirname); extern int __librt_link_r(struct _reent *r,const char *old,const char *new); extern int __librt_unlink_r(struct _reent *r,const char *path); -extern int __librt_access_r(struct _reent *r,const char *path,int amode); extern int __librt_utime_r(struct _reent *r,const char *path,const struct utimbuf *times); extern int __librt_usleep_r(struct _reent *r,useconds_t usec); @@ -88,7 +87,6 @@ static void __syscalls_init(void) __syscalls.rmdir_r = __librt_rmdir_r; __syscalls.link_r = __librt_link_r; __syscalls.unlink_r = __librt_unlink_r; - __syscalls.access_r = __librt_access_r; __syscalls.utime_r = __librt_utime_r; __syscalls.sleep_r = __librt_sleep_r; diff --git a/ppu/include/sys/file.h b/ppu/include/sys/file.h index 60ebd70a..3d00d420 100644 --- a/ppu/include/sys/file.h +++ b/ppu/include/sys/file.h @@ -132,12 +132,6 @@ LV2_SYSCALL sysLv2FsLink(const char *oldpath,const char *newpath) return_to_user_prog(s32); } -LV2_SYSCALL sysLv2FsAccess(const char *path,s32 amode) -{ - lv2syscall2(816,(u64)path,amode); - return_to_user_prog(s32); -} - #ifdef __cplusplus } #endif diff --git a/ppu/librt/Makefile b/ppu/librt/Makefile index ae153d87..3036da8d 100644 --- a/ppu/librt/Makefile +++ b/ppu/librt/Makefile @@ -45,7 +45,7 @@ VPATH := $(BASEDIR) OBJS := \ sbrk.o exit.o close.o lseek.o read.o open.o sleep.o write.o fstat.o \ socket.o lock.o dirent.o mkdir.o times.o umask.o lv2errno.o heap.o \ - chmod.o rename.o rmdir.o isatty.o gettod.o settod.o unlink.o access.o \ + chmod.o rename.o rmdir.o isatty.o gettod.o settod.o unlink.o \ link.o truncate.o fsync.o utime.o all: ppu diff --git a/ppu/librt/access.c b/ppu/librt/access.c deleted file mode 100644 index c43cc4e0..00000000 --- a/ppu/librt/access.c +++ /dev/null @@ -1,91 +0,0 @@ -#include -#include -#include <_ansi.h> -#include <_syslist.h> -#include -#include -#include -/* -#include - -#include -*/ -#include -#include - - -int _access(const char *fn, int flags, int* _errno) -{ - struct stat s; - - /* Did the pass us the right flags? */ - if ( (flags != F_OK) && (flags != R_OK) && (flags != W_OK) && (flags != X_OK) ) { - /* Nope. */ - *_errno = EINVAL; - return -1; - } - - if (stat(fn, &s)) { - /* return -1 because the file does not exist or pathname is too long. */ - return -1; - } - - if (flags == F_OK) { - /* We know the file exists because stat didn't fail. */ - return 0; - } - - if (flags & W_OK) { - /* Do we have write permission to the file? */ - if (s.st_mode & S_IWRITE) { - /* We do. */ - return 0; - } - - /* Nope. */ - *_errno = EACCES; - return -1; - } - - if (flags & R_OK) { - /* Do we have read permission to the file? */ - if (s.st_mode & S_IREAD) { - /* We do. */ - return 0; - } - - /* Nope. */ - *_errno = EACCES; - return -1; - } - - if (flags & X_OK) { - /* Do we have executable permission to the file? */ - if (s.st_mode & S_IEXEC) { - /* We do. */ - return 0; - } - - /* Nope. */ - *_errno = EACCES; - return -1; - } - - /* We should never reach this, ever...in case we do though, lets return -1. */ - /* and set errno to ENOSYS (Function not implemented */ - *_errno = ENOSYS; - return -1; -} - -int -_DEFUN(__librt_access_r,(r,path,amode), - struct _reent *r _AND - const char *path _AND - int amode) -{ -/* - Lv2 syscall 816 (sys_fs_access) crashes, so we use a standard implementation - return lv2errno_r(r,sysLv2FsAccess(path,amode)); -*/ - return _access(path,amode,&r->_errno); -}