• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #pragma once
18 
19 #include <lib/coverage/common/cov_shm.h>
20 #include <lib/tipc/tipc_srv.h>
21 #include <lk/list.h>
22 #include <stddef.h>
23 #include <string.h>
24 #include <trusty/uuid.h>
25 
26 /* Assume we have no more than 64 TAs running at the same time */
27 #define MAX_NUM_APPS 64
28 
29 /**
30  * struct srv_state - global state of the coverage server
31  * @hset:                 handle set
32  * @coverage_record_list: list of coverage records
33  * @mailbox:              mailbox used to broadcast events
34  */
35 struct srv_state {
36     struct tipc_hset* hset;
37     /*
38      * TODO: A hash map would be nice. But we only have a list implementation
39      * that's readily available. It should be good enough though, since the list
40      * is short (<100) and lookups/insertions are very infrequent.
41      */
42     struct list_node coverage_record_list;
43     struct cov_shm mailbox;
44 };
45 
set_srv_state(struct tipc_port * port,struct srv_state * state)46 static inline void set_srv_state(struct tipc_port* port,
47                                  struct srv_state* state) {
48     port->priv = state;
49 }
50 
get_srv_state(const struct tipc_port * port)51 static inline struct srv_state* get_srv_state(const struct tipc_port* port) {
52     return (struct srv_state*)(port->priv);
53 }
54 
55 /**
56  * struct coverage_record - code coverage record about a given TA
57  * @node:       list node
58  * @uuid:       UUID of target TA
59  * @idx:        unique index assigned to this record and corresponding TA
60  * @data:       shared memory region holding the coverage record
61  * @record_len: length of coverage record within @data
62  */
63 struct coverage_record {
64     struct list_node node;
65     struct uuid uuid;
66     size_t ta_idx;
67     struct cov_shm data;
68     size_t record_len;
69 };
70 
71 
find_coverage_record(struct list_node * head,const struct uuid * uuid)72 static struct coverage_record* find_coverage_record(
73         struct list_node* head,
74         const struct uuid* uuid) {
75     struct coverage_record* record;
76 
77     list_for_every_entry(head, record, struct coverage_record, node) {
78         if (!memcmp(&record->uuid, uuid, sizeof(struct uuid))) {
79             return record;
80         }
81     }
82     return NULL;
83 }
84 
85 /**
86  * coverage_aggregator_init() - initialize coverage aggregator service
87  * @state: pointer to global &struct srv_state
88  *
89  * Return: 0 on success, negative error code on error
90  */
91 int coverage_aggregator_init(struct srv_state* state);
92 
93 /**
94  * coverage_client_init() - initialize coverage client service
95  * @state: pointer to global &struct srv_state
96  *
97  * Return: 0 on success, negative error code on error
98  */
99 int coverage_client_init(struct srv_state* state);
100