Debian Codegraph @

runtime/transport/transport.h

raw
1 #ifndef _TRANSPORT_TRANSPORT_H_ /* -*- linux-c -*- */
2 #define _TRANSPORT_TRANSPORT_H_
3
4 /** @file transport.h
5 * @brief Header file for stp transport
6 */
7
8 #include "relay_compat.h"
9 #include "transport_msgs.h"
10
11 /* The size of print buffers. This limits the maximum */
12 /* amount of data a print can send. */
13 #define STP_BUFFER_SIZE 8192
14
15 /* STP_CTL_BUFFER_SIZE is the maximum size of a message */
16 /* exchanged on the control channel. */
17 #define STP_CTL_BUFFER_SIZE 384
18
19 static unsigned _stp_nsubbufs;
20 static unsigned _stp_subbuf_size;
21 static pid_t _stp_target;
22 static pid_t _stp_orig_target;
23
24 // flags to indicate choice of host filesystem for the relayfs
25 // pseudofiles; chosen within _stp_transport_fs_init
26 static unsigned procfs_p = 0;
27 static unsigned debugfs_p = 0;
28
29 static int _stp_transport_init(void);
30 static void _stp_transport_close(void);
31
32 static int _stp_lock_transport_dir(void);
33 static void _stp_unlock_transport_dir(void);
34
35 static struct dentry *_stp_debugfs_get_root_dir(void);
36 static void _stp_debugfs_remove_root_dir(void);
37
38 static struct dentry *_stp_get_module_dir(void);
39 static struct dentry *_stp_procfs_get_module_dir(void);
40 static struct dentry *_stp_debugfs_get_module_dir(void);
41
42 static int _stp_transport_fs_init(const char *module_name);
43 static void _stp_transport_fs_close(void);
44 static int _stp_debugfs_transport_fs_init(const char *module_name);
45 static void _stp_debugfs_transport_fs_close(void);
46 static int _stp_procfs_transport_fs_init(const char *module_name);
47 static void _stp_procfs_transport_fs_close(void);
48
49 static int __stp_debugfs_relay_remove_buf_file_callback(struct dentry *dentry);
50 static int __stp_procfs_relay_remove_buf_file_callback(struct dentry *dentry);
51 struct rchan_buf;
52 static struct dentry * __stp_debugfs_relay_create_buf_file_callback(const char *filename,
53 struct dentry *parent,
54 #ifdef STAPCONF_RELAY_UMODE_T
55 umode_t mode,
56 #else
57 int mode,
58 #endif
59 struct rchan_buf *buf,
60 int *is_global);
61 static struct dentry * __stp_procfs_relay_create_buf_file_callback(const char *filename,
62 struct dentry *parent,
63 #ifdef STAPCONF_RELAY_UMODE_T
64 umode_t mode,
65 #else
66 int mode,
67 #endif
68 struct rchan_buf *buf,
69 int *is_global);
70
71
72 static void _stp_attach(void);
73 static void _stp_detach(void);
74 static void _stp_handle_start(struct _stp_msg_start *st);
75 static int _stp_handle_kallsyms_lookups(void);
76
77 static uid_t _stp_uid;
78 static gid_t _stp_gid;
79
80 static atomic_t _stp_ctl_attached;
81
82 static int _stp_bufsize;
83
84
85 enum _stp_transport_state {
86 STP_TRANSPORT_STOPPED,
87 STP_TRANSPORT_INITIALIZED,
88 STP_TRANSPORT_RUNNING,
89 };
90
91 /*
92 * All transports must provide the following functions.
93 */
94
95 /*
96 * _stp_transport_get_state
97 *
98 * This function returns the current transport state.
99 */
100 static enum _stp_transport_state _stp_transport_get_state(void);
101
102 /*
103 * _stp_transport_data_fs_init
104 *
105 * This function allocates any buffers needed, creates files,
106 * etc. needed for this transport.
107 */
108 static int _stp_transport_data_fs_init(void);
109
110 /*
111 * _stp_transport_data_fs_start
112 *
113 * This function actually starts the transport.
114 */
115 static void _stp_transport_data_fs_start(void);
116
117 /*
118 * _stp_transport_data_fs_start
119 *
120 * This function stops the transport without doing any cleanup.
121 */
122 static void _stp_transport_data_fs_stop(void);
123
124 /*
125 * _stp_transport_data_fs_close
126 *
127 * This function cleans up items created by
128 * _stp_transport_data_fs_init().
129 */
130 static void _stp_transport_data_fs_close(void);
131
132 /*
133 * _stp_transport_data_fs_overwrite - set data overwrite mode
134 * overwrite: boolean
135 *
136 * When in overwrite mode and the transport buffers are full, older
137 * data gets overwritten.
138 */
139 static void _stp_transport_data_fs_overwrite(int overwrite);
140
141 /*
142 * _stp_data_write_reserve - reserve bytes
143 * size_request: number of bytes to reserve
144 * entry: allocated buffer is returned here
145 *
146 * This function attempts to reserve size_request number of bytes,
147 * returning the number of bytes actually reserved. The allocated
148 * buffer is returned in entry. Note that the number of bytes
149 * allocated may be less than the number of bytes requested.
150 */
151 static size_t _stp_data_write_reserve(size_t size_request, void **entry);
152
153
154 /*
155 * _stp_data_entry_data - return data pointer from entry
156 * entry: entry
157 *
158 * This function returns the data pointer from entry.
159 */
160 static unsigned char *_stp_data_entry_data(void *entry);
161
162 /*
163 * _stp_data_write_commit -
164 * entry: pointer returned by _stp-data_write_reserve()
165 *
166 * This function notifies the transport that the bytes in entry are
167 * ready to be written.
168 */
169 static int _stp_data_write_commit(void *entry);
170
171 #endif /* _TRANSPORT_TRANSPORT_H_ */