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.
5 #ifndef LIBRARIES_NACL_IO_KERNEL_WRAP_H_
6 #define LIBRARIES_NACL_IO_KERNEL_WRAP_H_
12 #include <sys/fcntl.h>
13 #include <sys/ioctl.h>
14 #include <sys/types.h>
16 #include "nacl_io/ossignal.h"
17 #include "nacl_io/ossocket.h"
18 #include "nacl_io/ostypes.h"
19 #include "nacl_io/osutime.h"
20 #include "sdk_util/macros.h"
22 #if defined(__native_client__) && defined(__GLIBC__)
23 #if __GLIBC__ == 2 && __GLIBC_MINOR__ == 9
24 #define NACL_GLIBC_OLD
26 #define NACL_GLIBC_NEW
30 // Curently enable NaCl IO IRT Extension when using newer glibc (which
31 // only supports this method interception).
32 #if defined(NACL_GLIBC_NEW)
33 # define NACL_IO_IRT_EXT 1
36 #if defined(__GLIBC__)
37 #include <sys/cdefs.h>
38 #define NOTHROW __THROW
43 // Most kernel intercept functions (ki_*) return -1 and set the global errno.
44 // However, the IRT wrappers are expected to return errno on failure. These
45 // macros are used in the wrappers to check that the ki_ function actually
46 // set errno and to its value.
47 #define RTN_ERRNO_IF(cond) \
53 #define ERRNO_RTN(cond) \
54 RTN_ERRNO_IF(cond < 0); \
58 typedef int chmod_mode_t
;
59 typedef int getcwd_size_t
;
60 typedef int read_ssize_t
;
61 typedef int write_ssize_t
;
64 typedef mode_t chmod_mode_t
;
65 typedef size_t getcwd_size_t
;
66 typedef ssize_t read_ssize_t
;
67 typedef ssize_t write_ssize_t
;
73 void kernel_wrap_init(void);
74 void kernel_wrap_uninit(void);
76 int NAME(access
)(const char* path
, int amode
) NOTHROW
;
77 int NAME(chdir
)(const char* path
) NOTHROW
;
78 int NAME(chmod
)(const char* path
, chmod_mode_t mode
) NOTHROW
;
79 int chown(const char* path
, uid_t owner
, gid_t group
) NOTHROW
;
80 int NAME(close
)(int fd
);
81 int NAME(dup
)(int oldfd
) NOTHROW
;
82 int NAME(dup2
)(int oldfd
, int newfd
) NOTHROW
;
83 int fchown(int fd
, uid_t owner
, gid_t group
) NOTHROW
;
85 int _fstat32(int fd
, struct _stat32
* buf
);
86 int _fstat64(int fd
, struct _stat64
* buf
);
87 int _fstat32i64(int fd
, struct _stat32i64
* buf
);
88 int _fstat64i32(int fd
, struct _stat64i32
* buf
);
89 #elif !defined(__linux__)
91 extern int fstat(int fd
, struct stat
* buf
) NOTHROW
;
94 int ftruncate(int fd
, off_t length
) NOTHROW
;
95 char* NAME(getcwd
)(char* buf
, getcwd_size_t size
) NOTHROW
;
96 char* getwd(char* buf
) NOTHROW
;
97 #if !defined(__BIONIC__)
98 int getdents(int fd
, void* buf
, unsigned int count
) NOTHROW
;
101 int getdents(unsigned int fd
, struct dirent
* buf
, unsigned int count
) NOTHROW
;
103 int NAME(isatty
)(int fd
) NOTHROW
;
104 int lchown(const char* path
, uid_t owner
, gid_t group
) NOTHROW
;
105 int link(const char* oldpath
, const char* newpath
) NOTHROW
;
106 off_t
NAME(lseek
)(int fd
, off_t offset
, int whence
) NOTHROW
;
108 int _mkdir(const char* path
);
110 int mkdir(const char* path
, mode_t mode
) NOTHROW
;
112 void* mmap(void* addr
, size_t length
, int prot
, int flags
, int fd
,
113 off_t offset
) NOTHROW
;
114 int mount(const char* source
, const char* target
, const char* filesystemtype
,
115 unsigned long mountflags
, const void* data
) NOTHROW
;
116 int munmap(void* addr
, size_t length
) NOTHROW
;
117 int NAME(open
)(const char* path
, int oflag
, ...);
118 read_ssize_t
NAME(read
)(int fd
, void* buf
, size_t nbyte
);
119 int remove(const char* path
) NOTHROW
;
120 int NAME(rmdir
)(const char* path
) NOTHROW
;
121 sighandler_t
sigset(int sig
, sighandler_t disp
);
123 int setenv(const char* name
, const char* value
, int overwrite
);
124 int _stat32(const char* path
, struct _stat32
* buf
);
125 int _stat64(const char* path
, struct _stat64
* buf
);
126 int _stat32i64(const char* path
, struct _stat32i64
* buf
);
127 int _stat64i32(const char* path
, struct _stat64i32
* buf
);
128 #elif !defined(__linux__)
129 extern int stat(const char* path
, struct stat
* buf
) NOTHROW
;
131 int symlink(const char* oldpath
, const char* newpath
) NOTHROW
;
132 int umount(const char* path
) NOTHROW
;
133 int NAME(unlink
)(const char* path
) NOTHROW
;
134 int utime(const char* filename
, const struct utimbuf
* times
) NOTHROW
;
135 read_ssize_t
NAME(write
)(int fd
, const void* buf
, size_t nbyte
);
137 #ifdef PROVIDES_SOCKET_API
139 int accept(int fd
, struct sockaddr
* addr
, socklen_t
* len
);
140 int bind(int fd
, const struct sockaddr
* addr
, socklen_t len
);
141 int connect(int fd
, const struct sockaddr
* addr
, socklen_t len
);
142 struct hostent
* gethostbyname(const char* name
);
143 int getpeername(int fd
, struct sockaddr
* addr
, socklen_t
* len
);
144 int getsockname(int fd
, struct sockaddr
* addr
, socklen_t
* len
);
145 int getsockopt(int fd
, int lvl
, int optname
, void* optval
, socklen_t
* len
);
146 int listen(int fd
, int backlog
);
147 ssize_t
recv(int fd
, void* buf
, size_t len
, int flags
);
148 ssize_t
recvfrom(int fd
,
152 struct sockaddr
* addr
,
154 ssize_t
recvmsg(int fd
, struct msghdr
* msg
, int flags
);
155 ssize_t
send(int fd
, const void* buf
, size_t len
, int flags
);
156 ssize_t
sendto(int fd
,
160 const struct sockaddr
* addr
,
162 ssize_t
sendmsg(int fd
, const struct msghdr
* msg
, int flags
);
163 int setsockopt(int fd
, int lvl
, int optname
, const void* optval
, socklen_t len
);
164 int shutdown(int fd
, int how
);
165 int socket(int domain
, int type
, int protocol
);
166 int socketpair(int domain
, int type
, int protocl
, int* sv
);
167 #endif // PROVIDES_SOCKET_API
171 #endif // LIBRARIES_NACL_IO_KERNEL_WRAP_H_