@@ -85,32 +85,26 @@ void elf_load_sections(elf_img_info_t *elf_img_info)
85
85
86
86
/* header */
87
87
#ifdef CONFIG_ARCH_ARM32
88
- elf_img_info -> header =
89
- (struct elf32_hdr * )malloc (sizeof (struct elf32_hdr ));
88
+ elf_img_info -> header = (struct elf32_hdr * ) malloc (sizeof (struct elf32_hdr ));
90
89
#else
91
- elf_img_info -> header =
92
- (struct elf64_hdr * )malloc (sizeof (struct elf64_hdr ));
90
+ elf_img_info -> header = (struct elf64_hdr * ) malloc (sizeof (struct elf64_hdr ));
93
91
#endif
94
92
if (!elf_img_info -> header ) {
95
93
printk ("%s: failed to allocate memory\n" , __func__ );
96
94
kernel_panic ();
97
95
}
98
96
99
97
#ifdef CONFIG_ARCH_ARM32
100
- memcpy (elf_img_info -> header , elf_img_info -> file_buffer ,
101
- sizeof (struct elf32_hdr ));
98
+ memcpy (elf_img_info -> header , elf_img_info -> file_buffer , sizeof (struct elf32_hdr ));
102
99
#else
103
- memcpy (elf_img_info -> header , elf_img_info -> file_buffer ,
104
- sizeof (struct elf64_hdr ));
100
+ memcpy (elf_img_info -> header , elf_img_info -> file_buffer , sizeof (struct elf64_hdr ));
105
101
#endif
106
102
107
- LOG_DEBUG ("Magic: 0x%02x%c%c%c\n" , elf_img_info -> header -> e_ident [EI_MAG0 ],
108
- elf_img_info -> header -> e_ident [EI_MAG1 ],
109
- elf_img_info -> header -> e_ident [EI_MAG2 ],
110
- elf_img_info -> header -> e_ident [EI_MAG3 ]);
103
+ LOG_DEBUG ("Magic: 0x%02x%c%c%c\n" , elf_img_info -> header -> e_ident [EI_MAG0 ], elf_img_info -> header -> e_ident [EI_MAG1 ],
104
+ elf_img_info -> header -> e_ident [EI_MAG2 ], elf_img_info -> header -> e_ident [EI_MAG3 ]);
111
105
LOG_DEBUG ("%d sections\n" , elf_img_info -> header -> e_shnum );
112
- LOG_DEBUG ("section table is at offset 0x%08x (%d bytes/section)\n" ,
113
- elf_img_info -> header -> e_shoff , elf_img_info -> header -> e_shentsize );
106
+ LOG_DEBUG ("section table is at offset 0x%08x (%d bytes/section)\n" , elf_img_info -> header -> e_shoff ,
107
+ elf_img_info -> header -> e_shentsize );
114
108
115
109
#ifdef CONFIG_ARCH_ARM32
116
110
LOG_DEBUG ("sizeof(struct elf32_shdr): %d bytes\n" , sizeof (struct elf32_shdr ));
@@ -120,65 +114,49 @@ void elf_load_sections(elf_img_info_t *elf_img_info)
120
114
121
115
/* sections */
122
116
#ifdef CONFIG_ARCH_ARM32
123
- elf_img_info -> sections = (struct elf32_shdr * )malloc (
124
- elf_img_info -> header -> e_shnum * sizeof (struct elf32_shdr ));
117
+ elf_img_info -> sections = (struct elf32_shdr * ) malloc (elf_img_info -> header -> e_shnum * sizeof (struct elf32_shdr ));
125
118
#else
126
- elf_img_info -> sections = (struct elf64_shdr * )malloc (
127
- elf_img_info -> header -> e_shnum * sizeof (struct elf64_shdr ));
119
+ elf_img_info -> sections = (struct elf64_shdr * ) malloc (elf_img_info -> header -> e_shnum * sizeof (struct elf64_shdr ));
128
120
#endif
129
121
130
122
if (!elf_img_info -> sections ) {
131
123
LOG_CRITICAL ("%s: failed to allocate memory\n" , __func__ );
132
124
kernel_panic ();
133
125
}
134
126
135
- elf_img_info -> section_names =
136
- (char * * )malloc (elf_img_info -> header -> e_shnum * sizeof (char * ));
127
+ elf_img_info -> section_names = (char * * ) malloc (elf_img_info -> header -> e_shnum * sizeof (char * ));
137
128
if (!elf_img_info -> section_names ) {
138
129
LOG_CRITICAL ("%s: failed to allocate memory\n" , __func__ );
139
130
kernel_panic ();
140
131
}
141
132
142
133
for (i = 0 ; i < elf_img_info -> header -> e_shnum ; i ++ )
143
134
memcpy (elf_img_info -> sections + i ,
144
- elf_img_info -> file_buffer +
145
- elf_img_info -> header -> e_shoff +
146
- i * elf_img_info -> header -> e_shentsize ,
135
+ elf_img_info -> file_buffer + elf_img_info -> header -> e_shoff + i * elf_img_info -> header -> e_shentsize ,
147
136
sizeof (struct elf32_shdr ));
148
137
149
138
/* Section names */
150
139
for (i = 0 ; i < elf_img_info -> header -> e_shnum ; i ++ ) {
151
140
section_name_offset =
152
- elf_img_info -> sections [elf_img_info -> header -> e_shstrndx ]
153
- .sh_offset +
154
- elf_img_info -> sections [i ].sh_name ;
155
- section_name_len =
156
- strlen ((const char * )(elf_img_info -> file_buffer +
157
- section_name_offset ));
158
-
159
- elf_img_info -> section_names [i ] =
160
- (char * )malloc (section_name_len + 1 );
141
+ elf_img_info -> sections [elf_img_info -> header -> e_shstrndx ].sh_offset + elf_img_info -> sections [i ].sh_name ;
142
+ section_name_len = strlen ((const char * ) (elf_img_info -> file_buffer + section_name_offset ));
143
+
144
+ elf_img_info -> section_names [i ] = (char * ) malloc (section_name_len + 1 );
161
145
if (!elf_img_info -> section_names [i ]) {
162
146
printk ("%s: failed to allocate memory\n" , __func__ );
163
147
kernel_panic ();
164
148
}
165
149
166
- strcpy (elf_img_info -> section_names [i ],
167
- (char * )(elf_img_info -> file_buffer +
168
- section_name_offset ));
150
+ strcpy (elf_img_info -> section_names [i ], (char * ) (elf_img_info -> file_buffer + section_name_offset ));
169
151
170
- LOG_DEBUG ("[0x%08x] section name: %s\t(%d bytes)\n" ,
171
- section_name_offset , elf_img_info -> section_names [i ],
172
- section_name_len );
152
+ LOG_DEBUG ("[0x%08x] section name: %s\t(%d bytes)\n" , section_name_offset , elf_img_info -> section_names [i ],
153
+ section_name_len );
173
154
}
174
155
175
156
for (i = 0 ; i < elf_img_info -> header -> e_shnum ; i ++ ) {
176
- LOG_DEBUG ("\t[0x%08x] %s loads at 0x%08x (%d bytes) - flags: 0x%08x\n" ,
177
- elf_img_info -> sections [i ].sh_offset ,
178
- elf_img_info -> section_names [i ],
179
- elf_img_info -> sections [i ].sh_addr ,
180
- elf_img_info -> sections [i ].sh_size ,
181
- elf_img_info -> sections [i ].sh_flags );
157
+ LOG_DEBUG ("\t[0x%08x] %s loads at 0x%08x (%d bytes) - flags: 0x%08x\n" , elf_img_info -> sections [i ].sh_offset ,
158
+ elf_img_info -> section_names [i ], elf_img_info -> sections [i ].sh_addr , elf_img_info -> sections [i ].sh_size ,
159
+ elf_img_info -> sections [i ].sh_flags );
182
160
}
183
161
}
184
162
@@ -188,11 +166,9 @@ void elf_load_segments(elf_img_info_t *elf_img_info)
188
166
189
167
/* Segments */
190
168
#ifdef CONFIG_ARCH_ARM32
191
- elf_img_info -> segments = (struct elf32_phdr * )malloc (
192
- sizeof (struct elf32_phdr ) * elf_img_info -> header -> e_phnum );
169
+ elf_img_info -> segments = (struct elf32_phdr * ) malloc (sizeof (struct elf32_phdr ) * elf_img_info -> header -> e_phnum );
193
170
#else
194
- elf_img_info -> segments = (struct elf64_phdr * )malloc (
195
- sizeof (struct elf64_phdr ) * elf_img_info -> header -> e_phnum );
171
+ elf_img_info -> segments = (struct elf64_phdr * ) malloc (sizeof (struct elf64_phdr ) * elf_img_info -> header -> e_phnum );
196
172
#endif
197
173
198
174
if (!elf_img_info -> segments ) {
@@ -201,8 +177,8 @@ void elf_load_segments(elf_img_info_t *elf_img_info)
201
177
}
202
178
203
179
LOG_DEBUG ("%d segments\n" , elf_img_info -> header -> e_phnum );
204
- LOG_DEBUG ("segment table is at offset 0x%08x (%d bytes/section)\n" ,
205
- elf_img_info -> header -> e_phoff , elf_img_info -> header -> e_phentsize );
180
+ LOG_DEBUG ("segment table is at offset 0x%08x (%d bytes/section)\n" , elf_img_info -> header -> e_phoff ,
181
+ elf_img_info -> header -> e_phentsize );
206
182
#ifdef CONFIG_ARCH_ARM32
207
183
LOG_DEBUG ("sizeof(struct elf32_phdr): %d bytes\n" , sizeof (struct elf32_phdr ));
208
184
#else
@@ -213,34 +189,23 @@ void elf_load_segments(elf_img_info_t *elf_img_info)
213
189
for (i = 0 ; i < elf_img_info -> header -> e_phnum ; i ++ ) {
214
190
#ifdef CONFIG_ARCH_ARM32
215
191
memcpy (elf_img_info -> segments + i ,
216
- elf_img_info -> file_buffer +
217
- elf_img_info -> header -> e_phoff +
218
- i * elf_img_info -> header -> e_phentsize ,
192
+ elf_img_info -> file_buffer + elf_img_info -> header -> e_phoff + i * elf_img_info -> header -> e_phentsize ,
219
193
sizeof (struct elf32_phdr ));
220
194
#else
221
195
memcpy (elf_img_info -> segments + i ,
222
- elf_img_info -> file_buffer +
223
- elf_img_info -> header -> e_phoff +
224
- i * elf_img_info -> header -> e_phentsize ,
196
+ elf_img_info -> file_buffer + elf_img_info -> header -> e_phoff + i * elf_img_info -> header -> e_phentsize ,
225
197
sizeof (struct elf64_phdr ));
226
198
#endif
227
199
228
200
if (elf_img_info -> segments [i ].p_type == PT_LOAD )
229
- elf_img_info -> segment_page_count +=
230
- (elf_img_info -> segments [i ].p_memsz >>
231
- PAGE_SHIFT ) +
232
- 1 ;
201
+ elf_img_info -> segment_page_count += (elf_img_info -> segments [i ].p_memsz >> PAGE_SHIFT ) + 1 ;
233
202
}
234
- LOG_DEBUG ("segments use %d virtual pages\n" ,
235
- elf_img_info -> segment_page_count );
203
+ LOG_DEBUG ("segments use %d virtual pages\n" , elf_img_info -> segment_page_count );
236
204
237
205
for (i = 0 ; i < elf_img_info -> header -> e_phnum ; i ++ ) {
238
206
LOG_DEBUG ("[0x%08x] vaddr: 0x%08x; paddr: 0x%08x; filesize: 0x%08x; memsize: 0x%08x flags: 0x%08x\n" ,
239
- elf_img_info -> segments [i ].p_offset ,
240
- elf_img_info -> segments [i ].p_vaddr ,
241
- elf_img_info -> segments [i ].p_paddr ,
242
- elf_img_info -> segments [i ].p_filesz ,
243
- elf_img_info -> segments [i ].p_memsz ,
244
- elf_img_info -> segments [i ].p_flags );
207
+ elf_img_info -> segments [i ].p_offset , elf_img_info -> segments [i ].p_vaddr ,
208
+ elf_img_info -> segments [i ].p_paddr , elf_img_info -> segments [i ].p_filesz ,
209
+ elf_img_info -> segments [i ].p_memsz , elf_img_info -> segments [i ].p_flags );
245
210
}
246
211
}
0 commit comments