|
| 1 | +// SPDX-License-Identifier: BSD-3-Clause |
| 2 | +/* Copyright 2018-2021, Intel Corporation */ |
| 3 | + |
| 4 | +/* |
| 5 | + * ctl_debug.c -- implementation of the debug CTL namespace |
| 6 | + */ |
| 7 | + |
| 8 | +#include "ctl.h" |
| 9 | +#include "ctl_debug.h" |
| 10 | + |
| 11 | +static struct ctl* ctl_debug; |
| 12 | + |
| 13 | +static int alloc_pattern = 0; |
| 14 | + |
| 15 | +struct ctl* get_debug_ctl(void) { |
| 16 | + return ctl_debug; |
| 17 | +} |
| 18 | + |
| 19 | +/* |
| 20 | + * CTL_WRITE_HANDLER(alloc_pattern) -- sets the alloc_pattern field in heap |
| 21 | + */ |
| 22 | +static int |
| 23 | +CTL_WRITE_HANDLER(alloc_pattern, )(void *ctx, |
| 24 | + enum ctl_query_source source, void *arg, struct ctl_indexes *indexes) |
| 25 | +{ |
| 26 | + /* suppress unused-parameter errors */ |
| 27 | + (void)source, (void)indexes, (void)ctx; |
| 28 | + |
| 29 | + int arg_in = *(int *)arg; |
| 30 | + alloc_pattern = arg_in; |
| 31 | + return 0; |
| 32 | +} |
| 33 | + |
| 34 | +/* |
| 35 | + * CTL_READ_HANDLER(alloc_pattern) -- returns alloc_pattern heap field |
| 36 | + */ |
| 37 | +static int |
| 38 | +CTL_READ_HANDLER(alloc_pattern, )(void *ctx, |
| 39 | + enum ctl_query_source source, void *arg, struct ctl_indexes *indexes) |
| 40 | +{ |
| 41 | + /* suppress unused-parameter errors */ |
| 42 | + (void)source, (void)indexes, (void)ctx; |
| 43 | + |
| 44 | + int *arg_out = arg; |
| 45 | + *arg_out = alloc_pattern; |
| 46 | + return 0; |
| 47 | +} |
| 48 | + |
| 49 | +static const struct ctl_argument CTL_ARG(alloc_pattern) = CTL_ARG_LONG_LONG; |
| 50 | + |
| 51 | +static const struct ctl_node CTL_NODE(heap, )[] = { |
| 52 | + CTL_LEAF_RW(alloc_pattern), |
| 53 | + |
| 54 | + CTL_NODE_END |
| 55 | +}; |
| 56 | + |
| 57 | +static const struct ctl_node CTL_NODE(debug, )[] = { |
| 58 | + CTL_CHILD(heap, ), |
| 59 | + |
| 60 | + CTL_NODE_END |
| 61 | +}; |
| 62 | + |
| 63 | +/* |
| 64 | + * debug_ctl_register -- registers ctl nodes for "debug" module |
| 65 | + */ |
| 66 | +void |
| 67 | +debug_ctl_register(struct ctl *ctl) |
| 68 | +{ |
| 69 | + CTL_REGISTER_MODULE(ctl, debug); |
| 70 | +} |
| 71 | + |
| 72 | +void initialize_debug_ctl(void) { |
| 73 | + ctl_debug = ctl_new(); |
| 74 | + debug_ctl_register(ctl_debug); |
| 75 | +} |
| 76 | + |
| 77 | +void deinitialize_debug_ctl(void) { |
| 78 | + ctl_delete(ctl_debug); |
| 79 | +} |
0 commit comments