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

Side by Side Diff: native_client_sdk/src/libraries/nacl_mounts/kernel_wrap_newlib.cc

Issue 11066105: [NaCl SDK] nacl_mounts: wrap functions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: win fix Created 8 years, 2 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
(Empty)
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
3 * found in the LICENSE file.
4 */
5
6 #include "nacl_mounts/kernel_wrap.h"
7 #include <dirent.h>
8 #include <errno.h>
9 #include <irt.h>
10 #include <sys/stat.h>
11 #include "nacl_mounts/kernel_intercept.h"
12
13 EXTERN_C_BEGIN
14
15 #define REAL(name) __nacl_irt_##name##_real
16 #define WRAP(name) __nacl_irt_##name##_wrap
17 #define STRUCT_NAME(group) __libnacl_irt_##group
18 #define DECLARE_STRUCT(group) \
19 extern struct nacl_irt_##group STRUCT_NAME(group);
20 #define MUX(group, name) STRUCT_NAME(group).name
21 #define DECLARE(group, name) typeof(MUX(group, name)) REAL(name);
22 #define DO_WRAP(group, name) do { \
23 REAL(name) = MUX(group, name); \
24 MUX(group, name) = (typeof(REAL(name))) WRAP(name); \
25 } while (0)
26
27 DECLARE_STRUCT(fdio)
28 DECLARE_STRUCT(filename)
29
30 DECLARE(fdio, close)
31 DECLARE(fdio, dup)
32 DECLARE(fdio, fstat)
33 DECLARE(fdio, getdents)
34 DECLARE(fdio, read)
35 DECLARE(fdio, seek)
36 DECLARE(fdio, write)
37 DECLARE(filename, open)
38 DECLARE(filename, stat)
39
40 int access(const char* path, int amode) {
41 return ki_access(path, amode);
42 }
43
44 int chdir(const char* path) {
45 return ki_chdir(path);
46 }
47
48 int chmod(const char* path, mode_t mode) {
49 return ki_chmod(path, mode);
50 }
51
52 int WRAP(close)(int fd) {
53 return (ki_close(fd) < 0) ? errno : 0;
54 }
55
56 int WRAP(dup)(int fd, int* newfd) {
57 *newfd = ki_dup(fd);
58 return (*newfd < 0) ? errno : 0;
59 }
60
61 int WRAP(fstat)(int fd, struct stat *buf) {
62 return (ki_fstat(fd, buf) < 0) ? errno : 0;
63 }
64
65 int fsync(int fd) {
66 return ki_fsync(fd);
67 }
68
69 char* getcwd(char* buf, size_t size) {
70 // gtest uses getcwd in a static initializer. If we haven't initialized the
71 // kernel-intercept yet, just return ".".
72 if (!ki_is_initialized()) {
73 if (size < 2) {
74 errno = ERANGE;
75 return NULL;
76 }
77 buf[0] = '.';
78 buf[1] = 0;
79 return buf;
80 }
81 return ki_getcwd(buf, size);
82 }
83
84 char* getwd(char* buf) {
85 return ki_getwd(buf);
86 }
87
88 int getdents(int fd, void* buf, unsigned int count) {
89 return ki_getdents(fd, buf, count);
90 }
91
92 int WRAP(getdents)(int fd, dirent* buf, size_t count, size_t *nread) {
93 return (ki_getdents(fd, buf, count) < 0) ? errno : 0;
94 }
95
96 int isatty(int fd) {
97 return ki_isatty(fd);
98 }
99
100 int mkdir(const char* path, mode_t mode) {
101 return ki_mkdir(path, mode);
102 }
103
104 int mount(const char* source, const char* target, const char* filesystemtype,
105 unsigned long mountflags, const void* data) {
106 return ki_mount(source, target, filesystemtype, mountflags, data);
107 }
108
109 int WRAP(open)(const char* pathname, int oflag, mode_t cmode, int* newfd) {
110 *newfd = ki_open(pathname, oflag);
111 return (*newfd < 0) ? errno : 0;
112 }
113
114 int WRAP(read)(int fd, void *buf, size_t count, size_t *nread) {
115 *nread = ki_read(fd, buf, count);
116 return (*nread < 0) ? errno : 0;
117 }
118
119 int remove(const char* path) {
120 return ki_remove(path);
121 }
122
123 int rmdir(const char* path) {
124 return ki_rmdir(path);
125 }
126
127 int WRAP(seek)(int fd, off_t offset, int whence, off_t* new_offset) {
128 *new_offset = ki_lseek(fd, offset, whence);
129 return (*new_offset < 0) ? errno : 0;
130 }
131
132 int WRAP(stat)(const char *pathname, struct stat *buf) {
133 return (ki_stat(pathname, buf) < 0) ? errno : 0;
134 }
135
136 int umount(const char* path) {
137 return ki_umount(path);
138 }
139
140 int unlink(const char* path) {
141 return ki_unlink(path);
142 }
143
144 int WRAP(write)(int fd, const void *buf, size_t count, size_t *nwrote) {
145 *nwrote = ki_write(fd, buf, count);
146 return (*nwrote < 0) ? errno : 0;
147 }
148
149 EXTERN_C_END
150
151 static struct NaClMountsStaticInitializer {
152 NaClMountsStaticInitializer() {
153 DO_WRAP(fdio, close);
154 DO_WRAP(fdio, dup);
155 DO_WRAP(fdio, fstat);
156 DO_WRAP(fdio, getdents);
157 DO_WRAP(fdio, read);
158 DO_WRAP(fdio, seek);
159 DO_WRAP(fdio, write);
160 DO_WRAP(filename, open);
161 DO_WRAP(filename, stat);
162 }
163 } nacl_mounts_static_initializer;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698