• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef _POLL_H
17 #error "Never include this file directly; instead, include <poll.h>"
18 #endif
19 
20 #include <signal.h>
21 #include "fortify.h"
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 int __poll_chk(struct pollfd*, nfds_t, int, size_t);
28 #ifdef _GNU_SOURCE
29 int __ppoll_chk(struct pollfd*, nfds_t, const struct timespec*, const sigset_t*, size_t);
30 #endif
31 
32 #ifdef __FORTIFY_COMPILATION
33 __DIAGNOSE_FORTIFY_INLINE
poll(struct pollfd * const fds __DIAGNOSE_PASS_OBJECT_SIZE,nfds_t fd_amount,int timeout)34 int poll(struct pollfd* const fds __DIAGNOSE_PASS_OBJECT_SIZE, nfds_t fd_amount, int timeout)
35 __DIAGNOSE_OVERLOAD
36 __DIAGNOSE_ERROR_IF(__DIAGNOSE_UNEVALUATED_LT(__DIAGNOSE_BOS(fds), sizeof(*fds) * fd_amount),
37     "in call to 'poll', " FD_COUNT_LARGE_GIVEN_BUFFER)
38 {
39 #ifdef __FORTIFY_RUNTIME
40     size_t bos_fds = __DIAGNOSE_BOS(fds);
41 
42     if (!__DIAGNOSE_BOS_FD_COUNT_TRIVIALLY_SAFE(bos_fds, fds, fd_amount)) {
43         return __poll_chk(fds, fd_amount, timeout, bos_fds);
44     }
45 #endif
46     return __DIAGNOSE_CALL_BYPASSING_FORTIFY(poll)(fds, fd_amount, timeout);
47 }
48 
49 #ifdef _GNU_SOURCE
50 __DIAGNOSE_FORTIFY_INLINE
ppoll(struct pollfd * const fds __DIAGNOSE_PASS_OBJECT_SIZE,nfds_t fd_amount,const struct timespec * timeout,const sigset_t * mask)51 int ppoll(struct pollfd* const fds __DIAGNOSE_PASS_OBJECT_SIZE, nfds_t fd_amount,
52     const struct timespec* timeout, const sigset_t* mask)
53 __DIAGNOSE_OVERLOAD
54 __DIAGNOSE_ERROR_IF(__DIAGNOSE_UNEVALUATED_LT(__DIAGNOSE_BOS(fds), sizeof(*fds) * fd_amount),
55     "in call to 'ppoll', " FD_COUNT_LARGE_GIVEN_BUFFER)
56 {
57 #ifdef __FORTIFY_RUNTIME
58     size_t bos_fds = __DIAGNOSE_BOS(fds);
59 
60     if (!__DIAGNOSE_BOS_FD_COUNT_TRIVIALLY_SAFE(bos_fds, fds, fd_amount)) {
61         return __ppoll_chk(fds, fd_amount, timeout, mask, bos_fds);
62     }
63 #endif
64     return __DIAGNOSE_CALL_BYPASSING_FORTIFY(ppoll)(fds, fd_amount, timeout, mask);
65 }
66 #endif
67 
68 #endif
69 
70 #ifdef __cplusplus
71 }
72 #endif