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); |
| 84 | pid_t gettid(void) __pure2; |
| 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); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 121 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 122 | long fpathconf(int __fd, int __name); |
| 123 | long pathconf(const char* __path, int __name); |
Elliott Hughes | a186b2e | 2014-09-22 14:49:07 -0700 | [diff] [blame] | 124 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 125 | int access(const char* __path, int __mode); |
| 126 | int faccessat(int __dirfd, const char* __path, int __mode, int __flags) __INTRODUCED_IN(16); |
| 127 | int link(const char* __oldpath, const char* __newpath); |
| 128 | int linkat(int __olddirfd, const char* __oldpath, int __newdirfd, |
| 129 | const char* __newpath, int __flags) __INTRODUCED_IN(21); |
| 130 | int unlink(const char* __path); |
| 131 | int unlinkat(int __dirfd, const char* __path, int __flags); |
| 132 | int chdir(const char* __path); |
| 133 | int fchdir(int __fd); |
| 134 | int rmdir(const char* __path); |
| 135 | int pipe(int* __pipefd); |
Elliott Hughes | 5f5cc45 | 2014-08-18 16:04:03 -0700 | [diff] [blame] | 136 | #if defined(__USE_GNU) |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 137 | int pipe2(int* __pipefd, int __flags) __INTRODUCED_IN(9); |
David 'Digit' Turner | 275cd48 | 2010-09-27 17:33:08 +0200 | [diff] [blame] | 138 | #endif |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 139 | int chroot(const char* __path); |
| 140 | int symlink(const char* __oldpath, const char* __newpath); |
| 141 | int symlinkat(const char* __oldpath, int __newdirfd, const char* __newpath) __INTRODUCED_IN(21); |
| 142 | ssize_t readlink(const char* __path, char* __buf, size_t __bufsiz); |
| 143 | ssize_t readlinkat(int __dirfd, const char* __path, char* __buf, |
| 144 | size_t __bufsiz) __INTRODUCED_IN(21); |
| 145 | int chown(const char* __path, uid_t __owner, gid_t __group); |
| 146 | int fchown(int __fd, uid_t __owner, gid_t __group); |
| 147 | int fchownat(int __dirfd, const char* __path, uid_t __owner, gid_t __group, int __flags); |
| 148 | int lchown(const char* __path, uid_t __owner, gid_t __group); |
| 149 | char* getcwd(char* __buf, size_t __size); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 150 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 151 | int sync(void); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 152 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 153 | int close(int __fd); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 154 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 155 | ssize_t read(int __fd, void* __buf, size_t __count); |
| 156 | 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] | 157 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 158 | int dup(int __oldfd); |
| 159 | int dup2(int __oldfd, int __newfd); |
| 160 | int dup3(int __oldfd, int __newfd, int __flags) __INTRODUCED_IN(21); |
| 161 | int fsync(int __fd); |
| 162 | int fdatasync(int __fd) __INTRODUCED_IN(9); |
Elliott Hughes | 68dc20d | 2015-02-06 22:28:49 -0800 | [diff] [blame] | 163 | |
| 164 | #if defined(__USE_FILE_OFFSET64) |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 165 | off_t lseek(int __fd, off_t __offset, int __whence) __RENAME(lseek64); |
Elliott Hughes | 68dc20d | 2015-02-06 22:28:49 -0800 | [diff] [blame] | 166 | #else |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 167 | off_t lseek(int __fd, off_t __offset, int __whence); |
Elliott Hughes | 68dc20d | 2015-02-06 22:28:49 -0800 | [diff] [blame] | 168 | #endif |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 169 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 170 | off64_t lseek64(int __fd, off64_t __offset, int __whence); |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 171 | |
| 172 | #if defined(__USE_FILE_OFFSET64) && __ANDROID_API__ >= 21 |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 173 | int truncate(const char* __path, off_t __length) __RENAME(truncate64) __INTRODUCED_IN(21); |
| 174 | ssize_t pread(int __fd, void* __buf, size_t __count, off_t __offset) __RENAME(pread64) |
Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 175 | __INTRODUCED_IN(12); |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 176 | ssize_t pwrite(int __fd, const void* __buf, size_t __count, off_t __offset) |
Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 177 | __RENAME(pwrite64) __INTRODUCED_IN(12); |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 178 | int ftruncate(int __fd, off_t __length) __RENAME(ftruncate64) __INTRODUCED_IN(12); |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 179 | #else |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 180 | int truncate(const char* __path, off_t __length); |
| 181 | ssize_t pread(int __fd, void* __buf, size_t __count, off_t __offset); |
| 182 | ssize_t pwrite(int __fd, const void* __buf, size_t __count, off_t __offset); |
| 183 | int ftruncate(int __fd, off_t __length); |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 184 | #endif |
| 185 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 186 | int truncate64(const char* __path, off64_t __length) __INTRODUCED_IN(21); |
| 187 | ssize_t pread64(int __fd, void* __buf, size_t __count, off64_t __offset) __INTRODUCED_IN(12); |
| 188 | ssize_t pwrite64(int __fd, const void* __buf, size_t __count, off64_t __offset) |
Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 189 | __INTRODUCED_IN(12); |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 190 | 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] | 191 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 192 | int pause(void); |
| 193 | unsigned int alarm(unsigned int __seconds); |
| 194 | unsigned int sleep(unsigned int __seconds); |
| 195 | int usleep(useconds_t __usec); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 196 | |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 197 | int gethostname(char* __name, size_t __len); |
Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 198 | 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] | 199 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 200 | int brk(void* __addr); |
| 201 | void* sbrk(ptrdiff_t __increment); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 202 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 203 | int isatty(int __fd); |
| 204 | char* ttyname(int __fd); |
| 205 | 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] | 206 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 207 | int acct(const char* __filepath); |
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 | #if __ANDROID_API__ >= 21 |
Josh Gao | b6a4a4c | 2016-07-26 16:34:40 -0700 | [diff] [blame] | 210 | int getpagesize(void) __INTRODUCED_IN(21); |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 211 | #else |
Dan Albert | a39f5d8 | 2016-09-14 17:10:26 -0700 | [diff] [blame^] | 212 | static __inline__ int getpagesize(void) { |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 213 | return sysconf(_SC_PAGESIZE); |
| 214 | } |
| 215 | #endif |
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 | long syscall(long __number, ...); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 218 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 219 | int daemon(int __nochdir, int __noclose); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 220 | |
Elliott Hughes | a6ecba4 | 2014-02-10 18:37:02 -0800 | [diff] [blame] | 221 | #if defined(__arm__) || (defined(__mips__) && !defined(__LP64__)) |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 222 | int cacheflush(long __addr, long __nbytes, long __cache); |
Elliott Hughes | a6ecba4 | 2014-02-10 18:37:02 -0800 | [diff] [blame] | 223 | /* __attribute__((deprecated("use __builtin___clear_cache instead"))); */ |
| 224 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 225 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 226 | pid_t tcgetpgrp(int __fd); |
| 227 | int tcsetpgrp(int __fd, pid_t __pid); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 228 | |
Elliott Hughes | cf399f7 | 2009-10-05 13:19:05 -0700 | [diff] [blame] | 229 | /* Used to retry syscalls that can return EINTR. */ |
| 230 | #define TEMP_FAILURE_RETRY(exp) ({ \ |
Dan Albert | a7821b7 | 2014-05-21 20:33:28 -0700 | [diff] [blame] | 231 | __typeof__(exp) _rc; \ |
Elliott Hughes | cf399f7 | 2009-10-05 13:19:05 -0700 | [diff] [blame] | 232 | do { \ |
| 233 | _rc = (exp); \ |
| 234 | } while (_rc == -1 && errno == EINTR); \ |
| 235 | _rc; }) |
| 236 | |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 237 | /* TODO(unified-headers): Factor out all the FORTIFY features. */ |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 238 | char* __getcwd_chk(char*, size_t, size_t) __INTRODUCED_IN(24); |
Daniel Micay | 9101b00 | 2015-05-20 15:31:26 -0400 | [diff] [blame] | 239 | __errordecl(__getcwd_dest_size_error, "getcwd called with size bigger than destination"); |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 240 | char* __getcwd_real(char*, size_t) __RENAME(getcwd); |
Daniel Micay | 9101b00 | 2015-05-20 15:31:26 -0400 | [diff] [blame] | 241 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 242 | ssize_t __pread_chk(int, void*, size_t, off_t, size_t) __INTRODUCED_IN(23); |
Daniel Micay | e7e1c87 | 2015-04-16 09:07:45 -0400 | [diff] [blame] | 243 | __errordecl(__pread_dest_size_error, "pread called with size bigger than destination"); |
| 244 | __errordecl(__pread_count_toobig_error, "pread called with count > SSIZE_MAX"); |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 245 | ssize_t __pread_real(int, void*, size_t, off_t) __RENAME(pread); |
Daniel Micay | e7e1c87 | 2015-04-16 09:07:45 -0400 | [diff] [blame] | 246 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 247 | ssize_t __pread64_chk(int, void*, size_t, off64_t, size_t) __INTRODUCED_IN(23); |
Daniel Micay | e7e1c87 | 2015-04-16 09:07:45 -0400 | [diff] [blame] | 248 | __errordecl(__pread64_dest_size_error, "pread64 called with size bigger than destination"); |
| 249 | __errordecl(__pread64_count_toobig_error, "pread64 called with count > SSIZE_MAX"); |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 250 | 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] | 251 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 252 | ssize_t __pwrite_chk(int, const void*, size_t, off_t, size_t) __INTRODUCED_IN(24); |
Daniel Micay | afdd154 | 2015-07-20 21:37:29 -0400 | [diff] [blame] | 253 | __errordecl(__pwrite_dest_size_error, "pwrite called with size bigger than destination"); |
| 254 | __errordecl(__pwrite_count_toobig_error, "pwrite called with count > SSIZE_MAX"); |
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); |
Daniel Micay | afdd154 | 2015-07-20 21:37:29 -0400 | [diff] [blame] | 258 | __errordecl(__pwrite64_dest_size_error, "pwrite64 called with size bigger than destination"); |
| 259 | __errordecl(__pwrite64_count_toobig_error, "pwrite64 called with count > SSIZE_MAX"); |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 260 | ssize_t __pwrite64_real(int, const void*, size_t, off64_t) __RENAME(pwrite64) __INTRODUCED_IN(12); |
Daniel Micay | afdd154 | 2015-07-20 21:37:29 -0400 | [diff] [blame] | 261 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 262 | ssize_t __read_chk(int, void*, size_t, size_t) __INTRODUCED_IN(21); |
Nick Kralevich | b036b5c | 2013-10-09 20:16:34 -0700 | [diff] [blame] | 263 | __errordecl(__read_dest_size_error, "read called with size bigger than destination"); |
| 264 | __errordecl(__read_count_toobig_error, "read called with count > SSIZE_MAX"); |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 265 | ssize_t __read_real(int, void*, size_t) __RENAME(read); |
Nick Kralevich | b036b5c | 2013-10-09 20:16:34 -0700 | [diff] [blame] | 266 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 267 | ssize_t __write_chk(int, const void*, size_t, size_t) __INTRODUCED_IN(24); |
Daniel Micay | afdd154 | 2015-07-20 21:37:29 -0400 | [diff] [blame] | 268 | __errordecl(__write_dest_size_error, "write called with size bigger than destination"); |
| 269 | __errordecl(__write_count_toobig_error, "write called with count > SSIZE_MAX"); |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 270 | ssize_t __write_real(int, const void*, size_t) __RENAME(write); |
Daniel Micay | afdd154 | 2015-07-20 21:37:29 -0400 | [diff] [blame] | 271 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 272 | ssize_t __readlink_chk(const char*, char*, size_t, size_t) __INTRODUCED_IN(23); |
Daniel Micay | 4228188 | 2015-04-17 11:26:36 -0400 | [diff] [blame] | 273 | __errordecl(__readlink_dest_size_error, "readlink called with size bigger than destination"); |
| 274 | __errordecl(__readlink_size_toobig_error, "readlink called with size > SSIZE_MAX"); |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 275 | ssize_t __readlink_real(const char*, char*, size_t) __RENAME(readlink); |
Daniel Micay | 4228188 | 2015-04-17 11:26:36 -0400 | [diff] [blame] | 276 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 277 | 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] | 278 | __errordecl(__readlinkat_dest_size_error, "readlinkat called with size bigger than destination"); |
| 279 | __errordecl(__readlinkat_size_toobig_error, "readlinkat called with size > SSIZE_MAX"); |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 280 | ssize_t __readlinkat_real(int dirfd, const char*, char*, size_t) __RENAME(readlinkat) __INTRODUCED_IN(21); |
Daniel Micay | 4228188 | 2015-04-17 11:26:36 -0400 | [diff] [blame] | 281 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 282 | int getdomainname(char*, size_t) __INTRODUCED_IN_FUTURE; |
| 283 | int setdomainname(const char*, size_t) __INTRODUCED_IN_FUTURE; |
Greg Hackmann | e2faf07 | 2016-03-03 08:37:53 -0800 | [diff] [blame] | 284 | |
Dan Albert | 658727e | 2014-10-07 11:10:36 -0700 | [diff] [blame] | 285 | #if defined(__BIONIC_FORTIFY) |
| 286 | |
Dan Albert | dfa6bbb | 2016-08-02 15:08:32 -0700 | [diff] [blame] | 287 | #if __ANDROID_API__ >= 24 |
Daniel Micay | 9101b00 | 2015-05-20 15:31:26 -0400 | [diff] [blame] | 288 | __BIONIC_FORTIFY_INLINE |
| 289 | char* getcwd(char* buf, size_t size) { |
| 290 | size_t bos = __bos(buf); |
| 291 | |
| 292 | #if defined(__clang__) |
| 293 | /* |
| 294 | * Work around LLVM's incorrect __builtin_object_size implementation here |
| 295 | * to avoid needing the workaround in the __getcwd_chk ABI forever. |
| 296 | * |
| 297 | * https://llvm.org/bugs/show_bug.cgi?id=23277 |
| 298 | */ |
| 299 | if (buf == NULL) { |
| 300 | bos = __BIONIC_FORTIFY_UNKNOWN_SIZE; |
| 301 | } |
| 302 | #else |
| 303 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 304 | return __getcwd_real(buf, size); |
| 305 | } |
| 306 | |
| 307 | if (__builtin_constant_p(size) && (size > bos)) { |
| 308 | __getcwd_dest_size_error(); |
| 309 | } |
| 310 | |
| 311 | if (__builtin_constant_p(size) && (size <= bos)) { |
| 312 | return __getcwd_real(buf, size); |
| 313 | } |
| 314 | #endif |
| 315 | |
| 316 | return __getcwd_chk(buf, size, bos); |
| 317 | } |
Dan Albert | dfa6bbb | 2016-08-02 15:08:32 -0700 | [diff] [blame] | 318 | #endif /* __ANDROID_API__ >= 24 */ |
Daniel Micay | 9101b00 | 2015-05-20 15:31:26 -0400 | [diff] [blame] | 319 | |
Daniel Micay | e7e1c87 | 2015-04-16 09:07:45 -0400 | [diff] [blame] | 320 | #if defined(__USE_FILE_OFFSET64) |
| 321 | #define __PREAD_PREFIX(x) __pread64_ ## x |
| 322 | #else |
| 323 | #define __PREAD_PREFIX(x) __pread_ ## x |
| 324 | #endif |
| 325 | |
Dan Albert | dfa6bbb | 2016-08-02 15:08:32 -0700 | [diff] [blame] | 326 | #if __ANDROID_API__ >= 23 |
Daniel Micay | e7e1c87 | 2015-04-16 09:07:45 -0400 | [diff] [blame] | 327 | __BIONIC_FORTIFY_INLINE |
| 328 | ssize_t pread(int fd, void* buf, size_t count, off_t offset) { |
| 329 | size_t bos = __bos0(buf); |
| 330 | |
| 331 | #if !defined(__clang__) |
| 332 | if (__builtin_constant_p(count) && (count > SSIZE_MAX)) { |
| 333 | __PREAD_PREFIX(count_toobig_error)(); |
| 334 | } |
| 335 | |
| 336 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 337 | return __PREAD_PREFIX(real)(fd, buf, count, offset); |
| 338 | } |
| 339 | |
| 340 | if (__builtin_constant_p(count) && (count > bos)) { |
| 341 | __PREAD_PREFIX(dest_size_error)(); |
| 342 | } |
| 343 | |
| 344 | if (__builtin_constant_p(count) && (count <= bos)) { |
| 345 | return __PREAD_PREFIX(real)(fd, buf, count, offset); |
| 346 | } |
| 347 | #endif |
| 348 | |
| 349 | return __PREAD_PREFIX(chk)(fd, buf, count, offset, bos); |
| 350 | } |
| 351 | |
| 352 | __BIONIC_FORTIFY_INLINE |
| 353 | ssize_t pread64(int fd, void* buf, size_t count, off64_t offset) { |
| 354 | size_t bos = __bos0(buf); |
| 355 | |
| 356 | #if !defined(__clang__) |
| 357 | if (__builtin_constant_p(count) && (count > SSIZE_MAX)) { |
| 358 | __pread64_count_toobig_error(); |
| 359 | } |
| 360 | |
| 361 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 362 | return __pread64_real(fd, buf, count, offset); |
| 363 | } |
| 364 | |
| 365 | if (__builtin_constant_p(count) && (count > bos)) { |
| 366 | __pread64_dest_size_error(); |
| 367 | } |
| 368 | |
| 369 | if (__builtin_constant_p(count) && (count <= bos)) { |
| 370 | return __pread64_real(fd, buf, count, offset); |
| 371 | } |
| 372 | #endif |
| 373 | |
| 374 | return __pread64_chk(fd, buf, count, offset, bos); |
| 375 | } |
Dan Albert | dfa6bbb | 2016-08-02 15:08:32 -0700 | [diff] [blame] | 376 | #endif /* __ANDROID_API__ >= 23 */ |
Daniel Micay | e7e1c87 | 2015-04-16 09:07:45 -0400 | [diff] [blame] | 377 | |
Daniel Micay | afdd154 | 2015-07-20 21:37:29 -0400 | [diff] [blame] | 378 | #if defined(__USE_FILE_OFFSET64) |
| 379 | #define __PWRITE_PREFIX(x) __pwrite64_ ## x |
| 380 | #else |
| 381 | #define __PWRITE_PREFIX(x) __pwrite_ ## x |
| 382 | #endif |
| 383 | |
Dan Albert | dfa6bbb | 2016-08-02 15:08:32 -0700 | [diff] [blame] | 384 | #if __ANDROID_API__ >= 24 |
Daniel Micay | afdd154 | 2015-07-20 21:37:29 -0400 | [diff] [blame] | 385 | __BIONIC_FORTIFY_INLINE |
| 386 | ssize_t pwrite(int fd, const void* buf, size_t count, off_t offset) { |
| 387 | size_t bos = __bos0(buf); |
| 388 | |
| 389 | #if !defined(__clang__) |
| 390 | if (__builtin_constant_p(count) && (count > SSIZE_MAX)) { |
| 391 | __PWRITE_PREFIX(count_toobig_error)(); |
| 392 | } |
| 393 | |
| 394 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 395 | return __PWRITE_PREFIX(real)(fd, buf, count, offset); |
| 396 | } |
| 397 | |
| 398 | if (__builtin_constant_p(count) && (count > bos)) { |
| 399 | __PWRITE_PREFIX(dest_size_error)(); |
| 400 | } |
| 401 | |
| 402 | if (__builtin_constant_p(count) && (count <= bos)) { |
| 403 | return __PWRITE_PREFIX(real)(fd, buf, count, offset); |
| 404 | } |
| 405 | #endif |
| 406 | |
| 407 | return __PWRITE_PREFIX(chk)(fd, buf, count, offset, bos); |
| 408 | } |
| 409 | |
| 410 | __BIONIC_FORTIFY_INLINE |
| 411 | ssize_t pwrite64(int fd, const void* buf, size_t count, off64_t offset) { |
| 412 | size_t bos = __bos0(buf); |
| 413 | |
| 414 | #if !defined(__clang__) |
| 415 | if (__builtin_constant_p(count) && (count > SSIZE_MAX)) { |
| 416 | __pwrite64_count_toobig_error(); |
| 417 | } |
| 418 | |
| 419 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 420 | return __pwrite64_real(fd, buf, count, offset); |
| 421 | } |
| 422 | |
| 423 | if (__builtin_constant_p(count) && (count > bos)) { |
| 424 | __pwrite64_dest_size_error(); |
| 425 | } |
| 426 | |
| 427 | if (__builtin_constant_p(count) && (count <= bos)) { |
| 428 | return __pwrite64_real(fd, buf, count, offset); |
| 429 | } |
| 430 | #endif |
| 431 | |
| 432 | return __pwrite64_chk(fd, buf, count, offset, bos); |
| 433 | } |
Dan Albert | dfa6bbb | 2016-08-02 15:08:32 -0700 | [diff] [blame] | 434 | #endif /* __ANDROID_API__ >= 24 */ |
Daniel Micay | afdd154 | 2015-07-20 21:37:29 -0400 | [diff] [blame] | 435 | |
Dan Albert | dfa6bbb | 2016-08-02 15:08:32 -0700 | [diff] [blame] | 436 | #if __ANDROID_API__ >= 21 |
Nick Kralevich | b036b5c | 2013-10-09 20:16:34 -0700 | [diff] [blame] | 437 | __BIONIC_FORTIFY_INLINE |
| 438 | ssize_t read(int fd, void* buf, size_t count) { |
| 439 | size_t bos = __bos0(buf); |
| 440 | |
| 441 | #if !defined(__clang__) |
| 442 | if (__builtin_constant_p(count) && (count > SSIZE_MAX)) { |
| 443 | __read_count_toobig_error(); |
| 444 | } |
| 445 | |
| 446 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 447 | return __read_real(fd, buf, count); |
| 448 | } |
| 449 | |
| 450 | if (__builtin_constant_p(count) && (count > bos)) { |
| 451 | __read_dest_size_error(); |
| 452 | } |
| 453 | |
| 454 | if (__builtin_constant_p(count) && (count <= bos)) { |
| 455 | return __read_real(fd, buf, count); |
| 456 | } |
| 457 | #endif |
| 458 | |
| 459 | return __read_chk(fd, buf, count, bos); |
| 460 | } |
Dan Albert | dfa6bbb | 2016-08-02 15:08:32 -0700 | [diff] [blame] | 461 | #endif /* __ANDROID_API__ >= 21 */ |
Daniel Micay | e7e1c87 | 2015-04-16 09:07:45 -0400 | [diff] [blame] | 462 | |
Dan Albert | dfa6bbb | 2016-08-02 15:08:32 -0700 | [diff] [blame] | 463 | #if __ANDROID_API__ >= 24 |
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 | } |
Dan Albert | dfa6bbb | 2016-08-02 15:08:32 -0700 | [diff] [blame] | 490 | #endif /* __ANDROID_API__ >= 24 */ |
Daniel Micay | afdd154 | 2015-07-20 21:37:29 -0400 | [diff] [blame] | 491 | |
Dan Albert | 2990404 | 2016-09-08 16:11:23 -0700 | [diff] [blame] | 492 | #if __ANDROID_API__ >= 23 |
Daniel Micay | afdd154 | 2015-07-20 21:37:29 -0400 | [diff] [blame] | 493 | __BIONIC_FORTIFY_INLINE |
Daniel Micay | 4228188 | 2015-04-17 11:26:36 -0400 | [diff] [blame] | 494 | ssize_t readlink(const char* path, char* buf, size_t size) { |
| 495 | size_t bos = __bos(buf); |
| 496 | |
| 497 | #if !defined(__clang__) |
| 498 | if (__builtin_constant_p(size) && (size > SSIZE_MAX)) { |
| 499 | __readlink_size_toobig_error(); |
| 500 | } |
| 501 | |
| 502 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 503 | return __readlink_real(path, buf, size); |
| 504 | } |
| 505 | |
| 506 | if (__builtin_constant_p(size) && (size > bos)) { |
| 507 | __readlink_dest_size_error(); |
| 508 | } |
| 509 | |
| 510 | if (__builtin_constant_p(size) && (size <= bos)) { |
| 511 | return __readlink_real(path, buf, size); |
| 512 | } |
| 513 | #endif |
| 514 | |
| 515 | return __readlink_chk(path, buf, size, bos); |
| 516 | } |
| 517 | |
| 518 | __BIONIC_FORTIFY_INLINE |
| 519 | ssize_t readlinkat(int dirfd, const char* path, char* buf, size_t size) { |
| 520 | size_t bos = __bos(buf); |
| 521 | |
| 522 | #if !defined(__clang__) |
| 523 | if (__builtin_constant_p(size) && (size > SSIZE_MAX)) { |
| 524 | __readlinkat_size_toobig_error(); |
| 525 | } |
| 526 | |
| 527 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 528 | return __readlinkat_real(dirfd, path, buf, size); |
| 529 | } |
| 530 | |
| 531 | if (__builtin_constant_p(size) && (size > bos)) { |
| 532 | __readlinkat_dest_size_error(); |
| 533 | } |
| 534 | |
| 535 | if (__builtin_constant_p(size) && (size <= bos)) { |
| 536 | return __readlinkat_real(dirfd, path, buf, size); |
| 537 | } |
| 538 | #endif |
| 539 | |
| 540 | return __readlinkat_chk(dirfd, path, buf, size, bos); |
| 541 | } |
Dan Albert | 2990404 | 2016-09-08 16:11:23 -0700 | [diff] [blame] | 542 | #endif /* __ANDROID_API__ >= 23 */ |
Daniel Micay | 4228188 | 2015-04-17 11:26:36 -0400 | [diff] [blame] | 543 | |
Nick Kralevich | b036b5c | 2013-10-09 20:16:34 -0700 | [diff] [blame] | 544 | #endif /* defined(__BIONIC_FORTIFY) */ |
| 545 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 546 | __END_DECLS |
| 547 | |
| 548 | #endif /* _UNISTD_H_ */ |