| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <sys/types.h> // Include something that will define __BIONIC__. | 5 #include <sys/types.h> // Include something that will define __BIONIC__. |
| 6 | 6 |
| 7 // The entire file is wrapped in this #if. We do this so this .cc file can be | 7 // The entire file is wrapped in this #if. We do this so this .cc file can be |
| 8 // compiled, even on a non-bionic build. | 8 // compiled, even on a non-bionic build. |
| 9 | 9 |
| 10 #if defined(__native_client__) && defined(__BIONIC__) | 10 #if defined(__native_client__) && defined(__BIONIC__) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 void nacl_stat_to_stat(const nacl_abi_stat* nacl_buf, struct stat* buf) { | 44 void nacl_stat_to_stat(const nacl_abi_stat* nacl_buf, struct stat* buf) { |
| 45 memset(buf, 0, sizeof(struct stat)); | 45 memset(buf, 0, sizeof(struct stat)); |
| 46 buf->st_dev = nacl_buf->nacl_abi_st_dev; | 46 buf->st_dev = nacl_buf->nacl_abi_st_dev; |
| 47 buf->st_ino = nacl_buf->nacl_abi_st_ino; | 47 buf->st_ino = nacl_buf->nacl_abi_st_ino; |
| 48 buf->st_mode = nacl_buf->nacl_abi_st_mode; | 48 buf->st_mode = nacl_buf->nacl_abi_st_mode; |
| 49 buf->st_nlink = nacl_buf->nacl_abi_st_nlink; | 49 buf->st_nlink = nacl_buf->nacl_abi_st_nlink; |
| 50 buf->st_uid = nacl_buf->nacl_abi_st_uid; | 50 buf->st_uid = nacl_buf->nacl_abi_st_uid; |
| 51 buf->st_gid = nacl_buf->nacl_abi_st_gid; | 51 buf->st_gid = nacl_buf->nacl_abi_st_gid; |
| 52 buf->st_rdev = nacl_buf->nacl_abi_st_rdev; | 52 buf->st_rdev = nacl_buf->nacl_abi_st_rdev; |
| 53 buf->st_size = nacl_buf->nacl_abi_st_size ; | 53 buf->st_size = nacl_buf->nacl_abi_st_size; |
| 54 buf->st_blksize = nacl_buf->nacl_abi_st_blksize; | 54 buf->st_blksize = nacl_buf->nacl_abi_st_blksize; |
| 55 buf->st_blocks = nacl_buf->nacl_abi_st_blocks; | 55 buf->st_blocks = nacl_buf->nacl_abi_st_blocks; |
| 56 buf->st_atime = nacl_buf->nacl_abi_st_atime; | 56 buf->st_atime = nacl_buf->nacl_abi_st_atime; |
| 57 buf->st_mtime = nacl_buf->nacl_abi_st_mtime; | 57 buf->st_mtime = nacl_buf->nacl_abi_st_mtime; |
| 58 buf->st_ctime = nacl_buf->nacl_abi_st_ctime; | 58 buf->st_ctime = nacl_buf->nacl_abi_st_ctime; |
| 59 } | 59 } |
| 60 | 60 |
| 61 } // namespace | 61 } // namespace |
| 62 | 62 |
| 63 // From native_client/src/trusted/service_runtime/include/sys/dirent.h | 63 // From native_client/src/trusted/service_runtime/include/sys/dirent.h |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 95 |
| 96 EXTERN_C_BEGIN | 96 EXTERN_C_BEGIN |
| 97 | 97 |
| 98 // Macro to get the REAL function pointer | 98 // Macro to get the REAL function pointer |
| 99 #define REAL(name) __nacl_irt_##name##_real | 99 #define REAL(name) __nacl_irt_##name##_real |
| 100 | 100 |
| 101 // Macro to get the WRAP function | 101 // Macro to get the WRAP function |
| 102 #define WRAP(name) __nacl_irt_##name##_wrap | 102 #define WRAP(name) __nacl_irt_##name##_wrap |
| 103 | 103 |
| 104 // Declare REAL function pointer. | 104 // Declare REAL function pointer. |
| 105 #define DECLARE_REAL_PTR(name) \ | 105 #define DECLARE_REAL_PTR(name) typeof(__nacl_irt_##name) REAL(name); |
| 106 typeof(__nacl_irt_##name) REAL(name); | |
| 107 | 106 |
| 108 // Assign the REAL function pointer. | 107 // Assign the REAL function pointer. |
| 109 #define ASSIGN_REAL_PTR(name) \ | 108 #define ASSIGN_REAL_PTR(name) REAL(name) = __nacl_irt_##name; |
| 110 REAL(name) = __nacl_irt_##name; | |
| 111 | 109 |
| 112 // Switch IRT's pointer to the REAL pointer | 110 // Switch IRT's pointer to the REAL pointer |
| 113 #define USE_REAL(name) \ | 111 #define USE_REAL(name) __nacl_irt_##name = (typeof(__nacl_irt_##name))REAL(name) |
| 114 __nacl_irt_##name = (typeof(__nacl_irt_##name)) REAL(name) | |
| 115 | 112 |
| 116 // Switch IRT's pointer to the WRAP function | 113 // Switch IRT's pointer to the WRAP function |
| 117 #define USE_WRAP(name) \ | 114 #define USE_WRAP(name) __nacl_irt_##name = (typeof(__nacl_irt_##name))WRAP(name) |
| 118 __nacl_irt_##name = (typeof(__nacl_irt_##name)) WRAP(name) | |
| 119 | 115 |
| 120 #define EXPAND_SYMBOL_LIST_OPERATION(OP) \ | 116 #define EXPAND_SYMBOL_LIST_OPERATION(OP) \ |
| 121 OP(chdir); \ | 117 OP(chdir); \ |
| 122 OP(close); \ | 118 OP(close); \ |
| 123 OP(dup); \ | 119 OP(dup); \ |
| 124 OP(dup2); \ | 120 OP(dup2); \ |
| 125 OP(exit); \ | 121 OP(exit); \ |
| 126 OP(fchdir); \ | 122 OP(fchdir); \ |
| 127 OP(fchmod); \ | 123 OP(fchmod); \ |
| 128 OP(fdatasync); \ | 124 OP(fdatasync); \ |
| 129 OP(fstat); \ | 125 OP(fstat); \ |
| 130 OP(fsync); \ | 126 OP(fsync); \ |
| 131 OP(getcwd); \ | 127 OP(getcwd); \ |
| 132 OP(getdents); \ | 128 OP(getdents); \ |
| 133 OP(isatty); \ | 129 OP(isatty); \ |
| 134 OP(lstat); \ | 130 OP(lstat); \ |
| 135 OP(mkdir); \ | 131 OP(mkdir); \ |
| 136 OP(mmap); \ | 132 OP(mmap); \ |
| 137 OP(munmap); \ | 133 OP(munmap); \ |
| 138 OP(open); \ | 134 OP(open); \ |
| 139 OP(open_resource); \ | 135 OP(open_resource); \ |
| 140 OP(poll); \ | 136 OP(poll); \ |
| 141 OP(read); \ | 137 OP(read); \ |
| 142 OP(readlink); \ | 138 OP(readlink); \ |
| 143 OP(rmdir); \ | 139 OP(rmdir); \ |
| 144 OP(seek); \ | 140 OP(seek); \ |
| 145 OP(stat); \ | 141 OP(stat); \ |
| 146 OP(truncate); \ | 142 OP(truncate); \ |
| 147 OP(write); \ | 143 OP(write); |
| 148 | 144 |
| 149 EXPAND_SYMBOL_LIST_OPERATION(DECLARE_REAL_PTR); | 145 EXPAND_SYMBOL_LIST_OPERATION(DECLARE_REAL_PTR); |
| 150 | 146 |
| 151 int WRAP(chdir)(const char* pathname) { | 147 int WRAP(chdir)(const char* pathname) { |
| 152 ERRNO_RTN(ki_chdir(pathname)); | 148 ERRNO_RTN(ki_chdir(pathname)); |
| 153 } | 149 } |
| 154 | 150 |
| 155 int WRAP(close)(int fd) { | 151 int WRAP(close)(int fd) { |
| 156 ERRNO_RTN(ki_close(fd)); | 152 ERRNO_RTN(ki_close(fd)); |
| 157 } | 153 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 174 } | 170 } |
| 175 | 171 |
| 176 int WRAP(fchmod)(int fd, mode_t mode) NOTHROW { | 172 int WRAP(fchmod)(int fd, mode_t mode) NOTHROW { |
| 177 ERRNO_RTN(ki_fchmod(fd, mode)); | 173 ERRNO_RTN(ki_fchmod(fd, mode)); |
| 178 } | 174 } |
| 179 | 175 |
| 180 int WRAP(fdatasync)(int fd) NOTHROW { | 176 int WRAP(fdatasync)(int fd) NOTHROW { |
| 181 ERRNO_RTN(ki_fdatasync(fd)); | 177 ERRNO_RTN(ki_fdatasync(fd)); |
| 182 } | 178 } |
| 183 | 179 |
| 184 int WRAP(fstat)(int fd, struct nacl_abi_stat *nacl_buf) { | 180 int WRAP(fstat)(int fd, struct nacl_abi_stat* nacl_buf) { |
| 185 struct stat buf; | 181 struct stat buf; |
| 186 memset(&buf, 0, sizeof(struct stat)); | 182 memset(&buf, 0, sizeof(struct stat)); |
| 187 int res = ki_fstat(fd, &buf); | 183 int res = ki_fstat(fd, &buf); |
| 188 RTN_ERRNO_IF(res < 0); | 184 RTN_ERRNO_IF(res < 0); |
| 189 stat_to_nacl_stat(&buf, nacl_buf); | 185 stat_to_nacl_stat(&buf, nacl_buf); |
| 190 return 0; | 186 return 0; |
| 191 } | 187 } |
| 192 | 188 |
| 193 int WRAP(fsync)(int fd) NOTHROW { | 189 int WRAP(fsync)(int fd) NOTHROW { |
| 194 ERRNO_RTN(ki_fsync(fd)); | 190 ERRNO_RTN(ki_fsync(fd)); |
| 195 } | 191 } |
| 196 | 192 |
| 197 int WRAP(getcwd)(char* buf, size_t size) { | 193 int WRAP(getcwd)(char* buf, size_t size) { |
| 198 RTN_ERRNO_IF(ki_getcwd(buf, size) == NULL); | 194 RTN_ERRNO_IF(ki_getcwd(buf, size) == NULL); |
| 199 return 0; | 195 return 0; |
| 200 } | 196 } |
| 201 | 197 |
| 202 int WRAP(getdents)(int fd, dirent* nacl_buf, size_t nacl_count, size_t *nread) { | 198 int WRAP(getdents)(int fd, dirent* nacl_buf, size_t nacl_count, size_t* nread) { |
| 203 int nacl_offset = 0; | 199 int nacl_offset = 0; |
| 204 // "buf" contains dirent(s); "nacl_buf" contains nacl_abi_dirent(s). | 200 // "buf" contains dirent(s); "nacl_buf" contains nacl_abi_dirent(s). |
| 205 // nacl_abi_dirent(s) are smaller than dirent(s), so nacl_count bytes buffer | 201 // nacl_abi_dirent(s) are smaller than dirent(s), so nacl_count bytes buffer |
| 206 // is enough | 202 // is enough |
| 207 char* buf = (char*)alloca(nacl_count); | 203 char* buf = (char*)alloca(nacl_count); |
| 208 int offset = 0; | 204 int offset = 0; |
| 209 int count; | 205 int count; |
| 210 | 206 |
| 211 count = ki_getdents(fd, buf, nacl_count); | 207 count = ki_getdents(fd, buf, nacl_count); |
| 212 RTN_ERRNO_IF(count < 0); | 208 RTN_ERRNO_IF(count < 0); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 227 *nread = nacl_offset; | 223 *nread = nacl_offset; |
| 228 return 0; | 224 return 0; |
| 229 } | 225 } |
| 230 | 226 |
| 231 int WRAP(isatty)(int fd, int* result) { | 227 int WRAP(isatty)(int fd, int* result) { |
| 232 *result = ki_isatty(fd); | 228 *result = ki_isatty(fd); |
| 233 RTN_ERRNO_IF(*result == 0); | 229 RTN_ERRNO_IF(*result == 0); |
| 234 return 0; | 230 return 0; |
| 235 } | 231 } |
| 236 | 232 |
| 237 int WRAP(lstat)(const char *path, struct nacl_abi_stat* nacl_buf) { | 233 int WRAP(lstat)(const char* path, struct nacl_abi_stat* nacl_buf) { |
| 238 struct stat buf; | 234 struct stat buf; |
| 239 memset(&buf, 0, sizeof(struct stat)); | 235 memset(&buf, 0, sizeof(struct stat)); |
| 240 int res = ki_lstat(path, &buf); | 236 int res = ki_lstat(path, &buf); |
| 241 RTN_ERRNO_IF(res < 0); | 237 RTN_ERRNO_IF(res < 0); |
| 242 stat_to_nacl_stat(&buf, nacl_buf); | 238 stat_to_nacl_stat(&buf, nacl_buf); |
| 243 return 0; | 239 return 0; |
| 244 } | 240 } |
| 245 | 241 |
| 246 int WRAP(mkdir)(const char* pathname, mode_t mode) { | 242 int WRAP(mkdir)(const char* pathname, mode_t mode) { |
| 247 ERRNO_RTN(ki_mkdir(pathname, mode)); | 243 ERRNO_RTN(ki_mkdir(pathname, mode)); |
| 248 } | 244 } |
| 249 | 245 |
| 250 int WRAP(mmap)(void** addr, size_t length, int prot, int flags, int fd, | 246 int WRAP(mmap)(void** addr, |
| 247 size_t length, |
| 248 int prot, |
| 249 int flags, |
| 250 int fd, |
| 251 int64_t offset) { | 251 int64_t offset) { |
| 252 if (flags & MAP_ANONYMOUS) | 252 if (flags & MAP_ANONYMOUS) |
| 253 return REAL(mmap)(addr, length, prot, flags, fd, offset); | 253 return REAL(mmap)(addr, length, prot, flags, fd, offset); |
| 254 | 254 |
| 255 *addr = ki_mmap(*addr, length, prot, flags, fd, offset); | 255 *addr = ki_mmap(*addr, length, prot, flags, fd, offset); |
| 256 RTN_ERRNO_IF(*addr == (void*)-1) | 256 RTN_ERRNO_IF(*addr == (void*)-1) |
| 257 return 0; | 257 return 0; |
| 258 } | 258 } |
| 259 | 259 |
| 260 int WRAP(munmap)(void* addr, size_t length) { | 260 int WRAP(munmap)(void* addr, size_t length) { |
| 261 // Always let the real munmap run on the address range. It is not an error if | 261 // Always let the real munmap run on the address range. It is not an error if |
| 262 // there are no mapped pages in that range. | 262 // there are no mapped pages in that range. |
| 263 ki_munmap(addr, length); | 263 ki_munmap(addr, length); |
| 264 return REAL(munmap)(addr, length); | 264 return REAL(munmap)(addr, length); |
| 265 } | 265 } |
| 266 | 266 |
| 267 int WRAP(open)(const char* pathname, int oflag, mode_t cmode, int* newfd) { | 267 int WRAP(open)(const char* pathname, int oflag, mode_t cmode, int* newfd) { |
| 268 *newfd = ki_open(pathname, oflag); | 268 *newfd = ki_open(pathname, oflag); |
| 269 ERRNO_RTN(*newfd); | 269 ERRNO_RTN(*newfd); |
| 270 } | 270 } |
| 271 | 271 |
| 272 int WRAP(open_resource)(const char* file, int* fd) { | 272 int WRAP(open_resource)(const char* file, int* fd) { |
| 273 *fd = ki_open_resource(file); | 273 *fd = ki_open_resource(file); |
| 274 ERRNO_RTN(*fd); | 274 ERRNO_RTN(*fd); |
| 275 } | 275 } |
| 276 | 276 |
| 277 int WRAP(poll)(struct pollfd *fds, nfds_t nfds, int timeout, int* count) { | 277 int WRAP(poll)(struct pollfd* fds, nfds_t nfds, int timeout, int* count) { |
| 278 *count = ki_poll(fds, nfds, timeout); | 278 *count = ki_poll(fds, nfds, timeout); |
| 279 ERRNO_RTN(*count); | 279 ERRNO_RTN(*count); |
| 280 | |
| 281 } | 280 } |
| 282 | 281 |
| 283 int WRAP(read)(int fd, void *buf, size_t count, size_t *nread) { | 282 int WRAP(read)(int fd, void* buf, size_t count, size_t* nread) { |
| 284 ssize_t signed_nread = ki_read(fd, buf, count); | 283 ssize_t signed_nread = ki_read(fd, buf, count); |
| 285 *nread = static_cast<size_t>(signed_nread); | 284 *nread = static_cast<size_t>(signed_nread); |
| 286 ERRNO_RTN(signed_nread); | 285 ERRNO_RTN(signed_nread); |
| 287 } | 286 } |
| 288 | 287 |
| 289 int WRAP(readlink)(const char* path, char* buf, size_t count, size_t* nread) { | 288 int WRAP(readlink)(const char* path, char* buf, size_t count, size_t* nread) { |
| 290 ssize_t signed_nread = ki_readlink(path, buf, count); | 289 ssize_t signed_nread = ki_readlink(path, buf, count); |
| 291 *nread = static_cast<size_t>(signed_nread); | 290 *nread = static_cast<size_t>(signed_nread); |
| 292 ERRNO_RTN(signed_nread); | 291 ERRNO_RTN(signed_nread); |
| 293 } | 292 } |
| 294 | 293 |
| 295 int WRAP(rmdir)(const char* pathname) { | 294 int WRAP(rmdir)(const char* pathname) { |
| 296 ERRNO_RTN(ki_rmdir(pathname)); | 295 ERRNO_RTN(ki_rmdir(pathname)); |
| 297 } | 296 } |
| 298 | 297 |
| 299 int WRAP(seek)(int fd, off64_t offset, int whence, int64_t* new_offset) { | 298 int WRAP(seek)(int fd, off64_t offset, int whence, int64_t* new_offset) { |
| 300 *new_offset = ki_lseek(fd, offset, whence); | 299 *new_offset = ki_lseek(fd, offset, whence); |
| 301 ERRNO_RTN(*new_offset); | 300 ERRNO_RTN(*new_offset); |
| 302 } | 301 } |
| 303 | 302 |
| 304 int WRAP(select)(int nfds, fd_set* readfds, fd_set* writefds, | 303 int WRAP(select)(int nfds, |
| 305 fd_set* exceptfds, struct timeval* timeout, int* count) { | 304 fd_set* readfds, |
| 305 fd_set* writefds, |
| 306 fd_set* exceptfds, |
| 307 struct timeval* timeout, |
| 308 int* count) { |
| 306 *count = ki_select(nfds, readfds, writefds, exceptfds, timeout); | 309 *count = ki_select(nfds, readfds, writefds, exceptfds, timeout); |
| 307 ERRNO_RTN(*count); | 310 ERRNO_RTN(*count); |
| 308 } | 311 } |
| 309 | 312 |
| 310 int WRAP(stat)(const char *pathname, struct nacl_abi_stat *nacl_buf) { | 313 int WRAP(stat)(const char* pathname, struct nacl_abi_stat* nacl_buf) { |
| 311 struct stat buf; | 314 struct stat buf; |
| 312 memset(&buf, 0, sizeof(struct stat)); | 315 memset(&buf, 0, sizeof(struct stat)); |
| 313 int res = ki_stat(pathname, &buf); | 316 int res = ki_stat(pathname, &buf); |
| 314 RTN_ERRNO_IF(res < 0); | 317 RTN_ERRNO_IF(res < 0); |
| 315 stat_to_nacl_stat(&buf, nacl_buf); | 318 stat_to_nacl_stat(&buf, nacl_buf); |
| 316 return 0; | 319 return 0; |
| 317 } | 320 } |
| 318 | 321 |
| 319 int WRAP(truncate)(const char *name, int64_t len) { | 322 int WRAP(truncate)(const char* name, int64_t len) { |
| 320 ERRNO_RTN(ki_truncate(name, len)); | 323 ERRNO_RTN(ki_truncate(name, len)); |
| 321 } | 324 } |
| 322 | 325 |
| 323 int WRAP(write)(int fd, const void* buf, size_t count, size_t* nwrote) { | 326 int WRAP(write)(int fd, const void* buf, size_t count, size_t* nwrote) { |
| 324 ssize_t signed_nwrote = ki_write(fd, buf, count); | 327 ssize_t signed_nwrote = ki_write(fd, buf, count); |
| 325 *nwrote = static_cast<size_t>(signed_nwrote); | 328 *nwrote = static_cast<size_t>(signed_nwrote); |
| 326 ERRNO_RTN(signed_nwrote); | 329 ERRNO_RTN(signed_nwrote); |
| 327 } | 330 } |
| 328 | 331 |
| 329 static void assign_real_pointers() { | 332 static void assign_real_pointers() { |
| 330 static bool assigned = false; | 333 static bool assigned = false; |
| 331 if (!assigned) { | 334 if (!assigned) { |
| 332 EXPAND_SYMBOL_LIST_OPERATION(ASSIGN_REAL_PTR) | 335 EXPAND_SYMBOL_LIST_OPERATION(ASSIGN_REAL_PTR) |
| 333 assigned = true; | 336 assigned = true; |
| 334 } | 337 } |
| 335 } | 338 } |
| 336 | 339 |
| 337 #define CHECK_REAL(func) \ | 340 #define CHECK_REAL(func) \ |
| 338 if (!REAL(func)) \ | 341 if (!REAL(func)) \ |
| 339 assign_real_pointers(); | 342 assign_real_pointers(); |
| 340 | 343 |
| 341 // "real" functions, i.e. the unwrapped original functions. | 344 // "real" functions, i.e. the unwrapped original functions. |
| 342 | 345 |
| 343 int _real_close(int fd) { | 346 int _real_close(int fd) { |
| 344 CHECK_REAL(close); | 347 CHECK_REAL(close); |
| 345 return REAL(close)(fd); | 348 return REAL(close)(fd); |
| 346 } | 349 } |
| 347 | 350 |
| 348 void _real_exit(int status) { | 351 void _real_exit(int status) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 361 | 364 |
| 362 int _real_fdatasync(int fd) { | 365 int _real_fdatasync(int fd) { |
| 363 CHECK_REAL(fdatasync); | 366 CHECK_REAL(fdatasync); |
| 364 return REAL(fdatasync)(fd); | 367 return REAL(fdatasync)(fd); |
| 365 } | 368 } |
| 366 | 369 |
| 367 int _real_fstat(int fd, struct stat* buf) { | 370 int _real_fstat(int fd, struct stat* buf) { |
| 368 struct nacl_abi_stat st; | 371 struct nacl_abi_stat st; |
| 369 CHECK_REAL(fstat); | 372 CHECK_REAL(fstat); |
| 370 | 373 |
| 371 int err = REAL(fstat)(fd, (struct stat*) &st); | 374 int err = REAL(fstat)(fd, (struct stat*)&st); |
| 372 if (err) { | 375 if (err) { |
| 373 errno = err; | 376 errno = err; |
| 374 return -1; | 377 return -1; |
| 375 } | 378 } |
| 376 | 379 |
| 377 nacl_stat_to_stat(&st, buf); | 380 nacl_stat_to_stat(&st, buf); |
| 378 return 0; | 381 return 0; |
| 379 } | 382 } |
| 380 | 383 |
| 381 int _real_fsync(int fd) { | 384 int _real_fsync(int fd) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 394 int err = REAL(getdents)(fd, (dirent*)nacl_buf, count, &nacl_nread); | 397 int err = REAL(getdents)(fd, (dirent*)nacl_buf, count, &nacl_nread); |
| 395 if (err) | 398 if (err) |
| 396 return err; | 399 return err; |
| 397 | 400 |
| 398 while (nacl_offset < nacl_nread) { | 401 while (nacl_offset < nacl_nread) { |
| 399 dirent* d = (dirent*)((char*)buf + offset); | 402 dirent* d = (dirent*)((char*)buf + offset); |
| 400 nacl_abi_dirent* nacl_d = (nacl_abi_dirent*)(nacl_buf + nacl_offset); | 403 nacl_abi_dirent* nacl_d = (nacl_abi_dirent*)(nacl_buf + nacl_offset); |
| 401 d->d_ino = nacl_d->nacl_abi_d_ino; | 404 d->d_ino = nacl_d->nacl_abi_d_ino; |
| 402 d->d_off = nacl_d->nacl_abi_d_off; | 405 d->d_off = nacl_d->nacl_abi_d_off; |
| 403 d->d_reclen = nacl_d->nacl_abi_d_reclen + d_name_shift; | 406 d->d_reclen = nacl_d->nacl_abi_d_reclen + d_name_shift; |
| 404 size_t d_name_len = nacl_d->nacl_abi_d_reclen - | 407 size_t d_name_len = |
| 405 offsetof(nacl_abi_dirent, nacl_abi_d_name); | 408 nacl_d->nacl_abi_d_reclen - offsetof(nacl_abi_dirent, nacl_abi_d_name); |
| 406 memcpy(d->d_name, nacl_d->nacl_abi_d_name, d_name_len); | 409 memcpy(d->d_name, nacl_d->nacl_abi_d_name, d_name_len); |
| 407 | 410 |
| 408 offset += d->d_reclen; | 411 offset += d->d_reclen; |
| 409 offset += nacl_d->nacl_abi_d_reclen; | 412 offset += nacl_d->nacl_abi_d_reclen; |
| 410 } | 413 } |
| 411 | 414 |
| 412 *nread = offset; | 415 *nread = offset; |
| 413 return 0; | 416 return 0; |
| 414 } | 417 } |
| 415 | 418 |
| 416 int _real_isatty(int fd, int* result) { | 419 int _real_isatty(int fd, int* result) { |
| 417 *result = isatty(fd); | 420 *result = isatty(fd); |
| 418 return *result ? 0 : -1; | 421 return *result ? 0 : -1; |
| 419 } | 422 } |
| 420 | 423 |
| 421 int _real_lseek(int fd, int64_t offset, int whence, int64_t* new_offset) { | 424 int _real_lseek(int fd, int64_t offset, int whence, int64_t* new_offset) { |
| 422 CHECK_REAL(seek); | 425 CHECK_REAL(seek); |
| 423 nacl_abi_off_t nacl_new_offs; | 426 nacl_abi_off_t nacl_new_offs; |
| 424 int ret = REAL(seek)(fd, offset, whence, &nacl_new_offs); | 427 int ret = REAL(seek)(fd, offset, whence, &nacl_new_offs); |
| 425 *new_offset = static_cast<off_t>(nacl_new_offs); | 428 *new_offset = static_cast<off_t>(nacl_new_offs); |
| 426 return ret; | 429 return ret; |
| 427 } | 430 } |
| 428 | 431 |
| 429 int _real_lstat(const char* path, struct stat* buf) { | 432 int _real_lstat(const char* path, struct stat* buf) { |
| 430 struct nacl_abi_stat st; | 433 struct nacl_abi_stat st; |
| 431 CHECK_REAL(fstat); | 434 CHECK_REAL(fstat); |
| 432 | 435 |
| 433 int err = REAL(lstat)(path, (struct stat*) &st); | 436 int err = REAL(lstat)(path, (struct stat*)&st); |
| 434 if (err) { | 437 if (err) { |
| 435 errno = err; | 438 errno = err; |
| 436 return -1; | 439 return -1; |
| 437 } | 440 } |
| 438 | 441 |
| 439 nacl_stat_to_stat(&st, buf); | 442 nacl_stat_to_stat(&st, buf); |
| 440 return 0; | 443 return 0; |
| 441 } | 444 } |
| 442 | 445 |
| 443 | |
| 444 int _real_mkdir(const char* pathname, mode_t mode) { | 446 int _real_mkdir(const char* pathname, mode_t mode) { |
| 445 CHECK_REAL(mkdir); | 447 CHECK_REAL(mkdir); |
| 446 return REAL(mkdir)(pathname, mode); | 448 return REAL(mkdir)(pathname, mode); |
| 447 } | 449 } |
| 448 | 450 |
| 449 int _real_mmap(void** addr, size_t length, int prot, int flags, int fd, | 451 int _real_mmap(void** addr, |
| 452 size_t length, |
| 453 int prot, |
| 454 int flags, |
| 455 int fd, |
| 450 int64_t offset) { | 456 int64_t offset) { |
| 451 CHECK_REAL(mmap); | 457 CHECK_REAL(mmap); |
| 452 return REAL(mmap)(addr, length, prot, flags, fd, offset); | 458 return REAL(mmap)(addr, length, prot, flags, fd, offset); |
| 453 } | 459 } |
| 454 | 460 |
| 455 int _real_munmap(void* addr, size_t length) { | 461 int _real_munmap(void* addr, size_t length) { |
| 456 CHECK_REAL(munmap); | 462 CHECK_REAL(munmap); |
| 457 return REAL(munmap)(addr, length); | 463 return REAL(munmap)(addr, length); |
| 458 } | 464 } |
| 459 | 465 |
| 460 int _real_open(const char* pathname, int oflag, mode_t cmode, int* newfd) { | 466 int _real_open(const char* pathname, int oflag, mode_t cmode, int* newfd) { |
| 461 CHECK_REAL(open); | 467 CHECK_REAL(open); |
| 462 return REAL(open)(pathname, oflag, cmode, newfd); | 468 return REAL(open)(pathname, oflag, cmode, newfd); |
| 463 } | 469 } |
| 464 | 470 |
| 465 int _real_open_resource(const char* file, int* fd) { | 471 int _real_open_resource(const char* file, int* fd) { |
| 466 CHECK_REAL(open_resource); | 472 CHECK_REAL(open_resource); |
| 467 return REAL(open_resource)(file, fd); | 473 return REAL(open_resource)(file, fd); |
| 468 } | 474 } |
| 469 | 475 |
| 470 int _real_read(int fd, void *buf, size_t count, size_t *nread) { | 476 int _real_read(int fd, void* buf, size_t count, size_t* nread) { |
| 471 CHECK_REAL(read); | 477 CHECK_REAL(read); |
| 472 return REAL(read)(fd, buf, count, nread); | 478 return REAL(read)(fd, buf, count, nread); |
| 473 } | 479 } |
| 474 | 480 |
| 475 int _real_readlink(const char *path, char* buf, size_t count, size_t* nread) { | 481 int _real_readlink(const char* path, char* buf, size_t count, size_t* nread) { |
| 476 CHECK_REAL(readlink); | 482 CHECK_REAL(readlink); |
| 477 return REAL(readlink)(path, buf, count, nread); | 483 return REAL(readlink)(path, buf, count, nread); |
| 478 } | 484 } |
| 479 | 485 |
| 480 int _real_rmdir(const char* pathname) { | 486 int _real_rmdir(const char* pathname) { |
| 481 CHECK_REAL(rmdir); | 487 CHECK_REAL(rmdir); |
| 482 return REAL(rmdir)(pathname); | 488 return REAL(rmdir)(pathname); |
| 483 } | 489 } |
| 484 | 490 |
| 485 int _real_truncate(const char* pathname, int64_t len) { | 491 int _real_truncate(const char* pathname, int64_t len) { |
| 486 CHECK_REAL(truncate); | 492 CHECK_REAL(truncate); |
| 487 return REAL(truncate)(pathname, len); | 493 return REAL(truncate)(pathname, len); |
| 488 } | 494 } |
| 489 | 495 |
| 490 int _real_write(int fd, const void *buf, size_t count, size_t *nwrote) { | 496 int _real_write(int fd, const void* buf, size_t count, size_t* nwrote) { |
| 491 CHECK_REAL(write); | 497 CHECK_REAL(write); |
| 492 return REAL(write)(fd, buf, count, nwrote); | 498 return REAL(write)(fd, buf, count, nwrote); |
| 493 } | 499 } |
| 494 | 500 |
| 495 static bool s_wrapped = false; | 501 static bool s_wrapped = false; |
| 496 void kernel_wrap_init() { | 502 void kernel_wrap_init() { |
| 497 if (!s_wrapped) { | 503 if (!s_wrapped) { |
| 498 assign_real_pointers(); | 504 assign_real_pointers(); |
| 499 EXPAND_SYMBOL_LIST_OPERATION(USE_WRAP) | 505 EXPAND_SYMBOL_LIST_OPERATION(USE_WRAP) |
| 500 s_wrapped = true; | 506 s_wrapped = true; |
| 501 } | 507 } |
| 502 } | 508 } |
| 503 | 509 |
| 504 void kernel_wrap_uninit() { | 510 void kernel_wrap_uninit() { |
| 505 if (s_wrapped) { | 511 if (s_wrapped) { |
| 506 EXPAND_SYMBOL_LIST_OPERATION(USE_REAL) | 512 EXPAND_SYMBOL_LIST_OPERATION(USE_REAL) |
| 507 s_wrapped = false; | 513 s_wrapped = false; |
| 508 } | 514 } |
| 509 } | 515 } |
| 510 | 516 |
| 511 EXTERN_C_END | 517 EXTERN_C_END |
| 512 | 518 |
| 513 #endif // defined(__native_client__) && defined(__GLIBC__) | 519 #endif // defined(__native_client__) && defined(__GLIBC__) |
| OLD | NEW |