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 __GLIBC__. |
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. |
9 #if defined(__native_client__) && defined(__GLIBC__) | 9 #if defined(__native_client__) && defined(__GLIBC__) |
10 | 10 |
11 #include "nacl_io/kernel_wrap.h" | 11 #include "nacl_io/kernel_wrap.h" |
12 #include <alloca.h> | 12 #include <alloca.h> |
13 #include <dirent.h> | 13 #include <dirent.h> |
14 #include <errno.h> | 14 #include <errno.h> |
15 #include <irt.h> | 15 #include <irt.h> |
16 #include <irt_syscalls.h> | 16 #include <irt_syscalls.h> |
17 #include <nacl_stat.h> | 17 #include <nacl_stat.h> |
18 #include <string.h> | 18 #include <string.h> |
19 #include <sys/mman.h> | 19 #include <sys/mman.h> |
20 #include <sys/stat.h> | 20 #include <sys/stat.h> |
| 21 #include <sys/time.h> |
21 #include "nacl_io/kernel_intercept.h" | 22 #include "nacl_io/kernel_intercept.h" |
22 | 23 |
23 | 24 |
24 namespace { | 25 namespace { |
25 | 26 |
26 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) { |
27 memset(nacl_buf, 0, sizeof(struct nacl_abi_stat)); | 28 memset(nacl_buf, 0, sizeof(struct nacl_abi_stat)); |
28 nacl_buf->nacl_abi_st_dev = buf->st_dev; | 29 nacl_buf->nacl_abi_st_dev = buf->st_dev; |
29 nacl_buf->nacl_abi_st_ino = buf->st_ino; | 30 nacl_buf->nacl_abi_st_ino = buf->st_ino; |
30 nacl_buf->nacl_abi_st_mode = buf->st_mode; | 31 nacl_buf->nacl_abi_st_mode = buf->st_mode; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 } | 131 } |
131 | 132 |
132 int chmod(const char* path, mode_t mode) NOTHROW { | 133 int chmod(const char* path, mode_t mode) NOTHROW { |
133 return ki_chmod(path, mode); | 134 return ki_chmod(path, mode); |
134 } | 135 } |
135 | 136 |
136 int WRAP(chdir) (const char* pathname) { | 137 int WRAP(chdir) (const char* pathname) { |
137 return (ki_chdir(pathname)) ? errno : 0; | 138 return (ki_chdir(pathname)) ? errno : 0; |
138 } | 139 } |
139 | 140 |
140 int chown(const char* path, uid_t owner, gid_t group) { | 141 int chown(const char* path, uid_t owner, gid_t group) NOTHROW { |
141 return ki_chown(path, owner, group); | 142 return ki_chown(path, owner, group); |
142 } | 143 } |
143 | 144 |
144 int WRAP(close)(int fd) { | 145 int WRAP(close)(int fd) { |
145 return (ki_close(fd) < 0) ? errno : 0; | 146 return (ki_close(fd) < 0) ? errno : 0; |
146 } | 147 } |
147 | 148 |
148 int WRAP(dup)(int fd, int* newfd) NOTHROW { | 149 int WRAP(dup)(int fd, int* newfd) NOTHROW { |
149 *newfd = ki_dup(fd); | 150 *newfd = ki_dup(fd); |
150 return (*newfd < 0) ? errno : 0; | 151 return (*newfd < 0) ? errno : 0; |
151 } | 152 } |
152 | 153 |
153 int WRAP(dup2)(int fd, int newfd) NOTHROW { | 154 int WRAP(dup2)(int fd, int newfd) NOTHROW { |
154 return (ki_dup2(fd, newfd) < 0) ? errno : 0; | 155 return (ki_dup2(fd, newfd) < 0) ? errno : 0; |
155 } | 156 } |
156 | 157 |
157 int fchown(int fd, uid_t owner, gid_t group) { | 158 int fchown(int fd, uid_t owner, gid_t group) NOTHROW { |
158 return ki_fchown(fd, owner, group); | 159 return ki_fchown(fd, owner, group); |
159 } | 160 } |
160 | 161 |
161 int WRAP(fstat)(int fd, struct nacl_abi_stat *nacl_buf) { | 162 int WRAP(fstat)(int fd, struct nacl_abi_stat *nacl_buf) { |
162 struct stat buf; | 163 struct stat buf; |
163 memset(&buf, 0, sizeof(struct stat)); | 164 memset(&buf, 0, sizeof(struct stat)); |
164 int res = ki_fstat(fd, &buf); | 165 int res = ki_fstat(fd, &buf); |
165 if (res < 0) | 166 if (res < 0) |
166 return errno; | 167 return errno; |
167 stat_to_nacl_stat(&buf, nacl_buf); | 168 stat_to_nacl_stat(&buf, nacl_buf); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 } | 224 } |
224 | 225 |
225 int ioctl(int d, int request, char* argp) NOTHROW { | 226 int ioctl(int d, int request, char* argp) NOTHROW { |
226 return ki_ioctl(d, request, argp); | 227 return ki_ioctl(d, request, argp); |
227 } | 228 } |
228 | 229 |
229 int isatty(int fd) NOTHROW { | 230 int isatty(int fd) NOTHROW { |
230 return ki_isatty(fd); | 231 return ki_isatty(fd); |
231 } | 232 } |
232 | 233 |
233 int lchown(const char* path, uid_t owner, gid_t group) { | 234 int lchown(const char* path, uid_t owner, gid_t group) NOTHROW { |
234 return ki_lchown(path, owner, group); | 235 return ki_lchown(path, owner, group); |
235 } | 236 } |
236 | 237 |
237 int link(const char* oldpath, const char* newpath) NOTHROW { | 238 int link(const char* oldpath, const char* newpath) NOTHROW { |
238 return ki_link(oldpath, newpath); | 239 return ki_link(oldpath, newpath); |
239 } | 240 } |
240 | 241 |
241 int mkdir(const char* path, mode_t mode) NOTHROW { | 242 int mkdir(const char* path, mode_t mode) NOTHROW { |
242 return ki_mkdir(path, mode); | 243 return ki_mkdir(path, mode); |
243 } | 244 } |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 } | 417 } |
417 | 418 |
418 int _real_rmdir(const char* pathname) { | 419 int _real_rmdir(const char* pathname) { |
419 return REAL(rmdir)(pathname); | 420 return REAL(rmdir)(pathname); |
420 } | 421 } |
421 | 422 |
422 int _real_write(int fd, const void *buf, size_t count, size_t *nwrote) { | 423 int _real_write(int fd, const void *buf, size_t count, size_t *nwrote) { |
423 return REAL(write)(fd, buf, count, nwrote); | 424 return REAL(write)(fd, buf, count, nwrote); |
424 } | 425 } |
425 | 426 |
| 427 uint64_t usec_since_epoch() { |
| 428 struct timeval tv; |
| 429 gettimeofday(&tv, NULL); |
| 430 return tv.tv_usec + (tv.tv_sec * 1000000); |
| 431 } |
426 | 432 |
427 void kernel_wrap_init() { | 433 void kernel_wrap_init() { |
428 static bool wrapped = false; | 434 static bool wrapped = false; |
429 | 435 |
430 if (!wrapped) { | 436 if (!wrapped) { |
431 wrapped = true; | 437 wrapped = true; |
432 DO_WRAP(chdir); | 438 DO_WRAP(chdir); |
433 DO_WRAP(close); | 439 DO_WRAP(close); |
434 DO_WRAP(dup); | 440 DO_WRAP(dup); |
435 DO_WRAP(dup2); | 441 DO_WRAP(dup2); |
(...skipping 11 matching lines...) Expand all Loading... |
447 DO_WRAP(munmap); | 453 DO_WRAP(munmap); |
448 DO_WRAP(open_resource); | 454 DO_WRAP(open_resource); |
449 } | 455 } |
450 } | 456 } |
451 | 457 |
452 EXTERN_C_END | 458 EXTERN_C_END |
453 | 459 |
454 | 460 |
455 #endif // defined(__native_client__) && defined(__GLIBC__) | 461 #endif // defined(__native_client__) && defined(__GLIBC__) |
456 | 462 |
OLD | NEW |