fortify: use __builtin_constant_p for more short-circuits
This also lets us retire our |__enable_if| version of |strlen|, which
should catch strictly fewer cases where we can fold the string's length
to a constant than |__builtin_constant_p| inside of |strlen|.
Bug: 131861088
Test: checkbuild on internal master. blueline bionic tests pass + it
boots.
Change-Id: I21b750a24f7d1825591a88d12a385be03a0a7ca3
diff --git a/libc/include/bits/fortify/poll.h b/libc/include/bits/fortify/poll.h
index 0d9b927..660dfca 100644
--- a/libc/include/bits/fortify/poll.h
+++ b/libc/include/bits/fortify/poll.h
@@ -37,6 +37,10 @@
#if defined(__BIONIC_FORTIFY)
#if __ANDROID_API__ >= __ANDROID_API_M__
+#define __bos_fd_count_trivially_safe(bos_val, fds, fd_count) \
+ __bos_dynamic_check_impl_and((bos_val), >=, (sizeof(*fds) * (fd_count)), \
+ (fd_count) <= __BIONIC_CAST(static_cast, nfds_t, -1) / sizeof(*fds))
+
__BIONIC_FORTIFY_INLINE
int poll(struct pollfd* const fds __pass_object_size, nfds_t fd_count, int timeout)
__overloadable
@@ -44,7 +48,7 @@
"in call to 'poll', fd_count is larger than the given buffer") {
size_t bos_fds = __bos(fds);
- if (bos_fds == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
+ if (__bos_fd_count_trivially_safe(bos_fds, fds, fd_count)) {
return __call_bypassing_fortify(poll)(fds, fd_count, timeout);
}
return __poll_chk(fds, fd_count, timeout, bos_fds);
@@ -57,7 +61,7 @@
"in call to 'ppoll', fd_count is larger than the given buffer") {
size_t bos_fds = __bos(fds);
- if (bos_fds == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
+ if (__bos_fd_count_trivially_safe(bos_fds, fds, fd_count)) {
return __call_bypassing_fortify(ppoll)(fds, fd_count, timeout, mask);
}
return __ppoll_chk(fds, fd_count, timeout, mask, bos_fds);
@@ -71,12 +75,14 @@
"in call to 'ppoll64', fd_count is larger than the given buffer") {
size_t bos_fds = __bos(fds);
- if (bos_fds == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
+ if (__bos_fd_count_trivially_safe(bos_fds, fds, fd_count)) {
return __call_bypassing_fortify(ppoll64)(fds, fd_count, timeout, mask);
}
return __ppoll64_chk(fds, fd_count, timeout, mask, bos_fds);
}
#endif
+#undef __bos_fd_count_trivially_safe
+
#endif /* __ANDROID_API__ >= __ANDROID_API_M__ */
#endif /* defined(__BIONIC_FORTIFY) */