1 /*
2 * Copyright Meta Platforms, Inc. and its affiliates.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <errno.h>
8 #include <debug/coredump.h>
9
10 static int error;
11 static bool is_valid;
12
coredump_empty_backend_start(void)13 static void coredump_empty_backend_start(void)
14 {
15 /* Reset error, is_valid */
16 error = 0;
17 is_valid = false;
18 }
19
coredump_empty_backend_end(void)20 static void coredump_empty_backend_end(void)
21 {
22 is_valid = true;
23 }
24
coredump_empty_backend_buffer_output(uint8_t * buf,size_t buflen)25 static void coredump_empty_backend_buffer_output(uint8_t *buf, size_t buflen)
26 {
27 /* no-op */
28 }
29
coredump_empty_backend_query(enum coredump_query_id query_id,void * arg)30 static int coredump_empty_backend_query(enum coredump_query_id query_id,
31 void *arg)
32 {
33 int ret;
34
35 switch (query_id) {
36 case COREDUMP_QUERY_GET_ERROR:
37 ret = error;
38 break;
39 case COREDUMP_QUERY_HAS_STORED_DUMP:
40 ret = 0;
41 if (is_valid) {
42 ret = 1;
43 }
44 break;
45 default:
46 ret = -ENOTSUP;
47 break;
48 }
49
50 return ret;
51 }
52
coredump_empty_backend_cmd(enum coredump_cmd_id cmd_id,void * arg)53 static int coredump_empty_backend_cmd(enum coredump_cmd_id cmd_id,
54 void *arg)
55 {
56 int ret;
57
58 switch (cmd_id) {
59 case COREDUMP_CMD_CLEAR_ERROR:
60 error = 0;
61 ret = 0;
62 break;
63 case COREDUMP_CMD_VERIFY_STORED_DUMP:
64 ret = 0;
65 if (is_valid) {
66 ret = 1;
67 }
68 break;
69 default:
70 ret = -ENOTSUP;
71 break;
72 }
73
74 return ret;
75 }
76
77 struct coredump_backend_api coredump_backend_other = {
78 .start = coredump_empty_backend_start,
79 .end = coredump_empty_backend_end,
80 .buffer_output = coredump_empty_backend_buffer_output,
81 .query = coredump_empty_backend_query,
82 .cmd = coredump_empty_backend_cmd,
83 };
84