1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 1994, by Sun Microsytems, Inc.
*/
#ifndef _TNFCTL_H
#define _TNFCTL_H
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/types.h>
#include <gelf.h>
#ifdef __cplusplus
extern "C" {
#endif
#define TNFCTL_LIBTNFPROBE "libtnfprobe.so.1"
/*
* data model dependent defs
*/
#if defined(_LP64)
#define ELF3264_R_SYM GELF_R_SYM
typedef GElf_Shdr Elf3264_Shdr;
typedef GElf_Dyn Elf3264_Dyn;
typedef GElf_Sword Elf3264_Sword;
typedef GElf_Sym Elf3264_Sym;
typedef GElf_Word Elf3264_Word;
typedef GElf_Addr Elf3264_Addr;
typedef GElf_Rela Elf3264_Rela;
typedef GElf_Rel Elf3264_Rel;
#else
#define ELF3264_R_SYM ELF32_R_SYM
typedef Elf32_Shdr Elf3264_Shdr;
typedef Elf32_Dyn Elf3264_Dyn;
typedef Elf32_Sword Elf3264_Sword;
typedef Elf32_Sym Elf3264_Sym;
typedef Elf32_Word Elf3264_Word;
typedef Elf32_Addr Elf3264_Addr;
typedef Elf32_Rela Elf3264_Rela;
typedef Elf32_Rel Elf3264_Rel;
#endif
/*
* Opaque tnfctl handle
*/
typedef struct tnfctl_handle tnfctl_handle_t;
/*
* Opaque probe handle
*/
typedef struct tnfctl_probe_handle tnfctl_probe_t;
/*
* Trace attributes and probe state
*/
typedef enum {
TNFCTL_BUF_OK,
TNFCTL_BUF_NONE,
TNFCTL_BUF_BROKEN
} tnfctl_bufstate_t;
typedef struct tnfctl_trace_attrs {
pid_t targ_pid; /* user process only */
const char *trace_file_name; /* user process only */
size_t trace_buf_size;
size_t trace_min_size;
tnfctl_bufstate_t trace_buf_state;
boolean_t trace_state;
boolean_t filter_state; /* kernel mode only */
long pad;
} tnfctl_trace_attrs_t;
typedef struct tnfctl_probe_state {
ulong_t id;
const char *attr_string;
boolean_t enabled;
boolean_t traced;
boolean_t new_probe;
const char *obj_name; /* user process only */
const char * const *func_names; /* array of func names ptrs */
const uintptr_t *func_addrs; /* array of func addresses */
void *client_registered_data;
long pad;
} tnfctl_probe_state_t;
/*
* error codes
*/
typedef enum {
TNFCTL_ERR_NONE = 0, /* success */
TNFCTL_ERR_ACCES, /* permission denied */
TNFCTL_ERR_NOTARGET, /* target process finished */
TNFCTL_ERR_ALLOCFAIL, /* memory allocation failure */
TNFCTL_ERR_INTERNAL, /* internal error */
TNFCTL_ERR_SIZETOOSMALL, /* requested trace size is too small */
TNFCTL_ERR_SIZETOOBIG, /* requested trace size is too big */
TNFCTL_ERR_BADARG, /* Bad Input Argument */
TNFCTL_ERR_NOTDYNAMIC, /* Target is not a dynamic executable */
TNFCTL_ERR_NOLIBTNFPROBE, /* libtnfprobe not linked in target */
TNFCTL_ERR_BUFBROKEN, /* tracing broken */
TNFCTL_ERR_BUFEXISTS, /* buffer already exists */
TNFCTL_ERR_NOBUF, /* no buffer */
TNFCTL_ERR_BADDEALLOC, /* can't deallocate buffer */
TNFCTL_ERR_NOPROCESS, /* no such target process */
TNFCTL_ERR_FILENOTFOUND, /* file not found */
TNFCTL_ERR_BUSY, /* kernel/process already tracing */
TNFCTL_ERR_INVALIDPROBE, /* probe no longer valid (dlclos'ed) */
TNFCTL_ERR_USR1, /* error extensions - semantics */
TNFCTL_ERR_USR2, /* set by user */
TNFCTL_ERR_USR3,
TNFCTL_ERR_USR4,
TNFCTL_ERR_USR5
} tnfctl_errcode_t;
/*
* event codes
*/
typedef enum {
TNFCTL_EVENT_EINTR, /* target was interrupted by a signal */
TNFCTL_EVENT_TARGGONE, /* target finished - did not call exit */
TNFCTL_EVENT_DLOPEN, /* target did a dlopen */
TNFCTL_EVENT_DLCLOSE, /* target did a dlclose */
TNFCTL_EVENT_EXEC, /* target did an exec */
TNFCTL_EVENT_FORK, /* target did a fork */
TNFCTL_EVENT_EXIT /* target called exit */
} tnfctl_event_t;
/*
* action to perform on target process
*/
typedef enum {
TNFCTL_TARG_DEFAULT, /* kills target if it was started with */
/* tnfctl_exec_open() */
TNFCTL_TARG_KILL, /* kills target */
TNFCTL_TARG_RESUME, /* target is let free */
TNFCTL_TARG_SUSPEND /* target is suspended */
} tnfctl_targ_op_t;
/*
* data structures needed when using tnfctl_indirect_open() interface i.e. for
* clients that will supply callback functions for inspecting target image.
*/
typedef struct tnfctl_ind_obj_info {
int objfd; /* -1 indicates fd not available */
uintptr_t text_base; /* address where text of loadobj was mapped */
uintptr_t data_base; /* address where data of loadobj was mapped */
const char *objname; /* null terminated full pathname to loadobj */
} tnfctl_ind_obj_info_t;
typedef int tnfctl_ind_obj_f(
void *, /* opaque prochandle */
const struct tnfctl_ind_obj_info *, /* info about this object */
void *); /* client supplied data */
typedef struct tnfctl_ind_config {
int (*p_read)(void *, uintptr_t, void *, size_t);
int (*p_write)(void *, uintptr_t, void *, size_t);
pid_t (*p_getpid)(void *);
int (*p_obj_iter)(void *, tnfctl_ind_obj_f *, void * /* client_data */);
} tnfctl_ind_config_t;
/*
* maps an errcode to a string
*/
const char *tnfctl_strerror(tnfctl_errcode_t);
/*
* interfaces to open a tnfctl handle
*/
tnfctl_errcode_t tnfctl_pid_open(
pid_t, /* pid */
tnfctl_handle_t **); /* return value */
tnfctl_errcode_t tnfctl_indirect_open(
void *, /* prochandle */
tnfctl_ind_config_t *, /* config */
tnfctl_handle_t **); /* return value */
tnfctl_errcode_t tnfctl_exec_open(
const char *, /* pgm name */
char * const *, /* argv */
char * const *, /* envp */
const char *, /* ld_preload */
const char *, /* libtnfprobe_path */
tnfctl_handle_t **); /* return value */
tnfctl_errcode_t tnfctl_internal_open(tnfctl_handle_t **);
tnfctl_errcode_t tnfctl_kernel_open(tnfctl_handle_t **);
/*
* direct mode - to continue process
*/
tnfctl_errcode_t tnfctl_continue(
tnfctl_handle_t *,
tnfctl_event_t *, /* return value - why did process stop ? */
tnfctl_handle_t **); /* return value - if fork, handle on child */
/*
* informs libtnfctl that libraries may have changed
*/
tnfctl_errcode_t tnfctl_check_libs(tnfctl_handle_t *);
/*
*
*/
tnfctl_errcode_t tnfctl_close(tnfctl_handle_t *, tnfctl_targ_op_t);
tnfctl_errcode_t tnfctl_trace_attrs_get(
tnfctl_handle_t *,
tnfctl_trace_attrs_t *);
tnfctl_errcode_t tnfctl_buffer_alloc(
tnfctl_handle_t *,
const char *, /* filename - ignored if kernel handle */
uint_t); /* buffer size */
/*
* kernel tracing only
*/
tnfctl_errcode_t tnfctl_buffer_dealloc(tnfctl_handle_t *);
tnfctl_errcode_t tnfctl_trace_state_set(tnfctl_handle_t *, boolean_t);
tnfctl_errcode_t tnfctl_filter_state_set(tnfctl_handle_t *, boolean_t);
tnfctl_errcode_t tnfctl_filter_list_get(tnfctl_handle_t *, pid_t **, int *);
tnfctl_errcode_t tnfctl_filter_list_add(tnfctl_handle_t *, pid_t);
tnfctl_errcode_t tnfctl_filter_list_delete(tnfctl_handle_t *, pid_t);
/*
* probe operation interface
*/
typedef tnfctl_errcode_t (*tnfctl_probe_op_t)(
tnfctl_handle_t *,
tnfctl_probe_t *, /* opaque probe handle */
void *); /* client supplied data */
tnfctl_errcode_t tnfctl_probe_apply(
tnfctl_handle_t *,
tnfctl_probe_op_t, /* func to apply to each of the probes */
void *); /* client data - arg to pass to func */
tnfctl_errcode_t tnfctl_probe_apply_ids(
tnfctl_handle_t *,
ulong_t, /* # of probe id's in array */
ulong_t *, /* array of probe id's */
tnfctl_probe_op_t, /* func to apply to each those probes */
void *); /* client data - arg to pass to func */
tnfctl_errcode_t tnfctl_register_funcs(
tnfctl_handle_t *,
void *(*)(tnfctl_handle_t *, tnfctl_probe_t *), /* create_func */
void (*)(void *)); /* destroy_func */
tnfctl_errcode_t tnfctl_probe_state_get(tnfctl_handle_t *, tnfctl_probe_t *,
tnfctl_probe_state_t *);
/*
* supplied probe functions that can be used with tnfctl_probe_apply()
* and tnfctl_probe_apply_ids(). last argument is ignored when it is "void *"
*/
tnfctl_errcode_t tnfctl_probe_enable(tnfctl_handle_t *, tnfctl_probe_t *,
void *);
tnfctl_errcode_t tnfctl_probe_disable(tnfctl_handle_t *, tnfctl_probe_t *,
void *);
tnfctl_errcode_t tnfctl_probe_trace(tnfctl_handle_t *, tnfctl_probe_t *,
void *);
tnfctl_errcode_t tnfctl_probe_untrace(tnfctl_handle_t *, tnfctl_probe_t *,
void *);
tnfctl_errcode_t tnfctl_probe_disconnect_all(tnfctl_handle_t *,
tnfctl_probe_t *, void *);
tnfctl_errcode_t tnfctl_probe_connect(
tnfctl_handle_t *,
tnfctl_probe_t *,
const char *, /* library base name */
const char *); /* function name */
#ifdef __cplusplus
}
#endif
#endif /* _TNFCTL_H */
|