blob: b3f8c1149aac7ddcf12e1ad952dd70735a3bed22 [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);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800121
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700122long fpathconf(int __fd, int __name);
123long pathconf(const char* __path, int __name);
Elliott Hughesa186b2e2014-09-22 14:49:07 -0700124
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700125int access(const char* __path, int __mode);
126int faccessat(int __dirfd, const char* __path, int __mode, int __flags) __INTRODUCED_IN(16);
127int link(const char* __oldpath, const char* __newpath);
128int linkat(int __olddirfd, const char* __oldpath, int __newdirfd,
129 const char* __newpath, int __flags) __INTRODUCED_IN(21);
130int unlink(const char* __path);
131int unlinkat(int __dirfd, const char* __path, int __flags);
132int chdir(const char* __path);
133int fchdir(int __fd);
134int rmdir(const char* __path);
135int pipe(int* __pipefd);
Elliott Hughes5f5cc452014-08-18 16:04:03 -0700136#if defined(__USE_GNU)
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700137int pipe2(int* __pipefd, int __flags) __INTRODUCED_IN(9);
David 'Digit' Turner275cd482010-09-27 17:33:08 +0200138#endif
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700139int chroot(const char* __path);
140int symlink(const char* __oldpath, const char* __newpath);
141int symlinkat(const char* __oldpath, int __newdirfd, const char* __newpath) __INTRODUCED_IN(21);
George Burgess IV7cc779f2017-02-09 00:00:31 -0800142ssize_t readlink(const char* __path, char* __buf, size_t __bufsiz)
143 __overloadable __RENAME_CLANG(readlink);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700144ssize_t readlinkat(int __dirfd, const char* __path, char* __buf,
George Burgess IV7cc779f2017-02-09 00:00:31 -0800145 size_t __bufsiz)
146 __INTRODUCED_IN(21) __overloadable __RENAME_CLANG(readlinkat);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700147int chown(const char* __path, uid_t __owner, gid_t __group);
148int fchown(int __fd, uid_t __owner, gid_t __group);
149int fchownat(int __dirfd, const char* __path, uid_t __owner, gid_t __group, int __flags);
150int lchown(const char* __path, uid_t __owner, gid_t __group);
George Burgess IV7cc779f2017-02-09 00:00:31 -0800151char* getcwd(char* __buf, size_t __size) __overloadable __RENAME_CLANG(getcwd);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800152
Elliott Hughes79a8f4b2016-11-29 15:16:08 -0800153void sync(void);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800154
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700155int close(int __fd);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800156
George Burgess IV7cc779f2017-02-09 00:00:31 -0800157ssize_t read(int __fd, void* __buf, size_t __count) __overloadable
158 __RENAME_CLANG(read);
159ssize_t write(int __fd, const void* __buf, size_t __count) __overloadable
160 __RENAME_CLANG(write);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800161
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700162int dup(int __oldfd);
163int dup2(int __oldfd, int __newfd);
164int dup3(int __oldfd, int __newfd, int __flags) __INTRODUCED_IN(21);
165int fsync(int __fd);
166int fdatasync(int __fd) __INTRODUCED_IN(9);
Elliott Hughes68dc20d2015-02-06 22:28:49 -0800167
168#if defined(__USE_FILE_OFFSET64)
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700169off_t lseek(int __fd, off_t __offset, int __whence) __RENAME(lseek64);
Elliott Hughes68dc20d2015-02-06 22:28:49 -0800170#else
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700171off_t lseek(int __fd, off_t __offset, int __whence);
Elliott Hughes68dc20d2015-02-06 22:28:49 -0800172#endif
Dan Albertaf4713e2015-09-04 12:59:53 -0700173
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700174off64_t lseek64(int __fd, off64_t __offset, int __whence);
Dan Albertaf4713e2015-09-04 12:59:53 -0700175
Elliott Hughes5bc78c82016-11-16 11:35:43 -0800176#if defined(__USE_FILE_OFFSET64) && __ANDROID_API__ >= __ANDROID_API_L__
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700177int truncate(const char* __path, off_t __length) __RENAME(truncate64) __INTRODUCED_IN(21);
George Burgess IV7cc779f2017-02-09 00:00:31 -0800178ssize_t pread(int __fd, void* __buf, size_t __count, off_t __offset)
179 __overloadable __RENAME(pread64) __INTRODUCED_IN(12);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700180ssize_t pwrite(int __fd, const void* __buf, size_t __count, off_t __offset)
George Burgess IV7cc779f2017-02-09 00:00:31 -0800181 __overloadable __RENAME(pwrite64) __INTRODUCED_IN(12);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700182int ftruncate(int __fd, off_t __length) __RENAME(ftruncate64) __INTRODUCED_IN(12);
Dan Albertaf4713e2015-09-04 12:59:53 -0700183#else
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700184int truncate(const char* __path, off_t __length);
George Burgess IV7cc779f2017-02-09 00:00:31 -0800185ssize_t pread(int __fd, void* __buf, size_t __count, off_t __offset)
186 __overloadable __RENAME_CLANG(pread);
187ssize_t pwrite(int __fd, const void* __buf, size_t __count, off_t __offset)
188 __overloadable __RENAME_CLANG(pwrite);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700189int ftruncate(int __fd, off_t __length);
Dan Albertaf4713e2015-09-04 12:59:53 -0700190#endif
191
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700192int truncate64(const char* __path, off64_t __length) __INTRODUCED_IN(21);
George Burgess IV7cc779f2017-02-09 00:00:31 -0800193ssize_t pread64(int __fd, void* __buf, size_t __count, off64_t __offset)
194 __INTRODUCED_IN(12) __overloadable __RENAME_CLANG(pread64);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700195ssize_t pwrite64(int __fd, const void* __buf, size_t __count, off64_t __offset)
George Burgess IV7cc779f2017-02-09 00:00:31 -0800196 __INTRODUCED_IN(12) __overloadable __RENAME_CLANG(pwrite64);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700197int ftruncate64(int __fd, off64_t __length) __INTRODUCED_IN(12);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800198
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700199int pause(void);
200unsigned int alarm(unsigned int __seconds);
201unsigned int sleep(unsigned int __seconds);
202int usleep(useconds_t __usec);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800203
Dan Albertaf4713e2015-09-04 12:59:53 -0700204int gethostname(char* __name, size_t __len);
Josh Gao14adff12016-04-29 12:00:55 -0700205int sethostname(const char* __name, size_t __len) __INTRODUCED_IN(23);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800206
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700207int brk(void* __addr);
208void* sbrk(ptrdiff_t __increment);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800209
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700210int isatty(int __fd);
211char* ttyname(int __fd);
212int ttyname_r(int __fd, char* __buf, size_t __buflen) __INTRODUCED_IN(8);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800213
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700214int acct(const char* __filepath);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800215
Elliott Hughes5bc78c82016-11-16 11:35:43 -0800216#if __ANDROID_API__ >= __ANDROID_API_L__
Josh Gaob6a4a4c2016-07-26 16:34:40 -0700217int getpagesize(void) __INTRODUCED_IN(21);
Dan Albertaf4713e2015-09-04 12:59:53 -0700218#else
Dan Alberta39f5d82016-09-14 17:10:26 -0700219static __inline__ int getpagesize(void) {
Dan Albertaf4713e2015-09-04 12:59:53 -0700220 return sysconf(_SC_PAGESIZE);
221}
222#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800223
Dan Albertaf4713e2015-09-04 12:59:53 -0700224long syscall(long __number, ...);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800225
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700226int daemon(int __nochdir, int __noclose);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800227
Elliott Hughesa6ecba42014-02-10 18:37:02 -0800228#if defined(__arm__) || (defined(__mips__) && !defined(__LP64__))
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700229int cacheflush(long __addr, long __nbytes, long __cache);
Elliott Hughesa6ecba42014-02-10 18:37:02 -0800230 /* __attribute__((deprecated("use __builtin___clear_cache instead"))); */
231#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800232
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700233pid_t tcgetpgrp(int __fd);
234int tcsetpgrp(int __fd, pid_t __pid);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800235
Elliott Hughescf399f72009-10-05 13:19:05 -0700236/* Used to retry syscalls that can return EINTR. */
237#define TEMP_FAILURE_RETRY(exp) ({ \
Dan Alberta7821b72014-05-21 20:33:28 -0700238 __typeof__(exp) _rc; \
Elliott Hughescf399f72009-10-05 13:19:05 -0700239 do { \
240 _rc = (exp); \
241 } while (_rc == -1 && errno == EINTR); \
242 _rc; })
243
Dan Albertaf4713e2015-09-04 12:59:53 -0700244/* TODO(unified-headers): Factor out all the FORTIFY features. */
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700245char* __getcwd_chk(char*, size_t, size_t) __INTRODUCED_IN(24);
Daniel Micay9101b002015-05-20 15:31:26 -0400246
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700247ssize_t __pread_chk(int, void*, size_t, off_t, size_t) __INTRODUCED_IN(23);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700248ssize_t __pread_real(int, void*, size_t, off_t) __RENAME(pread);
Daniel Micaye7e1c872015-04-16 09:07:45 -0400249
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700250ssize_t __pread64_chk(int, void*, size_t, off64_t, size_t) __INTRODUCED_IN(23);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700251ssize_t __pread64_real(int, void*, size_t, off64_t) __RENAME(pread64) __INTRODUCED_IN(12);
Daniel Micaye7e1c872015-04-16 09:07:45 -0400252
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700253ssize_t __pwrite_chk(int, const void*, size_t, off_t, size_t) __INTRODUCED_IN(24);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700254ssize_t __pwrite_real(int, const void*, size_t, off_t) __RENAME(pwrite);
Daniel Micayafdd1542015-07-20 21:37:29 -0400255
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700256ssize_t __pwrite64_chk(int, const void*, size_t, off64_t, size_t) __INTRODUCED_IN(24);
George Burgess IV7cc779f2017-02-09 00:00:31 -0800257ssize_t __pwrite64_real(int, const void*, size_t, off64_t) __RENAME(pwrite64)
258 __INTRODUCED_IN(12);
Daniel Micayafdd1542015-07-20 21:37:29 -0400259
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700260ssize_t __read_chk(int, void*, size_t, size_t) __INTRODUCED_IN(21);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700261ssize_t __write_chk(int, const void*, size_t, size_t) __INTRODUCED_IN(24);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700262ssize_t __readlink_chk(const char*, char*, size_t, size_t) __INTRODUCED_IN(23);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700263ssize_t __readlinkat_chk(int dirfd, const char*, char*, size_t, size_t) __INTRODUCED_IN(23);
Daniel Micay42281882015-04-17 11:26:36 -0400264
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700265int getdomainname(char*, size_t) __INTRODUCED_IN_FUTURE;
266int setdomainname(const char*, size_t) __INTRODUCED_IN_FUTURE;
Greg Hackmanne2faf072016-03-03 08:37:53 -0800267
Dan Albert658727e2014-10-07 11:10:36 -0700268#if defined(__BIONIC_FORTIFY)
269
George Burgess IV7cc779f2017-02-09 00:00:31 -0800270#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
Daniel Micay9101b002015-05-20 15:31:26 -0400277
278#if defined(__clang__)
George Burgess IV7cc779f2017-02-09 00:00:31 -0800279#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
293char* 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
298char* getcwd(char* const __pass_object_size buf, size_t size) __overloadable {
299 size_t bos = __bos(buf);
300
Daniel Micay9101b002015-05-20 15:31:26 -0400301 /*
George Burgess IV7cc779f2017-02-09 00:00:31 -0800302 * 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.
Daniel Micay9101b002015-05-20 15:31:26 -0400305 */
George Burgess IV7cc779f2017-02-09 00:00:31 -0800306 if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE || buf == NULL) {
307 return __call_bypassing_fortify(getcwd)(buf, size);
Daniel Micay9101b002015-05-20 15:31:26 -0400308 }
George Burgess IV7cc779f2017-02-09 00:00:31 -0800309
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
316ssize_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
320ssize_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
325ssize_t pread(int fd, void* const __pass_object_size 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
337ssize_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
341ssize_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
346ssize_t pread64(int fd, void* const __pass_object_size 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
360ssize_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
365ssize_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
371ssize_t pwrite(int fd, const void* const __pass_object_size 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
383ssize_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
388ssize_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
394ssize_t pwrite64(int fd, const void* const __pass_object_size buf, size_t count,
395 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__BIONIC_ERROR_FUNCTION_VISIBILITY
407ssize_t read(int fd, void* buf, size_t count) __overloadable
408 __error_if_overflows_ssizet(count);
409
410__BIONIC_ERROR_FUNCTION_VISIBILITY
411ssize_t read(int fd, void* buf, size_t count) __overloadable
412 __enable_if_no_overflow_ssizet(count)
413 __error_if_overflows_objectsize(count, __bos0(buf));
414
415__BIONIC_FORTIFY_INLINE
416ssize_t read(int fd, void* const __pass_object_size buf, size_t count)
417 __overloadable {
418 size_t bos = __bos0(buf);
419
420 if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
421 return __call_bypassing_fortify(read)(fd, buf, count);
422 }
423
424 return __read_chk(fd, buf, count, bos);
425}
426
427__BIONIC_ERROR_FUNCTION_VISIBILITY
428ssize_t write(int fd, const void* buf, size_t count) __overloadable
429 __error_if_overflows_ssizet(count);
430
431__BIONIC_ERROR_FUNCTION_VISIBILITY
432ssize_t write(int fd, const void* buf, size_t count) __overloadable
433 __enable_if_no_overflow_ssizet(count)
434 __error_if_overflows_objectsize(count, __bos0(buf));
435
436__BIONIC_FORTIFY_INLINE
437ssize_t write(int fd, const void* const __pass_object_size buf, size_t count)
438 __overloadable {
439 size_t bos = __bos0(buf);
440
441 if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
442 return __call_bypassing_fortify(write)(fd, buf, count);
443 }
444
445 return __write_chk(fd, buf, count, bos);
446}
447
448__BIONIC_ERROR_FUNCTION_VISIBILITY
449ssize_t readlink(const char* path, char* buf, size_t size) __overloadable
450 __error_if_overflows_ssizet(size);
451
452__BIONIC_ERROR_FUNCTION_VISIBILITY
453ssize_t readlink(const char* path, char* buf, size_t size) __overloadable
454 __enable_if_no_overflow_ssizet(size)
455 __error_if_overflows_objectsize(size, __bos(buf));
456
457__BIONIC_FORTIFY_INLINE
458ssize_t readlink(const char* path, char* const __pass_object_size buf,
459 size_t size) __overloadable {
460 size_t bos = __bos(buf);
461
462 if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
463 return __call_bypassing_fortify(readlink)(path, buf, size);
464 }
465
466 return __readlink_chk(path, buf, size, bos);
467}
468
469
470__BIONIC_ERROR_FUNCTION_VISIBILITY
471ssize_t readlinkat(int dirfd, const char* path, char* buf, size_t size)
472 __overloadable
473 __error_if_overflows_ssizet(size);
474
475__BIONIC_ERROR_FUNCTION_VISIBILITY
476ssize_t readlinkat(int dirfd, const char* path, char* buf, size_t size)
477 __overloadable
478 __enable_if_no_overflow_ssizet(size)
479 __error_if_overflows_objectsize(size, __bos(buf));
480
481__BIONIC_FORTIFY_INLINE
482ssize_t readlinkat(int dirfd, const char* path,
483 char* const __pass_object_size buf, size_t size)
484 __overloadable {
485 size_t bos = __bos(buf);
486
487 if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
488 return __call_bypassing_fortify(readlinkat)(dirfd, path, buf, size);
489 }
490
491 return __readlinkat_chk(dirfd, path, buf, size, bos);
492}
493
494#undef __enable_if_no_overflow_ssizet
495#undef __error_if_overflows_objectsize
496#undef __error_if_overflows_ssizet
497#else /* defined(__clang__) */
498
499char* __getcwd_real(char*, size_t) __RENAME(getcwd);
500ssize_t __read_real(int, void*, size_t) __RENAME(read);
501ssize_t __write_real(int, const void*, size_t) __RENAME(write);
502ssize_t __readlink_real(const char*, char*, size_t) __RENAME(readlink);
503ssize_t __readlinkat_real(int dirfd, const char*, char*, size_t) __RENAME(readlinkat);
504
505__errordecl(__getcwd_dest_size_error, "getcwd called with size bigger than destination");
506__errordecl(__pread_dest_size_error, "pread called with size bigger than destination");
507__errordecl(__pread_count_toobig_error, "pread called with count > SSIZE_MAX");
508__errordecl(__pread64_dest_size_error, "pread64 called with size bigger than destination");
509__errordecl(__pread64_count_toobig_error, "pread64 called with count > SSIZE_MAX");
510__errordecl(__pwrite_dest_size_error, "pwrite called with size bigger than destination");
511__errordecl(__pwrite_count_toobig_error, "pwrite called with count > SSIZE_MAX");
512__errordecl(__pwrite64_dest_size_error, "pwrite64 called with size bigger than destination");
513__errordecl(__pwrite64_count_toobig_error, "pwrite64 called with count > SSIZE_MAX");
514__errordecl(__read_dest_size_error, "read called with size bigger than destination");
515__errordecl(__read_count_toobig_error, "read called with count > SSIZE_MAX");
516__errordecl(__write_dest_size_error, "write called with size bigger than destination");
517__errordecl(__write_count_toobig_error, "write called with count > SSIZE_MAX");
518__errordecl(__readlink_dest_size_error, "readlink called with size bigger than destination");
519__errordecl(__readlink_size_toobig_error, "readlink called with size > SSIZE_MAX");
520__errordecl(__readlinkat_dest_size_error, "readlinkat called with size bigger than destination");
521__errordecl(__readlinkat_size_toobig_error, "readlinkat called with size > SSIZE_MAX");
522
523#if __ANDROID_API__ >= __ANDROID_API_N__
524__BIONIC_FORTIFY_INLINE
525char* getcwd(char* buf, size_t size) __overloadable {
526 size_t bos = __bos(buf);
527
Daniel Micay9101b002015-05-20 15:31:26 -0400528 if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
529 return __getcwd_real(buf, size);
530 }
531
532 if (__builtin_constant_p(size) && (size > bos)) {
533 __getcwd_dest_size_error();
534 }
535
536 if (__builtin_constant_p(size) && (size <= bos)) {
537 return __getcwd_real(buf, size);
538 }
Daniel Micay9101b002015-05-20 15:31:26 -0400539
540 return __getcwd_chk(buf, size, bos);
541}
Elliott Hughes5bc78c82016-11-16 11:35:43 -0800542#endif /* __ANDROID_API__ >= __ANDROID_API_N__ */
Daniel Micay9101b002015-05-20 15:31:26 -0400543
Elliott Hughes5bc78c82016-11-16 11:35:43 -0800544#if __ANDROID_API__ >= __ANDROID_API_M__
Daniel Micaye7e1c872015-04-16 09:07:45 -0400545__BIONIC_FORTIFY_INLINE
546ssize_t pread(int fd, void* buf, size_t count, off_t offset) {
547 size_t bos = __bos0(buf);
548
Daniel Micaye7e1c872015-04-16 09:07:45 -0400549 if (__builtin_constant_p(count) && (count > SSIZE_MAX)) {
550 __PREAD_PREFIX(count_toobig_error)();
551 }
552
553 if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
554 return __PREAD_PREFIX(real)(fd, buf, count, offset);
555 }
556
557 if (__builtin_constant_p(count) && (count > bos)) {
558 __PREAD_PREFIX(dest_size_error)();
559 }
560
561 if (__builtin_constant_p(count) && (count <= bos)) {
562 return __PREAD_PREFIX(real)(fd, buf, count, offset);
563 }
Daniel Micaye7e1c872015-04-16 09:07:45 -0400564
565 return __PREAD_PREFIX(chk)(fd, buf, count, offset, bos);
566}
567
568__BIONIC_FORTIFY_INLINE
569ssize_t pread64(int fd, void* buf, size_t count, off64_t offset) {
570 size_t bos = __bos0(buf);
571
Daniel Micaye7e1c872015-04-16 09:07:45 -0400572 if (__builtin_constant_p(count) && (count > SSIZE_MAX)) {
573 __pread64_count_toobig_error();
574 }
575
576 if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
577 return __pread64_real(fd, buf, count, offset);
578 }
579
580 if (__builtin_constant_p(count) && (count > bos)) {
581 __pread64_dest_size_error();
582 }
583
584 if (__builtin_constant_p(count) && (count <= bos)) {
585 return __pread64_real(fd, buf, count, offset);
586 }
Daniel Micaye7e1c872015-04-16 09:07:45 -0400587
588 return __pread64_chk(fd, buf, count, offset, bos);
589}
Elliott Hughes5bc78c82016-11-16 11:35:43 -0800590#endif /* __ANDROID_API__ >= __ANDROID_API_M__ */
Daniel Micaye7e1c872015-04-16 09:07:45 -0400591
Elliott Hughes5bc78c82016-11-16 11:35:43 -0800592#if __ANDROID_API__ >= __ANDROID_API_N__
Daniel Micayafdd1542015-07-20 21:37:29 -0400593__BIONIC_FORTIFY_INLINE
594ssize_t pwrite(int fd, const void* buf, size_t count, off_t offset) {
595 size_t bos = __bos0(buf);
596
Daniel Micayafdd1542015-07-20 21:37:29 -0400597 if (__builtin_constant_p(count) && (count > SSIZE_MAX)) {
598 __PWRITE_PREFIX(count_toobig_error)();
599 }
600
601 if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
602 return __PWRITE_PREFIX(real)(fd, buf, count, offset);
603 }
604
605 if (__builtin_constant_p(count) && (count > bos)) {
606 __PWRITE_PREFIX(dest_size_error)();
607 }
608
609 if (__builtin_constant_p(count) && (count <= bos)) {
610 return __PWRITE_PREFIX(real)(fd, buf, count, offset);
611 }
Daniel Micayafdd1542015-07-20 21:37:29 -0400612
613 return __PWRITE_PREFIX(chk)(fd, buf, count, offset, bos);
614}
615
616__BIONIC_FORTIFY_INLINE
617ssize_t pwrite64(int fd, const void* buf, size_t count, off64_t offset) {
618 size_t bos = __bos0(buf);
619
Daniel Micayafdd1542015-07-20 21:37:29 -0400620 if (__builtin_constant_p(count) && (count > SSIZE_MAX)) {
621 __pwrite64_count_toobig_error();
622 }
623
624 if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
625 return __pwrite64_real(fd, buf, count, offset);
626 }
627
628 if (__builtin_constant_p(count) && (count > bos)) {
629 __pwrite64_dest_size_error();
630 }
631
632 if (__builtin_constant_p(count) && (count <= bos)) {
633 return __pwrite64_real(fd, buf, count, offset);
634 }
Daniel Micayafdd1542015-07-20 21:37:29 -0400635
636 return __pwrite64_chk(fd, buf, count, offset, bos);
637}
Elliott Hughes5bc78c82016-11-16 11:35:43 -0800638#endif /* __ANDROID_API__ >= __ANDROID_API_N__ */
Daniel Micayafdd1542015-07-20 21:37:29 -0400639
Elliott Hughes5bc78c82016-11-16 11:35:43 -0800640#if __ANDROID_API__ >= __ANDROID_API_L__
Nick Kralevichb036b5c2013-10-09 20:16:34 -0700641__BIONIC_FORTIFY_INLINE
642ssize_t read(int fd, void* buf, size_t count) {
643 size_t bos = __bos0(buf);
644
Nick Kralevichb036b5c2013-10-09 20:16:34 -0700645 if (__builtin_constant_p(count) && (count > SSIZE_MAX)) {
646 __read_count_toobig_error();
647 }
648
649 if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
650 return __read_real(fd, buf, count);
651 }
652
653 if (__builtin_constant_p(count) && (count > bos)) {
654 __read_dest_size_error();
655 }
656
657 if (__builtin_constant_p(count) && (count <= bos)) {
658 return __read_real(fd, buf, count);
659 }
Nick Kralevichb036b5c2013-10-09 20:16:34 -0700660
661 return __read_chk(fd, buf, count, bos);
662}
Elliott Hughes5bc78c82016-11-16 11:35:43 -0800663#endif /* __ANDROID_API__ >= __ANDROID_API_L__ */
Daniel Micaye7e1c872015-04-16 09:07:45 -0400664
Elliott Hughes5bc78c82016-11-16 11:35:43 -0800665#if __ANDROID_API__ >= __ANDROID_API_N__
Daniel Micay42281882015-04-17 11:26:36 -0400666__BIONIC_FORTIFY_INLINE
Daniel Micayafdd1542015-07-20 21:37:29 -0400667ssize_t write(int fd, const void* buf, size_t count) {
668 size_t bos = __bos0(buf);
669
Daniel Micayafdd1542015-07-20 21:37:29 -0400670 if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
671 return __write_real(fd, buf, count);
672 }
673
674 if (__builtin_constant_p(count) && (count > bos)) {
675 __write_dest_size_error();
676 }
677
678 if (__builtin_constant_p(count) && (count <= bos)) {
679 return __write_real(fd, buf, count);
680 }
Daniel Micayafdd1542015-07-20 21:37:29 -0400681
682 return __write_chk(fd, buf, count, bos);
683}
Elliott Hughes5bc78c82016-11-16 11:35:43 -0800684#endif /* __ANDROID_API__ >= __ANDROID_API_N__ */
Daniel Micayafdd1542015-07-20 21:37:29 -0400685
Elliott Hughes5bc78c82016-11-16 11:35:43 -0800686#if __ANDROID_API__ >= __ANDROID_API_M__
Daniel Micayafdd1542015-07-20 21:37:29 -0400687__BIONIC_FORTIFY_INLINE
Daniel Micay42281882015-04-17 11:26:36 -0400688ssize_t readlink(const char* path, char* buf, size_t size) {
689 size_t bos = __bos(buf);
690
Daniel Micay42281882015-04-17 11:26:36 -0400691 if (__builtin_constant_p(size) && (size > SSIZE_MAX)) {
692 __readlink_size_toobig_error();
693 }
694
695 if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
696 return __readlink_real(path, buf, size);
697 }
698
699 if (__builtin_constant_p(size) && (size > bos)) {
700 __readlink_dest_size_error();
701 }
702
703 if (__builtin_constant_p(size) && (size <= bos)) {
704 return __readlink_real(path, buf, size);
705 }
Daniel Micay42281882015-04-17 11:26:36 -0400706
707 return __readlink_chk(path, buf, size, bos);
708}
709
710__BIONIC_FORTIFY_INLINE
711ssize_t readlinkat(int dirfd, const char* path, char* buf, size_t size) {
712 size_t bos = __bos(buf);
713
Daniel Micay42281882015-04-17 11:26:36 -0400714 if (__builtin_constant_p(size) && (size > SSIZE_MAX)) {
715 __readlinkat_size_toobig_error();
716 }
717
718 if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
719 return __readlinkat_real(dirfd, path, buf, size);
720 }
721
722 if (__builtin_constant_p(size) && (size > bos)) {
723 __readlinkat_dest_size_error();
724 }
725
726 if (__builtin_constant_p(size) && (size <= bos)) {
727 return __readlinkat_real(dirfd, path, buf, size);
728 }
Daniel Micay42281882015-04-17 11:26:36 -0400729
730 return __readlinkat_chk(dirfd, path, buf, size, bos);
731}
Elliott Hughes5bc78c82016-11-16 11:35:43 -0800732#endif /* __ANDROID_API__ >= __ANDROID_API_M__ */
George Burgess IV7cc779f2017-02-09 00:00:31 -0800733#endif /* defined(__clang__) */
734#undef __PREAD_PREFIX
735#undef __PWRITE_PREFIX
Nick Kralevichb036b5c2013-10-09 20:16:34 -0700736#endif /* defined(__BIONIC_FORTIFY) */
737
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800738__END_DECLS
739
740#endif /* _UNISTD_H_ */