1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #define TLOG_TAG "metrics-test-crasher"
18 
19 #include <lib/tipc/tipc_srv.h>
20 #include <lk/err_ptr.h>
21 #include <metrics_test_crasher_consts.h>
22 #include <stdlib.h>
23 #include <trusty_log.h>
24 #include <uapi/err.h>
25 
26 static struct tipc_port_acl crasher_port_acl = {
27         .flags = IPC_PORT_ALLOW_NS_CONNECT,
28 };
29 
30 static struct tipc_port crasher_port = {
31         .name = METRICS_TEST_CRAHSER_PORT,
32         .msg_max_size = 1024,
33         .msg_queue_len = 1,
34         .acl = &crasher_port_acl,
35 };
36 
on_message(const struct tipc_port * port,handle_t chan,void * ctx)37 static int on_message(const struct tipc_port* port, handle_t chan, void* ctx) {
38     /* Exit on any message received. */
39     exit(EXIT_FAILURE);
40     return 0;
41 }
42 
43 static struct tipc_srv_ops crasher_ops = {
44         .on_message = on_message,
45 };
46 
main(void)47 int main(void) {
48     int rc;
49     struct tipc_hset* hset;
50 
51     hset = tipc_hset_create();
52     if (IS_ERR(hset)) {
53         return PTR_ERR(hset);
54     }
55 
56     rc = tipc_add_service(hset, &crasher_port, 1, 0, &crasher_ops);
57     if (rc != NO_ERROR) {
58         return rc;
59     }
60 
61     return tipc_run_event_loop(hset);
62 }
63