blob: b570c8f136a1ad2e1e7ae78649d863c7a40cbf5b [file] [log] [blame]
Ben Murdochca12bfa2013-07-23 11:17:05 +01001// 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)2a99a7e2013-03-28 15:31:22 +00005#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)a36e5922013-08-05 13:57:33 +010010
11#include "nacl_io/ossocket.h"
Ben Murdoch2385ea32013-08-06 11:01:04 +010012#include "nacl_io/osstat.h"
Ben Murdochbb1529c2013-08-08 10:24:53 +010013#include "nacl_io/ostermios.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000014#include "nacl_io/ostypes.h"
Ben Murdocheb525c52013-07-10 11:40:50 +010015#include "nacl_io/osutime.h"
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010016#include "sdk_util/macros.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000017
18EXTERN_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.
26void ki_init(void* kernel_proxy);
27void ki_init_ppapi(void* kernel_proxy,
28 PP_Instance instance,
29 PPB_GetInterface get_browser_interface);
30int ki_is_initialized();
31void ki_uninit();
32
33int ki_chdir(const char* path);
34char* ki_getcwd(char* buf, size_t size);
35char* ki_getwd(char* buf);
36int ki_dup(int oldfd);
37int ki_dup2(int oldfd, int newfd);
38int ki_chmod(const char* path, mode_t mode);
39int ki_stat(const char* path, struct stat* buf);
40int ki_mkdir(const char* path, mode_t mode);
41int ki_rmdir(const char* path);
42int ki_mount(const char* source, const char* target, const char* filesystemtype,
43 unsigned long mountflags, const void *data);
44int ki_umount(const char* path);
45int ki_open(const char* path, int oflag);
46ssize_t ki_read(int fd, void* buf, size_t nbyte);
47ssize_t ki_write(int fd, const void* buf, size_t nbyte);
48int ki_fstat(int fd, struct stat *buf);
49int ki_getdents(int fd, void* buf, unsigned int count);
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +010050int ki_ftruncate(int fd, off_t length);
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000051int ki_fsync(int fd);
52int ki_isatty(int fd);
53int ki_close(int fd);
54off_t ki_lseek(int fd, off_t offset, int whence);
55int ki_remove(const char* path);
56int ki_unlink(const char* path);
57int ki_access(const char* path, int amode);
58int ki_link(const char* oldpath, const char* newpath);
59int ki_symlink(const char* oldpath, const char* newpath);
60void* ki_mmap(void* addr, size_t length, int prot, int flags, int fd,
61 off_t offset);
62int ki_munmap(void* addr, size_t length);
63int ki_open_resource(const char* file);
Ben Murdocheb525c52013-07-10 11:40:50 +010064int ki_ioctl(int d, int request, char* argp);
65int ki_chown(const char* path, uid_t owner, gid_t group);
66int ki_fchown(int fd, uid_t owner, gid_t group);
67int ki_lchown(const char* path, uid_t owner, gid_t group);
68int ki_utime(const char* filename, const struct utimbuf* times);
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000069
Ben Murdoch32409262013-08-07 11:04:47 +010070int ki_poll(struct pollfd *fds, nfds_t nfds, int timeout);
71int ki_select(int nfds, fd_set* readfds, fd_set* writefds,
72 fd_set* exceptfds, struct timeval* timeout);
73
Ben Murdochbb1529c2013-08-08 10:24:53 +010074int ki_tcflush(int fd, int queue_selector);
75int ki_tcgetattr(int fd, struct termios* termios_p);
76int ki_tcsetattr(int fd, int optional_actions,
77 const struct termios *termios_p);
78
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +010079#ifdef PROVIDES_SOCKET_API
80// Socket Functions
81int ki_accept(int fd, struct sockaddr* addr, socklen_t* len);
82int ki_bind(int fd, const struct sockaddr* addr, socklen_t len);
83int ki_connect(int fd, const struct sockaddr* addr, socklen_t len);
Ben Murdochbb1529c2013-08-08 10:24:53 +010084struct hostent* ki_gethostbyname(const char* name);
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +010085int ki_getpeername(int fd, struct sockaddr* addr, socklen_t* len);
86int ki_getsockname(int fd, struct sockaddr* addr, socklen_t* len);
87int ki_getsockopt(int fd, int lvl, int optname, void* optval, socklen_t* len);
Ben Murdochbb1529c2013-08-08 10:24:53 +010088void ki_herror(const char *s);
89const char *ki_hstrerror(int err);
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +010090int ki_listen(int fd, int backlog);
91ssize_t ki_recv(int fd, void* buf, size_t len, int flags);
92ssize_t ki_recvfrom(int fd, void* buf, size_t len, int flags,
93 struct sockaddr* addr, socklen_t* addrlen);
94ssize_t ki_recvmsg(int fd, struct msghdr* msg, int flags);
95ssize_t ki_send(int fd, const void* buf, size_t len, int flags);
96ssize_t ki_sendto(int fd, const void* buf, size_t len, int flags,
97 const struct sockaddr* addr, socklen_t addrlen);
98ssize_t ki_sendmsg(int fd, const struct msghdr* msg, int flags);
99int ki_setsockopt(int fd, int lvl, int optname, const void* optval,
100 socklen_t len);
101int ki_shutdown(int fd, int how);
102int ki_socket(int domain, int type, int protocol);
103int ki_socketpair(int domain, int type, int protocl, int* sv);
Ben Murdochbb1529c2013-08-08 10:24:53 +0100104#endif // PROVIDES_SOCKET_API
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +0100105
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000106EXTERN_C_END
107
108#endif // LIBRARIES_NACL_IO_KERNEL_INTERCEPT_H_