99c5a086 |
1 | |
2 | #include "marker.h" |
52204d63 |
3 | #include <stdio.h> |
c604f8bf |
4 | #include <errno.h> |
37fac847 |
5 | #include <sys/user.h> |
52204d63 |
6 | |
a010d844 |
7 | __attribute__ ((visibility ("protected"))) |
8 | extern struct marker __start___markers[]; |
9 | |
10 | __attribute__ ((visibility ("protected"))) |
11 | extern struct marker __stop___markers[]; |
99c5a086 |
12 | |
13 | /** |
14 | * __mark_empty_function - Empty probe callback |
15 | * @probe_private: probe private data |
16 | * @call_private: call site private data |
17 | * @fmt: format string |
18 | * @...: variable argument list |
19 | * |
20 | * Empty callback provided as a probe to the markers. By providing this to a |
21 | * disabled marker, we make sure the execution flow is always valid even |
22 | * though the function pointer change and the marker enabling are two distinct |
23 | * operations that modifies the execution flow of preemptible code. |
24 | */ |
20fd073e |
25 | __attribute__ ((visibility ("protected"))) |
99c5a086 |
26 | void __mark_empty_function(void *probe_private, void *call_private, |
27 | const char *fmt, va_list *args) |
28 | { |
29 | } |
30 | |
31 | /* |
32 | * marker_probe_cb Callback that prepares the variable argument list for probes. |
33 | * @mdata: pointer of type struct marker |
34 | * @call_private: caller site private data |
35 | * @fmt: format string |
36 | * @...: Variable argument list. |
37 | * |
38 | */ |
20fd073e |
39 | __attribute__ ((visibility ("protected"))) |
99c5a086 |
40 | void marker_probe_cb(const struct marker *mdata, void *call_private, |
41 | const char *fmt, ...) |
42 | { |
3c23bb5b |
43 | char buf[PAGE_SIZE]; |
44 | va_list ap; |
99c5a086 |
45 | |
3c23bb5b |
46 | va_start(ap, fmt); |
47 | vsnprintf(buf, PAGE_SIZE-1, fmt, ap); |
48 | sys_trace(0, 0, buf); |
49 | va_end(ap); |
99c5a086 |
50 | } |
52204d63 |
51 | |
b664a2ae |
52 | //FIXME : imv_read won't work with optimized immediate values. |
53 | //will need to issue one sys_marker call for each immediate value. |
20fd073e |
54 | __attribute__ ((visibility ("protected"))) |
55 | void testip(void) |
56 | { |
57 | printf("addr : %p\n", __builtin_return_address(0)); |
58 | } |
b664a2ae |
59 | |
a010d844 |
60 | __attribute__((constructor, visibility ("protected"))) |
61 | void marker_init(void) |
52204d63 |
62 | { |
63 | struct marker *iter; |
c604f8bf |
64 | int ret; |
52204d63 |
65 | |
b664a2ae |
66 | printf("Marker section : from %p to %p (init)\n", |
67 | __start___markers, __stop___markers); |
20fd073e |
68 | testip(); |
b664a2ae |
69 | for (iter = __start___markers; iter < __stop___markers; iter++) { |
70 | printf("Marker : %s\n", iter->name); |
71 | ret = sys_marker(iter->name, iter->format, |
72 | &imv_read(iter->state), 1); |
73 | if (ret) |
74 | perror("Error connecting markers"); |
75 | } |
76 | } |
77 | |
a010d844 |
78 | __attribute__((destructor, visibility ("protected"))) |
79 | void marker_fini(void) |
b664a2ae |
80 | { |
81 | struct marker *iter; |
82 | int ret; |
83 | |
84 | printf("Marker section : from %p to %p (fini)\n", |
52204d63 |
85 | __start___markers, __stop___markers); |
86 | for (iter = __start___markers; iter < __stop___markers; iter++) { |
87 | printf("Marker : %s\n", iter->name); |
b664a2ae |
88 | ret = sys_marker(iter->name, iter->format, |
89 | &imv_read(iter->state), 0); |
90 | if (ret) |
91 | perror("Error disconnecting markers"); |
52204d63 |
92 | } |
93 | } |