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 * @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)
10 struct ksplice_symbol
{
14 struct list_head
*candidate_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 * @insn_addend: The part of the ELF addend resulting from quirks of
24 * the instruction one of whose operands is the relocation.
25 * For example, this is -4 on x86 pc-relative jumps.
26 * @target_addend: The rest of the ELF addend. This is equal to the offset
27 * against the symbol that the relocation refers to.
29 struct ksplice_reloc
{
30 unsigned long blank_addr
;
31 struct ksplice_symbol
*symbol
;
32 const struct ksplice_reloc_howto
*howto
;
37 enum ksplice_reloc_howto_type
{
39 KSPLICE_HOWTO_RELOC_PATCH
,
43 KSPLICE_HOWTO_EXTABLE
,
48 * struct ksplice_reloc_howto - Ksplice's relocation type information
49 * @type: The type of the relocation
50 * @pcrel: Is the relocation PC relative?
51 * @size: The size, in bytes, of the item to be relocated
52 * @dst_mask: Bitmask for which parts of the instruction or data are
53 * replaced with the relocated value
54 * (based on dst_mask from GNU BFD's reloc_howto_struct)
55 * @rightshift: The value the final relocation is shifted right by;
56 * used to drop unwanted data from the relocation
57 * (based on rightshift from GNU BFD's reloc_howto_struct)
58 * @signed_addend: Should the addend be interpreted as a signed value?
60 struct ksplice_reloc_howto
{
61 enum ksplice_reloc_howto_type type
;
65 unsigned int rightshift
;
69 #if BITS_PER_LONG == 32
70 #define KSPLICE_CANARY 0x77777777UL
71 #elif BITS_PER_LONG == 64
72 #define KSPLICE_CANARY 0x7777777777777777UL
73 #endif /* BITS_PER_LONG */
76 * struct ksplice_section - Ksplice's analogue of an ELF section
77 * @symbol: The ksplice_symbol associated with this section
78 * @size: The length, in bytes, of this section
79 * @address: The address of the section
80 * @flags: Flags indicating the type of the section, whether or
81 * not it has been matched, etc.
83 struct ksplice_section
{
84 struct ksplice_symbol
*symbol
;
85 unsigned long address
;
88 const unsigned char **match_map
;
90 #define KSPLICE_SECTION_TEXT 0x00000001
91 #define KSPLICE_SECTION_RODATA 0x00000002
92 #define KSPLICE_SECTION_DATA 0x00000004
93 #define KSPLICE_SECTION_STRING 0x00000008
94 #define KSPLICE_SECTION_MATCHED 0x10000000
96 #define MAX_TRAMPOLINE_SIZE 5
98 enum ksplice_patch_type
{
101 KSPLICE_PATCH_EXPORT
,
105 * struct ksplice_patch - A replacement that Ksplice should perform
106 * @oldaddr: The address of the obsolete function or structure
107 * @repladdr: The address of the replacement function
108 * @type: The type of the ksplice patch
109 * @size: The size of the patch
110 * @contents: The bytes to be installed at oldaddr
111 * @vaddr The address of the page mapping used to write at oldaddr
112 * @saved: The bytes originally at oldaddr which were
113 * overwritten by the patch
115 struct ksplice_patch
{
116 unsigned long oldaddr
;
117 unsigned long repladdr
;
118 enum ksplice_patch_type type
;
126 #ifdef KSPLICE_STANDALONE
127 struct ksplice_system_map
{
129 unsigned long nr_candidates
;
130 const unsigned long *candidates
;
132 #endif /* KSPLICE_STANDALONE */
135 #include <linux/module.h>
136 #include <linux/stringify.h>
137 #include <linux/version.h>
139 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
140 /* 6e21828743247270d09a86756a0c11702500dbfb was after 2.6.18 */
144 #endif /* LINUX_VERSION_CODE */
146 #if defined(CONFIG_PARAVIRT) && defined(CONFIG_X86_64) && \
147 LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25) && \
148 LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
149 /* Linux 2.6.25 and 2.6.26 apply paravirt replacements to the core
150 * kernel but not modules on x86-64. If we are patching the core
151 * kernel, we need to apply the same replacements to our update
152 * modules in order for run-pre matching to succeed.
154 #define KSPLICE_NEED_PARAINSTRUCTIONS 1
155 #endif /* KSPLICE_NEED_PARAINSTRUCTIONS */
157 #define _PASTE(x, y) x##y
158 #define PASTE(x, y) _PASTE(x, y)
159 #define KSPLICE_UNIQ(s) PASTE(s##_, KSPLICE_MID)
160 #define KSPLICE_KID_UNIQ(s) PASTE(s##_, KSPLICE_KID)
161 #ifdef KSPLICE_STANDALONE
162 #define init_ksplice_mod_change KSPLICE_KID_UNIQ(init_ksplice_mod_change)
163 #define cleanup_ksplice_mod_change KSPLICE_KID_UNIQ(cleanup_ksplice_mod_change)
167 * struct ksplice_module_list_entry - A record of a ksplice_mod_change's target
168 * @target_mod_name: The name of the ksplice_mod_change's target module
169 * @new_code_mod_name: The name of the ksplice_mod_change's new_code module
170 * @applied: Whether the ksplice_mod_change was applied or not (this
171 * will be false for ksplice_mod_changes patching targets
172 * that are not loaded when the partial flag is set)
174 struct ksplice_module_list_entry
{
175 const char *target_mod_name
;
176 const char *new_code_mod_name
;
180 struct list_head update_list
; /* list head for this is per-update */
181 struct list_head list
; /* list head for this is global */
184 /* List of all ksplice modules and the module they patch */
185 extern struct list_head ksplice_modules
;
187 /* There are two actions, apply and reverse */
189 enum ksplice_action
{
195 * struct ksplice_hooks - Hooks to be run during an action (apply or reverse)
196 * @pre: Runs before the action;
197 * may return nonzero to abort the action
198 * @check: Runs inside stop_machine before the action;
199 * may return nonzero to abort the action
200 * @intra: Runs inside stop_machine during the action
201 * @post: Runs after the action is successfully performed
202 * @fail: Runs if the action is aborted for any reason
204 struct ksplice_hooks
{
205 const typeof(int (*)(void)) *pre
, *pre_end
, *check
, *check_end
;
206 const typeof(void (*)(void)) *intra
, *intra_end
, *post
, *post_end
,
211 * struct ksplice_code - Ksplice metadata for an object
212 * @relocs: The Ksplice relocations for the object
213 * @symbols: The Ksplice symbols for the object
214 * @sections: The Ksplice sections for the object
216 struct ksplice_code
{
217 struct ksplice_reloc
*relocs
, *relocs_end
;
218 struct ksplice_section
*sections
, *sections_end
;
219 struct ksplice_symbol
*symbols
, *symbols_end
;
220 #ifdef KSPLICE_NEED_PARAINSTRUCTIONS
221 struct paravirt_patch_site
*parainstructions
, *parainstructions_end
;
222 #endif /* KSPLICE_NEED_PARAINSTRUCTIONS */
223 #ifdef KSPLICE_STANDALONE
224 struct ksplice_system_map
*system_map
, *system_map_end
;
225 #endif /* KSPLICE_STANDALONE */
229 * struct ksplice_mod_change - Data for one module modified by a Ksplice update
230 * @name: The name of the new_code module for the change
231 * @kid: The Ksplice unique identifier for the change
232 * @target_name: The name of the module modified by the change
233 * @new_code_mod: The new_code module for the change
234 * @old_code: The old code for run-pre matching
235 * @new_code: The new code to switch to
236 * @patches: The function replacements in the change
237 * @patches_end: The end pointer for patches array
238 * @hooks: Hooks to be run during apply and reverse
239 * @update: The atomic update the change is part of
240 * @target: The module modified by the change
241 * @safety_records: The ranges of addresses that must not be on a
242 * kernel stack for the patch to apply safely
244 struct ksplice_mod_change
{
247 const char *target_name
;
248 #ifdef KSPLICE_STANDALONE
249 unsigned long map_printk
;
250 #endif /* KSPLICE_STANDALONE */
251 struct module
*new_code_mod
;
252 struct ksplice_code old_code
, new_code
;
253 struct ksplice_patch
*patches
, *patches_end
;
254 struct ksplice_hooks hooks
[KS_ACTIONS
];
256 struct update
*update
;
257 struct module
*target
;
258 struct list_head temp_labelvals
;
259 struct list_head safety_records
;
260 struct list_head list
;
264 int init_ksplice_mod_change(struct ksplice_mod_change
*change
);
266 void cleanup_ksplice_mod_change(struct ksplice_mod_change
*change
);
268 #endif /* __KERNEL__ */