@@ -18,10 +18,32 @@
#define TRACEFS_PIPE "/sys/kernel/tracing/trace_pipe"
#define DEBUGFS_PIPE "/sys/kernel/debug/tracing/trace_pipe"
-#define MAX_SYMS 400000
-static struct ksym syms[MAX_SYMS];
+static struct ksym *syms;
+static int sym_cap;
static int sym_cnt;
+static int ksyms__add_symbol(const char *name, unsigned long addr)
+{
+ void *tmp;
+ unsigned int new_cap;
+
+ if (sym_cnt + 1 > sym_cap) {
+ new_cap = sym_cap * 4 / 3;
+ tmp = realloc(syms, sizeof(struct ksym) * new_cap);
+ if (!tmp)
+ return -ENOMEM;
+ syms = tmp;
+ sym_cap = new_cap;
+ }
+
+ syms[sym_cnt].addr = addr;
+ syms[sym_cnt].name = strdup(name);
+
+ sym_cnt++;
+
+ return 0;
+}
+
static int ksym_cmp(const void *p1, const void *p2)
{
return ((struct ksym *)p1)->addr - ((struct ksym *)p2)->addr;
@@ -33,9 +55,13 @@ int load_kallsyms_refresh(void)
char func[256], buf[256];
char symbol;
void *addr;
- int i = 0;
+ int ret;
+ sym_cap = 1024;
sym_cnt = 0;
+ syms = malloc(sizeof(struct ksym) * sym_cap);
+ if (!syms)
+ return -ENOMEM;
f = fopen("/proc/kallsyms", "r");
if (!f)
@@ -46,15 +72,11 @@ int load_kallsyms_refresh(void)
break;
if (!addr)
continue;
- if (i >= MAX_SYMS)
- return -EFBIG;
-
- syms[i].addr = (long) addr;
- syms[i].name = strdup(func);
- i++;
+ ret = ksyms__add_symbol(func, (unsigned long)addr);
+ if (ret)
+ return ret;
}
fclose(f);
- sym_cnt = i;
qsort(syms, sym_cnt, sizeof(struct ksym), ksym_cmp);
return 0;
}