Linux kernel & device driver programming

Cross-Referenced Linux and Device Driver Code

[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ]
Version: [ 2.6.11.8 ] [ 2.6.25 ] [ 2.6.25.8 ] [ 2.6.31.13 ] Architecture: [ i386 ]
  1 #include <linux/mm.h>
  2 #include <linux/hugetlb.h>
  3 #include <linux/mount.h>
  4 #include <linux/seq_file.h>
  5 #include <asm/elf.h>
  6 #include <asm/uaccess.h>
  7 #include "internal.h"
  8 
  9 char *task_mem(struct mm_struct *mm, char *buffer)
 10 {
 11         unsigned long data, text, lib;
 12 
 13         data = mm->total_vm - mm->shared_vm - mm->stack_vm;
 14         text = (PAGE_ALIGN(mm->end_code) - (mm->start_code & PAGE_MASK)) >> 10;
 15         lib = (mm->exec_vm << (PAGE_SHIFT-10)) - text;
 16         buffer += sprintf(buffer,
 17                 "VmSize:\t%8lu kB\n"
 18                 "VmLck:\t%8lu kB\n"
 19                 "VmRSS:\t%8lu kB\n"
 20                 "VmData:\t%8lu kB\n"
 21                 "VmStk:\t%8lu kB\n"
 22                 "VmExe:\t%8lu kB\n"
 23                 "VmLib:\t%8lu kB\n"
 24                 "VmPTE:\t%8lu kB\n",
 25                 (mm->total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
 26                 mm->locked_vm << (PAGE_SHIFT-10),
 27                 mm->rss << (PAGE_SHIFT-10),
 28                 data << (PAGE_SHIFT-10),
 29                 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
 30                 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10);
 31         return buffer;
 32 }
 33 
 34 unsigned long task_vsize(struct mm_struct *mm)
 35 {
 36         return PAGE_SIZE * mm->total_vm;
 37 }
 38 
 39 int task_statm(struct mm_struct *mm, int *shared, int *text,
 40                int *data, int *resident)
 41 {
 42         *shared = mm->rss - mm->anon_rss;
 43         *text = (PAGE_ALIGN(mm->end_code) - (mm->start_code & PAGE_MASK))
 44                                                                 >> PAGE_SHIFT;
 45         *data = mm->total_vm - mm->shared_vm;
 46         *resident = mm->rss;
 47         return mm->total_vm;
 48 }
 49 
 50 int proc_exe_link(struct inode *inode, struct dentry **dentry, struct vfsmount **mnt)
 51 {
 52         struct vm_area_struct * vma;
 53         int result = -ENOENT;
 54         struct task_struct *task = proc_task(inode);
 55         struct mm_struct * mm = get_task_mm(task);
 56 
 57         if (!mm)
 58                 goto out;
 59         down_read(&mm->mmap_sem);
 60 
 61         vma = mm->mmap;
 62         while (vma) {
 63                 if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
 64                         break;
 65                 vma = vma->vm_next;
 66         }
 67 
 68         if (vma) {
 69                 *mnt = mntget(vma->vm_file->f_vfsmnt);
 70                 *dentry = dget(vma->vm_file->f_dentry);
 71                 result = 0;
 72         }
 73 
 74         up_read(&mm->mmap_sem);
 75         mmput(mm);
 76 out:
 77         return result;
 78 }
 79 
 80 static int show_map(struct seq_file *m, void *v)
 81 {
 82         struct vm_area_struct *map = v;
 83         struct file *file = map->vm_file;
 84         int flags = map->vm_flags;
 85         unsigned long ino = 0;
 86         dev_t dev = 0;
 87         int len;
 88 
 89         if (file) {
 90                 struct inode *inode = map->vm_file->f_dentry->d_inode;
 91                 dev = inode->i_sb->s_dev;
 92                 ino = inode->i_ino;
 93         }
 94 
 95         seq_printf(m, "%08lx-%08lx %c%c%c%c %08lx %02x:%02x %lu %n",
 96                         map->vm_start,
 97                         map->vm_end,
 98                         flags & VM_READ ? 'r' : '-',
 99                         flags & VM_WRITE ? 'w' : '-',
100                         flags & VM_EXEC ? 'x' : '-',
101                         flags & VM_MAYSHARE ? 's' : 'p',
102                         map->vm_pgoff << PAGE_SHIFT,
103                         MAJOR(dev), MINOR(dev), ino, &len);
104 
105         if (map->vm_file) {
106                 len = 25 + sizeof(void*) * 6 - len;
107                 if (len < 1)
108                         len = 1;
109                 seq_printf(m, "%*c", len, ' ');
110                 seq_path(m, file->f_vfsmnt, file->f_dentry, "");
111         }
112         seq_putc(m, '\n');
113         return 0;
114 }
115 
116 static void *m_start(struct seq_file *m, loff_t *pos)
117 {
118         struct task_struct *task = m->private;
119         struct mm_struct *mm = get_task_mm(task);
120         struct vm_area_struct * map;
121         loff_t l = *pos;
122 
123         if (!mm)
124                 return NULL;
125 
126         down_read(&mm->mmap_sem);
127         map = mm->mmap;
128         while (l-- && map)
129                 map = map->vm_next;
130         if (!map) {
131                 up_read(&mm->mmap_sem);
132                 mmput(mm);
133                 if (l == -1)
134                         map = get_gate_vma(task);
135         }
136         return map;
137 }
138 
139 static void m_stop(struct seq_file *m, void *v)
140 {
141         struct task_struct *task = m->private;
142         struct vm_area_struct *map = v;
143         if (map && map != get_gate_vma(task)) {
144                 struct mm_struct *mm = map->vm_mm;
145                 up_read(&mm->mmap_sem);
146                 mmput(mm);
147         }
148 }
149 
150 static void *m_next(struct seq_file *m, void *v, loff_t *pos)
151 {
152         struct task_struct *task = m->private;
153         struct vm_area_struct *map = v;
154         (*pos)++;
155         if (map->vm_next)
156                 return map->vm_next;
157         m_stop(m, v);
158         if (map != get_gate_vma(task))
159                 return get_gate_vma(task);
160         return NULL;
161 }
162 
163 struct seq_operations proc_pid_maps_op = {
164         .start  = m_start,
165         .next   = m_next,
166         .stop   = m_stop,
167         .show   = show_map
168 };
169 
  This page was automatically generated by the LXR engine.