- add sources.
[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 // The kernel intercept module provides a C->C++ thunk between the libc
25 // kernel calls and the KernelProxy singleton.
26
27 // ki_init must be called with an uninitialized KernelProxy object.  Calling
28 // with NULL will instantiate a default kernel proxy object.  ki_init must
29 // be called before any other ki_XXX function can be used.
30 void ki_init(void* kernel_proxy);
31 void ki_init_ppapi(void* kernel_proxy,
32                    PP_Instance instance,
33                    PPB_GetInterface get_browser_interface);
34 int ki_is_initialized();
35 void ki_uninit();
36
37 int ki_chdir(const char* path);
38 char* ki_getcwd(char* buf, size_t size);
39 char* ki_getwd(char* buf);
40 int ki_dup(int oldfd);
41 int ki_dup2(int oldfd, int newfd);
42 int ki_chmod(const char* path, mode_t mode);
43 int ki_fchdir(int fd);
44 int ki_fchmod(int fd, mode_t mode);
45 int ki_stat(const char* path, struct stat* buf);
46 int ki_mkdir(const char* path, mode_t mode);
47 int ki_rmdir(const char* path);
48 int ki_mount(const char* source, const char* target, const char* filesystemtype,
49              unsigned long mountflags, const void *data);
50 int ki_umount(const char* path);
51 int ki_open(const char* path, int oflag);
52 int ki_pipe(int pipefds[2]);
53 ssize_t ki_read(int fd, void* buf, size_t nbyte);
54 ssize_t ki_write(int fd, const void* buf, size_t nbyte);
55 int ki_fstat(int fd, struct stat *buf);
56 int ki_getdents(int fd, void* buf, unsigned int count);
57 int ki_fsync(int fd);
58 int ki_fdatasync(int fd);
59 int ki_ftruncate(int fd, off_t length);
60 int ki_isatty(int fd);
61 int ki_close(int fd);
62 off_t ki_lseek(int fd, off_t offset, int whence);
63 int ki_remove(const char* path);
64 int ki_unlink(const char* path);
65 int ki_truncate(const char* path, off_t length);
66 int ki_lstat(const char* path, struct stat* buf);
67 int ki_link(const char* oldpath, const char* newpath);
68 int ki_rename(const char* oldpath, const char* newpath);
69 int ki_symlink(const char* oldpath, const char* newpath);
70 int ki_access(const char* path, int amode);
71 int ki_readlink(const char *path, char *buf, size_t count);
72 int ki_utimes(const char *path, const struct timeval times[2]);
73 void* ki_mmap(void* addr, size_t length, int prot, int flags, int fd,
74               off_t offset);
75 int ki_munmap(void* addr, size_t length);
76 int ki_open_resource(const char* file);
77 int ki_fcntl(int d, int request, va_list args);
78 int ki_ioctl(int d, int request, va_list args);
79 int ki_chown(const char* path, uid_t owner, gid_t group);
80 int ki_fchown(int fd, uid_t owner, gid_t group);
81 int ki_lchown(const char* path, uid_t owner, gid_t group);
82 int ki_utime(const char* filename, const struct utimbuf* times);
83
84 int ki_poll(struct pollfd *fds, nfds_t nfds, int timeout);
85 int ki_select(int nfds, fd_set* readfds, fd_set* writefds,
86               fd_set* exceptfds, struct timeval* timeout);
87
88 int ki_tcflush(int fd, int queue_selector);
89 int ki_tcgetattr(int fd, struct termios* termios_p);
90 int ki_tcsetattr(int fd, int optional_actions,
91                  const struct termios *termios_p);
92 int ki_kill(pid_t pid, int sig);
93 int ki_killpg(pid_t pid, int sig);
94 int ki_sigaction(int, const struct sigaction*, struct sigaction*);
95 int ki_sigpause(int sigmask);
96 int ki_sigpending(sigset_t* set);
97 int ki_sigsuspend(const sigset_t* set);
98 sighandler_t ki_signal(int signum, sighandler_t handler);
99 sighandler_t ki_sigset(int signum, sighandler_t handler);
100
101 #ifdef PROVIDES_SOCKET_API
102 // Socket Functions
103 int ki_accept(int fd, struct sockaddr* addr, socklen_t* len);
104 int ki_bind(int fd, const struct sockaddr* addr, socklen_t len);
105 int ki_connect(int fd, const struct sockaddr* addr, socklen_t len);
106 struct hostent* ki_gethostbyname(const char* name);
107 int ki_getpeername(int fd, struct sockaddr* addr, socklen_t* len);
108 int ki_getsockname(int fd, struct sockaddr* addr, socklen_t* len);
109 int ki_getsockopt(int fd, int lvl, int optname, void* optval, socklen_t* len);
110 int ki_listen(int fd, int backlog);
111 ssize_t ki_recv(int fd, void* buf, size_t len, int flags);
112 ssize_t ki_recvfrom(int fd, void* buf, size_t len, int flags,
113                     struct sockaddr* addr, socklen_t* addrlen);
114 ssize_t ki_recvmsg(int fd, struct msghdr* msg, int flags);
115 ssize_t ki_send(int fd, const void* buf, size_t len, int flags);
116 ssize_t ki_sendto(int fd, const void* buf, size_t len, int flags,
117                   const struct sockaddr* addr, socklen_t addrlen);
118 ssize_t ki_sendmsg(int fd, const struct msghdr* msg, int flags);
119 int ki_setsockopt(int fd, int lvl, int optname, const void* optval,
120                   socklen_t len);
121 int ki_shutdown(int fd, int how);
122 int ki_socket(int domain, int type, int protocol);
123 int ki_socketpair(int domain, int type, int protocl, int* sv);
124 #endif  // PROVIDES_SOCKET_API
125
126 EXTERN_C_END
127
128 #endif  // LIBRARIES_NACL_IO_KERNEL_INTERCEPT_H_