1 #include <linux/types.h>
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)
10 struct ksplice_symbol
{
14 struct list_head
*vals
;
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
25 struct ksplice_reloc
{
26 unsigned long blank_addr
;
27 struct ksplice_symbol
*symbol
;
28 const struct ksplice_reloc_howto
*howto
;
33 enum ksplice_reloc_howto_type
{
35 KSPLICE_HOWTO_RELOC_PATCH
,
39 KSPLICE_HOWTO_EXTABLE
,
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?
55 struct ksplice_reloc_howto
{
56 enum ksplice_reloc_howto_type type
;
60 unsigned int rightshift
;
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 */
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.
78 struct ksplice_section
{
79 struct ksplice_symbol
*symbol
;
80 unsigned long address
;
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
{
95 KSPLICE_PATCH_BUGLINE
,
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
;
122 #ifdef KSPLICE_STANDALONE
123 struct ksplice_system_map
{
125 unsigned long nr_candidates
;
126 const unsigned long *candidates
;
128 #endif /* KSPLICE_STANDALONE */
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 */
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_mod_change KSPLICE_KID_UNIQ(init_ksplice_mod_change)
159 #define cleanup_ksplice_mod_change KSPLICE_KID_UNIQ(cleanup_ksplice_mod_change)
163 * struct ksplice_module_list_entry - A record of a ksplice_mod_change's target
164 * @target_name: The name of the ksplice_mod_change's target module
165 * @primary_name: The name of the ksplice_mod_change's primary module
166 * @applied: Whether the ksplice_mod_change was applied or not (this
167 * will be false for ksplice_mod_changes patching targets
168 * that are not loaded when the partial flag is set)
170 struct ksplice_module_list_entry
{
171 const char *target_name
;
172 const char *primary_name
;
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_modules
;
184 * struct ksplice_code - Ksplice metadata for an object
185 * @relocs: The Ksplice relocations for the object
186 * @symbols: The Ksplice symbols for the object
187 * @sections: The Ksplice sections for the object
189 struct ksplice_code
{
190 struct ksplice_reloc
*relocs
, *relocs_end
;
191 struct ksplice_section
*sections
, *sections_end
;
192 struct ksplice_symbol
*symbols
, *symbols_end
;
193 #ifdef KSPLICE_NEED_PARAINSTRUCTIONS
194 struct paravirt_patch_site
*parainstructions
, *parainstructions_end
;
195 #endif /* KSPLICE_NEED_PARAINSTRUCTIONS */
196 #ifdef KSPLICE_STANDALONE
197 struct ksplice_system_map
*system_map
, *system_map_end
;
198 #endif /* KSPLICE_STANDALONE */
202 * struct ksplice_mod_change - Data for one module modified by a Ksplice update
203 * @name: The name of the primary module for the change
204 * @kid: The Ksplice unique identifier for the change
205 * @target_name: The name of the module modified by the change
206 * @primary: The primary module associated with the change
207 * @old_code: The old code for run-pre matching
208 * @new_code: The new code to switch to
209 * @patches: The function replacements in the change
210 * @patches_end: The end pointer for patches array
211 * @update: The atomic update the change is part of
212 * @target: The module modified by the change
213 * @safety_records: The ranges of addresses that must not be on a
214 * kernel stack for the patch to apply safely
216 struct ksplice_mod_change
{
219 const char *target_name
;
220 #ifdef KSPLICE_STANDALONE
221 unsigned long map_printk
;
222 #endif /* KSPLICE_STANDALONE */
223 struct module
*primary
;
224 struct ksplice_code old_code
, new_code
;
225 struct ksplice_patch
*patches
, *patches_end
;
226 const typeof(int (*)(void)) *pre_apply
, *pre_apply_end
, *check_apply
,
228 const typeof(void (*)(void)) *apply
, *apply_end
, *post_apply
,
229 *post_apply_end
, *fail_apply
, *fail_apply_end
;
230 const typeof(int (*)(void)) *pre_reverse
, *pre_reverse_end
,
231 *check_reverse
, *check_reverse_end
;
232 const typeof(void (*)(void)) *reverse
, *reverse_end
, *post_reverse
,
233 *post_reverse_end
, *fail_reverse
, *fail_reverse_end
;
235 struct update
*update
;
236 struct module
*target
;
237 struct list_head temp_labelvals
;
238 struct list_head safety_records
;
239 struct list_head list
;
243 int init_ksplice_mod_change(struct ksplice_mod_change
*change
);
245 void cleanup_ksplice_mod_change(struct ksplice_mod_change
*change
);
247 #endif /* __KERNEL__ */