From: Ingo Molnar <mingo@elte.hu>
To: Andrew Morton <akpm@osdl.org>
Cc: linux-kernel@vger.kernel.org, Linus Torvalds <torvalds@osdl.org>
Subject: [patch] annotate /proc/<PID>/maps with [heap]/[stack]/[vdso] markers
Date: Mon, 31 Jan 2005 20:06:04 +0100 [thread overview]
Message-ID: <20050131190604.GA4423@elte.hu> (raw)
This patch makes the /proc/<PID>/maps file easier to parse (both for
humans and for applications), by annotating the heap, stack and vdso
mappings with [heap], [stack] and [vdso] markers.
It makes it easier/faster to determine at a quick glance whether an
application has a secure VM layout, and it also makes it easier for
tools to determine whether e.g. the heap or stack is executable or not.
new maps file, on a patched kernel:
001c4000-001d9000 r-xp 00000000 03:01 19954 /lib/ld-2.3.3.so
001d9000-001db000 rw-p 00014000 03:01 19954 /lib/ld-2.3.3.so
001dd000-002fb000 r-xp 00000000 03:01 19960 /lib/tls/libc-2.3.3.so
002fb000-002fd000 r--p 0011d000 03:01 19960 /lib/tls/libc-2.3.3.so
002fd000-002ff000 rw-p 0011f000 03:01 19960 /lib/tls/libc-2.3.3.so
002ff000-00301000 rw-p 002ff000 00:00 0
08048000-0804c000 r-xp 00000000 03:01 31968 /bin/cat
0804c000-0804d000 rw-p 00003000 03:01 31968 /bin/cat
0804d000-0806e000 rw-p 0804d000 00:00 0 [heap]
b7dbc000-b7dbd000 r--p 009d1000 03:01 83628 /usr/lib/locale/locale-archive
b7dbd000-b7dc4000 r--p 0097d000 03:01 83628 /usr/lib/locale/locale-archive
b7dc4000-b7df1000 r--p 0094a000 03:01 83628 /usr/lib/locale/locale-archive
b7df1000-b7ff1000 r--p 00000000 03:01 83628 /usr/lib/locale/locale-archive
b7ff1000-b7ff2000 rw-p b7ff1000 00:00 0
bffeb000-c0000000 rw-p bffeb000 00:00 0 [stack]
ffffe000-fffff000 ---p 00000000 00:00 0 [vdso]
Tested on x86, but should work on all architectures.
Signed-off-by: Ingo Molnar <mingo@elte.hu>
--- fs/proc/task_mmu.c.orig
+++ fs/proc/task_mmu.c
@@ -77,9 +77,18 @@ out:
return result;
}
+static void pad_len_spaces(struct seq_file *m, int len)
+{
+ len = 25 + sizeof(void*) * 6 - len;
+ if (len < 1)
+ len = 1;
+ seq_printf(m, "%*c", len, ' ');
+}
+
static int show_map(struct seq_file *m, void *v)
{
struct vm_area_struct *map = v;
+ struct mm_struct *mm = map->vm_mm;
struct file *file = map->vm_file;
int flags = map->vm_flags;
unsigned long ino = 0;
@@ -102,12 +117,31 @@ static int show_map(struct seq_file *m,
map->vm_pgoff << PAGE_SHIFT,
MAJOR(dev), MINOR(dev), ino, &len);
+ /*
+ * Print the dentry name for named mappings, and a
+ * special [heap] marker for the heap:
+ */
if (map->vm_file) {
- len = 25 + sizeof(void*) * 6 - len;
- if (len < 1)
- len = 1;
- seq_printf(m, "%*c", len, ' ');
+ pad_len_spaces(m, len);
seq_path(m, file->f_vfsmnt, file->f_dentry, "");
+ } else {
+ if (mm) {
+ if (map->vm_start <= mm->start_brk &&
+ map->vm_end >= mm->brk) {
+ pad_len_spaces(m, len);
+ seq_puts(m, "[heap]");
+ } else {
+ if (map->vm_start <= mm->start_stack &&
+ map->vm_end >= mm->start_stack) {
+
+ pad_len_spaces(m, len);
+ seq_puts(m, "[stack]");
+ }
+ }
+ } else {
+ pad_len_spaces(m, len);
+ seq_puts(m, "[vdso]");
+ }
}
seq_putc(m, '\n');
return 0;
reply other threads:[~2005-01-31 19:07 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20050131190604.GA4423@elte.hu \
--to=mingo@elte.hu \
--cc=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@osdl.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox