Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
awilliam
GitHub Repository: awilliam/linux-vfio
Path: blob/master/arch/m68k/kernel/module_no.c
10817 views
1
#include <linux/moduleloader.h>
2
#include <linux/elf.h>
3
#include <linux/vmalloc.h>
4
#include <linux/fs.h>
5
#include <linux/string.h>
6
#include <linux/kernel.h>
7
8
#if 0
9
#define DEBUGP printk
10
#else
11
#define DEBUGP(fmt...)
12
#endif
13
14
void *module_alloc(unsigned long size)
15
{
16
if (size == 0)
17
return NULL;
18
return vmalloc(size);
19
}
20
21
22
/* Free memory returned from module_alloc */
23
void module_free(struct module *mod, void *module_region)
24
{
25
vfree(module_region);
26
}
27
28
/* We don't need anything special. */
29
int module_frob_arch_sections(Elf_Ehdr *hdr,
30
Elf_Shdr *sechdrs,
31
char *secstrings,
32
struct module *mod)
33
{
34
return 0;
35
}
36
37
int apply_relocate(Elf32_Shdr *sechdrs,
38
const char *strtab,
39
unsigned int symindex,
40
unsigned int relsec,
41
struct module *me)
42
{
43
unsigned int i;
44
Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
45
Elf32_Sym *sym;
46
uint32_t *location;
47
48
DEBUGP("Applying relocate section %u to %u\n", relsec,
49
sechdrs[relsec].sh_info);
50
for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
51
/* This is where to make the change */
52
location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
53
+ rel[i].r_offset;
54
/* This is the symbol it is referring to. Note that all
55
undefined symbols have been resolved. */
56
sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
57
+ ELF32_R_SYM(rel[i].r_info);
58
59
switch (ELF32_R_TYPE(rel[i].r_info)) {
60
case R_68K_32:
61
/* We add the value into the location given */
62
*location += sym->st_value;
63
break;
64
case R_68K_PC32:
65
/* Add the value, subtract its postition */
66
*location += sym->st_value - (uint32_t)location;
67
break;
68
default:
69
printk(KERN_ERR "module %s: Unknown relocation: %u\n",
70
me->name, ELF32_R_TYPE(rel[i].r_info));
71
return -ENOEXEC;
72
}
73
}
74
return 0;
75
}
76
77
int apply_relocate_add(Elf32_Shdr *sechdrs,
78
const char *strtab,
79
unsigned int symindex,
80
unsigned int relsec,
81
struct module *me)
82
{
83
unsigned int i;
84
Elf32_Rela *rel = (void *)sechdrs[relsec].sh_addr;
85
Elf32_Sym *sym;
86
uint32_t *location;
87
88
DEBUGP("Applying relocate_add section %u to %u\n", relsec,
89
sechdrs[relsec].sh_info);
90
for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
91
/* This is where to make the change */
92
location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
93
+ rel[i].r_offset;
94
/* This is the symbol it is referring to. Note that all
95
undefined symbols have been resolved. */
96
sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
97
+ ELF32_R_SYM(rel[i].r_info);
98
99
switch (ELF32_R_TYPE(rel[i].r_info)) {
100
case R_68K_32:
101
/* We add the value into the location given */
102
*location = rel[i].r_addend + sym->st_value;
103
break;
104
case R_68K_PC32:
105
/* Add the value, subtract its postition */
106
*location = rel[i].r_addend + sym->st_value - (uint32_t)location;
107
break;
108
default:
109
printk(KERN_ERR "module %s: Unknown relocation: %u\n",
110
me->name, ELF32_R_TYPE(rel[i].r_info));
111
return -ENOEXEC;
112
}
113
}
114
return 0;
115
}
116
117
int module_finalize(const Elf_Ehdr *hdr,
118
const Elf_Shdr *sechdrs,
119
struct module *me)
120
{
121
return 0;
122
}
123
124
void module_arch_cleanup(struct module *mod)
125
{
126
}
127
128