Commit | Line | Data |
---|---|---|
c39c72ee PMF |
1 | /* Copyright (C) 2009 Pierre-Marc Fournier |
2 | * | |
3 | * This library is free software; you can redistribute it and/or | |
4 | * modify it under the terms of the GNU Lesser General Public | |
5 | * License as published by the Free Software Foundation; either | |
6 | * version 2.1 of the License, or (at your option) any later version. | |
7 | * | |
8 | * This library 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 GNU | |
11 | * Lesser General Public License for more details. | |
12 | * | |
13 | * You should have received a copy of the GNU Lesser General Public | |
14 | * License along with this library; if not, write to the Free Software | |
15 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
16 | */ | |
17 | ||
f9e5ce61 PMF |
18 | #ifndef USTCOMM_H |
19 | #define USTCOMM_H | |
20 | ||
21 | #include <sys/types.h> | |
b02e31e5 | 22 | #include <sys/un.h> |
22d9080d | 23 | #include <urcu/list.h> |
f9e5ce61 | 24 | |
17bb07b4 | 25 | #include <ust/kcompat/kcompat.h> |
aca1ad90 | 26 | |
397d8454 | 27 | #define SOCK_DIR "/tmp/ust-app-socks" |
1031eea2 NC |
28 | #define USER_TMP_DIR "/tmp" |
29 | #define USER_SOCK_DIR_BASE "ust-socks-" | |
30 | #define USER_SOCK_DIR USER_TMP_DIR "/" USER_SOCK_DIR_BASE | |
ab33e65c | 31 | |
4723ca09 | 32 | struct ustcomm_sock { |
0222e121 | 33 | struct cds_list_head list; |
aca1ad90 | 34 | int fd; |
4723ca09 | 35 | int epoll_fd; |
aca1ad90 PMF |
36 | }; |
37 | ||
4723ca09 | 38 | struct ustcomm_header { |
4723ca09 | 39 | int command; |
72098143 NC |
40 | long size; |
41 | int result; | |
4723ca09 | 42 | int fd_included; |
811e4b93 | 43 | }; |
aca1ad90 | 44 | |
72098143 NC |
45 | #define USTCOMM_BUFFER_SIZE ((1 << 12) - sizeof(struct ustcomm_header)) |
46 | ||
47 | /* Specify a sata size that leaves margin at the end of a buffer | |
48 | * in order to make sure that we never have more data than | |
49 | * will fit in the buffer AND that the last chars (due to a | |
50 | * pre-receive memset) will always be 0, terminating any string | |
51 | */ | |
52 | #define USTCOMM_DATA_SIZE (USTCOMM_BUFFER_SIZE - 20 * sizeof(void *)) | |
53 | ||
54 | enum tracectl_commands { | |
55 | ALLOC_TRACE, | |
56 | CONSUME_BUFFER, | |
57 | CREATE_TRACE, | |
58 | DESTROY_TRACE, | |
59 | DISABLE_MARKER, | |
60 | ENABLE_MARKER, | |
61 | EXIT, | |
62 | FORCE_SUBBUF_SWITCH, | |
63 | GET_BUF_SHMID_PIPE_FD, | |
64 | GET_PIDUNIQUE, | |
65 | GET_SOCK_PATH, | |
66 | GET_SUBBUFFER, | |
67 | GET_SUBBUF_NUM_SIZE, | |
68 | LIST_MARKERS, | |
69 | LIST_TRACE_EVENTS, | |
70 | LOAD_PROBE_LIB, | |
71 | NOTIFY_BUF_MAPPED, | |
72 | PRINT_MARKERS, | |
73 | PRINT_TRACE_EVENTS, | |
74 | PUT_SUBBUFFER, | |
75 | SETUP_TRACE, | |
76 | SET_SOCK_PATH, | |
77 | SET_SUBBUF_NUM, | |
78 | SET_SUBBUF_SIZE, | |
79 | START, | |
80 | START_TRACE, | |
81 | STOP_TRACE, | |
82 | }; | |
83 | ||
28c1bb40 NC |
84 | struct ustcomm_single_field { |
85 | char *field; | |
10f2b724 NC |
86 | char data[USTCOMM_DATA_SIZE]; |
87 | }; | |
88 | ||
72098143 | 89 | struct ustcomm_channel_info { |
d89b8191 | 90 | char *trace; |
72098143 NC |
91 | char *channel; |
92 | unsigned int subbuf_size; | |
93 | unsigned int subbuf_num; | |
94 | char data[USTCOMM_DATA_SIZE]; | |
95 | }; | |
96 | ||
97 | struct ustcomm_buffer_info { | |
d89b8191 | 98 | char *trace; |
72098143 NC |
99 | char *channel; |
100 | int ch_cpu; | |
101 | pid_t pid; | |
102 | int buf_shmid; | |
103 | int buf_struct_shmid; | |
104 | long consumed_old; | |
105 | char data[USTCOMM_DATA_SIZE]; | |
106 | }; | |
107 | ||
b521931e | 108 | struct ustcomm_ust_marker_info { |
d89b8191 | 109 | char *trace; |
72098143 | 110 | char *channel; |
b521931e | 111 | char *ust_marker; |
72098143 NC |
112 | char data[USTCOMM_DATA_SIZE]; |
113 | }; | |
114 | ||
72098143 NC |
115 | struct ustcomm_pidunique { |
116 | s64 pidunique; | |
117 | }; | |
d0b5f2b9 | 118 | |
72098143 NC |
119 | struct ustcomm_notify_buf_mapped { |
120 | char data[USTCOMM_DATA_SIZE]; | |
121 | }; | |
b02e31e5 | 122 | |
4723ca09 | 123 | /* Ensure directory existence, usefull for unix sockets */ |
304f67a5 | 124 | extern int ensure_dir_exists(const char *dir, mode_t mode); |
0e4b45ac | 125 | |
4723ca09 NC |
126 | /* Create and delete sockets */ |
127 | extern struct ustcomm_sock * ustcomm_init_sock(int fd, int epoll_fd, | |
0222e121 | 128 | struct cds_list_head *list); |
4723ca09 | 129 | extern void ustcomm_del_sock(struct ustcomm_sock *sock, int keep_in_epoll); |
d0b5f2b9 | 130 | |
4723ca09 NC |
131 | /* Create and delete named sockets */ |
132 | extern struct ustcomm_sock * ustcomm_init_named_socket(const char *name, | |
133 | int epoll_fd); | |
134 | extern void ustcomm_del_named_sock(struct ustcomm_sock *sock, | |
135 | int keep_socket_file); | |
3847c3ba | 136 | |
4723ca09 NC |
137 | /* Send and receive functions for file descriptors */ |
138 | extern int ustcomm_send_fd(int sock, const struct ustcomm_header *header, | |
139 | const char *data, int *fd); | |
140 | extern int ustcomm_recv_fd(int sock, struct ustcomm_header *header, | |
72098143 | 141 | char *data, int *fd); |
d0b5f2b9 | 142 | |
4723ca09 NC |
143 | /* Normal send and receive functions */ |
144 | extern int ustcomm_send(int sock, const struct ustcomm_header *header, | |
145 | const char *data); | |
146 | extern int ustcomm_recv(int sock, struct ustcomm_header *header, | |
72098143 | 147 | char *data); |
f9e5ce61 | 148 | |
72098143 NC |
149 | /* Receive and allocate data, not to be used inside libust */ |
150 | extern int ustcomm_recv_alloc(int sock, | |
151 | struct ustcomm_header *header, | |
152 | char **data); | |
153 | ||
154 | /* Request function, send and receive */ | |
155 | extern int ustcomm_req(int sock, | |
156 | const struct ustcomm_header *req_header, | |
157 | const char *req_data, | |
158 | struct ustcomm_header *res_header, | |
159 | char *res_data); | |
3bb56863 | 160 | |
4723ca09 | 161 | extern int ustcomm_request_consumer(pid_t pid, const char *channel); |
dbd75de7 NC |
162 | |
163 | /* Returns the current users socket directory, must be freed */ | |
164 | extern char *ustcomm_user_sock_dir(void); | |
0f79e1ef NC |
165 | |
166 | /* Get the st_m_time from proc*/ | |
167 | extern time_t ustcomm_pid_st_mtime(pid_t pid); | |
168 | ||
169 | /* Check that a socket is live */ | |
170 | extern int ustcomm_is_socket_live(char *sock_name, pid_t *read_pid); | |
171 | ||
4723ca09 NC |
172 | extern int ustcomm_connect_app(pid_t pid, int *app_fd); |
173 | extern int ustcomm_connect_path(const char *path, int *connection_fd); | |
72098143 | 174 | |
7e92827d | 175 | extern int nth_token_is(const char *str, const char *token, int tok_no); |
b02e31e5 | 176 | |
7e92827d | 177 | extern char *nth_token(const char *str, int tok_no); |
b02e31e5 | 178 | |
72098143 NC |
179 | /* String serialising functions, printf straight into a buffer */ |
180 | #define USTCOMM_POISON_PTR (void *)0x19831018 | |
181 | ||
182 | extern char * ustcomm_print_data(char *data_field, int field_size, | |
183 | int *offset, const char *format, ...); | |
184 | extern char * ustcomm_restore_ptr(char *ptr, char *data_field, | |
185 | int data_field_size); | |
186 | ||
187 | #define COMPUTE_MSG_SIZE(struct_ptr, offset) \ | |
188 | (size_t) (long)(struct_ptr)->data - (long)(struct_ptr) + (offset) | |
189 | ||
190 | /* Packing and unpacking functions, making life easier */ | |
28c1bb40 NC |
191 | extern int ustcomm_pack_single_field(struct ustcomm_header *header, |
192 | struct ustcomm_single_field *sf, | |
10f2b724 NC |
193 | const char *trace); |
194 | ||
28c1bb40 | 195 | extern int ustcomm_unpack_single_field(struct ustcomm_single_field *sf); |
10f2b724 | 196 | |
72098143 NC |
197 | extern int ustcomm_pack_channel_info(struct ustcomm_header *header, |
198 | struct ustcomm_channel_info *ch_inf, | |
d89b8191 | 199 | const char *trace, |
72098143 NC |
200 | const char *channel); |
201 | ||
202 | extern int ustcomm_unpack_channel_info(struct ustcomm_channel_info *ch_inf); | |
203 | ||
204 | extern int ustcomm_pack_buffer_info(struct ustcomm_header *header, | |
205 | struct ustcomm_buffer_info *buf_inf, | |
d89b8191 | 206 | const char *trace, |
72098143 NC |
207 | const char *channel, |
208 | int channel_cpu); | |
209 | ||
210 | extern int ustcomm_unpack_buffer_info(struct ustcomm_buffer_info *buf_inf); | |
211 | ||
b521931e MD |
212 | extern int ustcomm_pack_ust_marker_info(struct ustcomm_header *header, |
213 | struct ustcomm_ust_marker_info *ust_marker_inf, | |
d89b8191 | 214 | const char *trace, |
72098143 | 215 | const char *channel, |
b521931e | 216 | const char *ust_marker); |
72098143 | 217 | |
b521931e | 218 | extern int ustcomm_unpack_ust_marker_info(struct ustcomm_ust_marker_info *ust_marker_inf); |
72098143 | 219 | |
f9e5ce61 | 220 | #endif /* USTCOMM_H */ |