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