blob: 3a29dbe7898e329e9ddd61f141dfb44f68a59ca8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * kallsyms.c: in-kernel printing of symbolic oopses and stack traces.
3 *
4 * Rewritten and vastly simplified by Rusty Russell for in-kernel
5 * module loader:
6 * Copyright 2002 Rusty Russell <rusty@rustcorp.com.au> IBM Corporation
7 *
8 * ChangeLog:
9 *
10 * (25/Aug/2004) Paulo Marques <pmarques@grupopie.com>
11 * Changed the compression method from stem compression to "table lookup"
12 * compression (see scripts/kallsyms.c for a more complete description)
13 */
14#include <linux/kallsyms.h>
15#include <linux/module.h>
16#include <linux/init.h>
17#include <linux/seq_file.h>
18#include <linux/fs.h>
19#include <linux/err.h>
20#include <linux/proc_fs.h>
Tim Schmielau4e57b682005-10-30 15:03:48 -080021#include <linux/sched.h> /* for cond_resched */
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/mm.h>
Adam B. Jerome07354a02006-12-06 20:35:30 -080023#include <linux/ctype.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
25#include <asm/sections.h>
26
27#ifdef CONFIG_KALLSYMS_ALL
28#define all_var 1
29#else
30#define all_var 0
31#endif
32
Manish Katiyarad6ccfa2009-05-12 13:43:35 -070033/*
34 * These will be re-linked against their real values
35 * during the second link stage.
36 */
Sam Ravnborg2ea03892009-01-14 21:38:20 +010037extern const unsigned long kallsyms_addresses[] __attribute__((weak));
38extern const u8 kallsyms_names[] __attribute__((weak));
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Manish Katiyarad6ccfa2009-05-12 13:43:35 -070040/*
41 * Tell the compiler that the count isn't in the small data section if the arch
42 * has one (eg: FRV).
David Howells9e6c1e62007-11-28 16:22:04 -080043 */
44extern const unsigned long kallsyms_num_syms
Sam Ravnborg2ea03892009-01-14 21:38:20 +010045__attribute__((weak, section(".rodata")));
David Howells9e6c1e62007-11-28 16:22:04 -080046
Sam Ravnborg2ea03892009-01-14 21:38:20 +010047extern const u8 kallsyms_token_table[] __attribute__((weak));
48extern const u16 kallsyms_token_index[] __attribute__((weak));
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Sam Ravnborg2ea03892009-01-14 21:38:20 +010050extern const unsigned long kallsyms_markers[] __attribute__((weak));
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52static inline int is_kernel_inittext(unsigned long addr)
53{
54 if (addr >= (unsigned long)_sinittext
55 && addr <= (unsigned long)_einittext)
56 return 1;
57 return 0;
58}
59
60static inline int is_kernel_text(unsigned long addr)
61{
62 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_etext)
63 return 1;
64 return in_gate_area_no_task(addr);
65}
66
67static inline int is_kernel(unsigned long addr)
68{
69 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
70 return 1;
71 return in_gate_area_no_task(addr);
72}
73
Franck Bui-Huuffc50892006-10-03 01:13:48 -070074static int is_ksym_addr(unsigned long addr)
75{
76 if (all_var)
77 return is_kernel(addr);
78
Robin Getza3b81112008-02-06 01:36:26 -080079 return is_kernel_text(addr) || is_kernel_inittext(addr);
Franck Bui-Huuffc50892006-10-03 01:13:48 -070080}
81
Manish Katiyarad6ccfa2009-05-12 13:43:35 -070082/*
83 * Expand a compressed symbol data into the resulting uncompressed string,
84 * given the offset to where the symbol is in the compressed stream.
85 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070086static unsigned int kallsyms_expand_symbol(unsigned int off, char *result)
87{
88 int len, skipped_first = 0;
Jan Beulichaad09472006-12-08 02:35:57 -080089 const u8 *tptr, *data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
Manish Katiyarad6ccfa2009-05-12 13:43:35 -070091 /* Get the compressed symbol length from the first symbol byte. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 data = &kallsyms_names[off];
93 len = *data;
94 data++;
95
Manish Katiyarad6ccfa2009-05-12 13:43:35 -070096 /*
97 * Update the offset to return the offset for the next symbol on
98 * the compressed stream.
99 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 off += len + 1;
101
Manish Katiyarad6ccfa2009-05-12 13:43:35 -0700102 /*
103 * For every byte on the compressed symbol data, copy the table
104 * entry for that byte.
105 */
106 while (len) {
107 tptr = &kallsyms_token_table[kallsyms_token_index[*data]];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 data++;
109 len--;
110
111 while (*tptr) {
Manish Katiyarad6ccfa2009-05-12 13:43:35 -0700112 if (skipped_first) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 *result = *tptr;
114 result++;
115 } else
116 skipped_first = 1;
117 tptr++;
118 }
119 }
120
121 *result = '\0';
122
Manish Katiyarad6ccfa2009-05-12 13:43:35 -0700123 /* Return to offset to the next symbol. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 return off;
125}
126
Manish Katiyarad6ccfa2009-05-12 13:43:35 -0700127/*
128 * Get symbol type information. This is encoded as a single char at the
129 * beginning of the symbol name.
130 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131static char kallsyms_get_symbol_type(unsigned int off)
132{
Manish Katiyarad6ccfa2009-05-12 13:43:35 -0700133 /*
134 * Get just the first code, look it up in the token table,
135 * and return the first char from this token.
136 */
137 return kallsyms_token_table[kallsyms_token_index[kallsyms_names[off + 1]]];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138}
139
140
Manish Katiyarad6ccfa2009-05-12 13:43:35 -0700141/*
142 * Find the offset on the compressed stream given and index in the
143 * kallsyms array.
144 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145static unsigned int get_symbol_offset(unsigned long pos)
146{
Jan Beulichaad09472006-12-08 02:35:57 -0800147 const u8 *name;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 int i;
149
Manish Katiyarad6ccfa2009-05-12 13:43:35 -0700150 /*
151 * Use the closest marker we have. We have markers every 256 positions,
152 * so that should be close enough.
153 */
154 name = &kallsyms_names[kallsyms_markers[pos >> 8]];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
Manish Katiyarad6ccfa2009-05-12 13:43:35 -0700156 /*
157 * Sequentially scan all the symbols up to the point we're searching
158 * for. Every symbol is stored in a [<len>][<len> bytes of data] format,
159 * so we just need to add the len to the current pointer for every
160 * symbol we wish to skip.
161 */
162 for (i = 0; i < (pos & 0xFF); i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 name = name + (*name) + 1;
164
165 return name - kallsyms_names;
166}
167
168/* Lookup the address for this symbol. Returns 0 if not found. */
169unsigned long kallsyms_lookup_name(const char *name)
170{
Tejun Heo9281ace2007-07-17 04:03:51 -0700171 char namebuf[KSYM_NAME_LEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 unsigned long i;
173 unsigned int off;
174
175 for (i = 0, off = 0; i < kallsyms_num_syms; i++) {
176 off = kallsyms_expand_symbol(off, namebuf);
177
178 if (strcmp(namebuf, name) == 0)
179 return kallsyms_addresses[i];
180 }
181 return module_kallsyms_lookup_name(name);
182}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
Anders Kaseorg75a66612008-12-05 19:03:58 -0500184int kallsyms_on_each_symbol(int (*fn)(void *, const char *, struct module *,
185 unsigned long),
186 void *data)
187{
188 char namebuf[KSYM_NAME_LEN];
189 unsigned long i;
190 unsigned int off;
191 int ret;
192
193 for (i = 0, off = 0; i < kallsyms_num_syms; i++) {
194 off = kallsyms_expand_symbol(off, namebuf);
195 ret = fn(data, namebuf, NULL, kallsyms_addresses[i]);
196 if (ret != 0)
197 return ret;
198 }
199 return module_kallsyms_on_each_symbol(fn, data);
200}
201EXPORT_SYMBOL_GPL(kallsyms_on_each_symbol);
202
Franck Bui-Huuffc50892006-10-03 01:13:48 -0700203static unsigned long get_symbol_pos(unsigned long addr,
204 unsigned long *symbolsize,
205 unsigned long *offset)
206{
207 unsigned long symbol_start = 0, symbol_end = 0;
208 unsigned long i, low, high, mid;
209
Sam Ravnborg2ea03892009-01-14 21:38:20 +0100210 /* This kernel should never had been booted. */
211 BUG_ON(!kallsyms_addresses);
212
Manish Katiyarad6ccfa2009-05-12 13:43:35 -0700213 /* Do a binary search on the sorted kallsyms_addresses array. */
Franck Bui-Huuffc50892006-10-03 01:13:48 -0700214 low = 0;
215 high = kallsyms_num_syms;
216
217 while (high - low > 1) {
Vegard Nossum2fc9c4e2008-07-25 01:45:34 -0700218 mid = low + (high - low) / 2;
Franck Bui-Huuffc50892006-10-03 01:13:48 -0700219 if (kallsyms_addresses[mid] <= addr)
220 low = mid;
221 else
222 high = mid;
223 }
224
225 /*
Manish Katiyarad6ccfa2009-05-12 13:43:35 -0700226 * Search for the first aliased symbol. Aliased
227 * symbols are symbols with the same address.
Franck Bui-Huuffc50892006-10-03 01:13:48 -0700228 */
229 while (low && kallsyms_addresses[low-1] == kallsyms_addresses[low])
230 --low;
231
232 symbol_start = kallsyms_addresses[low];
233
Manish Katiyarad6ccfa2009-05-12 13:43:35 -0700234 /* Search for next non-aliased symbol. */
Franck Bui-Huuffc50892006-10-03 01:13:48 -0700235 for (i = low + 1; i < kallsyms_num_syms; i++) {
236 if (kallsyms_addresses[i] > symbol_start) {
237 symbol_end = kallsyms_addresses[i];
238 break;
239 }
240 }
241
Manish Katiyarad6ccfa2009-05-12 13:43:35 -0700242 /* If we found no next symbol, we use the end of the section. */
Franck Bui-Huuffc50892006-10-03 01:13:48 -0700243 if (!symbol_end) {
244 if (is_kernel_inittext(addr))
245 symbol_end = (unsigned long)_einittext;
246 else if (all_var)
247 symbol_end = (unsigned long)_end;
248 else
249 symbol_end = (unsigned long)_etext;
250 }
251
Alexey Dobriyanffb45122007-05-08 00:28:41 -0700252 if (symbolsize)
253 *symbolsize = symbol_end - symbol_start;
254 if (offset)
255 *offset = addr - symbol_start;
Franck Bui-Huuffc50892006-10-03 01:13:48 -0700256
257 return low;
258}
259
260/*
261 * Lookup an address but don't bother to find any names.
262 */
263int kallsyms_lookup_size_offset(unsigned long addr, unsigned long *symbolsize,
264 unsigned long *offset)
265{
Rusty Russell6dd06c92008-01-29 17:13:22 -0500266 char namebuf[KSYM_NAME_LEN];
Franck Bui-Huuffc50892006-10-03 01:13:48 -0700267 if (is_ksym_addr(addr))
268 return !!get_symbol_pos(addr, symbolsize, offset);
269
Rusty Russell6dd06c92008-01-29 17:13:22 -0500270 return !!module_address_lookup(addr, symbolsize, offset, NULL, namebuf);
Franck Bui-Huuffc50892006-10-03 01:13:48 -0700271}
272
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273/*
274 * Lookup an address
Manish Katiyarad6ccfa2009-05-12 13:43:35 -0700275 * - modname is set to NULL if it's in the kernel.
276 * - We guarantee that the returned name is valid until we reschedule even if.
277 * It resides in a module.
278 * - We also guarantee that modname will be valid until rescheduled.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 */
280const char *kallsyms_lookup(unsigned long addr,
281 unsigned long *symbolsize,
282 unsigned long *offset,
283 char **modname, char *namebuf)
284{
Tejun Heo9281ace2007-07-17 04:03:51 -0700285 namebuf[KSYM_NAME_LEN - 1] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 namebuf[0] = 0;
287
Franck Bui-Huuffc50892006-10-03 01:13:48 -0700288 if (is_ksym_addr(addr)) {
289 unsigned long pos;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
Franck Bui-Huuffc50892006-10-03 01:13:48 -0700291 pos = get_symbol_pos(addr, symbolsize, offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 /* Grab name */
Franck Bui-Huuffc50892006-10-03 01:13:48 -0700293 kallsyms_expand_symbol(get_symbol_offset(pos), namebuf);
Kyle McMartin7a74fc42007-05-30 02:43:16 -0400294 if (modname)
295 *modname = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 return namebuf;
297 }
298
Manish Katiyarad6ccfa2009-05-12 13:43:35 -0700299 /* See if it's in a module. */
Rusty Russell6dd06c92008-01-29 17:13:22 -0500300 return module_address_lookup(addr, symbolsize, offset, modname,
301 namebuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302}
303
Alexey Dobriyan9d65cb42007-05-08 00:28:43 -0700304int lookup_symbol_name(unsigned long addr, char *symname)
305{
306 symname[0] = '\0';
Tejun Heo9281ace2007-07-17 04:03:51 -0700307 symname[KSYM_NAME_LEN - 1] = '\0';
Alexey Dobriyan9d65cb42007-05-08 00:28:43 -0700308
309 if (is_ksym_addr(addr)) {
310 unsigned long pos;
311
312 pos = get_symbol_pos(addr, NULL, NULL);
313 /* Grab name */
314 kallsyms_expand_symbol(get_symbol_offset(pos), symname);
315 return 0;
316 }
Manish Katiyarad6ccfa2009-05-12 13:43:35 -0700317 /* See if it's in a module. */
Alexey Dobriyan9d65cb42007-05-08 00:28:43 -0700318 return lookup_module_symbol_name(addr, symname);
319}
320
Alexey Dobriyana5c43da2007-05-08 00:28:47 -0700321int lookup_symbol_attrs(unsigned long addr, unsigned long *size,
322 unsigned long *offset, char *modname, char *name)
323{
324 name[0] = '\0';
Tejun Heo9281ace2007-07-17 04:03:51 -0700325 name[KSYM_NAME_LEN - 1] = '\0';
Alexey Dobriyana5c43da2007-05-08 00:28:47 -0700326
327 if (is_ksym_addr(addr)) {
328 unsigned long pos;
329
330 pos = get_symbol_pos(addr, size, offset);
331 /* Grab name */
332 kallsyms_expand_symbol(get_symbol_offset(pos), name);
333 modname[0] = '\0';
334 return 0;
335 }
Manish Katiyarad6ccfa2009-05-12 13:43:35 -0700336 /* See if it's in a module. */
Alexey Dobriyana5c43da2007-05-08 00:28:47 -0700337 return lookup_module_symbol_attrs(addr, size, offset, modname, name);
338}
339
Robert Peterson42e38082007-04-30 15:09:48 -0700340/* Look up a kernel symbol and return it in a text buffer. */
341int sprint_symbol(char *buffer, unsigned long address)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342{
343 char *modname;
344 const char *name;
345 unsigned long offset, size;
Hugh Dickins966c8c12008-11-19 15:36:36 -0800346 int len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
Hugh Dickins966c8c12008-11-19 15:36:36 -0800348 name = kallsyms_lookup(address, &size, &offset, &modname, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 if (!name)
Robert Peterson42e38082007-04-30 15:09:48 -0700350 return sprintf(buffer, "0x%lx", address);
Andrew Morton19769b72007-07-15 23:41:24 -0700351
Hugh Dickins966c8c12008-11-19 15:36:36 -0800352 if (name != buffer)
353 strcpy(buffer, name);
354 len = strlen(buffer);
355 buffer += len;
356
Andrew Morton19769b72007-07-15 23:41:24 -0700357 if (modname)
Hugh Dickins966c8c12008-11-19 15:36:36 -0800358 len += sprintf(buffer, "+%#lx/%#lx [%s]",
359 offset, size, modname);
Andrew Morton19769b72007-07-15 23:41:24 -0700360 else
Hugh Dickins966c8c12008-11-19 15:36:36 -0800361 len += sprintf(buffer, "+%#lx/%#lx", offset, size);
362
363 return len;
Robert Peterson42e38082007-04-30 15:09:48 -0700364}
Manish Katiyarad6ccfa2009-05-12 13:43:35 -0700365EXPORT_SYMBOL_GPL(sprint_symbol);
Robert Peterson42e38082007-04-30 15:09:48 -0700366
367/* Look up a kernel symbol and print it to the kernel messages. */
368void __print_symbol(const char *fmt, unsigned long address)
369{
370 char buffer[KSYM_SYMBOL_LEN];
371
372 sprint_symbol(buffer, address);
373
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 printk(fmt, buffer);
375}
Manish Katiyarad6ccfa2009-05-12 13:43:35 -0700376EXPORT_SYMBOL(__print_symbol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
378/* To avoid using get_symbol_offset for every symbol, we carry prefix along. */
Manish Katiyarad6ccfa2009-05-12 13:43:35 -0700379struct kallsym_iter {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 loff_t pos;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 unsigned long value;
Manish Katiyarad6ccfa2009-05-12 13:43:35 -0700382 unsigned int nameoff; /* If iterating in core kernel symbols. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 char type;
Tejun Heo9281ace2007-07-17 04:03:51 -0700384 char name[KSYM_NAME_LEN];
385 char module_name[MODULE_NAME_LEN];
Alexey Dobriyanea078902007-05-08 00:28:39 -0700386 int exported;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387};
388
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389static int get_ksymbol_mod(struct kallsym_iter *iter)
390{
Alexey Dobriyanea078902007-05-08 00:28:39 -0700391 if (module_get_kallsym(iter->pos - kallsyms_num_syms, &iter->value,
392 &iter->type, iter->name, iter->module_name,
393 &iter->exported) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 return 1;
396}
397
398/* Returns space to next name. */
399static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
400{
401 unsigned off = iter->nameoff;
402
Alexey Dobriyanea078902007-05-08 00:28:39 -0700403 iter->module_name[0] = '\0';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 iter->value = kallsyms_addresses[iter->pos];
405
406 iter->type = kallsyms_get_symbol_type(off);
407
408 off = kallsyms_expand_symbol(off, iter->name);
409
410 return off - iter->nameoff;
411}
412
413static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
414{
415 iter->name[0] = '\0';
416 iter->nameoff = get_symbol_offset(new_pos);
417 iter->pos = new_pos;
418}
419
420/* Returns false if pos at or past end of file. */
421static int update_iter(struct kallsym_iter *iter, loff_t pos)
422{
423 /* Module symbols can be accessed randomly. */
424 if (pos >= kallsyms_num_syms) {
425 iter->pos = pos;
426 return get_ksymbol_mod(iter);
427 }
Manish Katiyarad6ccfa2009-05-12 13:43:35 -0700428
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 /* If we're not on the desired position, reset to new position. */
430 if (pos != iter->pos)
431 reset_iter(iter, pos);
432
433 iter->nameoff += get_ksymbol_core(iter);
434 iter->pos++;
435
436 return 1;
437}
438
439static void *s_next(struct seq_file *m, void *p, loff_t *pos)
440{
441 (*pos)++;
442
443 if (!update_iter(m->private, *pos))
444 return NULL;
445 return p;
446}
447
448static void *s_start(struct seq_file *m, loff_t *pos)
449{
450 if (!update_iter(m->private, *pos))
451 return NULL;
452 return m->private;
453}
454
455static void s_stop(struct seq_file *m, void *p)
456{
457}
458
459static int s_show(struct seq_file *m, void *p)
460{
461 struct kallsym_iter *iter = m->private;
462
Manish Katiyarad6ccfa2009-05-12 13:43:35 -0700463 /* Some debugging symbols have no name. Ignore them. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 if (!iter->name[0])
465 return 0;
466
Alexey Dobriyanea078902007-05-08 00:28:39 -0700467 if (iter->module_name[0]) {
468 char type;
469
Manish Katiyarad6ccfa2009-05-12 13:43:35 -0700470 /*
471 * Label it "global" if it is exported,
472 * "local" if not exported.
473 */
Alexey Dobriyanea078902007-05-08 00:28:39 -0700474 type = iter->exported ? toupper(iter->type) :
475 tolower(iter->type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 seq_printf(m, "%0*lx %c %s\t[%s]\n",
Manish Katiyarad6ccfa2009-05-12 13:43:35 -0700477 (int)(2 * sizeof(void *)),
Alexey Dobriyanea078902007-05-08 00:28:39 -0700478 iter->value, type, iter->name, iter->module_name);
479 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 seq_printf(m, "%0*lx %c %s\n",
Manish Katiyarad6ccfa2009-05-12 13:43:35 -0700481 (int)(2 * sizeof(void *)),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 iter->value, iter->type, iter->name);
483 return 0;
484}
485
Helge Deller15ad7cd2006-12-06 20:40:36 -0800486static const struct seq_operations kallsyms_op = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 .start = s_start,
488 .next = s_next,
489 .stop = s_stop,
490 .show = s_show
491};
492
493static int kallsyms_open(struct inode *inode, struct file *file)
494{
Manish Katiyarad6ccfa2009-05-12 13:43:35 -0700495 /*
496 * We keep iterator in m->private, since normal case is to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 * s_start from where we left off, so we avoid doing
Manish Katiyarad6ccfa2009-05-12 13:43:35 -0700498 * using get_symbol_offset for every symbol.
499 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 struct kallsym_iter *iter;
501 int ret;
502
503 iter = kmalloc(sizeof(*iter), GFP_KERNEL);
504 if (!iter)
505 return -ENOMEM;
506 reset_iter(iter, 0);
507
508 ret = seq_open(file, &kallsyms_op);
509 if (ret == 0)
510 ((struct seq_file *)file->private_data)->private = iter;
511 else
512 kfree(iter);
513 return ret;
514}
515
Helge Deller15ad7cd2006-12-06 20:40:36 -0800516static const struct file_operations kallsyms_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 .open = kallsyms_open,
518 .read = seq_read,
519 .llseek = seq_lseek,
Martin Peschke5a0c6a02007-05-08 00:29:25 -0700520 .release = seq_release_private,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521};
522
523static int __init kallsyms_init(void)
524{
Denis V. Lunevc33fff02008-04-29 01:02:31 -0700525 proc_create("kallsyms", 0444, NULL, &kallsyms_operations);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 return 0;
527}
Manish Katiyarad6ccfa2009-05-12 13:43:35 -0700528device_initcall(kallsyms_init);