| 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 #include <errno.h> | |
| 6 #include "nacl_mounts/kernel_intercept.h" | |
| 7 #include "nacl_mounts/kernel_proxy.h" | |
| 8 #include "nacl_mounts/kernel_wrap.h" | |
| 9 #include "nacl_mounts/pepper_interface.h" | |
| 10 #include "nacl_mounts/pepper_interface.h" | |
| 11 #include "nacl_mounts/real_pepper_interface.h" | |
| 12 | |
| 13 | |
| 14 static KernelProxy* s_kp; | |
| 15 | |
| 16 void ki_init(void* kp) { | |
| 17 ki_init_ppapi(kp, 0, NULL); | |
| 18 } | |
| 19 | |
| 20 void ki_init_ppapi(void* kp, | |
| 21 PP_Instance instance, | |
| 22 PPB_GetInterface get_browser_interface) { | |
| 23 kernel_wrap_init(); | |
| 24 | |
| 25 if (kp == NULL) kp = new KernelProxy(); | |
| 26 s_kp = static_cast<KernelProxy*>(kp); | |
| 27 | |
| 28 PepperInterface* ppapi = NULL; | |
| 29 if (instance && get_browser_interface) | |
| 30 ppapi = new RealPepperInterface(instance, get_browser_interface); | |
| 31 | |
| 32 s_kp->Init(ppapi); | |
| 33 } | |
| 34 | |
| 35 int ki_is_initialized() { | |
| 36 return s_kp != NULL; | |
| 37 } | |
| 38 | |
| 39 void ki_uninit() { | |
| 40 s_kp = NULL; | |
| 41 } | |
| 42 | |
| 43 int ki_chdir(const char* path) { | |
| 44 return s_kp->chdir(path); | |
| 45 } | |
| 46 | |
| 47 char* ki_getcwd(char* buf, size_t size) { | |
| 48 // gtest uses getcwd in a static initializer. If we haven't initialized the | |
| 49 // kernel-intercept yet, just return ".". | |
| 50 if (!ki_is_initialized()) { | |
| 51 if (size < 2) { | |
| 52 errno = ERANGE; | |
| 53 return NULL; | |
| 54 } | |
| 55 buf[0] = '.'; | |
| 56 buf[1] = 0; | |
| 57 return buf; | |
| 58 } | |
| 59 return s_kp->getcwd(buf, size); | |
| 60 } | |
| 61 | |
| 62 char* ki_getwd(char* buf) { | |
| 63 return s_kp->getwd(buf); | |
| 64 } | |
| 65 | |
| 66 int ki_dup(int oldfd) { | |
| 67 return s_kp->dup(oldfd); | |
| 68 } | |
| 69 | |
| 70 int ki_dup2(int oldfd, int newfd) { | |
| 71 return s_kp->dup2(oldfd, newfd); | |
| 72 } | |
| 73 | |
| 74 int ki_chmod(const char *path, mode_t mode) { | |
| 75 return s_kp->chmod(path, mode); | |
| 76 } | |
| 77 | |
| 78 int ki_stat(const char *path, struct stat *buf) { | |
| 79 return s_kp->stat(path, buf); | |
| 80 } | |
| 81 | |
| 82 int ki_mkdir(const char *path, mode_t mode) { | |
| 83 return s_kp->mkdir(path, mode); | |
| 84 } | |
| 85 | |
| 86 int ki_rmdir(const char *path) { | |
| 87 return s_kp->rmdir(path); | |
| 88 } | |
| 89 | |
| 90 int ki_mount(const char *source, const char *target, const char *filesystemtype, | |
| 91 unsigned long mountflags, const void *data) { | |
| 92 return s_kp->mount(source, target, filesystemtype, mountflags, data); | |
| 93 } | |
| 94 | |
| 95 int ki_umount(const char *path) { | |
| 96 return s_kp->umount(path); | |
| 97 } | |
| 98 | |
| 99 int ki_open(const char *path, int oflag) { | |
| 100 return s_kp->open(path, oflag); | |
| 101 } | |
| 102 | |
| 103 ssize_t ki_read(int fd, void *buf, size_t nbyte) { | |
| 104 return s_kp->read(fd, buf, nbyte); | |
| 105 } | |
| 106 | |
| 107 ssize_t ki_write(int fd, const void *buf, size_t nbyte) { | |
| 108 return s_kp->write(fd, buf, nbyte); | |
| 109 } | |
| 110 | |
| 111 int ki_fstat(int fd, struct stat *buf){ | |
| 112 return s_kp->fstat(fd, buf); | |
| 113 } | |
| 114 | |
| 115 int ki_getdents(int fd, void *buf, unsigned int count) { | |
| 116 return s_kp->getdents(fd, buf, count); | |
| 117 } | |
| 118 | |
| 119 int ki_fsync(int fd) { | |
| 120 return s_kp->fsync(fd); | |
| 121 } | |
| 122 | |
| 123 int ki_isatty(int fd) { | |
| 124 if (!ki_is_initialized()) | |
| 125 return 0; | |
| 126 return s_kp->isatty(fd); | |
| 127 } | |
| 128 | |
| 129 int ki_close(int fd) { | |
| 130 if (!ki_is_initialized()) | |
| 131 return 0; | |
| 132 return s_kp->close(fd); | |
| 133 } | |
| 134 | |
| 135 off_t ki_lseek(int fd, off_t offset, int whence) { | |
| 136 return s_kp->lseek(fd, offset, whence); | |
| 137 } | |
| 138 | |
| 139 int ki_remove(const char* path) { | |
| 140 return s_kp->remove(path); | |
| 141 } | |
| 142 | |
| 143 int ki_unlink(const char* path) { | |
| 144 return s_kp->unlink(path); | |
| 145 } | |
| 146 | |
| 147 int ki_access(const char* path, int amode) { | |
| 148 return s_kp->access(path, amode); | |
| 149 } | |
| 150 | |
| 151 int ki_link(const char* oldpath, const char* newpath) { | |
| 152 return s_kp->link(oldpath, newpath); | |
| 153 } | |
| 154 | |
| 155 int ki_symlink(const char* oldpath, const char* newpath) { | |
| 156 return s_kp->symlink(oldpath, newpath); | |
| 157 } | |
| OLD | NEW |