Linux Audio

Check our new training course

Loading...
v4.6
 
 
 1#include "symbol/kallsyms.h"
 2#include <stdio.h>
 3#include <stdlib.h>
 4
 5u8 kallsyms2elf_type(char type)
 6{
 7	type = tolower(type);
 8	return (type == 't' || type == 'w') ? STT_FUNC : STT_OBJECT;
 9}
10
11int kallsyms__parse(const char *filename, void *arg,
12		    int (*process_symbol)(void *arg, const char *name,
13					  char type, u64 start))
14{
15	char *line = NULL;
16	size_t n;
17	int err = -1;
18	FILE *file = fopen(filename, "r");
19
20	if (file == NULL)
21		goto out_failure;
22
23	err = 0;
24
25	while (!feof(file)) {
26		u64 start;
27		int line_len, len;
28		char symbol_type;
29		char *symbol_name;
30
31		line_len = getline(&line, &n, file);
32		if (line_len < 0 || !line)
33			break;
34
35		line[--line_len] = '\0'; /* \n */
36
37		len = hex2u64(line, &start);
 
 
 
 
38
39		len++;
40		if (len + 2 >= line_len)
41			continue;
42
43		symbol_type = line[len];
44		len += 2;
45		symbol_name = line + len;
46		len = line_len - len;
47
48		if (len >= KSYM_NAME_LEN) {
49			err = -1;
50			break;
51		}
52
53		err = process_symbol(arg, symbol_name, symbol_type, start);
54		if (err)
55			break;
56	}
57
58	free(line);
59	fclose(file);
60	return err;
61
62out_failure:
63	return -1;
64}
v4.17
 1// SPDX-License-Identifier: GPL-2.0
 2#include <ctype.h>
 3#include "symbol/kallsyms.h"
 4#include <stdio.h>
 5#include <stdlib.h>
 6
 7u8 kallsyms2elf_type(char type)
 8{
 9	type = tolower(type);
10	return (type == 't' || type == 'w') ? STT_FUNC : STT_OBJECT;
11}
12
13int kallsyms__parse(const char *filename, void *arg,
14		    int (*process_symbol)(void *arg, const char *name,
15					  char type, u64 start))
16{
17	char *line = NULL;
18	size_t n;
19	int err = -1;
20	FILE *file = fopen(filename, "r");
21
22	if (file == NULL)
23		goto out_failure;
24
25	err = 0;
26
27	while (!feof(file)) {
28		u64 start;
29		int line_len, len;
30		char symbol_type;
31		char *symbol_name;
32
33		line_len = getline(&line, &n, file);
34		if (line_len < 0 || !line)
35			break;
36
37		line[--line_len] = '\0'; /* \n */
38
39		len = hex2u64(line, &start);
40
41		/* Skip the line if we failed to parse the address. */
42		if (!len)
43			continue;
44
45		len++;
46		if (len + 2 >= line_len)
47			continue;
48
49		symbol_type = line[len];
50		len += 2;
51		symbol_name = line + len;
52		len = line_len - len;
53
54		if (len >= KSYM_NAME_LEN) {
55			err = -1;
56			break;
57		}
58
59		err = process_symbol(arg, symbol_name, symbol_type, start);
60		if (err)
61			break;
62	}
63
64	free(line);
65	fclose(file);
66	return err;
67
68out_failure:
69	return -1;
70}