temporary workaround for derefs on arm32
[platform/upstream/bcc.git] / tools / dbus-message-type.c
1 #include <uapi/linux/ptrace.h>
2 #include <linux/sched.h>
3
4 #define DBUS_TYPE_OFFSET 1
5
6 typedef enum {
7   G_DBUS_MESSAGE_TYPE_INVALID,
8   G_DBUS_MESSAGE_TYPE_METHOD_CALL,
9   G_DBUS_MESSAGE_TYPE_METHOD_RETURN,
10   G_DBUS_MESSAGE_TYPE_ERROR,
11   G_DBUS_MESSAGE_TYPE_SIGNAL
12 } GDBusMessageType;
13
14 typedef enum {
15   G_DBUS_MESSAGE_FLAGS_NONE = 0,
16   G_DBUS_MESSAGE_FLAGS_NO_REPLY_EXPECTED = (1<<0),
17   G_DBUS_MESSAGE_FLAGS_NO_AUTO_START = (1<<1)
18 } GDBusMessageFlags;
19
20 typedef enum
21 {
22   G_DBUS_MESSAGE_BYTE_ORDER_BIG_ENDIAN    = 'B',
23   G_DBUS_MESSAGE_BYTE_ORDER_LITTLE_ENDIAN = 'l'
24 } GDBusMessageByteOrder;
25
26 struct GTypeInstance {
27         void *g_class;
28 };
29
30 struct GObject {
31         struct GTypeInstance g_type_instance;
32
33         volatile unsigned int ref_count;
34         void *qdata;
35 };
36
37 struct GHashTable {
38         int size;
39         int mod;
40         unsigned int mask;
41         int nnodes;
42         int noccupied;
43
44         void *keys;
45         void *hashes;
46         void *values;
47 };
48
49 struct GVariant {
50         void *type_info;
51         unsigned long size;
52
53         union {
54                 struct {
55                         void *bytes;
56                         const char *gconstpointer;
57                 } serialised;
58
59                 struct {
60                         struct GVariant **children;
61                         unsigned long n_children;
62                 } tree;
63         } content;
64
65         int state;
66         int ref_count;
67 };
68
69 struct GDBusMessage {
70         struct GObject parent_instance;
71         GDBusMessageType type;
72         GDBusMessageFlags flags;
73         bool locked;
74         GDBusMessageByteOrder byte_order;
75         unsigned char major_protocol_version;
76         unsigned int serial;
77         struct GHashTable *headers;
78         struct GVariant *body;
79 };
80
81 struct DBusString {
82         void *str;
83         int len;
84         unsigned int allocated;
85         unsigned int constant : 1;
86         unsigned int locked : 1;
87         unsigned int invalid : 1;
88         unsigned int align_offset : 3;
89 };
90
91 struct DBusHeaderFields {
92         int value_pos;
93 };
94
95 struct DBusHeader {
96         struct DBusString data;
97
98         struct DBusHeaderFields fields[9];
99
100         u32 padding;
101         u32 byte_order;
102         unsigned char protocol_version;
103 };
104
105 struct DBusMessage {
106         int refcount;
107         struct DBusHeader header;
108         struct DBusString body;
109
110         unsigned int locked : 1;
111
112         void * list;
113         long size_counter_delta;
114         int timeout_ms;
115
116         u32 changed_stamp : 21;
117         void *slot_list;
118
119         int generation;
120
121         int *unix_fds;
122
123         unsigned n_unix_fds;
124         unsigned n_unix_fds_allocated;
125
126         long unix_fd_counter_delta;
127
128         struct DBusString *signature;
129         struct DBusString *unique_sender;
130         size_t gvariant_body_last_offset;
131         size_t gvariant_body_last_pos;
132 };
133
134 struct data_t {
135         u32 pid;
136         char comm[TASK_COMM_LEN];
137 };
138
139 BPF_HASH(message, struct data_t, int);
140 BPF_HISTOGRAM(msg_type, int);
141
142 int g_get_message_type(struct pt_regs *ctx, void *conn, struct GDBusMessage *message) {
143         msg_type.increment(message->type);
144         return 0;
145 }
146
147 int dbus_get_message_type(struct pt_regs *ctx, void *conn, struct DBusMessage *message) {
148         bpf_trace_printk("dbus: %d\n", PT_REGS_RC(ctx));
149         return 0;
150 }
151
152 int message_type(struct pt_regs *ctx, void *conn, struct DBusMessage *message) {
153         char *addr = 0;
154         bpf_probe_read(&addr, sizeof(addr), (char*)message + offsetof(struct DBusMessage, header.data.str));
155         char type;
156         bpf_probe_read(&type, sizeof(type), addr + 1);
157         msg_type.increment(type);
158         return 0;
159 }