mirror of
https://github.com/dynup/kpatch
synced 2025-02-18 10:46:55 +00:00
Merge pull request #1052 from sm00th/symvers
Make symvers reading code more flexible.
This commit is contained in:
commit
e0bd024c18
@ -280,18 +280,24 @@ static void symtab_read(struct lookup_table *table, char *path)
|
|||||||
fclose(file);
|
fclose(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Symvers file format is the following for kernels v5.3 and newer:
|
||||||
|
* <CRC> <Symbol> <Namespace> <Module> <Export Type>
|
||||||
|
*
|
||||||
|
* Separated by tabs. <Namespace> can be blank (i.e. ""). Kernels before v5.3
|
||||||
|
* don't have namespace column at all.
|
||||||
|
*/
|
||||||
static void symvers_read(struct lookup_table *table, char *path)
|
static void symvers_read(struct lookup_table *table, char *path)
|
||||||
{
|
{
|
||||||
FILE *file;
|
FILE *file;
|
||||||
unsigned int crc, i = 0;
|
unsigned int i = 0;
|
||||||
char name[256], mod[256], export[256];
|
char line[4096];
|
||||||
char *objname, *symname;
|
char *objname, *symname;
|
||||||
|
|
||||||
if ((file = fopen(path, "r")) == NULL)
|
if ((file = fopen(path, "r")) == NULL)
|
||||||
ERROR("fopen");
|
ERROR("fopen");
|
||||||
|
|
||||||
while (fscanf(file, "%x %s %s %s\n",
|
while (fgets(line, 4096, file))
|
||||||
&crc, name, mod, export) != EOF)
|
|
||||||
table->exp_nr++;
|
table->exp_nr++;
|
||||||
|
|
||||||
table->exp_syms = malloc(table->exp_nr * sizeof(*table->exp_syms));
|
table->exp_syms = malloc(table->exp_nr * sizeof(*table->exp_syms));
|
||||||
@ -302,8 +308,31 @@ static void symvers_read(struct lookup_table *table, char *path)
|
|||||||
|
|
||||||
rewind(file);
|
rewind(file);
|
||||||
|
|
||||||
while (fscanf(file, "%x %s %s %s\n",
|
while (fgets(line, 4096, file)) {
|
||||||
&crc, name, mod, export) != EOF) {
|
char *name, *namespace, *mod, *tmp;
|
||||||
|
|
||||||
|
if (!(name = strchr(line, '\t')))
|
||||||
|
continue;
|
||||||
|
*name++ = '\0';
|
||||||
|
|
||||||
|
if (!(namespace = strchr(name, '\t')))
|
||||||
|
continue;
|
||||||
|
*namespace++ = '\0';
|
||||||
|
|
||||||
|
if (!(mod = strchr(namespace, '\t')))
|
||||||
|
continue;
|
||||||
|
*mod++ = '\0';
|
||||||
|
|
||||||
|
if ((tmp = strchr(mod, '\t')) != NULL) {
|
||||||
|
*tmp++ = '\0';
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* Looks like it's an old symvers file with no
|
||||||
|
* namespace column.
|
||||||
|
*/
|
||||||
|
mod = namespace;
|
||||||
|
}
|
||||||
|
|
||||||
symname = strdup(name);
|
symname = strdup(name);
|
||||||
if (!symname)
|
if (!symname)
|
||||||
perror("strdup");
|
perror("strdup");
|
||||||
|
Loading…
Reference in New Issue
Block a user