1 /*
2  * Copyright (C) 2023 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 "coverage-srv"
18 
19 #include "coverage.h"
20 
21 #include <lib/coverage/common/cov_shm.h>
22 #include <lib/tipc/tipc_srv.h>
23 #include <lk/err_ptr.h>
24 #include <trusty_log.h>
25 
26 static struct srv_state state;
27 
main(void)28 int main(void) {
29     int rc;
30     struct tipc_hset* hset;
31 
32     hset = tipc_hset_create();
33     if (IS_ERR(hset)) {
34         TLOGE("failed (%d) to create handle set\n", PTR_ERR(hset));
35         return PTR_ERR(hset);
36     }
37     state.hset = hset;
38 
39     list_initialize(&state.coverage_record_list);
40 
41     rc = cov_shm_alloc(&state.mailbox, MAX_NUM_APPS);
42     if (rc != NO_ERROR) {
43         TLOGE("failed to allocate shared memory for mailbox\n");
44         return ERR_NO_MEMORY;
45     }
46 
47     rc = coverage_aggregator_init(&state);
48     if (rc != NO_ERROR) {
49         TLOGE("failed (%d) to initialize coverage aggregator service\n", rc);
50         return rc;
51     }
52 
53     rc = coverage_client_init(&state);
54     if (rc != NO_ERROR) {
55         TLOGE("failed (%d) to initialize coverage client service\n", rc);
56         return rc;
57     }
58 
59     return tipc_run_event_loop(hset);
60 }
61