| 1 | |
| 2 | #include "marker.h" |
| 3 | #include <stdio.h> |
| 4 | #include <errno.h> |
| 5 | #include <sys/user.h> |
| 6 | |
| 7 | __attribute__ ((visibility ("protected"))) |
| 8 | extern struct marker __start___markers[]; |
| 9 | |
| 10 | __attribute__ ((visibility ("protected"))) |
| 11 | extern struct marker __stop___markers[]; |
| 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 | */ |
| 25 | __attribute__ ((visibility ("protected"))) |
| 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 | */ |
| 39 | __attribute__ ((visibility ("protected"))) |
| 40 | void marker_probe_cb(const struct marker *mdata, void *call_private, |
| 41 | const char *fmt, ...) |
| 42 | { |
| 43 | char buf[PAGE_SIZE]; |
| 44 | va_list ap; |
| 45 | |
| 46 | va_start(ap, fmt); |
| 47 | vsnprintf(buf, PAGE_SIZE-1, fmt, ap); |
| 48 | sys_trace(0, 0, buf); |
| 49 | va_end(ap); |
| 50 | } |
| 51 | |
| 52 | //FIXME : imv_read won't work with optimized immediate values. |
| 53 | //will need to issue one sys_marker call for each immediate value. |
| 54 | __attribute__ ((visibility ("protected"))) |
| 55 | void testip(void) |
| 56 | { |
| 57 | printf("addr : %p\n", __builtin_return_address(0)); |
| 58 | } |
| 59 | |
| 60 | __attribute__((constructor, visibility ("protected"))) |
| 61 | void marker_init(void) |
| 62 | { |
| 63 | struct marker *iter; |
| 64 | int ret; |
| 65 | |
| 66 | printf("Marker section : from %p to %p (init)\n", |
| 67 | __start___markers, __stop___markers); |
| 68 | testip(); |
| 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 | |
| 78 | __attribute__((destructor, visibility ("protected"))) |
| 79 | void marker_fini(void) |
| 80 | { |
| 81 | struct marker *iter; |
| 82 | int ret; |
| 83 | |
| 84 | printf("Marker section : from %p to %p (fini)\n", |
| 85 | __start___markers, __stop___markers); |
| 86 | for (iter = __start___markers; iter < __stop___markers; iter++) { |
| 87 | printf("Marker : %s\n", iter->name); |
| 88 | ret = sys_marker(iter->name, iter->format, |
| 89 | &imv_read(iter->state), 0); |
| 90 | if (ret) |
| 91 | perror("Error disconnecting markers"); |
| 92 | } |
| 93 | } |