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