sysv_shm.c (109205) | sysv_shm.c (109623) |
---|---|
1/* $FreeBSD: head/sys/kern/sysv_shm.c 109205 2003-01-13 23:04:32Z dillon $ */ | 1/* $FreeBSD: head/sys/kern/sysv_shm.c 109623 2003-01-21 08:56:16Z alfred $ */ |
2/* $NetBSD: sysv_shm.c,v 1.23 1994/07/04 23:25:12 glass Exp $ */ 3 4/* 5 * Copyright (c) 1994 Adam Glass and Charles Hannum. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: --- 299 unchanged lines hidden (view full) --- 309 int error = 0; 310 311 if (!jail_sysvipc_allowed && jailed(td->td_ucred)) 312 return (ENOSYS); 313 mtx_lock(&Giant); 314 shmmap_s = p->p_vmspace->vm_shm; 315 if (shmmap_s == NULL) { 316 size = shminfo.shmseg * sizeof(struct shmmap_state); | 2/* $NetBSD: sysv_shm.c,v 1.23 1994/07/04 23:25:12 glass Exp $ */ 3 4/* 5 * Copyright (c) 1994 Adam Glass and Charles Hannum. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: --- 299 unchanged lines hidden (view full) --- 309 int error = 0; 310 311 if (!jail_sysvipc_allowed && jailed(td->td_ucred)) 312 return (ENOSYS); 313 mtx_lock(&Giant); 314 shmmap_s = p->p_vmspace->vm_shm; 315 if (shmmap_s == NULL) { 316 size = shminfo.shmseg * sizeof(struct shmmap_state); |
317 shmmap_s = malloc(size, M_SHM, M_WAITOK); | 317 shmmap_s = malloc(size, M_SHM, 0); |
318 for (i = 0; i < shminfo.shmseg; i++) 319 shmmap_s[i].shmid = -1; 320 p->p_vmspace->vm_shm = shmmap_s; 321 } 322 shmseg = shm_find_segment_by_shmid(uap->shmid); 323 if (shmseg == NULL) { 324 error = EINVAL; 325 goto done2; --- 312 unchanged lines hidden (view full) --- 638 /* 639 * In case we sleep in malloc(), mark the segment present but deleted 640 * so that noone else tries to create the same key. 641 */ 642 shmseg->shm_perm.mode = SHMSEG_ALLOCATED | SHMSEG_REMOVED; 643 shmseg->shm_perm.key = uap->key; 644 shmseg->shm_perm.seq = (shmseg->shm_perm.seq + 1) & 0x7fff; 645 shm_handle = (struct shm_handle *) | 318 for (i = 0; i < shminfo.shmseg; i++) 319 shmmap_s[i].shmid = -1; 320 p->p_vmspace->vm_shm = shmmap_s; 321 } 322 shmseg = shm_find_segment_by_shmid(uap->shmid); 323 if (shmseg == NULL) { 324 error = EINVAL; 325 goto done2; --- 312 unchanged lines hidden (view full) --- 638 /* 639 * In case we sleep in malloc(), mark the segment present but deleted 640 * so that noone else tries to create the same key. 641 */ 642 shmseg->shm_perm.mode = SHMSEG_ALLOCATED | SHMSEG_REMOVED; 643 shmseg->shm_perm.key = uap->key; 644 shmseg->shm_perm.seq = (shmseg->shm_perm.seq + 1) & 0x7fff; 645 shm_handle = (struct shm_handle *) |
646 malloc(sizeof(struct shm_handle), M_SHM, M_WAITOK); | 646 malloc(sizeof(struct shm_handle), M_SHM, 0); |
647 shmid = IXSEQ_TO_IPCID(segnum, shmseg->shm_perm); 648 649 /* 650 * We make sure that we have allocated a pager before we need 651 * to. 652 */ 653 if (shm_use_phys) { 654 shm_handle->shm_object = --- 96 unchanged lines hidden (view full) --- 751shmfork_myhook(p1, p2) 752 struct proc *p1, *p2; 753{ 754 struct shmmap_state *shmmap_s; 755 size_t size; 756 int i; 757 758 size = shminfo.shmseg * sizeof(struct shmmap_state); | 647 shmid = IXSEQ_TO_IPCID(segnum, shmseg->shm_perm); 648 649 /* 650 * We make sure that we have allocated a pager before we need 651 * to. 652 */ 653 if (shm_use_phys) { 654 shm_handle->shm_object = --- 96 unchanged lines hidden (view full) --- 751shmfork_myhook(p1, p2) 752 struct proc *p1, *p2; 753{ 754 struct shmmap_state *shmmap_s; 755 size_t size; 756 int i; 757 758 size = shminfo.shmseg * sizeof(struct shmmap_state); |
759 shmmap_s = malloc(size, M_SHM, M_WAITOK); | 759 shmmap_s = malloc(size, M_SHM, 0); |
760 bcopy(p1->p_vmspace->vm_shm, shmmap_s, size); 761 p2->p_vmspace->vm_shm = shmmap_s; 762 for (i = 0; i < shminfo.shmseg; i++, shmmap_s++) 763 if (shmmap_s->shmid != -1) 764 shmsegs[IPCID_TO_IX(shmmap_s->shmid)].shm_nattch++; 765} 766 767static void --- 18 unchanged lines hidden (view full) --- 786shmrealloc(void) 787{ 788 int i; 789 struct shmid_ds *newsegs; 790 791 if (shmalloced >= shminfo.shmmni) 792 return; 793 | 760 bcopy(p1->p_vmspace->vm_shm, shmmap_s, size); 761 p2->p_vmspace->vm_shm = shmmap_s; 762 for (i = 0; i < shminfo.shmseg; i++, shmmap_s++) 763 if (shmmap_s->shmid != -1) 764 shmsegs[IPCID_TO_IX(shmmap_s->shmid)].shm_nattch++; 765} 766 767static void --- 18 unchanged lines hidden (view full) --- 786shmrealloc(void) 787{ 788 int i; 789 struct shmid_ds *newsegs; 790 791 if (shmalloced >= shminfo.shmmni) 792 return; 793 |
794 newsegs = malloc(shminfo.shmmni * sizeof(*newsegs), M_SHM, M_WAITOK); | 794 newsegs = malloc(shminfo.shmmni * sizeof(*newsegs), M_SHM, 0); |
795 if (newsegs == NULL) 796 return; 797 for (i = 0; i < shmalloced; i++) 798 bcopy(&shmsegs[i], &newsegs[i], sizeof(newsegs[0])); 799 for (; i < shminfo.shmmni; i++) { 800 shmsegs[i].shm_perm.mode = SHMSEG_FREE; 801 shmsegs[i].shm_perm.seq = 0; 802 } --- 10 unchanged lines hidden (view full) --- 813 TUNABLE_INT_FETCH("kern.ipc.shmmaxpgs", &shminfo.shmall); 814 shminfo.shmmax = shminfo.shmall * PAGE_SIZE; 815 TUNABLE_INT_FETCH("kern.ipc.shmmin", &shminfo.shmmin); 816 TUNABLE_INT_FETCH("kern.ipc.shmmni", &shminfo.shmmni); 817 TUNABLE_INT_FETCH("kern.ipc.shmseg", &shminfo.shmseg); 818 TUNABLE_INT_FETCH("kern.ipc.shm_use_phys", &shm_use_phys); 819 820 shmalloced = shminfo.shmmni; | 795 if (newsegs == NULL) 796 return; 797 for (i = 0; i < shmalloced; i++) 798 bcopy(&shmsegs[i], &newsegs[i], sizeof(newsegs[0])); 799 for (; i < shminfo.shmmni; i++) { 800 shmsegs[i].shm_perm.mode = SHMSEG_FREE; 801 shmsegs[i].shm_perm.seq = 0; 802 } --- 10 unchanged lines hidden (view full) --- 813 TUNABLE_INT_FETCH("kern.ipc.shmmaxpgs", &shminfo.shmall); 814 shminfo.shmmax = shminfo.shmall * PAGE_SIZE; 815 TUNABLE_INT_FETCH("kern.ipc.shmmin", &shminfo.shmmin); 816 TUNABLE_INT_FETCH("kern.ipc.shmmni", &shminfo.shmmni); 817 TUNABLE_INT_FETCH("kern.ipc.shmseg", &shminfo.shmseg); 818 TUNABLE_INT_FETCH("kern.ipc.shm_use_phys", &shm_use_phys); 819 820 shmalloced = shminfo.shmmni; |
821 shmsegs = malloc(shmalloced * sizeof(shmsegs[0]), M_SHM, M_WAITOK); | 821 shmsegs = malloc(shmalloced * sizeof(shmsegs[0]), M_SHM, 0); |
822 if (shmsegs == NULL) 823 panic("cannot allocate initial memory for sysvshm"); 824 for (i = 0; i < shmalloced; i++) { 825 shmsegs[i].shm_perm.mode = SHMSEG_FREE; 826 shmsegs[i].shm_perm.seq = 0; 827 } 828 shm_last_free = 0; 829 shm_nused = 0; --- 61 unchanged lines hidden --- | 822 if (shmsegs == NULL) 823 panic("cannot allocate initial memory for sysvshm"); 824 for (i = 0; i < shmalloced; i++) { 825 shmsegs[i].shm_perm.mode = SHMSEG_FREE; 826 shmsegs[i].shm_perm.seq = 0; 827 } 828 shm_last_free = 0; 829 shm_nused = 0; --- 61 unchanged lines hidden --- |