Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 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 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 5 | #ifndef LIBRARIES_NACL_IO_KERNEL_INTERCEPT_H_ |
| 6 | #define LIBRARIES_NACL_IO_KERNEL_INTERCEPT_H_ |
| 7 | |
| 8 | #include <ppapi/c/ppb.h> |
| 9 | #include <ppapi/c/pp_instance.h> |
Torne (Richard Coles) | a36e592 | 2013-08-05 13:57:33 +0100 | [diff] [blame] | 10 | |
| 11 | #include "nacl_io/ossocket.h" |
Ben Murdoch | 2385ea3 | 2013-08-06 11:01:04 +0100 | [diff] [blame] | 12 | #include "nacl_io/osstat.h" |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 13 | #include "nacl_io/ostermios.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 14 | #include "nacl_io/ostypes.h" |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 15 | #include "nacl_io/osutime.h" |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 16 | #include "sdk_util/macros.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 17 | |
| 18 | EXTERN_C_BEGIN |
| 19 | |
| 20 | // The kernel intercept module provides a C->C++ thunk between the libc |
| 21 | // kernel calls and the KernelProxy singleton. |
| 22 | |
| 23 | // ki_init must be called with an uninitialized KernelProxy object. Calling |
| 24 | // with NULL will instantiate a default kernel proxy object. ki_init must |
| 25 | // be called before any other ki_XXX function can be used. |
| 26 | void ki_init(void* kernel_proxy); |
| 27 | void ki_init_ppapi(void* kernel_proxy, |
| 28 | PP_Instance instance, |
| 29 | PPB_GetInterface get_browser_interface); |
| 30 | int ki_is_initialized(); |
| 31 | void ki_uninit(); |
| 32 | |
| 33 | int ki_chdir(const char* path); |
| 34 | char* ki_getcwd(char* buf, size_t size); |
| 35 | char* ki_getwd(char* buf); |
| 36 | int ki_dup(int oldfd); |
| 37 | int ki_dup2(int oldfd, int newfd); |
| 38 | int ki_chmod(const char* path, mode_t mode); |
| 39 | int ki_stat(const char* path, struct stat* buf); |
| 40 | int ki_mkdir(const char* path, mode_t mode); |
| 41 | int ki_rmdir(const char* path); |
| 42 | int ki_mount(const char* source, const char* target, const char* filesystemtype, |
| 43 | unsigned long mountflags, const void *data); |
| 44 | int ki_umount(const char* path); |
| 45 | int ki_open(const char* path, int oflag); |
| 46 | ssize_t ki_read(int fd, void* buf, size_t nbyte); |
| 47 | ssize_t ki_write(int fd, const void* buf, size_t nbyte); |
| 48 | int ki_fstat(int fd, struct stat *buf); |
| 49 | int ki_getdents(int fd, void* buf, unsigned int count); |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 50 | int ki_ftruncate(int fd, off_t length); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 51 | int ki_fsync(int fd); |
| 52 | int ki_isatty(int fd); |
| 53 | int ki_close(int fd); |
| 54 | off_t ki_lseek(int fd, off_t offset, int whence); |
| 55 | int ki_remove(const char* path); |
| 56 | int ki_unlink(const char* path); |
| 57 | int ki_access(const char* path, int amode); |
| 58 | int ki_link(const char* oldpath, const char* newpath); |
| 59 | int ki_symlink(const char* oldpath, const char* newpath); |
| 60 | void* ki_mmap(void* addr, size_t length, int prot, int flags, int fd, |
| 61 | off_t offset); |
| 62 | int ki_munmap(void* addr, size_t length); |
| 63 | int ki_open_resource(const char* file); |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 64 | int ki_ioctl(int d, int request, char* argp); |
| 65 | int ki_chown(const char* path, uid_t owner, gid_t group); |
| 66 | int ki_fchown(int fd, uid_t owner, gid_t group); |
| 67 | int ki_lchown(const char* path, uid_t owner, gid_t group); |
| 68 | int ki_utime(const char* filename, const struct utimbuf* times); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 69 | |
Ben Murdoch | 3240926 | 2013-08-07 11:04:47 +0100 | [diff] [blame] | 70 | int ki_poll(struct pollfd *fds, nfds_t nfds, int timeout); |
| 71 | int ki_select(int nfds, fd_set* readfds, fd_set* writefds, |
| 72 | fd_set* exceptfds, struct timeval* timeout); |
| 73 | |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 74 | int ki_tcflush(int fd, int queue_selector); |
| 75 | int ki_tcgetattr(int fd, struct termios* termios_p); |
| 76 | int ki_tcsetattr(int fd, int optional_actions, |
| 77 | const struct termios *termios_p); |
| 78 | |
Torne (Richard Coles) | a36e592 | 2013-08-05 13:57:33 +0100 | [diff] [blame] | 79 | #ifdef PROVIDES_SOCKET_API |
| 80 | // Socket Functions |
| 81 | int ki_accept(int fd, struct sockaddr* addr, socklen_t* len); |
| 82 | int ki_bind(int fd, const struct sockaddr* addr, socklen_t len); |
| 83 | int ki_connect(int fd, const struct sockaddr* addr, socklen_t len); |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 84 | struct hostent* ki_gethostbyname(const char* name); |
Torne (Richard Coles) | a36e592 | 2013-08-05 13:57:33 +0100 | [diff] [blame] | 85 | int ki_getpeername(int fd, struct sockaddr* addr, socklen_t* len); |
| 86 | int ki_getsockname(int fd, struct sockaddr* addr, socklen_t* len); |
| 87 | int ki_getsockopt(int fd, int lvl, int optname, void* optval, socklen_t* len); |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 88 | void ki_herror(const char *s); |
| 89 | const char *ki_hstrerror(int err); |
Torne (Richard Coles) | a36e592 | 2013-08-05 13:57:33 +0100 | [diff] [blame] | 90 | int ki_listen(int fd, int backlog); |
| 91 | ssize_t ki_recv(int fd, void* buf, size_t len, int flags); |
| 92 | ssize_t ki_recvfrom(int fd, void* buf, size_t len, int flags, |
| 93 | struct sockaddr* addr, socklen_t* addrlen); |
| 94 | ssize_t ki_recvmsg(int fd, struct msghdr* msg, int flags); |
| 95 | ssize_t ki_send(int fd, const void* buf, size_t len, int flags); |
| 96 | ssize_t ki_sendto(int fd, const void* buf, size_t len, int flags, |
| 97 | const struct sockaddr* addr, socklen_t addrlen); |
| 98 | ssize_t ki_sendmsg(int fd, const struct msghdr* msg, int flags); |
| 99 | int ki_setsockopt(int fd, int lvl, int optname, const void* optval, |
| 100 | socklen_t len); |
| 101 | int ki_shutdown(int fd, int how); |
| 102 | int ki_socket(int domain, int type, int protocol); |
| 103 | int ki_socketpair(int domain, int type, int protocl, int* sv); |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 104 | #endif // PROVIDES_SOCKET_API |
Torne (Richard Coles) | a36e592 | 2013-08-05 13:57:33 +0100 | [diff] [blame] | 105 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 106 | EXTERN_C_END |
| 107 | |
| 108 | #endif // LIBRARIES_NACL_IO_KERNEL_INTERCEPT_H_ |