OLD | NEW |
| (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 // The entire file is wrapped in this #if. We do this so this .cc file can be | |
7 // compiled, even on a non-Windows build. | |
8 #if defined(WIN32) | |
9 | |
10 #include "nacl_mounts/kernel_wrap.h" | |
11 #include <errno.h> | |
12 #include <fcntl.h> | |
13 #include <stdarg.h> | |
14 #include <string.h> | |
15 #include <sys/types.h> // This must be included before <sys/stat.h>. | |
16 #include <sys/stat.h> | |
17 #include "nacl_mounts/kernel_intercept.h" | |
18 | |
19 namespace { | |
20 | |
21 template <typename SrcStat, typename DstStat> | |
22 void CopyStat(const SrcStat* src, DstStat* dst) { | |
23 memset(dst, 0, sizeof(DstStat)); | |
24 dst->st_dev = src->st_dev; | |
25 dst->st_ino = src->st_ino; | |
26 dst->st_mode = src->st_mode; | |
27 dst->st_nlink = src->st_nlink; | |
28 dst->st_uid = src->st_uid; | |
29 dst->st_gid = src->st_gid; | |
30 dst->st_rdev = src->st_rdev; | |
31 dst->st_size = src->st_size; | |
32 dst->st_atime = src->st_atime; | |
33 dst->st_mtime = src->st_mtime; | |
34 dst->st_ctime = src->st_ctime; | |
35 } | |
36 | |
37 } // namespace | |
38 | |
39 EXTERN_C_BEGIN | |
40 | |
41 // This needs to be included because it is defined in read.c, which we wish to | |
42 // override. Define with dummy values for now... though this seems like it will | |
43 // break ftelli64/fgetpos/fstream. | |
44 char _lookuptrailbytes[256] = {0}; | |
45 | |
46 int _access(const char* path, int amode) { | |
47 return ki_access(path, amode); | |
48 } | |
49 | |
50 int _chdir(const char* path) { | |
51 return ki_chdir(path); | |
52 } | |
53 | |
54 int _chmod(const char* path, mode_t mode) { | |
55 return ki_chmod(path, mode); | |
56 } | |
57 | |
58 int _close(int fd) { | |
59 return ki_close(fd); | |
60 } | |
61 | |
62 int _close_nolock(int fd) { | |
63 return ki_close(fd); | |
64 } | |
65 | |
66 int _dup(int oldfd) { | |
67 return ki_dup(oldfd); | |
68 } | |
69 | |
70 int _dup2(int oldfd, int newfd) { | |
71 return ki_dup2(oldfd, newfd); | |
72 } | |
73 | |
74 int _fstat32(int fd, struct _stat32* buf) { | |
75 struct stat ki_buf; | |
76 int res = ki_fstat(fd, &ki_buf); | |
77 CopyStat(&ki_buf, buf); | |
78 return res; | |
79 } | |
80 | |
81 int _fstat64(int fd, struct _stat64* buf) { | |
82 struct stat ki_buf; | |
83 int res = ki_fstat(fd, &ki_buf); | |
84 CopyStat(&ki_buf, buf); | |
85 return res; | |
86 } | |
87 | |
88 int _fstat32i64(int fd, struct _stat32i64* buf) { | |
89 struct stat ki_buf; | |
90 int res = ki_fstat(fd, &ki_buf); | |
91 CopyStat(&ki_buf, buf); | |
92 return res; | |
93 } | |
94 | |
95 int _fstat64i32(int fd, struct _stat64i32* buf) { | |
96 struct stat ki_buf; | |
97 int res = ki_fstat(fd, &ki_buf); | |
98 CopyStat(&ki_buf, buf); | |
99 return res; | |
100 } | |
101 | |
102 int fsync(int fd) { | |
103 return ki_fsync(fd); | |
104 } | |
105 | |
106 char* _getcwd(char* buf, int size) { | |
107 return ki_getcwd(buf, size); | |
108 } | |
109 | |
110 char* getwd(char* buf) { | |
111 return ki_getwd(buf); | |
112 } | |
113 | |
114 int getdents(int fd, void* buf, unsigned int count) { | |
115 return ki_getdents(fd, buf, count); | |
116 } | |
117 | |
118 int _isatty(int fd) { | |
119 return ki_isatty(fd); | |
120 } | |
121 | |
122 int link(const char* oldpath, const char* newpath) { | |
123 return ki_link(oldpath, newpath); | |
124 } | |
125 | |
126 off_t _lseek(int fd, off_t offset, int whence) { | |
127 return ki_lseek(fd, offset, whence); | |
128 } | |
129 | |
130 int _mkdir(const char* path) { | |
131 return ki_mkdir(path, 0777); | |
132 } | |
133 | |
134 int mount(const char* source, const char* target, const char* filesystemtype, | |
135 unsigned long mountflags, const void *data) { | |
136 return ki_mount(source, target, filesystemtype, mountflags, data); | |
137 } | |
138 | |
139 int _open(const char* path, int oflag, ...) { | |
140 #if 0 | |
141 // TODO(binji): ki_open should use the pmode parameter. When it does, this | |
142 // will be necessary to add in. | |
143 va_list list; | |
144 int pmode = 0; | |
145 if (oflag & _O_CREAT) { | |
146 va_start(list, oflag); | |
147 pmode = va_arg(list, int); | |
148 va_end(list); | |
149 } | |
150 #endif | |
151 return ki_open(path, oflag); | |
152 } | |
153 | |
154 int _sopen(const char* path, int oflag, int shflag) { | |
155 return ki_open(path, oflag); | |
156 } | |
157 | |
158 errno_t _sopen_s(int* pfh, const char* path, int oflag, int shflag, int pmode) { | |
159 *pfh = ki_open(path, oflag); | |
160 return (*pfh < 0) ? errno : 0; | |
161 } | |
162 | |
163 int _read(int fd, void* buf, size_t nbyte) { | |
164 if (!ki_is_initialized()) | |
165 return 0; | |
166 | |
167 return ki_read(fd, buf, nbyte); | |
168 } | |
169 | |
170 int _read_nolock(int fd, void* buf, size_t nbyte) { | |
171 if (!ki_is_initialized()) | |
172 return 0; | |
173 | |
174 return ki_read(fd, buf, nbyte); | |
175 } | |
176 | |
177 int remove(const char* path) { | |
178 return ki_remove(path); | |
179 } | |
180 | |
181 int _rmdir(const char* path) { | |
182 return ki_rmdir(path); | |
183 } | |
184 | |
185 int _stat32(const char* path, struct _stat32* buf) { | |
186 struct stat ki_buf; | |
187 int res = ki_stat(path, &ki_buf); | |
188 CopyStat(&ki_buf, buf); | |
189 return res; | |
190 } | |
191 | |
192 int _stat64(const char* path, struct _stat64* buf) { | |
193 struct stat ki_buf; | |
194 int res = ki_stat(path, &ki_buf); | |
195 CopyStat(&ki_buf, buf); | |
196 return res; | |
197 } | |
198 | |
199 int _stat64i32(const char* path, struct _stat64i32* buf) { | |
200 struct stat ki_buf; | |
201 int res = ki_stat(path, &ki_buf); | |
202 CopyStat(&ki_buf, buf); | |
203 return res; | |
204 } | |
205 | |
206 int _stat32i64(const char* path, struct _stat32i64* buf) { | |
207 struct stat ki_buf; | |
208 int res = ki_stat(path, &ki_buf); | |
209 CopyStat(&ki_buf, buf); | |
210 return res; | |
211 } | |
212 | |
213 int symlink(const char* oldpath, const char* newpath) { | |
214 return ki_symlink(oldpath, newpath); | |
215 } | |
216 | |
217 int umount(const char* path) { | |
218 return ki_umount(path); | |
219 } | |
220 | |
221 int _unlink(const char* path) { | |
222 return ki_unlink(path); | |
223 } | |
224 | |
225 int _write(int fd, const void* buf, size_t nbyte) { | |
226 if (!ki_is_initialized()) | |
227 return 0; | |
228 | |
229 return ki_write(fd, buf, nbyte); | |
230 } | |
231 | |
232 // Do nothing for Windows, we replace the library at link time. | |
233 void kernel_wrap_init() { | |
234 } | |
235 EXTERN_C_END | |
236 | |
237 #endif // defined(WIN32) | |
OLD | NEW |