3 * Copyright (C) 1992, 1993 Krishna Balasubramanian
4 * Many improvements/fixes by Bruno Haible.
5 * Replaced `struct shm_desc' by `struct vm_area_struct', July 1994.
6 * Fixed the shm swap deallocation (shm_unuse()), August 1998 Andrea Arcangeli.
8 * /proc/sysvipc/shm support (c) 1999 Dragos Acostachioaie <dragos@iname.com>
9 * BIGMEM support, Andrea Arcangeli <andrea@suse.de>
10 * SMP thread shm, Jean-Luc Boyard <jean-luc.boyard@siemens.fr>
11 * HIGHMEM support, Ingo Molnar <mingo@redhat.com>
12 * Make shmmax, shmall, shmmni sysctl'able, Christoph Rohland <cr@sap.com>
13 * Shared /dev/zero support, Kanoj Sarcar <kanoj@sgi.com>
14 * Move the mm functionality over to mm/shmem.c, Christoph Rohland <cr@sap.com>
16 * support for audit of ipc object properties and permission changes
17 * Dustin Kirkland <dustin.kirkland@us.ibm.com>
21 * Pavel Emelianov <xemul@openvz.org>
24 #include <linux/slab.h>
26 #include <linux/hugetlb.h>
27 #include <linux/shm.h>
28 #include <linux/init.h>
29 #include <linux/file.h>
30 #include <linux/mman.h>
31 #include <linux/shmem_fs.h>
32 #include <linux/security.h>
33 #include <linux/syscalls.h>
34 #include <linux/audit.h>
35 #include <linux/capability.h>
36 #include <linux/ptrace.h>
37 #include <linux/seq_file.h>
38 #include <linux/mutex.h>
39 #include <linux/nsproxy.h>
40 #include <linux/vs_context.h>
41 #include <linux/vs_limit.h>
43 #include <asm/uaccess.h>
47 static struct file_operations shm_file_operations;
48 static struct vm_operations_struct shm_vm_ops;
50 static struct ipc_ids init_shm_ids;
52 #define shm_ids(ns) (*((ns)->ids[IPC_SHM_IDS]))
54 #define shm_lock(ns, id) \
55 ((struct shmid_kernel*)ipc_lock(&shm_ids(ns),id))
56 #define shm_unlock(shp) \
57 ipc_unlock(&(shp)->shm_perm)
58 #define shm_get(ns, id) \
59 ((struct shmid_kernel*)ipc_get(&shm_ids(ns),id))
60 #define shm_buildid(ns, id, seq) \
61 ipc_buildid(&shm_ids(ns), id, seq)
63 static int newseg (struct ipc_namespace *ns, key_t key,
64 int shmflg, size_t size);
65 static void shm_open (struct vm_area_struct *shmd);
66 static void shm_close (struct vm_area_struct *shmd);
67 static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
69 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
72 static void __ipc_init __shm_init_ns(struct ipc_namespace *ns, struct ipc_ids *ids)
74 ns->ids[IPC_SHM_IDS] = ids;
75 ns->shm_ctlmax = SHMMAX;
76 ns->shm_ctlall = SHMALL;
77 ns->shm_ctlmni = SHMMNI;
82 static void do_shm_rmid(struct ipc_namespace *ns, struct shmid_kernel *shp)
85 shp->shm_perm.mode |= SHM_DEST;
86 /* Do not find it any more */
87 shp->shm_perm.key = IPC_PRIVATE;
94 int shm_init_ns(struct ipc_namespace *ns)
98 ids = kmalloc(sizeof(struct ipc_ids), GFP_KERNEL);
102 __shm_init_ns(ns, ids);
106 void shm_exit_ns(struct ipc_namespace *ns)
109 struct shmid_kernel *shp;
111 mutex_lock(&shm_ids(ns).mutex);
112 for (i = 0; i <= shm_ids(ns).max_id; i++) {
113 shp = shm_lock(ns, i);
117 do_shm_rmid(ns, shp);
119 mutex_unlock(&shm_ids(ns).mutex);
121 ipc_fini_ids(ns->ids[IPC_SHM_IDS]);
122 kfree(ns->ids[IPC_SHM_IDS]);
123 ns->ids[IPC_SHM_IDS] = NULL;
127 void __init shm_init (void)
129 __shm_init_ns(&init_ipc_ns, &init_shm_ids);
130 ipc_init_proc_interface("sysvipc/shm",
131 " key shmid perms size cpid lpid nattch uid gid cuid cgid atime dtime ctime\n",
132 IPC_SHM_IDS, sysvipc_shm_proc_show);
135 static inline int shm_checkid(struct ipc_namespace *ns,
136 struct shmid_kernel *s, int id)
138 if (ipc_checkid(&shm_ids(ns), &s->shm_perm, id))
143 static inline struct shmid_kernel *shm_rmid(struct ipc_namespace *ns, int id)
145 return (struct shmid_kernel *)ipc_rmid(&shm_ids(ns), id);
148 static inline int shm_addid(struct ipc_namespace *ns, struct shmid_kernel *shp)
150 return ipc_addid(&shm_ids(ns), &shp->shm_perm, ns->shm_ctlmni);
155 static inline void shm_inc(struct ipc_namespace *ns, int id)
157 struct shmid_kernel *shp;
159 shp = shm_lock(ns, id);
161 shp->shm_atim = get_seconds();
162 shp->shm_lprid = current->tgid;
167 #define shm_file_ns(file) (*((struct ipc_namespace **)&(file)->private_data))
169 /* This is called by fork, once for every shm attach. */
170 static void shm_open(struct vm_area_struct *shmd)
172 shm_inc(shm_file_ns(shmd->vm_file),
173 shmd->vm_file->f_path.dentry->d_inode->i_ino);
177 * shm_destroy - free the struct shmid_kernel
179 * @shp: struct to free
181 * It has to be called with shp and shm_ids.mutex locked,
182 * but returns with shp unlocked and freed.
184 static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
186 struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
187 int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
189 vx_ipcshm_sub(vxi, shp, numpages);
190 ns->shm_tot -= numpages;
192 shm_rmid(ns, shp->id);
194 if (!is_file_hugepages(shp->shm_file))
195 shmem_lock(shp->shm_file, 0, shp->mlock_user);
197 user_shm_unlock(shp->shm_file->f_path.dentry->d_inode->i_size,
199 fput (shp->shm_file);
200 security_shm_free(shp);
206 * remove the attach descriptor shmd.
207 * free memory for segment if it is marked destroyed.
208 * The descriptor has already been removed from the current->mm->mmap list
209 * and will later be kfree()d.
211 static void shm_close (struct vm_area_struct *shmd)
213 struct file * file = shmd->vm_file;
214 int id = file->f_path.dentry->d_inode->i_ino;
215 struct shmid_kernel *shp;
216 struct ipc_namespace *ns;
218 ns = shm_file_ns(file);
220 mutex_lock(&shm_ids(ns).mutex);
221 /* remove from the list of attaches of the shm segment */
222 shp = shm_lock(ns, id);
224 shp->shm_lprid = current->tgid;
225 shp->shm_dtim = get_seconds();
227 if(shp->shm_nattch == 0 &&
228 shp->shm_perm.mode & SHM_DEST)
229 shm_destroy(ns, shp);
232 mutex_unlock(&shm_ids(ns).mutex);
235 static int shm_mmap(struct file * file, struct vm_area_struct * vma)
239 ret = shmem_mmap(file, vma);
241 vma->vm_ops = &shm_vm_ops;
242 if (!(vma->vm_flags & VM_WRITE))
243 vma->vm_flags &= ~VM_MAYWRITE;
244 shm_inc(shm_file_ns(file), file->f_path.dentry->d_inode->i_ino);
250 static int shm_release(struct inode *ino, struct file *file)
252 struct ipc_namespace *ns;
254 ns = shm_file_ns(file);
256 shm_file_ns(file) = NULL;
260 static struct file_operations shm_file_operations = {
262 .release = shm_release,
264 .get_unmapped_area = shmem_get_unmapped_area,
268 static struct vm_operations_struct shm_vm_ops = {
269 .open = shm_open, /* callback for a new vm-area open */
270 .close = shm_close, /* callback for when the vm-area is released */
271 .nopage = shmem_nopage,
272 #if defined(CONFIG_NUMA) && defined(CONFIG_SHMEM)
273 .set_policy = shmem_set_policy,
274 .get_policy = shmem_get_policy,
278 static int newseg (struct ipc_namespace *ns, key_t key, int shmflg, size_t size)
281 struct shmid_kernel *shp;
282 int numpages = (size + PAGE_SIZE -1) >> PAGE_SHIFT;
287 if (size < SHMMIN || size > ns->shm_ctlmax)
290 if (ns->shm_tot + numpages > ns->shm_ctlall)
293 if (!vx_ipcshm_avail(current->vx_info, numpages))
296 shp = ipc_rcu_alloc(sizeof(*shp));
300 shp->shm_perm.key = key;
301 shp->shm_perm.xid = vx_current_xid();
302 shp->shm_perm.mode = (shmflg & S_IRWXUGO);
303 shp->mlock_user = NULL;
305 shp->shm_perm.security = NULL;
306 error = security_shm_alloc(shp);
312 if (shmflg & SHM_HUGETLB) {
313 /* hugetlb_zero_setup takes care of mlock user accounting */
314 file = hugetlb_zero_setup(size);
315 shp->mlock_user = current->user;
317 int acctflag = VM_ACCOUNT;
319 * Do not allow no accounting for OVERCOMMIT_NEVER, even
322 if ((shmflg & SHM_NORESERVE) &&
323 sysctl_overcommit_memory != OVERCOMMIT_NEVER)
325 sprintf (name, "SYSV%08x", key);
326 file = shmem_file_setup(name, size, acctflag);
328 error = PTR_ERR(file);
333 id = shm_addid(ns, shp);
337 shp->shm_cprid = current->tgid;
339 shp->shm_atim = shp->shm_dtim = 0;
340 shp->shm_ctim = get_seconds();
341 shp->shm_segsz = size;
343 shp->id = shm_buildid(ns, id, shp->shm_perm.seq);
344 shp->shm_file = file;
345 file->f_path.dentry->d_inode->i_ino = shp->id;
347 shm_file_ns(file) = get_ipc_ns(ns);
349 /* Hugetlb ops would have already been assigned. */
350 if (!(shmflg & SHM_HUGETLB))
351 file->f_op = &shm_file_operations;
353 ns->shm_tot += numpages;
354 vx_ipcshm_add(current->vx_info, key, numpages);
361 security_shm_free(shp);
366 asmlinkage long sys_shmget (key_t key, size_t size, int shmflg)
368 struct shmid_kernel *shp;
370 struct ipc_namespace *ns;
372 ns = current->nsproxy->ipc_ns;
374 mutex_lock(&shm_ids(ns).mutex);
375 if (key == IPC_PRIVATE) {
376 err = newseg(ns, key, shmflg, size);
377 } else if ((id = ipc_findkey(&shm_ids(ns), key)) == -1) {
378 if (!(shmflg & IPC_CREAT))
381 err = newseg(ns, key, shmflg, size);
382 } else if ((shmflg & IPC_CREAT) && (shmflg & IPC_EXCL)) {
385 shp = shm_lock(ns, id);
387 if (shp->shm_segsz < size)
389 else if (ipcperms(&shp->shm_perm, shmflg))
392 int shmid = shm_buildid(ns, id, shp->shm_perm.seq);
393 err = security_shm_associate(shp, shmflg);
399 mutex_unlock(&shm_ids(ns).mutex);
404 static inline unsigned long copy_shmid_to_user(void __user *buf, struct shmid64_ds *in, int version)
408 return copy_to_user(buf, in, sizeof(*in));
413 ipc64_perm_to_ipc_perm(&in->shm_perm, &out.shm_perm);
414 out.shm_segsz = in->shm_segsz;
415 out.shm_atime = in->shm_atime;
416 out.shm_dtime = in->shm_dtime;
417 out.shm_ctime = in->shm_ctime;
418 out.shm_cpid = in->shm_cpid;
419 out.shm_lpid = in->shm_lpid;
420 out.shm_nattch = in->shm_nattch;
422 return copy_to_user(buf, &out, sizeof(out));
435 static inline unsigned long copy_shmid_from_user(struct shm_setbuf *out, void __user *buf, int version)
440 struct shmid64_ds tbuf;
442 if (copy_from_user(&tbuf, buf, sizeof(tbuf)))
445 out->uid = tbuf.shm_perm.uid;
446 out->gid = tbuf.shm_perm.gid;
447 out->mode = tbuf.shm_perm.mode;
453 struct shmid_ds tbuf_old;
455 if (copy_from_user(&tbuf_old, buf, sizeof(tbuf_old)))
458 out->uid = tbuf_old.shm_perm.uid;
459 out->gid = tbuf_old.shm_perm.gid;
460 out->mode = tbuf_old.shm_perm.mode;
469 static inline unsigned long copy_shminfo_to_user(void __user *buf, struct shminfo64 *in, int version)
473 return copy_to_user(buf, in, sizeof(*in));
478 if(in->shmmax > INT_MAX)
479 out.shmmax = INT_MAX;
481 out.shmmax = (int)in->shmmax;
483 out.shmmin = in->shmmin;
484 out.shmmni = in->shmmni;
485 out.shmseg = in->shmseg;
486 out.shmall = in->shmall;
488 return copy_to_user(buf, &out, sizeof(out));
495 static void shm_get_stat(struct ipc_namespace *ns, unsigned long *rss,
503 for (i = 0; i <= shm_ids(ns).max_id; i++) {
504 struct shmid_kernel *shp;
507 shp = shm_get(ns, i);
511 inode = shp->shm_file->f_path.dentry->d_inode;
513 if (is_file_hugepages(shp->shm_file)) {
514 struct address_space *mapping = inode->i_mapping;
515 *rss += (HPAGE_SIZE/PAGE_SIZE)*mapping->nrpages;
517 struct shmem_inode_info *info = SHMEM_I(inode);
518 spin_lock(&info->lock);
519 *rss += inode->i_mapping->nrpages;
520 *swp += info->swapped;
521 spin_unlock(&info->lock);
526 asmlinkage long sys_shmctl (int shmid, int cmd, struct shmid_ds __user *buf)
528 struct shm_setbuf setbuf;
529 struct shmid_kernel *shp;
531 struct ipc_namespace *ns;
533 if (cmd < 0 || shmid < 0) {
538 version = ipc_parse_version(&cmd);
539 ns = current->nsproxy->ipc_ns;
541 switch (cmd) { /* replace with proc interface ? */
544 struct shminfo64 shminfo;
546 err = security_shm_shmctl(NULL, cmd);
550 memset(&shminfo,0,sizeof(shminfo));
551 shminfo.shmmni = shminfo.shmseg = ns->shm_ctlmni;
552 shminfo.shmmax = ns->shm_ctlmax;
553 shminfo.shmall = ns->shm_ctlall;
555 shminfo.shmmin = SHMMIN;
556 if(copy_shminfo_to_user (buf, &shminfo, version))
558 /* reading a integer is always atomic */
559 err= shm_ids(ns).max_id;
566 struct shm_info shm_info;
568 err = security_shm_shmctl(NULL, cmd);
572 memset(&shm_info,0,sizeof(shm_info));
573 mutex_lock(&shm_ids(ns).mutex);
574 shm_info.used_ids = shm_ids(ns).in_use;
575 shm_get_stat (ns, &shm_info.shm_rss, &shm_info.shm_swp);
576 shm_info.shm_tot = ns->shm_tot;
577 shm_info.swap_attempts = 0;
578 shm_info.swap_successes = 0;
579 err = shm_ids(ns).max_id;
580 mutex_unlock(&shm_ids(ns).mutex);
581 if(copy_to_user (buf, &shm_info, sizeof(shm_info))) {
586 err = err < 0 ? 0 : err;
592 struct shmid64_ds tbuf;
594 memset(&tbuf, 0, sizeof(tbuf));
595 shp = shm_lock(ns, shmid);
599 } else if(cmd==SHM_STAT) {
601 if (shmid > shm_ids(ns).max_id)
603 result = shm_buildid(ns, shmid, shp->shm_perm.seq);
605 err = shm_checkid(ns, shp,shmid);
611 if (ipcperms (&shp->shm_perm, S_IRUGO))
613 err = security_shm_shmctl(shp, cmd);
616 kernel_to_ipc64_perm(&shp->shm_perm, &tbuf.shm_perm);
617 tbuf.shm_segsz = shp->shm_segsz;
618 tbuf.shm_atime = shp->shm_atim;
619 tbuf.shm_dtime = shp->shm_dtim;
620 tbuf.shm_ctime = shp->shm_ctim;
621 tbuf.shm_cpid = shp->shm_cprid;
622 tbuf.shm_lpid = shp->shm_lprid;
623 if (!is_file_hugepages(shp->shm_file))
624 tbuf.shm_nattch = shp->shm_nattch;
626 tbuf.shm_nattch = file_count(shp->shm_file) - 1;
628 if(copy_shmid_to_user (buf, &tbuf, version))
637 shp = shm_lock(ns, shmid);
642 err = shm_checkid(ns, shp,shmid);
646 err = audit_ipc_obj(&(shp->shm_perm));
650 if (!capable(CAP_IPC_LOCK)) {
652 if (current->euid != shp->shm_perm.uid &&
653 current->euid != shp->shm_perm.cuid)
655 if (cmd == SHM_LOCK &&
656 !current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur)
660 err = security_shm_shmctl(shp, cmd);
665 struct user_struct * user = current->user;
666 if (!is_file_hugepages(shp->shm_file)) {
667 err = shmem_lock(shp->shm_file, 1, user);
669 shp->shm_perm.mode |= SHM_LOCKED;
670 shp->mlock_user = user;
673 } else if (!is_file_hugepages(shp->shm_file)) {
674 shmem_lock(shp->shm_file, 0, shp->mlock_user);
675 shp->shm_perm.mode &= ~SHM_LOCKED;
676 shp->mlock_user = NULL;
684 * We cannot simply remove the file. The SVID states
685 * that the block remains until the last person
686 * detaches from it, then is deleted. A shmat() on
687 * an RMID segment is legal in older Linux and if
688 * we change it apps break...
690 * Instead we set a destroyed flag, and then blow
691 * the name away when the usage hits zero.
693 mutex_lock(&shm_ids(ns).mutex);
694 shp = shm_lock(ns, shmid);
698 err = shm_checkid(ns, shp, shmid);
702 err = audit_ipc_obj(&(shp->shm_perm));
706 if (current->euid != shp->shm_perm.uid &&
707 current->euid != shp->shm_perm.cuid &&
708 !capable(CAP_SYS_ADMIN)) {
713 err = security_shm_shmctl(shp, cmd);
717 do_shm_rmid(ns, shp);
718 mutex_unlock(&shm_ids(ns).mutex);
724 if (copy_shmid_from_user (&setbuf, buf, version)) {
728 mutex_lock(&shm_ids(ns).mutex);
729 shp = shm_lock(ns, shmid);
733 err = shm_checkid(ns, shp,shmid);
736 err = audit_ipc_obj(&(shp->shm_perm));
739 err = audit_ipc_set_perm(0, setbuf.uid, setbuf.gid, setbuf.mode);
743 if (current->euid != shp->shm_perm.uid &&
744 current->euid != shp->shm_perm.cuid &&
745 !capable(CAP_SYS_ADMIN)) {
749 err = security_shm_shmctl(shp, cmd);
753 shp->shm_perm.uid = setbuf.uid;
754 shp->shm_perm.gid = setbuf.gid;
755 shp->shm_perm.mode = (shp->shm_perm.mode & ~S_IRWXUGO)
756 | (setbuf.mode & S_IRWXUGO);
757 shp->shm_ctim = get_seconds();
770 mutex_unlock(&shm_ids(ns).mutex);
779 * Fix shmaddr, allocate descriptor, map shm, add attach descriptor to lists.
781 * NOTE! Despite the name, this is NOT a direct system call entrypoint. The
782 * "raddr" thing points to kernel space, and there has to be a wrapper around
785 long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
787 struct shmid_kernel *shp;
796 struct ipc_namespace *ns;
801 } else if ((addr = (ulong)shmaddr)) {
802 if (addr & (SHMLBA-1)) {
803 if (shmflg & SHM_RND)
804 addr &= ~(SHMLBA-1); /* round down */
806 #ifndef __ARCH_FORCE_SHMLBA
807 if (addr & ~PAGE_MASK)
811 flags = MAP_SHARED | MAP_FIXED;
813 if ((shmflg & SHM_REMAP))
819 if (shmflg & SHM_RDONLY) {
823 prot = PROT_READ | PROT_WRITE;
824 acc_mode = S_IRUGO | S_IWUGO;
826 if (shmflg & SHM_EXEC) {
832 * We cannot rely on the fs check since SYSV IPC does have an
833 * additional creator id...
835 ns = current->nsproxy->ipc_ns;
836 shp = shm_lock(ns, shmid);
841 err = shm_checkid(ns, shp,shmid);
846 if (ipcperms(&shp->shm_perm, acc_mode)) {
852 err = security_shm_shmat(shp, shmaddr, shmflg);
858 file = shp->shm_file;
859 size = i_size_read(file->f_path.dentry->d_inode);
863 down_write(¤t->mm->mmap_sem);
864 if (addr && !(shmflg & SHM_REMAP)) {
865 user_addr = ERR_PTR(-EINVAL);
866 if (find_vma_intersection(current->mm, addr, addr + size))
869 * If shm segment goes below stack, make sure there is some
870 * space left for the stack to grow (at least 4 pages).
872 if (addr < current->mm->start_stack &&
873 addr > current->mm->start_stack - size - PAGE_SIZE * 5)
877 user_addr = (void*) do_mmap (file, addr, size, prot, flags, 0);
880 up_write(¤t->mm->mmap_sem);
882 mutex_lock(&shm_ids(ns).mutex);
883 shp = shm_lock(ns, shmid);
886 if(shp->shm_nattch == 0 &&
887 shp->shm_perm.mode & SHM_DEST)
888 shm_destroy(ns, shp);
891 mutex_unlock(&shm_ids(ns).mutex);
893 *raddr = (unsigned long) user_addr;
895 if (IS_ERR(user_addr))
896 err = PTR_ERR(user_addr);
901 asmlinkage long sys_shmat(int shmid, char __user *shmaddr, int shmflg)
906 err = do_shmat(shmid, shmaddr, shmflg, &ret);
909 force_successful_syscall_return();
914 * detach and kill segment if marked destroyed.
915 * The work is done in shm_close.
917 asmlinkage long sys_shmdt(char __user *shmaddr)
919 struct mm_struct *mm = current->mm;
920 struct vm_area_struct *vma, *next;
921 unsigned long addr = (unsigned long)shmaddr;
923 int retval = -EINVAL;
925 if (addr & ~PAGE_MASK)
928 down_write(&mm->mmap_sem);
931 * This function tries to be smart and unmap shm segments that
932 * were modified by partial mlock or munmap calls:
933 * - It first determines the size of the shm segment that should be
934 * unmapped: It searches for a vma that is backed by shm and that
935 * started at address shmaddr. It records it's size and then unmaps
937 * - Then it unmaps all shm vmas that started at shmaddr and that
938 * are within the initially determined size.
939 * Errors from do_munmap are ignored: the function only fails if
940 * it's called with invalid parameters or if it's called to unmap
941 * a part of a vma. Both calls in this function are for full vmas,
942 * the parameters are directly copied from the vma itself and always
943 * valid - therefore do_munmap cannot fail. (famous last words?)
946 * If it had been mremap()'d, the starting address would not
947 * match the usual checks anyway. So assume all vma's are
948 * above the starting address given.
950 vma = find_vma(mm, addr);
956 * Check if the starting address would match, i.e. it's
957 * a fragment created by mprotect() and/or munmap(), or it
958 * otherwise it starts at this address with no hassles.
960 if ((vma->vm_ops == &shm_vm_ops || is_vm_hugetlb_page(vma)) &&
961 (vma->vm_start - addr)/PAGE_SIZE == vma->vm_pgoff) {
964 size = vma->vm_file->f_path.dentry->d_inode->i_size;
965 do_munmap(mm, vma->vm_start, vma->vm_end - vma->vm_start);
967 * We discovered the size of the shm segment, so
968 * break out of here and fall through to the next
969 * loop that uses the size information to stop
970 * searching for matching vma's.
980 * We need look no further than the maximum address a fragment
981 * could possibly have landed at. Also cast things to loff_t to
982 * prevent overflows and make comparisions vs. equal-width types.
984 size = PAGE_ALIGN(size);
985 while (vma && (loff_t)(vma->vm_end - addr) <= size) {
988 /* finding a matching vma now does not alter retval */
989 if ((vma->vm_ops == &shm_vm_ops || is_vm_hugetlb_page(vma)) &&
990 (vma->vm_start - addr)/PAGE_SIZE == vma->vm_pgoff)
992 do_munmap(mm, vma->vm_start, vma->vm_end - vma->vm_start);
996 up_write(&mm->mmap_sem);
1000 #ifdef CONFIG_PROC_FS
1001 static int sysvipc_shm_proc_show(struct seq_file *s, void *it)
1003 struct shmid_kernel *shp = it;
1006 #define SMALL_STRING "%10d %10d %4o %10u %5u %5u %5d %5u %5u %5u %5u %10lu %10lu %10lu\n"
1007 #define BIG_STRING "%10d %10d %4o %21u %5u %5u %5d %5u %5u %5u %5u %10lu %10lu %10lu\n"
1009 if (sizeof(size_t) <= sizeof(int))
1010 format = SMALL_STRING;
1012 format = BIG_STRING;
1013 return seq_printf(s, format,
1020 is_file_hugepages(shp->shm_file) ? (file_count(shp->shm_file) - 1) : shp->shm_nattch,