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 #ifndef LIBRARIES_NACL_IO_KERNEL_WRAP_H_ | 5 #ifndef LIBRARIES_NACL_IO_KERNEL_WRAP_H_ |
6 #define LIBRARIES_NACL_IO_KERNEL_WRAP_H_ | 6 #define LIBRARIES_NACL_IO_KERNEL_WRAP_H_ |
7 | 7 |
| 8 #include <assert.h> |
8 #include <signal.h> | 9 #include <signal.h> |
9 #include <stdint.h> | 10 #include <stdint.h> |
10 #include <stdlib.h> | 11 #include <stdlib.h> |
11 #include <sys/fcntl.h> | 12 #include <sys/fcntl.h> |
12 #include <sys/ioctl.h> | 13 #include <sys/ioctl.h> |
13 #include <sys/types.h> | 14 #include <sys/types.h> |
14 | 15 |
15 #include "nacl_io/ossocket.h" | 16 #include "nacl_io/ossocket.h" |
16 #include "nacl_io/ostypes.h" | 17 #include "nacl_io/ostypes.h" |
17 #include "nacl_io/osutime.h" | 18 #include "nacl_io/osutime.h" |
18 #include "sdk_util/macros.h" | 19 #include "sdk_util/macros.h" |
19 | 20 |
20 #if defined(__GLIBC__) | 21 #if defined(__GLIBC__) |
21 #include <sys/cdefs.h> | 22 #include <sys/cdefs.h> |
22 #define NOTHROW __THROW | 23 #define NOTHROW __THROW |
23 #else | 24 #else |
24 #define NOTHROW | 25 #define NOTHROW |
25 #endif | 26 #endif |
26 | 27 |
| 28 // Most kernel intercept functions (ki_*) return -1 and set the global errno. |
| 29 // However, the IRT wrappers are expected to return errno on failure. These |
| 30 // macros are used in the wrappers to check that the ki_ function actually |
| 31 // set errno and to its value. |
| 32 #define RTN_ERRNO_IF(cond) \ |
| 33 if (cond) { \ |
| 34 assert(errno != 0); \ |
| 35 return errno; \ |
| 36 } |
| 37 |
| 38 #define ERRNO_RTN(cond) \ |
| 39 RTN_ERRNO_IF(cond < 0); \ |
| 40 return 0; |
| 41 |
27 #if defined(WIN32) | 42 #if defined(WIN32) |
28 typedef int chmod_mode_t; | 43 typedef int chmod_mode_t; |
29 typedef int getcwd_size_t; | 44 typedef int getcwd_size_t; |
30 typedef int read_ssize_t; | 45 typedef int read_ssize_t; |
31 typedef int write_ssize_t; | 46 typedef int write_ssize_t; |
32 #define NAME(x) _##x | 47 #define NAME(x) _##x |
33 #else | 48 #else |
34 typedef mode_t chmod_mode_t; | 49 typedef mode_t chmod_mode_t; |
35 typedef size_t getcwd_size_t; | 50 typedef size_t getcwd_size_t; |
36 typedef ssize_t read_ssize_t; | 51 typedef ssize_t read_ssize_t; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 int setsockopt(int fd, int lvl, int optname, const void* optval, | 140 int setsockopt(int fd, int lvl, int optname, const void* optval, |
126 socklen_t len); | 141 socklen_t len); |
127 int shutdown(int fd, int how); | 142 int shutdown(int fd, int how); |
128 int socket(int domain, int type, int protocol); | 143 int socket(int domain, int type, int protocol); |
129 int socketpair(int domain, int type, int protocl, int* sv); | 144 int socketpair(int domain, int type, int protocl, int* sv); |
130 #endif // PROVIDES_SOCKET_API | 145 #endif // PROVIDES_SOCKET_API |
131 | 146 |
132 EXTERN_C_END | 147 EXTERN_C_END |
133 | 148 |
134 #endif // LIBRARIES_NACL_IO_KERNEL_WRAP_H_ | 149 #endif // LIBRARIES_NACL_IO_KERNEL_WRAP_H_ |
OLD | NEW |