Don't build the ksplice core twice.
[ksplice.git] / kmodsrc / ksplice.h
blob50943f76e4f9986b0f6dc173676fe22d4e394653
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 * @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 *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_BUGLINE,
96 KSPLICE_PATCH_DATA,
97 KSPLICE_PATCH_EXPORT,
101 * struct ksplice_patch - A replacement that Ksplice should perform
102 * @oldaddr: The address of the obsolete function or structure
103 * @repladdr: The address of the replacement function
104 * @type: The type of the ksplice patch
105 * @size: The size of the patch
106 * @contents: The bytes to be installed at oldaddr
107 * @vaddr The address of the page mapping used to write at oldaddr
108 * @saved: The bytes originally at oldaddr which were
109 * overwritten by the patch
111 struct ksplice_patch {
112 unsigned long oldaddr;
113 unsigned long repladdr;
114 enum ksplice_patch_type type;
115 unsigned int size;
116 void *contents;
117 /* private: */
118 void *vaddr;
119 void *saved;
122 #ifdef KSPLICE_STANDALONE
123 struct ksplice_system_map {
124 const char *label;
125 unsigned long nr_candidates;
126 const unsigned long *candidates;
128 #endif /* KSPLICE_STANDALONE */
130 #ifdef __KERNEL__
131 #include <linux/module.h>
132 #include <linux/stringify.h>
133 #include <linux/version.h>
135 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
136 /* 6e21828743247270d09a86756a0c11702500dbfb was after 2.6.18 */
137 #define bool _Bool
138 #define false 0
139 #define true 1
140 #endif /* LINUX_VERSION_CODE */
142 #if defined(CONFIG_PARAVIRT) && defined(CONFIG_X86_64) && \
143 LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25) && \
144 LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
145 /* Linux 2.6.25 and 2.6.26 apply paravirt replacements to the core
146 * kernel but not modules on x86-64. If we are patching the core
147 * kernel, we need to apply the same replacements to our update
148 * modules in order for run-pre matching to succeed.
150 #define KSPLICE_NEED_PARAINSTRUCTIONS 1
151 #endif /* KSPLICE_NEED_PARAINSTRUCTIONS */
153 #define _PASTE(x, y) x##y
154 #define PASTE(x, y) _PASTE(x, y)
155 #define KSPLICE_UNIQ(s) PASTE(s##_, KSPLICE_MID)
156 #define KSPLICE_KID_UNIQ(s) PASTE(s##_, KSPLICE_KID)
157 #ifdef KSPLICE_STANDALONE
158 #define init_ksplice_pack KSPLICE_KID_UNIQ(init_ksplice_pack)
159 #define cleanup_ksplice_pack KSPLICE_KID_UNIQ(cleanup_ksplice_pack)
160 #endif
163 * struct ksplice_module_list_entry - A record of a Ksplice pack's target
164 * @target_name: The name of the pack's target module
165 * @primary_name: The name of the pack's primary module
166 * @applied: Whether the pack was applied or not (this will be
167 * false for packs patching targets that are not loaded
168 * when the partial flag is set)
170 struct ksplice_module_list_entry {
171 const char *target_name;
172 const char *primary_name;
173 const char *kid;
174 bool applied;
175 /* private: */
176 struct list_head update_list; /* list head for this is per-update */
177 struct list_head list; /* list head for this is global */
180 /* List of all ksplice modules and the module they patch */
181 extern struct list_head ksplice_module_list;
184 * struct ksplice_pack - Data for one module modified by a Ksplice update
185 * @name: The name of the primary module for the pack
186 * @kid: The Ksplice unique identifier for the pack
187 * @target_name: The name of the module modified by the pack
188 * @primary: The primary module associated with the pack
189 * @primary_relocs: The relocations for the primary module
190 * @primary_relocs_end: The end pointer for primary_relocs
191 * @primary_sections: The sections in the primary module
192 * @primary_sections_end: The end pointer for primary_sections array
193 * @helper_relocs: The relocations for the helper module
194 * @helper_relocs_end: The end pointer for helper_relocs array
195 * @helper_sections: The sections in the helper module
196 * @helper_sections_end: The end pointer for helper_sections array
197 * @patches: The function replacements in the pack
198 * @patches_end: The end pointer for patches array
199 * @update: The atomic update the pack is part of
200 * @target: The module modified by the pack
201 * @safety_records: The ranges of addresses that must not be on a
202 * kernel stack for the patch to apply safely
204 struct ksplice_pack {
205 const char *name;
206 const char *kid;
207 const char *target_name;
208 #ifdef KSPLICE_STANDALONE
209 unsigned long map_printk;
210 #endif /* KSPLICE_STANDALONE */
211 struct module *primary;
212 struct ksplice_reloc *primary_relocs, *primary_relocs_end;
213 const struct ksplice_section *primary_sections, *primary_sections_end;
214 struct ksplice_symbol *primary_symbols, *primary_symbols_end;
215 struct ksplice_reloc *helper_relocs, *helper_relocs_end;
216 struct ksplice_section *helper_sections, *helper_sections_end;
217 struct ksplice_symbol *helper_symbols, *helper_symbols_end;
218 struct ksplice_patch *patches, *patches_end;
219 const typeof(int (*)(void)) *pre_apply, *pre_apply_end, *check_apply,
220 *check_apply_end;
221 const typeof(void (*)(void)) *apply, *apply_end, *post_apply,
222 *post_apply_end, *fail_apply, *fail_apply_end;
223 const typeof(int (*)(void)) *pre_reverse, *pre_reverse_end,
224 *check_reverse, *check_reverse_end;
225 const typeof(void (*)(void)) *reverse, *reverse_end, *post_reverse,
226 *post_reverse_end, *fail_reverse, *fail_reverse_end;
227 #ifdef KSPLICE_NEED_PARAINSTRUCTIONS
228 struct paravirt_patch_site
229 *primary_parainstructions, *primary_parainstructions_end,
230 *helper_parainstructions, *helper_parainstructions_end;
231 #endif /* KSPLICE_NEED_PARAINSTRUCTIONS */
232 #ifdef KSPLICE_STANDALONE
233 struct ksplice_system_map
234 *primary_system_map, *primary_system_map_end,
235 *helper_system_map, *helper_system_map_end;
236 #endif /* KSPLICE_STANDALONE */
237 /* private: */
238 struct update *update;
239 struct module *target;
240 struct list_head temp_labelvals;
241 struct list_head safety_records;
242 struct list_head list;
246 int init_ksplice_pack(struct ksplice_pack *pack);
248 void cleanup_ksplice_pack(struct ksplice_pack *pack);
250 #endif /* __KERNEL__ */