This repository has been archived by the owner on Oct 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 522
/
libkdump.h
120 lines (94 loc) · 3.27 KB
/
libkdump.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
#ifndef _LIBKDUMP_H_
#define _LIBKDUMP_H_
#include <stdint.h>
#include <stdio.h>
#if !(defined(__x86_64__) || defined(__i386__))
# error x86-64 and i386 are the only supported architectures
#endif
#ifdef __x86_64__
#define DEFAULT_PHYSICAL_OFFSET 0xffff880000000000ull
#else
#define DEFAULT_PHYSICAL_OFFSET 0xc0000000ull
#endif
/**
* libkdump exception handling
*/
typedef enum {
SIGNAL_HANDLER, /**< Install a signal handler to catch SIGSEGV */
TSX /**< Use Intel TSX to suppress exception */
} libkdump_fault_handling_t;
/**
* libkdump load thread action
*/
typedef enum {
NOP, /**< Just run an endless loop */
IO, /**< Perform I/O operations to trigger interrupts */
YIELD /**< Continuously switch to the operating system */
} libkdump_load_t;
/**
* libkdump configuration
*/
typedef struct {
size_t cache_miss_threshold; /**< Cache miss threshold in cycles for Flush Reload */
libkdump_fault_handling_t fault_handling; /**< Type of fault handling (TSX or signal handler) */
int measurements; /**< Number of measurements to perform for one address */
int accept_after; /**< How many measurements must be the same to accept the read value */
int load_threads; /**< Number of threads which are started to increase the chance of reading from inaccessible addresses */
libkdump_load_t load_type; /**< Function the load threads should execute */
int retries; /**< Number of Meltdown retries for an address */
size_t physical_offset; /**< Address of the physical direct map */
} libkdump_config_t;
extern libkdump_config_t libkdump_auto_config;
/**
* Initializes libkdump
*
* @param[in] configuration The configuration for libkdump, or 'libkdump_auto_config' for auto configuration.
*
* @return 0 Initialization was successful
* @return -1 Initialization failed, errno contains the error code
*/
int libkdump_init(const libkdump_config_t configuration);
/**
* Returns a config to be used with libkdump_init. All parameters are automatically configured to sane defaults.
*
* @return A libkdump configuration (libkdump_config_t)
*/
libkdump_config_t libkdump_get_autoconfig();
/**
* Reads one character from the given (virtual) address using Meltdown
*
* @param[in] addr The virtual address to read from
*
* @return The read character
*/
int libkdump_read(size_t addr);
/**
* Cleans up and reverts everything which was changed by libkdump.
*
* @return 0 Cleanup was successful
* @return -1 Cleanup failed, errno contains the error code
*/
int libkdump_cleanup();
/**
* Retrieves the physical address of a virtual address. Requires root (or read permissions for /proc/self/pagemap).
*
* @param[in] addr The virtual address to convert
*
* @return The physical address, or 0 if an error occurred (errno contains the error code)
*/
size_t libkdump_virt_to_phys(size_t addr);
/**
* Converts a physical address to a virtual address using the physical direct map offset.
*
* @param[in] addr The physical address to convert
*
* @return The virtual address, or -1ULL if an error occured.
*/
size_t libkdump_phys_to_virt(size_t addr);
/**
* Enables or disables the debug output of libkdump as required.
*
* @param[in] enable Enable (1) or disable (0) the debug output of libkdump. Default is disabled.
*/
void libkdump_enable_debug(int enable);
#endif