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#ifndef LIBRARIES_NACL_IO_KERNEL_INTERCEPT_H_ 6#define LIBRARIES_NACL_IO_KERNEL_INTERCEPT_H_ 7 8#include <stdarg.h> 9#include <sys/time.h> 10 11#include <ppapi/c/ppb.h> 12#include <ppapi/c/pp_instance.h> 13 14#include "nacl_io/ossignal.h" 15#include "nacl_io/ossocket.h" 16#include "nacl_io/osstat.h" 17#include "nacl_io/ostermios.h" 18#include "nacl_io/ostypes.h" 19#include "nacl_io/osutime.h" 20#include "sdk_util/macros.h" 21 22EXTERN_C_BEGIN 23 24#ifdef __cplusplus 25namespace nacl_io { 26class KernelProxy; 27} 28#endif 29 30struct fuse_operations; 31 32/* 33 * The kernel intercept module provides a C->C++ thunk between the libc 34 * kernel calls and the KernelProxy singleton. 35 */ 36 37/* 38 * ki_init must be called with an uninitialized KernelProxy object. Calling 39 * with NULL will instantiate a default kernel proxy object. ki_init must 40 * be called before any other ki_XXX function can be used. 41 */ 42int ki_init(void* kernel_proxy); 43 44/* 45 * Saves the current internal state. This is used by test code which can 46 * use this to save the current state before calling ki_init(). The 47 * pushed state is restored by ki_pop_state_for_testing() (or ki_uninit()). 48 */ 49int ki_push_state_for_testing(void); 50 51int ki_pop_state_for_testing(void); 52 53int ki_init_ppapi(void* kernel_proxy, 54 PP_Instance instance, 55 PPB_GetInterface get_browser_interface); 56 57/* 58 * ki_init_interface() is a variant of ki_init() that can be called with 59 * a PepperInterface object. 60 */ 61int ki_init_interface(void* kernel_proxy, void* pepper_interface); 62 63#ifdef __cplusplus 64nacl_io::KernelProxy* ki_get_proxy(); 65#endif 66 67int ki_is_initialized(void); 68int ki_uninit(void); 69 70int ki_chdir(const char* path); 71void ki_exit(int status); 72char* ki_getcwd(char* buf, size_t size); 73char* ki_getwd(char* buf); 74int ki_dup(int oldfd); 75int ki_dup2(int oldfd, int newfd); 76int ki_chmod(const char* path, mode_t mode); 77int ki_fchdir(int fd); 78int ki_fchmod(int fd, mode_t mode); 79int ki_stat(const char* path, struct stat* buf); 80int ki_mkdir(const char* path, mode_t mode); 81int ki_rmdir(const char* path); 82int ki_mount(const char* source, 83 const char* target, 84 const char* filesystemtype, 85 unsigned long mountflags, 86 const void* data); 87int ki_umount(const char* path); 88int ki_open(const char* path, int oflag, mode_t mode); 89int ki_pipe(int pipefds[2]); 90ssize_t ki_read(int fd, void* buf, size_t nbyte); 91ssize_t ki_write(int fd, const void* buf, size_t nbyte); 92int ki_fstat(int fd, struct stat* buf); 93int ki_getdents(int fd, void* buf, unsigned int count); 94int ki_fsync(int fd); 95int ki_fdatasync(int fd); 96int ki_ftruncate(int fd, off_t length); 97int ki_isatty(int fd); 98int ki_close(int fd); 99off_t ki_lseek(int fd, off_t offset, int whence); 100int ki_remove(const char* path); 101int ki_unlink(const char* path); 102int ki_truncate(const char* path, off_t length); 103int ki_lstat(const char* path, struct stat* buf); 104int ki_link(const char* oldpath, const char* newpath); 105int ki_rename(const char* oldpath, const char* newpath); 106int ki_symlink(const char* oldpath, const char* newpath); 107int ki_access(const char* path, int amode); 108int ki_readlink(const char* path, char* buf, size_t count); 109int ki_utimes(const char* path, const struct timeval times[2]); 110int ki_futimes(int fd, const struct timeval times[2]); 111void* ki_mmap(void* addr, 112 size_t length, 113 int prot, 114 int flags, 115 int fd, 116 off_t offset); 117int ki_munmap(void* addr, size_t length); 118int ki_open_resource(const char* file); 119int ki_fcntl(int d, int request, va_list args); 120int ki_ioctl(int d, int request, va_list args); 121int ki_chown(const char* path, uid_t owner, gid_t group); 122int ki_fchown(int fd, uid_t owner, gid_t group); 123int ki_lchown(const char* path, uid_t owner, gid_t group); 124int ki_utime(const char* filename, const struct utimbuf* times); 125int ki_futimens(int fd, const struct timespec times[2]); 126 127int ki_poll(struct pollfd* fds, nfds_t nfds, int timeout); 128int ki_select(int nfds, 129 fd_set* readfds, 130 fd_set* writefds, 131 fd_set* exceptfds, 132 struct timeval* timeout); 133 134int ki_tcflush(int fd, int queue_selector); 135int ki_tcgetattr(int fd, struct termios* termios_p); 136int ki_tcsetattr(int fd, int optional_actions, const struct termios* termios_p); 137int ki_kill(pid_t pid, int sig); 138int ki_killpg(pid_t pid, int sig); 139int ki_sigaction(int signum, 140 const struct sigaction* action, 141 struct sigaction* oaction); 142int ki_sigpause(int sigmask); 143int ki_sigpending(sigset_t* set); 144int ki_sigsuspend(const sigset_t* set); 145sighandler_t ki_signal(int signum, sighandler_t handler); 146sighandler_t ki_sigset(int signum, sighandler_t handler); 147 148#ifdef PROVIDES_SOCKET_API 149/* Socket Functions */ 150int ki_accept(int fd, struct sockaddr* addr, socklen_t* len); 151int ki_bind(int fd, const struct sockaddr* addr, socklen_t len); 152int ki_connect(int fd, const struct sockaddr* addr, socklen_t len); 153void ki_freeaddrinfo(struct addrinfo* res); 154int ki_getaddrinfo(const char* node, 155 const char* service, 156 const struct addrinfo* hints, 157 struct addrinfo** res); 158struct hostent* ki_gethostbyname(const char* name); 159int ki_getnameinfo(const struct sockaddr *sa, 160 socklen_t salen, 161 char *host, 162 size_t hostlen, 163 char *serv, 164 size_t servlen, 165 unsigned int flags); 166int ki_getpeername(int fd, struct sockaddr* addr, socklen_t* len); 167int ki_getsockname(int fd, struct sockaddr* addr, socklen_t* len); 168int ki_getsockopt(int fd, int lvl, int optname, void* optval, socklen_t* len); 169int ki_listen(int fd, int backlog); 170ssize_t ki_recv(int fd, void* buf, size_t len, int flags); 171ssize_t ki_recvfrom(int fd, 172 void* buf, 173 size_t len, 174 int flags, 175 struct sockaddr* addr, 176 socklen_t* addrlen); 177ssize_t ki_recvmsg(int fd, struct msghdr* msg, int flags); 178ssize_t ki_send(int fd, const void* buf, size_t len, int flags); 179ssize_t ki_sendto(int fd, 180 const void* buf, 181 size_t len, 182 int flags, 183 const struct sockaddr* addr, 184 socklen_t addrlen); 185ssize_t ki_sendmsg(int fd, const struct msghdr* msg, int flags); 186int ki_setsockopt(int fd, 187 int lvl, 188 int optname, 189 const void* optval, 190 socklen_t len); 191int ki_shutdown(int fd, int how); 192int ki_socket(int domain, int type, int protocol); 193int ki_socketpair(int domain, int type, int protocl, int* sv); 194#endif /* PROVIDES_SOCKET_API */ 195 196EXTERN_C_END 197 198#endif /* LIBRARIES_NACL_IO_KERNEL_INTERCEPT_H_ */ 199