ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / native_client_sdk / src / libraries / nacl_io / kernel_wrap.h
blob2e2265cc2afb9cd05013613e20362df165ba0f6e
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_
8 #include <assert.h>
9 #include <signal.h>
10 #include <stdint.h>
11 #include <stdlib.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 // Curently enable NaCl IO IRT Extension when using newlib
23 #if defined(__native_client__) && defined(_NEWLIB_VERSION)
24 # define NACL_IO_IRT_EXT 1
25 #endif
27 #if defined(__GLIBC__)
28 #include <sys/cdefs.h>
29 #define NOTHROW __THROW
30 #else
31 #define NOTHROW
32 #endif
34 // Most kernel intercept functions (ki_*) return -1 and set the global errno.
35 // However, the IRT wrappers are expected to return errno on failure. These
36 // macros are used in the wrappers to check that the ki_ function actually
37 // set errno and to its value.
38 #define RTN_ERRNO_IF(cond) \
39 if (cond) { \
40 assert(errno != 0); \
41 return errno; \
44 #define ERRNO_RTN(cond) \
45 RTN_ERRNO_IF(cond < 0); \
46 return 0;
48 #if defined(WIN32)
49 typedef int chmod_mode_t;
50 typedef int getcwd_size_t;
51 typedef int read_ssize_t;
52 typedef int write_ssize_t;
53 #define NAME(x) _##x
54 #else
55 typedef mode_t chmod_mode_t;
56 typedef size_t getcwd_size_t;
57 typedef ssize_t read_ssize_t;
58 typedef ssize_t write_ssize_t;
59 #define NAME(x) x
60 #endif
62 EXTERN_C_BEGIN
64 void kernel_wrap_init(void);
65 void kernel_wrap_uninit(void);
67 int NAME(access)(const char* path, int amode) NOTHROW;
68 int NAME(chdir)(const char* path) NOTHROW;
69 int NAME(chmod)(const char* path, chmod_mode_t mode) NOTHROW;
70 int chown(const char* path, uid_t owner, gid_t group) NOTHROW;
71 int NAME(close)(int fd);
72 int NAME(dup)(int oldfd) NOTHROW;
73 int NAME(dup2)(int oldfd, int newfd) NOTHROW;
74 int fchown(int fd, uid_t owner, gid_t group) NOTHROW;
75 #if defined(WIN32)
76 int _fstat32(int fd, struct _stat32* buf);
77 int _fstat64(int fd, struct _stat64* buf);
78 int _fstat32i64(int fd, struct _stat32i64* buf);
79 int _fstat64i32(int fd, struct _stat64i32* buf);
80 #elif !defined(__linux__)
81 struct stat;
82 extern int fstat(int fd, struct stat* buf) NOTHROW;
83 #endif
84 int fsync(int fd);
85 int ftruncate(int fd, off_t length) NOTHROW;
86 char* NAME(getcwd)(char* buf, getcwd_size_t size) NOTHROW;
87 char* getwd(char* buf) NOTHROW;
88 #if !defined(__BIONIC__)
89 int getdents(int fd, void* buf, unsigned int count) NOTHROW;
90 #else
91 struct dirent;
92 int getdents(unsigned int fd, struct dirent* buf, unsigned int count) NOTHROW;
93 #endif
94 int NAME(isatty)(int fd) NOTHROW;
95 int lchown(const char* path, uid_t owner, gid_t group) NOTHROW;
96 int link(const char* oldpath, const char* newpath) NOTHROW;
97 off_t NAME(lseek)(int fd, off_t offset, int whence) NOTHROW;
98 #if defined(WIN32)
99 int _mkdir(const char* path);
100 #else
101 int mkdir(const char* path, mode_t mode) NOTHROW;
102 #endif
103 void* mmap(void* addr, size_t length, int prot, int flags, int fd,
104 off_t offset) NOTHROW;
105 int mount(const char* source, const char* target, const char* filesystemtype,
106 unsigned long mountflags, const void* data) NOTHROW;
107 int munmap(void* addr, size_t length) NOTHROW;
108 int NAME(open)(const char* path, int oflag, ...);
109 read_ssize_t NAME(read)(int fd, void* buf, size_t nbyte);
110 int remove(const char* path) NOTHROW;
111 int NAME(rmdir)(const char* path) NOTHROW;
112 sighandler_t sigset(int sig, sighandler_t disp);
113 #if defined(WIN32)
114 int setenv(const char* name, const char* value, int overwrite);
115 int _stat32(const char* path, struct _stat32* buf);
116 int _stat64(const char* path, struct _stat64* buf);
117 int _stat32i64(const char* path, struct _stat32i64* buf);
118 int _stat64i32(const char* path, struct _stat64i32* buf);
119 #elif !defined(__linux__)
120 extern int stat(const char* path, struct stat* buf) NOTHROW;
121 #endif
122 int symlink(const char* oldpath, const char* newpath) NOTHROW;
123 int umount(const char* path) NOTHROW;
124 int NAME(unlink)(const char* path) NOTHROW;
125 int utime(const char* filename, const struct utimbuf* times) NOTHROW;
126 read_ssize_t NAME(write)(int fd, const void* buf, size_t nbyte);
128 #ifdef PROVIDES_SOCKET_API
129 // Socket Functions
130 int accept(int fd, struct sockaddr* addr, socklen_t* len);
131 int bind(int fd, const struct sockaddr* addr, socklen_t len);
132 int connect(int fd, const struct sockaddr* addr, socklen_t len);
133 struct hostent* gethostbyname(const char* name);
134 int getpeername(int fd, struct sockaddr* addr, socklen_t* len);
135 int getsockname(int fd, struct sockaddr* addr, socklen_t* len);
136 int getsockopt(int fd, int lvl, int optname, void* optval, socklen_t* len);
137 int listen(int fd, int backlog);
138 ssize_t recv(int fd, void* buf, size_t len, int flags);
139 ssize_t recvfrom(int fd,
140 void* buf,
141 size_t len,
142 int flags,
143 struct sockaddr* addr,
144 socklen_t* addrlen);
145 ssize_t recvmsg(int fd, struct msghdr* msg, int flags);
146 ssize_t send(int fd, const void* buf, size_t len, int flags);
147 ssize_t sendto(int fd,
148 const void* buf,
149 size_t len,
150 int flags,
151 const struct sockaddr* addr,
152 socklen_t addrlen);
153 ssize_t sendmsg(int fd, const struct msghdr* msg, int flags);
154 int setsockopt(int fd, int lvl, int optname, const void* optval, socklen_t len);
155 int shutdown(int fd, int how);
156 int socket(int domain, int type, int protocol);
157 int socketpair(int domain, int type, int protocl, int* sv);
158 #endif // PROVIDES_SOCKET_API
160 EXTERN_C_END
162 #endif // LIBRARIES_NACL_IO_KERNEL_WRAP_H_