Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / native_client_sdk / src / libraries / nacl_io / kernel_intercept.h
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
22 EXTERN_C_BEGIN
23
24 #ifdef __cplusplus
25 namespace nacl_io {
26 class KernelProxy;
27 }
28 #endif
29
30 struct 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  */
42 int 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  */
49 int ki_push_state_for_testing(void);
50
51 int ki_pop_state_for_testing(void);
52
53 int 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  */
61 int ki_init_interface(void* kernel_proxy, void* pepper_interface);
62
63 #ifdef __cplusplus
64 nacl_io::KernelProxy* ki_get_proxy();
65 #endif
66
67 int ki_is_initialized(void);
68 int ki_uninit(void);
69
70 int ki_chdir(const char* path);
71 void ki_exit(int status);
72 char* ki_getcwd(char* buf, size_t size);
73 char* ki_getwd(char* buf);
74 int ki_dup(int oldfd);
75 int ki_dup2(int oldfd, int newfd);
76 int ki_chmod(const char* path, mode_t mode);
77 int ki_fchdir(int fd);
78 int ki_fchmod(int fd, mode_t mode);
79 int ki_stat(const char* path, struct stat* buf);
80 int ki_mkdir(const char* path, mode_t mode);
81 int ki_rmdir(const char* path);
82 int ki_mount(const char* source,
83              const char* target,
84              const char* filesystemtype,
85              unsigned long mountflags,
86              const void* data);
87 int ki_umount(const char* path);
88 int ki_open(const char* path, int oflag, mode_t mode);
89 int ki_pipe(int pipefds[2]);
90 ssize_t ki_read(int fd, void* buf, size_t nbyte);
91 ssize_t ki_write(int fd, const void* buf, size_t nbyte);
92 int ki_fstat(int fd, struct stat* buf);
93 int ki_getdents(int fd, void* buf, unsigned int count);
94 int ki_fsync(int fd);
95 int ki_fdatasync(int fd);
96 int ki_ftruncate(int fd, off_t length);
97 int ki_isatty(int fd);
98 int ki_close(int fd);
99 off_t ki_lseek(int fd, off_t offset, int whence);
100 int ki_remove(const char* path);
101 int ki_unlink(const char* path);
102 int ki_truncate(const char* path, off_t length);
103 int ki_lstat(const char* path, struct stat* buf);
104 int ki_link(const char* oldpath, const char* newpath);
105 int ki_rename(const char* oldpath, const char* newpath);
106 int ki_symlink(const char* oldpath, const char* newpath);
107 int ki_access(const char* path, int amode);
108 int ki_readlink(const char* path, char* buf, size_t count);
109 int ki_utimes(const char* path, const struct timeval times[2]);
110 int ki_futimes(int fd, const struct timeval times[2]);
111 void* ki_mmap(void* addr,
112               size_t length,
113               int prot,
114               int flags,
115               int fd,
116               off_t offset);
117 int ki_munmap(void* addr, size_t length);
118 int ki_open_resource(const char* file);
119 int ki_fcntl(int d, int request, va_list args);
120 int ki_ioctl(int d, int request, va_list args);
121 int ki_chown(const char* path, uid_t owner, gid_t group);
122 int ki_fchown(int fd, uid_t owner, gid_t group);
123 int ki_lchown(const char* path, uid_t owner, gid_t group);
124 int ki_utime(const char* filename, const struct utimbuf* times);
125 int ki_futimens(int fd, const struct timespec times[2]);
126 mode_t ki_umask(mode_t mask);
127
128 int ki_poll(struct pollfd* fds, nfds_t nfds, int timeout);
129 int ki_select(int nfds,
130               fd_set* readfds,
131               fd_set* writefds,
132               fd_set* exceptfds,
133               struct timeval* timeout);
134
135 int ki_tcflush(int fd, int queue_selector);
136 int ki_tcgetattr(int fd, struct termios* termios_p);
137 int ki_tcsetattr(int fd, int optional_actions, const struct termios* termios_p);
138 int ki_kill(pid_t pid, int sig);
139 int ki_killpg(pid_t pid, int sig);
140 int ki_sigaction(int signum,
141                  const struct sigaction* action,
142                  struct sigaction* oaction);
143 int ki_sigpause(int sigmask);
144 int ki_sigpending(sigset_t* set);
145 int ki_sigsuspend(const sigset_t* set);
146 sighandler_t ki_signal(int signum, sighandler_t handler);
147 sighandler_t ki_sigset(int signum, sighandler_t handler);
148
149 #ifdef PROVIDES_SOCKET_API
150 /* Socket Functions */
151 int ki_accept(int fd, struct sockaddr* addr, socklen_t* len);
152 int ki_bind(int fd, const struct sockaddr* addr, socklen_t len);
153 int ki_connect(int fd, const struct sockaddr* addr, socklen_t len);
154 void ki_freeaddrinfo(struct addrinfo* res);
155 int ki_getaddrinfo(const char* node,
156                    const char* service,
157                    const struct addrinfo* hints,
158                    struct addrinfo** res);
159 struct hostent* ki_gethostbyname(const char* name);
160 int ki_getnameinfo(const struct sockaddr *sa,
161                    socklen_t salen,
162                    char *host,
163                    size_t hostlen,
164                    char *serv,
165                    size_t servlen,
166                    unsigned int flags);
167 int ki_getpeername(int fd, struct sockaddr* addr, socklen_t* len);
168 int ki_getsockname(int fd, struct sockaddr* addr, socklen_t* len);
169 int ki_getsockopt(int fd, int lvl, int optname, void* optval, socklen_t* len);
170 int ki_listen(int fd, int backlog);
171 ssize_t ki_recv(int fd, void* buf, size_t len, int flags);
172 ssize_t ki_recvfrom(int fd,
173                     void* buf,
174                     size_t len,
175                     int flags,
176                     struct sockaddr* addr,
177                     socklen_t* addrlen);
178 ssize_t ki_recvmsg(int fd, struct msghdr* msg, int flags);
179 ssize_t ki_send(int fd, const void* buf, size_t len, int flags);
180 ssize_t ki_sendto(int fd,
181                   const void* buf,
182                   size_t len,
183                   int flags,
184                   const struct sockaddr* addr,
185                   socklen_t addrlen);
186 ssize_t ki_sendmsg(int fd, const struct msghdr* msg, int flags);
187 int ki_setsockopt(int fd,
188                   int lvl,
189                   int optname,
190                   const void* optval,
191                   socklen_t len);
192 int ki_shutdown(int fd, int how);
193 int ki_socket(int domain, int type, int protocol);
194 int ki_socketpair(int domain, int type, int protocl, int* sv);
195 #endif  /* PROVIDES_SOCKET_API */
196
197 EXTERN_C_END
198
199 #endif  /* LIBRARIES_NACL_IO_KERNEL_INTERCEPT_H_ */