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 _LLKD_H_
18 #define _LLKD_H_
19 
20 #ifndef LOG_TAG
21 #define LOG_TAG "livelock"
22 #endif
23 
24 #include <stdbool.h>
25 #include <sys/cdefs.h>
26 
27 __BEGIN_DECLS
28 
29 bool llkInit(const char* threadname); /* threadname NULL, not spawned */
30 unsigned llkCheckMilliseconds(void);
31 
32 /* clang-format off */
33 #define LLK_ENABLE_WRITEABLE_PROPERTY   "llk.enable"
34 #define LLK_ENABLE_PROPERTY             "ro." LLK_ENABLE_WRITEABLE_PROPERTY
35 #define LLK_ENABLE_DEFAULT              false /* "eng" and userdebug true */
36 #define KHT_ENABLE_WRITEABLE_PROPERTY   "khungtask.enable"
37 #define KHT_ENABLE_PROPERTY             "ro." KHT_ENABLE_WRITEABLE_PROPERTY
38 #define LLK_ENABLE_SYSRQ_T_PROPERTY     "ro.llk.sysrq_t"
39 #define LLK_ENABLE_SYSRQ_T_DEFAULT      true
40 #define LLK_MLOCKALL_PROPERTY           "ro.llk.mlockall"
41 #define LLK_MLOCKALL_DEFAULT            true
42 #define LLK_KILLTEST_PROPERTY           "ro.llk.killtest"
43 #define LLK_KILLTEST_DEFAULT            true
44 #define LLK_TIMEOUT_MS_PROPERTY         "ro.llk.timeout_ms"
45 #define KHT_TIMEOUT_PROPERTY            "ro.khungtask.timeout"
46 #define LLK_D_TIMEOUT_MS_PROPERTY       "ro.llk.D.timeout_ms"
47 #define LLK_Z_TIMEOUT_MS_PROPERTY       "ro.llk.Z.timeout_ms"
48 #define LLK_STACK_TIMEOUT_MS_PROPERTY   "ro.llk.stack.timeout_ms"
49 #define LLK_CHECK_MS_PROPERTY           "ro.llk.check_ms"
50 /* LLK_CHECK_MS_DEFAULT = actual timeout_ms / LLK_CHECKS_PER_TIMEOUT_DEFAULT */
51 #define LLK_CHECKS_PER_TIMEOUT_DEFAULT  5
52 #define LLK_CHECK_STACK_PROPERTY        "ro.llk.stack"
53 #define LLK_CHECK_STACK_DEFAULT         \
54     "cma_alloc,__get_user_pages,bit_wait_io,wait_on_page_bit_killable"
55 #define LLK_IGNORELIST_PROCESS_PROPERTY "ro.llk.ignorelist.process"
56 #define LLK_IGNORELIST_PROCESS_DEFAULT  \
57     "0,1,2,init,[kthreadd],[khungtaskd],lmkd,llkd,watchdogd,[watchdogd],[watchdogd/0]"
58 #define LLK_IGNORELIST_PARENT_PROPERTY  "ro.llk.ignorelist.parent"
59 #define LLK_IGNORELIST_PARENT_DEFAULT   "0,2,[kthreadd],adbd&[setsid]"
60 #define LLK_IGNORELIST_UID_PROPERTY     "ro.llk.ignorelist.uid"
61 #define LLK_IGNORELIST_UID_DEFAULT      ""
62 #define LLK_IGNORELIST_STACK_PROPERTY   "ro.llk.ignorelist.process.stack"
63 #define LLK_IGNORELIST_STACK_DEFAULT    "init,lmkd.llkd,llkd,keystore,ueventd,apexd"
64 /* clang-format on */
65 
66 __END_DECLS
67 
68 #ifdef __cplusplus
69 extern "C++" { /* In case this included wrapped with __BEGIN_DECLS */
70 
71 #include <chrono>
72 
73 __BEGIN_DECLS
74 /* C++ code allowed to not specify threadname argument for this C linkage */
75 bool llkInit(const char* threadname = nullptr);
76 __END_DECLS
77 std::chrono::milliseconds llkCheck(bool checkRunning = false);
78 
79 /* clang-format off */
80 #define LLK_TIMEOUT_MS_DEFAULT  std::chrono::duration_cast<milliseconds>(std::chrono::minutes(10))
81 #define LLK_TIMEOUT_MS_MINIMUM  std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::seconds(10))
82 #define LLK_CHECK_MS_MINIMUM    std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::seconds(1))
83 /* clang-format on */
84 
85 } /* extern "C++" */
86 #endif /* __cplusplus */
87 
88 #endif /* _LLKD_H_ */
89