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 |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 OP(sendmsg); \ | 150 OP(sendmsg); \ |
151 OP(sendto); \ | 151 OP(sendto); \ |
152 OP(recv); \ | 152 OP(recv); \ |
153 OP(recvmsg); \ | 153 OP(recvmsg); \ |
154 OP(recvfrom); \ | 154 OP(recvfrom); \ |
155 OP(getpeername); \ | 155 OP(getpeername); \ |
156 OP(getsockname); \ | 156 OP(getsockname); \ |
157 OP(getsockopt); \ | 157 OP(getsockopt); \ |
158 OP(setsockopt); \ | 158 OP(setsockopt); \ |
159 OP(socketpair); \ | 159 OP(socketpair); \ |
160 OP(shutdown); | 160 OP(shutdown); \ |
| 161 \ |
| 162 OP(access); \ |
| 163 OP(unlink); \ |
| 164 OP(fchdir); \ |
| 165 OP(fchmod); \ |
| 166 OP(fsync); \ |
| 167 OP(fdatasync); \ |
| 168 OP(lstat); \ |
| 169 OP(readlink); \ |
| 170 OP(utimes); |
161 | 171 |
162 // TODO(bradnelson): Add these as well. | 172 // TODO(bradnelson): Add these as well. |
163 // OP(epoll_create); | 173 // OP(epoll_create); |
164 // OP(epoll_create1); | 174 // OP(epoll_create1); |
165 // OP(epoll_ctl); | 175 // OP(epoll_ctl); |
166 // OP(epoll_pwait); | 176 // OP(epoll_pwait); |
167 // OP(ppoll); | 177 // OP(ppoll); |
168 // OP(pselect); | 178 // OP(pselect); |
169 // | |
170 | 179 |
171 EXPAND_SYMBOL_LIST_OPERATION(DECLARE_REAL_PTR); | 180 EXPAND_SYMBOL_LIST_OPERATION(DECLARE_REAL_PTR); |
172 | 181 |
173 int WRAP(chdir)(const char* pathname) { | 182 int WRAP(chdir)(const char* pathname) { |
174 RTN_ERRNO_IF(ki_chdir(pathname) < 0); | 183 ERRNO_RTN(ki_chdir(pathname)); |
175 return 0; | |
176 } | 184 } |
177 | 185 |
178 int WRAP(close)(int fd) { | 186 int WRAP(close)(int fd) { |
179 RTN_ERRNO_IF(ki_close(fd) < 0); | 187 ERRNO_RTN(ki_close(fd)); |
180 return 0; | |
181 } | 188 } |
182 | 189 |
183 int WRAP(dup)(int fd, int* newfd) NOTHROW { | 190 int WRAP(dup)(int fd, int* newfd) NOTHROW { |
184 *newfd = ki_dup(fd); | 191 *newfd = ki_dup(fd); |
185 RTN_ERRNO_IF(*newfd < 0); | 192 RTN_ERRNO_IF(*newfd < 0); |
186 return 0; | 193 return 0; |
187 } | 194 } |
188 | 195 |
189 int WRAP(dup2)(int fd, int newfd) NOTHROW { | 196 int WRAP(dup2)(int fd, int newfd) NOTHROW { |
190 RTN_ERRNO_IF(ki_dup2(fd, newfd) < 0); | 197 ERRNO_RTN(ki_dup2(fd, newfd)); |
191 return 0; | |
192 } | 198 } |
193 | 199 |
194 void WRAP(exit)(int status) { | 200 void WRAP(exit)(int status) { |
195 ki_exit(status); | 201 ki_exit(status); |
196 } | 202 } |
197 | 203 |
198 int WRAP(fstat)(int fd, struct nacl_abi_stat* nacl_buf) { | 204 int WRAP(fstat)(int fd, struct nacl_abi_stat* nacl_buf) { |
199 struct stat buf; | 205 struct stat buf; |
200 memset(&buf, 0, sizeof(struct stat)); | 206 memset(&buf, 0, sizeof(struct stat)); |
201 int res = ki_fstat(fd, &buf); | 207 int res = ki_fstat(fd, &buf); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 | 319 |
314 int WRAP(stat)(const char* pathname, struct nacl_abi_stat* nacl_buf) { | 320 int WRAP(stat)(const char* pathname, struct nacl_abi_stat* nacl_buf) { |
315 struct stat buf; | 321 struct stat buf; |
316 memset(&buf, 0, sizeof(struct stat)); | 322 memset(&buf, 0, sizeof(struct stat)); |
317 int res = ki_stat(pathname, &buf); | 323 int res = ki_stat(pathname, &buf); |
318 RTN_ERRNO_IF(res < 0); | 324 RTN_ERRNO_IF(res < 0); |
319 stat_to_nacl_stat(&buf, nacl_buf); | 325 stat_to_nacl_stat(&buf, nacl_buf); |
320 return 0; | 326 return 0; |
321 } | 327 } |
322 | 328 |
| 329 int WRAP(lstat)(const char* pathname, struct nacl_abi_stat* nacl_buf) { |
| 330 struct stat buf; |
| 331 memset(&buf, 0, sizeof(struct stat)); |
| 332 int res = ki_lstat(pathname, &buf); |
| 333 RTN_ERRNO_IF(res < 0); |
| 334 stat_to_nacl_stat(&buf, nacl_buf); |
| 335 return 0; |
| 336 } |
| 337 |
| 338 int WRAP(readlink)(const char* pathname, |
| 339 char* buf, |
| 340 size_t count, |
| 341 size_t* nread) { |
| 342 int rtn = ki_readlink(pathname, buf, count); |
| 343 RTN_ERRNO_IF(rtn < 0); |
| 344 *nread = rtn; |
| 345 return 0; |
| 346 } |
| 347 |
| 348 int WRAP(utimes)(const char *filename, const struct timeval *times) { |
| 349 ERRNO_RTN(ki_utimes(filename, times)); |
| 350 } |
| 351 |
| 352 int WRAP(access)(const char* pathname, int amode) { |
| 353 ERRNO_RTN(ki_access(pathname, amode)); |
| 354 } |
| 355 |
| 356 int WRAP(unlink)(const char* pathname) { |
| 357 ERRNO_RTN(ki_unlink(pathname)); |
| 358 } |
| 359 |
| 360 int WRAP(fchdir)(int fd) { |
| 361 ERRNO_RTN(ki_fchdir(fd)); |
| 362 } |
| 363 |
| 364 int WRAP(fchmod)(int fd, mode_t mode) { |
| 365 ERRNO_RTN(ki_fchmod(fd, mode)); |
| 366 } |
| 367 |
| 368 int WRAP(fsync)(int fd) { |
| 369 ERRNO_RTN(ki_fsync(fd)); |
| 370 } |
| 371 |
| 372 int WRAP(fdatasync)(int fd) { |
| 373 ERRNO_RTN(ki_fdatasync(fd)); |
| 374 } |
| 375 |
323 int WRAP(write)(int fd, const void* buf, size_t count, size_t* nwrote) { | 376 int WRAP(write)(int fd, const void* buf, size_t count, size_t* nwrote) { |
324 ssize_t signed_nwrote = ki_write(fd, buf, count); | 377 ssize_t signed_nwrote = ki_write(fd, buf, count); |
325 *nwrote = static_cast<size_t>(signed_nwrote); | 378 *nwrote = static_cast<size_t>(signed_nwrote); |
326 RTN_ERRNO_IF(signed_nwrote < 0); | 379 RTN_ERRNO_IF(signed_nwrote < 0); |
327 return 0; | 380 return 0; |
328 } | 381 } |
329 | 382 |
330 int WRAP(accept)(int sockfd, | 383 int WRAP(accept)(int sockfd, |
331 struct sockaddr* addr, | 384 struct sockaddr* addr, |
332 socklen_t* addrlen, | 385 socklen_t* addrlen, |
333 int* sd) { | 386 int* sd) { |
334 *sd = ki_accept(sockfd, addr, addrlen); | 387 *sd = ki_accept(sockfd, addr, addrlen); |
335 RTN_ERRNO_IF(*sd < 0); | 388 RTN_ERRNO_IF(*sd < 0); |
336 return 0; | 389 return 0; |
337 } | 390 } |
338 | 391 |
339 int WRAP(bind)(int sockfd, const struct sockaddr* addr, socklen_t addrlen) { | 392 int WRAP(bind)(int sockfd, const struct sockaddr* addr, socklen_t addrlen) { |
340 RTN_ERRNO_IF(ki_bind(sockfd, addr, addrlen) < 0); | 393 ERRNO_RTN(ki_bind(sockfd, addr, addrlen)); |
341 return 0; | |
342 } | 394 } |
343 | 395 |
344 int WRAP(connect)(int sockfd, const struct sockaddr* addr, socklen_t addrlen) { | 396 int WRAP(connect)(int sockfd, const struct sockaddr* addr, socklen_t addrlen) { |
345 RTN_ERRNO_IF(ki_connect(sockfd, addr, addrlen) < 0); | 397 ERRNO_RTN(ki_connect(sockfd, addr, addrlen)); |
346 return 0; | |
347 } | 398 } |
348 | 399 |
349 int WRAP(getpeername)(int sockfd, struct sockaddr* addr, socklen_t* addrlen) { | 400 int WRAP(getpeername)(int sockfd, struct sockaddr* addr, socklen_t* addrlen) { |
350 RTN_ERRNO_IF(ki_getpeername(sockfd, addr, addrlen) < 0); | 401 ERRNO_RTN(ki_getpeername(sockfd, addr, addrlen)); |
351 return 0; | |
352 } | 402 } |
353 | 403 |
354 int WRAP(getsockname)(int sockfd, struct sockaddr* addr, socklen_t* addrlen) { | 404 int WRAP(getsockname)(int sockfd, struct sockaddr* addr, socklen_t* addrlen) { |
355 RTN_ERRNO_IF(ki_getsockname(sockfd, addr, addrlen) < 0); | 405 ERRNO_RTN(ki_getsockname(sockfd, addr, addrlen)); |
356 return 0; | |
357 } | 406 } |
358 | 407 |
359 int WRAP(getsockopt)(int sockfd, | 408 int WRAP(getsockopt)(int sockfd, |
360 int level, | 409 int level, |
361 int optname, | 410 int optname, |
362 void* optval, | 411 void* optval, |
363 socklen_t* optlen) { | 412 socklen_t* optlen) { |
364 RTN_ERRNO_IF(ki_getsockopt(sockfd, level, optname, optval, optlen) < 0); | 413 ERRNO_RTN(ki_getsockopt(sockfd, level, optname, optval, optlen)); |
365 return 0; | |
366 } | 414 } |
367 | 415 |
368 int WRAP(setsockopt)(int sockfd, | 416 int WRAP(setsockopt)(int sockfd, |
369 int level, | 417 int level, |
370 int optname, | 418 int optname, |
371 const void* optval, | 419 const void* optval, |
372 socklen_t optlen) { | 420 socklen_t optlen) { |
373 RTN_ERRNO_IF(ki_setsockopt(sockfd, level, optname, optval, optlen) < 0); | 421 ERRNO_RTN(ki_setsockopt(sockfd, level, optname, optval, optlen)); |
374 return 0; | |
375 } | 422 } |
376 | 423 |
377 int WRAP(listen)(int sockfd, int backlog) { | 424 int WRAP(listen)(int sockfd, int backlog) { |
378 RTN_ERRNO_IF(ki_listen(sockfd, backlog) < 0); | 425 ERRNO_RTN(ki_listen(sockfd, backlog)); |
379 return 0; | |
380 } | 426 } |
381 | 427 |
382 int WRAP(recv)(int sockfd, void* buf, size_t len, int flags, int* count) { | 428 int WRAP(recv)(int sockfd, void* buf, size_t len, int flags, int* count) { |
383 ssize_t signed_nread = ki_recv(sockfd, buf, len, flags); | 429 ssize_t signed_nread = ki_recv(sockfd, buf, len, flags); |
384 *count = static_cast<int>(signed_nread); | 430 *count = static_cast<int>(signed_nread); |
385 RTN_ERRNO_IF(signed_nread < 0); | 431 RTN_ERRNO_IF(signed_nread < 0); |
386 return 0; | 432 return 0; |
387 } | 433 } |
388 | 434 |
389 int WRAP(recvfrom)(int sockfd, | 435 int WRAP(recvfrom)(int sockfd, |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 if (s_wrapped) { | 630 if (s_wrapped) { |
585 LOG_TRACE("kernel_wrap_uninit"); | 631 LOG_TRACE("kernel_wrap_uninit"); |
586 EXPAND_SYMBOL_LIST_OPERATION(USE_REAL) | 632 EXPAND_SYMBOL_LIST_OPERATION(USE_REAL) |
587 s_wrapped = false; | 633 s_wrapped = false; |
588 } | 634 } |
589 } | 635 } |
590 | 636 |
591 EXTERN_C_END | 637 EXTERN_C_END |
592 | 638 |
593 #endif // defined(__native_client__) && defined(__GLIBC__) | 639 #endif // defined(__native_client__) && defined(__GLIBC__) |
OLD | NEW |