[FIX] race condition when use sspt_proc
[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 "sspt_file.h"
30
31 struct slot_manager;
32 struct task_struct;
33 struct pf_group;
34 struct sspt_filter;
35 struct sspt_ip;
36
37 /** Flags for sspt_*_uninstall() */
38 enum US_FLAGS {
39         US_UNREGS_PROBE,        /**< probes remove and disarm */
40         US_DISARM,              /**< probes disarm */
41         US_UNINSTALL            /**< probes remove from list install */
42 };
43
44 /**
45  * @struct sspt_proc
46  * @breaf Image of process for specified process
47  */
48 struct sspt_proc {
49         struct list_head list;          /**< For global process list */
50
51         /* sspt_file */
52         struct list_head file_head;     /**< For sspt_file */
53
54         pid_t tgid;                     /**< Thread group ID */
55         struct task_struct *leader;     /**< Ptr to the task leader */
56         struct mm_struct *__mm;
57         struct task_struct *__task;
58         struct slot_manager *sm;        /**< Ptr to the manager slot */
59
60         struct {
61                 unsigned after_exec:1;
62                 unsigned after_fork:1;
63         } suspect;
64
65         struct {
66                 struct mutex mtx;       /**< Mutex for filter list */
67                 struct list_head head;  /**< Filter head */
68         } filters;
69
70         unsigned first_install:1;       /**< Install flag */
71         struct sspt_feature *feature;   /**< Ptr to the feature */
72         atomic_t usage;
73
74         /* FIXME: for preload (remove those fields) */
75         unsigned long r_state_addr;     /**< address of r_state */
76         void *private_data;             /**< Process private data */
77 };
78
79 struct sspt_proc_cb {
80         void *(*priv_create)(struct sspt_proc *);
81         void (*priv_destroy)(struct sspt_proc *, void *);
82 };
83
84
85 struct list_head *sspt_proc_list(void);
86
87 struct sspt_proc *sspt_proc_by_task(struct task_struct *task);
88 struct sspt_proc *sspt_proc_get_by_task(struct task_struct *task);
89 struct sspt_proc *sspt_proc_get_by_task_or_new(struct task_struct *task);
90 struct sspt_proc *sspt_proc_get(struct sspt_proc *proc);
91 void sspt_proc_put(struct sspt_proc *proc);
92 void sspt_proc_cleanup(struct sspt_proc *proc);
93
94 void on_each_proc_no_lock(void (*func)(struct sspt_proc *, void *),
95                           void *data);
96 void on_each_proc(void (*func)(struct sspt_proc *, void *), void *data);
97
98 void sspt_proc_check_empty(void);
99
100 struct sspt_file *sspt_proc_find_file(struct sspt_proc *proc,
101                                       struct dentry *dentry);
102 struct sspt_file *sspt_proc_find_file_or_new(struct sspt_proc *proc,
103                                              struct dentry *dentry);
104 void sspt_proc_install_page(struct sspt_proc *proc, unsigned long page_addr);
105 void sspt_proc_install(struct sspt_proc *proc);
106 int sspt_proc_uninstall(struct sspt_proc *proc,
107                         struct task_struct *task,
108                         enum US_FLAGS flag);
109
110 int sspt_proc_get_files_by_region(struct sspt_proc *proc,
111                                   struct list_head *head,
112                                   unsigned long start, size_t len);
113 void sspt_proc_insert_files(struct sspt_proc *proc, struct list_head *head);
114
115 void sspt_proc_read_lock(void);
116 void sspt_proc_read_unlock(void);
117 void sspt_proc_write_lock(void);
118 void sspt_proc_write_unlock(void);
119
120 void sspt_proc_add_filter(struct sspt_proc *proc, struct pf_group *pfg);
121 void sspt_proc_del_filter(struct sspt_proc *proc, struct pf_group *pfg);
122 void sspt_proc_del_all_filters(struct sspt_proc *proc);
123 bool sspt_proc_is_filter_new(struct sspt_proc *proc, struct pf_group *pfg);
124
125 void sspt_proc_on_each_filter(struct sspt_proc *proc,
126                               void (*func)(struct sspt_filter *, void *),
127                               void *data);
128
129 void sspt_proc_on_each_ip(struct sspt_proc *proc,
130                           void (*func)(struct sspt_ip *, void *), void *data);
131
132 bool sspt_proc_is_send_event(struct sspt_proc *proc);
133
134 int sspt_proc_cb_set(struct sspt_proc_cb *cb);
135 void sspt_proc_priv_create(struct sspt_proc *proc);
136 void sspt_proc_priv_destroy(struct sspt_proc *proc);
137
138 void sspt_reset_proc(struct task_struct *task);
139 void sspt_change_leader(struct task_struct *prev, struct task_struct *next);
140 int sspt_proc_init(void);
141 void sspt_proc_uninit(void);
142
143
144 #endif /* __SSPT_PROC__ */