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 */ 28 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 37 #include <bits/fcntl.h> 38 #include <bits/getopt.h> 39 #include <bits/ioctl.h> 40 #include <bits/lockf.h> 41 #include <bits/posix_limits.h> 42 #include <bits/seek_constants.h> 43 #include <bits/sysconf.h> 44 45 __BEGIN_DECLS 46 47 #define STDIN_FILENO 0 48 #define STDOUT_FILENO 1 49 #define STDERR_FILENO 2 50 51 #define F_OK 0 52 #define X_OK 1 53 #define W_OK 2 54 #define R_OK 4 55 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 77 extern char** environ; 78 79 __noreturn void _exit(int __status); 80 81 pid_t fork(void); 82 pid_t vfork(void); 83 pid_t getpid(void); 84 pid_t gettid(void) __attribute_const__; 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); 92 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); 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))); 101 102 int nice(int __incr); 103 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); 121 122 long fpathconf(int __fd, int __name); 123 long pathconf(const char* __path, int __name); 124 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); 136 #if defined(__USE_GNU) 137 int pipe2(int* __pipefd, int __flags) __INTRODUCED_IN(9); 138 #endif 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 __overloadable __RENAME_CLANG(readlink); 144 ssize_t readlinkat(int __dirfd, const char* __path, char* __buf, 145 size_t __bufsiz) 146 __INTRODUCED_IN(21) __overloadable __RENAME_CLANG(readlinkat); 147 int chown(const char* __path, uid_t __owner, gid_t __group); 148 int fchown(int __fd, uid_t __owner, gid_t __group); 149 int fchownat(int __dirfd, const char* __path, uid_t __owner, gid_t __group, int __flags); 150 int lchown(const char* __path, uid_t __owner, gid_t __group); 151 char* getcwd(char* __buf, size_t __size) __overloadable __RENAME_CLANG(getcwd); 152 153 void sync(void); 154 155 int close(int __fd); 156 157 ssize_t read(int __fd, void* __buf, size_t __count) __overloadable 158 __RENAME_CLANG(read); 159 ssize_t write(int __fd, const void* __buf, size_t __count) __overloadable 160 __RENAME_CLANG(write); 161 162 int dup(int __oldfd); 163 int dup2(int __oldfd, int __newfd); 164 int dup3(int __oldfd, int __newfd, int __flags) __INTRODUCED_IN(21); 165 int fsync(int __fd); 166 int fdatasync(int __fd) __INTRODUCED_IN(9); 167 168 #if defined(__USE_FILE_OFFSET64) 169 off_t lseek(int __fd, off_t __offset, int __whence) __RENAME(lseek64); 170 #else 171 off_t lseek(int __fd, off_t __offset, int __whence); 172 #endif 173 174 off64_t lseek64(int __fd, off64_t __offset, int __whence); 175 176 #if defined(__USE_FILE_OFFSET64) && __ANDROID_API__ >= __ANDROID_API_L__ 177 int truncate(const char* __path, off_t __length) __RENAME(truncate64) __INTRODUCED_IN(21); 178 ssize_t pread(int __fd, void* __buf, size_t __count, off_t __offset) 179 __overloadable __RENAME(pread64) __INTRODUCED_IN(12); 180 ssize_t pwrite(int __fd, const void* __buf, size_t __count, off_t __offset) 181 __overloadable __RENAME(pwrite64) __INTRODUCED_IN(12); 182 int ftruncate(int __fd, off_t __length) __RENAME(ftruncate64) __INTRODUCED_IN(12); 183 #else 184 int truncate(const char* __path, off_t __length); 185 ssize_t pread(int __fd, void* __buf, size_t __count, off_t __offset) 186 __overloadable __RENAME_CLANG(pread); 187 ssize_t pwrite(int __fd, const void* __buf, size_t __count, off_t __offset) 188 __overloadable __RENAME_CLANG(pwrite); 189 int ftruncate(int __fd, off_t __length); 190 #endif 191 192 int truncate64(const char* __path, off64_t __length) __INTRODUCED_IN(21); 193 ssize_t pread64(int __fd, void* __buf, size_t __count, off64_t __offset) 194 __INTRODUCED_IN(12) __overloadable __RENAME_CLANG(pread64); 195 ssize_t pwrite64(int __fd, const void* __buf, size_t __count, off64_t __offset) 196 __INTRODUCED_IN(12) __overloadable __RENAME_CLANG(pwrite64); 197 int ftruncate64(int __fd, off64_t __length) __INTRODUCED_IN(12); 198 199 int pause(void); 200 unsigned int alarm(unsigned int __seconds); 201 unsigned int sleep(unsigned int __seconds); 202 int usleep(useconds_t __usec); 203 204 int gethostname(char* __name, size_t __len); 205 int sethostname(const char* __name, size_t __len) __INTRODUCED_IN(23); 206 207 int brk(void* __addr); 208 void* sbrk(ptrdiff_t __increment); 209 210 int isatty(int __fd); 211 char* ttyname(int __fd); 212 int ttyname_r(int __fd, char* __buf, size_t __buflen) __INTRODUCED_IN(8); 213 214 int acct(const char* __filepath); 215 216 #if __ANDROID_API__ >= __ANDROID_API_L__ 217 int getpagesize(void) __INTRODUCED_IN(21); 218 #else 219 static __inline__ int getpagesize(void) { 220 return sysconf(_SC_PAGESIZE); 221 } 222 #endif 223 224 long syscall(long __number, ...); 225 226 int daemon(int __nochdir, int __noclose); 227 228 #if defined(__arm__) || (defined(__mips__) && !defined(__LP64__)) 229 int cacheflush(long __addr, long __nbytes, long __cache); 230 /* __attribute__((deprecated("use __builtin___clear_cache instead"))); */ 231 #endif 232 233 pid_t tcgetpgrp(int __fd); 234 int tcsetpgrp(int __fd, pid_t __pid); 235 236 /* Used to retry syscalls that can return EINTR. */ 237 #define TEMP_FAILURE_RETRY(exp) ({ \ 238 __typeof__(exp) _rc; \ 239 do { \ 240 _rc = (exp); \ 241 } while (_rc == -1 && errno == EINTR); \ 242 _rc; }) 243 244 /* TODO(unified-headers): Factor out all the FORTIFY features. */ 245 char* __getcwd_chk(char*, size_t, size_t) __INTRODUCED_IN(24); 246 247 ssize_t __pread_chk(int, void*, size_t, off_t, size_t) __INTRODUCED_IN(23); 248 ssize_t __pread_real(int, void*, size_t, off_t) __RENAME(pread); 249 250 ssize_t __pread64_chk(int, void*, size_t, off64_t, size_t) __INTRODUCED_IN(23); 251 ssize_t __pread64_real(int, void*, size_t, off64_t) __RENAME(pread64) __INTRODUCED_IN(12); 252 253 ssize_t __pwrite_chk(int, const void*, size_t, off_t, size_t) __INTRODUCED_IN(24); 254 ssize_t __pwrite_real(int, const void*, size_t, off_t) __RENAME(pwrite); 255 256 ssize_t __pwrite64_chk(int, const void*, size_t, off64_t, size_t) __INTRODUCED_IN(24); 257 ssize_t __pwrite64_real(int, const void*, size_t, off64_t) __RENAME(pwrite64) 258 __INTRODUCED_IN(12); 259 260 ssize_t __read_chk(int, void*, size_t, size_t) __INTRODUCED_IN(21); 261 ssize_t __write_chk(int, const void*, size_t, size_t) __INTRODUCED_IN(24); 262 ssize_t __readlink_chk(const char*, char*, size_t, size_t) __INTRODUCED_IN(23); 263 ssize_t __readlinkat_chk(int dirfd, const char*, char*, size_t, size_t) __INTRODUCED_IN(23); 264 265 int getdomainname(char*, size_t) __INTRODUCED_IN(26); 266 int setdomainname(const char*, size_t) __INTRODUCED_IN(26); 267 268 #if defined(__BIONIC_FORTIFY) 269 270 #if defined(__USE_FILE_OFFSET64) 271 #define __PREAD_PREFIX(x) __pread64_ ## x 272 #define __PWRITE_PREFIX(x) __pwrite64_ ## x 273 #else 274 #define __PREAD_PREFIX(x) __pread_ ## x 275 #define __PWRITE_PREFIX(x) __pwrite_ ## x 276 #endif 277 278 #if defined(__clang__) 279 #define __error_if_overflows_ssizet(what) \ 280 __enable_if(what > SSIZE_MAX, #what " must be <= SSIZE_MAX") \ 281 __errorattr(#what " must be <= SSIZE_MAX") 282 283 #define __enable_if_no_overflow_ssizet(what) \ 284 __enable_if((what) <= SSIZE_MAX, "enabled if " #what " <= SSIZE_MAX") 285 286 #define __error_if_overflows_objectsize(what, objsize) \ 287 __enable_if((objsize) != __BIONIC_FORTIFY_UNKNOWN_SIZE && \ 288 (what) > (objsize), \ 289 "'" #what "' bytes overflows the given object") \ 290 __errorattr("'" #what "' bytes overflows the given object") 291 292 __BIONIC_ERROR_FUNCTION_VISIBILITY 293 char* getcwd(char* buf, size_t size) __overloadable 294 __error_if_overflows_objectsize(size, __bos(buf)); 295 296 #if __ANDROID_API__ >= __ANDROID_API_N__ 297 __BIONIC_FORTIFY_INLINE 298 char* getcwd(char* const __pass_object_size buf, size_t size) __overloadable { 299 size_t bos = __bos(buf); 300 301 /* 302 * Clang responds bos==0 if buf==NULL 303 * (https://llvm.org/bugs/show_bug.cgi?id=23277). Given that NULL is a valid 304 * value, we need to handle that. 305 */ 306 if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE || buf == NULL) { 307 return __call_bypassing_fortify(getcwd)(buf, size); 308 } 309 310 return __getcwd_chk(buf, size, bos); 311 } 312 #endif /* __ANDROID_API__ >= __ANDROID_API_N__ */ 313 314 #if __ANDROID_API__ >= __ANDROID_API_M__ 315 __BIONIC_ERROR_FUNCTION_VISIBILITY 316 ssize_t pread(int fd, void* buf, size_t count, off_t offset) __overloadable 317 __error_if_overflows_ssizet(count); 318 319 __BIONIC_ERROR_FUNCTION_VISIBILITY 320 ssize_t pread(int fd, void* buf, size_t count, off_t offset) __overloadable 321 __enable_if_no_overflow_ssizet(count) 322 __error_if_overflows_objectsize(count, __bos0(buf)); 323 324 __BIONIC_FORTIFY_INLINE 325 ssize_t pread(int fd, void* const __pass_object_size0 buf, size_t count, 326 off_t offset) __overloadable { 327 size_t bos = __bos0(buf); 328 329 if (count == __BIONIC_FORTIFY_UNKNOWN_SIZE) { 330 return __PREAD_PREFIX(real)(fd, buf, count, offset); 331 } 332 333 return __PREAD_PREFIX(chk)(fd, buf, count, offset, bos); 334 } 335 336 __BIONIC_ERROR_FUNCTION_VISIBILITY 337 ssize_t pread64(int fd, void* buf, size_t count, off64_t offset) __overloadable 338 __error_if_overflows_ssizet(count); 339 340 __BIONIC_ERROR_FUNCTION_VISIBILITY 341 ssize_t pread64(int fd, void* buf, size_t count, off64_t offset) __overloadable 342 __enable_if_no_overflow_ssizet(count) 343 __error_if_overflows_objectsize(count, __bos0(buf)); 344 345 __BIONIC_FORTIFY_INLINE 346 ssize_t pread64(int fd, void* const __pass_object_size0 buf, size_t count, 347 off64_t offset) __overloadable { 348 size_t bos = __bos0(buf); 349 350 if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { 351 return __pread64_real(fd, buf, count, offset); 352 } 353 354 return __pread64_chk(fd, buf, count, offset, bos); 355 } 356 #endif /* __ANDROID_API__ >= __ANDROID_API_M__ */ 357 358 #if __ANDROID_API__ >= __ANDROID_API_N__ 359 __BIONIC_ERROR_FUNCTION_VISIBILITY 360 ssize_t pwrite(int fd, const void* buf, size_t count, off_t offset) 361 __overloadable 362 __error_if_overflows_ssizet(count); 363 364 __BIONIC_ERROR_FUNCTION_VISIBILITY 365 ssize_t pwrite(int fd, const void* buf, size_t count, off_t offset) 366 __overloadable 367 __enable_if_no_overflow_ssizet(count) 368 __error_if_overflows_objectsize(count, __bos0(buf)); 369 370 __BIONIC_FORTIFY_INLINE 371 ssize_t pwrite(int fd, const void* const __pass_object_size0 buf, size_t count, 372 off_t offset) __overloadable { 373 size_t bos = __bos0(buf); 374 375 if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { 376 return __PWRITE_PREFIX(real)(fd, buf, count, offset); 377 } 378 379 return __PWRITE_PREFIX(chk)(fd, buf, count, offset, bos); 380 } 381 382 __BIONIC_ERROR_FUNCTION_VISIBILITY 383 ssize_t pwrite64(int fd, const void* buf, size_t count, off64_t offset) 384 __overloadable 385 __error_if_overflows_ssizet(count); 386 387 __BIONIC_ERROR_FUNCTION_VISIBILITY 388 ssize_t pwrite64(int fd, const void* buf, size_t count, off64_t offset) 389 __overloadable 390 __enable_if_no_overflow_ssizet(count) 391 __error_if_overflows_objectsize(count, __bos0(buf)); 392 393 __BIONIC_FORTIFY_INLINE 394 ssize_t pwrite64(int fd, const void* const __pass_object_size0 buf, 395 size_t count, off64_t offset) __overloadable { 396 size_t bos = __bos0(buf); 397 398 if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { 399 return __pwrite64_real(fd, buf, count, offset); 400 } 401 402 return __pwrite64_chk(fd, buf, count, offset, bos); 403 } 404 #endif /* __ANDROID_API__ >= __ANDROID_API_N__ */ 405 406 #if __ANDROID_API__ >= __ANDROID_API_L__ 407 __BIONIC_ERROR_FUNCTION_VISIBILITY 408 ssize_t read(int fd, void* buf, size_t count) __overloadable 409 __error_if_overflows_ssizet(count); 410 411 __BIONIC_ERROR_FUNCTION_VISIBILITY 412 ssize_t read(int fd, void* buf, size_t count) __overloadable 413 __enable_if_no_overflow_ssizet(count) 414 __error_if_overflows_objectsize(count, __bos0(buf)); 415 416 __BIONIC_FORTIFY_INLINE 417 ssize_t read(int fd, void* const __pass_object_size0 buf, size_t count) 418 __overloadable { 419 size_t bos = __bos0(buf); 420 421 if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { 422 return __call_bypassing_fortify(read)(fd, buf, count); 423 } 424 425 return __read_chk(fd, buf, count, bos); 426 } 427 #endif /* __ANDROID_API__ >= __ANDROID_API_L__ */ 428 429 #if __ANDROID_API__ >= __ANDROID_API_N__ 430 __BIONIC_ERROR_FUNCTION_VISIBILITY 431 ssize_t write(int fd, const void* buf, size_t count) __overloadable 432 __error_if_overflows_ssizet(count); 433 434 __BIONIC_ERROR_FUNCTION_VISIBILITY 435 ssize_t write(int fd, const void* buf, size_t count) __overloadable 436 __enable_if_no_overflow_ssizet(count) 437 __error_if_overflows_objectsize(count, __bos0(buf)); 438 439 __BIONIC_FORTIFY_INLINE 440 ssize_t write(int fd, const void* const __pass_object_size0 buf, size_t count) 441 __overloadable { 442 size_t bos = __bos0(buf); 443 444 if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { 445 return __call_bypassing_fortify(write)(fd, buf, count); 446 } 447 448 return __write_chk(fd, buf, count, bos); 449 } 450 #endif /* __ANDROID_API__ >= __ANDROID_API_N__ */ 451 452 #if __ANDROID_API__ >= __ANDROID_API_M__ 453 __BIONIC_ERROR_FUNCTION_VISIBILITY 454 ssize_t readlink(const char* path, char* buf, size_t size) __overloadable 455 __error_if_overflows_ssizet(size); 456 457 __BIONIC_ERROR_FUNCTION_VISIBILITY 458 ssize_t readlink(const char* path, char* buf, size_t size) __overloadable 459 __enable_if_no_overflow_ssizet(size) 460 __error_if_overflows_objectsize(size, __bos(buf)); 461 462 __BIONIC_FORTIFY_INLINE 463 ssize_t readlink(const char* path, char* const __pass_object_size buf, 464 size_t size) __overloadable { 465 size_t bos = __bos(buf); 466 467 if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { 468 return __call_bypassing_fortify(readlink)(path, buf, size); 469 } 470 471 return __readlink_chk(path, buf, size, bos); 472 } 473 474 __BIONIC_ERROR_FUNCTION_VISIBILITY 475 ssize_t readlinkat(int dirfd, const char* path, char* buf, size_t size) 476 __overloadable 477 __error_if_overflows_ssizet(size); 478 479 __BIONIC_ERROR_FUNCTION_VISIBILITY 480 ssize_t readlinkat(int dirfd, const char* path, char* buf, size_t size) 481 __overloadable 482 __enable_if_no_overflow_ssizet(size) 483 __error_if_overflows_objectsize(size, __bos(buf)); 484 485 __BIONIC_FORTIFY_INLINE 486 ssize_t readlinkat(int dirfd, const char* path, 487 char* const __pass_object_size buf, size_t size) 488 __overloadable { 489 size_t bos = __bos(buf); 490 491 if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { 492 return __call_bypassing_fortify(readlinkat)(dirfd, path, buf, size); 493 } 494 495 return __readlinkat_chk(dirfd, path, buf, size, bos); 496 } 497 #endif /* __ANDROID_API__ >= __ANDROID_API_M__ */ 498 499 #undef __enable_if_no_overflow_ssizet 500 #undef __error_if_overflows_objectsize 501 #undef __error_if_overflows_ssizet 502 #else /* defined(__clang__) */ 503 504 char* __getcwd_real(char*, size_t) __RENAME(getcwd); 505 ssize_t __read_real(int, void*, size_t) __RENAME(read); 506 ssize_t __write_real(int, const void*, size_t) __RENAME(write); 507 ssize_t __readlink_real(const char*, char*, size_t) __RENAME(readlink); 508 ssize_t __readlinkat_real(int dirfd, const char*, char*, size_t) __RENAME(readlinkat); 509 510 __errordecl(__getcwd_dest_size_error, "getcwd called with size bigger than destination"); 511 __errordecl(__pread_dest_size_error, "pread called with size bigger than destination"); 512 __errordecl(__pread_count_toobig_error, "pread called with count > SSIZE_MAX"); 513 __errordecl(__pread64_dest_size_error, "pread64 called with size bigger than destination"); 514 __errordecl(__pread64_count_toobig_error, "pread64 called with count > SSIZE_MAX"); 515 __errordecl(__pwrite_dest_size_error, "pwrite called with size bigger than destination"); 516 __errordecl(__pwrite_count_toobig_error, "pwrite called with count > SSIZE_MAX"); 517 __errordecl(__pwrite64_dest_size_error, "pwrite64 called with size bigger than destination"); 518 __errordecl(__pwrite64_count_toobig_error, "pwrite64 called with count > SSIZE_MAX"); 519 __errordecl(__read_dest_size_error, "read called with size bigger than destination"); 520 __errordecl(__read_count_toobig_error, "read called with count > SSIZE_MAX"); 521 __errordecl(__write_dest_size_error, "write called with size bigger than destination"); 522 __errordecl(__write_count_toobig_error, "write called with count > SSIZE_MAX"); 523 __errordecl(__readlink_dest_size_error, "readlink called with size bigger than destination"); 524 __errordecl(__readlink_size_toobig_error, "readlink called with size > SSIZE_MAX"); 525 __errordecl(__readlinkat_dest_size_error, "readlinkat called with size bigger than destination"); 526 __errordecl(__readlinkat_size_toobig_error, "readlinkat called with size > SSIZE_MAX"); 527 528 #if __ANDROID_API__ >= __ANDROID_API_N__ 529 __BIONIC_FORTIFY_INLINE 530 char* getcwd(char* buf, size_t size) __overloadable { 531 size_t bos = __bos(buf); 532 533 if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { 534 return __getcwd_real(buf, size); 535 } 536 537 if (__builtin_constant_p(size) && (size > bos)) { 538 __getcwd_dest_size_error(); 539 } 540 541 if (__builtin_constant_p(size) && (size <= bos)) { 542 return __getcwd_real(buf, size); 543 } 544 545 return __getcwd_chk(buf, size, bos); 546 } 547 #endif /* __ANDROID_API__ >= __ANDROID_API_N__ */ 548 549 #if __ANDROID_API__ >= __ANDROID_API_M__ 550 __BIONIC_FORTIFY_INLINE 551 ssize_t pread(int fd, void* buf, size_t count, off_t offset) { 552 size_t bos = __bos0(buf); 553 554 if (__builtin_constant_p(count) && (count > SSIZE_MAX)) { 555 __PREAD_PREFIX(count_toobig_error)(); 556 } 557 558 if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { 559 return __PREAD_PREFIX(real)(fd, buf, count, offset); 560 } 561 562 if (__builtin_constant_p(count) && (count > bos)) { 563 __PREAD_PREFIX(dest_size_error)(); 564 } 565 566 if (__builtin_constant_p(count) && (count <= bos)) { 567 return __PREAD_PREFIX(real)(fd, buf, count, offset); 568 } 569 570 return __PREAD_PREFIX(chk)(fd, buf, count, offset, bos); 571 } 572 573 __BIONIC_FORTIFY_INLINE 574 ssize_t pread64(int fd, void* buf, size_t count, off64_t offset) { 575 size_t bos = __bos0(buf); 576 577 if (__builtin_constant_p(count) && (count > SSIZE_MAX)) { 578 __pread64_count_toobig_error(); 579 } 580 581 if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { 582 return __pread64_real(fd, buf, count, offset); 583 } 584 585 if (__builtin_constant_p(count) && (count > bos)) { 586 __pread64_dest_size_error(); 587 } 588 589 if (__builtin_constant_p(count) && (count <= bos)) { 590 return __pread64_real(fd, buf, count, offset); 591 } 592 593 return __pread64_chk(fd, buf, count, offset, bos); 594 } 595 #endif /* __ANDROID_API__ >= __ANDROID_API_M__ */ 596 597 #if __ANDROID_API__ >= __ANDROID_API_N__ 598 __BIONIC_FORTIFY_INLINE 599 ssize_t pwrite(int fd, const void* buf, size_t count, off_t offset) { 600 size_t bos = __bos0(buf); 601 602 if (__builtin_constant_p(count) && (count > SSIZE_MAX)) { 603 __PWRITE_PREFIX(count_toobig_error)(); 604 } 605 606 if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { 607 return __PWRITE_PREFIX(real)(fd, buf, count, offset); 608 } 609 610 if (__builtin_constant_p(count) && (count > bos)) { 611 __PWRITE_PREFIX(dest_size_error)(); 612 } 613 614 if (__builtin_constant_p(count) && (count <= bos)) { 615 return __PWRITE_PREFIX(real)(fd, buf, count, offset); 616 } 617 618 return __PWRITE_PREFIX(chk)(fd, buf, count, offset, bos); 619 } 620 621 __BIONIC_FORTIFY_INLINE 622 ssize_t pwrite64(int fd, const void* buf, size_t count, off64_t offset) { 623 size_t bos = __bos0(buf); 624 625 if (__builtin_constant_p(count) && (count > SSIZE_MAX)) { 626 __pwrite64_count_toobig_error(); 627 } 628 629 if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { 630 return __pwrite64_real(fd, buf, count, offset); 631 } 632 633 if (__builtin_constant_p(count) && (count > bos)) { 634 __pwrite64_dest_size_error(); 635 } 636 637 if (__builtin_constant_p(count) && (count <= bos)) { 638 return __pwrite64_real(fd, buf, count, offset); 639 } 640 641 return __pwrite64_chk(fd, buf, count, offset, bos); 642 } 643 #endif /* __ANDROID_API__ >= __ANDROID_API_N__ */ 644 645 #if __ANDROID_API__ >= __ANDROID_API_L__ 646 __BIONIC_FORTIFY_INLINE 647 ssize_t read(int fd, void* buf, size_t count) { 648 size_t bos = __bos0(buf); 649 650 if (__builtin_constant_p(count) && (count > SSIZE_MAX)) { 651 __read_count_toobig_error(); 652 } 653 654 if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { 655 return __read_real(fd, buf, count); 656 } 657 658 if (__builtin_constant_p(count) && (count > bos)) { 659 __read_dest_size_error(); 660 } 661 662 if (__builtin_constant_p(count) && (count <= bos)) { 663 return __read_real(fd, buf, count); 664 } 665 666 return __read_chk(fd, buf, count, bos); 667 } 668 #endif /* __ANDROID_API__ >= __ANDROID_API_L__ */ 669 670 #if __ANDROID_API__ >= __ANDROID_API_N__ 671 __BIONIC_FORTIFY_INLINE 672 ssize_t write(int fd, const void* buf, size_t count) { 673 size_t bos = __bos0(buf); 674 675 if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { 676 return __write_real(fd, buf, count); 677 } 678 679 if (__builtin_constant_p(count) && (count > bos)) { 680 __write_dest_size_error(); 681 } 682 683 if (__builtin_constant_p(count) && (count <= bos)) { 684 return __write_real(fd, buf, count); 685 } 686 687 return __write_chk(fd, buf, count, bos); 688 } 689 #endif /* __ANDROID_API__ >= __ANDROID_API_N__ */ 690 691 #if __ANDROID_API__ >= __ANDROID_API_M__ 692 __BIONIC_FORTIFY_INLINE 693 ssize_t readlink(const char* path, char* buf, size_t size) { 694 size_t bos = __bos(buf); 695 696 if (__builtin_constant_p(size) && (size > SSIZE_MAX)) { 697 __readlink_size_toobig_error(); 698 } 699 700 if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { 701 return __readlink_real(path, buf, size); 702 } 703 704 if (__builtin_constant_p(size) && (size > bos)) { 705 __readlink_dest_size_error(); 706 } 707 708 if (__builtin_constant_p(size) && (size <= bos)) { 709 return __readlink_real(path, buf, size); 710 } 711 712 return __readlink_chk(path, buf, size, bos); 713 } 714 715 __BIONIC_FORTIFY_INLINE 716 ssize_t readlinkat(int dirfd, const char* path, char* buf, size_t size) { 717 size_t bos = __bos(buf); 718 719 if (__builtin_constant_p(size) && (size > SSIZE_MAX)) { 720 __readlinkat_size_toobig_error(); 721 } 722 723 if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { 724 return __readlinkat_real(dirfd, path, buf, size); 725 } 726 727 if (__builtin_constant_p(size) && (size > bos)) { 728 __readlinkat_dest_size_error(); 729 } 730 731 if (__builtin_constant_p(size) && (size <= bos)) { 732 return __readlinkat_real(dirfd, path, buf, size); 733 } 734 735 return __readlinkat_chk(dirfd, path, buf, size, bos); 736 } 737 #endif /* __ANDROID_API__ >= __ANDROID_API_M__ */ 738 #endif /* defined(__clang__) */ 739 #undef __PREAD_PREFIX 740 #undef __PWRITE_PREFIX 741 #endif /* defined(__BIONIC_FORTIFY) */ 742 743 __END_DECLS 744 745 #endif /* _UNISTD_H_ */ 746