Index: native_client_sdk/src/libraries/nacl_io/kernel_wrap_bionic.cc |
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_wrap_glibc.cc b/native_client_sdk/src/libraries/nacl_io/kernel_wrap_bionic.cc |
similarity index 79% |
copy from native_client_sdk/src/libraries/nacl_io/kernel_wrap_glibc.cc |
copy to native_client_sdk/src/libraries/nacl_io/kernel_wrap_bionic.cc |
index f895ffb0fee46d76c87053a7fd1ce587a84e191f..a72deb5b43a088eb6c7972805f01db9b688b0505 100644 |
--- a/native_client_sdk/src/libraries/nacl_io/kernel_wrap_glibc.cc |
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_wrap_bionic.cc |
@@ -2,30 +2,26 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include <sys/types.h> // Include something that will define __GLIBC__. |
+#include <sys/types.h> // Include something that will define __BIONIC__. |
// The entire file is wrapped in this #if. We do this so this .cc file can be |
-// compiled, even on a non-glibc build. |
-#if defined(__native_client__) && defined(__GLIBC__) |
- |
-#include "nacl_io/kernel_wrap.h" |
+// compiled, even on a non-bionic build. |
+#if defined(__native_client__) && defined(__BIONIC__) |
#include <alloca.h> |
#include <assert.h> |
#include <dirent.h> |
#include <errno.h> |
-#include <irt.h> |
#include <irt_syscalls.h> |
-#include <nacl_stat.h> |
#include <string.h> |
#include <sys/stat.h> |
#include <sys/time.h> |
#include "nacl_io/kernel_intercept.h" |
+#include "nacl_io/kernel_wrap.h" |
#include "nacl_io/kernel_wrap_real.h" |
#include "nacl_io/osmman.h" |
- |
namespace { |
void stat_to_nacl_stat(const struct stat* buf, nacl_abi_stat* nacl_buf) { |
@@ -111,7 +107,6 @@ EXTERN_C_BEGIN |
// Assign the REAL function pointer. |
#define ASSIGN_REAL_PTR(name) \ |
- assert(__nacl_irt_##name != NULL); \ |
REAL(name) = __nacl_irt_##name; |
// Switch IRT's pointer to the REAL pointer |
@@ -127,23 +122,31 @@ EXTERN_C_BEGIN |
OP(chdir); \ |
OP(close); \ |
OP(dup); \ |
- OP(dup2); \ |
+ OP(dup2); \ |
OP(exit); \ |
+ OP(fchdir); \ |
+ OP(fchmod); \ |
+ OP(fdatasync); \ |
OP(fstat); \ |
+ OP(fsync); \ |
OP(getcwd); \ |
OP(getdents); \ |
+ OP(isatty); \ |
+ OP(lstat); \ |
OP(mkdir); \ |
+ OP(mmap); \ |
+ OP(munmap); \ |
OP(open); \ |
- OP(poll);\ |
+ OP(open_resource); \ |
+ OP(poll); \ |
OP(read); \ |
+ OP(readlink); \ |
OP(rmdir); \ |
OP(seek); \ |
OP(stat); \ |
- OP(select); \ |
+ OP(truncate); \ |
OP(write); \ |
- OP(mmap); \ |
- OP(munmap); \ |
- OP(open_resource); |
+ |
EXPAND_SYMBOL_LIST_OPERATION(DECLARE_REAL_PTR); |
@@ -168,6 +171,18 @@ void WRAP(exit)(int status) { |
ki_exit(status); |
} |
+int WRAP(fchdir)(int fd) NOTHROW { |
+ return (ki_fchdir(fd)) ? errno : 0; |
+} |
+ |
+int WRAP(fchmod)(int fd, mode_t mode) NOTHROW { |
+ return (ki_fchmod(fd, mode)) ? errno : 0; |
+} |
+ |
+int WRAP(fdatasync)(int fd) NOTHROW { |
+ return (ki_fdatasync(fd)) ? errno : 0; |
+} |
+ |
int WRAP(fstat)(int fd, struct nacl_abi_stat *nacl_buf) { |
struct stat buf; |
memset(&buf, 0, sizeof(struct stat)); |
@@ -178,7 +193,11 @@ int WRAP(fstat)(int fd, struct nacl_abi_stat *nacl_buf) { |
return 0; |
} |
-int WRAP(getcwd)(char* buf, size_t size) { |
+int WRAP(fsync)(int fd) NOTHROW { |
+ return (ki_fsync(fd)) ? errno : 0; |
+} |
+ |
+char* WRAP(getcwd)(char* buf, size_t size) { |
if (ki_getcwd(buf, size) == NULL) |
return errno; |
return 0; |
@@ -214,12 +233,29 @@ int WRAP(getdents)(int fd, dirent* nacl_buf, size_t nacl_count, size_t *nread) { |
return 0; |
} |
+int WRAP(isatty)(int fd, int* result) { |
+ *result = ki_isatty(fd); |
+ if (*result == 1) |
+ return errno; |
+ return 0; |
+} |
+ |
+int WRAP(lstat)(const char *path, struct nacl_abi_stat* nacl_buf) { |
+ struct stat buf; |
+ memset(&buf, 0, sizeof(struct stat)); |
+ int res = ki_lstat(path, &buf); |
+ if (res < 0) |
+ return errno; |
+ stat_to_nacl_stat(&buf, nacl_buf); |
+ return 0; |
+} |
+ |
int WRAP(mkdir)(const char* pathname, mode_t mode) { |
return (ki_mkdir(pathname, mode)) ? errno : 0; |
} |
int WRAP(mmap)(void** addr, size_t length, int prot, int flags, int fd, |
- off_t offset) { |
+ int64_t offset) { |
if (flags & MAP_ANONYMOUS) |
return REAL(mmap)(addr, length, prot, flags, fd, offset); |
@@ -256,11 +292,17 @@ int WRAP(read)(int fd, void *buf, size_t count, size_t *nread) { |
return (signed_nread < 0) ? errno : 0; |
} |
+int WRAP(readlink)(const char* path, char* buf, size_t count, size_t* nread) { |
+ ssize_t signed_nread = ki_readlink(path, buf, count); |
+ *nread = static_cast<size_t>(signed_nread); |
+ return (signed_nread < 0) ? errno : 0; |
+} |
+ |
int WRAP(rmdir)(const char* pathname) { |
return (ki_rmdir(pathname) < 0) ? errno : 0; |
} |
-int WRAP(seek)(int fd, off_t offset, int whence, off_t* new_offset) { |
+int WRAP(seek)(int fd, off64_t offset, int whence, int64_t* new_offset) { |
*new_offset = ki_lseek(fd, offset, whence); |
return (*new_offset < 0) ? errno : 0; |
} |
@@ -281,6 +323,10 @@ int WRAP(stat)(const char *pathname, struct nacl_abi_stat *nacl_buf) { |
return 0; |
} |
+int WRAP(truncate)(const char *name, int64_t len) { |
+ return (ki_truncate(name, len)) ? errno : 0; |
+} |
+ |
int WRAP(write)(int fd, const void* buf, size_t count, size_t* nwrote) { |
ssize_t signed_nwrote = ki_write(fd, buf, count); |
*nwrote = static_cast<size_t>(signed_nwrote); |
@@ -307,14 +353,29 @@ int _real_close(int fd) { |
} |
void _real_exit(int status) { |
- CHECK_REAL(exit); |
REAL(exit)(status); |
} |
+int _real_fchdir(int fd) { |
+ CHECK_REAL(fchdir); |
+ return REAL(fchdir)(fd); |
+} |
+ |
+int _real_fchmod(int fd, mode_t mode) { |
+ CHECK_REAL(fchmod); |
+ return REAL(fchmod)(fd, mode); |
+} |
+ |
+int _real_fdatasync(int fd) { |
+ CHECK_REAL(fdatasync); |
+ return REAL(fdatasync)(fd); |
+} |
+ |
int _real_fstat(int fd, struct stat* buf) { |
struct nacl_abi_stat st; |
CHECK_REAL(fstat); |
- int err = REAL(fstat)(fd, &st); |
+ |
+ int err = REAL(fstat)(fd, (struct stat*) &st); |
if (err) { |
errno = err; |
return -1; |
@@ -324,6 +385,11 @@ int _real_fstat(int fd, struct stat* buf) { |
return 0; |
} |
+int _real_fsync(int fd) { |
+ CHECK_REAL(fsync); |
+ return REAL(fsync)(fd); |
+} |
+ |
int _real_getdents(int fd, void* buf, size_t count, size_t* nread) { |
// "buf" contains dirent(s); "nacl_buf" contains nacl_abi_dirent(s). |
// See WRAP(getdents) above. |
@@ -354,18 +420,41 @@ int _real_getdents(int fd, void* buf, size_t count, size_t* nread) { |
return 0; |
} |
-int _real_lseek(int fd, off_t offset, int whence, off_t* new_offset) { |
+int _real_isatty(int fd, int* result) { |
+ *result = isatty(fd); |
+ return *result ? 0 : -1; |
+} |
+ |
+int _real_lseek(int fd, int64_t offset, int whence, int64_t* new_offset) { |
CHECK_REAL(seek); |
- return REAL(seek)(fd, offset, whence, new_offset); |
+ nacl_abi_off_t nacl_new_offs; |
+ int ret = REAL(seek)(fd, offset, whence, &nacl_new_offs); |
+ *new_offset = static_cast<off_t>(nacl_new_offs); |
+ return ret; |
} |
+int _real_lstat(const char* path, struct stat* buf) { |
+ struct nacl_abi_stat st; |
+ CHECK_REAL(fstat); |
+ |
+ int err = REAL(lstat)(path, (struct stat*) &st); |
+ if (err) { |
+ errno = err; |
+ return -1; |
+ } |
+ |
+ nacl_stat_to_stat(&st, buf); |
+ return 0; |
+} |
+ |
+ |
int _real_mkdir(const char* pathname, mode_t mode) { |
CHECK_REAL(mkdir); |
return REAL(mkdir)(pathname, mode); |
} |
int _real_mmap(void** addr, size_t length, int prot, int flags, int fd, |
- off_t offset) { |
+ int64_t offset) { |
CHECK_REAL(mmap); |
return REAL(mmap)(addr, length, prot, flags, fd, offset); |
} |
@@ -390,11 +479,21 @@ int _real_read(int fd, void *buf, size_t count, size_t *nread) { |
return REAL(read)(fd, buf, count, nread); |
} |
+int _real_readlink(const char *path, char* buf, size_t count, size_t* nread) { |
+ CHECK_REAL(readlink); |
+ return REAL(readlink)(path, buf, count, nread); |
+} |
+ |
int _real_rmdir(const char* pathname) { |
CHECK_REAL(rmdir); |
return REAL(rmdir)(pathname); |
} |
+int _real_truncate(const char* pathname, int64_t len) { |
+ CHECK_REAL(truncate); |
+ return REAL(truncate)(pathname, len); |
+} |
+ |
int _real_write(int fd, const void *buf, size_t count, size_t *nwrote) { |
CHECK_REAL(write); |
return REAL(write)(fd, buf, count, nwrote); |