diff --git a/ndk/sources/android/libportable/arch-mips/errno.c b/ndk/sources/android/libportable/arch-mips/errno.c index 6ccd5122f..14e292528 100644 --- a/ndk/sources/android/libportable/arch-mips/errno.c +++ b/ndk/sources/android/libportable/arch-mips/errno.c @@ -285,7 +285,7 @@ volatile int* WRAP(__errno)() int save_errno; /* pthread_* calls may modify errno so use a copy */ - save_errno = errno; + save_errno = *REAL(__errno)(); p = errno_key_data(); @@ -322,7 +322,7 @@ volatile int* WRAP(__errno)() ALOGV("%s: new save_errno:%d p:%p->{pshadow:%d, perrno:%d}", __func__, save_errno, p, p->pshadow, p->perrno); - errno = save_errno; + *REAL(__errno)() = save_errno; ALOGV("%s: return (&p->perrno):%p; }", __func__, &p->perrno); @@ -338,7 +338,7 @@ void WRAP(__set_errno)(int portable_errno) int save_errno; /* pthread_* calls may modify errno so use a copy */ - save_errno = errno; + save_errno = *REAL(__errno)(); p = errno_key_data(); @@ -352,7 +352,7 @@ void WRAP(__set_errno)(int portable_errno) ALOGV("%s: new save_errno:%d, p:%p->{pshadow:%d, perrno:%d}", __func__, save_errno, p, p->pshadow, p->perrno); - errno = save_errno; + *REAL(__errno)() = save_errno; ALOGV("%s: return; }", __func__); } diff --git a/ndk/sources/android/libportable/arch-mips/fcntl.c b/ndk/sources/android/libportable/arch-mips/fcntl.c index 2ef83e5dc..174b02719 100644 --- a/ndk/sources/android/libportable/arch-mips/fcntl.c +++ b/ndk/sources/android/libportable/arch-mips/fcntl.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -317,7 +318,7 @@ int WRAP(fcntl)(int fd, int portable_cmd, ...) if (invalid_pointer(flock_portable)) { ALOGE("%s: flock_portable:%p == {NULL||-1}", __func__, flock_portable); - errno = EFAULT; + *REAL(__errno)() = EFAULT; result = -1; goto done; } @@ -350,7 +351,7 @@ int WRAP(fcntl)(int fd, int portable_cmd, ...) if (invalid_pointer(flock_portable)) { ALOGE("%s: flock_portable:%p == {NULL||-1}", __func__, flock_portable); - errno = EFAULT; + *REAL(__errno)() = EFAULT; result = -1; goto done; } diff --git a/ndk/sources/android/libportable/arch-mips/filefd.c b/ndk/sources/android/libportable/arch-mips/filefd.c index f6e55fa46..d80eb3dd2 100644 --- a/ndk/sources/android/libportable/arch-mips/filefd.c +++ b/ndk/sources/android/libportable/arch-mips/filefd.c @@ -113,7 +113,7 @@ static int export_fd_env() ALOGV("%s:() {", __func__); - saved_errno = errno; + saved_errno = *REAL(__errno)(); type_env_allocated = malloc(max_env_size); fd_env_allocated = malloc(max_env_size); @@ -216,7 +216,7 @@ done: if (fd_env_allocated) free(fd_env_allocated); - errno = saved_errno; + *REAL(__errno)() = saved_errno; ALOGV("%s: return(rv:%d); }", __func__, rv); return rv; @@ -239,7 +239,7 @@ static int import_fd_env(int verify) ALOGV("%s:(verify:%d) {", __func__, verify); - saved_errno = errno; + saved_errno = *REAL(__errno)(); /* * get file descriptor environment pointer and make a @@ -328,7 +328,7 @@ done: if (fd_env_allocated) free(fd_env_allocated); - errno = saved_errno; + *REAL(__errno)() = saved_errno; ALOGV("%s: return(rv:%d); }", __func__, rv); return rv; diff --git a/ndk/sources/android/libportable/arch-mips/resource.c b/ndk/sources/android/libportable/arch-mips/resource.c index 38ee79dfc..91b473d3f 100644 --- a/ndk/sources/android/libportable/arch-mips/resource.c +++ b/ndk/sources/android/libportable/arch-mips/resource.c @@ -39,13 +39,13 @@ static inline int mips_change_resource(int resource) return resource; } -extern int getrlimit(int resource, struct rlimit *rlp); +extern int REAL(getrlimit)(int resource, struct rlimit *rlp); int WRAP(getrlimit)(int resource, struct rlimit *rlp) { return REAL(getrlimit)(mips_change_resource(resource), rlp); } -extern int setrlimit(int resource, const struct rlimit *rlp); +extern int REAL(setrlimit)(int resource, const struct rlimit *rlp); int WRAP(setrlimit)(int resource, const struct rlimit *rlp) { return REAL(setrlimit)(mips_change_resource(resource), rlp); diff --git a/ndk/sources/android/libportable/arch-mips/signal.c b/ndk/sources/android/libportable/arch-mips/signal.c index c96e898f1..4d2d2587c 100644 --- a/ndk/sources/android/libportable/arch-mips/signal.c +++ b/ndk/sources/android/libportable/arch-mips/signal.c @@ -1329,7 +1329,6 @@ __hidden int read_signalfd_mapper(int fd, void *buf, size_t count) return rv; } - int WRAP(sigsuspend)(const sigset_portable_t *portable_sigmask) { int rv; @@ -1338,7 +1337,7 @@ int WRAP(sigsuspend)(const sigset_portable_t *portable_sigmask) ALOGV("%s(portable_sigmask:%p) {", __func__, portable_sigmask); if (invalid_pointer((void *)portable_sigmask)) { - errno = EFAULT; + *REAL(__errno)() = EFAULT; rv = -1; } else { sigset_pton((sigset_portable_t *)portable_sigmask, &mips_sigmask); @@ -1359,7 +1358,7 @@ int WRAP(sigpending)(sigset_portable_t *portable_sigset) portable_sigset); if (invalid_pointer((void *)portable_sigset)) { - errno = EFAULT; + *REAL(__errno)() = EFAULT; rv = -1; } else { rv = REAL(sigpending)(&mips_sigset); @@ -1382,7 +1381,7 @@ int WRAP(sigwait)(const sigset_portable_t *portable_sigset, int *ptr_to_portable portable_sigset, ptr_to_portable_sig); if (invalid_pointer((void *)portable_sigset)) { - errno = EFAULT; + *REAL(__errno)() = EFAULT; rv = -1; } else { sigset_pton((sigset_portable_t *)portable_sigset, &mips_sigset); @@ -1508,7 +1507,7 @@ int WRAP(__rt_sigaction)(int portable_signum, const struct sigaction_portable *a /* NOTE: ARM kernel is expecting sizeof(sigset_t) to be 8 bytes */ if (sigsetsize != (2* sizeof(long))) { - errno = EINVAL; + *REAL(__errno)() = EINVAL; rv = -1; goto done; } @@ -1533,7 +1532,7 @@ int WRAP(__rt_sigprocmask)(int portable_how, /* NOTE: ARM kernel is expecting sizeof(sigset_t) to be 8 bytes */ if (sigsetsize != (2* sizeof(long))) { - errno = EINVAL; + *REAL(__errno)() = EINVAL; rv = -1; goto done; } @@ -1565,7 +1564,7 @@ int WRAP(__rt_sigtimedwait)(const sigset_portable_t *portable_sigset, /* NOTE: ARM kernel is expecting sizeof(sigset_t) to be 8 bytes */ if (portable_sigsetsize != (2* sizeof(long))) { - errno = EINVAL; + *REAL(__errno)() = EINVAL; rv = -1; goto done; } diff --git a/ndk/sources/android/libportable/arch-mips/stat.c b/ndk/sources/android/libportable/arch-mips/stat.c index 06fb42df9..8706f86e5 100644 --- a/ndk/sources/android/libportable/arch-mips/stat.c +++ b/ndk/sources/android/libportable/arch-mips/stat.c @@ -16,6 +16,7 @@ #include #include +#include #include /* Note: The Portable Header will define stat to stat_portable */ @@ -25,7 +26,7 @@ int WRAP(stat)(const char *path, struct stat_portable *s) int ret; if (invalid_pointer(s)) { - errno = EFAULT; + *REAL(__errno)() = EFAULT; return -1; } ret = REAL(stat)(path, &mips_stat); @@ -39,7 +40,7 @@ int WRAP(fstat)(int fd, struct stat_portable *s) int ret; if (invalid_pointer(s)) { - errno = EFAULT; + *REAL(__errno)() = EFAULT; return -1; } ret = REAL(fstat)(fd, &mips_stat); @@ -53,7 +54,7 @@ int WRAP(lstat)(const char *path, struct stat_portable *s) int ret; if (invalid_pointer(s)) { - errno = EFAULT; + *REAL(__errno)() = EFAULT; return -1; } ret = REAL(lstat)(path, &mips_stat); @@ -67,7 +68,7 @@ int WRAP(fstatat)(int dirfd, const char *path, struct stat_portable *s, int flag int ret; if (invalid_pointer(s)) { - errno = EFAULT; + *REAL(__errno)() = EFAULT; return -1; } ret = REAL(fstatat)(dirfd, path, &mips_stat, flags); diff --git a/ndk/sources/android/libportable/arch-mips/statfs.c b/ndk/sources/android/libportable/arch-mips/statfs.c index 6c0e079f3..45dfd093a 100644 --- a/ndk/sources/android/libportable/arch-mips/statfs.c +++ b/ndk/sources/android/libportable/arch-mips/statfs.c @@ -17,6 +17,7 @@ #include #include #include +#include #include static inline void statfs_ntop(struct statfs *n_statfs, struct statfs_portable *p_statfs) @@ -40,7 +41,7 @@ int WRAP(statfs)(const char* path, struct statfs_portable* stat) int ret; if (invalid_pointer(stat)) { - errno = EFAULT; + *REAL(__errno)() = EFAULT; return -1; } ret = REAL(statfs)(path, &mips_stat); @@ -54,7 +55,7 @@ int WRAP(fstatfs)(int fd, struct statfs_portable* stat) int ret; if (invalid_pointer(stat)) { - errno = EFAULT; + *REAL(__errno)() = EFAULT; return -1; } ret = REAL(fstatfs)(fd, &mips_stat); diff --git a/ndk/sources/android/libportable/arch-mips/syscall.c b/ndk/sources/android/libportable/arch-mips/syscall.c index 39d15d90f..5e31b80e1 100644 --- a/ndk/sources/android/libportable/arch-mips/syscall.c +++ b/ndk/sources/android/libportable/arch-mips/syscall.c @@ -597,7 +597,7 @@ int WRAP(syscall)(int portable_number, ...) ALOGV("%s: native_number:%d <= 0; ret = -1; [ERROR: FIX SYSTEM CALL]", __func__, native_number); - errno = ENOSYS; + *REAL(__errno)() = ENOSYS; ret = -1; goto done; } @@ -633,7 +633,7 @@ int WRAP(syscall)(int portable_number, ...) done: if (ret == -1) { - ALOGV("%s: ret == -1; errno:%d;", __func__, errno); + ALOGV("%s: ret == -1; errno:%d;", __func__, *REAL(__errno)()); } ALOGV("%s: return(ret:%d); }", __func__, ret); return ret; diff --git a/ndk/sources/android/libportable/common/include/errno_portable.h b/ndk/sources/android/libportable/common/include/errno_portable.h index 17f4d0a5d..61888c614 100644 --- a/ndk/sources/android/libportable/common/include/errno_portable.h +++ b/ndk/sources/android/libportable/common/include/errno_portable.h @@ -130,4 +130,6 @@ extern __hidden int errno_ntop(int native_errno); extern __hidden int errno_pton(int native_errno); +extern volatile int* REAL(__errno)(void); + #endif /* _ERRNO_PORTABLE_H */ diff --git a/ndk/sources/android/libportable/common/include/log_portable.h b/ndk/sources/android/libportable/common/include/log_portable.h index 79baa62d6..1a4fd435c 100644 --- a/ndk/sources/android/libportable/common/include/log_portable.h +++ b/ndk/sources/android/libportable/common/include/log_portable.h @@ -75,9 +75,9 @@ static inline char *portable_tag() { * to preserve the value of errno while logging. */ #define LOG_PRI(priority, tag, ...) ({ \ - int _errno = errno; \ + int _errno = *REAL(__errno)(); \ int _rv = android_printLog(priority, tag, __VA_ARGS__); \ - errno = _errno; \ + *REAL(__errno)() = _errno; \ _rv; /* Returned to caller */ \ }) @@ -85,14 +85,14 @@ static inline char *portable_tag() { #include # define PERROR(str) { \ - ALOGE("%s: PERROR('%s'): errno:%d:'%s'", __func__, str, errno, strerror(errno)); \ + ALOGE("%s: PERROR('%s'): errno:%d:'%s'", __func__, str, *REAL(__errno)(), strerror(errno)); \ } # define ASSERT(cond) ALOG_ASSERT(cond, "assertion failed:(%s), file: %s, line: %d:%s", \ #cond, __FILE__, __LINE__, __func__); #else #include -# define PERROR(str) fprintf(stderr, "%s: PERROR('%s'): errno:%d:'%s'", __func__, str, errno, strerror(errno)) +# define PERROR(str) fprintf(stderr, "%s: PERROR('%s'): errno:%d:'%s'", __func__, str, *REAL(__errno)(), strerror(*REAL(__errno)())) # define ASSERT(cond) assert(cond) # define ALOGV(a,...) # define ALOGW(a,...)