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> |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 36 | |
Josh Gao | ee8d169 | 2016-04-07 14:16:30 -0700 | [diff] [blame] | 37 | #include <bits/fcntl.h> |
Josh Gao | 7449e59 | 2016-04-07 16:37:49 -0700 | [diff] [blame] | 38 | #include <bits/getopt.h> |
Josh Gao | 98e574c | 2016-04-07 14:19:03 -0700 | [diff] [blame] | 39 | #include <bits/ioctl.h> |
Elliott Hughes | 5704c42 | 2016-01-25 18:06:24 -0800 | [diff] [blame] | 40 | #include <bits/lockf.h> |
| 41 | #include <bits/posix_limits.h> |
Elliott Hughes | fd936ae | 2016-08-12 10:16:34 -0700 | [diff] [blame] | 42 | #include <bits/seek_constants.h> |
Josh Gao | 8c8ef59 | 2016-04-07 16:33:30 -0700 | [diff] [blame] | 43 | #include <bits/sysconf.h> |
Elliott Hughes | 1ed337d | 2015-02-02 14:02:09 -0800 | [diff] [blame] | 44 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 45 | __BEGIN_DECLS |
| 46 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 47 | #define STDIN_FILENO 0 |
| 48 | #define STDOUT_FILENO 1 |
| 49 | #define STDERR_FILENO 2 |
| 50 | |
Elliott Hughes | 1ed337d | 2015-02-02 14:02:09 -0800 | [diff] [blame] | 51 | #define F_OK 0 |
| 52 | #define X_OK 1 |
| 53 | #define W_OK 2 |
| 54 | #define R_OK 4 |
| 55 | |
Elliott Hughes | a186b2e | 2014-09-22 14:49:07 -0700 | [diff] [blame] | 56 | #define _PC_FILESIZEBITS 0 |
| 57 | #define _PC_LINK_MAX 1 |
| 58 | #define _PC_MAX_CANON 2 |
| 59 | #define _PC_MAX_INPUT 3 |
| 60 | #define _PC_NAME_MAX 4 |
| 61 | #define _PC_PATH_MAX 5 |
| 62 | #define _PC_PIPE_BUF 6 |
| 63 | #define _PC_2_SYMLINKS 7 |
| 64 | #define _PC_ALLOC_SIZE_MIN 8 |
| 65 | #define _PC_REC_INCR_XFER_SIZE 9 |
| 66 | #define _PC_REC_MAX_XFER_SIZE 10 |
| 67 | #define _PC_REC_MIN_XFER_SIZE 11 |
| 68 | #define _PC_REC_XFER_ALIGN 12 |
| 69 | #define _PC_SYMLINK_MAX 13 |
| 70 | #define _PC_CHOWN_RESTRICTED 14 |
| 71 | #define _PC_NO_TRUNC 15 |
| 72 | #define _PC_VDISABLE 16 |
| 73 | #define _PC_ASYNC_IO 17 |
| 74 | #define _PC_PRIO_IO 18 |
| 75 | #define _PC_SYNC_IO 19 |
| 76 | |
Elliott Hughes | 58d9e28 | 2014-04-22 17:41:00 -0700 | [diff] [blame] | 77 | extern char** environ; |
| 78 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 79 | __noreturn void _exit(int __status); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 80 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 81 | pid_t fork(void); |
| 82 | pid_t vfork(void); |
| 83 | pid_t getpid(void); |
Elliott Hughes | 95fa061 | 2016-09-28 12:29:52 -0700 | [diff] [blame] | 84 | pid_t gettid(void) __attribute_const__; |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 85 | pid_t getpgid(pid_t __pid); |
| 86 | int setpgid(pid_t __pid, pid_t __pgid); |
| 87 | pid_t getppid(void); |
| 88 | pid_t getpgrp(void); |
| 89 | int setpgrp(void); |
| 90 | pid_t getsid(pid_t __pid) __INTRODUCED_IN(17); |
| 91 | pid_t setsid(void); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 92 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 93 | int execv(const char* __path, char* const* __argv); |
| 94 | int execvp(const char* __file, char* const* __argv); |
| 95 | int execvpe(const char* __file, char* const* __argv, char* const* __envp) __INTRODUCED_IN(21); |
| 96 | int execve(const char* __file, char* const* __argv, char* const* __envp); |
Josh Gao | d80a52e | 2016-08-10 15:18:29 -0700 | [diff] [blame] | 97 | int execl(const char* __path, const char* __arg0, ...) __attribute__((__sentinel__)); |
| 98 | int execlp(const char* __file, const char* __arg0, ...) __attribute__((__sentinel__)); |
| 99 | int execle(const char* __path, const char* __arg0, ... /*, char* const* __envp */) |
| 100 | __attribute__((__sentinel__(1))); |
David 'Digit' Turner | b083bb5 | 2011-05-26 02:46:41 +0200 | [diff] [blame] | 101 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 102 | int nice(int __incr); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 103 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 104 | int setuid(uid_t __uid); |
| 105 | uid_t getuid(void); |
| 106 | int seteuid(uid_t __uid); |
| 107 | uid_t geteuid(void); |
| 108 | int setgid(gid_t __gid); |
| 109 | gid_t getgid(void); |
| 110 | int setegid(gid_t __gid); |
| 111 | gid_t getegid(void); |
| 112 | int getgroups(int __size, gid_t* __list); |
| 113 | int setgroups(size_t __size, const gid_t* __list); |
| 114 | int setreuid(uid_t __ruid, uid_t __euid); |
| 115 | int setregid(gid_t __rgid, gid_t __egid); |
| 116 | int setresuid(uid_t __ruid, uid_t __euid, uid_t __suid); |
| 117 | int setresgid(gid_t __rgid, gid_t __egid, gid_t __sgid); |
| 118 | int getresuid(uid_t* __ruid, uid_t* __euid, uid_t* __suid); |
| 119 | int getresgid(gid_t* __rgid, gid_t* __egid, gid_t* __sgid); |
| 120 | char* getlogin(void); |
Elliott Hughes | 06bd586 | 2017-07-28 16:27:49 -0700 | [diff] [blame^] | 121 | int getlogin_r(char* __buffer, size_t __buffer_size) __INTRODUCED_IN_FUTURE; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 122 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 123 | long fpathconf(int __fd, int __name); |
| 124 | long pathconf(const char* __path, int __name); |
Elliott Hughes | a186b2e | 2014-09-22 14:49:07 -0700 | [diff] [blame] | 125 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 126 | int access(const char* __path, int __mode); |
| 127 | int faccessat(int __dirfd, const char* __path, int __mode, int __flags) __INTRODUCED_IN(16); |
| 128 | int link(const char* __oldpath, const char* __newpath); |
| 129 | int linkat(int __olddirfd, const char* __oldpath, int __newdirfd, |
| 130 | const char* __newpath, int __flags) __INTRODUCED_IN(21); |
| 131 | int unlink(const char* __path); |
| 132 | int unlinkat(int __dirfd, const char* __path, int __flags); |
| 133 | int chdir(const char* __path); |
| 134 | int fchdir(int __fd); |
| 135 | int rmdir(const char* __path); |
| 136 | int pipe(int* __pipefd); |
Elliott Hughes | 5f5cc45 | 2014-08-18 16:04:03 -0700 | [diff] [blame] | 137 | #if defined(__USE_GNU) |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 138 | int pipe2(int* __pipefd, int __flags) __INTRODUCED_IN(9); |
David 'Digit' Turner | 275cd48 | 2010-09-27 17:33:08 +0200 | [diff] [blame] | 139 | #endif |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 140 | int chroot(const char* __path); |
| 141 | int symlink(const char* __oldpath, const char* __newpath); |
| 142 | int symlinkat(const char* __oldpath, int __newdirfd, const char* __newpath) __INTRODUCED_IN(21); |
George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 143 | ssize_t readlink(const char* __path, char* __buf, size_t __bufsiz) |
| 144 | __overloadable __RENAME_CLANG(readlink); |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 145 | ssize_t readlinkat(int __dirfd, const char* __path, char* __buf, |
George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 146 | size_t __bufsiz) |
| 147 | __INTRODUCED_IN(21) __overloadable __RENAME_CLANG(readlinkat); |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 148 | int chown(const char* __path, uid_t __owner, gid_t __group); |
| 149 | int fchown(int __fd, uid_t __owner, gid_t __group); |
| 150 | int fchownat(int __dirfd, const char* __path, uid_t __owner, gid_t __group, int __flags); |
| 151 | int lchown(const char* __path, uid_t __owner, gid_t __group); |
George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 152 | char* getcwd(char* __buf, size_t __size) __overloadable __RENAME_CLANG(getcwd); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 153 | |
Elliott Hughes | 79a8f4b | 2016-11-29 15:16:08 -0800 | [diff] [blame] | 154 | void sync(void); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 155 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 156 | int close(int __fd); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 157 | |
George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 158 | ssize_t read(int __fd, void* __buf, size_t __count) __overloadable |
| 159 | __RENAME_CLANG(read); |
| 160 | ssize_t write(int __fd, const void* __buf, size_t __count) __overloadable |
| 161 | __RENAME_CLANG(write); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 162 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 163 | int dup(int __oldfd); |
| 164 | int dup2(int __oldfd, int __newfd); |
| 165 | int dup3(int __oldfd, int __newfd, int __flags) __INTRODUCED_IN(21); |
| 166 | int fsync(int __fd); |
| 167 | int fdatasync(int __fd) __INTRODUCED_IN(9); |
Elliott Hughes | 68dc20d | 2015-02-06 22:28:49 -0800 | [diff] [blame] | 168 | |
| 169 | #if defined(__USE_FILE_OFFSET64) |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 170 | off_t lseek(int __fd, off_t __offset, int __whence) __RENAME(lseek64); |
Elliott Hughes | 68dc20d | 2015-02-06 22:28:49 -0800 | [diff] [blame] | 171 | #else |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 172 | off_t lseek(int __fd, off_t __offset, int __whence); |
Elliott Hughes | 68dc20d | 2015-02-06 22:28:49 -0800 | [diff] [blame] | 173 | #endif |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 174 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 175 | off64_t lseek64(int __fd, off64_t __offset, int __whence); |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 176 | |
Elliott Hughes | 00fedf5 | 2017-07-05 15:23:50 -0700 | [diff] [blame] | 177 | #if defined(__USE_FILE_OFFSET64) |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 178 | int truncate(const char* __path, off_t __length) __RENAME(truncate64) __INTRODUCED_IN(21); |
George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 179 | ssize_t pread(int __fd, void* __buf, size_t __count, off_t __offset) |
| 180 | __overloadable __RENAME(pread64) __INTRODUCED_IN(12); |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 181 | ssize_t pwrite(int __fd, const void* __buf, size_t __count, off_t __offset) |
George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 182 | __overloadable __RENAME(pwrite64) __INTRODUCED_IN(12); |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 183 | int ftruncate(int __fd, off_t __length) __RENAME(ftruncate64) __INTRODUCED_IN(12); |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 184 | #else |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 185 | int truncate(const char* __path, off_t __length); |
George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 186 | ssize_t pread(int __fd, void* __buf, size_t __count, off_t __offset) |
| 187 | __overloadable __RENAME_CLANG(pread); |
| 188 | ssize_t pwrite(int __fd, const void* __buf, size_t __count, off_t __offset) |
| 189 | __overloadable __RENAME_CLANG(pwrite); |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 190 | int ftruncate(int __fd, off_t __length); |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 191 | #endif |
| 192 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 193 | int truncate64(const char* __path, off64_t __length) __INTRODUCED_IN(21); |
George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 194 | ssize_t pread64(int __fd, void* __buf, size_t __count, off64_t __offset) |
| 195 | __INTRODUCED_IN(12) __overloadable __RENAME_CLANG(pread64); |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 196 | ssize_t pwrite64(int __fd, const void* __buf, size_t __count, off64_t __offset) |
George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 197 | __INTRODUCED_IN(12) __overloadable __RENAME_CLANG(pwrite64); |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 198 | int ftruncate64(int __fd, off64_t __length) __INTRODUCED_IN(12); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 199 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 200 | int pause(void); |
| 201 | unsigned int alarm(unsigned int __seconds); |
| 202 | unsigned int sleep(unsigned int __seconds); |
| 203 | int usleep(useconds_t __usec); |
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 | int gethostname(char* __name, size_t __len); |
Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 206 | int sethostname(const char* __name, size_t __len) __INTRODUCED_IN(23); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 207 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 208 | int brk(void* __addr); |
| 209 | void* sbrk(ptrdiff_t __increment); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 210 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 211 | int isatty(int __fd); |
| 212 | char* ttyname(int __fd); |
| 213 | 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] | 214 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 215 | int acct(const char* __filepath); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 216 | |
Elliott Hughes | 5bc78c8 | 2016-11-16 11:35:43 -0800 | [diff] [blame] | 217 | #if __ANDROID_API__ >= __ANDROID_API_L__ |
Josh Gao | b6a4a4c | 2016-07-26 16:34:40 -0700 | [diff] [blame] | 218 | int getpagesize(void) __INTRODUCED_IN(21); |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 219 | #else |
Dan Albert | a39f5d8 | 2016-09-14 17:10:26 -0700 | [diff] [blame] | 220 | static __inline__ int getpagesize(void) { |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 221 | return sysconf(_SC_PAGESIZE); |
| 222 | } |
| 223 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 224 | |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 225 | long syscall(long __number, ...); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 226 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 227 | int daemon(int __nochdir, int __noclose); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 228 | |
Elliott Hughes | a6ecba4 | 2014-02-10 18:37:02 -0800 | [diff] [blame] | 229 | #if defined(__arm__) || (defined(__mips__) && !defined(__LP64__)) |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 230 | int cacheflush(long __addr, long __nbytes, long __cache); |
Elliott Hughes | a6ecba4 | 2014-02-10 18:37:02 -0800 | [diff] [blame] | 231 | /* __attribute__((deprecated("use __builtin___clear_cache instead"))); */ |
| 232 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 233 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 234 | pid_t tcgetpgrp(int __fd); |
| 235 | int tcsetpgrp(int __fd, pid_t __pid); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 236 | |
Elliott Hughes | cf399f7 | 2009-10-05 13:19:05 -0700 | [diff] [blame] | 237 | /* Used to retry syscalls that can return EINTR. */ |
| 238 | #define TEMP_FAILURE_RETRY(exp) ({ \ |
Dan Albert | a7821b7 | 2014-05-21 20:33:28 -0700 | [diff] [blame] | 239 | __typeof__(exp) _rc; \ |
Elliott Hughes | cf399f7 | 2009-10-05 13:19:05 -0700 | [diff] [blame] | 240 | do { \ |
| 241 | _rc = (exp); \ |
| 242 | } while (_rc == -1 && errno == EINTR); \ |
| 243 | _rc; }) |
| 244 | |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 245 | /* TODO(unified-headers): Factor out all the FORTIFY features. */ |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 246 | char* __getcwd_chk(char*, size_t, size_t) __INTRODUCED_IN(24); |
Daniel Micay | 9101b00 | 2015-05-20 15:31:26 -0400 | [diff] [blame] | 247 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 248 | ssize_t __pread_chk(int, void*, size_t, off_t, size_t) __INTRODUCED_IN(23); |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 249 | ssize_t __pread_real(int, void*, size_t, off_t) __RENAME(pread); |
Daniel Micay | e7e1c87 | 2015-04-16 09:07:45 -0400 | [diff] [blame] | 250 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 251 | ssize_t __pread64_chk(int, void*, size_t, off64_t, size_t) __INTRODUCED_IN(23); |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 252 | ssize_t __pread64_real(int, void*, size_t, off64_t) __RENAME(pread64) __INTRODUCED_IN(12); |
Daniel Micay | e7e1c87 | 2015-04-16 09:07:45 -0400 | [diff] [blame] | 253 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 254 | ssize_t __pwrite_chk(int, const void*, size_t, off_t, size_t) __INTRODUCED_IN(24); |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 255 | ssize_t __pwrite_real(int, const void*, size_t, off_t) __RENAME(pwrite); |
Daniel Micay | afdd154 | 2015-07-20 21:37:29 -0400 | [diff] [blame] | 256 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 257 | ssize_t __pwrite64_chk(int, const void*, size_t, off64_t, size_t) __INTRODUCED_IN(24); |
George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 258 | ssize_t __pwrite64_real(int, const void*, size_t, off64_t) __RENAME(pwrite64) |
| 259 | __INTRODUCED_IN(12); |
Daniel Micay | afdd154 | 2015-07-20 21:37:29 -0400 | [diff] [blame] | 260 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 261 | ssize_t __read_chk(int, void*, size_t, size_t) __INTRODUCED_IN(21); |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 262 | ssize_t __write_chk(int, const void*, size_t, size_t) __INTRODUCED_IN(24); |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 263 | ssize_t __readlink_chk(const char*, char*, size_t, size_t) __INTRODUCED_IN(23); |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 264 | ssize_t __readlinkat_chk(int dirfd, const char*, char*, size_t, size_t) __INTRODUCED_IN(23); |
Daniel Micay | 4228188 | 2015-04-17 11:26:36 -0400 | [diff] [blame] | 265 | |
Josh Gao | 2e8e5e6 | 2017-04-20 12:58:31 -0700 | [diff] [blame] | 266 | int getdomainname(char*, size_t) __INTRODUCED_IN(26); |
| 267 | int setdomainname(const char*, size_t) __INTRODUCED_IN(26); |
Greg Hackmann | e2faf07 | 2016-03-03 08:37:53 -0800 | [diff] [blame] | 268 | |
Dan Albert | 658727e | 2014-10-07 11:10:36 -0700 | [diff] [blame] | 269 | #if defined(__BIONIC_FORTIFY) |
| 270 | |
George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 271 | #if defined(__USE_FILE_OFFSET64) |
| 272 | #define __PREAD_PREFIX(x) __pread64_ ## x |
| 273 | #define __PWRITE_PREFIX(x) __pwrite64_ ## x |
| 274 | #else |
| 275 | #define __PREAD_PREFIX(x) __pread_ ## x |
| 276 | #define __PWRITE_PREFIX(x) __pwrite_ ## x |
| 277 | #endif |
Daniel Micay | 9101b00 | 2015-05-20 15:31:26 -0400 | [diff] [blame] | 278 | |
| 279 | #if defined(__clang__) |
George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 280 | #define __error_if_overflows_ssizet(what) \ |
| 281 | __enable_if(what > SSIZE_MAX, #what " must be <= SSIZE_MAX") \ |
| 282 | __errorattr(#what " must be <= SSIZE_MAX") |
| 283 | |
| 284 | #define __enable_if_no_overflow_ssizet(what) \ |
| 285 | __enable_if((what) <= SSIZE_MAX, "enabled if " #what " <= SSIZE_MAX") |
| 286 | |
| 287 | #define __error_if_overflows_objectsize(what, objsize) \ |
| 288 | __enable_if((objsize) != __BIONIC_FORTIFY_UNKNOWN_SIZE && \ |
| 289 | (what) > (objsize), \ |
| 290 | "'" #what "' bytes overflows the given object") \ |
| 291 | __errorattr("'" #what "' bytes overflows the given object") |
| 292 | |
| 293 | __BIONIC_ERROR_FUNCTION_VISIBILITY |
| 294 | char* getcwd(char* buf, size_t size) __overloadable |
| 295 | __error_if_overflows_objectsize(size, __bos(buf)); |
| 296 | |
| 297 | #if __ANDROID_API__ >= __ANDROID_API_N__ |
| 298 | __BIONIC_FORTIFY_INLINE |
| 299 | char* getcwd(char* const __pass_object_size buf, size_t size) __overloadable { |
| 300 | size_t bos = __bos(buf); |
| 301 | |
Daniel Micay | 9101b00 | 2015-05-20 15:31:26 -0400 | [diff] [blame] | 302 | /* |
George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 303 | * Clang responds bos==0 if buf==NULL |
| 304 | * (https://llvm.org/bugs/show_bug.cgi?id=23277). Given that NULL is a valid |
| 305 | * value, we need to handle that. |
Daniel Micay | 9101b00 | 2015-05-20 15:31:26 -0400 | [diff] [blame] | 306 | */ |
George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 307 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE || buf == NULL) { |
| 308 | return __call_bypassing_fortify(getcwd)(buf, size); |
Daniel Micay | 9101b00 | 2015-05-20 15:31:26 -0400 | [diff] [blame] | 309 | } |
George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 310 | |
| 311 | return __getcwd_chk(buf, size, bos); |
| 312 | } |
| 313 | #endif /* __ANDROID_API__ >= __ANDROID_API_N__ */ |
| 314 | |
| 315 | #if __ANDROID_API__ >= __ANDROID_API_M__ |
| 316 | __BIONIC_ERROR_FUNCTION_VISIBILITY |
| 317 | ssize_t pread(int fd, void* buf, size_t count, off_t offset) __overloadable |
| 318 | __error_if_overflows_ssizet(count); |
| 319 | |
| 320 | __BIONIC_ERROR_FUNCTION_VISIBILITY |
| 321 | ssize_t pread(int fd, void* buf, size_t count, off_t offset) __overloadable |
| 322 | __enable_if_no_overflow_ssizet(count) |
| 323 | __error_if_overflows_objectsize(count, __bos0(buf)); |
| 324 | |
| 325 | __BIONIC_FORTIFY_INLINE |
George Burgess IV | 156d5a8 | 2017-02-10 13:56:22 -0800 | [diff] [blame] | 326 | ssize_t pread(int fd, void* const __pass_object_size0 buf, size_t count, |
George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 327 | off_t offset) __overloadable { |
| 328 | size_t bos = __bos0(buf); |
| 329 | |
| 330 | if (count == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 331 | return __PREAD_PREFIX(real)(fd, buf, count, offset); |
| 332 | } |
| 333 | |
| 334 | return __PREAD_PREFIX(chk)(fd, buf, count, offset, bos); |
| 335 | } |
| 336 | |
| 337 | __BIONIC_ERROR_FUNCTION_VISIBILITY |
| 338 | ssize_t pread64(int fd, void* buf, size_t count, off64_t offset) __overloadable |
| 339 | __error_if_overflows_ssizet(count); |
| 340 | |
| 341 | __BIONIC_ERROR_FUNCTION_VISIBILITY |
| 342 | ssize_t pread64(int fd, void* buf, size_t count, off64_t offset) __overloadable |
| 343 | __enable_if_no_overflow_ssizet(count) |
| 344 | __error_if_overflows_objectsize(count, __bos0(buf)); |
| 345 | |
| 346 | __BIONIC_FORTIFY_INLINE |
George Burgess IV | 156d5a8 | 2017-02-10 13:56:22 -0800 | [diff] [blame] | 347 | ssize_t pread64(int fd, void* const __pass_object_size0 buf, size_t count, |
George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 348 | off64_t offset) __overloadable { |
| 349 | size_t bos = __bos0(buf); |
| 350 | |
| 351 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 352 | return __pread64_real(fd, buf, count, offset); |
| 353 | } |
| 354 | |
| 355 | return __pread64_chk(fd, buf, count, offset, bos); |
| 356 | } |
| 357 | #endif /* __ANDROID_API__ >= __ANDROID_API_M__ */ |
| 358 | |
| 359 | #if __ANDROID_API__ >= __ANDROID_API_N__ |
| 360 | __BIONIC_ERROR_FUNCTION_VISIBILITY |
| 361 | ssize_t pwrite(int fd, const void* buf, size_t count, off_t offset) |
| 362 | __overloadable |
| 363 | __error_if_overflows_ssizet(count); |
| 364 | |
| 365 | __BIONIC_ERROR_FUNCTION_VISIBILITY |
| 366 | ssize_t pwrite(int fd, const void* buf, size_t count, off_t offset) |
| 367 | __overloadable |
| 368 | __enable_if_no_overflow_ssizet(count) |
| 369 | __error_if_overflows_objectsize(count, __bos0(buf)); |
| 370 | |
| 371 | __BIONIC_FORTIFY_INLINE |
George Burgess IV | 156d5a8 | 2017-02-10 13:56:22 -0800 | [diff] [blame] | 372 | ssize_t pwrite(int fd, const void* const __pass_object_size0 buf, size_t count, |
George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 373 | off_t offset) __overloadable { |
| 374 | size_t bos = __bos0(buf); |
| 375 | |
| 376 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 377 | return __PWRITE_PREFIX(real)(fd, buf, count, offset); |
| 378 | } |
| 379 | |
| 380 | return __PWRITE_PREFIX(chk)(fd, buf, count, offset, bos); |
| 381 | } |
| 382 | |
| 383 | __BIONIC_ERROR_FUNCTION_VISIBILITY |
| 384 | ssize_t pwrite64(int fd, const void* buf, size_t count, off64_t offset) |
| 385 | __overloadable |
| 386 | __error_if_overflows_ssizet(count); |
| 387 | |
| 388 | __BIONIC_ERROR_FUNCTION_VISIBILITY |
| 389 | ssize_t pwrite64(int fd, const void* buf, size_t count, off64_t offset) |
| 390 | __overloadable |
| 391 | __enable_if_no_overflow_ssizet(count) |
| 392 | __error_if_overflows_objectsize(count, __bos0(buf)); |
| 393 | |
| 394 | __BIONIC_FORTIFY_INLINE |
George Burgess IV | 156d5a8 | 2017-02-10 13:56:22 -0800 | [diff] [blame] | 395 | ssize_t pwrite64(int fd, const void* const __pass_object_size0 buf, |
| 396 | size_t count, off64_t offset) __overloadable { |
George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 397 | size_t bos = __bos0(buf); |
| 398 | |
| 399 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 400 | return __pwrite64_real(fd, buf, count, offset); |
| 401 | } |
| 402 | |
| 403 | return __pwrite64_chk(fd, buf, count, offset, bos); |
| 404 | } |
| 405 | #endif /* __ANDROID_API__ >= __ANDROID_API_N__ */ |
| 406 | |
Dan Albert | 9c2094f | 2017-02-14 19:28:18 -0800 | [diff] [blame] | 407 | #if __ANDROID_API__ >= __ANDROID_API_L__ |
George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 408 | __BIONIC_ERROR_FUNCTION_VISIBILITY |
| 409 | ssize_t read(int fd, void* buf, size_t count) __overloadable |
| 410 | __error_if_overflows_ssizet(count); |
| 411 | |
| 412 | __BIONIC_ERROR_FUNCTION_VISIBILITY |
| 413 | ssize_t read(int fd, void* buf, size_t count) __overloadable |
| 414 | __enable_if_no_overflow_ssizet(count) |
| 415 | __error_if_overflows_objectsize(count, __bos0(buf)); |
| 416 | |
| 417 | __BIONIC_FORTIFY_INLINE |
George Burgess IV | 156d5a8 | 2017-02-10 13:56:22 -0800 | [diff] [blame] | 418 | ssize_t read(int fd, void* const __pass_object_size0 buf, size_t count) |
George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 419 | __overloadable { |
| 420 | size_t bos = __bos0(buf); |
| 421 | |
| 422 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 423 | return __call_bypassing_fortify(read)(fd, buf, count); |
| 424 | } |
| 425 | |
| 426 | return __read_chk(fd, buf, count, bos); |
| 427 | } |
Dan Albert | 9c2094f | 2017-02-14 19:28:18 -0800 | [diff] [blame] | 428 | #endif /* __ANDROID_API__ >= __ANDROID_API_L__ */ |
George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 429 | |
Dan Albert | 9c2094f | 2017-02-14 19:28:18 -0800 | [diff] [blame] | 430 | #if __ANDROID_API__ >= __ANDROID_API_N__ |
George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 431 | __BIONIC_ERROR_FUNCTION_VISIBILITY |
| 432 | ssize_t write(int fd, const void* buf, size_t count) __overloadable |
| 433 | __error_if_overflows_ssizet(count); |
| 434 | |
| 435 | __BIONIC_ERROR_FUNCTION_VISIBILITY |
| 436 | ssize_t write(int fd, const void* buf, size_t count) __overloadable |
| 437 | __enable_if_no_overflow_ssizet(count) |
| 438 | __error_if_overflows_objectsize(count, __bos0(buf)); |
| 439 | |
| 440 | __BIONIC_FORTIFY_INLINE |
George Burgess IV | 156d5a8 | 2017-02-10 13:56:22 -0800 | [diff] [blame] | 441 | ssize_t write(int fd, const void* const __pass_object_size0 buf, size_t count) |
George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 442 | __overloadable { |
| 443 | size_t bos = __bos0(buf); |
| 444 | |
| 445 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 446 | return __call_bypassing_fortify(write)(fd, buf, count); |
| 447 | } |
| 448 | |
| 449 | return __write_chk(fd, buf, count, bos); |
| 450 | } |
Dan Albert | 9c2094f | 2017-02-14 19:28:18 -0800 | [diff] [blame] | 451 | #endif /* __ANDROID_API__ >= __ANDROID_API_N__ */ |
George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 452 | |
Dan Albert | 9c2094f | 2017-02-14 19:28:18 -0800 | [diff] [blame] | 453 | #if __ANDROID_API__ >= __ANDROID_API_M__ |
George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 454 | __BIONIC_ERROR_FUNCTION_VISIBILITY |
| 455 | ssize_t readlink(const char* path, char* buf, size_t size) __overloadable |
| 456 | __error_if_overflows_ssizet(size); |
| 457 | |
| 458 | __BIONIC_ERROR_FUNCTION_VISIBILITY |
| 459 | ssize_t readlink(const char* path, char* buf, size_t size) __overloadable |
| 460 | __enable_if_no_overflow_ssizet(size) |
| 461 | __error_if_overflows_objectsize(size, __bos(buf)); |
| 462 | |
| 463 | __BIONIC_FORTIFY_INLINE |
| 464 | ssize_t readlink(const char* path, char* const __pass_object_size buf, |
| 465 | size_t size) __overloadable { |
| 466 | size_t bos = __bos(buf); |
| 467 | |
| 468 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 469 | return __call_bypassing_fortify(readlink)(path, buf, size); |
| 470 | } |
| 471 | |
| 472 | return __readlink_chk(path, buf, size, bos); |
| 473 | } |
| 474 | |
George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 475 | __BIONIC_ERROR_FUNCTION_VISIBILITY |
| 476 | ssize_t readlinkat(int dirfd, const char* path, char* buf, size_t size) |
| 477 | __overloadable |
| 478 | __error_if_overflows_ssizet(size); |
| 479 | |
| 480 | __BIONIC_ERROR_FUNCTION_VISIBILITY |
| 481 | ssize_t readlinkat(int dirfd, const char* path, char* buf, size_t size) |
| 482 | __overloadable |
| 483 | __enable_if_no_overflow_ssizet(size) |
| 484 | __error_if_overflows_objectsize(size, __bos(buf)); |
| 485 | |
| 486 | __BIONIC_FORTIFY_INLINE |
| 487 | ssize_t readlinkat(int dirfd, const char* path, |
| 488 | char* const __pass_object_size buf, size_t size) |
| 489 | __overloadable { |
| 490 | size_t bos = __bos(buf); |
| 491 | |
| 492 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 493 | return __call_bypassing_fortify(readlinkat)(dirfd, path, buf, size); |
| 494 | } |
| 495 | |
| 496 | return __readlinkat_chk(dirfd, path, buf, size, bos); |
| 497 | } |
Dan Albert | 9c2094f | 2017-02-14 19:28:18 -0800 | [diff] [blame] | 498 | #endif /* __ANDROID_API__ >= __ANDROID_API_M__ */ |
George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 499 | |
| 500 | #undef __enable_if_no_overflow_ssizet |
| 501 | #undef __error_if_overflows_objectsize |
| 502 | #undef __error_if_overflows_ssizet |
| 503 | #else /* defined(__clang__) */ |
| 504 | |
| 505 | char* __getcwd_real(char*, size_t) __RENAME(getcwd); |
| 506 | ssize_t __read_real(int, void*, size_t) __RENAME(read); |
| 507 | ssize_t __write_real(int, const void*, size_t) __RENAME(write); |
| 508 | ssize_t __readlink_real(const char*, char*, size_t) __RENAME(readlink); |
| 509 | ssize_t __readlinkat_real(int dirfd, const char*, char*, size_t) __RENAME(readlinkat); |
| 510 | |
| 511 | __errordecl(__getcwd_dest_size_error, "getcwd called with size bigger than destination"); |
| 512 | __errordecl(__pread_dest_size_error, "pread called with size bigger than destination"); |
| 513 | __errordecl(__pread_count_toobig_error, "pread called with count > SSIZE_MAX"); |
| 514 | __errordecl(__pread64_dest_size_error, "pread64 called with size bigger than destination"); |
| 515 | __errordecl(__pread64_count_toobig_error, "pread64 called with count > SSIZE_MAX"); |
| 516 | __errordecl(__pwrite_dest_size_error, "pwrite called with size bigger than destination"); |
| 517 | __errordecl(__pwrite_count_toobig_error, "pwrite called with count > SSIZE_MAX"); |
| 518 | __errordecl(__pwrite64_dest_size_error, "pwrite64 called with size bigger than destination"); |
| 519 | __errordecl(__pwrite64_count_toobig_error, "pwrite64 called with count > SSIZE_MAX"); |
| 520 | __errordecl(__read_dest_size_error, "read called with size bigger than destination"); |
| 521 | __errordecl(__read_count_toobig_error, "read called with count > SSIZE_MAX"); |
| 522 | __errordecl(__write_dest_size_error, "write called with size bigger than destination"); |
| 523 | __errordecl(__write_count_toobig_error, "write called with count > SSIZE_MAX"); |
| 524 | __errordecl(__readlink_dest_size_error, "readlink called with size bigger than destination"); |
| 525 | __errordecl(__readlink_size_toobig_error, "readlink called with size > SSIZE_MAX"); |
| 526 | __errordecl(__readlinkat_dest_size_error, "readlinkat called with size bigger than destination"); |
| 527 | __errordecl(__readlinkat_size_toobig_error, "readlinkat called with size > SSIZE_MAX"); |
| 528 | |
| 529 | #if __ANDROID_API__ >= __ANDROID_API_N__ |
| 530 | __BIONIC_FORTIFY_INLINE |
| 531 | char* getcwd(char* buf, size_t size) __overloadable { |
| 532 | size_t bos = __bos(buf); |
| 533 | |
Daniel Micay | 9101b00 | 2015-05-20 15:31:26 -0400 | [diff] [blame] | 534 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 535 | return __getcwd_real(buf, size); |
| 536 | } |
| 537 | |
| 538 | if (__builtin_constant_p(size) && (size > bos)) { |
| 539 | __getcwd_dest_size_error(); |
| 540 | } |
| 541 | |
| 542 | if (__builtin_constant_p(size) && (size <= bos)) { |
| 543 | return __getcwd_real(buf, size); |
| 544 | } |
Daniel Micay | 9101b00 | 2015-05-20 15:31:26 -0400 | [diff] [blame] | 545 | |
| 546 | return __getcwd_chk(buf, size, bos); |
| 547 | } |
Elliott Hughes | 5bc78c8 | 2016-11-16 11:35:43 -0800 | [diff] [blame] | 548 | #endif /* __ANDROID_API__ >= __ANDROID_API_N__ */ |
Daniel Micay | 9101b00 | 2015-05-20 15:31:26 -0400 | [diff] [blame] | 549 | |
Elliott Hughes | 5bc78c8 | 2016-11-16 11:35:43 -0800 | [diff] [blame] | 550 | #if __ANDROID_API__ >= __ANDROID_API_M__ |
Daniel Micay | e7e1c87 | 2015-04-16 09:07:45 -0400 | [diff] [blame] | 551 | __BIONIC_FORTIFY_INLINE |
| 552 | ssize_t pread(int fd, void* buf, size_t count, off_t offset) { |
| 553 | size_t bos = __bos0(buf); |
| 554 | |
Daniel Micay | e7e1c87 | 2015-04-16 09:07:45 -0400 | [diff] [blame] | 555 | if (__builtin_constant_p(count) && (count > SSIZE_MAX)) { |
| 556 | __PREAD_PREFIX(count_toobig_error)(); |
| 557 | } |
| 558 | |
| 559 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 560 | return __PREAD_PREFIX(real)(fd, buf, count, offset); |
| 561 | } |
| 562 | |
| 563 | if (__builtin_constant_p(count) && (count > bos)) { |
| 564 | __PREAD_PREFIX(dest_size_error)(); |
| 565 | } |
| 566 | |
| 567 | if (__builtin_constant_p(count) && (count <= bos)) { |
| 568 | return __PREAD_PREFIX(real)(fd, buf, count, offset); |
| 569 | } |
Daniel Micay | e7e1c87 | 2015-04-16 09:07:45 -0400 | [diff] [blame] | 570 | |
| 571 | return __PREAD_PREFIX(chk)(fd, buf, count, offset, bos); |
| 572 | } |
| 573 | |
| 574 | __BIONIC_FORTIFY_INLINE |
| 575 | ssize_t pread64(int fd, void* buf, size_t count, off64_t offset) { |
| 576 | size_t bos = __bos0(buf); |
| 577 | |
Daniel Micay | e7e1c87 | 2015-04-16 09:07:45 -0400 | [diff] [blame] | 578 | if (__builtin_constant_p(count) && (count > SSIZE_MAX)) { |
| 579 | __pread64_count_toobig_error(); |
| 580 | } |
| 581 | |
| 582 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 583 | return __pread64_real(fd, buf, count, offset); |
| 584 | } |
| 585 | |
| 586 | if (__builtin_constant_p(count) && (count > bos)) { |
| 587 | __pread64_dest_size_error(); |
| 588 | } |
| 589 | |
| 590 | if (__builtin_constant_p(count) && (count <= bos)) { |
| 591 | return __pread64_real(fd, buf, count, offset); |
| 592 | } |
Daniel Micay | e7e1c87 | 2015-04-16 09:07:45 -0400 | [diff] [blame] | 593 | |
| 594 | return __pread64_chk(fd, buf, count, offset, bos); |
| 595 | } |
Elliott Hughes | 5bc78c8 | 2016-11-16 11:35:43 -0800 | [diff] [blame] | 596 | #endif /* __ANDROID_API__ >= __ANDROID_API_M__ */ |
Daniel Micay | e7e1c87 | 2015-04-16 09:07:45 -0400 | [diff] [blame] | 597 | |
Elliott Hughes | 5bc78c8 | 2016-11-16 11:35:43 -0800 | [diff] [blame] | 598 | #if __ANDROID_API__ >= __ANDROID_API_N__ |
Daniel Micay | afdd154 | 2015-07-20 21:37:29 -0400 | [diff] [blame] | 599 | __BIONIC_FORTIFY_INLINE |
| 600 | ssize_t pwrite(int fd, const void* buf, size_t count, off_t offset) { |
| 601 | size_t bos = __bos0(buf); |
| 602 | |
Daniel Micay | afdd154 | 2015-07-20 21:37:29 -0400 | [diff] [blame] | 603 | if (__builtin_constant_p(count) && (count > SSIZE_MAX)) { |
| 604 | __PWRITE_PREFIX(count_toobig_error)(); |
| 605 | } |
| 606 | |
| 607 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 608 | return __PWRITE_PREFIX(real)(fd, buf, count, offset); |
| 609 | } |
| 610 | |
| 611 | if (__builtin_constant_p(count) && (count > bos)) { |
| 612 | __PWRITE_PREFIX(dest_size_error)(); |
| 613 | } |
| 614 | |
| 615 | if (__builtin_constant_p(count) && (count <= bos)) { |
| 616 | return __PWRITE_PREFIX(real)(fd, buf, count, offset); |
| 617 | } |
Daniel Micay | afdd154 | 2015-07-20 21:37:29 -0400 | [diff] [blame] | 618 | |
| 619 | return __PWRITE_PREFIX(chk)(fd, buf, count, offset, bos); |
| 620 | } |
| 621 | |
| 622 | __BIONIC_FORTIFY_INLINE |
| 623 | ssize_t pwrite64(int fd, const void* buf, size_t count, off64_t offset) { |
| 624 | size_t bos = __bos0(buf); |
| 625 | |
Daniel Micay | afdd154 | 2015-07-20 21:37:29 -0400 | [diff] [blame] | 626 | if (__builtin_constant_p(count) && (count > SSIZE_MAX)) { |
| 627 | __pwrite64_count_toobig_error(); |
| 628 | } |
| 629 | |
| 630 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 631 | return __pwrite64_real(fd, buf, count, offset); |
| 632 | } |
| 633 | |
| 634 | if (__builtin_constant_p(count) && (count > bos)) { |
| 635 | __pwrite64_dest_size_error(); |
| 636 | } |
| 637 | |
| 638 | if (__builtin_constant_p(count) && (count <= bos)) { |
| 639 | return __pwrite64_real(fd, buf, count, offset); |
| 640 | } |
Daniel Micay | afdd154 | 2015-07-20 21:37:29 -0400 | [diff] [blame] | 641 | |
| 642 | return __pwrite64_chk(fd, buf, count, offset, bos); |
| 643 | } |
Elliott Hughes | 5bc78c8 | 2016-11-16 11:35:43 -0800 | [diff] [blame] | 644 | #endif /* __ANDROID_API__ >= __ANDROID_API_N__ */ |
Daniel Micay | afdd154 | 2015-07-20 21:37:29 -0400 | [diff] [blame] | 645 | |
Elliott Hughes | 5bc78c8 | 2016-11-16 11:35:43 -0800 | [diff] [blame] | 646 | #if __ANDROID_API__ >= __ANDROID_API_L__ |
Nick Kralevich | b036b5c | 2013-10-09 20:16:34 -0700 | [diff] [blame] | 647 | __BIONIC_FORTIFY_INLINE |
| 648 | ssize_t read(int fd, void* buf, size_t count) { |
| 649 | size_t bos = __bos0(buf); |
| 650 | |
Nick Kralevich | b036b5c | 2013-10-09 20:16:34 -0700 | [diff] [blame] | 651 | if (__builtin_constant_p(count) && (count > SSIZE_MAX)) { |
| 652 | __read_count_toobig_error(); |
| 653 | } |
| 654 | |
| 655 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 656 | return __read_real(fd, buf, count); |
| 657 | } |
| 658 | |
| 659 | if (__builtin_constant_p(count) && (count > bos)) { |
| 660 | __read_dest_size_error(); |
| 661 | } |
| 662 | |
| 663 | if (__builtin_constant_p(count) && (count <= bos)) { |
| 664 | return __read_real(fd, buf, count); |
| 665 | } |
Nick Kralevich | b036b5c | 2013-10-09 20:16:34 -0700 | [diff] [blame] | 666 | |
| 667 | return __read_chk(fd, buf, count, bos); |
| 668 | } |
Elliott Hughes | 5bc78c8 | 2016-11-16 11:35:43 -0800 | [diff] [blame] | 669 | #endif /* __ANDROID_API__ >= __ANDROID_API_L__ */ |
Daniel Micay | e7e1c87 | 2015-04-16 09:07:45 -0400 | [diff] [blame] | 670 | |
Elliott Hughes | 5bc78c8 | 2016-11-16 11:35:43 -0800 | [diff] [blame] | 671 | #if __ANDROID_API__ >= __ANDROID_API_N__ |
Daniel Micay | 4228188 | 2015-04-17 11:26:36 -0400 | [diff] [blame] | 672 | __BIONIC_FORTIFY_INLINE |
Daniel Micay | afdd154 | 2015-07-20 21:37:29 -0400 | [diff] [blame] | 673 | ssize_t write(int fd, const void* buf, size_t count) { |
| 674 | size_t bos = __bos0(buf); |
| 675 | |
Daniel Micay | afdd154 | 2015-07-20 21:37:29 -0400 | [diff] [blame] | 676 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 677 | return __write_real(fd, buf, count); |
| 678 | } |
| 679 | |
| 680 | if (__builtin_constant_p(count) && (count > bos)) { |
| 681 | __write_dest_size_error(); |
| 682 | } |
| 683 | |
| 684 | if (__builtin_constant_p(count) && (count <= bos)) { |
| 685 | return __write_real(fd, buf, count); |
| 686 | } |
Daniel Micay | afdd154 | 2015-07-20 21:37:29 -0400 | [diff] [blame] | 687 | |
| 688 | return __write_chk(fd, buf, count, bos); |
| 689 | } |
Elliott Hughes | 5bc78c8 | 2016-11-16 11:35:43 -0800 | [diff] [blame] | 690 | #endif /* __ANDROID_API__ >= __ANDROID_API_N__ */ |
Daniel Micay | afdd154 | 2015-07-20 21:37:29 -0400 | [diff] [blame] | 691 | |
Elliott Hughes | 5bc78c8 | 2016-11-16 11:35:43 -0800 | [diff] [blame] | 692 | #if __ANDROID_API__ >= __ANDROID_API_M__ |
Daniel Micay | afdd154 | 2015-07-20 21:37:29 -0400 | [diff] [blame] | 693 | __BIONIC_FORTIFY_INLINE |
Daniel Micay | 4228188 | 2015-04-17 11:26:36 -0400 | [diff] [blame] | 694 | ssize_t readlink(const char* path, char* buf, size_t size) { |
| 695 | size_t bos = __bos(buf); |
| 696 | |
Daniel Micay | 4228188 | 2015-04-17 11:26:36 -0400 | [diff] [blame] | 697 | if (__builtin_constant_p(size) && (size > SSIZE_MAX)) { |
| 698 | __readlink_size_toobig_error(); |
| 699 | } |
| 700 | |
| 701 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 702 | return __readlink_real(path, buf, size); |
| 703 | } |
| 704 | |
| 705 | if (__builtin_constant_p(size) && (size > bos)) { |
| 706 | __readlink_dest_size_error(); |
| 707 | } |
| 708 | |
| 709 | if (__builtin_constant_p(size) && (size <= bos)) { |
| 710 | return __readlink_real(path, buf, size); |
| 711 | } |
Daniel Micay | 4228188 | 2015-04-17 11:26:36 -0400 | [diff] [blame] | 712 | |
| 713 | return __readlink_chk(path, buf, size, bos); |
| 714 | } |
| 715 | |
| 716 | __BIONIC_FORTIFY_INLINE |
| 717 | ssize_t readlinkat(int dirfd, const char* path, char* buf, size_t size) { |
| 718 | size_t bos = __bos(buf); |
| 719 | |
Daniel Micay | 4228188 | 2015-04-17 11:26:36 -0400 | [diff] [blame] | 720 | if (__builtin_constant_p(size) && (size > SSIZE_MAX)) { |
| 721 | __readlinkat_size_toobig_error(); |
| 722 | } |
| 723 | |
| 724 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 725 | return __readlinkat_real(dirfd, path, buf, size); |
| 726 | } |
| 727 | |
| 728 | if (__builtin_constant_p(size) && (size > bos)) { |
| 729 | __readlinkat_dest_size_error(); |
| 730 | } |
| 731 | |
| 732 | if (__builtin_constant_p(size) && (size <= bos)) { |
| 733 | return __readlinkat_real(dirfd, path, buf, size); |
| 734 | } |
Daniel Micay | 4228188 | 2015-04-17 11:26:36 -0400 | [diff] [blame] | 735 | |
| 736 | return __readlinkat_chk(dirfd, path, buf, size, bos); |
| 737 | } |
Elliott Hughes | 5bc78c8 | 2016-11-16 11:35:43 -0800 | [diff] [blame] | 738 | #endif /* __ANDROID_API__ >= __ANDROID_API_M__ */ |
George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 739 | #endif /* defined(__clang__) */ |
| 740 | #undef __PREAD_PREFIX |
| 741 | #undef __PWRITE_PREFIX |
Nick Kralevich | b036b5c | 2013-10-09 20:16:34 -0700 | [diff] [blame] | 742 | #endif /* defined(__BIONIC_FORTIFY) */ |
| 743 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 744 | __END_DECLS |
| 745 | |
| 746 | #endif /* _UNISTD_H_ */ |