Re: [PATCH] procps-1.2.7: oops and fix

Kurt Garloff (garloff@kg1.ping.de)
Thu, 21 May 1998 15:43:48 +0200


--VS++wcV0S1rZb1Fb
Content-Type: text/plain; charset=us-ascii

On Thu, May 21, 1998 at 01:35:20AM +0200, Kurt Garloff wrote:
> Hi,
>
> my kernel is highly modularized, so a lot of kernel functions are loaded as
> modules. procps-1.2.7 will fail on an "ps axl" and segv in find_func ().
> An easy patch would check for out of range kernel syms and return &0.
> I did a little more work and added a function to look in /proc/ksyms for the
> relevant address. [Patch appended]

... and I forgot to really append it ...
Here it comes.

-- 
Kurt Garloff, Dortmund 
<K.Garloff@ping.de>
PGP key on http://student.physik.uni-dortmund.de/homepages/garloff

--VS++wcV0S1rZb1Fb Content-Type: text/plain; charset=us-ascii Content-Description: procps-127.diff Content-Disposition: attachment; filename="procps-127.diff"

--- procps-1.2.7/proc/ksym.c.old Fri Sep 19 23:55:07 1997 +++ procps-1.2.7/proc/ksym.c Thu May 21 01:22:08 1998 @@ -1,3 +1,4 @@ + /* kernel address -> symbol with next lower address. Charles Blake, 1996. * Written to obviate the need for psdatabase initialization based upon kernel * binary formats, etc. @@ -30,6 +31,8 @@ static char *sysmap, *sysmap_last, sysmap_fmt[10]; static int sysmap_len, sysmap_mean = 32, sysmap_addrsz; +static char buf[128]; + /* scan backward in a string no further than address beg looking for c */ static char *strchrrev(char *a, char *beg, char c) { if (a) @@ -196,6 +199,31 @@ return 0; } +/* Uhhh: This is a linear search. */ +char* find_module_sym(unsigned long address) { + FILE *fd; + unsigned long adr, best_adr = 0; + char mod[32], nm[32]; char c; + *mod = 1; + *buf = 0; /* sprintf (buf, "%08x", address); */ + fd = fopen ("/proc/ksyms", "r"); + if (!fd) return ("(no proc)"); + while (!feof (fd) && !(*mod == 0)) { + fscanf (fd, "%x %s\n", &adr, nm); + if ((c = fgetc (fd)) != '[') *mod = 0; + else { fscanf (fd, "%s", mod); }; + if (abs(address - adr) < abs(address - best_adr) /* && address >= adr */ + && abs(address - adr) < 0xa00) { + best_adr = adr; *buf = '['; + if (address - adr > 0x100) strcpy (buf+1, mod); /* module name */ + else strcpy(buf, nm); /* name of function/variable */ + }; + }; + fclose (fd); + return buf; +}; + + char * find_func(unsigned long address) { int n; struct sym_s *p; @@ -209,6 +237,7 @@ read_tbl(&db_hdr.fncs, &fncs); p = fncs.tbl; n = fncs.nsym; + if (address > p[n-1].addr) return find_module_sym(address); while (n) { int i = n / 2; if (p[i].addr < address) {

--VS++wcV0S1rZb1Fb--

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu