Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: native_client_sdk/src/libraries/nacl_io/kernel_wrap_glibc.cc

Issue 303223007: [NaCl SDK] nacl_io: Run clang-format over nacl_io sources. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 12
13 #include <alloca.h> 13 #include <alloca.h>
14 #include <assert.h> 14 #include <assert.h>
15 #include <dirent.h> 15 #include <dirent.h>
16 #include <errno.h> 16 #include <errno.h>
17 #include <irt.h> 17 #include <irt.h>
18 #include <irt_syscalls.h> 18 #include <irt_syscalls.h>
19 #include <nacl_stat.h> 19 #include <nacl_stat.h>
20 #include <string.h> 20 #include <string.h>
21 #include <sys/stat.h> 21 #include <sys/stat.h>
22 #include <sys/time.h> 22 #include <sys/time.h>
23 23
24 #include "nacl_io/kernel_intercept.h" 24 #include "nacl_io/kernel_intercept.h"
25 #include "nacl_io/kernel_wrap_real.h" 25 #include "nacl_io/kernel_wrap_real.h"
26 #include "nacl_io/log.h" 26 #include "nacl_io/log.h"
27 #include "nacl_io/osmman.h" 27 #include "nacl_io/osmman.h"
28 28
29
30 namespace { 29 namespace {
31 30
32 void stat_to_nacl_stat(const struct stat* buf, nacl_abi_stat* nacl_buf) { 31 void stat_to_nacl_stat(const struct stat* buf, nacl_abi_stat* nacl_buf) {
33 memset(nacl_buf, 0, sizeof(struct nacl_abi_stat)); 32 memset(nacl_buf, 0, sizeof(struct nacl_abi_stat));
34 nacl_buf->nacl_abi_st_dev = buf->st_dev; 33 nacl_buf->nacl_abi_st_dev = buf->st_dev;
35 nacl_buf->nacl_abi_st_ino = buf->st_ino; 34 nacl_buf->nacl_abi_st_ino = buf->st_ino;
36 nacl_buf->nacl_abi_st_mode = buf->st_mode; 35 nacl_buf->nacl_abi_st_mode = buf->st_mode;
37 nacl_buf->nacl_abi_st_nlink = buf->st_nlink; 36 nacl_buf->nacl_abi_st_nlink = buf->st_nlink;
38 nacl_buf->nacl_abi_st_uid = buf->st_uid; 37 nacl_buf->nacl_abi_st_uid = buf->st_uid;
39 nacl_buf->nacl_abi_st_gid = buf->st_gid; 38 nacl_buf->nacl_abi_st_gid = buf->st_gid;
40 nacl_buf->nacl_abi_st_rdev = buf->st_rdev; 39 nacl_buf->nacl_abi_st_rdev = buf->st_rdev;
41 nacl_buf->nacl_abi_st_size = buf->st_size; 40 nacl_buf->nacl_abi_st_size = buf->st_size;
42 nacl_buf->nacl_abi_st_blksize = buf->st_blksize; 41 nacl_buf->nacl_abi_st_blksize = buf->st_blksize;
43 nacl_buf->nacl_abi_st_blocks = buf->st_blocks; 42 nacl_buf->nacl_abi_st_blocks = buf->st_blocks;
44 nacl_buf->nacl_abi_st_atime = buf->st_atime; 43 nacl_buf->nacl_abi_st_atime = buf->st_atime;
45 nacl_buf->nacl_abi_st_mtime = buf->st_mtime; 44 nacl_buf->nacl_abi_st_mtime = buf->st_mtime;
46 nacl_buf->nacl_abi_st_ctime = buf->st_ctime; 45 nacl_buf->nacl_abi_st_ctime = buf->st_ctime;
47 } 46 }
48 47
49 void nacl_stat_to_stat(const nacl_abi_stat* nacl_buf, struct stat* buf) { 48 void nacl_stat_to_stat(const nacl_abi_stat* nacl_buf, struct stat* buf) {
50 memset(buf, 0, sizeof(struct stat)); 49 memset(buf, 0, sizeof(struct stat));
51 buf->st_dev = nacl_buf->nacl_abi_st_dev; 50 buf->st_dev = nacl_buf->nacl_abi_st_dev;
52 buf->st_ino = nacl_buf->nacl_abi_st_ino; 51 buf->st_ino = nacl_buf->nacl_abi_st_ino;
53 buf->st_mode = nacl_buf->nacl_abi_st_mode; 52 buf->st_mode = nacl_buf->nacl_abi_st_mode;
54 buf->st_nlink = nacl_buf->nacl_abi_st_nlink; 53 buf->st_nlink = nacl_buf->nacl_abi_st_nlink;
55 buf->st_uid = nacl_buf->nacl_abi_st_uid; 54 buf->st_uid = nacl_buf->nacl_abi_st_uid;
56 buf->st_gid = nacl_buf->nacl_abi_st_gid; 55 buf->st_gid = nacl_buf->nacl_abi_st_gid;
57 buf->st_rdev = nacl_buf->nacl_abi_st_rdev; 56 buf->st_rdev = nacl_buf->nacl_abi_st_rdev;
58 buf->st_size = nacl_buf->nacl_abi_st_size ; 57 buf->st_size = nacl_buf->nacl_abi_st_size;
59 buf->st_blksize = nacl_buf->nacl_abi_st_blksize; 58 buf->st_blksize = nacl_buf->nacl_abi_st_blksize;
60 buf->st_blocks = nacl_buf->nacl_abi_st_blocks; 59 buf->st_blocks = nacl_buf->nacl_abi_st_blocks;
61 buf->st_atime = nacl_buf->nacl_abi_st_atime; 60 buf->st_atime = nacl_buf->nacl_abi_st_atime;
62 buf->st_mtime = nacl_buf->nacl_abi_st_mtime; 61 buf->st_mtime = nacl_buf->nacl_abi_st_mtime;
63 buf->st_ctime = nacl_buf->nacl_abi_st_ctime; 62 buf->st_ctime = nacl_buf->nacl_abi_st_ctime;
64 } 63 }
65 64
66 } // namespace 65 } // namespace
67 66
68 // From native_client/src/trusted/service_runtime/include/sys/dirent.h 67 // From native_client/src/trusted/service_runtime/include/sys/dirent.h
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 99
101 EXTERN_C_BEGIN 100 EXTERN_C_BEGIN
102 101
103 // Macro to get the REAL function pointer 102 // Macro to get the REAL function pointer
104 #define REAL(name) __nacl_irt_##name##_real 103 #define REAL(name) __nacl_irt_##name##_real
105 104
106 // Macro to get the WRAP function 105 // Macro to get the WRAP function
107 #define WRAP(name) __nacl_irt_##name##_wrap 106 #define WRAP(name) __nacl_irt_##name##_wrap
108 107
109 // Declare REAL function pointer. 108 // Declare REAL function pointer.
110 #define DECLARE_REAL_PTR(name) \ 109 #define DECLARE_REAL_PTR(name) typeof(__nacl_irt_##name) REAL(name);
111 typeof(__nacl_irt_##name) REAL(name);
112 110
113 // Assign the REAL function pointer. 111 // Assign the REAL function pointer.
114 #define ASSIGN_REAL_PTR(name) \ 112 #define ASSIGN_REAL_PTR(name) \
115 assert(__nacl_irt_##name != NULL); \ 113 assert(__nacl_irt_##name != NULL); \
116 REAL(name) = __nacl_irt_##name; 114 REAL(name) = __nacl_irt_##name;
117 115
118 // Switch IRT's pointer to the REAL pointer 116 // Switch IRT's pointer to the REAL pointer
119 #define USE_REAL(name) \ 117 #define USE_REAL(name) __nacl_irt_##name = (typeof(__nacl_irt_##name))REAL(name)
120 __nacl_irt_##name = (typeof(__nacl_irt_##name)) REAL(name)
121 118
122 // Switch IRT's pointer to the WRAP function 119 // Switch IRT's pointer to the WRAP function
123 #define USE_WRAP(name) \ 120 #define USE_WRAP(name) __nacl_irt_##name = (typeof(__nacl_irt_##name))WRAP(name)
124 __nacl_irt_##name = (typeof(__nacl_irt_##name)) WRAP(name)
125 121
126 #define EXPAND_SYMBOL_LIST_OPERATION(OP) \ 122 #define EXPAND_SYMBOL_LIST_OPERATION(OP) \
127 OP(chdir); \ 123 OP(chdir); \
128 OP(close); \ 124 OP(close); \
129 OP(dup); \ 125 OP(dup); \
130 OP(dup2); \ 126 OP(dup2); \
131 OP(exit); \ 127 OP(exit); \
132 OP(fstat); \ 128 OP(fstat); \
133 OP(getcwd); \ 129 OP(getcwd); \
134 OP(getdents); \ 130 OP(getdents); \
135 OP(mkdir); \ 131 OP(mkdir); \
136 OP(open); \ 132 OP(open); \
137 OP(poll);\ 133 OP(poll); \
138 OP(read); \ 134 OP(read); \
139 OP(rmdir); \ 135 OP(rmdir); \
140 OP(seek); \ 136 OP(seek); \
141 OP(stat); \ 137 OP(stat); \
142 OP(select); \ 138 OP(select); \
143 OP(write); \ 139 OP(write); \
144 OP(mmap); \ 140 OP(mmap); \
145 OP(munmap); \ 141 OP(munmap); \
146 OP(open_resource); \ 142 OP(open_resource); \
147 \ 143 \
148 OP(socket); \ 144 OP(socket); \
149 OP(accept); \ 145 OP(accept); \
150 OP(bind); \ 146 OP(bind); \
151 OP(listen); \ 147 OP(listen); \
152 OP(connect); \ 148 OP(connect); \
153 OP(send); \ 149 OP(send); \
154 OP(sendmsg); \ 150 OP(sendmsg); \
155 OP(sendto); \ 151 OP(sendto); \
156 OP(recv); \ 152 OP(recv); \
157 OP(recvmsg); \ 153 OP(recvmsg); \
158 OP(recvfrom); \ 154 OP(recvfrom); \
159 OP(getpeername); \ 155 OP(getpeername); \
160 OP(getsockname); \ 156 OP(getsockname); \
161 OP(getsockopt); \ 157 OP(getsockopt); \
162 OP(setsockopt); \ 158 OP(setsockopt); \
163 OP(socketpair); \ 159 OP(socketpair); \
164 OP(shutdown); 160 OP(shutdown);
165 161
166 // TODO(bradnelson): Add these as well. 162 // TODO(bradnelson): Add these as well.
167 // OP(epoll_create); 163 // OP(epoll_create);
168 // OP(epoll_create1); 164 // OP(epoll_create1);
169 // OP(epoll_ctl); 165 // OP(epoll_ctl);
170 // OP(epoll_pwait); 166 // OP(epoll_pwait);
171 // OP(ppoll); 167 // OP(ppoll);
172 // OP(pselect); 168 // OP(pselect);
173 // 169 //
(...skipping 18 matching lines...) Expand all
192 188
193 int WRAP(dup2)(int fd, int newfd) NOTHROW { 189 int WRAP(dup2)(int fd, int newfd) NOTHROW {
194 RTN_ERRNO_IF(ki_dup2(fd, newfd) < 0); 190 RTN_ERRNO_IF(ki_dup2(fd, newfd) < 0);
195 return 0; 191 return 0;
196 } 192 }
197 193
198 void WRAP(exit)(int status) { 194 void WRAP(exit)(int status) {
199 ki_exit(status); 195 ki_exit(status);
200 } 196 }
201 197
202 int WRAP(fstat)(int fd, struct nacl_abi_stat *nacl_buf) { 198 int WRAP(fstat)(int fd, struct nacl_abi_stat* nacl_buf) {
203 struct stat buf; 199 struct stat buf;
204 memset(&buf, 0, sizeof(struct stat)); 200 memset(&buf, 0, sizeof(struct stat));
205 int res = ki_fstat(fd, &buf); 201 int res = ki_fstat(fd, &buf);
206 RTN_ERRNO_IF(res < 0); 202 RTN_ERRNO_IF(res < 0);
207 stat_to_nacl_stat(&buf, nacl_buf); 203 stat_to_nacl_stat(&buf, nacl_buf);
208 return 0; 204 return 0;
209 } 205 }
210 206
211 int WRAP(getcwd)(char* buf, size_t size) { 207 int WRAP(getcwd)(char* buf, size_t size) {
212 RTN_ERRNO_IF(ki_getcwd(buf, size) == NULL); 208 RTN_ERRNO_IF(ki_getcwd(buf, size) == NULL);
213 return 0; 209 return 0;
214 } 210 }
215 211
216 int WRAP(getdents)(int fd, dirent* nacl_buf, size_t nacl_count, size_t *nread) { 212 int WRAP(getdents)(int fd, dirent* nacl_buf, size_t nacl_count, size_t* nread) {
217 int nacl_offset = 0; 213 int nacl_offset = 0;
218 // "buf" contains dirent(s); "nacl_buf" contains nacl_abi_dirent(s). 214 // "buf" contains dirent(s); "nacl_buf" contains nacl_abi_dirent(s).
219 // nacl_abi_dirent(s) are smaller than dirent(s), so nacl_count bytes buffer 215 // nacl_abi_dirent(s) are smaller than dirent(s), so nacl_count bytes buffer
220 // is enough 216 // is enough
221 char* buf = (char*)alloca(nacl_count); 217 char* buf = (char*)alloca(nacl_count);
222 int offset = 0; 218 int offset = 0;
223 int count; 219 int count;
224 220
225 count = ki_getdents(fd, buf, nacl_count); 221 count = ki_getdents(fd, buf, nacl_count);
226 RTN_ERRNO_IF(count < 0); 222 RTN_ERRNO_IF(count < 0);
(...skipping 13 matching lines...) Expand all
240 236
241 *nread = nacl_offset; 237 *nread = nacl_offset;
242 return 0; 238 return 0;
243 } 239 }
244 240
245 int WRAP(mkdir)(const char* pathname, mode_t mode) { 241 int WRAP(mkdir)(const char* pathname, mode_t mode) {
246 RTN_ERRNO_IF(ki_mkdir(pathname, mode) < 0); 242 RTN_ERRNO_IF(ki_mkdir(pathname, mode) < 0);
247 return 0; 243 return 0;
248 } 244 }
249 245
250 int WRAP(mmap)(void** addr, size_t length, int prot, int flags, int fd, 246 int WRAP(mmap)(void** addr,
247 size_t length,
248 int prot,
249 int flags,
250 int fd,
251 off_t offset) { 251 off_t offset) {
252 if (flags & MAP_ANONYMOUS) 252 if (flags & MAP_ANONYMOUS)
253 return REAL(mmap)(addr, length, prot, flags, fd, offset); 253 return REAL(mmap)(addr, length, prot, flags, fd, offset);
254 254
255 *addr = ki_mmap(*addr, length, prot, flags, fd, offset); 255 *addr = ki_mmap(*addr, length, prot, flags, fd, offset);
256 RTN_ERRNO_IF(*addr == (void*)-1); 256 RTN_ERRNO_IF(*addr == (void*)-1);
257 return 0; 257 return 0;
258 } 258 }
259 259
260 int WRAP(munmap)(void* addr, size_t length) { 260 int WRAP(munmap)(void* addr, size_t length) {
261 // Always let the real munmap run on the address range. It is not an error if 261 // Always let the real munmap run on the address range. It is not an error if
262 // there are no mapped pages in that range. 262 // there are no mapped pages in that range.
263 ki_munmap(addr, length); 263 ki_munmap(addr, length);
264 return REAL(munmap)(addr, length); 264 return REAL(munmap)(addr, length);
265 } 265 }
266 266
267 int WRAP(open)(const char* pathname, int oflag, mode_t cmode, int* newfd) { 267 int WRAP(open)(const char* pathname, int oflag, mode_t cmode, int* newfd) {
268 *newfd = ki_open(pathname, oflag); 268 *newfd = ki_open(pathname, oflag);
269 RTN_ERRNO_IF(*newfd < 0); 269 RTN_ERRNO_IF(*newfd < 0);
270 return 0; 270 return 0;
271 } 271 }
272 272
273 int WRAP(open_resource)(const char* file, int* fd) { 273 int WRAP(open_resource)(const char* file, int* fd) {
274 *fd = ki_open_resource(file); 274 *fd = ki_open_resource(file);
275 RTN_ERRNO_IF(*fd < 0); 275 RTN_ERRNO_IF(*fd < 0);
276 return 0; 276 return 0;
277 } 277 }
278 278
279 int WRAP(poll)(struct pollfd *fds, nfds_t nfds, int timeout, int* count) { 279 int WRAP(poll)(struct pollfd* fds, nfds_t nfds, int timeout, int* count) {
280 *count = ki_poll(fds, nfds, timeout); 280 *count = ki_poll(fds, nfds, timeout);
281 RTN_ERRNO_IF(*count < 0); 281 RTN_ERRNO_IF(*count < 0);
282 return 0; 282 return 0;
283 } 283 }
284 284
285 int WRAP(read)(int fd, void *buf, size_t count, size_t *nread) { 285 int WRAP(read)(int fd, void* buf, size_t count, size_t* nread) {
286 ssize_t signed_nread = ki_read(fd, buf, count); 286 ssize_t signed_nread = ki_read(fd, buf, count);
287 *nread = static_cast<size_t>(signed_nread); 287 *nread = static_cast<size_t>(signed_nread);
288 RTN_ERRNO_IF(signed_nread < 0); 288 RTN_ERRNO_IF(signed_nread < 0);
289 return 0; 289 return 0;
290 } 290 }
291 291
292 int WRAP(rmdir)(const char* pathname) { 292 int WRAP(rmdir)(const char* pathname) {
293 RTN_ERRNO_IF(ki_rmdir(pathname) < 0); 293 RTN_ERRNO_IF(ki_rmdir(pathname) < 0);
294 return 0; 294 return 0;
295 } 295 }
296 296
297 int WRAP(seek)(int fd, off_t offset, int whence, off_t* new_offset) { 297 int WRAP(seek)(int fd, off_t offset, int whence, off_t* new_offset) {
298 *new_offset = ki_lseek(fd, offset, whence); 298 *new_offset = ki_lseek(fd, offset, whence);
299 RTN_ERRNO_IF(*new_offset < 0); 299 RTN_ERRNO_IF(*new_offset < 0);
300 return 0; 300 return 0;
301 } 301 }
302 302
303 int WRAP(select)(int nfds, fd_set* readfds, fd_set* writefds, 303 int WRAP(select)(int nfds,
304 fd_set* exceptfds, struct timeval* timeout, int* count) { 304 fd_set* readfds,
305 fd_set* writefds,
306 fd_set* exceptfds,
307 struct timeval* timeout,
308 int* count) {
305 *count = ki_select(nfds, readfds, writefds, exceptfds, timeout); 309 *count = ki_select(nfds, readfds, writefds, exceptfds, timeout);
306 RTN_ERRNO_IF(*count < 0); 310 RTN_ERRNO_IF(*count < 0);
307 return 0; 311 return 0;
308 } 312 }
309 313
310 int WRAP(stat)(const char *pathname, struct nacl_abi_stat *nacl_buf) { 314 int WRAP(stat)(const char* pathname, struct nacl_abi_stat* nacl_buf) {
311 struct stat buf; 315 struct stat buf;
312 memset(&buf, 0, sizeof(struct stat)); 316 memset(&buf, 0, sizeof(struct stat));
313 int res = ki_stat(pathname, &buf); 317 int res = ki_stat(pathname, &buf);
314 RTN_ERRNO_IF(res < 0); 318 RTN_ERRNO_IF(res < 0);
315 stat_to_nacl_stat(&buf, nacl_buf); 319 stat_to_nacl_stat(&buf, nacl_buf);
316 return 0; 320 return 0;
317 } 321 }
318 322
319 int WRAP(write)(int fd, const void* buf, size_t count, size_t* nwrote) { 323 int WRAP(write)(int fd, const void* buf, size_t count, size_t* nwrote) {
320 ssize_t signed_nwrote = ki_write(fd, buf, count); 324 ssize_t signed_nwrote = ki_write(fd, buf, count);
321 *nwrote = static_cast<size_t>(signed_nwrote); 325 *nwrote = static_cast<size_t>(signed_nwrote);
322 RTN_ERRNO_IF(signed_nwrote < 0); 326 RTN_ERRNO_IF(signed_nwrote < 0);
323 return 0; 327 return 0;
324 } 328 }
325 329
326 int WRAP(accept)(int sockfd, struct sockaddr* addr, 330 int WRAP(accept)(int sockfd,
327 socklen_t* addrlen, int *sd) { 331 struct sockaddr* addr,
332 socklen_t* addrlen,
333 int* sd) {
328 *sd = ki_accept(sockfd, addr, addrlen); 334 *sd = ki_accept(sockfd, addr, addrlen);
329 RTN_ERRNO_IF(*sd < 0); 335 RTN_ERRNO_IF(*sd < 0);
330 return 0; 336 return 0;
331 } 337 }
332 338
333 int WRAP(bind)(int sockfd, const struct sockaddr* addr, socklen_t addrlen) { 339 int WRAP(bind)(int sockfd, const struct sockaddr* addr, socklen_t addrlen) {
334 RTN_ERRNO_IF(ki_bind(sockfd, addr, addrlen) < 0); 340 RTN_ERRNO_IF(ki_bind(sockfd, addr, addrlen) < 0);
335 return 0; 341 return 0;
336 } 342 }
337 343
338 int WRAP(connect)(int sockfd, const struct sockaddr* addr, socklen_t addrlen) { 344 int WRAP(connect)(int sockfd, const struct sockaddr* addr, socklen_t addrlen) {
339 RTN_ERRNO_IF(ki_connect(sockfd, addr, addrlen) < 0); 345 RTN_ERRNO_IF(ki_connect(sockfd, addr, addrlen) < 0);
340 return 0; 346 return 0;
341 } 347 }
342 348
343 int WRAP(getpeername)(int sockfd, struct sockaddr* addr, socklen_t* addrlen) { 349 int WRAP(getpeername)(int sockfd, struct sockaddr* addr, socklen_t* addrlen) {
344 RTN_ERRNO_IF(ki_getpeername(sockfd, addr, addrlen) < 0); 350 RTN_ERRNO_IF(ki_getpeername(sockfd, addr, addrlen) < 0);
345 return 0; 351 return 0;
346 } 352 }
347 353
348 int WRAP(getsockname)(int sockfd, struct sockaddr* addr, socklen_t* addrlen) { 354 int WRAP(getsockname)(int sockfd, struct sockaddr* addr, socklen_t* addrlen) {
349 RTN_ERRNO_IF(ki_getsockname(sockfd, addr, addrlen) < 0); 355 RTN_ERRNO_IF(ki_getsockname(sockfd, addr, addrlen) < 0);
350 return 0; 356 return 0;
351 } 357 }
352 358
353 int WRAP(getsockopt)(int sockfd, int level, int optname, void* optval, 359 int WRAP(getsockopt)(int sockfd,
360 int level,
361 int optname,
362 void* optval,
354 socklen_t* optlen) { 363 socklen_t* optlen) {
355 RTN_ERRNO_IF(ki_getsockopt(sockfd, level, optname, optval, optlen) < 0); 364 RTN_ERRNO_IF(ki_getsockopt(sockfd, level, optname, optval, optlen) < 0);
356 return 0; 365 return 0;
357 } 366 }
358 367
359 int WRAP(setsockopt)(int sockfd, int level, int optname, const void* optval, 368 int WRAP(setsockopt)(int sockfd,
369 int level,
370 int optname,
371 const void* optval,
360 socklen_t optlen) { 372 socklen_t optlen) {
361 RTN_ERRNO_IF(ki_setsockopt(sockfd, level, optname, optval, optlen) < 0); 373 RTN_ERRNO_IF(ki_setsockopt(sockfd, level, optname, optval, optlen) < 0);
362 return 0; 374 return 0;
363 } 375 }
364 376
365 int WRAP(listen)(int sockfd, int backlog) { 377 int WRAP(listen)(int sockfd, int backlog) {
366 RTN_ERRNO_IF(ki_listen(sockfd, backlog) < 0); 378 RTN_ERRNO_IF(ki_listen(sockfd, backlog) < 0);
367 return 0; 379 return 0;
368 } 380 }
369 381
370 int WRAP(recv)(int sockfd, void* buf, size_t len, int flags, int* count) { 382 int WRAP(recv)(int sockfd, void* buf, size_t len, int flags, int* count) {
371 ssize_t signed_nread = ki_recv(sockfd, buf, len, flags); 383 ssize_t signed_nread = ki_recv(sockfd, buf, len, flags);
372 *count = static_cast<int>(signed_nread); 384 *count = static_cast<int>(signed_nread);
373 RTN_ERRNO_IF(signed_nread < 0); 385 RTN_ERRNO_IF(signed_nread < 0);
374 return 0; 386 return 0;
375 } 387 }
376 388
377 int WRAP(recvfrom)(int sockfd, void* buf, size_t len, int flags, 389 int WRAP(recvfrom)(int sockfd,
378 struct sockaddr* addr, socklen_t* addrlen, int* count) { 390 void* buf,
391 size_t len,
392 int flags,
393 struct sockaddr* addr,
394 socklen_t* addrlen,
395 int* count) {
379 ssize_t signed_nread = ki_recvfrom(sockfd, buf, len, flags, addr, addrlen); 396 ssize_t signed_nread = ki_recvfrom(sockfd, buf, len, flags, addr, addrlen);
380 *count = static_cast<int>(signed_nread); 397 *count = static_cast<int>(signed_nread);
381 RTN_ERRNO_IF(signed_nread < 0); 398 RTN_ERRNO_IF(signed_nread < 0);
382 return 0; 399 return 0;
383 } 400 }
384 401
385 int WRAP(recvmsg)(int sockfd, struct msghdr* msg, int flags, int *count) { 402 int WRAP(recvmsg)(int sockfd, struct msghdr* msg, int flags, int* count) {
386 ssize_t signed_nread = ki_recvmsg(sockfd, msg, flags); 403 ssize_t signed_nread = ki_recvmsg(sockfd, msg, flags);
387 *count = static_cast<int>(signed_nread); 404 *count = static_cast<int>(signed_nread);
388 RTN_ERRNO_IF(signed_nread < 0); 405 RTN_ERRNO_IF(signed_nread < 0);
389 return 0; 406 return 0;
390 } 407 }
391 408
392 ssize_t WRAP(send)(int sockfd, const void* buf, size_t len, int flags, 409 ssize_t WRAP(send)(int sockfd, const void* buf, size_t len, int flags,
393 int* count) { 410 int* count) {
394 ssize_t signed_nread = ki_send(sockfd, buf, len, flags); 411 ssize_t signed_nread = ki_send(sockfd, buf, len, flags);
395 *count = static_cast<int>(signed_nread); 412 *count = static_cast<int>(signed_nread);
396 RTN_ERRNO_IF(signed_nread < 0); 413 RTN_ERRNO_IF(signed_nread < 0);
397 return 0; 414 return 0;
398 } 415 }
399 416
400 ssize_t WRAP(sendto)(int sockfd, const void* buf, size_t len, int flags, 417 ssize_t WRAP(sendto)(int sockfd,
401 const struct sockaddr* addr, socklen_t addrlen, 418 const void* buf,
419 size_t len,
420 int flags,
421 const struct sockaddr* addr,
422 socklen_t addrlen,
402 int* count) { 423 int* count) {
403 ssize_t signed_nread = ki_sendto(sockfd, buf, len, flags, addr, addrlen); 424 ssize_t signed_nread = ki_sendto(sockfd, buf, len, flags, addr, addrlen);
404 *count = static_cast<int>(signed_nread); 425 *count = static_cast<int>(signed_nread);
405 RTN_ERRNO_IF(signed_nread < 0); 426 RTN_ERRNO_IF(signed_nread < 0);
406 return 0; 427 return 0;
407 } 428 }
408 429
409 ssize_t WRAP(sendmsg)(int sockfd, const struct msghdr* msg, int flags, 430 ssize_t WRAP(sendmsg)(int sockfd,
431 const struct msghdr* msg,
432 int flags,
410 int* count) { 433 int* count) {
411 ssize_t signed_nread = ki_sendmsg(sockfd, msg, flags); 434 ssize_t signed_nread = ki_sendmsg(sockfd, msg, flags);
412 *count = static_cast<int>(signed_nread); 435 *count = static_cast<int>(signed_nread);
413 RTN_ERRNO_IF(signed_nread < 0); 436 RTN_ERRNO_IF(signed_nread < 0);
414 return 0; 437 return 0;
415 } 438 }
416 439
417 int WRAP(shutdown)(int sockfd, int how) { 440 int WRAP(shutdown)(int sockfd, int how) {
418 RTN_ERRNO_IF(ki_shutdown(sockfd, how) < 0); 441 RTN_ERRNO_IF(ki_shutdown(sockfd, how) < 0);
419 return 0; 442 return 0;
(...skipping 12 matching lines...) Expand all
432 455
433 static void assign_real_pointers() { 456 static void assign_real_pointers() {
434 static bool assigned = false; 457 static bool assigned = false;
435 if (!assigned) { 458 if (!assigned) {
436 EXPAND_SYMBOL_LIST_OPERATION(ASSIGN_REAL_PTR) 459 EXPAND_SYMBOL_LIST_OPERATION(ASSIGN_REAL_PTR)
437 assigned = true; 460 assigned = true;
438 } 461 }
439 } 462 }
440 463
441 #define CHECK_REAL(func) \ 464 #define CHECK_REAL(func) \
442 if (!REAL(func)) \ 465 if (!REAL(func)) \
443 assign_real_pointers(); 466 assign_real_pointers();
444 467
445 // "real" functions, i.e. the unwrapped original functions. 468 // "real" functions, i.e. the unwrapped original functions.
446 469
447 int _real_close(int fd) { 470 int _real_close(int fd) {
448 CHECK_REAL(close); 471 CHECK_REAL(close);
449 return REAL(close)(fd); 472 return REAL(close)(fd);
450 } 473 }
451 474
452 void _real_exit(int status) { 475 void _real_exit(int status) {
(...skipping 25 matching lines...) Expand all
478 int err = REAL(getdents)(fd, (dirent*)nacl_buf, count, &nacl_nread); 501 int err = REAL(getdents)(fd, (dirent*)nacl_buf, count, &nacl_nread);
479 if (err) 502 if (err)
480 return err; 503 return err;
481 504
482 while (nacl_offset < nacl_nread) { 505 while (nacl_offset < nacl_nread) {
483 dirent* d = (dirent*)((char*)buf + offset); 506 dirent* d = (dirent*)((char*)buf + offset);
484 nacl_abi_dirent* nacl_d = (nacl_abi_dirent*)(nacl_buf + nacl_offset); 507 nacl_abi_dirent* nacl_d = (nacl_abi_dirent*)(nacl_buf + nacl_offset);
485 d->d_ino = nacl_d->nacl_abi_d_ino; 508 d->d_ino = nacl_d->nacl_abi_d_ino;
486 d->d_off = nacl_d->nacl_abi_d_off; 509 d->d_off = nacl_d->nacl_abi_d_off;
487 d->d_reclen = nacl_d->nacl_abi_d_reclen + d_name_shift; 510 d->d_reclen = nacl_d->nacl_abi_d_reclen + d_name_shift;
488 size_t d_name_len = nacl_d->nacl_abi_d_reclen - 511 size_t d_name_len =
489 offsetof(nacl_abi_dirent, nacl_abi_d_name); 512 nacl_d->nacl_abi_d_reclen - offsetof(nacl_abi_dirent, nacl_abi_d_name);
490 memcpy(d->d_name, nacl_d->nacl_abi_d_name, d_name_len); 513 memcpy(d->d_name, nacl_d->nacl_abi_d_name, d_name_len);
491 514
492 offset += d->d_reclen; 515 offset += d->d_reclen;
493 offset += nacl_d->nacl_abi_d_reclen; 516 offset += nacl_d->nacl_abi_d_reclen;
494 } 517 }
495 518
496 *nread = offset; 519 *nread = offset;
497 return 0; 520 return 0;
498 } 521 }
499 522
500 int _real_lseek(int fd, off_t offset, int whence, off_t* new_offset) { 523 int _real_lseek(int fd, off_t offset, int whence, off_t* new_offset) {
501 CHECK_REAL(seek); 524 CHECK_REAL(seek);
502 return REAL(seek)(fd, offset, whence, new_offset); 525 return REAL(seek)(fd, offset, whence, new_offset);
503 } 526 }
504 527
505 int _real_mkdir(const char* pathname, mode_t mode) { 528 int _real_mkdir(const char* pathname, mode_t mode) {
506 CHECK_REAL(mkdir); 529 CHECK_REAL(mkdir);
507 return REAL(mkdir)(pathname, mode); 530 return REAL(mkdir)(pathname, mode);
508 } 531 }
509 532
510 int _real_mmap(void** addr, size_t length, int prot, int flags, int fd, 533 int _real_mmap(void** addr,
534 size_t length,
535 int prot,
536 int flags,
537 int fd,
511 off_t offset) { 538 off_t offset) {
512 CHECK_REAL(mmap); 539 CHECK_REAL(mmap);
513 return REAL(mmap)(addr, length, prot, flags, fd, offset); 540 return REAL(mmap)(addr, length, prot, flags, fd, offset);
514 } 541 }
515 542
516 int _real_munmap(void* addr, size_t length) { 543 int _real_munmap(void* addr, size_t length) {
517 CHECK_REAL(munmap); 544 CHECK_REAL(munmap);
518 return REAL(munmap)(addr, length); 545 return REAL(munmap)(addr, length);
519 } 546 }
520 547
521 int _real_open(const char* pathname, int oflag, mode_t cmode, int* newfd) { 548 int _real_open(const char* pathname, int oflag, mode_t cmode, int* newfd) {
522 CHECK_REAL(open); 549 CHECK_REAL(open);
523 return REAL(open)(pathname, oflag, cmode, newfd); 550 return REAL(open)(pathname, oflag, cmode, newfd);
524 } 551 }
525 552
526 int _real_open_resource(const char* file, int* fd) { 553 int _real_open_resource(const char* file, int* fd) {
527 CHECK_REAL(open_resource); 554 CHECK_REAL(open_resource);
528 return REAL(open_resource)(file, fd); 555 return REAL(open_resource)(file, fd);
529 } 556 }
530 557
531 int _real_read(int fd, void *buf, size_t count, size_t *nread) { 558 int _real_read(int fd, void* buf, size_t count, size_t* nread) {
532 CHECK_REAL(read); 559 CHECK_REAL(read);
533 return REAL(read)(fd, buf, count, nread); 560 return REAL(read)(fd, buf, count, nread);
534 } 561 }
535 562
536 int _real_rmdir(const char* pathname) { 563 int _real_rmdir(const char* pathname) {
537 CHECK_REAL(rmdir); 564 CHECK_REAL(rmdir);
538 return REAL(rmdir)(pathname); 565 return REAL(rmdir)(pathname);
539 } 566 }
540 567
541 int _real_write(int fd, const void *buf, size_t count, size_t *nwrote) { 568 int _real_write(int fd, const void* buf, size_t count, size_t* nwrote) {
542 CHECK_REAL(write); 569 CHECK_REAL(write);
543 return REAL(write)(fd, buf, count, nwrote); 570 return REAL(write)(fd, buf, count, nwrote);
544 } 571 }
545 572
546 static bool s_wrapped = false; 573 static bool s_wrapped = false;
547 void kernel_wrap_init() { 574 void kernel_wrap_init() {
548 if (!s_wrapped) { 575 if (!s_wrapped) {
549 LOG_TRACE("kernel_wrap_init"); 576 LOG_TRACE("kernel_wrap_init");
550 assign_real_pointers(); 577 assign_real_pointers();
551 EXPAND_SYMBOL_LIST_OPERATION(USE_WRAP) 578 EXPAND_SYMBOL_LIST_OPERATION(USE_WRAP)
552 s_wrapped = true; 579 s_wrapped = true;
553 } 580 }
554 } 581 }
555 582
556 void kernel_wrap_uninit() { 583 void kernel_wrap_uninit() {
557 if (s_wrapped) { 584 if (s_wrapped) {
558 LOG_TRACE("kernel_wrap_uninit"); 585 LOG_TRACE("kernel_wrap_uninit");
559 EXPAND_SYMBOL_LIST_OPERATION(USE_REAL) 586 EXPAND_SYMBOL_LIST_OPERATION(USE_REAL)
560 s_wrapped = false; 587 s_wrapped = false;
561 } 588 }
562 } 589 }
563 590
564 EXTERN_C_END 591 EXTERN_C_END
565 592
566 #endif // defined(__native_client__) && defined(__GLIBC__) 593 #endif // defined(__native_client__) && defined(__GLIBC__)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698