EXTRACT_SYMBOL(thread_return)
[ksplice.git] / kmodsrc / ksplice.h
blob3bbac699806b3e76957aefec70bbeb22691935cc
1 #include <linux/types.h>
3 /**
4 * struct ksplice_symbol - Ksplice's analogue of an ELF symbol
5 * @name: The ELF name of the symbol
6 * @label: A unique Ksplice name for the symbol
7 * @candidate_vals: A linked list of possible values for the symbol, or NULL
8 * @value: The value of the symbol (valid when vals is NULL)
9 **/
10 struct ksplice_symbol {
11 const char *name;
12 const char *label;
13 /* private: */
14 struct list_head *candidate_vals;
15 unsigned long value;
18 /**
19 * struct ksplice_reloc - Ksplice's analogue of an ELF relocation
20 * @blank_addr: The address of the relocation's storage unit
21 * @symbol: The ksplice_symbol associated with this relocation
22 * @howto: The information regarding the relocation type
23 * @addend: The ELF addend of the relocation
24 **/
25 struct ksplice_reloc {
26 unsigned long blank_addr;
27 struct ksplice_symbol *symbol;
28 const struct ksplice_reloc_howto *howto;
29 long insn_addend;
30 long target_addend;
33 enum ksplice_reloc_howto_type {
34 KSPLICE_HOWTO_RELOC,
35 KSPLICE_HOWTO_RELOC_PATCH,
36 KSPLICE_HOWTO_DATE,
37 KSPLICE_HOWTO_TIME,
38 KSPLICE_HOWTO_BUG,
39 KSPLICE_HOWTO_EXTABLE,
42 /**
43 * struct ksplice_reloc_howto - Ksplice's relocation type information
44 * @type: The type of the relocation
45 * @pcrel: Is the relocation PC relative?
46 * @size: The size, in bytes, of the item to be relocated
47 * @dst_mask: Bitmask for which parts of the instruction or data are
48 * replaced with the relocated value
49 * (based on dst_mask from GNU BFD's reloc_howto_struct)
50 * @rightshift: The value the final relocation is shifted right by;
51 * used to drop unwanted data from the relocation
52 * (based on rightshift from GNU BFD's reloc_howto_struct)
53 * @signed_addend: Should the addend be interpreted as a signed value?
54 **/
55 struct ksplice_reloc_howto {
56 enum ksplice_reloc_howto_type type;
57 int pcrel;
58 int size;
59 long dst_mask;
60 unsigned int rightshift;
61 int signed_addend;
64 #if BITS_PER_LONG == 32
65 #define KSPLICE_CANARY 0x77777777UL
66 #elif BITS_PER_LONG == 64
67 #define KSPLICE_CANARY 0x7777777777777777UL
68 #endif /* BITS_PER_LONG */
70 /**
71 * struct ksplice_section - Ksplice's analogue of an ELF section
72 * @symbol: The ksplice_symbol associated with this section
73 * @size: The length, in bytes, of this section
74 * @address: The address of the section
75 * @flags: Flags indicating the type of the section, whether or
76 * not it has been matched, etc.
77 **/
78 struct ksplice_section {
79 struct ksplice_symbol *symbol;
80 unsigned long address;
81 unsigned long size;
82 unsigned int flags;
83 const unsigned char **match_map;
85 #define KSPLICE_SECTION_TEXT 0x00000001
86 #define KSPLICE_SECTION_RODATA 0x00000002
87 #define KSPLICE_SECTION_DATA 0x00000004
88 #define KSPLICE_SECTION_STRING 0x00000008
89 #define KSPLICE_SECTION_MATCHED 0x10000000
91 #define MAX_TRAMPOLINE_SIZE 5
93 enum ksplice_patch_type {
94 KSPLICE_PATCH_TEXT,
95 KSPLICE_PATCH_DATA,
96 KSPLICE_PATCH_EXPORT,
99 /**
100 * struct ksplice_patch - A replacement that Ksplice should perform
101 * @oldaddr: The address of the obsolete function or structure
102 * @repladdr: The address of the replacement function
103 * @type: The type of the ksplice patch
104 * @size: The size of the patch
105 * @contents: The bytes to be installed at oldaddr
106 * @vaddr The address of the page mapping used to write at oldaddr
107 * @saved: The bytes originally at oldaddr which were
108 * overwritten by the patch
110 struct ksplice_patch {
111 unsigned long oldaddr;
112 unsigned long repladdr;
113 enum ksplice_patch_type type;
114 unsigned int size;
115 void *contents;
116 /* private: */
117 void *vaddr;
118 void *saved;
121 #ifdef KSPLICE_STANDALONE
122 struct ksplice_system_map {
123 const char *label;
124 unsigned long nr_candidates;
125 const unsigned long *candidates;
127 #endif /* KSPLICE_STANDALONE */
129 #ifdef __KERNEL__
130 #include <linux/module.h>
131 #include <linux/stringify.h>
132 #include <linux/version.h>
134 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
135 /* 6e21828743247270d09a86756a0c11702500dbfb was after 2.6.18 */
136 #define bool _Bool
137 #define false 0
138 #define true 1
139 #endif /* LINUX_VERSION_CODE */
141 #if defined(CONFIG_PARAVIRT) && defined(CONFIG_X86_64) && \
142 LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25) && \
143 LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
144 /* Linux 2.6.25 and 2.6.26 apply paravirt replacements to the core
145 * kernel but not modules on x86-64. If we are patching the core
146 * kernel, we need to apply the same replacements to our update
147 * modules in order for run-pre matching to succeed.
149 #define KSPLICE_NEED_PARAINSTRUCTIONS 1
150 #endif /* KSPLICE_NEED_PARAINSTRUCTIONS */
152 #define _PASTE(x, y) x##y
153 #define PASTE(x, y) _PASTE(x, y)
154 #define KSPLICE_UNIQ(s) PASTE(s##_, KSPLICE_MID)
155 #define KSPLICE_KID_UNIQ(s) PASTE(s##_, KSPLICE_KID)
156 #ifdef KSPLICE_STANDALONE
157 #define init_ksplice_mod_change KSPLICE_KID_UNIQ(init_ksplice_mod_change)
158 #define cleanup_ksplice_mod_change KSPLICE_KID_UNIQ(cleanup_ksplice_mod_change)
159 #endif
162 * struct ksplice_module_list_entry - A record of a ksplice_mod_change's target
163 * @target_mod_name: The name of the ksplice_mod_change's target module
164 * @new_code_mod_name: The name of the ksplice_mod_change's new_code module
165 * @applied: Whether the ksplice_mod_change was applied or not (this
166 * will be false for ksplice_mod_changes patching targets
167 * that are not loaded when the partial flag is set)
169 struct ksplice_module_list_entry {
170 const char *target_mod_name;
171 const char *new_code_mod_name;
172 const char *kid;
173 bool applied;
174 /* private: */
175 struct list_head update_list; /* list head for this is per-update */
176 struct list_head list; /* list head for this is global */
179 /* List of all ksplice modules and the module they patch */
180 extern struct list_head ksplice_modules;
182 /* There are two actions, apply and reverse */
183 #define KS_ACTIONS 2
184 enum ksplice_action {
185 KS_APPLY,
186 KS_REVERSE,
190 * struct ksplice_hooks - Hooks to be run during an action (apply or reverse)
191 * @pre: Runs before the action;
192 * may return nonzero to abort the action
193 * @check: Runs inside stop_machine before the action;
194 * may return nonzero to abort the action
195 * @intra: Runs inside stop_machine during the action
196 * @post: Runs after the action is successfully performed
197 * @fail: Runs if the action is aborted for any reason
199 struct ksplice_hooks {
200 const typeof(int (*)(void)) *pre, *pre_end, *check, *check_end;
201 const typeof(void (*)(void)) *intra, *intra_end, *post, *post_end,
202 *fail, *fail_end;
206 * struct ksplice_code - Ksplice metadata for an object
207 * @relocs: The Ksplice relocations for the object
208 * @symbols: The Ksplice symbols for the object
209 * @sections: The Ksplice sections for the object
211 struct ksplice_code {
212 struct ksplice_reloc *relocs, *relocs_end;
213 struct ksplice_section *sections, *sections_end;
214 struct ksplice_symbol *symbols, *symbols_end;
215 #ifdef KSPLICE_NEED_PARAINSTRUCTIONS
216 struct paravirt_patch_site *parainstructions, *parainstructions_end;
217 #endif /* KSPLICE_NEED_PARAINSTRUCTIONS */
218 #ifdef KSPLICE_STANDALONE
219 struct ksplice_system_map *system_map, *system_map_end;
220 #endif /* KSPLICE_STANDALONE */
224 * struct ksplice_mod_change - Data for one module modified by a Ksplice update
225 * @name: The name of the new_code module for the change
226 * @kid: The Ksplice unique identifier for the change
227 * @target_name: The name of the module modified by the change
228 * @new_code_mod: The new_code module for the change
229 * @old_code: The old code for run-pre matching
230 * @new_code: The new code to switch to
231 * @patches: The function replacements in the change
232 * @patches_end: The end pointer for patches array
233 * @hooks: Hooks to be run during apply and reverse
234 * @update: The atomic update the change is part of
235 * @target: The module modified by the change
236 * @safety_records: The ranges of addresses that must not be on a
237 * kernel stack for the patch to apply safely
239 struct ksplice_mod_change {
240 const char *name;
241 const char *kid;
242 const char *target_name;
243 #ifdef KSPLICE_STANDALONE
244 unsigned long map_printk;
245 #endif /* KSPLICE_STANDALONE */
246 struct module *new_code_mod;
247 struct ksplice_code old_code, new_code;
248 struct ksplice_patch *patches, *patches_end;
249 struct ksplice_hooks hooks[KS_ACTIONS];
250 /* private: */
251 struct update *update;
252 struct module *target;
253 struct list_head temp_labelvals;
254 struct list_head safety_records;
255 struct list_head list;
259 int init_ksplice_mod_change(struct ksplice_mod_change *change);
261 void cleanup_ksplice_mod_change(struct ksplice_mod_change *change);
263 #endif /* __KERNEL__ */