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" |
ab33e65c | 28 | |
4723ca09 | 29 | struct ustcomm_sock { |
aca1ad90 PMF |
30 | struct list_head list; |
31 | int fd; | |
4723ca09 | 32 | int epoll_fd; |
aca1ad90 PMF |
33 | }; |
34 | ||
4723ca09 | 35 | struct ustcomm_header { |
4723ca09 | 36 | int command; |
72098143 NC |
37 | long size; |
38 | int result; | |
4723ca09 | 39 | int fd_included; |
811e4b93 | 40 | }; |
aca1ad90 | 41 | |
72098143 NC |
42 | #define USTCOMM_BUFFER_SIZE ((1 << 12) - sizeof(struct ustcomm_header)) |
43 | ||
44 | /* Specify a sata size that leaves margin at the end of a buffer | |
45 | * in order to make sure that we never have more data than | |
46 | * will fit in the buffer AND that the last chars (due to a | |
47 | * pre-receive memset) will always be 0, terminating any string | |
48 | */ | |
49 | #define USTCOMM_DATA_SIZE (USTCOMM_BUFFER_SIZE - 20 * sizeof(void *)) | |
50 | ||
51 | enum tracectl_commands { | |
52 | ALLOC_TRACE, | |
53 | CONSUME_BUFFER, | |
54 | CREATE_TRACE, | |
55 | DESTROY_TRACE, | |
56 | DISABLE_MARKER, | |
57 | ENABLE_MARKER, | |
58 | EXIT, | |
59 | FORCE_SUBBUF_SWITCH, | |
60 | GET_BUF_SHMID_PIPE_FD, | |
61 | GET_PIDUNIQUE, | |
62 | GET_SOCK_PATH, | |
63 | GET_SUBBUFFER, | |
64 | GET_SUBBUF_NUM_SIZE, | |
65 | LIST_MARKERS, | |
66 | LIST_TRACE_EVENTS, | |
67 | LOAD_PROBE_LIB, | |
68 | NOTIFY_BUF_MAPPED, | |
69 | PRINT_MARKERS, | |
70 | PRINT_TRACE_EVENTS, | |
71 | PUT_SUBBUFFER, | |
72 | SETUP_TRACE, | |
73 | SET_SOCK_PATH, | |
74 | SET_SUBBUF_NUM, | |
75 | SET_SUBBUF_SIZE, | |
76 | START, | |
77 | START_TRACE, | |
78 | STOP_TRACE, | |
79 | }; | |
80 | ||
81 | struct ustcomm_channel_info { | |
82 | char *channel; | |
83 | unsigned int subbuf_size; | |
84 | unsigned int subbuf_num; | |
85 | char data[USTCOMM_DATA_SIZE]; | |
86 | }; | |
87 | ||
88 | struct ustcomm_buffer_info { | |
89 | char *channel; | |
90 | int ch_cpu; | |
91 | pid_t pid; | |
92 | int buf_shmid; | |
93 | int buf_struct_shmid; | |
94 | long consumed_old; | |
95 | char data[USTCOMM_DATA_SIZE]; | |
96 | }; | |
97 | ||
98 | struct ustcomm_marker_info { | |
99 | char *channel; | |
100 | char *marker; | |
101 | char data[USTCOMM_DATA_SIZE]; | |
102 | }; | |
103 | ||
104 | struct ustcomm_sock_path { | |
105 | char *sock_path; | |
106 | char data[USTCOMM_DATA_SIZE]; | |
107 | }; | |
108 | ||
109 | struct ustcomm_pidunique { | |
110 | s64 pidunique; | |
111 | }; | |
d0b5f2b9 | 112 | |
72098143 NC |
113 | struct ustcomm_notify_buf_mapped { |
114 | char data[USTCOMM_DATA_SIZE]; | |
115 | }; | |
b02e31e5 | 116 | |
4723ca09 NC |
117 | /* Ensure directory existence, usefull for unix sockets */ |
118 | extern int ensure_dir_exists(const char *dir); | |
0e4b45ac | 119 | |
4723ca09 NC |
120 | /* Create and delete sockets */ |
121 | extern struct ustcomm_sock * ustcomm_init_sock(int fd, int epoll_fd, | |
122 | struct list_head *list); | |
123 | extern void ustcomm_del_sock(struct ustcomm_sock *sock, int keep_in_epoll); | |
d0b5f2b9 | 124 | |
4723ca09 NC |
125 | /* Create and delete named sockets */ |
126 | extern struct ustcomm_sock * ustcomm_init_named_socket(const char *name, | |
127 | int epoll_fd); | |
128 | extern void ustcomm_del_named_sock(struct ustcomm_sock *sock, | |
129 | int keep_socket_file); | |
3847c3ba | 130 | |
4723ca09 NC |
131 | /* Send and receive functions for file descriptors */ |
132 | extern int ustcomm_send_fd(int sock, const struct ustcomm_header *header, | |
133 | const char *data, int *fd); | |
134 | extern int ustcomm_recv_fd(int sock, struct ustcomm_header *header, | |
72098143 | 135 | char *data, int *fd); |
d0b5f2b9 | 136 | |
4723ca09 NC |
137 | /* Normal send and receive functions */ |
138 | extern int ustcomm_send(int sock, const struct ustcomm_header *header, | |
139 | const char *data); | |
140 | extern int ustcomm_recv(int sock, struct ustcomm_header *header, | |
72098143 | 141 | char *data); |
f9e5ce61 | 142 | |
72098143 NC |
143 | /* Receive and allocate data, not to be used inside libust */ |
144 | extern int ustcomm_recv_alloc(int sock, | |
145 | struct ustcomm_header *header, | |
146 | char **data); | |
147 | ||
148 | /* Request function, send and receive */ | |
149 | extern int ustcomm_req(int sock, | |
150 | const struct ustcomm_header *req_header, | |
151 | const char *req_data, | |
152 | struct ustcomm_header *res_header, | |
153 | char *res_data); | |
3bb56863 | 154 | |
4723ca09 NC |
155 | extern int ustcomm_request_consumer(pid_t pid, const char *channel); |
156 | extern int ustcomm_connect_app(pid_t pid, int *app_fd); | |
157 | extern int ustcomm_connect_path(const char *path, int *connection_fd); | |
72098143 | 158 | |
7e92827d | 159 | extern int nth_token_is(const char *str, const char *token, int tok_no); |
b02e31e5 | 160 | |
7e92827d | 161 | extern char *nth_token(const char *str, int tok_no); |
b02e31e5 | 162 | |
72098143 NC |
163 | /* String serialising functions, printf straight into a buffer */ |
164 | #define USTCOMM_POISON_PTR (void *)0x19831018 | |
165 | ||
166 | extern char * ustcomm_print_data(char *data_field, int field_size, | |
167 | int *offset, const char *format, ...); | |
168 | extern char * ustcomm_restore_ptr(char *ptr, char *data_field, | |
169 | int data_field_size); | |
170 | ||
171 | #define COMPUTE_MSG_SIZE(struct_ptr, offset) \ | |
172 | (size_t) (long)(struct_ptr)->data - (long)(struct_ptr) + (offset) | |
173 | ||
174 | /* Packing and unpacking functions, making life easier */ | |
175 | extern int ustcomm_pack_channel_info(struct ustcomm_header *header, | |
176 | struct ustcomm_channel_info *ch_inf, | |
177 | const char *channel); | |
178 | ||
179 | extern int ustcomm_unpack_channel_info(struct ustcomm_channel_info *ch_inf); | |
180 | ||
181 | extern int ustcomm_pack_buffer_info(struct ustcomm_header *header, | |
182 | struct ustcomm_buffer_info *buf_inf, | |
183 | const char *channel, | |
184 | int channel_cpu); | |
185 | ||
186 | extern int ustcomm_unpack_buffer_info(struct ustcomm_buffer_info *buf_inf); | |
187 | ||
188 | extern int ustcomm_pack_marker_info(struct ustcomm_header *header, | |
189 | struct ustcomm_marker_info *marker_inf, | |
190 | const char *channel, | |
191 | const char *marker); | |
192 | ||
193 | extern int ustcomm_unpack_marker_info(struct ustcomm_marker_info *marker_inf); | |
194 | ||
195 | ||
196 | extern int ustcomm_pack_sock_path(struct ustcomm_header *header, | |
197 | struct ustcomm_sock_path *sock_path_inf, | |
198 | const char *socket_path); | |
199 | ||
200 | extern int ustcomm_unpack_sock_path(struct ustcomm_sock_path *sock_path_inf); | |
201 | ||
f9e5ce61 | 202 | #endif /* USTCOMM_H */ |