1997-06-02 22:51:41 +05:30
|
|
|
|
/*
|
|
|
|
|
ksym.c - functions for kernel address->symbol translation
|
1997-06-13 13:12:20 +05:30
|
|
|
|
Copyright (c) 1995, 1996 Dr. G.W. Wettstein <greg@wind.rmcc.com>
|
|
|
|
|
Copyright (c) 1996 Enjellic Systems Development
|
2007-05-28 20:56:09 +05:30
|
|
|
|
Copyright (c) 1997-2007 Martin Schulze <joey@infodrom.org>
|
1997-06-02 22:51:41 +05:30
|
|
|
|
|
|
|
|
|
This file is part of the sysklogd package, a kernel and system log daemon.
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This file contains functions which handle the translation of kernel
|
|
|
|
|
* numeric addresses into symbols for the klogd utility.
|
|
|
|
|
*
|
|
|
|
|
* Sat Oct 28 09:00:14 CDT 1995: Dr. Wettstein
|
|
|
|
|
* Initial Version.
|
|
|
|
|
*
|
|
|
|
|
* Fri Nov 24 12:50:52 CST 1995: Dr. Wettstein
|
|
|
|
|
* Added VERBOSE_DEBUGGING define to make debugging output more
|
|
|
|
|
* manageable.
|
|
|
|
|
*
|
|
|
|
|
* Added support for verification of the loaded kernel symbols. If
|
|
|
|
|
* no version information can be be found in the mapfile a warning
|
|
|
|
|
* message is issued but translation will still take place. This
|
|
|
|
|
* will be the default case if kernel versions < 1.3.43 are used.
|
|
|
|
|
*
|
|
|
|
|
* If the symbols in the mapfile are of the same version as the kernel
|
|
|
|
|
* that is running an informative message is issued. If the symbols
|
|
|
|
|
* in the mapfile do not match the current kernel version a warning
|
|
|
|
|
* message is issued and translation is disabled.
|
|
|
|
|
*
|
|
|
|
|
* Wed Dec 6 16:14:11 CST 1995: Dr. Wettstein
|
|
|
|
|
* Added /boot/System.map to the list of symbol maps to search for.
|
|
|
|
|
* Also made this map the first item in the search list. I am open
|
|
|
|
|
* to CONSTRUCTIVE suggestions for any additions or corrections to
|
|
|
|
|
* the list of symbol maps to search for. Be forewarned that the
|
|
|
|
|
* list in use is the consensus agreement between myself, Linus and
|
|
|
|
|
* some package distributers. It is a given that no list will suit
|
|
|
|
|
* everyone's taste. If you have rabid concerns about the list
|
|
|
|
|
* please feel free to edit the system_maps array and compile your
|
|
|
|
|
* own binaries.
|
|
|
|
|
*
|
|
|
|
|
* Added support for searching of the list of symbol maps. This
|
|
|
|
|
* allows support for access to multiple symbol maps. The theory
|
|
|
|
|
* behind this is that a production kernel may have a system map in
|
|
|
|
|
* /boot/System.map. If a test kernel is booted this system map
|
|
|
|
|
* would be skipped in favor of one found in /usr/src/linux.
|
|
|
|
|
*
|
|
|
|
|
* Thu Jan 18 11:18:31 CST 1996: Dr. Wettstein
|
|
|
|
|
* Added patch from beta-testers to allow for reading of both
|
|
|
|
|
* ELF and a.out map files.
|
|
|
|
|
*
|
1997-06-13 13:12:20 +05:30
|
|
|
|
* Wed Aug 21 09:15:49 CDT 1996: Dr. Wettstein
|
|
|
|
|
* Reloading of kernel module symbols is now turned on by the
|
|
|
|
|
* SetParanoiaLevel function. The default behavior is to NOT reload
|
|
|
|
|
* the kernel module symbols when a protection fault is detected.
|
|
|
|
|
*
|
|
|
|
|
* Added support for freeing of the current kernel module symbols.
|
|
|
|
|
* This was necessary to support reloading of the kernel module symbols.
|
|
|
|
|
*
|
|
|
|
|
* When a matching static symbol table is loaded the kernel version
|
|
|
|
|
* number is printed.
|
|
|
|
|
*
|
1997-06-11 02:36:52 +05:30
|
|
|
|
* Mon Jun 9 17:12:42 CST 1997: Martin Schulze
|
|
|
|
|
* Added #1 and #2 to some error messages in order to being able
|
|
|
|
|
* to divide them (ulmo@Q.Net)
|
1997-06-13 15:05:55 +05:30
|
|
|
|
*
|
|
|
|
|
* Fri Jun 13 10:50:23 CST 1997: Martin Schulze
|
|
|
|
|
* Changed definition of LookupSymbol to non-static because it is
|
|
|
|
|
* used in klogd.c, too.
|
1998-01-10 23:32:57 +05:30
|
|
|
|
*
|
|
|
|
|
* Fri Jan 9 23:00:08 CET 1998: Martin Schulze <joey@infodrom.north.de>
|
|
|
|
|
* Fixed bug that caused klogd to die if there is no System.map available.
|
1998-04-14 04:57:37 +05:30
|
|
|
|
*
|
1998-04-14 05:16:21 +05:30
|
|
|
|
* Sun 29 Mar 18:14:07 BST 1998: Mark Simon Phillips <M.S.Phillips@nortel.co.uk>
|
1998-04-14 04:57:37 +05:30
|
|
|
|
* Switched to fgets() as gets() is not buffer overrun secure.
|
|
|
|
|
*
|
|
|
|
|
* Mon Apr 13 18:18:45 CEST 1998: Martin Schulze <joey@infodrom.north.de>
|
|
|
|
|
* Modified loop for detecting the correct system map. Now it won't
|
|
|
|
|
* stop if a file has been found but doesn't contain the correct map.
|
|
|
|
|
* Special thanks go go Mark Simon Phillips for the hint.
|
1998-10-12 22:09:49 +05:30
|
|
|
|
*
|
|
|
|
|
* Mon Oct 12 00:42:30 CEST 1998: Martin Schulze <joey@infodrom.north.de>
|
|
|
|
|
* Modified CheckVersion()
|
|
|
|
|
* . Use shift to decode the kernel version
|
|
|
|
|
* . Compare integers of kernel version
|
|
|
|
|
* . extract major.minor.patch from utsname.release via sscanf()
|
|
|
|
|
* The reason lays in possible use of kernel flavours which
|
|
|
|
|
* modify utsname.release but no the Version_ symbol.
|
2000-09-13 02:45:28 +05:30
|
|
|
|
*
|
|
|
|
|
* Sun Feb 21 22:27:49 EST 1999: Keith Owens <kaos@ocs.com.au>
|
|
|
|
|
* Fixed bug that caused klogd to die if there is no sym_array available.
|
2000-09-13 03:23:31 +05:30
|
|
|
|
*
|
|
|
|
|
* Tue Sep 12 23:48:12 CEST 2000: Martin Schulze <joey@infodrom.ffis.de>
|
|
|
|
|
* Close symbol file in InitKsyms() when an error occurred.
|
2004-04-29 21:40:10 +05:30
|
|
|
|
*
|
|
|
|
|
* Thu Apr 29 18:07:16 CEST 2004: Dmitry Levin <ldv@altlinux.org>
|
|
|
|
|
* Close file descriptor in FindSymbolFile() in order not to leak
|
|
|
|
|
* file descriptors.
|
2004-07-16 12:18:27 +05:30
|
|
|
|
*
|
|
|
|
|
* Fri Jul 16 08:32:49 CEST 2004: Ulf H<EFBFBD>rnhammar <Ulf.Harnhammar.9485@student.uu.se>
|
|
|
|
|
* Added boundary check for fscanf() in InitKsyms() and
|
|
|
|
|
* CheckMapVersion() to prevent an unintended crash when reading
|
|
|
|
|
* an incorrect System.map.
|
2007-05-28 11:58:37 +05:30
|
|
|
|
*
|
|
|
|
|
* Mon May 28 08:27:51 CEST 2007: Martin Schulze <joey@infodrom.org>
|
|
|
|
|
* Added back /usr/src/linux/System.map as fall-back location.
|
2007-05-31 20:53:42 +05:30
|
|
|
|
*
|
|
|
|
|
* Thu May 31 16:56:26 CEST 2007: Martin Schulze <joey@infodrom.org>
|
|
|
|
|
* Improved symbol lookup, since symbols are spread over the entire
|
|
|
|
|
* address space. Return the symbol that fits best instead of
|
|
|
|
|
* the first hit.
|
1997-06-02 22:51:41 +05:30
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Includes. */
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <malloc.h>
|
|
|
|
|
#include <sys/utsname.h>
|
|
|
|
|
#include "klogd.h"
|
1997-06-13 13:12:20 +05:30
|
|
|
|
#include "ksyms.h"
|
2007-05-28 20:56:09 +05:30
|
|
|
|
#include "module.h"
|
1997-06-02 22:51:41 +05:30
|
|
|
|
|
|
|
|
|
#define VERBOSE_DEBUGGING 0
|
|
|
|
|
|
|
|
|
|
|
2007-05-31 20:22:20 +05:30
|
|
|
|
int num_syms = 0;
|
1997-06-13 13:12:20 +05:30
|
|
|
|
static int i_am_paranoid = 0;
|
|
|
|
|
static char vstring[12];
|
|
|
|
|
static struct sym_table *sym_array = (struct sym_table *) 0;
|
1997-06-02 22:51:41 +05:30
|
|
|
|
|
|
|
|
|
static char *system_maps[] =
|
|
|
|
|
{
|
1997-06-02 23:12:34 +05:30
|
|
|
|
"/boot/System.map",
|
1998-01-02 08:37:16 +05:30
|
|
|
|
"/System.map",
|
2007-05-28 11:58:37 +05:30
|
|
|
|
"/usr/src/linux/System.map",
|
1997-06-02 22:51:41 +05:30
|
|
|
|
#if defined(TEST)
|
|
|
|
|
"./System.map",
|
|
|
|
|
#endif
|
|
|
|
|
(char *) 0
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(TEST)
|
1997-06-13 13:12:20 +05:30
|
|
|
|
int debugging;
|
1997-06-02 22:51:41 +05:30
|
|
|
|
#else
|
|
|
|
|
extern int debugging;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Function prototypes. */
|
|
|
|
|
static char * FindSymbolFile(void);
|
|
|
|
|
static int AddSymbol(unsigned long, char*);
|
1997-06-13 13:12:20 +05:30
|
|
|
|
static void FreeSymbols(void);
|
1997-06-02 22:51:41 +05:30
|
|
|
|
static int CheckVersion(char *);
|
1998-04-14 04:57:37 +05:30
|
|
|
|
static int CheckMapVersion(char *);
|
1997-06-02 22:51:41 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
|
* Function: InitKsyms
|
|
|
|
|
*
|
|
|
|
|
* Purpose: This function is responsible for initializing and loading
|
|
|
|
|
* the data tables used by the kernel address translations.
|
|
|
|
|
*
|
2007-05-31 00:16:09 +05:30
|
|
|
|
* Arguments: (char *) mapfile
|
1997-06-02 22:51:41 +05:30
|
|
|
|
*
|
|
|
|
|
* mapfile:-> A pointer to a complete path
|
|
|
|
|
* specification of the file containing
|
|
|
|
|
* the kernel map to use.
|
|
|
|
|
*
|
|
|
|
|
* Return: int
|
|
|
|
|
*
|
|
|
|
|
* A boolean style context is returned. The return value will
|
|
|
|
|
* be true if initialization was successful. False if not.
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
extern int InitKsyms(mapfile)
|
|
|
|
|
|
|
|
|
|
char *mapfile;
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
auto char type,
|
|
|
|
|
sym[512];
|
|
|
|
|
|
|
|
|
|
auto int version = 0;
|
|
|
|
|
|
|
|
|
|
auto unsigned long int address;
|
|
|
|
|
|
|
|
|
|
auto FILE *sym_file;
|
|
|
|
|
|
|
|
|
|
|
1997-06-13 13:12:20 +05:30
|
|
|
|
/* Check and make sure that we are starting with a clean slate. */
|
|
|
|
|
if ( num_syms > 0 )
|
|
|
|
|
FreeSymbols();
|
|
|
|
|
|
|
|
|
|
|
1997-06-02 22:51:41 +05:30
|
|
|
|
/*
|
|
|
|
|
* Search for and open the file containing the kernel symbols.
|
|
|
|
|
*/
|
|
|
|
|
if ( mapfile != (char *) 0 )
|
|
|
|
|
{
|
|
|
|
|
if ( (sym_file = fopen(mapfile, "r")) == (FILE *) 0 )
|
|
|
|
|
{
|
|
|
|
|
Syslog(LOG_WARNING, "Cannot open map file: %s.", \
|
|
|
|
|
mapfile);
|
|
|
|
|
return(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if ( (mapfile = FindSymbolFile()) == (char *) 0 )
|
|
|
|
|
{
|
|
|
|
|
Syslog(LOG_WARNING, "Cannot find map file.");
|
|
|
|
|
if ( debugging )
|
|
|
|
|
fputs("Cannot find map file.\n", stderr);
|
|
|
|
|
return(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( (sym_file = fopen(mapfile, "r")) == (FILE *) 0 )
|
|
|
|
|
{
|
|
|
|
|
Syslog(LOG_WARNING, "Cannot open map file.");
|
|
|
|
|
if ( debugging )
|
|
|
|
|
fputs("Cannot open map file.\n", stderr);
|
|
|
|
|
return(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Read the kernel symbol table file and add entries for each
|
|
|
|
|
* line. I suspect that the use of fscanf is not really in vogue
|
|
|
|
|
* but it was quick and dirty and IMHO suitable for fixed format
|
|
|
|
|
* data such as this. If anybody doesn't agree with this please
|
|
|
|
|
* e-mail me a diff containing a parser with suitable political
|
|
|
|
|
* correctness -- GW.
|
|
|
|
|
*/
|
|
|
|
|
while ( !feof(sym_file) )
|
|
|
|
|
{
|
2004-07-16 12:18:27 +05:30
|
|
|
|
if ( fscanf(sym_file, "%lx %c %511s\n", &address, &type, sym)
|
1997-06-02 22:51:41 +05:30
|
|
|
|
!= 3 )
|
|
|
|
|
{
|
1997-06-11 02:36:52 +05:30
|
|
|
|
Syslog(LOG_ERR, "Error in symbol table input (#1).");
|
1997-06-02 22:51:41 +05:30
|
|
|
|
fclose(sym_file);
|
|
|
|
|
return(0);
|
|
|
|
|
}
|
|
|
|
|
if ( VERBOSE_DEBUGGING && debugging )
|
|
|
|
|
fprintf(stderr, "Address: %lx, Type: %c, Symbol: %s\n",
|
|
|
|
|
address, type, sym);
|
|
|
|
|
|
|
|
|
|
if ( AddSymbol(address, sym) == 0 )
|
|
|
|
|
{
|
|
|
|
|
Syslog(LOG_ERR, "Error adding symbol - %s.", sym);
|
2000-09-13 03:23:31 +05:30
|
|
|
|
fclose(sym_file);
|
1997-06-02 22:51:41 +05:30
|
|
|
|
return(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( version == 0 )
|
|
|
|
|
version = CheckVersion(sym);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Syslog(LOG_INFO, "Loaded %d symbols from %s.", num_syms, mapfile);
|
|
|
|
|
switch ( version )
|
|
|
|
|
{
|
|
|
|
|
case -1:
|
|
|
|
|
Syslog(LOG_WARNING, "Symbols do not match kernel version.");
|
|
|
|
|
num_syms = 0;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
|
Syslog(LOG_WARNING, "Cannot verify that symbols match " \
|
|
|
|
|
"kernel version.");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 1:
|
1997-06-13 13:12:20 +05:30
|
|
|
|
Syslog(LOG_INFO, "Symbols match kernel version %s.", vstring);
|
1997-06-02 22:51:41 +05:30
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fclose(sym_file);
|
|
|
|
|
return(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
|
* Function: FindSymbolFile
|
|
|
|
|
*
|
|
|
|
|
* Purpose: This function is responsible for encapsulating the search
|
|
|
|
|
* for a valid symbol file. Encapsulating the search for
|
|
|
|
|
* the map file in this function allows an intelligent search
|
|
|
|
|
* process to be implemented.
|
|
|
|
|
*
|
|
|
|
|
* The list of symbol files will be searched until either a
|
|
|
|
|
* symbol file is found whose version matches the currently
|
|
|
|
|
* executing kernel or the end of the list is encountered. If
|
|
|
|
|
* the end of the list is encountered the first available
|
|
|
|
|
* symbol file is returned to the caller.
|
|
|
|
|
*
|
|
|
|
|
* This strategy allows klogd to locate valid symbol files
|
|
|
|
|
* for both a production and an experimental kernel. For
|
|
|
|
|
* example a map for a production kernel could be installed
|
|
|
|
|
* in /boot. If an experimental kernel is loaded the map
|
|
|
|
|
* in /boot will be skipped and the map in /usr/src/linux would
|
|
|
|
|
* be used if its version number matches the executing kernel.
|
|
|
|
|
*
|
2007-05-31 00:16:09 +05:30
|
|
|
|
* Arguments: None specified.
|
1997-06-02 22:51:41 +05:30
|
|
|
|
*
|
|
|
|
|
* Return: char *
|
|
|
|
|
*
|
|
|
|
|
* If a valid system map cannot be located a null pointer
|
|
|
|
|
* is returned to the caller.
|
|
|
|
|
*
|
|
|
|
|
* If the search is succesful a pointer is returned to the
|
|
|
|
|
* caller which points to the name of the file containing
|
|
|
|
|
* the symbol table to be used.
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
static char * FindSymbolFile()
|
|
|
|
|
|
|
|
|
|
{
|
1998-04-14 04:57:37 +05:30
|
|
|
|
auto char *file = (char *) 0,
|
|
|
|
|
**mf = system_maps;
|
1997-06-02 22:51:41 +05:30
|
|
|
|
|
1997-06-11 02:36:52 +05:30
|
|
|
|
auto struct utsname utsname;
|
1997-06-13 13:12:20 +05:30
|
|
|
|
static char symfile[100];
|
1997-06-11 02:36:52 +05:30
|
|
|
|
|
1997-06-02 22:51:41 +05:30
|
|
|
|
auto FILE *sym_file = (FILE *) 0;
|
|
|
|
|
|
1997-06-11 02:36:52 +05:30
|
|
|
|
if ( uname(&utsname) < 0 )
|
|
|
|
|
{
|
|
|
|
|
Syslog(LOG_ERR, "Cannot get kernel version information.");
|
|
|
|
|
return(0);
|
|
|
|
|
}
|
1997-06-02 22:51:41 +05:30
|
|
|
|
|
|
|
|
|
if ( debugging )
|
|
|
|
|
fputs("Searching for symbol map.\n", stderr);
|
|
|
|
|
|
1998-04-14 04:57:37 +05:30
|
|
|
|
for (mf = system_maps; *mf != (char *) 0 && file == (char *) 0; ++mf)
|
1997-06-02 22:51:41 +05:30
|
|
|
|
{
|
1998-04-14 04:57:37 +05:30
|
|
|
|
|
1998-01-02 08:37:16 +05:30
|
|
|
|
sprintf (symfile, "%s-%s", *mf, utsname.release);
|
1997-06-02 22:51:41 +05:30
|
|
|
|
if ( debugging )
|
1997-06-11 02:36:52 +05:30
|
|
|
|
fprintf(stderr, "Trying %s.\n", symfile);
|
1998-04-14 04:57:37 +05:30
|
|
|
|
if ( (sym_file = fopen(symfile, "r")) != (FILE *) 0 ) {
|
|
|
|
|
if (CheckMapVersion(symfile) == 1)
|
|
|
|
|
file = symfile;
|
2004-04-29 21:40:10 +05:30
|
|
|
|
fclose (sym_file);
|
1997-06-02 22:51:41 +05:30
|
|
|
|
}
|
1998-04-14 04:57:37 +05:30
|
|
|
|
if (sym_file == (FILE *) 0 || file == (char *) 0) {
|
|
|
|
|
sprintf (symfile, "%s", *mf);
|
1997-06-02 22:51:41 +05:30
|
|
|
|
if ( debugging )
|
1998-04-14 04:57:37 +05:30
|
|
|
|
fprintf(stderr, "Trying %s.\n", symfile);
|
|
|
|
|
if ( (sym_file = fopen(symfile, "r")) != (FILE *) 0 ) {
|
|
|
|
|
if (CheckMapVersion(symfile) == 1)
|
|
|
|
|
file = symfile;
|
2004-04-29 21:40:10 +05:30
|
|
|
|
fclose (sym_file);
|
1997-06-02 22:51:41 +05:30
|
|
|
|
}
|
|
|
|
|
}
|
1998-04-14 04:57:37 +05:30
|
|
|
|
|
1998-01-10 23:32:57 +05:30
|
|
|
|
}
|
1997-06-02 22:51:41 +05:30
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* At this stage of the game we are at the end of the symbol
|
1998-04-14 04:57:37 +05:30
|
|
|
|
* tables.
|
1997-06-02 22:51:41 +05:30
|
|
|
|
*/
|
|
|
|
|
if ( debugging )
|
|
|
|
|
fprintf(stderr, "End of search list encountered.\n");
|
|
|
|
|
return(file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
|
* Function: CheckVersion
|
|
|
|
|
*
|
|
|
|
|
* Purpose: This function is responsible for determining whether or
|
|
|
|
|
* the system map being loaded matches the version of the
|
1998-04-14 04:57:37 +05:30
|
|
|
|
* currently running kernel.
|
1997-06-02 22:51:41 +05:30
|
|
|
|
*
|
|
|
|
|
* The kernel version is checked by examing a variable which
|
|
|
|
|
* is of the form: _Version_66347 (a.out) or Version_66437 (ELF).
|
|
|
|
|
*
|
|
|
|
|
* The suffix of this variable is the current kernel version
|
|
|
|
|
* of the kernel encoded in base 256. For example the
|
|
|
|
|
* above variable would be decoded as:
|
|
|
|
|
*
|
|
|
|
|
* (66347 = 1*65536 + 3*256 + 43 = 1.3.43)
|
|
|
|
|
*
|
|
|
|
|
* (Insert appropriate deities here) help us if Linus ever
|
|
|
|
|
* needs more than 255 patch levels to get a kernel out the
|
|
|
|
|
* door... :-)
|
|
|
|
|
*
|
2007-05-31 00:16:09 +05:30
|
|
|
|
* Arguments: (char *) version
|
1997-06-02 22:51:41 +05:30
|
|
|
|
*
|
|
|
|
|
* version:-> A pointer to the string which
|
|
|
|
|
* is to be decoded as a kernel
|
|
|
|
|
* version variable.
|
|
|
|
|
*
|
|
|
|
|
* Return: int
|
|
|
|
|
*
|
|
|
|
|
* -1:-> The currently running kernel version does
|
|
|
|
|
* not match this version string.
|
|
|
|
|
*
|
|
|
|
|
* 0:-> The string is not a kernel version variable.
|
|
|
|
|
*
|
|
|
|
|
* 1:-> The executing kernel is of the same version
|
|
|
|
|
* as the version string.
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
static int CheckVersion(version)
|
|
|
|
|
|
|
|
|
|
char *version;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
auto int vnum,
|
|
|
|
|
major,
|
|
|
|
|
minor,
|
|
|
|
|
patch;
|
|
|
|
|
|
1998-10-12 22:09:49 +05:30
|
|
|
|
#ifndef TESTING
|
|
|
|
|
int kvnum;
|
1997-06-02 22:51:41 +05:30
|
|
|
|
auto struct utsname utsname;
|
1998-10-12 22:09:49 +05:30
|
|
|
|
#endif
|
1997-06-02 22:51:41 +05:30
|
|
|
|
|
|
|
|
|
static char *prefix = { "Version_" };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Early return if there is no hope. */
|
|
|
|
|
if ( strncmp(version, prefix, strlen(prefix)) == 0 /* ELF */ ||
|
|
|
|
|
(*version == '_' &&
|
|
|
|
|
strncmp(++version, prefix, strlen(prefix)) == 0 ) /* a.out */ )
|
|
|
|
|
;
|
|
|
|
|
else
|
|
|
|
|
return(0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Since the symbol looks like a kernel version we can start
|
|
|
|
|
* things out by decoding the version string into its component
|
|
|
|
|
* parts.
|
|
|
|
|
*/
|
1997-06-13 13:12:20 +05:30
|
|
|
|
vnum = atoi(version + strlen(prefix));
|
1998-10-12 22:09:49 +05:30
|
|
|
|
patch = vnum & 0x000000FF;
|
|
|
|
|
minor = (vnum >> 8) & 0x000000FF;
|
|
|
|
|
major = (vnum >> 16) & 0x000000FF;
|
1997-06-02 22:51:41 +05:30
|
|
|
|
if ( debugging )
|
|
|
|
|
fprintf(stderr, "Version string = %s, Major = %d, " \
|
1997-06-13 13:12:20 +05:30
|
|
|
|
"Minor = %d, Patch = %d.\n", version +
|
|
|
|
|
strlen(prefix), major, minor, \
|
1997-06-02 22:51:41 +05:30
|
|
|
|
patch);
|
|
|
|
|
sprintf(vstring, "%d.%d.%d", major, minor, patch);
|
|
|
|
|
|
1998-10-12 22:09:49 +05:30
|
|
|
|
#ifndef TESTING
|
1997-06-02 22:51:41 +05:30
|
|
|
|
/*
|
|
|
|
|
* We should now have the version string in the vstring variable in
|
|
|
|
|
* the same format that it is stored in by the kernel. We now
|
|
|
|
|
* ask the kernel for its version information and compare the two
|
|
|
|
|
* values to determine if our system map matches the kernel
|
|
|
|
|
* version level.
|
|
|
|
|
*/
|
|
|
|
|
if ( uname(&utsname) < 0 )
|
|
|
|
|
{
|
|
|
|
|
Syslog(LOG_ERR, "Cannot get kernel version information.");
|
|
|
|
|
return(0);
|
|
|
|
|
}
|
|
|
|
|
if ( debugging )
|
|
|
|
|
fprintf(stderr, "Comparing kernel %s with symbol table %s.\n",\
|
|
|
|
|
utsname.release, vstring);
|
|
|
|
|
|
1998-10-12 22:09:49 +05:30
|
|
|
|
if ( sscanf (utsname.release, "%d.%d.%d", &major, &minor, &patch) < 3 )
|
|
|
|
|
{
|
|
|
|
|
Syslog(LOG_ERR, "Kernel send bogus release string `%s'.",
|
|
|
|
|
utsname.release);
|
|
|
|
|
return(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Compute the version code from data sent by the kernel */
|
|
|
|
|
kvnum = (major << 16) | (minor << 8) | patch;
|
|
|
|
|
|
1997-06-02 22:51:41 +05:30
|
|
|
|
/* Failure. */
|
1998-10-12 22:09:49 +05:30
|
|
|
|
if ( vnum != kvnum )
|
1997-06-02 22:51:41 +05:30
|
|
|
|
return(-1);
|
|
|
|
|
|
|
|
|
|
/* Success. */
|
1998-10-12 22:09:49 +05:30
|
|
|
|
#endif
|
1997-06-02 22:51:41 +05:30
|
|
|
|
return(1);
|
|
|
|
|
}
|
|
|
|
|
|
1998-04-14 04:57:37 +05:30
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
|
* Function: CheckMapVersion
|
|
|
|
|
*
|
|
|
|
|
* Purpose: This function is responsible for determining whether or
|
|
|
|
|
* the system map being loaded matches the version of the
|
|
|
|
|
* currently running kernel. It uses CheckVersion as
|
|
|
|
|
* backend.
|
|
|
|
|
*
|
2007-05-31 00:16:09 +05:30
|
|
|
|
* Arguments: (char *) fname
|
1998-04-14 04:57:37 +05:30
|
|
|
|
*
|
|
|
|
|
* fname:-> A pointer to the string which
|
|
|
|
|
* references the system map file to
|
|
|
|
|
* be used.
|
|
|
|
|
*
|
|
|
|
|
* Return: int
|
|
|
|
|
*
|
|
|
|
|
* -1:-> The currently running kernel version does
|
|
|
|
|
* not match the version in the given file.
|
|
|
|
|
*
|
|
|
|
|
* 0:-> No system map file or no version information.
|
|
|
|
|
*
|
|
|
|
|
* 1:-> The executing kernel is of the same version
|
|
|
|
|
* as the version of the map file.
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
static int CheckMapVersion(fname)
|
|
|
|
|
|
|
|
|
|
char *fname;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
int version;
|
|
|
|
|
FILE *sym_file;
|
|
|
|
|
auto unsigned long int address;
|
|
|
|
|
auto char type,
|
|
|
|
|
sym[512];
|
|
|
|
|
|
|
|
|
|
if ( (sym_file = fopen(fname, "r")) != (FILE *) 0 ) {
|
|
|
|
|
/*
|
|
|
|
|
* At this point a map file was successfully opened. We
|
|
|
|
|
* now need to search this file and look for version
|
|
|
|
|
* information.
|
|
|
|
|
*/
|
|
|
|
|
Syslog(LOG_INFO, "Inspecting %s", fname);
|
|
|
|
|
|
|
|
|
|
version = 0;
|
|
|
|
|
while ( !feof(sym_file) && (version == 0) )
|
|
|
|
|
{
|
2004-07-16 12:18:27 +05:30
|
|
|
|
if ( fscanf(sym_file, "%lx %c %511s\n", &address, \
|
1998-04-14 04:57:37 +05:30
|
|
|
|
&type, sym) != 3 )
|
|
|
|
|
{
|
|
|
|
|
Syslog(LOG_ERR, "Error in symbol table input (#2).");
|
|
|
|
|
fclose(sym_file);
|
|
|
|
|
return(0);
|
|
|
|
|
}
|
|
|
|
|
if ( VERBOSE_DEBUGGING && debugging )
|
|
|
|
|
fprintf(stderr, "Address: %lx, Type: %c, " \
|
|
|
|
|
"Symbol: %s\n", address, type, sym);
|
|
|
|
|
|
|
|
|
|
version = CheckVersion(sym);
|
|
|
|
|
}
|
|
|
|
|
fclose(sym_file);
|
|
|
|
|
|
|
|
|
|
switch ( version )
|
|
|
|
|
{
|
|
|
|
|
case -1:
|
|
|
|
|
Syslog(LOG_ERR, "Symbol table has incorrect " \
|
|
|
|
|
"version number.\n");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
|
if ( debugging )
|
|
|
|
|
fprintf(stderr, "No version information " \
|
|
|
|
|
"found.\n");
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
if ( debugging )
|
|
|
|
|
fprintf(stderr, "Found table with " \
|
|
|
|
|
"matching version number.\n");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return(version);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
|
}
|
|
|
|
|
|
1997-06-02 22:51:41 +05:30
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
|
* Function: AddSymbol
|
|
|
|
|
*
|
|
|
|
|
* Purpose: This function is responsible for adding a symbol name
|
|
|
|
|
* and its address to the symbol table.
|
|
|
|
|
*
|
2007-05-31 00:16:09 +05:30
|
|
|
|
* Arguments: (unsigned long) address, (char *) symbol
|
1997-06-02 22:51:41 +05:30
|
|
|
|
*
|
|
|
|
|
* Return: int
|
|
|
|
|
*
|
|
|
|
|
* A boolean value is assumed. True if the addition is
|
|
|
|
|
* successful. False if not.
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
static int AddSymbol(address, symbol)
|
|
|
|
|
|
|
|
|
|
unsigned long address;
|
|
|
|
|
|
|
|
|
|
char *symbol;
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
/* Allocate the the symbol table entry. */
|
|
|
|
|
sym_array = (struct sym_table *) realloc(sym_array, (num_syms+1) * \
|
|
|
|
|
sizeof(struct sym_table));
|
|
|
|
|
if ( sym_array == (struct sym_table *) 0 )
|
|
|
|
|
return(0);
|
|
|
|
|
|
|
|
|
|
/* Then the space for the symbol. */
|
|
|
|
|
sym_array[num_syms].name = (char *) malloc(strlen(symbol)*sizeof(char)\
|
|
|
|
|
+ 1);
|
|
|
|
|
if ( sym_array[num_syms].name == (char *) 0 )
|
|
|
|
|
return(0);
|
|
|
|
|
|
|
|
|
|
sym_array[num_syms].value = address;
|
|
|
|
|
strcpy(sym_array[num_syms].name, symbol);
|
|
|
|
|
++num_syms;
|
|
|
|
|
return(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
|
* Function: LookupSymbol
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Find the symbol which is related to the given kernel
|
|
|
|
|
* address.
|
|
|
|
|
*
|
2007-05-31 00:16:09 +05:30
|
|
|
|
* Arguments: (long int) value, (struct symbol *) sym
|
1997-06-02 22:51:41 +05:30
|
|
|
|
*
|
|
|
|
|
* value:-> The address to be located.
|
|
|
|
|
*
|
|
|
|
|
* sym:-> A pointer to a structure which will be
|
|
|
|
|
* loaded with the symbol's parameters.
|
|
|
|
|
*
|
|
|
|
|
* Return: (char *)
|
|
|
|
|
*
|
|
|
|
|
* If a match cannot be found a diagnostic string is printed.
|
|
|
|
|
* If a match is found the pointer to the symbolic name most
|
|
|
|
|
* closely matching the address is returned.
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
1997-06-13 15:05:55 +05:30
|
|
|
|
char * LookupSymbol(value, sym)
|
1997-06-02 22:51:41 +05:30
|
|
|
|
|
|
|
|
|
unsigned long value;
|
|
|
|
|
|
|
|
|
|
struct symbol *sym;
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
auto int lp;
|
|
|
|
|
|
2000-09-13 02:45:28 +05:30
|
|
|
|
auto char *last;
|
2007-05-31 20:53:42 +05:30
|
|
|
|
auto char *name;
|
|
|
|
|
|
|
|
|
|
struct symbol ksym, msym;
|
1997-06-02 22:51:41 +05:30
|
|
|
|
|
2000-09-13 02:45:28 +05:30
|
|
|
|
if (!sym_array)
|
|
|
|
|
return((char *) 0);
|
1997-06-02 22:51:41 +05:30
|
|
|
|
|
2000-09-13 02:45:28 +05:30
|
|
|
|
last = sym_array[0].name;
|
2007-05-31 20:53:42 +05:30
|
|
|
|
ksym.offset = 0;
|
|
|
|
|
ksym.size = 0;
|
1997-06-02 22:51:41 +05:30
|
|
|
|
if ( value < sym_array[0].value )
|
|
|
|
|
return((char *) 0);
|
|
|
|
|
|
2007-05-31 00:16:09 +05:30
|
|
|
|
for(lp = 0; lp <= num_syms; ++lp)
|
1997-06-02 22:51:41 +05:30
|
|
|
|
{
|
|
|
|
|
if ( sym_array[lp].value > value )
|
|
|
|
|
{
|
2007-05-31 20:53:42 +05:30
|
|
|
|
ksym.offset = value - sym_array[lp-1].value;
|
|
|
|
|
ksym.size = sym_array[lp].value - \
|
1997-06-02 22:51:41 +05:30
|
|
|
|
sym_array[lp-1].value;
|
2007-05-31 20:53:42 +05:30
|
|
|
|
break;
|
1997-06-02 22:51:41 +05:30
|
|
|
|
}
|
|
|
|
|
last = sym_array[lp].name;
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-31 20:53:42 +05:30
|
|
|
|
name = LookupModuleSymbol(value, &msym);
|
|
|
|
|
|
|
|
|
|
if ( ksym.offset == 0 && msym.offset == 0 )
|
|
|
|
|
{
|
|
|
|
|
return((char *) 0);
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-03 00:38:52 +05:30
|
|
|
|
if ( ksym.offset == 0 || msym.offset < 0 ||
|
|
|
|
|
(ksym.offset > 0 && ksym.offset < msym.offset) )
|
2007-05-31 20:53:42 +05:30
|
|
|
|
{
|
|
|
|
|
sym->offset = ksym.offset;
|
|
|
|
|
sym->size = ksym.size;
|
1997-06-13 13:12:20 +05:30
|
|
|
|
return(last);
|
2007-05-31 20:53:42 +05:30
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
sym->offset = msym.offset;
|
|
|
|
|
sym->size = msym.size;
|
|
|
|
|
return(name);
|
|
|
|
|
}
|
|
|
|
|
|
1997-06-13 13:12:20 +05:30
|
|
|
|
|
1997-06-02 22:51:41 +05:30
|
|
|
|
return((char *) 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1997-06-13 13:12:20 +05:30
|
|
|
|
/**************************************************************************
|
|
|
|
|
* Function: FreeSymbols
|
|
|
|
|
*
|
|
|
|
|
* Purpose: This function is responsible for freeing all memory which
|
|
|
|
|
* has been allocated to hold the static symbol table. It
|
|
|
|
|
* also initializes the symbol count and in general prepares
|
|
|
|
|
* for a re-read of a static symbol table.
|
|
|
|
|
*
|
2007-05-31 00:16:09 +05:30
|
|
|
|
* Arguments: void
|
1997-06-13 13:12:20 +05:30
|
|
|
|
*
|
|
|
|
|
* Return: void
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void FreeSymbols()
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
auto int lp;
|
|
|
|
|
|
|
|
|
|
/* Free each piece of memory allocated for symbol names. */
|
2007-05-31 00:16:09 +05:30
|
|
|
|
for(lp = 0; lp < num_syms; ++lp)
|
1997-06-13 13:12:20 +05:30
|
|
|
|
free(sym_array[lp].name);
|
|
|
|
|
|
|
|
|
|
/* Whack the entire array and initialize everything. */
|
|
|
|
|
free(sym_array);
|
|
|
|
|
sym_array = (struct sym_table *) 0;
|
|
|
|
|
num_syms = 0;
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1997-06-02 22:51:41 +05:30
|
|
|
|
/**************************************************************************
|
|
|
|
|
* Function: LogExpanded
|
|
|
|
|
*
|
|
|
|
|
* Purpose: This function is responsible for logging a kernel message
|
|
|
|
|
* line after all potential numeric kernel addresses have
|
|
|
|
|
* been resolved symolically.
|
|
|
|
|
*
|
2007-05-31 00:16:09 +05:30
|
|
|
|
* Arguments: (char *) line, (char *) el
|
1997-06-02 22:51:41 +05:30
|
|
|
|
*
|
|
|
|
|
* line:-> A pointer to the buffer containing the kernel
|
|
|
|
|
* message to be expanded and logged.
|
|
|
|
|
*
|
|
|
|
|
* el:-> A pointer to the buffer into which the expanded
|
|
|
|
|
* kernel line will be written.
|
|
|
|
|
*
|
|
|
|
|
* Return: void
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
extern char * ExpandKadds(line, el)
|
|
|
|
|
|
|
|
|
|
char *line;
|
|
|
|
|
|
|
|
|
|
char *el;
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
auto char dlm,
|
|
|
|
|
*kp,
|
|
|
|
|
*sl = line,
|
|
|
|
|
*elp = el,
|
|
|
|
|
*symbol;
|
|
|
|
|
|
1998-01-02 08:37:16 +05:30
|
|
|
|
char num[15];
|
1998-04-14 04:57:37 +05:30
|
|
|
|
auto unsigned long int value;
|
1997-06-02 22:51:41 +05:30
|
|
|
|
|
|
|
|
|
auto struct symbol sym;
|
1997-06-13 13:12:20 +05:30
|
|
|
|
|
2007-05-31 20:53:42 +05:30
|
|
|
|
sym.offset = 0;
|
|
|
|
|
sym.size = 0;
|
1997-06-13 13:12:20 +05:30
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This is as handy a place to put this as anyplace.
|
|
|
|
|
*
|
|
|
|
|
* Since the insertion of kernel modules can occur in a somewhat
|
|
|
|
|
* dynamic fashion we need some mechanism to insure that the
|
|
|
|
|
* kernel symbol tables get read just prior to when they are
|
|
|
|
|
* needed.
|
|
|
|
|
*
|
|
|
|
|
* To accomplish this we look for the Oops string and use its
|
|
|
|
|
* presence as a signal to load the module symbols.
|
|
|
|
|
*
|
|
|
|
|
* This is not the best solution of course, especially if the
|
|
|
|
|
* kernel is rapidly going out to lunch. What really needs to
|
|
|
|
|
* be done is to somehow generate a callback from the
|
|
|
|
|
* kernel whenever a module is loaded or unloaded. I am
|
|
|
|
|
* open for patches.
|
|
|
|
|
*/
|
|
|
|
|
if ( i_am_paranoid &&
|
|
|
|
|
(strstr(line, "Oops:") != (char *) 0) && !InitMsyms() )
|
|
|
|
|
Syslog(LOG_WARNING, "Cannot load kernel module symbols.\n");
|
1997-06-02 22:51:41 +05:30
|
|
|
|
|
1997-06-13 13:12:20 +05:30
|
|
|
|
|
1997-06-02 22:51:41 +05:30
|
|
|
|
/*
|
|
|
|
|
* Early return if there do not appear to be any kernel
|
|
|
|
|
* messages in this line.
|
|
|
|
|
*/
|
|
|
|
|
if ( (num_syms == 0) ||
|
|
|
|
|
(kp = strstr(line, "[<")) == (char *) 0 )
|
|
|
|
|
{
|
|
|
|
|
strcpy(el, line);
|
|
|
|
|
return(el);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Loop through and expand all kernel messages. */
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
while ( sl < kp+1 )
|
|
|
|
|
*elp++ = *sl++;
|
|
|
|
|
|
|
|
|
|
/* Now poised at a kernel delimiter. */
|
|
|
|
|
if ( (kp = strstr(sl, ">]")) == (char *) 0 )
|
|
|
|
|
{
|
|
|
|
|
strcpy(el, sl);
|
|
|
|
|
return(el);
|
|
|
|
|
}
|
|
|
|
|
dlm = *kp;
|
1998-01-02 08:37:16 +05:30
|
|
|
|
strncpy(num,sl+1,kp-sl-1);
|
|
|
|
|
num[kp-sl-1] = '\0';
|
1998-04-14 04:57:37 +05:30
|
|
|
|
value = strtoul(num, (char **) 0, 16);
|
1997-06-02 22:51:41 +05:30
|
|
|
|
if ( (symbol = LookupSymbol(value, &sym)) == (char *) 0 )
|
|
|
|
|
symbol = sl;
|
|
|
|
|
|
|
|
|
|
strcat(elp, symbol);
|
|
|
|
|
elp += strlen(symbol);
|
|
|
|
|
if ( debugging )
|
1998-04-14 04:57:37 +05:30
|
|
|
|
fprintf(stderr, "Symbol: %s = %lx = %s, %x/%d\n", \
|
1997-06-02 22:51:41 +05:30
|
|
|
|
sl+1, value, \
|
|
|
|
|
(sym.size==0) ? symbol+1 : symbol, \
|
|
|
|
|
sym.offset, sym.size);
|
|
|
|
|
|
|
|
|
|
value = 2;
|
|
|
|
|
if ( sym.size != 0 )
|
|
|
|
|
{
|
|
|
|
|
--value;
|
|
|
|
|
++kp;
|
2007-06-18 00:51:55 +05:30
|
|
|
|
elp += sprintf(elp, "+0x%x/0x%02x", sym.offset, sym.size);
|
1997-06-02 22:51:41 +05:30
|
|
|
|
}
|
|
|
|
|
strncat(elp, kp, value);
|
|
|
|
|
elp += value;
|
|
|
|
|
sl = kp + value;
|
|
|
|
|
if ( (kp = strstr(sl, "[<")) == (char *) 0 )
|
|
|
|
|
strcat(elp, sl);
|
|
|
|
|
}
|
|
|
|
|
while ( kp != (char *) 0);
|
|
|
|
|
|
|
|
|
|
if ( debugging )
|
|
|
|
|
fprintf(stderr, "Expanded line: %s\n", el);
|
|
|
|
|
return(el);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1997-06-13 13:12:20 +05:30
|
|
|
|
/**************************************************************************
|
|
|
|
|
* Function: SetParanoiaLevel
|
|
|
|
|
*
|
|
|
|
|
* Purpose: This function is an interface function for setting the
|
|
|
|
|
* mode of loadable module symbol lookups. Probably overkill
|
|
|
|
|
* but it does slay another global variable.
|
|
|
|
|
*
|
2007-05-31 00:16:09 +05:30
|
|
|
|
* Arguments: (int) level
|
1997-06-13 13:12:20 +05:30
|
|
|
|
*
|
|
|
|
|
* level:-> The amount of paranoia which is to be
|
|
|
|
|
* present when resolving kernel exceptions.
|
|
|
|
|
* Return: void
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
extern void SetParanoiaLevel(level)
|
|
|
|
|
|
|
|
|
|
int level;
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
i_am_paranoid = level;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1997-06-02 22:51:41 +05:30
|
|
|
|
/*
|
|
|
|
|
* Setting the -DTEST define enables the following code fragment to
|
|
|
|
|
* be compiled. This produces a small standalone program which will
|
|
|
|
|
* echo the standard input of the process to stdout while translating
|
|
|
|
|
* all numeric kernel addresses into their symbolic equivalent.
|
|
|
|
|
*/
|
|
|
|
|
#if defined(TEST)
|
|
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
|
|
extern int main(int, char **);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
extern int main(int argc, char *argv[])
|
|
|
|
|
{
|
|
|
|
|
auto char line[1024], eline[2048];
|
1997-06-13 13:12:20 +05:30
|
|
|
|
|
|
|
|
|
debugging = 1;
|
1997-06-02 22:51:41 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( !InitKsyms((char *) 0) )
|
|
|
|
|
{
|
|
|
|
|
fputs("ksym: Error loading system map.\n", stderr);
|
|
|
|
|
return(1);
|
|
|
|
|
}
|
1997-06-13 13:12:20 +05:30
|
|
|
|
|
1997-06-02 22:51:41 +05:30
|
|
|
|
while ( !feof(stdin) )
|
|
|
|
|
{
|
1998-04-14 04:57:37 +05:30
|
|
|
|
fgets(line, sizeof(line), stdin);
|
|
|
|
|
if (line[strlen(line)-1] == '\n') line[strlen(line)-1] = '\0'; /* Trash NL char */
|
1997-06-02 22:51:41 +05:30
|
|
|
|
memset(eline, '\0', sizeof(eline));
|
|
|
|
|
ExpandKadds(line, eline);
|
|
|
|
|
fprintf(stdout, "%s\n", eline);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extern void Syslog(int priority, char *fmt, ...)
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
|
fprintf(stdout, "Pr: %d, ", priority);
|
|
|
|
|
vfprintf(stdout, fmt, ap);
|
|
|
|
|
va_end(ap);
|
|
|
|
|
fputc('\n', stdout);
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2004-04-29 21:40:10 +05:30
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Local variables:
|
|
|
|
|
* c-indent-level: 8
|
|
|
|
|
* c-basic-offset: 8
|
|
|
|
|
* tab-width: 8
|
|
|
|
|
* End:
|
|
|
|
|
*/
|