[FIX] warning in ktd_exit()
[kernel/swap-modules.git] / us_manager / sspt / sspt_proc.h
1 #ifndef __SSPT_PROC__
2 #define __SSPT_PROC__
3
4 /**
5  * @file us_manager/sspt/sspt_proc.h
6  * @author Vyacheslav Cherkashin <v.cherkashin@samsung.com>
7  *
8  * @section LICENSE
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * @section COPYRIGHT
24  * Copyright (C) Samsung Electronics, 2013
25  */
26
27 #include <linux/types.h>
28 #include <linux/mutex.h>
29 #include <linux/rwsem.h>
30 #include "sspt_file.h"
31
32 struct slot_manager;
33 struct task_struct;
34 struct pf_group;
35 struct sspt_filter;
36 struct sspt_ip;
37
38 /** Flags for sspt_*_uninstall() */
39 enum US_FLAGS {
40         US_UNREGS_PROBE,        /**< probes remove and disarm */
41         US_DISARM,              /**< probes disarm */
42         US_UNINSTALL            /**< probes remove from list install */
43 };
44
45 /**
46  * @struct sspt_proc
47  * @breaf Image of process for specified process
48  */
49 struct sspt_proc {
50         struct list_head list;          /**< For global process list */
51
52         /* sspt_file */
53         struct {
54                 struct rw_semaphore sem;/**< Semaphore for files list */
55                 struct list_head head;  /**< For sspt_file */
56         } files;
57
58         pid_t tgid;                     /**< Thread group ID */
59         struct task_struct *leader;     /**< Ptr to the task leader */
60         struct mm_struct *__mm;
61         struct task_struct *__task;
62         struct slot_manager *sm;        /**< Ptr to the manager slot */
63
64         struct {
65                 unsigned after_exec:1;
66                 unsigned after_fork:1;
67         } suspect;
68
69         struct {
70                 struct mutex mtx;       /**< Mutex for filter list */
71                 struct list_head head;  /**< Filter head */
72         } filters;
73
74         unsigned first_install:1;       /**< Install flag */
75         struct sspt_feature *feature;   /**< Ptr to the feature */
76         atomic_t usage;
77
78         /* FIXME: for preload (remove those fields) */
79         unsigned long r_state_addr;     /**< address of r_state */
80         void *private_data;             /**< Process private data */
81 };
82
83 struct sspt_proc_cb {
84         void *(*priv_create)(struct sspt_proc *);
85         void (*priv_destroy)(struct sspt_proc *, void *);
86 };
87
88
89 struct list_head *sspt_proc_list(void);
90
91 struct sspt_proc *sspt_proc_by_task(struct task_struct *task);
92 struct sspt_proc *sspt_proc_get_by_task(struct task_struct *task);
93 struct sspt_proc *sspt_proc_get_by_task_or_new(struct task_struct *task);
94 struct sspt_proc *sspt_proc_get(struct sspt_proc *proc);
95 void sspt_proc_put(struct sspt_proc *proc);
96 void sspt_proc_cleanup(struct sspt_proc *proc);
97
98 void on_each_proc_no_lock(void (*func)(struct sspt_proc *, void *),
99                           void *data);
100 void on_each_proc(void (*func)(struct sspt_proc *, void *), void *data);
101
102 void sspt_proc_check_empty(void);
103
104 struct sspt_file *sspt_proc_find_file(struct sspt_proc *proc,
105                                       struct dentry *dentry);
106 struct sspt_file *sspt_proc_find_file_or_new(struct sspt_proc *proc,
107                                              struct dentry *dentry);
108 void sspt_proc_install_page(struct sspt_proc *proc, unsigned long page_addr);
109 void sspt_proc_install(struct sspt_proc *proc);
110 int sspt_proc_uninstall(struct sspt_proc *proc,
111                         struct task_struct *task,
112                         enum US_FLAGS flag);
113
114 int sspt_proc_get_files_by_region(struct sspt_proc *proc,
115                                   struct list_head *head,
116                                   unsigned long start, size_t len);
117 void sspt_proc_insert_files(struct sspt_proc *proc, struct list_head *head);
118
119 void sspt_proc_read_lock(void);
120 void sspt_proc_read_unlock(void);
121 void sspt_proc_write_lock(void);
122 void sspt_proc_write_unlock(void);
123
124 void sspt_proc_add_filter(struct sspt_proc *proc, struct pf_group *pfg);
125 void sspt_proc_del_filter(struct sspt_proc *proc, struct pf_group *pfg);
126 void sspt_proc_del_all_filters(struct sspt_proc *proc);
127 bool sspt_proc_is_filter_new(struct sspt_proc *proc, struct pf_group *pfg);
128
129 void sspt_proc_on_each_filter(struct sspt_proc *proc,
130                               void (*func)(struct sspt_filter *, void *),
131                               void *data);
132
133 void sspt_proc_on_each_ip(struct sspt_proc *proc,
134                           void (*func)(struct sspt_ip *, void *), void *data);
135
136 bool sspt_proc_is_send_event(struct sspt_proc *proc);
137
138 int sspt_proc_cb_set(struct sspt_proc_cb *cb);
139 void sspt_proc_priv_create(struct sspt_proc *proc);
140 void sspt_proc_priv_destroy(struct sspt_proc *proc);
141
142 void sspt_change_leader(struct task_struct *prev, struct task_struct *next);
143 int sspt_proc_init(void);
144 void sspt_proc_uninit(void);
145
146
147 #endif /* __SSPT_PROC__ */