Filenames in /proc/<pid>/maps for 2.1.48

Alain.Knaff@poboxes.com ("Alain.Knaff@poboxes.com")
Sat, 09 Aug 1997 12:54:18 +0200


The new links in /proc/<pid>/fd are cute. The following patch adds
the same feature to /proc/<pid>/maps:

> cat /proc/self/maps
08048000-0804e000 r-xp 00000000 03:0b 36967 /usr/bin/cat
0804e000-0804f000 rw-p 00005000 03:0b 36967 /usr/bin/cat
0804f000-08051000 rwxp 00000000 00:00 0
40000000-40006000 r-xp 00000000 03:0b 2487 /lib/ld-linux.so.1.9.4
40006000-40007000 rw-p 00005000 03:0b 2487 /lib/ld-linux.so.1.9.4
40007000-40008000 rw-p 00000000 00:00 0
4000b000-40010000 r-xp 00000000 03:0b 2424 /lib/uncompress.o
40010000-40012000 rw-p 00004000 03:0b 2424 /lib/uncompress.o
40012000-40013000 rw-p 00000000 00:00 0
40013000-4009d000 r-xp 00000000 03:0b 2422 /lib/libc.so.5.4.33
4009d000-400a2000 rw-p 00089000 03:0b 2422 /lib/libc.so.5.4.33
400a2000-400d5000 rw-p 00000000 00:00 0
bfffd000-c0000000 rwxp ffffe000 00:00 0

Regards,

Alain

diff -ur 2.1.48/linux/fs/proc/array.c linux/fs/proc/array.c
--- 2.1.48/linux/fs/proc/array.c Fri Aug 8 21:59:49 1997
+++ linux/fs/proc/array.c Fri Aug 8 23:06:05 1997
@@ -901,14 +901,14 @@
* + (index into the line)
*/
/* for systems with sizeof(void*) == 4: */
-#define MAPS_LINE_FORMAT4 "%08lx-%08lx %s %08lx %s %lu\n"
+#define MAPS_LINE_FORMAT4 "%08lx-%08lx %s %08lx %s %-10lu\n"
#define MAPS_LINE_MAX4 49 /* sum of 8 1 8 1 4 1 8 1 5 1 10 1 */

/* for systems with sizeof(void*) == 8: */
-#define MAPS_LINE_FORMAT8 "%016lx-%016lx %s %016lx %s %lu\n"
+#define MAPS_LINE_FORMAT8 "%016lx-%016lx %s %016lx %s %-10lu\n"
#define MAPS_LINE_MAX8 73 /* sum of 16 1 16 1 4 1 16 1 5 1 10 1 */

-#define MAPS_LINE_MAX MAPS_LINE_MAX8
+#define MAPS_LINE_MAX /*MAPS_LINE_MAX8*/ 200


static long read_maps (int pid, struct file * file,
@@ -965,6 +965,24 @@
sizeof(void*) == 4 ? MAPS_LINE_FORMAT4 : MAPS_LINE_FORMAT8,
map->vm_start, map->vm_end, str, map->vm_offset,
kdevname(dev), ino);
+
+
+ if (map->vm_dentry != NULL) {
+ char * tmp = (char*)__get_free_page(GFP_KERNEL), *path;
+ int len2;
+
+ path = d_path(map->vm_dentry, tmp, PAGE_SIZE);
+ len2 = tmp + PAGE_SIZE - path;
+
+ line[len-1]=' ';
+ if(len2 >= MAPS_LINE_MAX - 1 - len)
+ len2 = MAPS_LINE_MAX - 1 - len;
+ strncpy(line+len, path, len2);
+ len += len2;
+ line[len++] ='\n';
+ line[len] ='\0';
+ free_page((unsigned long)tmp);
+ }

if (column >= len) {
column = 0; /* continue with next line at column 0 */