Chromium Code Reviews| 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 __GLIBC__. | 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-glibc build. | 8 // compiled, even on a non-glibc build. |
|
binji
2014/04/02 18:35:53
non-bionic
noelallen1
2014/04/03 17:58:52
Done.
| |
| 9 #if defined(__native_client__) && defined(__GLIBC__) | |
| 10 | 9 |
| 10 #if defined(__native_client__) && defined(__BIONIC__) | |
| 11 #include "nacl_io/kernel_wrap.h" | 11 #include "nacl_io/kernel_wrap.h" |
| 12 | 12 |
| 13 #include <alloca.h> | 13 #include <alloca.h> |
| 14 #include <assert.h> | 14 #include <assert.h> |
| 15 #include <dirent.h> | 15 #include <dirent.h> |
| 16 #include <errno.h> | 16 #include <errno.h> |
| 17 #include <irt.h> | |
| 18 #include <irt_syscalls.h> | |
| 19 #include <nacl_stat.h> | |
| 20 #include <string.h> | 17 #include <string.h> |
| 21 #include <sys/stat.h> | 18 #include <sys/stat.h> |
| 22 #include <sys/time.h> | 19 #include <sys/time.h> |
| 20 #include <irt_syscalls.h> | |
|
binji
2014/04/02 18:35:53
alphabetize? If this has to come after the previou
noelallen1
2014/04/03 17:58:52
Done.
| |
| 23 | 21 |
| 24 #include "nacl_io/kernel_intercept.h" | 22 #include "nacl_io/kernel_intercept.h" |
| 25 #include "nacl_io/kernel_wrap_real.h" | 23 #include "nacl_io/kernel_wrap_real.h" |
| 26 #include "nacl_io/osmman.h" | 24 #include "nacl_io/osmman.h" |
| 27 | 25 |
| 28 | |
| 29 namespace { | 26 namespace { |
| 30 | 27 |
| 31 void stat_to_nacl_stat(const struct stat* buf, nacl_abi_stat* nacl_buf) { | 28 void stat_to_nacl_stat(const struct stat* buf, nacl_abi_stat* nacl_buf) { |
| 32 memset(nacl_buf, 0, sizeof(struct nacl_abi_stat)); | 29 memset(nacl_buf, 0, sizeof(struct nacl_abi_stat)); |
| 33 nacl_buf->nacl_abi_st_dev = buf->st_dev; | 30 nacl_buf->nacl_abi_st_dev = buf->st_dev; |
| 34 nacl_buf->nacl_abi_st_ino = buf->st_ino; | 31 nacl_buf->nacl_abi_st_ino = buf->st_ino; |
| 35 nacl_buf->nacl_abi_st_mode = buf->st_mode; | 32 nacl_buf->nacl_abi_st_mode = buf->st_mode; |
| 36 nacl_buf->nacl_abi_st_nlink = buf->st_nlink; | 33 nacl_buf->nacl_abi_st_nlink = buf->st_nlink; |
| 37 nacl_buf->nacl_abi_st_uid = buf->st_uid; | 34 nacl_buf->nacl_abi_st_uid = buf->st_uid; |
| 38 nacl_buf->nacl_abi_st_gid = buf->st_gid; | 35 nacl_buf->nacl_abi_st_gid = buf->st_gid; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 | 101 |
| 105 // Macro to get the WRAP function | 102 // Macro to get the WRAP function |
| 106 #define WRAP(name) __nacl_irt_##name##_wrap | 103 #define WRAP(name) __nacl_irt_##name##_wrap |
| 107 | 104 |
| 108 // Declare REAL function pointer. | 105 // Declare REAL function pointer. |
| 109 #define DECLARE_REAL_PTR(name) \ | 106 #define DECLARE_REAL_PTR(name) \ |
| 110 typeof(__nacl_irt_##name) REAL(name); | 107 typeof(__nacl_irt_##name) REAL(name); |
| 111 | 108 |
| 112 // Assign the REAL function pointer. | 109 // Assign the REAL function pointer. |
| 113 #define ASSIGN_REAL_PTR(name) \ | 110 #define ASSIGN_REAL_PTR(name) \ |
| 114 assert(__nacl_irt_##name != NULL); \ | |
| 115 REAL(name) = __nacl_irt_##name; | 111 REAL(name) = __nacl_irt_##name; |
| 116 | 112 |
| 117 // Switch IRT's pointer to the REAL pointer | 113 // Switch IRT's pointer to the REAL pointer |
| 118 #define USE_REAL(name) \ | 114 #define USE_REAL(name) \ |
| 119 __nacl_irt_##name = (typeof(__nacl_irt_##name)) REAL(name) | 115 __nacl_irt_##name = (typeof(__nacl_irt_##name)) REAL(name) |
| 120 | 116 |
| 121 // Switch IRT's pointer to the WRAP function | 117 // Switch IRT's pointer to the WRAP function |
| 122 #define USE_WRAP(name) \ | 118 #define USE_WRAP(name) \ |
| 123 __nacl_irt_##name = (typeof(__nacl_irt_##name)) WRAP(name) | 119 __nacl_irt_##name = (typeof(__nacl_irt_##name)) WRAP(name) |
| 124 | 120 |
| 125 | 121 |
| 126 #define EXPAND_SYMBOL_LIST_OPERATION(OP) \ | 122 #define EXPAND_SYMBOL_LIST_OPERATION(OP) \ |
| 127 OP(chdir); \ | 123 OP(chdir); \ |
| 128 OP(close); \ | 124 OP(close); \ |
| 129 OP(dup); \ | 125 OP(dup); \ |
| 130 OP(dup2); \ | 126 OP(dup2); \ |
|
binji
2014/04/02 18:35:53
nit: remove extra space
noelallen1
2014/04/03 17:58:52
Done.
| |
| 131 OP(exit); \ | 127 OP(exit); \ |
| 128 OP(fchdir); \ | |
| 129 OP(fchmod); \ | |
| 130 OP(fdatasync); \ | |
| 132 OP(fstat); \ | 131 OP(fstat); \ |
| 133 OP(getcwd); \ | 132 OP(fsync); \ |
| 134 OP(getdents); \ | 133 OP(getcwd); \ |
| 134 OP(getdents); \ | |
| 135 OP(isatty); \ | |
| 136 OP(lstat); \ | |
| 135 OP(mkdir); \ | 137 OP(mkdir); \ |
| 138 OP(mmap); \ | |
| 139 OP(munmap); \ | |
| 136 OP(open); \ | 140 OP(open); \ |
| 137 OP(poll);\ | 141 OP(open_resource); \ |
| 142 OP(poll); \ | |
| 138 OP(read); \ | 143 OP(read); \ |
| 144 OP(readlink); \ | |
| 139 OP(rmdir); \ | 145 OP(rmdir); \ |
| 140 OP(seek); \ | 146 OP(seek); \ |
| 141 OP(stat); \ | 147 OP(stat); \ |
| 142 OP(select); \ | 148 OP(truncate); \ |
| 143 OP(write); \ | 149 OP(write); \ |
| 144 OP(mmap); \ | 150 |
| 145 OP(munmap); \ | |
| 146 OP(open_resource); | |
| 147 | 151 |
| 148 EXPAND_SYMBOL_LIST_OPERATION(DECLARE_REAL_PTR); | 152 EXPAND_SYMBOL_LIST_OPERATION(DECLARE_REAL_PTR); |
| 149 | 153 |
| 150 int WRAP(chdir)(const char* pathname) { | 154 int WRAP(chdir) (const char* pathname) { |
|
binji
2014/04/02 18:35:53
nit: remove extra space
noelallen1
2014/04/03 17:58:52
Done.
| |
| 151 return (ki_chdir(pathname)) ? errno : 0; | 155 return (ki_chdir(pathname)) ? errno : 0; |
| 152 } | 156 } |
| 153 | 157 |
| 154 int WRAP(close)(int fd) { | 158 int WRAP(close)(int fd) { |
| 155 return (ki_close(fd) < 0) ? errno : 0; | 159 return (ki_close(fd) < 0) ? errno : 0; |
| 156 } | 160 } |
| 157 | 161 |
| 158 int WRAP(dup)(int fd, int* newfd) NOTHROW { | 162 int WRAP(dup)(int fd, int* newfd) NOTHROW { |
| 159 *newfd = ki_dup(fd); | 163 *newfd = ki_dup(fd); |
| 160 return (*newfd < 0) ? errno : 0; | 164 return (*newfd < 0) ? errno : 0; |
| 161 } | 165 } |
| 162 | 166 |
| 163 int WRAP(dup2)(int fd, int newfd) NOTHROW { | 167 int WRAP(dup2)(int fd, int newfd) NOTHROW { |
| 164 return (ki_dup2(fd, newfd) < 0) ? errno : 0; | 168 return (ki_dup2(fd, newfd) < 0) ? errno : 0; |
| 165 } | 169 } |
| 166 | 170 |
| 167 void WRAP(exit)(int status) { | 171 void WRAP(exit)(int status) { |
| 168 ki_exit(status); | 172 ki_exit(status); |
| 169 } | 173 } |
| 170 | 174 |
| 175 int WRAP(fchdir)(int fd) NOTHROW { | |
| 176 return (ki_fchdir(fd)) ? errno : 0; | |
| 177 } | |
| 178 | |
| 179 int WRAP(fchmod)(int fd, mode_t mode) NOTHROW { | |
| 180 return (ki_fchmod(fd, mode)) ? errno : 0; | |
| 181 } | |
| 182 | |
| 183 int WRAP(fdatasync)(int fd) NOTHROW { | |
| 184 return (ki_fdatasync(fd)) ? errno : 0; | |
| 185 } | |
| 186 | |
| 171 int WRAP(fstat)(int fd, struct nacl_abi_stat *nacl_buf) { | 187 int WRAP(fstat)(int fd, struct nacl_abi_stat *nacl_buf) { |
| 172 struct stat buf; | 188 struct stat buf; |
| 173 memset(&buf, 0, sizeof(struct stat)); | 189 memset(&buf, 0, sizeof(struct stat)); |
| 174 int res = ki_fstat(fd, &buf); | 190 int res = ki_fstat(fd, &buf); |
| 175 if (res < 0) | 191 if (res < 0) |
| 176 return errno; | 192 return errno; |
| 177 stat_to_nacl_stat(&buf, nacl_buf); | 193 stat_to_nacl_stat(&buf, nacl_buf); |
| 178 return 0; | 194 return 0; |
| 179 } | 195 } |
| 180 | 196 |
| 181 int WRAP(getcwd)(char* buf, size_t size) { | 197 int WRAP(fsync)(int fd) NOTHROW { |
| 182 if (ki_getcwd(buf, size) == NULL) | 198 return (ki_fsync(fd)) ? errno : 0; |
| 183 return errno; | 199 } |
| 184 return 0; | 200 |
| 201 char* WRAP(getcwd)(char* buf, size_t size) { | |
| 202 return ki_getcwd(buf, size); | |
|
binji
2014/04/02 18:35:53
why doesn't this return errno? Is this wrapped fun
noelallen1
2014/04/03 17:58:52
Done.
| |
| 185 } | 203 } |
| 186 | 204 |
| 187 int WRAP(getdents)(int fd, dirent* nacl_buf, size_t nacl_count, size_t *nread) { | 205 int WRAP(getdents)(int fd, dirent* nacl_buf, size_t nacl_count, size_t *nread) { |
| 188 int nacl_offset = 0; | 206 int nacl_offset = 0; |
| 189 // "buf" contains dirent(s); "nacl_buf" contains nacl_abi_dirent(s). | 207 // "buf" contains dirent(s); "nacl_buf" contains nacl_abi_dirent(s). |
| 190 // nacl_abi_dirent(s) are smaller than dirent(s), so nacl_count bytes buffer | 208 // nacl_abi_dirent(s) are smaller than dirent(s), so nacl_count bytes buffer |
| 191 // is enough | 209 // is enough |
| 192 char* buf = (char*)alloca(nacl_count); | 210 char* buf = (char*)alloca(nacl_count); |
| 193 int offset = 0; | 211 int offset = 0; |
| 194 int count; | 212 int count; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 207 memcpy(nacl_d->nacl_abi_d_name, d->d_name, d_name_len); | 225 memcpy(nacl_d->nacl_abi_d_name, d->d_name, d_name_len); |
| 208 | 226 |
| 209 offset += d->d_reclen; | 227 offset += d->d_reclen; |
| 210 nacl_offset += nacl_d->nacl_abi_d_reclen; | 228 nacl_offset += nacl_d->nacl_abi_d_reclen; |
| 211 } | 229 } |
| 212 | 230 |
| 213 *nread = nacl_offset; | 231 *nread = nacl_offset; |
| 214 return 0; | 232 return 0; |
| 215 } | 233 } |
| 216 | 234 |
| 235 int WRAP(isatty)(int fd, int* result) { | |
| 236 *result = ki_isatty(fd); | |
| 237 if (*result == 1) | |
| 238 return errno; | |
| 239 return 0; | |
| 240 } | |
| 241 | |
| 242 int WRAP(lstat)(const char *path, struct nacl_abi_stat* nacl_buf) { | |
| 243 struct stat buf; | |
| 244 memset(&buf, 0, sizeof(struct stat)); | |
| 245 int res = ki_lstat(path, &buf); | |
| 246 if (res < 0) | |
| 247 return errno; | |
| 248 stat_to_nacl_stat(&buf, nacl_buf); | |
| 249 return 0; | |
| 250 } | |
| 251 | |
| 217 int WRAP(mkdir)(const char* pathname, mode_t mode) { | 252 int WRAP(mkdir)(const char* pathname, mode_t mode) { |
| 218 return (ki_mkdir(pathname, mode)) ? errno : 0; | 253 return (ki_mkdir(pathname, mode)) ? errno : 0; |
| 219 } | 254 } |
| 220 | 255 |
| 221 int WRAP(mmap)(void** addr, size_t length, int prot, int flags, int fd, | 256 int WRAP(mmap)(void** addr, size_t length, int prot, int flags, int fd, |
| 222 off_t offset) { | 257 int64_t offset) { |
| 223 if (flags & MAP_ANONYMOUS) | 258 if (flags & MAP_ANONYMOUS) |
| 224 return REAL(mmap)(addr, length, prot, flags, fd, offset); | 259 return REAL(mmap)(addr, length, prot, flags, fd, offset); |
| 225 | 260 |
| 226 *addr = ki_mmap(*addr, length, prot, flags, fd, offset); | 261 *addr = ki_mmap(*addr, length, prot, flags, fd, offset); |
| 227 return *addr == (void*)-1 ? errno : 0; | 262 return *addr == (void*)-1 ? errno : 0; |
| 228 } | 263 } |
| 229 | 264 |
| 230 int WRAP(munmap)(void* addr, size_t length) { | 265 int WRAP(munmap)(void* addr, size_t length) { |
| 231 // Always let the real munmap run on the address range. It is not an error if | 266 // Always let the real munmap run on the address range. It is not an error if |
| 232 // there are no mapped pages in that range. | 267 // there are no mapped pages in that range. |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 249 return (*count < 0) ? errno : 0; | 284 return (*count < 0) ? errno : 0; |
| 250 | 285 |
| 251 } | 286 } |
| 252 | 287 |
| 253 int WRAP(read)(int fd, void *buf, size_t count, size_t *nread) { | 288 int WRAP(read)(int fd, void *buf, size_t count, size_t *nread) { |
| 254 ssize_t signed_nread = ki_read(fd, buf, count); | 289 ssize_t signed_nread = ki_read(fd, buf, count); |
| 255 *nread = static_cast<size_t>(signed_nread); | 290 *nread = static_cast<size_t>(signed_nread); |
| 256 return (signed_nread < 0) ? errno : 0; | 291 return (signed_nread < 0) ? errno : 0; |
| 257 } | 292 } |
| 258 | 293 |
| 294 int WRAP(readlink)(const char* path, char* buf, size_t count, size_t* nread) { | |
| 295 ssize_t signed_nread = ki_readlink(path, buf, count); | |
| 296 *nread = static_cast<size_t>(signed_nread); | |
| 297 return (signed_nread < 0) ? errno : 0; | |
| 298 } | |
| 299 | |
| 259 int WRAP(rmdir)(const char* pathname) { | 300 int WRAP(rmdir)(const char* pathname) { |
| 260 return (ki_rmdir(pathname) < 0) ? errno : 0; | 301 return (ki_rmdir(pathname) < 0) ? errno : 0; |
| 261 } | 302 } |
| 262 | 303 |
| 263 int WRAP(seek)(int fd, off_t offset, int whence, off_t* new_offset) { | 304 int WRAP(seek)(int fd, off64_t offset, int whence, int64_t* new_offset) { |
| 264 *new_offset = ki_lseek(fd, offset, whence); | 305 *new_offset = ki_lseek(fd, offset, whence); |
| 265 return (*new_offset < 0) ? errno : 0; | 306 return (*new_offset < 0) ? errno : 0; |
| 266 } | 307 } |
| 267 | 308 |
| 268 int WRAP(select)(int nfds, fd_set* readfds, fd_set* writefds, | 309 int WRAP(select)(int nfds, fd_set* readfds, fd_set* writefds, |
| 269 fd_set* exceptfds, struct timeval* timeout, int* count) { | 310 fd_set* exceptfds, struct timeval* timeout, int* count) { |
| 270 *count = ki_select(nfds, readfds, writefds, exceptfds, timeout); | 311 *count = ki_select(nfds, readfds, writefds, exceptfds, timeout); |
| 271 return (*count < 0) ? errno : 0; | 312 return (*count < 0) ? errno : 0; |
| 272 } | 313 } |
| 273 | 314 |
| 274 int WRAP(stat)(const char *pathname, struct nacl_abi_stat *nacl_buf) { | 315 int WRAP(stat)(const char *pathname, struct nacl_abi_stat *nacl_buf) { |
| 275 struct stat buf; | 316 struct stat buf; |
| 276 memset(&buf, 0, sizeof(struct stat)); | 317 memset(&buf, 0, sizeof(struct stat)); |
| 277 int res = ki_stat(pathname, &buf); | 318 int res = ki_stat(pathname, &buf); |
| 278 if (res < 0) | 319 if (res < 0) |
| 279 return errno; | 320 return errno; |
| 280 stat_to_nacl_stat(&buf, nacl_buf); | 321 stat_to_nacl_stat(&buf, nacl_buf); |
| 281 return 0; | 322 return 0; |
| 282 } | 323 } |
| 283 | 324 |
| 325 int WRAP(truncate)(const char *name, int64_t len) { | |
| 326 return (ki_truncate(name, len)) ? errno : 0; | |
| 327 } | |
| 328 | |
| 284 int WRAP(write)(int fd, const void* buf, size_t count, size_t* nwrote) { | 329 int WRAP(write)(int fd, const void* buf, size_t count, size_t* nwrote) { |
| 285 ssize_t signed_nwrote = ki_write(fd, buf, count); | 330 ssize_t signed_nwrote = ki_write(fd, buf, count); |
| 286 *nwrote = static_cast<size_t>(signed_nwrote); | 331 *nwrote = static_cast<size_t>(signed_nwrote); |
| 287 return (signed_nwrote < 0) ? errno : 0; | 332 return (signed_nwrote < 0) ? errno : 0; |
| 288 } | 333 } |
| 289 | 334 |
| 290 static void assign_real_pointers() { | 335 static void assign_real_pointers() { |
| 291 static bool assigned = false; | 336 static bool assigned = false; |
| 292 if (!assigned) { | 337 if (!assigned) { |
| 293 EXPAND_SYMBOL_LIST_OPERATION(ASSIGN_REAL_PTR) | 338 EXPAND_SYMBOL_LIST_OPERATION(ASSIGN_REAL_PTR) |
| 294 assigned = true; | 339 assigned = true; |
| 295 } | 340 } |
| 296 } | 341 } |
| 297 | 342 |
| 298 #define CHECK_REAL(func) \ | 343 #define CHECK_REAL(func) \ |
| 299 if (!REAL(func)) \ | 344 if (!REAL(func)) \ |
| 300 assign_real_pointers(); | 345 assign_real_pointers(); |
| 301 | 346 |
| 302 // "real" functions, i.e. the unwrapped original functions. | 347 // "real" functions, i.e. the unwrapped original functions. |
| 303 | 348 |
| 304 int _real_close(int fd) { | 349 int _real_close(int fd) { |
| 305 CHECK_REAL(close); | 350 CHECK_REAL(close); |
| 306 return REAL(close)(fd); | 351 return REAL(close)(fd); |
| 307 } | 352 } |
| 308 | 353 |
| 309 void _real_exit(int status) { | 354 void _real_exit(int status) { |
| 310 CHECK_REAL(exit); | |
| 311 REAL(exit)(status); | 355 REAL(exit)(status); |
| 312 } | 356 } |
| 313 | 357 |
| 358 int _real_fchdir(int fd) { | |
| 359 CHECK_REAL(fchdir); | |
| 360 return REAL(fchdir)(fd); | |
| 361 } | |
| 362 | |
| 363 int _real_fchmod(int fd, mode_t mode) { | |
| 364 CHECK_REAL(fchmod); | |
| 365 return REAL(fchmod)(fd, mode); | |
| 366 } | |
| 367 | |
| 368 int _real_fdatasync(int fd) { | |
| 369 CHECK_REAL(fdatasync); | |
| 370 return REAL(fdatasync)(fd); | |
| 371 } | |
| 372 | |
| 314 int _real_fstat(int fd, struct stat* buf) { | 373 int _real_fstat(int fd, struct stat* buf) { |
| 315 struct nacl_abi_stat st; | 374 struct nacl_abi_stat st; |
| 316 CHECK_REAL(fstat); | 375 CHECK_REAL(fstat); |
| 317 int err = REAL(fstat)(fd, &st); | 376 |
| 377 int err = REAL(fstat)(fd, (struct stat*) &st); | |
| 318 if (err) { | 378 if (err) { |
| 319 errno = err; | 379 errno = err; |
| 320 return -1; | 380 return -1; |
| 321 } | 381 } |
| 322 | 382 |
| 323 nacl_stat_to_stat(&st, buf); | 383 nacl_stat_to_stat(&st, buf); |
| 324 return 0; | 384 return 0; |
| 325 } | 385 } |
| 326 | 386 |
| 387 int _real_fsync(int fd) { | |
| 388 CHECK_REAL(fsync); | |
| 389 return REAL(fsync)(fd); | |
| 390 } | |
| 391 | |
| 327 int _real_getdents(int fd, void* buf, size_t count, size_t* nread) { | 392 int _real_getdents(int fd, void* buf, size_t count, size_t* nread) { |
| 328 // "buf" contains dirent(s); "nacl_buf" contains nacl_abi_dirent(s). | 393 // "buf" contains dirent(s); "nacl_buf" contains nacl_abi_dirent(s). |
| 329 // See WRAP(getdents) above. | 394 // See WRAP(getdents) above. |
| 330 char* nacl_buf = (char*)alloca(count); | 395 char* nacl_buf = (char*)alloca(count); |
| 331 size_t offset = 0; | 396 size_t offset = 0; |
| 332 size_t nacl_offset = 0; | 397 size_t nacl_offset = 0; |
| 333 size_t nacl_nread; | 398 size_t nacl_nread; |
| 334 CHECK_REAL(getdents); | 399 CHECK_REAL(getdents); |
| 335 int err = REAL(getdents)(fd, (dirent*)nacl_buf, count, &nacl_nread); | 400 int err = REAL(getdents)(fd, (dirent*)nacl_buf, count, &nacl_nread); |
| 336 if (err) | 401 if (err) |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 347 memcpy(d->d_name, nacl_d->nacl_abi_d_name, d_name_len); | 412 memcpy(d->d_name, nacl_d->nacl_abi_d_name, d_name_len); |
| 348 | 413 |
| 349 offset += d->d_reclen; | 414 offset += d->d_reclen; |
| 350 offset += nacl_d->nacl_abi_d_reclen; | 415 offset += nacl_d->nacl_abi_d_reclen; |
| 351 } | 416 } |
| 352 | 417 |
| 353 *nread = offset; | 418 *nread = offset; |
| 354 return 0; | 419 return 0; |
| 355 } | 420 } |
| 356 | 421 |
| 357 int _real_lseek(int fd, off_t offset, int whence, off_t* new_offset) { | 422 int _real_isatty(int fd, int* result) { |
| 423 *result = isatty(fd); | |
| 424 return *result ? 0 : -1; | |
| 425 } | |
| 426 | |
| 427 int _real_lseek(int fd, int64_t offset, int whence, int64_t* new_offset) { | |
| 358 CHECK_REAL(seek); | 428 CHECK_REAL(seek); |
| 359 return REAL(seek)(fd, offset, whence, new_offset); | 429 nacl_abi_off_t nacl_new_offs; |
| 430 int ret = REAL(seek)(fd, offset, whence, &nacl_new_offs); | |
| 431 *new_offset = static_cast<off_t>(nacl_new_offs); | |
| 432 return ret; | |
| 360 } | 433 } |
| 361 | 434 |
| 435 int _real_lstat(const char* path, struct stat* buf) { | |
| 436 struct nacl_abi_stat st; | |
| 437 CHECK_REAL(fstat); | |
| 438 | |
| 439 int err = REAL(lstat)(path, (struct stat*) &st); | |
|
binji
2014/04/02 18:35:53
This C-style cast makes me nervous... why are you
noelallen1
2014/04/03 17:58:52
Because the IRT.H unfortunately uses struct stat w
| |
| 440 if (err) { | |
| 441 errno = err; | |
| 442 return -1; | |
| 443 } | |
| 444 | |
| 445 nacl_stat_to_stat(&st, buf); | |
| 446 return 0; | |
| 447 } | |
| 448 | |
| 449 | |
| 362 int _real_mkdir(const char* pathname, mode_t mode) { | 450 int _real_mkdir(const char* pathname, mode_t mode) { |
| 363 CHECK_REAL(mkdir); | 451 CHECK_REAL(mkdir); |
| 364 return REAL(mkdir)(pathname, mode); | 452 return REAL(mkdir)(pathname, mode); |
| 365 } | 453 } |
| 366 | 454 |
| 367 int _real_mmap(void** addr, size_t length, int prot, int flags, int fd, | 455 int _real_mmap(void** addr, size_t length, int prot, int flags, int fd, |
| 368 off_t offset) { | 456 int64_t offset) { |
| 369 CHECK_REAL(mmap); | 457 CHECK_REAL(mmap); |
| 370 return REAL(mmap)(addr, length, prot, flags, fd, offset); | 458 return REAL(mmap)(addr, length, prot, flags, fd, offset); |
| 371 } | 459 } |
| 372 | 460 |
| 373 int _real_munmap(void* addr, size_t length) { | 461 int _real_munmap(void* addr, size_t length) { |
| 374 CHECK_REAL(munmap); | 462 CHECK_REAL(munmap); |
| 375 return REAL(munmap)(addr, length); | 463 return REAL(munmap)(addr, length); |
| 376 } | 464 } |
| 377 | 465 |
| 378 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) { |
| 379 CHECK_REAL(open); | 467 CHECK_REAL(open); |
| 380 return REAL(open)(pathname, oflag, cmode, newfd); | 468 return REAL(open)(pathname, oflag, cmode, newfd); |
| 381 } | 469 } |
| 382 | 470 |
| 383 int _real_open_resource(const char* file, int* fd) { | 471 int _real_open_resource(const char* file, int* fd) { |
| 384 CHECK_REAL(open_resource); | 472 CHECK_REAL(open_resource); |
| 385 return REAL(open_resource)(file, fd); | 473 return REAL(open_resource)(file, fd); |
| 386 } | 474 } |
| 387 | 475 |
| 388 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) { |
| 389 CHECK_REAL(read); | 477 CHECK_REAL(read); |
| 390 return REAL(read)(fd, buf, count, nread); | 478 return REAL(read)(fd, buf, count, nread); |
| 391 } | 479 } |
| 392 | 480 |
| 481 int _real_readlink(const char *path, char* buf, size_t count, size_t* nread) { | |
| 482 CHECK_REAL(readlink); | |
| 483 return REAL(readlink)(path, buf, count, nread); | |
| 484 } | |
| 485 | |
| 393 int _real_rmdir(const char* pathname) { | 486 int _real_rmdir(const char* pathname) { |
| 394 CHECK_REAL(rmdir); | 487 CHECK_REAL(rmdir); |
| 395 return REAL(rmdir)(pathname); | 488 return REAL(rmdir)(pathname); |
| 396 } | 489 } |
| 397 | 490 |
| 491 int _real_truncate(const char* pathname, int64_t len) { | |
| 492 CHECK_REAL(truncate); | |
| 493 return REAL(truncate)(pathname, len); | |
| 494 } | |
| 495 | |
| 398 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) { |
| 399 CHECK_REAL(write); | 497 CHECK_REAL(write); |
| 400 return REAL(write)(fd, buf, count, nwrote); | 498 return REAL(write)(fd, buf, count, nwrote); |
| 401 } | 499 } |
| 402 | 500 |
| 403 static bool s_wrapped = false; | 501 static bool s_wrapped = false; |
| 404 void kernel_wrap_init() { | 502 void kernel_wrap_init() { |
| 405 if (!s_wrapped) { | 503 if (!s_wrapped) { |
| 406 assign_real_pointers(); | 504 assign_real_pointers(); |
| 407 EXPAND_SYMBOL_LIST_OPERATION(USE_WRAP) | 505 EXPAND_SYMBOL_LIST_OPERATION(USE_WRAP) |
| 408 s_wrapped = true; | 506 s_wrapped = true; |
| 409 } | 507 } |
| 410 } | 508 } |
| 411 | 509 |
| 412 void kernel_wrap_uninit() { | 510 void kernel_wrap_uninit() { |
| 413 if (s_wrapped) { | 511 if (s_wrapped) { |
| 414 EXPAND_SYMBOL_LIST_OPERATION(USE_REAL) | 512 EXPAND_SYMBOL_LIST_OPERATION(USE_REAL) |
| 415 s_wrapped = false; | 513 s_wrapped = false; |
| 416 } | 514 } |
| 417 } | 515 } |
| 418 | 516 |
| 419 EXTERN_C_END | 517 EXTERN_C_END |
| 420 | 518 |
| 421 #endif // defined(__native_client__) && defined(__GLIBC__) | 519 #endif // defined(__native_client__) && defined(__GLIBC__) |
| OLD | NEW |