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-newlib build. | 8 // compiled, even on a non-newlib build. |
9 #if defined(__native_client__) && !defined(__GLIBC__) | 9 #if defined(__native_client__) && !defined(__GLIBC__) |
10 | 10 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 ssize_t signed_nread = ki_read(fd, buf, count); | 111 ssize_t signed_nread = ki_read(fd, buf, count); |
112 *nread = static_cast<size_t>(signed_nread); | 112 *nread = static_cast<size_t>(signed_nread); |
113 return (signed_nread < 0) ? errno : 0; | 113 return (signed_nread < 0) ? errno : 0; |
114 } | 114 } |
115 | 115 |
116 int WRAP(seek)(int fd, off_t offset, int whence, off_t* new_offset) { | 116 int WRAP(seek)(int fd, off_t offset, int whence, off_t* new_offset) { |
117 *new_offset = ki_lseek(fd, offset, whence); | 117 *new_offset = ki_lseek(fd, offset, whence); |
118 return (*new_offset < 0) ? errno : 0; | 118 return (*new_offset < 0) ? errno : 0; |
119 } | 119 } |
120 | 120 |
121 int WRAP(stat)(const char *pathname, struct stat *buf) { | 121 int WRAP(stat)(const char* pathname, struct stat* buf) { |
122 return (ki_stat(pathname, buf) < 0) ? errno : 0; | 122 return (ki_stat(pathname, buf) < 0) ? errno : 0; |
123 } | 123 } |
124 | 124 |
125 int WRAP(write)(int fd, const void *buf, size_t count, size_t *nwrote) { | 125 int WRAP(write)(int fd, const void* buf, size_t count, size_t* nwrote) { |
126 if (!ki_is_initialized()) | 126 if (!ki_is_initialized()) |
127 return REAL(write)(fd, buf, count, nwrote); | 127 return REAL(write)(fd, buf, count, nwrote); |
128 | 128 |
129 ssize_t signed_nwrote = ki_write(fd, buf, count); | 129 ssize_t signed_nwrote = ki_write(fd, buf, count); |
130 *nwrote = static_cast<size_t>(signed_nwrote); | 130 *nwrote = static_cast<size_t>(signed_nwrote); |
131 return (signed_nwrote < 0) ? errno : 0; | 131 return (signed_nwrote < 0) ? errno : 0; |
132 } | 132 } |
133 | 133 |
| 134 // Socket functions |
| 135 int accept(int fd, struct sockaddr* addr, socklen_t* len) { |
| 136 return ki_accept(fd, addr, len); |
| 137 } |
| 138 |
| 139 int bind(int fd, const struct sockaddr* addr, socklen_t len) { |
| 140 return ki_bind(fd, addr, len); |
| 141 } |
| 142 |
| 143 int connect(int fd, const struct sockaddr* addr, socklen_t len) { |
| 144 return ki_connect(fd, addr, len); |
| 145 } |
| 146 |
| 147 int getpeername(int fd, struct sockaddr* addr, socklen_t* len) { |
| 148 return ki_getpeername(fd, addr, len); |
| 149 } |
| 150 |
| 151 int getsockname(int fd, struct sockaddr* addr, socklen_t* len) { |
| 152 return ki_getsockname(fd, addr, len); |
| 153 } |
| 154 int getsockopt(int fd, int lvl, int optname, void* optval, socklen_t* len) { |
| 155 return ki_getsockopt(fd, lvl, optname, optval, len); |
| 156 } |
| 157 |
| 158 int listen(int fd, int backlog) { |
| 159 return ki_listen(fd, backlog); |
| 160 } |
| 161 |
| 162 ssize_t recv(int fd, void* buf, size_t len, int flags) { |
| 163 return ki_recv(fd, buf, len, flags); |
| 164 } |
| 165 |
| 166 ssize_t recvfrom(int fd, void* buf, size_t len, int flags, |
| 167 struct sockaddr* addr, socklen_t* addrlen) { |
| 168 return ki_recvfrom(fd, buf, len, flags, addr, addrlen); |
| 169 } |
| 170 |
| 171 ssize_t recvmsg(int fd, struct msghdr* msg, int flags) { |
| 172 return ki_recvmsg(fd, msg, flags); |
| 173 } |
| 174 |
| 175 ssize_t send(int fd, const void* buf, size_t len, int flags) { |
| 176 return ki_send(fd, buf, len, flags); |
| 177 } |
| 178 |
| 179 ssize_t sendto(int fd, const void* buf, size_t len, int flags, |
| 180 const struct sockaddr* addr, socklen_t addrlen) { |
| 181 return ki_sendto(fd, buf, len, flags, addr, addrlen); |
| 182 } |
| 183 |
| 184 ssize_t sendmsg(int fd, const struct msghdr* msg, int flags) { |
| 185 return ki_sendmsg(fd, msg, flags); |
| 186 } |
| 187 |
| 188 int setsockopt(int fd, int lvl, int optname, const void* optval, |
| 189 socklen_t len) { |
| 190 return ki_setsockopt(fd, lvl, optname, optval, len); |
| 191 } |
| 192 |
| 193 int shutdown(int fd, int how) { |
| 194 return ki_shutdown(fd, how); |
| 195 } |
| 196 |
| 197 int socket(int domain, int type, int protocol) { |
| 198 return ki_socket(domain, type, protocol); |
| 199 } |
| 200 |
| 201 int socketpair(int domain, int type, int protocol, int* sv) { |
| 202 return ki_socketpair(domain, type, protocol, sv); |
| 203 } |
134 | 204 |
135 // "real" functions, i.e. the unwrapped original functions. | 205 // "real" functions, i.e. the unwrapped original functions. |
136 | 206 |
137 int _real_close(int fd) { | 207 int _real_close(int fd) { |
138 return REAL(close)(fd); | 208 return REAL(close)(fd); |
139 } | 209 } |
140 | 210 |
141 int _real_fstat(int fd, struct stat *buf) { | 211 int _real_fstat(int fd, struct stat* buf) { |
142 return REAL(fstat)(fd, buf); | 212 return REAL(fstat)(fd, buf); |
143 } | 213 } |
144 | 214 |
145 int _real_getdents(int fd, dirent* nacl_buf, size_t nacl_count, size_t *nread) { | 215 int _real_getdents(int fd, dirent* nacl_buf, size_t nacl_count, size_t* nread) { |
146 return REAL(getdents)(fd, nacl_buf, nacl_count, nread); | 216 return REAL(getdents)(fd, nacl_buf, nacl_count, nread); |
147 } | 217 } |
148 | 218 |
149 int _real_lseek(int fd, off_t offset, int whence, off_t* new_offset) { | 219 int _real_lseek(int fd, off_t offset, int whence, off_t* new_offset) { |
150 return REAL(seek)(fd, offset, whence, new_offset); | 220 return REAL(seek)(fd, offset, whence, new_offset); |
151 } | 221 } |
152 | 222 |
153 int _real_mkdir(const char* pathname, mode_t mode) { | 223 int _real_mkdir(const char* pathname, mode_t mode) { |
154 return ENOSYS; | 224 return ENOSYS; |
155 } | 225 } |
156 | 226 |
157 int _real_mmap(void** addr, size_t length, int prot, int flags, int fd, | 227 int _real_mmap(void** addr, size_t length, int prot, int flags, int fd, |
158 off_t offset) { | 228 off_t offset) { |
159 return REAL(mmap)(addr, length, prot, flags, fd, offset); | 229 return REAL(mmap)(addr, length, prot, flags, fd, offset); |
160 } | 230 } |
161 | 231 |
162 int _real_munmap(void* addr, size_t length) { | 232 int _real_munmap(void* addr, size_t length) { |
163 return REAL(munmap)(addr, length); | 233 return REAL(munmap)(addr, length); |
164 } | 234 } |
165 | 235 |
166 int _real_open(const char* pathname, int oflag, mode_t cmode, int* newfd) { | 236 int _real_open(const char* pathname, int oflag, mode_t cmode, int* newfd) { |
167 return REAL(open)(pathname, oflag, cmode, newfd); | 237 return REAL(open)(pathname, oflag, cmode, newfd); |
168 } | 238 } |
169 | 239 |
170 int _real_open_resource(const char* file, int* fd) { | 240 int _real_open_resource(const char* file, int* fd) { |
171 return ENOSYS; | 241 return ENOSYS; |
172 } | 242 } |
173 | 243 |
174 int _real_read(int fd, void *buf, size_t count, size_t *nread) { | 244 int _real_read(int fd, void* buf, size_t count, size_t* nread) { |
175 return REAL(read)(fd, buf, count, nread); | 245 return REAL(read)(fd, buf, count, nread); |
176 } | 246 } |
177 | 247 |
178 int _real_rmdir(const char* pathname) { | 248 int _real_rmdir(const char* pathname) { |
179 return ENOSYS; | 249 return ENOSYS; |
180 } | 250 } |
181 | 251 |
182 int _real_write(int fd, const void *buf, size_t count, size_t *nwrote) { | 252 int _real_write(int fd, const void* buf, size_t count, size_t* nwrote) { |
183 return REAL(write)(fd, buf, count, nwrote); | 253 return REAL(write)(fd, buf, count, nwrote); |
184 } | 254 } |
185 | 255 |
186 uint64_t usec_since_epoch() { | 256 uint64_t usec_since_epoch() { |
187 struct timeval tv; | 257 struct timeval tv; |
188 gettimeofday(&tv, NULL); | 258 gettimeofday(&tv, NULL); |
189 return tv.tv_usec + (tv.tv_sec * 1000000); | 259 return tv.tv_usec + (tv.tv_sec * 1000000); |
190 } | 260 } |
191 | 261 |
192 static bool s_wrapped = false; | 262 static bool s_wrapped = false; |
193 void kernel_wrap_init() { | 263 void kernel_wrap_init() { |
194 if (!s_wrapped) { | 264 if (!s_wrapped) { |
195 EXPAND_SYMBOL_LIST_OPERATION(USE_WRAP); | 265 EXPAND_SYMBOL_LIST_OPERATION(USE_WRAP); |
196 s_wrapped = true; | 266 s_wrapped = true; |
197 } | 267 } |
198 } | 268 } |
199 | 269 |
200 void kernel_wrap_uninit() { | 270 void kernel_wrap_uninit() { |
201 if (s_wrapped) { | 271 if (s_wrapped) { |
202 EXPAND_SYMBOL_LIST_OPERATION(USE_REAL); | 272 EXPAND_SYMBOL_LIST_OPERATION(USE_REAL); |
203 s_wrapped = false; | 273 s_wrapped = false; |
204 } | 274 } |
205 } | 275 } |
206 | 276 |
207 EXTERN_C_END | 277 EXTERN_C_END |
208 | 278 |
209 | 279 |
210 #endif // defined(__native_client__) && !defined(__GLIBC__) | 280 #endif // defined(__native_client__) && !defined(__GLIBC__) |
211 | 281 |
OLD | NEW |