summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornoelallen@chromium.org <noelallen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-25 16:45:44 +0000
committernoelallen@chromium.org <noelallen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-25 16:45:44 +0000
commitb60769db8ed3169b3759f1224c1e341a88cac064 (patch)
tree86547565fe21e1735b00ae73a8d02bcc27dd2b42
parent50d484d4eff306b0524742037b234a605c598cf3 (diff)
downloadchromium_src-b60769db8ed3169b3759f1224c1e341a88cac064.zip
chromium_src-b60769db8ed3169b3759f1224c1e341a88cac064.tar.gz
chromium_src-b60769db8ed3169b3759f1224c1e341a88cac064.tar.bz2
[NaCl SDK] Add kernel_wrap_uninit
Used to help cleanup on testing, not expected to really be used by the developer. NOTRY=true R=binji@chromium.org Review URL: https://codereview.chromium.org/19466003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@213646 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--native_client_sdk/src/libraries/nacl_io/kernel_intercept.cc48
-rw-r--r--native_client_sdk/src/libraries/nacl_io/kernel_wrap.h1
-rw-r--r--native_client_sdk/src/libraries/nacl_io/kernel_wrap_glibc.cc97
-rw-r--r--native_client_sdk/src/libraries/nacl_io/kernel_wrap_newlib.cc92
-rw-r--r--native_client_sdk/src/libraries/nacl_io/kernel_wrap_win.cc4
5 files changed, 147 insertions, 95 deletions
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_intercept.cc b/native_client_sdk/src/libraries/nacl_io/kernel_intercept.cc
index c326e1d..9cad2c1 100644
--- a/native_client_sdk/src/libraries/nacl_io/kernel_intercept.cc
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_intercept.cc
@@ -3,15 +3,23 @@
// found in the LICENSE file.
#include <errno.h>
+
#include "nacl_io/kernel_intercept.h"
#include "nacl_io/kernel_proxy.h"
#include "nacl_io/kernel_wrap.h"
+#include "nacl_io/osmman.h"
#include "nacl_io/pepper_interface.h"
#include "nacl_io/pepper_interface.h"
#include "nacl_io/real_pepper_interface.h"
using namespace nacl_io;
+#define ON_NOSYS_RETURN(x) \
+ if (!ki_is_initialized()) { \
+ errno = ENOSYS; \
+ return x; \
+ }
+
static KernelProxy* s_kp;
void ki_init(void* kp) {
@@ -38,10 +46,13 @@ int ki_is_initialized() {
}
void ki_uninit() {
+ kernel_wrap_uninit();
s_kp = NULL;
}
+
int ki_chdir(const char* path) {
+ ON_NOSYS_RETURN(-1);
return s_kp->chdir(path);
}
@@ -61,135 +72,162 @@ char* ki_getcwd(char* buf, size_t size) {
}
char* ki_getwd(char* buf) {
+ ON_NOSYS_RETURN(NULL);
return s_kp->getwd(buf);
}
int ki_dup(int oldfd) {
+ ON_NOSYS_RETURN(-1);
return s_kp->dup(oldfd);
}
int ki_dup2(int oldfd, int newfd) {
+ ON_NOSYS_RETURN(-1);
return s_kp->dup2(oldfd, newfd);
}
int ki_chmod(const char *path, mode_t mode) {
+ ON_NOSYS_RETURN(-1);
return s_kp->chmod(path, mode);
}
int ki_stat(const char *path, struct stat *buf) {
+ ON_NOSYS_RETURN(-1);
return s_kp->stat(path, buf);
}
int ki_mkdir(const char *path, mode_t mode) {
+ ON_NOSYS_RETURN(-1);
return s_kp->mkdir(path, mode);
}
int ki_rmdir(const char *path) {
+ ON_NOSYS_RETURN(-1);
return s_kp->rmdir(path);
}
int ki_mount(const char *source, const char *target, const char *filesystemtype,
unsigned long mountflags, const void *data) {
+ ON_NOSYS_RETURN(-1);
return s_kp->mount(source, target, filesystemtype, mountflags, data);
}
int ki_umount(const char *path) {
+ ON_NOSYS_RETURN(-1);
return s_kp->umount(path);
}
int ki_open(const char *path, int oflag) {
+ ON_NOSYS_RETURN(-1);
return s_kp->open(path, oflag);
}
ssize_t ki_read(int fd, void *buf, size_t nbyte) {
+ ON_NOSYS_RETURN(-1);
return s_kp->read(fd, buf, nbyte);
}
ssize_t ki_write(int fd, const void *buf, size_t nbyte) {
+ ON_NOSYS_RETURN(-1);
return s_kp->write(fd, buf, nbyte);
}
int ki_fstat(int fd, struct stat *buf){
+ ON_NOSYS_RETURN(-1);
return s_kp->fstat(fd, buf);
}
int ki_getdents(int fd, void *buf, unsigned int count) {
+ ON_NOSYS_RETURN(-1);
return s_kp->getdents(fd, buf, count);
}
int ki_ftruncate(int fd, off_t length) {
+ ON_NOSYS_RETURN(-1);
return s_kp->ftruncate(fd, length);
}
int ki_fsync(int fd) {
+ ON_NOSYS_RETURN(-1);
return s_kp->fsync(fd);
}
int ki_isatty(int fd) {
- if (!ki_is_initialized())
- return 0;
+ ON_NOSYS_RETURN(0);
return s_kp->isatty(fd);
}
int ki_close(int fd) {
- if (!ki_is_initialized())
- return 0;
+ ON_NOSYS_RETURN(-1);
return s_kp->close(fd);
}
off_t ki_lseek(int fd, off_t offset, int whence) {
+ ON_NOSYS_RETURN(-1);
return s_kp->lseek(fd, offset, whence);
}
int ki_remove(const char* path) {
+ ON_NOSYS_RETURN(-1);
return s_kp->remove(path);
}
int ki_unlink(const char* path) {
+ ON_NOSYS_RETURN(-1);
return s_kp->unlink(path);
}
int ki_access(const char* path, int amode) {
+ ON_NOSYS_RETURN(-1);
return s_kp->access(path, amode);
}
int ki_link(const char* oldpath, const char* newpath) {
+ ON_NOSYS_RETURN(-1);
return s_kp->link(oldpath, newpath);
}
int ki_symlink(const char* oldpath, const char* newpath) {
+ ON_NOSYS_RETURN(-1);
return s_kp->symlink(oldpath, newpath);
}
void* ki_mmap(void* addr, size_t length, int prot, int flags, int fd,
off_t offset) {
+ ON_NOSYS_RETURN(MAP_FAILED);
return s_kp->mmap(addr, length, prot, flags, fd, offset);
}
int ki_munmap(void* addr, size_t length) {
+ ON_NOSYS_RETURN(-1);
return s_kp->munmap(addr, length);
}
int ki_open_resource(const char* file) {
- return s_kp->open_resource(file);
+ ON_NOSYS_RETURN(-1); return s_kp->open_resource(file);
}
int ki_ioctl(int d, int request, char* argp) {
+ ON_NOSYS_RETURN(-1);
return s_kp->ioctl(d, request, argp);
}
int ki_chown(const char* path, uid_t owner, gid_t group) {
+ ON_NOSYS_RETURN(-1);
return s_kp->chown(path, owner, group);
}
int ki_fchown(int fd, uid_t owner, gid_t group) {
+ ON_NOSYS_RETURN(-1);
return s_kp->fchown(fd, owner, group);
}
int ki_lchown(const char* path, uid_t owner, gid_t group) {
+ ON_NOSYS_RETURN(-1);
return s_kp->lchown(path, owner, group);
}
int ki_utime(const char* filename, const struct utimbuf* times) {
+ ON_NOSYS_RETURN(-1);
return s_kp->utime(filename, times);
}
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_wrap.h b/native_client_sdk/src/libraries/nacl_io/kernel_wrap.h
index 105c107..3f62698 100644
--- a/native_client_sdk/src/libraries/nacl_io/kernel_wrap.h
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_wrap.h
@@ -37,6 +37,7 @@ typedef ssize_t write_ssize_t;
EXTERN_C_BEGIN
void kernel_wrap_init();
+void kernel_wrap_uninit();
int NAME(access)(const char* path, int amode) NOTHROW;
int NAME(chdir)(const char* path) NOTHROW;
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_wrap_glibc.cc b/native_client_sdk/src/libraries/nacl_io/kernel_wrap_glibc.cc
index c32c4b5..85d26ba 100644
--- a/native_client_sdk/src/libraries/nacl_io/kernel_wrap_glibc.cc
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_wrap_glibc.cc
@@ -9,6 +9,7 @@
#if defined(__native_client__) && defined(__GLIBC__)
#include "nacl_io/kernel_wrap.h"
+
#include <alloca.h>
#include <dirent.h>
#include <errno.h>
@@ -16,10 +17,11 @@
#include <irt_syscalls.h>
#include <nacl_stat.h>
#include <string.h>
-#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/time.h>
+
#include "nacl_io/kernel_intercept.h"
+#include "nacl_io/osmman.h"
namespace {
@@ -95,32 +97,45 @@ static const int d_name_shift = offsetof (dirent, d_name) -
EXTERN_C_BEGIN
+// Macro to get the REAL function pointer
#define REAL(name) __nacl_irt_##name##_real
+
+// Macro to get the WRAP function
#define WRAP(name) __nacl_irt_##name##_wrap
-#define MUX(name) __nacl_irt_##name
-#define DECLARE(name) typeof(MUX(name)) REAL(name);
-#define DO_WRAP(name) do { \
- REAL(name) = MUX(name); \
- MUX(name) = (typeof(REAL(name))) WRAP(name); \
- } while (0)
-
-DECLARE(chdir)
-DECLARE(close)
-DECLARE(dup)
-DECLARE(dup2)
-DECLARE(fstat)
-DECLARE(getcwd)
-DECLARE(getdents)
-DECLARE(mkdir)
-DECLARE(open)
-DECLARE(read)
-DECLARE(rmdir)
-DECLARE(seek)
-DECLARE(stat)
-DECLARE(write)
-DECLARE(mmap)
-DECLARE(munmap)
-DECLARE(open_resource)
+
+// Declare REAL function pointer and assign it the REAL function.
+#define DECLARE_REAL_PTR(name) \
+ typeof(__nacl_irt_##name) REAL(name) = __nacl_irt_##name;
+
+// Switch IRT's pointer to the REAL pointer
+#define USE_REAL(name) \
+ __nacl_irt_##name = (typeof(__nacl_irt_##name)) REAL(name)
+
+// Switch IRT's pointer to the WRAP function
+#define USE_WRAP(name) \
+ __nacl_irt_##name = (typeof(__nacl_irt_##name)) WRAP(name)
+
+
+#define EXPAND_SYMBOL_LIST_OPERATION(OP) \
+ OP(chdir); \
+ OP(close); \
+ OP(dup); \
+ OP(dup2); \
+ OP(fstat); \
+ OP(getcwd); \
+ OP(getdents); \
+ OP(mkdir); \
+ OP(open); \
+ OP(read); \
+ OP(rmdir); \
+ OP(seek); \
+ OP(stat); \
+ OP(write); \
+ OP(mmap); \
+ OP(munmap); \
+ OP(open_resource);
+
+EXPAND_SYMBOL_LIST_OPERATION(DECLARE_REAL_PTR);
int access(const char* path, int amode) NOTHROW {
return ki_access(path, amode);
@@ -430,28 +445,18 @@ uint64_t usec_since_epoch() {
return tv.tv_usec + (tv.tv_sec * 1000000);
}
+static bool s_wrapped = false;
void kernel_wrap_init() {
- static bool wrapped = false;
-
- if (!wrapped) {
- wrapped = true;
- DO_WRAP(chdir);
- DO_WRAP(close);
- DO_WRAP(dup);
- DO_WRAP(dup2);
- DO_WRAP(fstat);
- DO_WRAP(getcwd);
- DO_WRAP(getdents);
- DO_WRAP(mkdir);
- DO_WRAP(open);
- DO_WRAP(read);
- DO_WRAP(rmdir);
- DO_WRAP(seek);
- DO_WRAP(stat);
- DO_WRAP(write);
- DO_WRAP(mmap);
- DO_WRAP(munmap);
- DO_WRAP(open_resource);
+ if (!s_wrapped) {
+ EXPAND_SYMBOL_LIST_OPERATION(USE_WRAP)
+ s_wrapped = true;
+ }
+}
+
+void kernel_wrap_uninit() {
+ if (s_wrapped) {
+ EXPAND_SYMBOL_LIST_OPERATION(USE_REAL)
+ s_wrapped = false;
}
}
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 ff5896f..26a85e3 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
@@ -19,37 +19,47 @@
EXTERN_C_BEGIN
+// Macro to get the REAL function pointer
#define REAL(name) __nacl_irt_##name##_real
+
+// Macro to get the WRAP function
#define WRAP(name) __nacl_irt_##name##_wrap
-#define STRUCT_NAME(group) __libnacl_irt_##group
-#define DECLARE_STRUCT(group) \
- extern struct nacl_irt_##group STRUCT_NAME(group);
-#define DECLARE_STRUCT_VERSION(group, version) \
- extern struct nacl_irt_##group##_##version STRUCT_NAME(group);
-#define MUX(group, name) STRUCT_NAME(group).name
-#define DECLARE(group, name) typeof(MUX(group, name)) REAL(name);
-#define DO_WRAP(group, name) do { \
- REAL(name) = MUX(group, name); \
- MUX(group, name) = (typeof(REAL(name))) WRAP(name); \
- } while (0)
-
-DECLARE_STRUCT(fdio)
-DECLARE_STRUCT(filename)
-DECLARE_STRUCT(memory)
-
-DECLARE(fdio, close)
-DECLARE(fdio, dup)
-DECLARE(fdio, dup2)
-DECLARE(fdio, fstat)
-DECLARE(fdio, getdents)
-DECLARE(fdio, read)
-DECLARE(fdio, seek)
-DECLARE(fdio, write)
-DECLARE(filename, open)
-DECLARE(filename, stat)
-DECLARE(memory, mmap)
-DECLARE(memory, munmap)
+// Declare REAL function pointer and assign it the REAL function.
+#define DECLARE_REAL_PTR(group, name) \
+ typeof(__libnacl_irt_##group.name) REAL(name) = __libnacl_irt_##group.name;
+
+// Switch IRT's pointer to the REAL pointer
+#define USE_REAL(group, name) \
+ __libnacl_irt_##group.name = (typeof(REAL(name))) REAL(name); \
+
+// Switch the IRT's pointer to the WRAP function
+#define USE_WRAP(group, name) \
+ __libnacl_irt_##group.name = (typeof(REAL(name))) WRAP(name); \
+
+
+
+extern struct nacl_irt_fdio __libnacl_irt_fdio;
+extern struct nacl_irt_filename __libnacl_irt_filename;
+extern struct nacl_irt_memory __libnacl_irt_memory;
+
+// Create function pointers to the REAL implementation
+#define EXPAND_SYMBOL_LIST_OPERATION(OP) \
+ OP(fdio, close); \
+ OP(fdio, dup); \
+ OP(fdio, dup2); \
+ OP(fdio, fstat); \
+ OP(fdio, getdents); \
+ OP(fdio, read); \
+ OP(fdio, seek); \
+ OP(fdio, write); \
+ OP(filename, open); \
+ OP(filename, stat); \
+ OP(memory, mmap); \
+ OP(memory, munmap);
+
+
+EXPAND_SYMBOL_LIST_OPERATION(DECLARE_REAL_PTR);
int access(const char* path, int amode) {
return ki_access(path, amode);
@@ -268,26 +278,20 @@ uint64_t usec_since_epoch() {
return tv.tv_usec + (tv.tv_sec * 1000000);
}
+static bool s_wrapped = false;
void kernel_wrap_init() {
- static bool wrapped = false;
-
- if (!wrapped) {
- wrapped = true;
- DO_WRAP(fdio, close);
- DO_WRAP(fdio, dup);
- DO_WRAP(fdio, dup2);
- DO_WRAP(fdio, fstat);
- DO_WRAP(fdio, getdents);
- DO_WRAP(fdio, read);
- DO_WRAP(fdio, seek);
- DO_WRAP(fdio, write);
- DO_WRAP(filename, open);
- DO_WRAP(filename, stat);
- DO_WRAP(memory, mmap);
- DO_WRAP(memory, munmap);
+ if (!s_wrapped) {
+ EXPAND_SYMBOL_LIST_OPERATION(USE_WRAP);
+ s_wrapped = true;
}
}
+void kernel_wrap_uninit() {
+ if (s_wrapped) {
+ EXPAND_SYMBOL_LIST_OPERATION(USE_REAL);
+ s_wrapped = false;
+ }
+}
EXTERN_C_END
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_wrap_win.cc b/native_client_sdk/src/libraries/nacl_io/kernel_wrap_win.cc
index 77b8b60..89db245 100644
--- a/native_client_sdk/src/libraries/nacl_io/kernel_wrap_win.cc
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_wrap_win.cc
@@ -325,6 +325,10 @@ uint64_t usec_since_epoch() {
// Do nothing for Windows, we replace the library at link time.
void kernel_wrap_init() {
}
+
+void kernel_wrap_uninit() {
+}
+
EXTERN_C_END
#endif // defined(WIN32)