]>
glassweightruler.freedombox.rocks Git - Ventoy.git/blob - VtoyTool/vtoyksym.c
1 /******************************************************************************
2 * vtoyksym.c ---- ventoy ksym
4 * Copyright (c) 2021, longpanda <admin@ventoy.net>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 3 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
27 static int verbose
= 0;
28 #define debug(fmt, ...) if(verbose) printf(fmt, ##__VA_ARGS__)
30 int vtoyksym_main(int argc
, char **argv
)
33 unsigned long long addr1
= 0;
34 unsigned long long addr2
= 0;
37 const char *name
= NULL
;
40 for (i
= 0; i
< argc
; i
++)
42 if (argv
[i
][0] == '-' && argv
[i
][1] == 'p')
44 printf("%d", getpagesize());
49 for (i
= 0; i
< argc
; i
++)
51 if (argv
[i
][0] == '-' && argv
[i
][1] == 'v')
58 name
= argv
[2] ? argv
[2] : "/proc/kallsyms";
59 fp
= fopen(name
, "r");
62 fprintf(stderr
, "Failed to open file %s err:%d\n", name
, errno
);
66 debug("open %s success\n", name
);
68 snprintf(sym
, sizeof(sym
), " %s", argv
[1]);
69 debug("lookup for <%s>\n", sym
);
71 while (fgets(line
, sizeof(line
), fp
))
73 if (strstr(line
, sym
))
75 addr1
= strtoull(line
, NULL
, 16);
76 if (!fgets(line
, sizeof(line
), fp
))
79 fprintf(stderr
, "Failed to read next line\n");
83 addr2
= strtoull(line
, NULL
, 16);
86 debug("addr1=<0x%llx> addr2=<0x%llx>\n", addr1
, addr2
);
93 debug("Invalid addr range\n");
98 printf("0x%llx %llu\n", addr1
, addr2
- addr1
);
107 #ifndef BUILD_VTOY_TOOL
108 int main(int argc
, char **argv
)
110 return vtoyksym_main(argc
, argv
);