2 * struct ksplice_symbol - Ksplice's analogue of an ELF symbol
3 * @name: The ELF name of the symbol
4 * @label: A unique Ksplice name for the symbol
6 struct ksplice_symbol
{
12 * struct ksplice_reloc - Ksplice's analogue of an ELF relocation
13 * @blank_addr: The address of the relocation's storage unit
14 * @blank_offset: The offset (from the start of the section) of the
15 * relocation's storage unit
16 * @symbol: The ksplice_symbol associated with this relocation
17 * @pcrel: Is the relocation PC relative?
18 * @addend: The ELF addend of the relocation
19 * @size: The size, in bytes, of the item to be relocated
20 * @dst_mask: Bitmask for which parts of the instruction or data are
21 * replaced with the relocated value
22 * (based on dst_mask from GNU BFD's reloc_howto_struct)
23 * @rightshift: The value the final relocation is shifted right by;
24 * used to drop unwanted data from the relocation
25 * (based on rightshift from GNU BFD's reloc_howto_struct)
26 * @signed_addend: Should the addend be interpreted as a signed value?
28 struct ksplice_reloc
{
29 unsigned long blank_addr
;
31 const struct ksplice_symbol
*symbol
;
36 unsigned int rightshift
;
41 * struct ksplice_section - Ksplice's analogue of an ELF section
42 * @symbol: The ksplice_symbol associated with this section
43 * @size: The length, in bytes, of this section
44 * @thismod_addr: The address of the section
45 * @flags: Specifies whether this section contains text, read-only
48 struct ksplice_section
{
49 const struct ksplice_symbol
*symbol
;
51 unsigned long thismod_addr
;
54 #define KSPLICE_SECTION_TEXT 0x00000001
55 #define KSPLICE_SECTION_RODATA 0x00000002
56 #define KSPLICE_SECTION_DATA 0x00000004
58 #define MAX_TRAMPOLINE_SIZE 5
61 * struct ksplice_trampoline - A trampoline Ksplice should insert
62 * @repladdr: The address of the replacement function
63 * @oldaddr: The address of the obsolete function
64 * @trampoline: The bytes of the trampoline itself
65 * @saved: The bytes of the original function which were
66 * overwritten by the trampoline
67 * @size: The size of the trampoline
69 * Any value put into a private field by user space will be ignored.
71 struct ksplice_trampoline
{
72 unsigned long repladdr
;
74 unsigned long oldaddr
;
75 char trampoline
[MAX_TRAMPOLINE_SIZE
];
76 char saved
[MAX_TRAMPOLINE_SIZE
];
81 * struct ksplice_patch - A function replacement that Ksplice should perform
82 * @label: The unique Ksplice name for the obsolete function
83 * @trampoline: A trampoline to insert over the obsolete function
84 * @reverse_trampoline: A trampoline to insert over the repladdr of any
85 * trampoline previously installed at the start of the
86 * obsolete function (if the function has been previously
89 * Any value put into a private field by user space will be ignored.
91 struct ksplice_patch
{
93 struct ksplice_trampoline trampoline
;
95 struct ksplice_trampoline reverse_trampoline
;
99 * struct ksplice_export - A change to be made to the exported symbol table
100 * @name: The obsolete name of the exported symbol
101 * @new_name: The new name of the exported symbol
102 * @sym: The kernel_symbol being changed
103 * @saved_name: The pointer to the original name of the kernel_symbol
105 * Any value put into a private field by user space will be ignored.
107 struct ksplice_export
{
109 const char *new_name
;
111 struct kernel_symbol
*sym
;
112 const char *saved_name
;
115 #ifdef KSPLICE_STANDALONE
116 struct ksplice_system_map
{
118 unsigned long nr_candidates
;
119 const unsigned long *candidates
;
121 #endif /* KSPLICE_STANDALONE */
124 #include <linux/module.h>
125 #include <linux/version.h>
127 #if defined(CONFIG_PARAVIRT) && defined(CONFIG_X86_64) && \
128 LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25) && \
129 LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
130 /* Linux 2.6.25 and 2.6.26 apply paravirt replacements to the core
131 * kernel but not modules on x86-64. If we are patching the core
132 * kernel, we need to apply the same replacements to our update
133 * modules in order for run-pre matching to succeed.
135 #define KSPLICE_NEED_PARAINSTRUCTIONS 1
136 #endif /* KSPLICE_NEED_PARAINSTRUCTIONS */
141 #define STR(x) _STR(x)
142 #define _PASTE(x, y) x##y
143 #define PASTE(x, y) _PASTE(x, y)
144 #define KSPLICE_UNIQ(s) PASTE(s##_, KSPLICE_MID)
145 #define KSPLICE_KID_UNIQ(s) PASTE(s##_, KSPLICE_KID)
146 #ifdef KSPLICE_STANDALONE
147 #define init_ksplice_pack KSPLICE_KID_UNIQ(init_ksplice_pack)
148 #define cleanup_ksplice_pack KSPLICE_KID_UNIQ(cleanup_ksplice_pack)
152 * struct ksplice_module_list_entry - A record of a Ksplice pack's target
153 * @target: A module that is patched
154 * @primary: A Ksplice module that patches target
156 struct ksplice_module_list_entry
{
157 struct module
*target
;
158 struct module
*primary
;
160 struct list_head list
;
163 /* List of all ksplice modules and the module they patch */
164 extern struct list_head ksplice_module_list
;
167 * struct ksplice_pack - Data for one module modified by a Ksplice update
168 * @name: The name of the primary module for the pack
169 * @kid: The Ksplice unique identifier for the pack
170 * @target_name: The name of the module modified by the pack
171 * @primary: The primary module associated with the pack
172 * @primary_relocs: The relocations for the primary module
173 * @primary_relocs_end: The end pointer for primary_relocs
174 * @primary_sections: The sections in the primary module
175 * @primary_sections_end: The end pointer for primary_sections array
176 * @helper_relocs: The relocations for the helper module
177 * @helper_relocs_end: The end pointer for helper_relocs array
178 * @helper_sections: The sections in the helper module
179 * @helper_sections_end: The end pointer for helper_sections array
180 * @patches: The function replacements in the pack
181 * @patches_end: The end pointer for patches array
182 * @exports: The exported symbol changes in the pack
183 * @exports_end: The end pointer for the exports array
184 * @update: The atomic update the pack is part of
185 * @target: The module modified by the pack
186 * @reloc_namevals: The mapping between Ksplice symbol labels and
188 * @safety_records: The ranges of addresses that must not be on a
189 * kernel stack for the patch to apply safely
191 struct ksplice_pack
{
194 const char *target_name
;
195 #ifdef KSPLICE_STANDALONE
196 unsigned long map_printk
;
197 #endif /* KSPLICE_STANDALONE */
198 struct module
*primary
;
199 const struct ksplice_reloc
*primary_relocs
, *primary_relocs_end
;
200 const struct ksplice_section
*primary_sections
, *primary_sections_end
;
201 const struct ksplice_reloc
*helper_relocs
, *helper_relocs_end
;
202 const struct ksplice_section
*helper_sections
, *helper_sections_end
;
203 struct ksplice_patch
*patches
, *patches_end
;
204 struct ksplice_export
*exports
, *exports_end
;
205 #ifdef KSPLICE_NEED_PARAINSTRUCTIONS
206 struct paravirt_patch_site
207 *primary_parainstructions
, *primary_parainstructions_end
,
208 *helper_parainstructions
, *helper_parainstructions_end
;
209 #endif /* KSPLICE_NEED_PARAINSTRUCTIONS */
210 #ifdef KSPLICE_STANDALONE
211 struct ksplice_system_map
212 *primary_system_map
, *primary_system_map_end
,
213 *helper_system_map
, *helper_system_map_end
;
214 #endif /* KSPLICE_STANDALONE */
216 struct ksplice_module_list_entry module_list_entry
;
217 struct update
*update
;
218 struct module
*target
;
219 struct list_head reloc_namevals
;
220 struct list_head safety_records
;
221 struct list_head list
;
226 * init_ksplice_pack() - Initializes a pack
227 * @pack: The pack to be initialized. The non-private fields should
228 * already be filled when this is called.
230 int init_ksplice_pack(struct ksplice_pack
*pack
);
233 * cleanup_ksplice_pack() - Cleans up a pack
234 * @pack: The pack to be cleaned up
236 void cleanup_ksplice_pack(struct ksplice_pack
*pack
);
238 #endif /* __KERNEL__ */