1 /* 2 * Copyright 2022 Google, Inc 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 /* 18 * This file defines no-op hook functions for LMKD. To override these 19 * definitions, enable the use_lmkd_hooks product variable and create a library 20 * "liblmkdhooks" that supplies definitions for the hook functions in your 21 * vendor folder. 22 */ 23 24 #ifndef _LMKD_HOOKS_H_ 25 #define _LMKD_HOOKS_H_ 26 27 #include <sys/types.h> 28 29 __BEGIN_DECLS 30 31 #ifdef LMKD_USE_HOOKS 32 33 /* 34 * Initialize all necessary Android props and perform any necessary validation 35 * on the values. Called before lmkd_init_hook() and will be called again 36 * whenever LMKD receives the LMK_UPDATE_PROPS command. Returns true on success, 37 * false otherwise. 38 */ 39 bool lmkd_update_props_hook(); 40 /* 41 * Perform any necessary initialization for the hooks. Called only once at the 42 * end of LMKD's init(). Returns true on success, false otherwise. 43 */ 44 bool lmkd_init_hook(); 45 /* 46 * Allows for interception of a kill by LMKD. This hook may attempt to free 47 * memory elsewhere to avoid the specified process being killed. Returns 0 to 48 * proceed with the kill, or the number of memory pages freed elsewhere to skip 49 * the kill. 50 */ 51 int lmkd_free_memory_before_kill_hook(struct proc* procp, int proc_size_pages, 52 int proc_oom_score, int kill_reason); 53 /* 54 * Invoked when LMKD has no more candidates to kill at any priority. The hook 55 * may attempt to free memory elsewhere to try to preserve system stability. 56 */ 57 void lmkd_no_kill_candidates_hook(); 58 59 #else /* LMKD_USE_HOOKS */ 60 61 static inline bool lmkd_update_props_hook() { return true; } 62 static inline bool lmkd_init_hook() { return true; } 63 static inline int lmkd_free_memory_before_kill_hook(struct proc*, int, int, 64 int) { 65 return 0; 66 } 67 static inline void lmkd_no_kill_candidates_hook() {} 68 69 #endif /* LMKD_USE_HOOKS */ 70 71 __END_DECLS 72 73 #endif 74