1 /**
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef COMMON_H
18 #define COMMON_H
19 
20 #include <time.h>
21 #define MAX_TEST_DURATION 300
22 
23 // exit status code
24 #define EXIT_VULNERABLE 113
25 
26 #define FAIL_CHECK(condition) \
27   if (!(condition)) { \
28     fprintf(stderr, "Check failed:\n\t" #condition "\n\tLine: %d\n", \
29             __LINE__); \
30     exit(EXIT_FAILURE); \
31   }
32 
33 #define _32_BIT UINTPTR_MAX == UINT32_MAX
34 #define _64_BIT UINTPTR_MAX == UINT64_MAX
35 
36 time_t start_timer(void);
37 int timer_active(time_t timer_started);
38 
start_timer()39 inline time_t start_timer() { return time(NULL); }
40 
timer_active(time_t timer_started)41 inline int timer_active(time_t timer_started) {
42   return time(NULL) < (timer_started + MAX_TEST_DURATION);
43 }
44 
45 #endif /* COMMON_H */
46