forked from Fraunhofer-AISEC/archie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfault_list.h
120 lines (105 loc) · 3.43 KB
/
fault_list.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
* Copyright 2021 Florian Andreas Hauschild
* Copyright (c) 2021 Fraunhofer AISEC
* Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This file contains the headers for managing fault descriptions
*/
#ifndef FAULT_LIST
#define FAULT_LIST
#include <inttypes.h>
#include <stdlib.h>
typedef struct
{
uint64_t address; //uint64_t?
uint64_t hitcounter;
uint64_t trignum;
} fault_trigger_t;
typedef struct
{
uint64_t address; //uint64_t?
uint64_t type; //Typedef enum?
uint64_t model;
uint64_t lifetime;
uint8_t num_bytes; // Used by overwrite to find out how many bytes to overwrite
uint8_t mask[16]; // uint8_t array?
uint8_t restoremask[16];
fault_trigger_t trigger;
} fault_t;
typedef struct fault_list_t fault_list_t;
typedef struct fault_list_t
{
fault_list_t *next;
fault_t fault;
} fault_list_t;
void init_fault_list(void);
/**
* add fault
*
* This function appends one fault to the linked list.
*
* fault_address: address of fault
* fault_type: type of fault. see enum on implemented targets
* fault_model: model of fault. see enum on implemented fault models
* fault_lifetime: How long should the fault reside. 0 means indefinitely
* fault_mask: bit mask on which bits should be targeted.
* fault_trigger_address: Address of trigger location. Fault will be injected if this location is reached
* fault_trigger_hitcounter: set how many times the location needs to be reached before the fault is injected
* num_bytes: Used by overwrite to determen the number of bytes to overwrite
*
* return -1 if fault
*/
int add_fault(uint64_t fault_address, uint64_t fault_type, uint64_t fault_model, uint64_t fault_lifetime, uint8_t fault_mask[16], uint64_t fault_trigger_address, uint64_t fault_trigger_hitcounter, uint8_t num_bytes);
/**
*
* delete_fault_queue
*
* This function removes faults from linked list
*
*/
void delete_fault_queue(void);
/**
* return_first_fault
*
* This function exists to separate fault list management from the rest of the code base
*/
fault_list_t* return_first_fault(void);
/**
* return_next
*
* function to return next pointer.
* This is to be able to change the current link list if desired
*/
fault_list_t * return_next(fault_list_t * current);
/**
* get_fault_trigger_address
*
* function to return the fault address.
* This is to be able to change the current data structure if needed
*/
uint64_t get_fault_trigger_address(fault_list_t * current);
/**
* set_fault_trigger_num
*
* Function sets the trigger number field. This is done to separate between two triggers with the same address
*/
void set_fault_trigger_num(fault_list_t * current, uint64_t trignum);
/**
* get_fault_struct_by_trigger
*
* Function returns the corresponding fault to a trigger address and trigger number
*/
fault_list_t * get_fault_struct_by_trigger(uint64_t fault_trigger_address, uint64_t fault_trigger_number);
#endif