2 * Copyright (c) 2015, The Linux Foundation. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 #ifndef __SEEMP_LOGK_STUB__
14 #define __SEEMP_LOGK_STUB__
16 #ifdef CONFIG_SEEMP_CORE
17 #include <linux/kernel.h>
19 #define MAX_BUF_SIZE 188
21 #define SEEMP_LOGK_API_SIZE sizeof(int)
23 /* Write: api_id + skip encoding byte + params */
24 #define SEEMP_LOGK_RECORD(api_id, format, ...) do { \
25 *((int *)(buf - SEEMP_LOGK_API_SIZE)) = api_id; \
26 snprintf(buf + 1, MAX_BUF_SIZE - 1, format, ##__VA_ARGS__); \
29 extern void *(*seemp_logk_kernel_begin)(char **buf);
30 extern void (*seemp_logk_kernel_end)(void *blck);
32 static inline void *seemp_setup_buf(char **buf)
36 if (seemp_logk_kernel_begin && seemp_logk_kernel_end) {
37 blck = seemp_logk_kernel_begin(buf);
39 seemp_logk_kernel_end(blck);
48 * NOTE: only sendto is going to be instrumented
49 * since send sys call internally calls sendto
50 * with 2 extra parameters
52 static inline void seemp_logk_sendto(int fd, void __user *buff, size_t len,
53 unsigned flags, struct sockaddr __user *addr, int addr_len)
58 /*sets up buf and blck correctly*/
59 blck = seemp_setup_buf(&buf);
64 SEEMP_LOGK_RECORD(SEEMP_API_kernel__sendto, "len=%u,fd=%d",
65 (unsigned int)len, fd);
67 seemp_logk_kernel_end(blck);
71 * NOTE: only recvfrom is going to be instrumented
72 * since recv sys call internally calls recvfrom
73 * with 2 extra parameters
75 static inline void seemp_logk_recvfrom(int fd, void __user *ubuf,
76 size_t size, unsigned flags, struct sockaddr __user *addr,
82 /*sets up buf and blck correctly*/
83 blck = seemp_setup_buf(&buf);
88 SEEMP_LOGK_RECORD(SEEMP_API_kernel__recvfrom, "size=%u,fd=%d",
89 (unsigned int)size, fd);
91 seemp_logk_kernel_end(blck);
94 static inline void seemp_logk_oom_adjust_write(pid_t pid,
95 kuid_t uid, int oom_adj)
100 /*sets up buf and blck correctly*/
101 blck = seemp_setup_buf(&buf);
106 SEEMP_LOGK_RECORD(SEEMP_API_kernel__oom_adjust_write,
107 "app_uid=%d,app_pid=%d,oom_adj=%d",
108 uid.val, pid, oom_adj);
110 seemp_logk_kernel_end(blck);
113 static inline void seemp_logk_oom_score_adj_write(pid_t pid, kuid_t uid,
119 /*sets up buf and blck correctly*/
120 blck = seemp_setup_buf(&buf);
125 snprintf(buf, MAX_BUF_SIZE,
126 "-1|kernel|oom_score_adj_write|app_uid=%d,app_pid=%d,oom_adj=%d|--end",
127 uid.val, pid, oom_adj_score);
129 seemp_logk_kernel_end(blck);
133 static inline void seemp_logk_sendto(int fd, void __user *buff,
134 size_t len, unsigned flags, struct sockaddr __user *addr,
139 static inline void seemp_logk_recvfrom
140 (int fd, void __user *ubuf, size_t size,
141 unsigned flags, struct sockaddr __user *addr,
142 int __user *addr_len)
146 static inline void seemp_logk_oom_adjust_write
147 (pid_t pid, kuid_t uid, int oom_adj)
151 static inline void seemp_logk_oom_score_adj_write
152 (pid_t pid, kuid_t uid, int oom_adj_score)