diff options
author | Matt Helsley <matthltc@us.ibm.com> | 2008-04-29 04:01:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-04-29 11:06:17 -0400 |
commit | 925d1c401fa6cfd0df5d2e37da8981494ccdec07 (patch) | |
tree | 4f3b7a09311cd99783b822350628125e44f9902d /mm/nommu.c | |
parent | e93b4ea20adb20f1f1f07f10ba5d7dd739d2843e (diff) |
procfs task exe symlink
The kernel implements readlink of /proc/pid/exe by getting the file from
the first executable VMA. Then the path to the file is reconstructed and
reported as the result.
Because of the VMA walk the code is slightly different on nommu systems.
This patch avoids separate /proc/pid/exe code on nommu systems. Instead of
walking the VMAs to find the first executable file-backed VMA we store a
reference to the exec'd file in the mm_struct.
That reference would prevent the filesystem holding the executable file
from being unmounted even after unmapping the VMAs. So we track the number
of VM_EXECUTABLE VMAs and drop the new reference when the last one is
unmapped. This avoids pinning the mounted filesystem.
[akpm@linux-foundation.org: improve comments]
[yamamoto@valinux.co.jp: fix dup_mmap]
Signed-off-by: Matt Helsley <matthltc@us.ibm.com>
Cc: Oleg Nesterov <oleg@tv-sign.ru>
Cc: David Howells <dhowells@redhat.com>
Cc:"Eric W. Biederman" <ebiederm@xmission.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Hugh Dickins <hugh@veritas.com>
Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/nommu.c')
-rw-r--r-- | mm/nommu.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/mm/nommu.c b/mm/nommu.c index 1d32fe89d57b..ef8c62cec697 100644 --- a/mm/nommu.c +++ b/mm/nommu.c | |||
@@ -966,8 +966,13 @@ unsigned long do_mmap_pgoff(struct file *file, | |||
966 | 966 | ||
967 | INIT_LIST_HEAD(&vma->anon_vma_node); | 967 | INIT_LIST_HEAD(&vma->anon_vma_node); |
968 | atomic_set(&vma->vm_usage, 1); | 968 | atomic_set(&vma->vm_usage, 1); |
969 | if (file) | 969 | if (file) { |
970 | get_file(file); | 970 | get_file(file); |
971 | if (vm_flags & VM_EXECUTABLE) { | ||
972 | added_exe_file_vma(current->mm); | ||
973 | vma->vm_mm = current->mm; | ||
974 | } | ||
975 | } | ||
971 | vma->vm_file = file; | 976 | vma->vm_file = file; |
972 | vma->vm_flags = vm_flags; | 977 | vma->vm_flags = vm_flags; |
973 | vma->vm_start = addr; | 978 | vma->vm_start = addr; |
@@ -1022,8 +1027,11 @@ unsigned long do_mmap_pgoff(struct file *file, | |||
1022 | up_write(&nommu_vma_sem); | 1027 | up_write(&nommu_vma_sem); |
1023 | kfree(vml); | 1028 | kfree(vml); |
1024 | if (vma) { | 1029 | if (vma) { |
1025 | if (vma->vm_file) | 1030 | if (vma->vm_file) { |
1026 | fput(vma->vm_file); | 1031 | fput(vma->vm_file); |
1032 | if (vma->vm_flags & VM_EXECUTABLE) | ||
1033 | removed_exe_file_vma(vma->vm_mm); | ||
1034 | } | ||
1027 | kfree(vma); | 1035 | kfree(vma); |
1028 | } | 1036 | } |
1029 | return ret; | 1037 | return ret; |
@@ -1053,7 +1061,7 @@ EXPORT_SYMBOL(do_mmap_pgoff); | |||
1053 | /* | 1061 | /* |
1054 | * handle mapping disposal for uClinux | 1062 | * handle mapping disposal for uClinux |
1055 | */ | 1063 | */ |
1056 | static void put_vma(struct vm_area_struct *vma) | 1064 | static void put_vma(struct mm_struct *mm, struct vm_area_struct *vma) |
1057 | { | 1065 | { |
1058 | if (vma) { | 1066 | if (vma) { |
1059 | down_write(&nommu_vma_sem); | 1067 | down_write(&nommu_vma_sem); |
@@ -1075,8 +1083,11 @@ static void put_vma(struct vm_area_struct *vma) | |||
1075 | realalloc -= kobjsize(vma); | 1083 | realalloc -= kobjsize(vma); |
1076 | askedalloc -= sizeof(*vma); | 1084 | askedalloc -= sizeof(*vma); |
1077 | 1085 | ||
1078 | if (vma->vm_file) | 1086 | if (vma->vm_file) { |
1079 | fput(vma->vm_file); | 1087 | fput(vma->vm_file); |
1088 | if (vma->vm_flags & VM_EXECUTABLE) | ||
1089 | removed_exe_file_vma(mm); | ||
1090 | } | ||
1080 | kfree(vma); | 1091 | kfree(vma); |
1081 | } | 1092 | } |
1082 | 1093 | ||
@@ -1113,7 +1124,7 @@ int do_munmap(struct mm_struct *mm, unsigned long addr, size_t len) | |||
1113 | found: | 1124 | found: |
1114 | vml = *parent; | 1125 | vml = *parent; |
1115 | 1126 | ||
1116 | put_vma(vml->vma); | 1127 | put_vma(mm, vml->vma); |
1117 | 1128 | ||
1118 | *parent = vml->next; | 1129 | *parent = vml->next; |
1119 | realalloc -= kobjsize(vml); | 1130 | realalloc -= kobjsize(vml); |
@@ -1158,7 +1169,7 @@ void exit_mmap(struct mm_struct * mm) | |||
1158 | 1169 | ||
1159 | while ((tmp = mm->context.vmlist)) { | 1170 | while ((tmp = mm->context.vmlist)) { |
1160 | mm->context.vmlist = tmp->next; | 1171 | mm->context.vmlist = tmp->next; |
1161 | put_vma(tmp->vma); | 1172 | put_vma(mm, tmp->vma); |
1162 | 1173 | ||
1163 | realalloc -= kobjsize(tmp); | 1174 | realalloc -= kobjsize(tmp); |
1164 | askedalloc -= sizeof(*tmp); | 1175 | askedalloc -= sizeof(*tmp); |