Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Unified Diff: native_client_sdk/src/libraries/nacl_io/kernel_wrap_newlib.cc

Issue 271513002: [NaCl SDK] nacl_io: Make IRT intercepts (and their test code) more robust. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: native_client_sdk/src/libraries/nacl_io/kernel_wrap_newlib.cc
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_wrap_newlib.cc b/native_client_sdk/src/libraries/nacl_io/kernel_wrap_newlib.cc
index 049e53b4925afb050d387966848bd7260ad6804a..8f6bd2a7126314feb7e3a41a7ceb618ddc523a69 100644
--- a/native_client_sdk/src/libraries/nacl_io/kernel_wrap_newlib.cc
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_wrap_newlib.cc
@@ -20,6 +20,7 @@
#include "nacl_io/kernel_intercept.h"
#include "nacl_io/kernel_wrap_real.h"
+#include "nacl_io/log.h"
EXTERN_C_BEGIN
@@ -89,21 +90,37 @@ extern struct nacl_irt_memory __libnacl_irt_memory;
OP(memory, mmap); \
OP(memory, munmap);
+// Most kernal intercept functions (ki_*) return -1 and set errno accordingly.
+// However the IRT wrappers are expected to return errno on failure. Here we
+// check that the ki_ function actually set errno and fall back to EIO if it
+// didn't.
+#define RTN_ERRNO_IF(cond) \
+ if (cond) { \
+ int rtn = errno; \
+ if (rtn == 0) rtn = EIO; \
+ return rtn; \
+ }
+
+#define ERRNO_RTN(function_call) \
binji 2014/05/06 23:25:54 make this consistent with the other kernel_wrap_*
Sam Clegg 2014/05/07 00:29:03 Done.
+ RTN_ERRNO_IF(function_call < 0); \
+ return 0;
EXPAND_SYMBOL_LIST_OPERATION(DECLARE_REAL_PTR);
int WRAP(close)(int fd) {
- return (ki_close(fd) < 0) ? errno : 0;
+ ERRNO_RTN(ki_close(fd));
binji 2014/05/06 23:25:54 do this stuff for kernel_wrap_bionic too
Sam Clegg 2014/05/07 00:29:03 Done.
}
int WRAP(dup)(int fd, int* newfd) {
*newfd = ki_dup(fd);
- return (*newfd < 0) ? errno : 0;
+ RTN_ERRNO_IF(*newfd < 0);
binji 2014/05/06 23:29:52 ERRNO_RTN
Sam Clegg 2014/05/07 00:29:03 Done.
+ return 0;
}
int WRAP(dup2)(int fd, int newfd) {
newfd = ki_dup2(fd, newfd);
- return (newfd < 0) ? errno : 0;
+ RTN_ERRNO_IF(newfd < 0);
binji 2014/05/06 23:29:52 ERRNO_RTN
Sam Clegg 2014/05/07 00:29:03 Done.
+ return 0;
}
void WRAP(exit)(int status) {
@@ -128,7 +145,7 @@ int WRAP(seek)(int fd, off_t offset, int whence, off_t* new_offset) {
}
int WRAP(fstat)(int fd, struct stat* buf) {
- return (ki_fstat(fd, buf) < 0) ? errno : 0;
+ ERRNO_RTN(ki_fstat(fd, buf));
}
int WRAP(getdents)(int fd, dirent* buf, size_t count, size_t* nread) {
@@ -140,23 +157,23 @@ int WRAP(getdents)(int fd, dirent* buf, size_t count, size_t* nread) {
}
int WRAP(fchdir)(int fd) {
- return (ki_fchdir(fd) < 0) ? errno : 0;
+ ERRNO_RTN(ki_fchdir(fd));
}
int WRAP(fchmod)(int fd, mode_t mode) {
- return (ki_fchmod(fd, mode) < 0) ? errno : 0;
+ ERRNO_RTN(ki_fchmod(fd, mode));
}
int WRAP(fsync)(int fd) {
- return (ki_fsync(fd) < 0) ? errno : 0;
+ ERRNO_RTN(ki_fsync(fd));
}
int WRAP(fdatasync)(int fd) {
- return (ki_fdatasync(fd) < 0) ? errno : 0;
+ ERRNO_RTN(ki_fdatasync(fd));
}
int WRAP(ftruncate)(int fd, off_t length) {
- return (ki_ftruncate(fd, length) < 0) ? errno : 0;
+ ERRNO_RTN(ki_ftruncate(fd, length));
}
int WRAP(isatty)(int fd, int* result) {
@@ -188,19 +205,19 @@ int WRAP(open)(const char* pathname, int oflag, mode_t cmode, int* newfd) {
}
int WRAP(stat)(const char* pathname, struct stat* buf) {
- return (ki_stat(pathname, buf) < 0) ? errno : 0;
+ ERRNO_RTN(ki_stat(pathname, buf));
}
int WRAP(mkdir)(const char* pathname, mode_t mode) {
- return (ki_mkdir(pathname, mode) < 0) ? errno : 0;
+ ERRNO_RTN(ki_mkdir(pathname, mode));
}
int WRAP(rmdir)(const char* pathname) {
- return (ki_rmdir(pathname) < 0) ? errno : 0;
+ ERRNO_RTN(ki_rmdir(pathname));
}
int WRAP(chdir)(const char* pathname) {
- return (ki_chdir(pathname) < 0) ? errno : 0;
+ ERRNO_RTN(ki_chdir(pathname));
}
int WRAP(getcwd)(char* pathname, size_t len) {
@@ -211,48 +228,47 @@ int WRAP(getcwd)(char* pathname, size_t len) {
}
int WRAP(unlink)(const char* pathname) {
- return (ki_unlink(pathname) < 0) ? errno : 0;
+ ERRNO_RTN(ki_unlink(pathname));
}
int WRAP(truncate)(const char* pathname, off_t length) {
- return (ki_truncate(pathname, length) < 0) ? errno : 0;
+ ERRNO_RTN(ki_truncate(pathname, length));
}
int WRAP(lstat)(const char* pathname, struct stat* buf) {
- return (ki_lstat(pathname, buf) < 0) ? errno : 0;
+ ERRNO_RTN(ki_lstat(pathname, buf));
}
int WRAP(link)(const char* pathname, const char* newpath) {
- return (ki_link(pathname, newpath) < 0) ? errno : 0;
+ ERRNO_RTN(ki_link(pathname, newpath));
}
int WRAP(rename)(const char* pathname, const char* newpath) {
- return (ki_rename(pathname, newpath) < 0) ? errno : 0;
+ ERRNO_RTN(ki_rename(pathname, newpath));
}
int WRAP(symlink)(const char* pathname, const char* newpath) {
- return (ki_symlink(pathname, newpath) < 0) ? errno : 0;
+ ERRNO_RTN(ki_symlink(pathname, newpath));
}
int WRAP(chmod)(const char* pathname, mode_t mode) {
- return (ki_chmod(pathname, mode) < 0) ? errno : 0;
+ ERRNO_RTN(ki_chmod(pathname, mode));
}
int WRAP(access)(const char* pathname, int amode) {
- return (ki_access(pathname, amode) < 0) ? errno : 0;
+ ERRNO_RTN(ki_access(pathname, amode));
}
int WRAP(readlink)(const char* pathname, char *buf,
size_t count, size_t *nread) {
int rtn = ki_readlink(pathname, buf, count);
- if (rtn < 0)
- return errno;
+ RTN_ERRNO_IF(rtn < 0);
*nread = rtn;
return 0;
}
int WRAP(utimes)(const char* pathname, const struct timeval times[2]) {
- return (ki_utimes(pathname, times) < 0) ? errno : 0;
+ ERRNO_RTN(ki_utimes(pathname, times));
}
static void assign_real_pointers() {
@@ -342,6 +358,7 @@ static bool s_wrapped = false;
void kernel_wrap_init() {
if (!s_wrapped) {
+ LOG_TRACE("kernel_wrap_init");
assign_real_pointers();
EXPAND_SYMBOL_LIST_OPERATION(USE_WRAP)
s_wrapped = true;
@@ -350,6 +367,7 @@ void kernel_wrap_init() {
void kernel_wrap_uninit() {
if (s_wrapped) {
+ LOG_TRACE("kernel_wrap_uninit");
EXPAND_SYMBOL_LIST_OPERATION(USE_REAL)
s_wrapped = false;
}

Powered by Google App Engine
This is Rietveld 408576698