summaryrefslogtreecommitdiff
path: root/include/chromeos/memory_wipe.h
blob: cc3535a1ba354ffb58b0e3dac359050d89af8901 (plain)
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
/*
 * Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 *
 * Alternatively, this software may be distributed under the terms of the
 * GNU General Public License ("GPL") version 2 as published by the Free
 * Software Foundation.
 */

/*
 * Memory wipe library for easily set and exclude memory regions that need
 * to be cleared.
 *
 * The following methods must be called in order:
 *   memory_wipe_init
 *   memory_wipe_exclude
 *   memory_wipe_execute
 */

#ifndef CHROMEOS_MEMORY_WIPE_H_
#define CHROMEOS_MEMORY_WIPE_H_

#include <linux/types.h>

/* A node in a linked list of edges, each at position "pos". */
typedef struct memory_wipe_edge_t {
	struct memory_wipe_edge_t *next;
	uintptr_t pos;
} memory_wipe_edge_t;

/*
 * Data describing memory to wipe. Contains a linked list of edges between the
 * regions of memory to wipe and not wipe.
 */
typedef struct memory_wipe_t {
	memory_wipe_edge_t head;
} memory_wipe_t;

/*
 * Initializes the memory region that needs to be cleared.
 *
 * @param wipe		Wipe structure to initialize.
 */
void memory_wipe_init(memory_wipe_t *wipe);

/*
 * Adds a memory region to be cleared.
 *
 * @param wipe		Wipe structure to add the region to.
 * @param start		The start of the region.
 * @param end		The end of the region.
 */
void memory_wipe_add(memory_wipe_t *wipe, uintptr_t start, uintptr_t end);

/*
 * Subtracts a memory region.
 *
 * @param wipe		Wipe structure to subtract the region from.
 * @param start		The start of the region.
 * @param end		The end of the region.
 */
void memory_wipe_sub(memory_wipe_t *wipe, uintptr_t start, uintptr_t end);

/*
 * Executes the memory wipe.
 *
 * @param wipe		Wipe structure to execute.
 */
void memory_wipe_execute(memory_wipe_t *wipe);

#endif /* CHROMEOS_MEMORY_WIPE_H */