1 /*
2  * Copyright (c) 2016 GitHub, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef LIBBCC_USDT_H
17 #define LIBBCC_USDT_H
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 #include <stdint.h>
24 
25 void *bcc_usdt_new_frompid(int pid, const char *path);
26 void *bcc_usdt_new_frompath(const char *path);
27 void bcc_usdt_close(void *usdt);
28 
29 struct bcc_usdt {
30     const char *provider;
31     const char *name;
32     const char *bin_path;
33     // Virtual address semaphore is found at
34     uint64_t semaphore;
35     int num_locations;
36     int num_arguments;
37     // Offset from start of file where semaphore is at
38     uint64_t semaphore_offset;
39 };
40 
41 struct bcc_usdt_location {
42     uint64_t address;
43     const char *bin_path;
44 };
45 
46 #define BCC_USDT_ARGUMENT_NONE                0x0
47 #define BCC_USDT_ARGUMENT_CONSTANT            0x1
48 #define BCC_USDT_ARGUMENT_DEREF_OFFSET        0x2
49 #define BCC_USDT_ARGUMENT_DEREF_IDENT         0x4
50 #define BCC_USDT_ARGUMENT_BASE_REGISTER_NAME  0x8
51 #define BCC_USDT_ARGUMENT_INDEX_REGISTER_NAME 0x10
52 #define BCC_USDT_ARGUMENT_SCALE               0x20
53 
54 struct bcc_usdt_argument {
55     int size;
56     int valid;
57     long long constant;
58     int deref_offset;
59     const char *deref_ident;
60     const char *base_register_name;
61     const char *index_register_name;
62     int scale;
63 };
64 
65 typedef void (*bcc_usdt_cb)(struct bcc_usdt *);
66 void bcc_usdt_foreach(void *usdt, bcc_usdt_cb callback);
67 int bcc_usdt_get_location(void *usdt, const char *provider_name,
68                           const char *probe_name,
69                           int index, struct bcc_usdt_location *location);
70 int bcc_usdt_get_argument(void *usdt, const char *provider_name,
71                           const char *probe_name,
72                           int location_index, int argument_index,
73                           struct bcc_usdt_argument *argument);
74 
75 int bcc_usdt_enable_probe(void *, const char *, const char *);
76 int bcc_usdt_addsem_probe(void *, const char *, const char *, int16_t);
77 #define BCC_USDT_HAS_FULLY_SPECIFIED_PROBE
78 int bcc_usdt_enable_fully_specified_probe(void *, const char *, const char *,
79                                           const char *);
80 int bcc_usdt_addsem_fully_specified_probe(void *, const char *, const char *,
81                                           const char *, int16_t);
82 const char *bcc_usdt_genargs(void **ctx_array, int len);
83 const char *bcc_usdt_get_probe_argctype(
84   void *ctx, const char* probe_name, const int arg_index
85 );
86 const char *bcc_usdt_get_fully_specified_probe_argctype(
87   void *ctx, const char* provider_name, const char* probe_name, const int arg_index
88 );
89 
90 typedef void (*bcc_usdt_uprobe_cb)(const char *, const char *, uint64_t, int);
91 void bcc_usdt_foreach_uprobe(void *usdt, bcc_usdt_uprobe_cb callback);
92 
93 #ifdef __cplusplus
94 }
95 #endif
96 #endif
97