The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * * Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * * Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in |
| 12 | * the documentation and/or other materials provided with the |
| 13 | * distribution. |
| 14 | * |
| 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 16 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 17 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 18 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 19 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
| 22 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
| 23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 25 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 26 | * SUCH DAMAGE. |
| 27 | */ |
Elliott Hughes | f4c948a | 2014-08-19 11:16:41 -0700 | [diff] [blame] | 28 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 29 | #ifndef _UNISTD_H_ |
| 30 | #define _UNISTD_H_ |
| 31 | |
| 32 | #include <stddef.h> |
| 33 | #include <sys/cdefs.h> |
| 34 | #include <sys/types.h> |
| 35 | #include <sys/select.h> |
| 36 | #include <sys/sysconf.h> |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 37 | |
Elliott Hughes | 1ed337d | 2015-02-02 14:02:09 -0800 | [diff] [blame] | 38 | #include <machine/posix_limits.h> |
| 39 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 40 | __BEGIN_DECLS |
| 41 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 42 | #define STDIN_FILENO 0 |
| 43 | #define STDOUT_FILENO 1 |
| 44 | #define STDERR_FILENO 2 |
| 45 | |
Elliott Hughes | 1ed337d | 2015-02-02 14:02:09 -0800 | [diff] [blame] | 46 | #define F_OK 0 |
| 47 | #define X_OK 1 |
| 48 | #define W_OK 2 |
| 49 | #define R_OK 4 |
| 50 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 51 | #define SEEK_SET 0 |
| 52 | #define SEEK_CUR 1 |
| 53 | #define SEEK_END 2 |
| 54 | |
Elliott Hughes | a186b2e | 2014-09-22 14:49:07 -0700 | [diff] [blame] | 55 | #define _PC_FILESIZEBITS 0 |
| 56 | #define _PC_LINK_MAX 1 |
| 57 | #define _PC_MAX_CANON 2 |
| 58 | #define _PC_MAX_INPUT 3 |
| 59 | #define _PC_NAME_MAX 4 |
| 60 | #define _PC_PATH_MAX 5 |
| 61 | #define _PC_PIPE_BUF 6 |
| 62 | #define _PC_2_SYMLINKS 7 |
| 63 | #define _PC_ALLOC_SIZE_MIN 8 |
| 64 | #define _PC_REC_INCR_XFER_SIZE 9 |
| 65 | #define _PC_REC_MAX_XFER_SIZE 10 |
| 66 | #define _PC_REC_MIN_XFER_SIZE 11 |
| 67 | #define _PC_REC_XFER_ALIGN 12 |
| 68 | #define _PC_SYMLINK_MAX 13 |
| 69 | #define _PC_CHOWN_RESTRICTED 14 |
| 70 | #define _PC_NO_TRUNC 15 |
| 71 | #define _PC_VDISABLE 16 |
| 72 | #define _PC_ASYNC_IO 17 |
| 73 | #define _PC_PRIO_IO 18 |
| 74 | #define _PC_SYNC_IO 19 |
| 75 | |
Elliott Hughes | 58d9e28 | 2014-04-22 17:41:00 -0700 | [diff] [blame] | 76 | extern char** environ; |
| 77 | |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 78 | extern __noreturn void _exit(int __status); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 79 | |
| 80 | extern pid_t fork(void); |
| 81 | extern pid_t vfork(void); |
| 82 | extern pid_t getpid(void); |
Elliott Hughes | b27a840 | 2014-06-10 20:47:49 -0700 | [diff] [blame] | 83 | extern pid_t gettid(void) __pure2; |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 84 | extern pid_t getpgid(pid_t __pid); |
| 85 | extern int setpgid(pid_t __pid, pid_t __pgid); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 86 | extern pid_t getppid(void); |
| 87 | extern pid_t getpgrp(void); |
| 88 | extern int setpgrp(void); |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 89 | extern pid_t getsid(pid_t __pid) __INTRODUCED_IN(21); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 90 | extern pid_t setsid(void); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 91 | |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 92 | extern int execv(const char* __path, char* const* __argv); |
| 93 | extern int execvp(const char* __file, char* const* __argv); |
| 94 | extern int execvpe(const char* __file, char* const* __argv, char* const* __envp) |
| 95 | __INTRODUCED_IN(21); |
| 96 | extern int execve(const char* __file, char* const* __argv, char* const* __envp); |
| 97 | extern int execl(const char* __path, const char* __arg0, ...); |
| 98 | extern int execlp(const char* __file, const char* __arg0, ...); |
| 99 | extern int execle(const char* __path, const char* __arg0, ...); |
David 'Digit' Turner | b083bb5 | 2011-05-26 02:46:41 +0200 | [diff] [blame] | 100 | |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 101 | extern int nice(int __incr); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 102 | |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 103 | extern int setuid(uid_t __uid); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 104 | extern uid_t getuid(void); |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 105 | extern int seteuid(uid_t __uid); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 106 | extern uid_t geteuid(void); |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 107 | extern int setgid(gid_t __gid); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 108 | extern gid_t getgid(void); |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 109 | extern int setegid(gid_t __gid); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 110 | extern gid_t getegid(void); |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 111 | extern int getgroups(int __size, gid_t* __list); |
| 112 | extern int setgroups(size_t __size, const gid_t* __list); |
| 113 | extern int setreuid(uid_t __ruid, uid_t __euid); |
| 114 | extern int setregid(gid_t __rgid, gid_t __egid); |
| 115 | extern int setresuid(uid_t __ruid, uid_t __euid, uid_t __suid); |
| 116 | extern int setresgid(gid_t __rgid, gid_t __egid, gid_t __sgid); |
| 117 | extern int getresuid(uid_t* __ruid, uid_t* __euid, uid_t* __suid); |
| 118 | extern int getresgid(gid_t* __rgid, gid_t* __egid, gid_t* __sgid); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 119 | extern char* getlogin(void); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 120 | |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 121 | extern long fpathconf(int __fd, int __name); |
| 122 | extern long pathconf(const char* __path, int __name); |
Elliott Hughes | a186b2e | 2014-09-22 14:49:07 -0700 | [diff] [blame] | 123 | |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 124 | extern int access(const char* __path, int __mode); |
| 125 | extern int faccessat(int __dirfd, const char* __path, int __mode, int __flags) |
| 126 | __INTRODUCED_IN(21); |
| 127 | extern int link(const char* __oldpath, const char* __newpath); |
| 128 | extern int linkat(int __olddirfd, const char* __oldpath, int __newdirfd, |
| 129 | const char* __newpath, int __flags) __INTRODUCED_IN(21); |
| 130 | extern int unlink(const char* __path); |
| 131 | extern int unlinkat(int __dirfd, const char* __path, int __flags); |
| 132 | extern int chdir(const char* __path); |
| 133 | extern int fchdir(int __fd); |
| 134 | extern int rmdir(const char* __path); |
| 135 | extern int pipe(int* __pipefd); |
Elliott Hughes | 5f5cc45 | 2014-08-18 16:04:03 -0700 | [diff] [blame] | 136 | #if defined(__USE_GNU) |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 137 | extern int pipe2(int* __pipefd, int __flags) __INTRODUCED_IN(9); |
David 'Digit' Turner | 275cd48 | 2010-09-27 17:33:08 +0200 | [diff] [blame] | 138 | #endif |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 139 | extern int chroot(const char* __path); |
| 140 | extern int symlink(const char* __oldpath, const char* __newpath); |
| 141 | extern int symlinkat(const char* __oldpath, int __newdirfd, |
| 142 | const char* __newpath) __INTRODUCED_IN(21); |
| 143 | extern ssize_t readlink(const char* __path, char* __buf, size_t __bufsiz); |
| 144 | extern ssize_t readlinkat(int __dirfd, const char* __path, char* __buf, |
| 145 | size_t __bufsiz) __INTRODUCED_IN(21); |
| 146 | extern int chown(const char* __path, uid_t __owner, gid_t __group); |
| 147 | extern int fchown(int __fd, uid_t __owner, gid_t __group); |
| 148 | extern int fchownat(int __dirfd, const char* __path, uid_t __owner, |
| 149 | gid_t __group, int __flags); |
| 150 | extern int lchown(const char* __path, uid_t __owner, gid_t __group); |
| 151 | extern char* getcwd(char* __buf, size_t __size); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 152 | |
| 153 | extern int sync(void); |
| 154 | |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 155 | extern int close(int __fd); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 156 | |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 157 | extern ssize_t read(int __fd, void* __buf, size_t __count); |
| 158 | extern ssize_t write(int __fd, const void* __buf, size_t __count); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 159 | |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 160 | extern int dup(int __oldfd); |
| 161 | extern int dup2(int __oldfd, int __newfd); |
| 162 | extern int dup3(int __oldfd, int __newfd, int __flags) __INTRODUCED_IN(21); |
| 163 | extern int fcntl(int __fd, int __cmd, ...); |
| 164 | extern int ioctl(int __fd, int __request, ...); |
| 165 | extern int fsync(int __fd); |
| 166 | extern int fdatasync(int __fd) __INTRODUCED_IN(9); |
Elliott Hughes | 68dc20d | 2015-02-06 22:28:49 -0800 | [diff] [blame] | 167 | |
| 168 | #if defined(__USE_FILE_OFFSET64) |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 169 | extern off_t lseek(int __fd, off_t __offset, int __whence) __RENAME(lseek64); |
Elliott Hughes | 68dc20d | 2015-02-06 22:28:49 -0800 | [diff] [blame] | 170 | #else |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 171 | extern off_t lseek(int __fd, off_t __offset, int __whence); |
Elliott Hughes | 68dc20d | 2015-02-06 22:28:49 -0800 | [diff] [blame] | 172 | #endif |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 173 | |
| 174 | extern off64_t lseek64(int __fd, off64_t __offset, int __whence); |
| 175 | |
| 176 | #if defined(__USE_FILE_OFFSET64) && __ANDROID_API__ >= 21 |
| 177 | extern int truncate(const char* __path, off_t __length) __RENAME(truncate64); |
| 178 | extern ssize_t pread(int __fd, void* __buf, size_t __count, off_t __offset) |
| 179 | __RENAME(pread64); |
| 180 | extern ssize_t pwrite(int __fd, const void* __buf, size_t __count, |
| 181 | off_t __offset) __RENAME(pwrite64); |
| 182 | extern int ftruncate(int __fd, off_t __length) __RENAME(ftruncate64); |
| 183 | #else |
| 184 | extern int truncate(const char* __path, off_t __length); |
| 185 | extern ssize_t pread(int __fd, void* __buf, size_t __count, off_t __offset); |
| 186 | extern ssize_t pwrite(int __fd, const void* __buf, size_t __count, |
| 187 | off_t __offset); |
| 188 | extern int ftruncate(int __fd, off_t __length); |
| 189 | #endif |
| 190 | |
| 191 | extern int truncate64(const char* __path, off64_t __length) __INTRODUCED_IN(21); |
| 192 | extern ssize_t pread64(int __fd, void* __buf, size_t __count, off64_t __offset) __INTRODUCED_IN(21); |
| 193 | extern ssize_t pwrite64(int __fd, const void* __buf, size_t __count, |
| 194 | off64_t __offset) __INTRODUCED_IN(21); |
| 195 | extern int ftruncate64(int __fd, off64_t __length) __INTRODUCED_IN(21); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 196 | |
| 197 | extern int pause(void); |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 198 | extern unsigned int alarm(unsigned int __seconds); |
| 199 | extern unsigned int sleep(unsigned int __seconds); |
| 200 | extern int usleep(useconds_t __usec); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 201 | |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 202 | int gethostname(char* __name, size_t __len); |
| 203 | int sethostname(const char* __name, size_t __len); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 204 | |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 205 | extern void* __brk(void* __addr); |
| 206 | extern int brk(void* __addr); |
| 207 | extern void* sbrk(ptrdiff_t __increment); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 208 | |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 209 | extern int getopt(int __argc, char* const* __argv, const char* __argstring); |
| 210 | extern char* optarg; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 211 | extern int optind, opterr, optopt; |
| 212 | |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 213 | extern int isatty(int __fd); |
| 214 | extern char* ttyname(int __fd); |
| 215 | extern int ttyname_r(int __fd, char* __buf, size_t __buflen) __INTRODUCED_IN(8); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 216 | |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 217 | extern int acct(const char* __filepath); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 218 | |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 219 | long sysconf(int __name); |
| 220 | |
| 221 | #if __ANDROID_API__ >= 21 |
Bernhard Rosenkraenzer | 9ae59c0 | 2013-09-18 23:29:08 +0200 | [diff] [blame] | 222 | int getpagesize(void); |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 223 | #else |
| 224 | __inline__ int getpagesize(void) { |
| 225 | return sysconf(_SC_PAGESIZE); |
| 226 | } |
| 227 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 228 | |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 229 | long syscall(long __number, ...); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 230 | |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 231 | extern int daemon(int __nochdir, int __noclose); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 232 | |
Elliott Hughes | a6ecba4 | 2014-02-10 18:37:02 -0800 | [diff] [blame] | 233 | #if defined(__arm__) || (defined(__mips__) && !defined(__LP64__)) |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 234 | extern int cacheflush(long __addr, long __nbytes, long __cache); |
Elliott Hughes | a6ecba4 | 2014-02-10 18:37:02 -0800 | [diff] [blame] | 235 | /* __attribute__((deprecated("use __builtin___clear_cache instead"))); */ |
| 236 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 237 | |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 238 | extern pid_t tcgetpgrp(int __fd); |
| 239 | extern int tcsetpgrp(int __fd, pid_t __pid); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 240 | |
Elliott Hughes | cf399f7 | 2009-10-05 13:19:05 -0700 | [diff] [blame] | 241 | /* Used to retry syscalls that can return EINTR. */ |
| 242 | #define TEMP_FAILURE_RETRY(exp) ({ \ |
Dan Albert | a7821b7 | 2014-05-21 20:33:28 -0700 | [diff] [blame] | 243 | __typeof__(exp) _rc; \ |
Elliott Hughes | cf399f7 | 2009-10-05 13:19:05 -0700 | [diff] [blame] | 244 | do { \ |
| 245 | _rc = (exp); \ |
| 246 | } while (_rc == -1 && errno == EINTR); \ |
| 247 | _rc; }) |
| 248 | |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 249 | /* TODO(unified-headers): Factor out all the FORTIFY features. */ |
Daniel Micay | 9101b00 | 2015-05-20 15:31:26 -0400 | [diff] [blame] | 250 | extern char* __getcwd_chk(char*, size_t, size_t); |
| 251 | __errordecl(__getcwd_dest_size_error, "getcwd called with size bigger than destination"); |
| 252 | extern char* __getcwd_real(char*, size_t) __RENAME(getcwd); |
| 253 | |
Daniel Micay | e7e1c87 | 2015-04-16 09:07:45 -0400 | [diff] [blame] | 254 | extern ssize_t __pread_chk(int, void*, size_t, off_t, size_t); |
| 255 | __errordecl(__pread_dest_size_error, "pread called with size bigger than destination"); |
| 256 | __errordecl(__pread_count_toobig_error, "pread called with count > SSIZE_MAX"); |
| 257 | extern ssize_t __pread_real(int, void*, size_t, off_t) __RENAME(pread); |
| 258 | |
| 259 | extern ssize_t __pread64_chk(int, void*, size_t, off64_t, size_t); |
| 260 | __errordecl(__pread64_dest_size_error, "pread64 called with size bigger than destination"); |
| 261 | __errordecl(__pread64_count_toobig_error, "pread64 called with count > SSIZE_MAX"); |
| 262 | extern ssize_t __pread64_real(int, void*, size_t, off64_t) __RENAME(pread64); |
| 263 | |
Daniel Micay | afdd154 | 2015-07-20 21:37:29 -0400 | [diff] [blame] | 264 | extern ssize_t __pwrite_chk(int, const void*, size_t, off_t, size_t); |
| 265 | __errordecl(__pwrite_dest_size_error, "pwrite called with size bigger than destination"); |
| 266 | __errordecl(__pwrite_count_toobig_error, "pwrite called with count > SSIZE_MAX"); |
| 267 | extern ssize_t __pwrite_real(int, const void*, size_t, off_t) __RENAME(pwrite); |
| 268 | |
| 269 | extern ssize_t __pwrite64_chk(int, const void*, size_t, off64_t, size_t); |
| 270 | __errordecl(__pwrite64_dest_size_error, "pwrite64 called with size bigger than destination"); |
| 271 | __errordecl(__pwrite64_count_toobig_error, "pwrite64 called with count > SSIZE_MAX"); |
| 272 | extern ssize_t __pwrite64_real(int, const void*, size_t, off64_t) __RENAME(pwrite64); |
| 273 | |
Nick Kralevich | b036b5c | 2013-10-09 20:16:34 -0700 | [diff] [blame] | 274 | extern ssize_t __read_chk(int, void*, size_t, size_t); |
| 275 | __errordecl(__read_dest_size_error, "read called with size bigger than destination"); |
| 276 | __errordecl(__read_count_toobig_error, "read called with count > SSIZE_MAX"); |
Elliott Hughes | 2cfb4e8 | 2014-08-18 14:45:42 -0700 | [diff] [blame] | 277 | extern ssize_t __read_real(int, void*, size_t) __RENAME(read); |
Nick Kralevich | b036b5c | 2013-10-09 20:16:34 -0700 | [diff] [blame] | 278 | |
Daniel Micay | afdd154 | 2015-07-20 21:37:29 -0400 | [diff] [blame] | 279 | extern ssize_t __write_chk(int, const void*, size_t, size_t); |
| 280 | __errordecl(__write_dest_size_error, "write called with size bigger than destination"); |
| 281 | __errordecl(__write_count_toobig_error, "write called with count > SSIZE_MAX"); |
| 282 | extern ssize_t __write_real(int, const void*, size_t) __RENAME(write); |
| 283 | |
Daniel Micay | 4228188 | 2015-04-17 11:26:36 -0400 | [diff] [blame] | 284 | extern ssize_t __readlink_chk(const char*, char*, size_t, size_t); |
| 285 | __errordecl(__readlink_dest_size_error, "readlink called with size bigger than destination"); |
| 286 | __errordecl(__readlink_size_toobig_error, "readlink called with size > SSIZE_MAX"); |
| 287 | extern ssize_t __readlink_real(const char*, char*, size_t) __RENAME(readlink); |
| 288 | |
| 289 | extern ssize_t __readlinkat_chk(int dirfd, const char*, char*, size_t, size_t); |
| 290 | __errordecl(__readlinkat_dest_size_error, "readlinkat called with size bigger than destination"); |
| 291 | __errordecl(__readlinkat_size_toobig_error, "readlinkat called with size > SSIZE_MAX"); |
| 292 | extern ssize_t __readlinkat_real(int dirfd, const char*, char*, size_t) __RENAME(readlinkat); |
| 293 | |
Dan Albert | 658727e | 2014-10-07 11:10:36 -0700 | [diff] [blame] | 294 | #if defined(__BIONIC_FORTIFY) |
| 295 | |
Daniel Micay | 9101b00 | 2015-05-20 15:31:26 -0400 | [diff] [blame] | 296 | __BIONIC_FORTIFY_INLINE |
| 297 | char* getcwd(char* buf, size_t size) { |
| 298 | size_t bos = __bos(buf); |
| 299 | |
| 300 | #if defined(__clang__) |
| 301 | /* |
| 302 | * Work around LLVM's incorrect __builtin_object_size implementation here |
| 303 | * to avoid needing the workaround in the __getcwd_chk ABI forever. |
| 304 | * |
| 305 | * https://llvm.org/bugs/show_bug.cgi?id=23277 |
| 306 | */ |
| 307 | if (buf == NULL) { |
| 308 | bos = __BIONIC_FORTIFY_UNKNOWN_SIZE; |
| 309 | } |
| 310 | #else |
| 311 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 312 | return __getcwd_real(buf, size); |
| 313 | } |
| 314 | |
| 315 | if (__builtin_constant_p(size) && (size > bos)) { |
| 316 | __getcwd_dest_size_error(); |
| 317 | } |
| 318 | |
| 319 | if (__builtin_constant_p(size) && (size <= bos)) { |
| 320 | return __getcwd_real(buf, size); |
| 321 | } |
| 322 | #endif |
| 323 | |
| 324 | return __getcwd_chk(buf, size, bos); |
| 325 | } |
| 326 | |
Daniel Micay | e7e1c87 | 2015-04-16 09:07:45 -0400 | [diff] [blame] | 327 | #if defined(__USE_FILE_OFFSET64) |
| 328 | #define __PREAD_PREFIX(x) __pread64_ ## x |
| 329 | #else |
| 330 | #define __PREAD_PREFIX(x) __pread_ ## x |
| 331 | #endif |
| 332 | |
| 333 | __BIONIC_FORTIFY_INLINE |
| 334 | ssize_t pread(int fd, void* buf, size_t count, off_t offset) { |
| 335 | size_t bos = __bos0(buf); |
| 336 | |
| 337 | #if !defined(__clang__) |
| 338 | if (__builtin_constant_p(count) && (count > SSIZE_MAX)) { |
| 339 | __PREAD_PREFIX(count_toobig_error)(); |
| 340 | } |
| 341 | |
| 342 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 343 | return __PREAD_PREFIX(real)(fd, buf, count, offset); |
| 344 | } |
| 345 | |
| 346 | if (__builtin_constant_p(count) && (count > bos)) { |
| 347 | __PREAD_PREFIX(dest_size_error)(); |
| 348 | } |
| 349 | |
| 350 | if (__builtin_constant_p(count) && (count <= bos)) { |
| 351 | return __PREAD_PREFIX(real)(fd, buf, count, offset); |
| 352 | } |
| 353 | #endif |
| 354 | |
| 355 | return __PREAD_PREFIX(chk)(fd, buf, count, offset, bos); |
| 356 | } |
| 357 | |
| 358 | __BIONIC_FORTIFY_INLINE |
| 359 | ssize_t pread64(int fd, void* buf, size_t count, off64_t offset) { |
| 360 | size_t bos = __bos0(buf); |
| 361 | |
| 362 | #if !defined(__clang__) |
| 363 | if (__builtin_constant_p(count) && (count > SSIZE_MAX)) { |
| 364 | __pread64_count_toobig_error(); |
| 365 | } |
| 366 | |
| 367 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 368 | return __pread64_real(fd, buf, count, offset); |
| 369 | } |
| 370 | |
| 371 | if (__builtin_constant_p(count) && (count > bos)) { |
| 372 | __pread64_dest_size_error(); |
| 373 | } |
| 374 | |
| 375 | if (__builtin_constant_p(count) && (count <= bos)) { |
| 376 | return __pread64_real(fd, buf, count, offset); |
| 377 | } |
| 378 | #endif |
| 379 | |
| 380 | return __pread64_chk(fd, buf, count, offset, bos); |
| 381 | } |
| 382 | |
Daniel Micay | afdd154 | 2015-07-20 21:37:29 -0400 | [diff] [blame] | 383 | #if defined(__USE_FILE_OFFSET64) |
| 384 | #define __PWRITE_PREFIX(x) __pwrite64_ ## x |
| 385 | #else |
| 386 | #define __PWRITE_PREFIX(x) __pwrite_ ## x |
| 387 | #endif |
| 388 | |
| 389 | __BIONIC_FORTIFY_INLINE |
| 390 | ssize_t pwrite(int fd, const void* buf, size_t count, off_t offset) { |
| 391 | size_t bos = __bos0(buf); |
| 392 | |
| 393 | #if !defined(__clang__) |
| 394 | if (__builtin_constant_p(count) && (count > SSIZE_MAX)) { |
| 395 | __PWRITE_PREFIX(count_toobig_error)(); |
| 396 | } |
| 397 | |
| 398 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 399 | return __PWRITE_PREFIX(real)(fd, buf, count, offset); |
| 400 | } |
| 401 | |
| 402 | if (__builtin_constant_p(count) && (count > bos)) { |
| 403 | __PWRITE_PREFIX(dest_size_error)(); |
| 404 | } |
| 405 | |
| 406 | if (__builtin_constant_p(count) && (count <= bos)) { |
| 407 | return __PWRITE_PREFIX(real)(fd, buf, count, offset); |
| 408 | } |
| 409 | #endif |
| 410 | |
| 411 | return __PWRITE_PREFIX(chk)(fd, buf, count, offset, bos); |
| 412 | } |
| 413 | |
| 414 | __BIONIC_FORTIFY_INLINE |
| 415 | ssize_t pwrite64(int fd, const void* buf, size_t count, off64_t offset) { |
| 416 | size_t bos = __bos0(buf); |
| 417 | |
| 418 | #if !defined(__clang__) |
| 419 | if (__builtin_constant_p(count) && (count > SSIZE_MAX)) { |
| 420 | __pwrite64_count_toobig_error(); |
| 421 | } |
| 422 | |
| 423 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 424 | return __pwrite64_real(fd, buf, count, offset); |
| 425 | } |
| 426 | |
| 427 | if (__builtin_constant_p(count) && (count > bos)) { |
| 428 | __pwrite64_dest_size_error(); |
| 429 | } |
| 430 | |
| 431 | if (__builtin_constant_p(count) && (count <= bos)) { |
| 432 | return __pwrite64_real(fd, buf, count, offset); |
| 433 | } |
| 434 | #endif |
| 435 | |
| 436 | return __pwrite64_chk(fd, buf, count, offset, bos); |
| 437 | } |
| 438 | |
Nick Kralevich | b036b5c | 2013-10-09 20:16:34 -0700 | [diff] [blame] | 439 | __BIONIC_FORTIFY_INLINE |
| 440 | ssize_t read(int fd, void* buf, size_t count) { |
| 441 | size_t bos = __bos0(buf); |
| 442 | |
| 443 | #if !defined(__clang__) |
| 444 | if (__builtin_constant_p(count) && (count > SSIZE_MAX)) { |
| 445 | __read_count_toobig_error(); |
| 446 | } |
| 447 | |
| 448 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 449 | return __read_real(fd, buf, count); |
| 450 | } |
| 451 | |
| 452 | if (__builtin_constant_p(count) && (count > bos)) { |
| 453 | __read_dest_size_error(); |
| 454 | } |
| 455 | |
| 456 | if (__builtin_constant_p(count) && (count <= bos)) { |
| 457 | return __read_real(fd, buf, count); |
| 458 | } |
| 459 | #endif |
| 460 | |
| 461 | return __read_chk(fd, buf, count, bos); |
| 462 | } |
Daniel Micay | e7e1c87 | 2015-04-16 09:07:45 -0400 | [diff] [blame] | 463 | |
Daniel Micay | 4228188 | 2015-04-17 11:26:36 -0400 | [diff] [blame] | 464 | __BIONIC_FORTIFY_INLINE |
Daniel Micay | afdd154 | 2015-07-20 21:37:29 -0400 | [diff] [blame] | 465 | ssize_t write(int fd, const void* buf, size_t count) { |
| 466 | size_t bos = __bos0(buf); |
| 467 | |
| 468 | #if !defined(__clang__) |
| 469 | #if 0 /* work around a false positive due to a missed optimization */ |
| 470 | if (__builtin_constant_p(count) && (count > SSIZE_MAX)) { |
| 471 | __write_count_toobig_error(); |
| 472 | } |
| 473 | #endif |
| 474 | |
| 475 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 476 | return __write_real(fd, buf, count); |
| 477 | } |
| 478 | |
| 479 | if (__builtin_constant_p(count) && (count > bos)) { |
| 480 | __write_dest_size_error(); |
| 481 | } |
| 482 | |
| 483 | if (__builtin_constant_p(count) && (count <= bos)) { |
| 484 | return __write_real(fd, buf, count); |
| 485 | } |
| 486 | #endif |
| 487 | |
| 488 | return __write_chk(fd, buf, count, bos); |
| 489 | } |
| 490 | |
| 491 | __BIONIC_FORTIFY_INLINE |
Daniel Micay | 4228188 | 2015-04-17 11:26:36 -0400 | [diff] [blame] | 492 | ssize_t readlink(const char* path, char* buf, size_t size) { |
| 493 | size_t bos = __bos(buf); |
| 494 | |
| 495 | #if !defined(__clang__) |
| 496 | if (__builtin_constant_p(size) && (size > SSIZE_MAX)) { |
| 497 | __readlink_size_toobig_error(); |
| 498 | } |
| 499 | |
| 500 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 501 | return __readlink_real(path, buf, size); |
| 502 | } |
| 503 | |
| 504 | if (__builtin_constant_p(size) && (size > bos)) { |
| 505 | __readlink_dest_size_error(); |
| 506 | } |
| 507 | |
| 508 | if (__builtin_constant_p(size) && (size <= bos)) { |
| 509 | return __readlink_real(path, buf, size); |
| 510 | } |
| 511 | #endif |
| 512 | |
| 513 | return __readlink_chk(path, buf, size, bos); |
| 514 | } |
| 515 | |
| 516 | __BIONIC_FORTIFY_INLINE |
| 517 | ssize_t readlinkat(int dirfd, const char* path, char* buf, size_t size) { |
| 518 | size_t bos = __bos(buf); |
| 519 | |
| 520 | #if !defined(__clang__) |
| 521 | if (__builtin_constant_p(size) && (size > SSIZE_MAX)) { |
| 522 | __readlinkat_size_toobig_error(); |
| 523 | } |
| 524 | |
| 525 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 526 | return __readlinkat_real(dirfd, path, buf, size); |
| 527 | } |
| 528 | |
| 529 | if (__builtin_constant_p(size) && (size > bos)) { |
| 530 | __readlinkat_dest_size_error(); |
| 531 | } |
| 532 | |
| 533 | if (__builtin_constant_p(size) && (size <= bos)) { |
| 534 | return __readlinkat_real(dirfd, path, buf, size); |
| 535 | } |
| 536 | #endif |
| 537 | |
| 538 | return __readlinkat_chk(dirfd, path, buf, size, bos); |
| 539 | } |
| 540 | |
Nick Kralevich | b036b5c | 2013-10-09 20:16:34 -0700 | [diff] [blame] | 541 | #endif /* defined(__BIONIC_FORTIFY) */ |
| 542 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 543 | __END_DECLS |
| 544 | |
| 545 | #endif /* _UNISTD_H_ */ |