1 /* 2 * Copyright 2018 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 #ifndef _LIBLMKD_UTILS_H_ 18 #define _LIBLMKD_UTILS_H_ 19 20 #include <sys/cdefs.h> 21 #include <sys/types.h> 22 23 #include <lmkd.h> 24 25 __BEGIN_DECLS 26 27 /* 28 * Connects to lmkd process and returns socket handle. 29 * On success returns socket handle. 30 * On error, -1 is returned, and errno is set appropriately. 31 */ 32 int lmkd_connect(); 33 34 /* 35 * Registers a process with lmkd and sets its oomadj score. 36 * On success returns 0. 37 * On error, -1 is returned. 38 * In the case of error errno is set appropriately. 39 */ 40 int lmkd_register_proc(int sock, struct lmk_procprio *params); 41 42 /* 43 * Registers a batch of processes with lmkd and sets its oomadj score. 44 * On success returns 0. 45 * On error, -1 is returned. 46 * In the case of error errno is set appropriately. 47 */ 48 int lmkd_register_procs(int sock, struct lmk_procs_prio* params, const int proc_count); 49 50 /* 51 * Unregisters a process previously registered with lmkd. 52 * On success returns 0. 53 * On error, -1 is returned. 54 * In the case of error errno is set appropriately. 55 */ 56 int lmkd_unregister_proc(int sock, struct lmk_procremove *params); 57 58 enum update_props_result { 59 UPDATE_PROPS_SUCCESS, 60 UPDATE_PROPS_FAIL, 61 UPDATE_PROPS_SEND_ERR, 62 UPDATE_PROPS_RECV_ERR, 63 UPDATE_PROPS_FORMAT_ERR, 64 }; 65 66 /* 67 * Updates lmkd properties. 68 * In the case of ERR_SEND or ERR_RECV errno is set appropriately. 69 */ 70 enum update_props_result lmkd_update_props(int sock); 71 72 /* 73 * Creates memcg directory for given process. 74 * On success returns 0. 75 * -1 is returned if path creation failed. 76 * -2 is returned if tasks file open operation failed. 77 * -3 is returned if tasks file write operation failed. 78 * In the case of error errno is set appropriately. 79 */ 80 int create_memcg(uid_t uid, pid_t pid); 81 82 enum boot_completed_notification_result { 83 BOOT_COMPLETED_NOTIF_SUCCESS, 84 BOOT_COMPLETED_NOTIF_FAILS, 85 BOOT_COMPLETED_NOTIF_ALREADY_HANDLED, 86 BOOT_COMPLETED_NOTIF_SEND_ERR, 87 BOOT_COMPLETED_NOTIF_RECV_ERR, 88 BOOT_COMPLETED_NOTIF_FORMAT_ERR, 89 }; 90 91 /* 92 * Notify LMKD the device has finished booting up. 93 */ 94 enum boot_completed_notification_result lmkd_notify_boot_completed(int sock); 95 96 enum get_kill_count_err_result { 97 GET_KILL_COUNT_SEND_ERR = -1, 98 GET_KILL_COUNT_RECV_ERR = -2, 99 GET_KILL_COUNT_FORMAT_ERR = -3, 100 }; 101 102 /* 103 * Get the number of kills LMKD has performed. 104 * On success returns number of kills. 105 * On error, get_kill_count_err_result integer value. 106 */ 107 int lmkd_get_kill_count(int sock, struct lmk_getkillcnt* params); 108 109 __END_DECLS 110 111 #endif /* _LIBLMKD_UTILS_H_ */ 112