blob: 8336976c53692016c00dbd36532685a138ee1d03 [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001/*
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 Hughesf4c948a2014-08-19 11:16:41 -070028
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080029#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 Project1dc9e472009-03-03 19:28:35 -080036
Josh Gaoee8d1692016-04-07 14:16:30 -070037#include <bits/fcntl.h>
Josh Gao7449e592016-04-07 16:37:49 -070038#include <bits/getopt.h>
Josh Gao98e574c2016-04-07 14:19:03 -070039#include <bits/ioctl.h>
Elliott Hughes5704c422016-01-25 18:06:24 -080040#include <bits/lockf.h>
41#include <bits/posix_limits.h>
Elliott Hughesfd936ae2016-08-12 10:16:34 -070042#include <bits/seek_constants.h>
Josh Gao8c8ef592016-04-07 16:33:30 -070043#include <bits/sysconf.h>
Elliott Hughes1ed337d2015-02-02 14:02:09 -080044
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080045__BEGIN_DECLS
46
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080047#define STDIN_FILENO 0
48#define STDOUT_FILENO 1
49#define STDERR_FILENO 2
50
Elliott Hughes1ed337d2015-02-02 14:02:09 -080051#define F_OK 0
52#define X_OK 1
53#define W_OK 2
54#define R_OK 4
55
Elliott Hughesa186b2e2014-09-22 14:49:07 -070056#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 Hughes58d9e282014-04-22 17:41:00 -070077extern char** environ;
78
Elliott Hughes3b2096a2016-07-22 18:57:12 -070079__noreturn void _exit(int __status);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080080
Elliott Hughes3b2096a2016-07-22 18:57:12 -070081pid_t fork(void);
82pid_t vfork(void);
83pid_t getpid(void);
Elliott Hughes95fa0612016-09-28 12:29:52 -070084pid_t gettid(void) __attribute_const__;
Elliott Hughes3b2096a2016-07-22 18:57:12 -070085pid_t getpgid(pid_t __pid);
86int setpgid(pid_t __pid, pid_t __pgid);
87pid_t getppid(void);
88pid_t getpgrp(void);
89int setpgrp(void);
90pid_t getsid(pid_t __pid) __INTRODUCED_IN(17);
91pid_t setsid(void);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080092
Elliott Hughes3b2096a2016-07-22 18:57:12 -070093int execv(const char* __path, char* const* __argv);
94int execvp(const char* __file, char* const* __argv);
95int execvpe(const char* __file, char* const* __argv, char* const* __envp) __INTRODUCED_IN(21);
96int execve(const char* __file, char* const* __argv, char* const* __envp);
Josh Gaod80a52e2016-08-10 15:18:29 -070097int execl(const char* __path, const char* __arg0, ...) __attribute__((__sentinel__));
98int execlp(const char* __file, const char* __arg0, ...) __attribute__((__sentinel__));
99int execle(const char* __path, const char* __arg0, ... /*, char* const* __envp */)
100 __attribute__((__sentinel__(1)));
David 'Digit' Turnerb083bb52011-05-26 02:46:41 +0200101
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700102int nice(int __incr);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800103
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700104int setuid(uid_t __uid);
105uid_t getuid(void);
106int seteuid(uid_t __uid);
107uid_t geteuid(void);
108int setgid(gid_t __gid);
109gid_t getgid(void);
110int setegid(gid_t __gid);
111gid_t getegid(void);
112int getgroups(int __size, gid_t* __list);
113int setgroups(size_t __size, const gid_t* __list);
114int setreuid(uid_t __ruid, uid_t __euid);
115int setregid(gid_t __rgid, gid_t __egid);
116int setresuid(uid_t __ruid, uid_t __euid, uid_t __suid);
117int setresgid(gid_t __rgid, gid_t __egid, gid_t __sgid);
118int getresuid(uid_t* __ruid, uid_t* __euid, uid_t* __suid);
119int getresgid(gid_t* __rgid, gid_t* __egid, gid_t* __sgid);
120char* getlogin(void);
Elliott Hughes06bd5862017-07-28 16:27:49 -0700121int getlogin_r(char* __buffer, size_t __buffer_size) __INTRODUCED_IN_FUTURE;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800122
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700123long fpathconf(int __fd, int __name);
124long pathconf(const char* __path, int __name);
Elliott Hughesa186b2e2014-09-22 14:49:07 -0700125
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700126int access(const char* __path, int __mode);
127int faccessat(int __dirfd, const char* __path, int __mode, int __flags) __INTRODUCED_IN(16);
128int link(const char* __oldpath, const char* __newpath);
129int linkat(int __olddirfd, const char* __oldpath, int __newdirfd,
130 const char* __newpath, int __flags) __INTRODUCED_IN(21);
131int unlink(const char* __path);
132int unlinkat(int __dirfd, const char* __path, int __flags);
133int chdir(const char* __path);
134int fchdir(int __fd);
135int rmdir(const char* __path);
136int pipe(int* __pipefd);
Elliott Hughes5f5cc452014-08-18 16:04:03 -0700137#if defined(__USE_GNU)
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700138int pipe2(int* __pipefd, int __flags) __INTRODUCED_IN(9);
David 'Digit' Turner275cd482010-09-27 17:33:08 +0200139#endif
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700140int chroot(const char* __path);
141int symlink(const char* __oldpath, const char* __newpath);
142int symlinkat(const char* __oldpath, int __newdirfd, const char* __newpath) __INTRODUCED_IN(21);
George Burgess IV7cc779f2017-02-09 00:00:31 -0800143ssize_t readlink(const char* __path, char* __buf, size_t __bufsiz)
144 __overloadable __RENAME_CLANG(readlink);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700145ssize_t readlinkat(int __dirfd, const char* __path, char* __buf,
George Burgess IV7cc779f2017-02-09 00:00:31 -0800146 size_t __bufsiz)
147 __INTRODUCED_IN(21) __overloadable __RENAME_CLANG(readlinkat);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700148int chown(const char* __path, uid_t __owner, gid_t __group);
149int fchown(int __fd, uid_t __owner, gid_t __group);
150int fchownat(int __dirfd, const char* __path, uid_t __owner, gid_t __group, int __flags);
151int lchown(const char* __path, uid_t __owner, gid_t __group);
George Burgess IV7cc779f2017-02-09 00:00:31 -0800152char* getcwd(char* __buf, size_t __size) __overloadable __RENAME_CLANG(getcwd);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800153
Elliott Hughes79a8f4b2016-11-29 15:16:08 -0800154void sync(void);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800155
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700156int close(int __fd);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800157
George Burgess IV7cc779f2017-02-09 00:00:31 -0800158ssize_t read(int __fd, void* __buf, size_t __count) __overloadable
159 __RENAME_CLANG(read);
160ssize_t write(int __fd, const void* __buf, size_t __count) __overloadable
161 __RENAME_CLANG(write);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800162
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700163int dup(int __oldfd);
164int dup2(int __oldfd, int __newfd);
165int dup3(int __oldfd, int __newfd, int __flags) __INTRODUCED_IN(21);
166int fsync(int __fd);
167int fdatasync(int __fd) __INTRODUCED_IN(9);
Elliott Hughes68dc20d2015-02-06 22:28:49 -0800168
169#if defined(__USE_FILE_OFFSET64)
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700170off_t lseek(int __fd, off_t __offset, int __whence) __RENAME(lseek64);
Elliott Hughes68dc20d2015-02-06 22:28:49 -0800171#else
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700172off_t lseek(int __fd, off_t __offset, int __whence);
Elliott Hughes68dc20d2015-02-06 22:28:49 -0800173#endif
Dan Albertaf4713e2015-09-04 12:59:53 -0700174
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700175off64_t lseek64(int __fd, off64_t __offset, int __whence);
Dan Albertaf4713e2015-09-04 12:59:53 -0700176
Elliott Hughes00fedf52017-07-05 15:23:50 -0700177#if defined(__USE_FILE_OFFSET64)
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700178int truncate(const char* __path, off_t __length) __RENAME(truncate64) __INTRODUCED_IN(21);
George Burgess IV7cc779f2017-02-09 00:00:31 -0800179ssize_t pread(int __fd, void* __buf, size_t __count, off_t __offset)
180 __overloadable __RENAME(pread64) __INTRODUCED_IN(12);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700181ssize_t pwrite(int __fd, const void* __buf, size_t __count, off_t __offset)
George Burgess IV7cc779f2017-02-09 00:00:31 -0800182 __overloadable __RENAME(pwrite64) __INTRODUCED_IN(12);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700183int ftruncate(int __fd, off_t __length) __RENAME(ftruncate64) __INTRODUCED_IN(12);
Dan Albertaf4713e2015-09-04 12:59:53 -0700184#else
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700185int truncate(const char* __path, off_t __length);
George Burgess IV7cc779f2017-02-09 00:00:31 -0800186ssize_t pread(int __fd, void* __buf, size_t __count, off_t __offset)
187 __overloadable __RENAME_CLANG(pread);
188ssize_t pwrite(int __fd, const void* __buf, size_t __count, off_t __offset)
189 __overloadable __RENAME_CLANG(pwrite);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700190int ftruncate(int __fd, off_t __length);
Dan Albertaf4713e2015-09-04 12:59:53 -0700191#endif
192
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700193int truncate64(const char* __path, off64_t __length) __INTRODUCED_IN(21);
George Burgess IV7cc779f2017-02-09 00:00:31 -0800194ssize_t pread64(int __fd, void* __buf, size_t __count, off64_t __offset)
195 __INTRODUCED_IN(12) __overloadable __RENAME_CLANG(pread64);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700196ssize_t pwrite64(int __fd, const void* __buf, size_t __count, off64_t __offset)
George Burgess IV7cc779f2017-02-09 00:00:31 -0800197 __INTRODUCED_IN(12) __overloadable __RENAME_CLANG(pwrite64);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700198int ftruncate64(int __fd, off64_t __length) __INTRODUCED_IN(12);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800199
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700200int pause(void);
201unsigned int alarm(unsigned int __seconds);
202unsigned int sleep(unsigned int __seconds);
203int usleep(useconds_t __usec);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800204
Dan Albertaf4713e2015-09-04 12:59:53 -0700205int gethostname(char* __name, size_t __len);
Josh Gao14adff12016-04-29 12:00:55 -0700206int sethostname(const char* __name, size_t __len) __INTRODUCED_IN(23);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800207
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700208int brk(void* __addr);
209void* sbrk(ptrdiff_t __increment);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800210
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700211int isatty(int __fd);
212char* ttyname(int __fd);
213int ttyname_r(int __fd, char* __buf, size_t __buflen) __INTRODUCED_IN(8);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800214
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700215int acct(const char* __filepath);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800216
Elliott Hughes5bc78c82016-11-16 11:35:43 -0800217#if __ANDROID_API__ >= __ANDROID_API_L__
Josh Gaob6a4a4c2016-07-26 16:34:40 -0700218int getpagesize(void) __INTRODUCED_IN(21);
Dan Albertaf4713e2015-09-04 12:59:53 -0700219#else
Dan Alberta39f5d82016-09-14 17:10:26 -0700220static __inline__ int getpagesize(void) {
Dan Albertaf4713e2015-09-04 12:59:53 -0700221 return sysconf(_SC_PAGESIZE);
222}
223#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800224
Dan Albertaf4713e2015-09-04 12:59:53 -0700225long syscall(long __number, ...);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800226
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700227int daemon(int __nochdir, int __noclose);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800228
Elliott Hughesa6ecba42014-02-10 18:37:02 -0800229#if defined(__arm__) || (defined(__mips__) && !defined(__LP64__))
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700230int cacheflush(long __addr, long __nbytes, long __cache);
Elliott Hughesa6ecba42014-02-10 18:37:02 -0800231 /* __attribute__((deprecated("use __builtin___clear_cache instead"))); */
232#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800233
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700234pid_t tcgetpgrp(int __fd);
235int tcsetpgrp(int __fd, pid_t __pid);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800236
Elliott Hughescf399f72009-10-05 13:19:05 -0700237/* Used to retry syscalls that can return EINTR. */
238#define TEMP_FAILURE_RETRY(exp) ({ \
Dan Alberta7821b72014-05-21 20:33:28 -0700239 __typeof__(exp) _rc; \
Elliott Hughescf399f72009-10-05 13:19:05 -0700240 do { \
241 _rc = (exp); \
242 } while (_rc == -1 && errno == EINTR); \
243 _rc; })
244
Dan Albertaf4713e2015-09-04 12:59:53 -0700245/* TODO(unified-headers): Factor out all the FORTIFY features. */
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700246char* __getcwd_chk(char*, size_t, size_t) __INTRODUCED_IN(24);
Daniel Micay9101b002015-05-20 15:31:26 -0400247
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700248ssize_t __pread_chk(int, void*, size_t, off_t, size_t) __INTRODUCED_IN(23);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700249ssize_t __pread_real(int, void*, size_t, off_t) __RENAME(pread);
Daniel Micaye7e1c872015-04-16 09:07:45 -0400250
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700251ssize_t __pread64_chk(int, void*, size_t, off64_t, size_t) __INTRODUCED_IN(23);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700252ssize_t __pread64_real(int, void*, size_t, off64_t) __RENAME(pread64) __INTRODUCED_IN(12);
Daniel Micaye7e1c872015-04-16 09:07:45 -0400253
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700254ssize_t __pwrite_chk(int, const void*, size_t, off_t, size_t) __INTRODUCED_IN(24);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700255ssize_t __pwrite_real(int, const void*, size_t, off_t) __RENAME(pwrite);
Daniel Micayafdd1542015-07-20 21:37:29 -0400256
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700257ssize_t __pwrite64_chk(int, const void*, size_t, off64_t, size_t) __INTRODUCED_IN(24);
George Burgess IV7cc779f2017-02-09 00:00:31 -0800258ssize_t __pwrite64_real(int, const void*, size_t, off64_t) __RENAME(pwrite64)
259 __INTRODUCED_IN(12);
Daniel Micayafdd1542015-07-20 21:37:29 -0400260
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700261ssize_t __read_chk(int, void*, size_t, size_t) __INTRODUCED_IN(21);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700262ssize_t __write_chk(int, const void*, size_t, size_t) __INTRODUCED_IN(24);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700263ssize_t __readlink_chk(const char*, char*, size_t, size_t) __INTRODUCED_IN(23);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700264ssize_t __readlinkat_chk(int dirfd, const char*, char*, size_t, size_t) __INTRODUCED_IN(23);
Daniel Micay42281882015-04-17 11:26:36 -0400265
Josh Gao2e8e5e62017-04-20 12:58:31 -0700266int getdomainname(char*, size_t) __INTRODUCED_IN(26);
267int setdomainname(const char*, size_t) __INTRODUCED_IN(26);
Greg Hackmanne2faf072016-03-03 08:37:53 -0800268
Dan Albert658727e2014-10-07 11:10:36 -0700269#if defined(__BIONIC_FORTIFY)
270
George Burgess IV7cc779f2017-02-09 00:00:31 -0800271#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 Micay9101b002015-05-20 15:31:26 -0400278
279#if defined(__clang__)
George Burgess IV7cc779f2017-02-09 00:00:31 -0800280#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
294char* 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
299char* getcwd(char* const __pass_object_size buf, size_t size) __overloadable {
300 size_t bos = __bos(buf);
301
Daniel Micay9101b002015-05-20 15:31:26 -0400302 /*
George Burgess IV7cc779f2017-02-09 00:00:31 -0800303 * 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 Micay9101b002015-05-20 15:31:26 -0400306 */
George Burgess IV7cc779f2017-02-09 00:00:31 -0800307 if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE || buf == NULL) {
308 return __call_bypassing_fortify(getcwd)(buf, size);
Daniel Micay9101b002015-05-20 15:31:26 -0400309 }
George Burgess IV7cc779f2017-02-09 00:00:31 -0800310
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
317ssize_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
321ssize_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 IV156d5a82017-02-10 13:56:22 -0800326ssize_t pread(int fd, void* const __pass_object_size0 buf, size_t count,
George Burgess IV7cc779f2017-02-09 00:00:31 -0800327 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
338ssize_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
342ssize_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 IV156d5a82017-02-10 13:56:22 -0800347ssize_t pread64(int fd, void* const __pass_object_size0 buf, size_t count,
George Burgess IV7cc779f2017-02-09 00:00:31 -0800348 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
361ssize_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
366ssize_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 IV156d5a82017-02-10 13:56:22 -0800372ssize_t pwrite(int fd, const void* const __pass_object_size0 buf, size_t count,
George Burgess IV7cc779f2017-02-09 00:00:31 -0800373 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
384ssize_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
389ssize_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 IV156d5a82017-02-10 13:56:22 -0800395ssize_t pwrite64(int fd, const void* const __pass_object_size0 buf,
396 size_t count, off64_t offset) __overloadable {
George Burgess IV7cc779f2017-02-09 00:00:31 -0800397 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 Albert9c2094f2017-02-14 19:28:18 -0800407#if __ANDROID_API__ >= __ANDROID_API_L__
George Burgess IV7cc779f2017-02-09 00:00:31 -0800408__BIONIC_ERROR_FUNCTION_VISIBILITY
409ssize_t read(int fd, void* buf, size_t count) __overloadable
410 __error_if_overflows_ssizet(count);
411
412__BIONIC_ERROR_FUNCTION_VISIBILITY
413ssize_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 IV156d5a82017-02-10 13:56:22 -0800418ssize_t read(int fd, void* const __pass_object_size0 buf, size_t count)
George Burgess IV7cc779f2017-02-09 00:00:31 -0800419 __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 Albert9c2094f2017-02-14 19:28:18 -0800428#endif /* __ANDROID_API__ >= __ANDROID_API_L__ */
George Burgess IV7cc779f2017-02-09 00:00:31 -0800429
Dan Albert9c2094f2017-02-14 19:28:18 -0800430#if __ANDROID_API__ >= __ANDROID_API_N__
George Burgess IV7cc779f2017-02-09 00:00:31 -0800431__BIONIC_ERROR_FUNCTION_VISIBILITY
432ssize_t write(int fd, const void* buf, size_t count) __overloadable
433 __error_if_overflows_ssizet(count);
434
435__BIONIC_ERROR_FUNCTION_VISIBILITY
436ssize_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 IV156d5a82017-02-10 13:56:22 -0800441ssize_t write(int fd, const void* const __pass_object_size0 buf, size_t count)
George Burgess IV7cc779f2017-02-09 00:00:31 -0800442 __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 Albert9c2094f2017-02-14 19:28:18 -0800451#endif /* __ANDROID_API__ >= __ANDROID_API_N__ */
George Burgess IV7cc779f2017-02-09 00:00:31 -0800452
Dan Albert9c2094f2017-02-14 19:28:18 -0800453#if __ANDROID_API__ >= __ANDROID_API_M__
George Burgess IV7cc779f2017-02-09 00:00:31 -0800454__BIONIC_ERROR_FUNCTION_VISIBILITY
455ssize_t readlink(const char* path, char* buf, size_t size) __overloadable
456 __error_if_overflows_ssizet(size);
457
458__BIONIC_ERROR_FUNCTION_VISIBILITY
459ssize_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
464ssize_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 IV7cc779f2017-02-09 00:00:31 -0800475__BIONIC_ERROR_FUNCTION_VISIBILITY
476ssize_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
481ssize_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
487ssize_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 Albert9c2094f2017-02-14 19:28:18 -0800498#endif /* __ANDROID_API__ >= __ANDROID_API_M__ */
George Burgess IV7cc779f2017-02-09 00:00:31 -0800499
500#undef __enable_if_no_overflow_ssizet
501#undef __error_if_overflows_objectsize
502#undef __error_if_overflows_ssizet
503#else /* defined(__clang__) */
504
505char* __getcwd_real(char*, size_t) __RENAME(getcwd);
506ssize_t __read_real(int, void*, size_t) __RENAME(read);
507ssize_t __write_real(int, const void*, size_t) __RENAME(write);
508ssize_t __readlink_real(const char*, char*, size_t) __RENAME(readlink);
509ssize_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
531char* getcwd(char* buf, size_t size) __overloadable {
532 size_t bos = __bos(buf);
533
Daniel Micay9101b002015-05-20 15:31:26 -0400534 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 Micay9101b002015-05-20 15:31:26 -0400545
546 return __getcwd_chk(buf, size, bos);
547}
Elliott Hughes5bc78c82016-11-16 11:35:43 -0800548#endif /* __ANDROID_API__ >= __ANDROID_API_N__ */
Daniel Micay9101b002015-05-20 15:31:26 -0400549
Elliott Hughes5bc78c82016-11-16 11:35:43 -0800550#if __ANDROID_API__ >= __ANDROID_API_M__
Daniel Micaye7e1c872015-04-16 09:07:45 -0400551__BIONIC_FORTIFY_INLINE
552ssize_t pread(int fd, void* buf, size_t count, off_t offset) {
553 size_t bos = __bos0(buf);
554
Daniel Micaye7e1c872015-04-16 09:07:45 -0400555 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 Micaye7e1c872015-04-16 09:07:45 -0400570
571 return __PREAD_PREFIX(chk)(fd, buf, count, offset, bos);
572}
573
574__BIONIC_FORTIFY_INLINE
575ssize_t pread64(int fd, void* buf, size_t count, off64_t offset) {
576 size_t bos = __bos0(buf);
577
Daniel Micaye7e1c872015-04-16 09:07:45 -0400578 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 Micaye7e1c872015-04-16 09:07:45 -0400593
594 return __pread64_chk(fd, buf, count, offset, bos);
595}
Elliott Hughes5bc78c82016-11-16 11:35:43 -0800596#endif /* __ANDROID_API__ >= __ANDROID_API_M__ */
Daniel Micaye7e1c872015-04-16 09:07:45 -0400597
Elliott Hughes5bc78c82016-11-16 11:35:43 -0800598#if __ANDROID_API__ >= __ANDROID_API_N__
Daniel Micayafdd1542015-07-20 21:37:29 -0400599__BIONIC_FORTIFY_INLINE
600ssize_t pwrite(int fd, const void* buf, size_t count, off_t offset) {
601 size_t bos = __bos0(buf);
602
Daniel Micayafdd1542015-07-20 21:37:29 -0400603 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 Micayafdd1542015-07-20 21:37:29 -0400618
619 return __PWRITE_PREFIX(chk)(fd, buf, count, offset, bos);
620}
621
622__BIONIC_FORTIFY_INLINE
623ssize_t pwrite64(int fd, const void* buf, size_t count, off64_t offset) {
624 size_t bos = __bos0(buf);
625
Daniel Micayafdd1542015-07-20 21:37:29 -0400626 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 Micayafdd1542015-07-20 21:37:29 -0400641
642 return __pwrite64_chk(fd, buf, count, offset, bos);
643}
Elliott Hughes5bc78c82016-11-16 11:35:43 -0800644#endif /* __ANDROID_API__ >= __ANDROID_API_N__ */
Daniel Micayafdd1542015-07-20 21:37:29 -0400645
Elliott Hughes5bc78c82016-11-16 11:35:43 -0800646#if __ANDROID_API__ >= __ANDROID_API_L__
Nick Kralevichb036b5c2013-10-09 20:16:34 -0700647__BIONIC_FORTIFY_INLINE
648ssize_t read(int fd, void* buf, size_t count) {
649 size_t bos = __bos0(buf);
650
Nick Kralevichb036b5c2013-10-09 20:16:34 -0700651 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 Kralevichb036b5c2013-10-09 20:16:34 -0700666
667 return __read_chk(fd, buf, count, bos);
668}
Elliott Hughes5bc78c82016-11-16 11:35:43 -0800669#endif /* __ANDROID_API__ >= __ANDROID_API_L__ */
Daniel Micaye7e1c872015-04-16 09:07:45 -0400670
Elliott Hughes5bc78c82016-11-16 11:35:43 -0800671#if __ANDROID_API__ >= __ANDROID_API_N__
Daniel Micay42281882015-04-17 11:26:36 -0400672__BIONIC_FORTIFY_INLINE
Daniel Micayafdd1542015-07-20 21:37:29 -0400673ssize_t write(int fd, const void* buf, size_t count) {
674 size_t bos = __bos0(buf);
675
Daniel Micayafdd1542015-07-20 21:37:29 -0400676 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 Micayafdd1542015-07-20 21:37:29 -0400687
688 return __write_chk(fd, buf, count, bos);
689}
Elliott Hughes5bc78c82016-11-16 11:35:43 -0800690#endif /* __ANDROID_API__ >= __ANDROID_API_N__ */
Daniel Micayafdd1542015-07-20 21:37:29 -0400691
Elliott Hughes5bc78c82016-11-16 11:35:43 -0800692#if __ANDROID_API__ >= __ANDROID_API_M__
Daniel Micayafdd1542015-07-20 21:37:29 -0400693__BIONIC_FORTIFY_INLINE
Daniel Micay42281882015-04-17 11:26:36 -0400694ssize_t readlink(const char* path, char* buf, size_t size) {
695 size_t bos = __bos(buf);
696
Daniel Micay42281882015-04-17 11:26:36 -0400697 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 Micay42281882015-04-17 11:26:36 -0400712
713 return __readlink_chk(path, buf, size, bos);
714}
715
716__BIONIC_FORTIFY_INLINE
717ssize_t readlinkat(int dirfd, const char* path, char* buf, size_t size) {
718 size_t bos = __bos(buf);
719
Daniel Micay42281882015-04-17 11:26:36 -0400720 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 Micay42281882015-04-17 11:26:36 -0400735
736 return __readlinkat_chk(dirfd, path, buf, size, bos);
737}
Elliott Hughes5bc78c82016-11-16 11:35:43 -0800738#endif /* __ANDROID_API__ >= __ANDROID_API_M__ */
George Burgess IV7cc779f2017-02-09 00:00:31 -0800739#endif /* defined(__clang__) */
740#undef __PREAD_PREFIX
741#undef __PWRITE_PREFIX
Nick Kralevichb036b5c2013-10-09 20:16:34 -0700742#endif /* defined(__BIONIC_FORTIFY) */
743
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800744__END_DECLS
745
746#endif /* _UNISTD_H_ */