George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | #ifndef _UNISTD_H_ |
| 29 | #error "Never include this file directly; instead, include <unistd.h>" |
| 30 | #endif |
| 31 | |
| 32 | char* __getcwd_chk(char*, size_t, size_t) __INTRODUCED_IN(24); |
| 33 | |
| 34 | ssize_t __pread_chk(int, void*, size_t, off_t, size_t) __INTRODUCED_IN(23); |
| 35 | ssize_t __pread_real(int, void*, size_t, off_t) __RENAME(pread); |
| 36 | |
| 37 | ssize_t __pread64_chk(int, void*, size_t, off64_t, size_t) __INTRODUCED_IN(23); |
| 38 | ssize_t __pread64_real(int, void*, size_t, off64_t) __RENAME(pread64) __INTRODUCED_IN(12); |
| 39 | |
| 40 | ssize_t __pwrite_chk(int, const void*, size_t, off_t, size_t) __INTRODUCED_IN(24); |
| 41 | ssize_t __pwrite_real(int, const void*, size_t, off_t) __RENAME(pwrite); |
| 42 | |
| 43 | ssize_t __pwrite64_chk(int, const void*, size_t, off64_t, size_t) __INTRODUCED_IN(24); |
| 44 | ssize_t __pwrite64_real(int, const void*, size_t, off64_t) __RENAME(pwrite64) |
| 45 | __INTRODUCED_IN(12); |
| 46 | |
| 47 | ssize_t __read_chk(int, void*, size_t, size_t) __INTRODUCED_IN(21); |
| 48 | ssize_t __write_chk(int, const void*, size_t, size_t) __INTRODUCED_IN(24); |
| 49 | ssize_t __readlink_chk(const char*, char*, size_t, size_t) __INTRODUCED_IN(23); |
| 50 | ssize_t __readlinkat_chk(int dirfd, const char*, char*, size_t, size_t) __INTRODUCED_IN(23); |
| 51 | |
| 52 | #if defined(__BIONIC_FORTIFY) |
| 53 | |
| 54 | #if defined(__USE_FILE_OFFSET64) |
| 55 | #define __PREAD_PREFIX(x) __pread64_ ## x |
| 56 | #define __PWRITE_PREFIX(x) __pwrite64_ ## x |
| 57 | #else |
| 58 | #define __PREAD_PREFIX(x) __pread_ ## x |
| 59 | #define __PWRITE_PREFIX(x) __pwrite_ ## x |
| 60 | #endif |
| 61 | |
| 62 | #if defined(__clang__) |
| 63 | #define __error_if_overflows_ssizet(what) \ |
| 64 | __enable_if(what > SSIZE_MAX, #what " must be <= SSIZE_MAX") \ |
| 65 | __errorattr(#what " must be <= SSIZE_MAX") |
| 66 | |
| 67 | #define __enable_if_no_overflow_ssizet(what) \ |
| 68 | __enable_if((what) <= SSIZE_MAX, "enabled if " #what " <= SSIZE_MAX") |
| 69 | |
| 70 | #define __error_if_overflows_objectsize(what, objsize) \ |
| 71 | __enable_if((objsize) != __BIONIC_FORTIFY_UNKNOWN_SIZE && \ |
| 72 | (what) > (objsize), \ |
| 73 | "'" #what "' bytes overflows the given object") \ |
| 74 | __errorattr("'" #what "' bytes overflows the given object") |
| 75 | |
| 76 | __BIONIC_ERROR_FUNCTION_VISIBILITY |
| 77 | char* getcwd(char* buf, size_t size) __overloadable |
| 78 | __error_if_overflows_objectsize(size, __bos(buf)); |
| 79 | |
| 80 | #if __ANDROID_API__ >= __ANDROID_API_N__ |
| 81 | __BIONIC_FORTIFY_INLINE |
| 82 | char* getcwd(char* const __pass_object_size buf, size_t size) __overloadable { |
| 83 | size_t bos = __bos(buf); |
| 84 | |
| 85 | /* |
| 86 | * Clang responds bos==0 if buf==NULL |
| 87 | * (https://llvm.org/bugs/show_bug.cgi?id=23277). Given that NULL is a valid |
| 88 | * value, we need to handle that. |
| 89 | */ |
| 90 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE || buf == NULL) { |
| 91 | return __call_bypassing_fortify(getcwd)(buf, size); |
| 92 | } |
| 93 | |
| 94 | return __getcwd_chk(buf, size, bos); |
| 95 | } |
| 96 | #endif /* __ANDROID_API__ >= __ANDROID_API_N__ */ |
| 97 | |
| 98 | #if __ANDROID_API__ >= __ANDROID_API_M__ |
| 99 | __BIONIC_ERROR_FUNCTION_VISIBILITY |
| 100 | ssize_t pread(int fd, void* buf, size_t count, off_t offset) __overloadable |
| 101 | __error_if_overflows_ssizet(count); |
| 102 | |
| 103 | __BIONIC_ERROR_FUNCTION_VISIBILITY |
| 104 | ssize_t pread(int fd, void* buf, size_t count, off_t offset) __overloadable |
| 105 | __enable_if_no_overflow_ssizet(count) |
| 106 | __error_if_overflows_objectsize(count, __bos0(buf)); |
| 107 | |
| 108 | __BIONIC_FORTIFY_INLINE |
| 109 | ssize_t pread(int fd, void* const __pass_object_size0 buf, size_t count, |
| 110 | off_t offset) __overloadable { |
| 111 | size_t bos = __bos0(buf); |
| 112 | |
| 113 | if (count == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 114 | return __PREAD_PREFIX(real)(fd, buf, count, offset); |
| 115 | } |
| 116 | |
| 117 | return __PREAD_PREFIX(chk)(fd, buf, count, offset, bos); |
| 118 | } |
| 119 | |
| 120 | __BIONIC_ERROR_FUNCTION_VISIBILITY |
| 121 | ssize_t pread64(int fd, void* buf, size_t count, off64_t offset) __overloadable |
| 122 | __error_if_overflows_ssizet(count); |
| 123 | |
| 124 | __BIONIC_ERROR_FUNCTION_VISIBILITY |
| 125 | ssize_t pread64(int fd, void* buf, size_t count, off64_t offset) __overloadable |
| 126 | __enable_if_no_overflow_ssizet(count) |
| 127 | __error_if_overflows_objectsize(count, __bos0(buf)); |
| 128 | |
| 129 | __BIONIC_FORTIFY_INLINE |
| 130 | ssize_t pread64(int fd, void* const __pass_object_size0 buf, size_t count, |
| 131 | off64_t offset) __overloadable { |
| 132 | size_t bos = __bos0(buf); |
| 133 | |
| 134 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 135 | return __pread64_real(fd, buf, count, offset); |
| 136 | } |
| 137 | |
| 138 | return __pread64_chk(fd, buf, count, offset, bos); |
| 139 | } |
| 140 | #endif /* __ANDROID_API__ >= __ANDROID_API_M__ */ |
| 141 | |
| 142 | #if __ANDROID_API__ >= __ANDROID_API_N__ |
| 143 | __BIONIC_ERROR_FUNCTION_VISIBILITY |
| 144 | ssize_t pwrite(int fd, const void* buf, size_t count, off_t offset) |
| 145 | __overloadable |
| 146 | __error_if_overflows_ssizet(count); |
| 147 | |
| 148 | __BIONIC_ERROR_FUNCTION_VISIBILITY |
| 149 | ssize_t pwrite(int fd, const void* buf, size_t count, off_t offset) |
| 150 | __overloadable |
| 151 | __enable_if_no_overflow_ssizet(count) |
| 152 | __error_if_overflows_objectsize(count, __bos0(buf)); |
| 153 | |
| 154 | __BIONIC_FORTIFY_INLINE |
| 155 | ssize_t pwrite(int fd, const void* const __pass_object_size0 buf, size_t count, |
| 156 | off_t offset) __overloadable { |
| 157 | size_t bos = __bos0(buf); |
| 158 | |
| 159 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 160 | return __PWRITE_PREFIX(real)(fd, buf, count, offset); |
| 161 | } |
| 162 | |
| 163 | return __PWRITE_PREFIX(chk)(fd, buf, count, offset, bos); |
| 164 | } |
| 165 | |
| 166 | __BIONIC_ERROR_FUNCTION_VISIBILITY |
| 167 | ssize_t pwrite64(int fd, const void* buf, size_t count, off64_t offset) |
| 168 | __overloadable |
| 169 | __error_if_overflows_ssizet(count); |
| 170 | |
| 171 | __BIONIC_ERROR_FUNCTION_VISIBILITY |
| 172 | ssize_t pwrite64(int fd, const void* buf, size_t count, off64_t offset) |
| 173 | __overloadable |
| 174 | __enable_if_no_overflow_ssizet(count) |
| 175 | __error_if_overflows_objectsize(count, __bos0(buf)); |
| 176 | |
| 177 | __BIONIC_FORTIFY_INLINE |
| 178 | ssize_t pwrite64(int fd, const void* const __pass_object_size0 buf, |
| 179 | size_t count, off64_t offset) __overloadable { |
| 180 | size_t bos = __bos0(buf); |
| 181 | |
| 182 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 183 | return __pwrite64_real(fd, buf, count, offset); |
| 184 | } |
| 185 | |
| 186 | return __pwrite64_chk(fd, buf, count, offset, bos); |
| 187 | } |
| 188 | #endif /* __ANDROID_API__ >= __ANDROID_API_N__ */ |
| 189 | |
| 190 | #if __ANDROID_API__ >= __ANDROID_API_L__ |
| 191 | __BIONIC_ERROR_FUNCTION_VISIBILITY |
| 192 | ssize_t read(int fd, void* buf, size_t count) __overloadable |
| 193 | __error_if_overflows_ssizet(count); |
| 194 | |
| 195 | __BIONIC_ERROR_FUNCTION_VISIBILITY |
| 196 | ssize_t read(int fd, void* buf, size_t count) __overloadable |
| 197 | __enable_if_no_overflow_ssizet(count) |
| 198 | __error_if_overflows_objectsize(count, __bos0(buf)); |
| 199 | |
| 200 | __BIONIC_FORTIFY_INLINE |
| 201 | ssize_t read(int fd, void* const __pass_object_size0 buf, size_t count) |
| 202 | __overloadable { |
| 203 | size_t bos = __bos0(buf); |
| 204 | |
| 205 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 206 | return __call_bypassing_fortify(read)(fd, buf, count); |
| 207 | } |
| 208 | |
| 209 | return __read_chk(fd, buf, count, bos); |
| 210 | } |
| 211 | #endif /* __ANDROID_API__ >= __ANDROID_API_L__ */ |
| 212 | |
| 213 | #if __ANDROID_API__ >= __ANDROID_API_N__ |
| 214 | __BIONIC_ERROR_FUNCTION_VISIBILITY |
| 215 | ssize_t write(int fd, const void* buf, size_t count) __overloadable |
| 216 | __error_if_overflows_ssizet(count); |
| 217 | |
| 218 | __BIONIC_ERROR_FUNCTION_VISIBILITY |
| 219 | ssize_t write(int fd, const void* buf, size_t count) __overloadable |
| 220 | __enable_if_no_overflow_ssizet(count) |
| 221 | __error_if_overflows_objectsize(count, __bos0(buf)); |
| 222 | |
| 223 | __BIONIC_FORTIFY_INLINE |
| 224 | ssize_t write(int fd, const void* const __pass_object_size0 buf, size_t count) |
| 225 | __overloadable { |
| 226 | size_t bos = __bos0(buf); |
| 227 | |
| 228 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 229 | return __call_bypassing_fortify(write)(fd, buf, count); |
| 230 | } |
| 231 | |
| 232 | return __write_chk(fd, buf, count, bos); |
| 233 | } |
| 234 | #endif /* __ANDROID_API__ >= __ANDROID_API_N__ */ |
| 235 | |
| 236 | #if __ANDROID_API__ >= __ANDROID_API_M__ |
| 237 | __BIONIC_ERROR_FUNCTION_VISIBILITY |
| 238 | ssize_t readlink(const char* path, char* buf, size_t size) __overloadable |
| 239 | __error_if_overflows_ssizet(size); |
| 240 | |
| 241 | __BIONIC_ERROR_FUNCTION_VISIBILITY |
| 242 | ssize_t readlink(const char* path, char* buf, size_t size) __overloadable |
| 243 | __enable_if_no_overflow_ssizet(size) |
| 244 | __error_if_overflows_objectsize(size, __bos(buf)); |
| 245 | |
| 246 | __BIONIC_FORTIFY_INLINE |
| 247 | ssize_t readlink(const char* path, char* const __pass_object_size buf, |
| 248 | size_t size) __overloadable { |
| 249 | size_t bos = __bos(buf); |
| 250 | |
| 251 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 252 | return __call_bypassing_fortify(readlink)(path, buf, size); |
| 253 | } |
| 254 | |
| 255 | return __readlink_chk(path, buf, size, bos); |
| 256 | } |
| 257 | |
| 258 | __BIONIC_ERROR_FUNCTION_VISIBILITY |
| 259 | ssize_t readlinkat(int dirfd, const char* path, char* buf, size_t size) |
| 260 | __overloadable |
| 261 | __error_if_overflows_ssizet(size); |
| 262 | |
| 263 | __BIONIC_ERROR_FUNCTION_VISIBILITY |
| 264 | ssize_t readlinkat(int dirfd, const char* path, char* buf, size_t size) |
| 265 | __overloadable |
| 266 | __enable_if_no_overflow_ssizet(size) |
| 267 | __error_if_overflows_objectsize(size, __bos(buf)); |
| 268 | |
| 269 | __BIONIC_FORTIFY_INLINE |
| 270 | ssize_t readlinkat(int dirfd, const char* path, |
| 271 | char* const __pass_object_size buf, size_t size) |
| 272 | __overloadable { |
| 273 | size_t bos = __bos(buf); |
| 274 | |
| 275 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 276 | return __call_bypassing_fortify(readlinkat)(dirfd, path, buf, size); |
| 277 | } |
| 278 | |
| 279 | return __readlinkat_chk(dirfd, path, buf, size, bos); |
| 280 | } |
| 281 | #endif /* __ANDROID_API__ >= __ANDROID_API_M__ */ |
| 282 | |
| 283 | #undef __enable_if_no_overflow_ssizet |
| 284 | #undef __error_if_overflows_objectsize |
| 285 | #undef __error_if_overflows_ssizet |
| 286 | #else /* defined(__clang__) */ |
| 287 | |
| 288 | char* __getcwd_real(char*, size_t) __RENAME(getcwd); |
| 289 | ssize_t __read_real(int, void*, size_t) __RENAME(read); |
| 290 | ssize_t __write_real(int, const void*, size_t) __RENAME(write); |
| 291 | ssize_t __readlink_real(const char*, char*, size_t) __RENAME(readlink); |
| 292 | ssize_t __readlinkat_real(int dirfd, const char*, char*, size_t) __RENAME(readlinkat); |
| 293 | |
| 294 | __errordecl(__getcwd_dest_size_error, "getcwd called with size bigger than destination"); |
| 295 | __errordecl(__pread_dest_size_error, "pread called with size bigger than destination"); |
| 296 | __errordecl(__pread_count_toobig_error, "pread called with count > SSIZE_MAX"); |
| 297 | __errordecl(__pread64_dest_size_error, "pread64 called with size bigger than destination"); |
| 298 | __errordecl(__pread64_count_toobig_error, "pread64 called with count > SSIZE_MAX"); |
| 299 | __errordecl(__pwrite_dest_size_error, "pwrite called with size bigger than destination"); |
| 300 | __errordecl(__pwrite_count_toobig_error, "pwrite called with count > SSIZE_MAX"); |
| 301 | __errordecl(__pwrite64_dest_size_error, "pwrite64 called with size bigger than destination"); |
| 302 | __errordecl(__pwrite64_count_toobig_error, "pwrite64 called with count > SSIZE_MAX"); |
| 303 | __errordecl(__read_dest_size_error, "read called with size bigger than destination"); |
| 304 | __errordecl(__read_count_toobig_error, "read called with count > SSIZE_MAX"); |
| 305 | __errordecl(__write_dest_size_error, "write called with size bigger than destination"); |
| 306 | __errordecl(__write_count_toobig_error, "write called with count > SSIZE_MAX"); |
| 307 | __errordecl(__readlink_dest_size_error, "readlink called with size bigger than destination"); |
| 308 | __errordecl(__readlink_size_toobig_error, "readlink called with size > SSIZE_MAX"); |
| 309 | __errordecl(__readlinkat_dest_size_error, "readlinkat called with size bigger than destination"); |
| 310 | __errordecl(__readlinkat_size_toobig_error, "readlinkat called with size > SSIZE_MAX"); |
| 311 | |
| 312 | #if __ANDROID_API__ >= __ANDROID_API_N__ |
| 313 | __BIONIC_FORTIFY_INLINE |
| 314 | char* getcwd(char* buf, size_t size) __overloadable { |
| 315 | size_t bos = __bos(buf); |
| 316 | |
| 317 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 318 | return __getcwd_real(buf, size); |
| 319 | } |
| 320 | |
| 321 | if (__builtin_constant_p(size) && (size > bos)) { |
| 322 | __getcwd_dest_size_error(); |
| 323 | } |
| 324 | |
| 325 | if (__builtin_constant_p(size) && (size <= bos)) { |
| 326 | return __getcwd_real(buf, size); |
| 327 | } |
| 328 | |
| 329 | return __getcwd_chk(buf, size, bos); |
| 330 | } |
| 331 | #endif /* __ANDROID_API__ >= __ANDROID_API_N__ */ |
| 332 | |
| 333 | #if __ANDROID_API__ >= __ANDROID_API_M__ |
| 334 | __BIONIC_FORTIFY_INLINE |
| 335 | ssize_t pread(int fd, void* buf, size_t count, off_t offset) { |
| 336 | size_t bos = __bos0(buf); |
| 337 | |
| 338 | if (__builtin_constant_p(count) && (count > SSIZE_MAX)) { |
| 339 | __PREAD_PREFIX(count_toobig_error)(); |
| 340 | } |
| 341 | |
| 342 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 343 | return __PREAD_PREFIX(real)(fd, buf, count, offset); |
| 344 | } |
| 345 | |
| 346 | if (__builtin_constant_p(count) && (count > bos)) { |
| 347 | __PREAD_PREFIX(dest_size_error)(); |
| 348 | } |
| 349 | |
| 350 | if (__builtin_constant_p(count) && (count <= bos)) { |
| 351 | return __PREAD_PREFIX(real)(fd, buf, count, offset); |
| 352 | } |
| 353 | |
| 354 | return __PREAD_PREFIX(chk)(fd, buf, count, offset, bos); |
| 355 | } |
| 356 | |
| 357 | __BIONIC_FORTIFY_INLINE |
| 358 | ssize_t pread64(int fd, void* buf, size_t count, off64_t offset) { |
| 359 | size_t bos = __bos0(buf); |
| 360 | |
| 361 | if (__builtin_constant_p(count) && (count > SSIZE_MAX)) { |
| 362 | __pread64_count_toobig_error(); |
| 363 | } |
| 364 | |
| 365 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 366 | return __pread64_real(fd, buf, count, offset); |
| 367 | } |
| 368 | |
| 369 | if (__builtin_constant_p(count) && (count > bos)) { |
| 370 | __pread64_dest_size_error(); |
| 371 | } |
| 372 | |
| 373 | if (__builtin_constant_p(count) && (count <= bos)) { |
| 374 | return __pread64_real(fd, buf, count, offset); |
| 375 | } |
| 376 | |
| 377 | return __pread64_chk(fd, buf, count, offset, bos); |
| 378 | } |
| 379 | #endif /* __ANDROID_API__ >= __ANDROID_API_M__ */ |
| 380 | |
| 381 | #if __ANDROID_API__ >= __ANDROID_API_N__ |
| 382 | __BIONIC_FORTIFY_INLINE |
| 383 | ssize_t pwrite(int fd, const void* buf, size_t count, off_t offset) { |
| 384 | size_t bos = __bos0(buf); |
| 385 | |
| 386 | if (__builtin_constant_p(count) && (count > SSIZE_MAX)) { |
| 387 | __PWRITE_PREFIX(count_toobig_error)(); |
| 388 | } |
| 389 | |
| 390 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 391 | return __PWRITE_PREFIX(real)(fd, buf, count, offset); |
| 392 | } |
| 393 | |
| 394 | if (__builtin_constant_p(count) && (count > bos)) { |
| 395 | __PWRITE_PREFIX(dest_size_error)(); |
| 396 | } |
| 397 | |
| 398 | if (__builtin_constant_p(count) && (count <= bos)) { |
| 399 | return __PWRITE_PREFIX(real)(fd, buf, count, offset); |
| 400 | } |
| 401 | |
| 402 | return __PWRITE_PREFIX(chk)(fd, buf, count, offset, bos); |
| 403 | } |
| 404 | |
| 405 | __BIONIC_FORTIFY_INLINE |
| 406 | ssize_t pwrite64(int fd, const void* buf, size_t count, off64_t offset) { |
| 407 | size_t bos = __bos0(buf); |
| 408 | |
| 409 | if (__builtin_constant_p(count) && (count > SSIZE_MAX)) { |
| 410 | __pwrite64_count_toobig_error(); |
| 411 | } |
| 412 | |
| 413 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 414 | return __pwrite64_real(fd, buf, count, offset); |
| 415 | } |
| 416 | |
| 417 | if (__builtin_constant_p(count) && (count > bos)) { |
| 418 | __pwrite64_dest_size_error(); |
| 419 | } |
| 420 | |
| 421 | if (__builtin_constant_p(count) && (count <= bos)) { |
| 422 | return __pwrite64_real(fd, buf, count, offset); |
| 423 | } |
| 424 | |
| 425 | return __pwrite64_chk(fd, buf, count, offset, bos); |
| 426 | } |
| 427 | #endif /* __ANDROID_API__ >= __ANDROID_API_N__ */ |
| 428 | |
| 429 | #if __ANDROID_API__ >= __ANDROID_API_L__ |
| 430 | __BIONIC_FORTIFY_INLINE |
| 431 | ssize_t read(int fd, void* buf, size_t count) { |
| 432 | size_t bos = __bos0(buf); |
| 433 | |
| 434 | if (__builtin_constant_p(count) && (count > SSIZE_MAX)) { |
| 435 | __read_count_toobig_error(); |
| 436 | } |
| 437 | |
| 438 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 439 | return __read_real(fd, buf, count); |
| 440 | } |
| 441 | |
| 442 | if (__builtin_constant_p(count) && (count > bos)) { |
| 443 | __read_dest_size_error(); |
| 444 | } |
| 445 | |
| 446 | if (__builtin_constant_p(count) && (count <= bos)) { |
| 447 | return __read_real(fd, buf, count); |
| 448 | } |
| 449 | |
| 450 | return __read_chk(fd, buf, count, bos); |
| 451 | } |
| 452 | #endif /* __ANDROID_API__ >= __ANDROID_API_L__ */ |
| 453 | |
| 454 | #if __ANDROID_API__ >= __ANDROID_API_N__ |
| 455 | __BIONIC_FORTIFY_INLINE |
| 456 | ssize_t write(int fd, const void* buf, size_t count) { |
| 457 | size_t bos = __bos0(buf); |
| 458 | |
| 459 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 460 | return __write_real(fd, buf, count); |
| 461 | } |
| 462 | |
| 463 | if (__builtin_constant_p(count) && (count > bos)) { |
| 464 | __write_dest_size_error(); |
| 465 | } |
| 466 | |
| 467 | if (__builtin_constant_p(count) && (count <= bos)) { |
| 468 | return __write_real(fd, buf, count); |
| 469 | } |
| 470 | |
| 471 | return __write_chk(fd, buf, count, bos); |
| 472 | } |
| 473 | #endif /* __ANDROID_API__ >= __ANDROID_API_N__ */ |
| 474 | |
| 475 | #if __ANDROID_API__ >= __ANDROID_API_M__ |
| 476 | __BIONIC_FORTIFY_INLINE |
| 477 | ssize_t readlink(const char* path, char* buf, size_t size) { |
| 478 | size_t bos = __bos(buf); |
| 479 | |
| 480 | if (__builtin_constant_p(size) && (size > SSIZE_MAX)) { |
| 481 | __readlink_size_toobig_error(); |
| 482 | } |
| 483 | |
| 484 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 485 | return __readlink_real(path, buf, size); |
| 486 | } |
| 487 | |
| 488 | if (__builtin_constant_p(size) && (size > bos)) { |
| 489 | __readlink_dest_size_error(); |
| 490 | } |
| 491 | |
| 492 | if (__builtin_constant_p(size) && (size <= bos)) { |
| 493 | return __readlink_real(path, buf, size); |
| 494 | } |
| 495 | |
| 496 | return __readlink_chk(path, buf, size, bos); |
| 497 | } |
| 498 | |
| 499 | __BIONIC_FORTIFY_INLINE |
| 500 | ssize_t readlinkat(int dirfd, const char* path, char* buf, size_t size) { |
| 501 | size_t bos = __bos(buf); |
| 502 | |
| 503 | if (__builtin_constant_p(size) && (size > SSIZE_MAX)) { |
| 504 | __readlinkat_size_toobig_error(); |
| 505 | } |
| 506 | |
| 507 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 508 | return __readlinkat_real(dirfd, path, buf, size); |
| 509 | } |
| 510 | |
| 511 | if (__builtin_constant_p(size) && (size > bos)) { |
| 512 | __readlinkat_dest_size_error(); |
| 513 | } |
| 514 | |
| 515 | if (__builtin_constant_p(size) && (size <= bos)) { |
| 516 | return __readlinkat_real(dirfd, path, buf, size); |
| 517 | } |
| 518 | |
| 519 | return __readlinkat_chk(dirfd, path, buf, size, bos); |
| 520 | } |
| 521 | #endif /* __ANDROID_API__ >= __ANDROID_API_M__ */ |
| 522 | #endif /* defined(__clang__) */ |
| 523 | #undef __PREAD_PREFIX |
| 524 | #undef __PWRITE_PREFIX |
| 525 | #endif /* defined(__BIONIC_FORTIFY) */ |