140
140
/* Function prototypes. */
141
static char * FindSymbolFile(void);
141
static char *FindSymbolFile(void);
142
142
static int AddSymbol(unsigned long, char*);
143
143
static void FreeSymbols(void);
144
144
static int CheckVersion(char *);
174
174
auto FILE *sym_file;
177
178
/* Check and make sure that we are starting with a clean slate. */
178
179
if ( num_syms > 0 )
183
* Search for and open the file containing the kernel symbols.
185
if ( mapfile != (char *) 0 ) {
186
if ( (sym_file = fopen(mapfile, "r")) == (FILE *) 0 )
183
/* Search for and open the file containing the kernel symbols. */
184
if ( mapfile != NULL ) {
185
if ( (sym_file = fopen(mapfile, "r")) == NULL )
188
Syslog(LOG_WARNING, "Cannot open map file: %s.", mapfile);
187
imklogLogIntMsg(LOG_WARNING, "Cannot open map file: %s.", mapfile);
192
if ( (mapfile = FindSymbolFile()) == (char *) 0 ) {
193
Syslog(LOG_WARNING, "Cannot find map file.");
191
if ( (mapfile = FindSymbolFile()) == NULL ) {
192
imklogLogIntMsg(LOG_WARNING, "Cannot find map file.");
194
193
dbgprintf("Cannot find map file.\n");
198
if ( (sym_file = fopen(mapfile, "r")) == (FILE *) 0 ) {
199
Syslog(LOG_WARNING, "Cannot open map file.");
197
if ( (sym_file = fopen(mapfile, "r")) == NULL ) {
198
imklogLogIntMsg(LOG_WARNING, "Cannot open map file.");
200
199
dbgprintf("Cannot open map file.\n");
207
* Read the kernel symbol table file and add entries for each
205
/* Read the kernel symbol table file and add entries for each
208
206
* line. I suspect that the use of fscanf is not really in vogue
209
207
* but it was quick and dirty and IMHO suitable for fixed format
210
208
* data such as this. If anybody doesn't agree with this please
214
212
while ( !feof(sym_file) ) {
215
213
if ( fscanf(sym_file, "%lx %c %s\n", &address, &type, sym) != 3 ) {
216
Syslog(LOG_ERR, "Error in symbol table input (#1).");
214
imklogLogIntMsg(LOG_ERR, "Error in symbol table input (#1).");
217
215
fclose(sym_file);
221
219
dbgprintf("Address: %lx, Type: %c, Symbol: %s\n", address, type, sym);
223
221
if ( AddSymbol(address, sym) == 0 ) {
224
Syslog(LOG_ERR, "Error adding symbol - %s.", sym);
222
imklogLogIntMsg(LOG_ERR, "Error adding symbol - %s.", sym);
225
223
fclose(sym_file);
234
Syslog(LOG_INFO, "Loaded %d symbols from %s.", num_syms, mapfile);
232
imklogLogIntMsg(LOG_INFO, "Loaded %d symbols from %s.", num_syms, mapfile);
235
233
switch(version) {
237
Syslog(LOG_WARNING, "Symbols do not match kernel version.");
235
imklogLogIntMsg(LOG_WARNING, "Symbols do not match kernel version.");
242
Syslog(LOG_WARNING, "Cannot verify that symbols match kernel version.");
240
imklogLogIntMsg(LOG_WARNING, "Cannot verify that symbols match kernel version.");
246
Syslog(LOG_INFO, "Symbols match kernel version %s.", vstring);
244
imklogLogIntMsg(LOG_INFO, "Symbols match kernel version %s.", vstring);
250
248
fclose(sym_file);
292
291
**************************************************************************/
293
292
static char *FindSymbolFile(void)
295
auto char *file = (char *) 0,
294
auto char *file = NULL,
296
295
**mf = system_maps;
298
296
auto struct utsname utsname;
299
static char symfile[100];
301
auto FILE *sym_file = (FILE *) 0;
303
if ( uname(&utsname) < 0 ) {
304
Syslog(LOG_ERR, "Cannot get kernel version information.");
297
static char mysymfile[100];
298
auto FILE *sym_file = NULL;
301
if(uname(&utsname) < 0) {
302
imklogLogIntMsg(LOG_ERR, "Cannot get kernel version information.");
308
306
dbgprintf("Searching for symbol map.\n");
310
for(mf = system_maps; *mf != (char *) 0 && file == (char *) 0; ++mf) {
312
snprintf(symfile, sizeof(symfile), "%s-%s", *mf, utsname.release);
313
dbgprintf("Trying %s.\n", symfile);
314
if ( (sym_file = fopen(symfile, "r")) != (FILE *) 0 ) {
315
if (CheckMapVersion(symfile) == 1)
308
for(mf = system_maps; *mf != NULL && file == NULL; ++mf) {
309
snprintf(mysymfile, sizeof(mysymfile), "%s-%s", *mf, utsname.release);
310
dbgprintf("Trying %s.\n", mysymfile);
311
if((sym_file = fopen(mysymfile, "r")) != NULL) {
312
if(CheckMapVersion(mysymfile) == 1)
317
314
fclose(sym_file);
319
if (sym_file == (FILE *) 0 || file == (char *) 0) {
320
sprintf (symfile, "%s", *mf);
321
dbgprintf("Trying %s.\n", symfile);
322
if ( (sym_file = fopen(symfile, "r")) != (FILE *) 0 ) {
323
if (CheckMapVersion(symfile) == 1)
316
if(sym_file == NULL || file == NULL) {
317
sprintf (mysymfile, "%s", *mf);
318
dbgprintf("Trying %s.\n", mysymfile);
319
if((sym_file = fopen(mysymfile, "r")) != NULL ) {
320
if (CheckMapVersion(mysymfile) == 1)
325
322
fclose(sym_file);
331
327
/* At this stage of the game we are at the end of the symbol tables. */
332
328
dbgprintf("End of search list encountered.\n");
412
409
if ( uname(&utsname) < 0 ) {
413
Syslog(LOG_ERR, "Cannot get kernel version information.");
410
imklogLogIntMsg(LOG_ERR, "Cannot get kernel version information.");
416
413
dbgprintf("Comparing kernel %s with symbol table %s.\n", utsname.release, vstring);
418
415
if ( sscanf (utsname.release, "%d.%d.%d", &major, &minor, &patch) < 3 ) {
419
Syslog(LOG_ERR, "Kernel send bogus release string `%s'.", utsname.release);
416
imklogLogIntMsg(LOG_ERR, "Kernel send bogus release string `%s'.", utsname.release);
467
if ( (sym_file = fopen(fname, "r")) != (FILE *) 0 ) {
464
if ( (sym_file = fopen(fname, "r")) != NULL ) {
469
466
* At this point a map file was successfully opened. We
470
467
* now need to search this file and look for version
473
Syslog(LOG_INFO, "Inspecting %s", fname);
470
imklogLogIntMsg(LOG_INFO, "Inspecting %s", fname);
476
473
while ( !feof(sym_file) && (version == 0) ) {
477
474
if ( fscanf(sym_file, "%lx %c %s\n", &address, &type, sym) != 3 ) {
478
Syslog(LOG_ERR, "Error in symbol table input (#2).");
475
imklogLogIntMsg(LOG_ERR, "Error in symbol table input (#2).");
479
476
fclose(sym_file);
683
680
* open for patches.
685
682
if ( i_am_paranoid &&
686
(strstr(line, "Oops:") != (char *) 0) && !InitMsyms() )
687
Syslog(LOG_WARNING, "Cannot load kernel module symbols.\n");
683
(strstr(line, "Oops:") != NULL) && !InitMsyms() )
684
imklogLogIntMsg(LOG_WARNING, "Cannot load kernel module symbols.\n");
788
785
strncpy(num,sl+1,kp-sl-1);
789
786
num[kp-sl-1] = '\0';
790
787
value = strtoul(num, (char **) 0, 16);
791
if ( (symbol = LookupSymbol(value, &sym)) == (char *) 0 )
788
if ( (symbol = LookupSymbol(value, &sym)) == NULL )
794
791
strcat(elp, symbol);