sysv_shm.c (10653) | sysv_shm.c (11626) |
---|---|
1/* $Id: sysv_shm.c,v 1.8 1995/08/30 00:33:02 bde Exp $ */ | 1/* $Id: sysv_shm.c,v 1.9 1995/09/09 18:10:09 davidg Exp $ */ |
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: --- 16 unchanged lines hidden (view full) --- 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 | 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: --- 16 unchanged lines hidden (view full) --- 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 |
34#include <sys/types.h> | |
35#include <sys/param.h> | 34#include <sys/param.h> |
35#include <sys/systm.h> 36#include <sys/sysproto.h> |
|
36#include <sys/kernel.h> 37#include <sys/shm.h> 38#include <sys/proc.h> | 37#include <sys/kernel.h> 38#include <sys/shm.h> 39#include <sys/proc.h> |
39#include <sys/uio.h> 40#include <sys/time.h> | |
41#include <sys/malloc.h> 42#include <sys/mman.h> | 40#include <sys/malloc.h> 41#include <sys/mman.h> |
43#include <sys/systm.h> | |
44#include <sys/stat.h> | 42#include <sys/stat.h> |
43#include <sys/sysent.h> |
|
45 46#include <vm/vm.h> 47#include <vm/vm_map.h> | 44 45#include <vm/vm.h> 46#include <vm/vm_map.h> |
48#include <vm/vm_map.h> | |
49#include <vm/vm_kern.h> 50 | 47#include <vm/vm_kern.h> 48 |
49struct shmat_args; 50extern int shmat __P((struct proc *p, struct shmat_args *uap, int *retval)); 51struct shmctl_args; 52extern int shmctl __P((struct proc *p, struct shmctl_args *uap, int *retval)); 53struct shmdt_args; 54extern int shmdt __P((struct proc *p, struct shmdt_args *uap, int *retval)); 55struct shmget_args; 56extern int shmget __P((struct proc *p, struct shmget_args *uap, int *retval)); 57 |
|
51static void shminit __P((void *)); 52SYSINIT(sysv_shm, SI_SUB_SYSV_SHM, SI_ORDER_FIRST, shminit, NULL) 53 | 58static void shminit __P((void *)); 59SYSINIT(sysv_shm, SI_SUB_SYSV_SHM, SI_ORDER_FIRST, shminit, NULL) 60 |
54int oshmctl(); 55int shmat(), shmctl(), shmdt(), shmget(); 56int (*shmcalls[])() = { shmat, oshmctl, shmdt, shmget, shmctl }; | 61struct oshmctl_args; 62int oshmctl __P((struct proc *p, struct oshmctl_args *uap, int *retval)); 63static int shmget_allocate_segment __P((struct proc *p, struct shmget_args *uap, int mode, int *retval)); 64static int shmget_existing __P((struct proc *p, struct shmget_args *uap, int mode, int segnum, int *retval)); |
57 | 65 |
66/* XXX casting to (sy_call_t *) is bogus, as usual. */ 67sy_call_t *shmcalls[] = { 68 (sy_call_t *)shmat, (sy_call_t *)oshmctl, 69 (sy_call_t *)shmdt, (sy_call_t *)shmget, 70 (sy_call_t *)shmctl 71}; 72 |
|
58#define SHMSEG_FREE 0x0200 59#define SHMSEG_REMOVED 0x0400 60#define SHMSEG_ALLOCATED 0x0800 61#define SHMSEG_WANTED 0x1000 62 63vm_map_t sysvshm_map; 64int shm_last_free, shm_nused, shm_committed; 65struct shmid_ds *shmsegs; --- 225 unchanged lines hidden (view full) --- 291 outbuf.shm_dtime = shmseg->shm_dtime; 292 outbuf.shm_ctime = shmseg->shm_ctime; 293 outbuf.shm_handle = shmseg->shm_internal; 294 error = copyout((caddr_t)&outbuf, uap->ubuf, sizeof(outbuf)); 295 if (error) 296 return error; 297 break; 298 default: | 73#define SHMSEG_FREE 0x0200 74#define SHMSEG_REMOVED 0x0400 75#define SHMSEG_ALLOCATED 0x0800 76#define SHMSEG_WANTED 0x1000 77 78vm_map_t sysvshm_map; 79int shm_last_free, shm_nused, shm_committed; 80struct shmid_ds *shmsegs; --- 225 unchanged lines hidden (view full) --- 306 outbuf.shm_dtime = shmseg->shm_dtime; 307 outbuf.shm_ctime = shmseg->shm_ctime; 308 outbuf.shm_handle = shmseg->shm_internal; 309 error = copyout((caddr_t)&outbuf, uap->ubuf, sizeof(outbuf)); 310 if (error) 311 return error; 312 break; 313 default: |
299 return shmctl(p, uap, retval); | 314 /* XXX casting to (sy_call_t *) is bogus, as usual. */ 315 return ((sy_call_t *)shmctl)(p, uap, retval); |
300 } 301 return 0; 302#else 303 return EINVAL; 304#endif 305} 306 307struct shmctl_args { --- 194 unchanged lines hidden (view full) --- 502 return error; 503 } 504 if ((uap->shmflg & IPC_CREAT) == 0) 505 return ENOENT; 506 } 507 return shmget_allocate_segment(p, uap, mode, retval); 508} 509 | 316 } 317 return 0; 318#else 319 return EINVAL; 320#endif 321} 322 323struct shmctl_args { --- 194 unchanged lines hidden (view full) --- 518 return error; 519 } 520 if ((uap->shmflg & IPC_CREAT) == 0) 521 return ENOENT; 522 } 523 return shmget_allocate_segment(p, uap, mode, retval); 524} 525 |
510struct shmsys_args { 511 u_int which; 512}; | |
513int 514shmsys(p, uap, retval) 515 struct proc *p; | 526int 527shmsys(p, uap, retval) 528 struct proc *p; |
516 struct shmsys_args *uap; | 529 /* XXX actually varargs. */ 530 struct shmsys_args /* { 531 u_int which; 532 int a2; 533 int a3; 534 int a4; 535 } */ *uap; |
517 int *retval; 518{ 519 520 if (uap->which >= sizeof(shmcalls)/sizeof(shmcalls[0])) 521 return EINVAL; | 536 int *retval; 537{ 538 539 if (uap->which >= sizeof(shmcalls)/sizeof(shmcalls[0])) 540 return EINVAL; |
522 return ((*shmcalls[uap->which])(p, &uap[1], retval)); | 541 return ((*shmcalls[uap->which])(p, &uap->a2, retval)); |
523} 524 525void 526shmfork(p1, p2, isvfork) 527 struct proc *p1, *p2; 528 int isvfork; 529{ 530 struct shmmap_state *shmmap_s; --- 20 unchanged lines hidden (view full) --- 551 for (i = 0; i < shminfo.shmseg; i++, shmmap_s++) 552 if (shmmap_s->shmid != -1) 553 shm_delete_mapping(p, shmmap_s); 554 free((caddr_t)p->p_vmspace->vm_shm, M_SHM); 555 p->p_vmspace->vm_shm = NULL; 556} 557 558void | 542} 543 544void 545shmfork(p1, p2, isvfork) 546 struct proc *p1, *p2; 547 int isvfork; 548{ 549 struct shmmap_state *shmmap_s; --- 20 unchanged lines hidden (view full) --- 570 for (i = 0; i < shminfo.shmseg; i++, shmmap_s++) 571 if (shmmap_s->shmid != -1) 572 shm_delete_mapping(p, shmmap_s); 573 free((caddr_t)p->p_vmspace->vm_shm, M_SHM); 574 p->p_vmspace->vm_shm = NULL; 575} 576 577void |
559shminit(udata) 560 void *udata; | 578shminit(dummy) 579 void *dummy; |
561{ 562 int i; 563 vm_offset_t garbage1, garbage2; 564 565 /* actually this *should* be pageable. SHM_{LOCK,UNLOCK} */ 566 sysvshm_map = kmem_suballoc(kernel_map, &garbage1, &garbage2, 567 shminfo.shmall * NBPG, TRUE); 568 for (i = 0; i < shminfo.shmmni; i++) { 569 shmsegs[i].shm_perm.mode = SHMSEG_FREE; 570 shmsegs[i].shm_perm.seq = 0; 571 } 572 shm_last_free = 0; 573 shm_nused = 0; 574 shm_committed = 0; 575} | 580{ 581 int i; 582 vm_offset_t garbage1, garbage2; 583 584 /* actually this *should* be pageable. SHM_{LOCK,UNLOCK} */ 585 sysvshm_map = kmem_suballoc(kernel_map, &garbage1, &garbage2, 586 shminfo.shmall * NBPG, TRUE); 587 for (i = 0; i < shminfo.shmmni; i++) { 588 shmsegs[i].shm_perm.mode = SHMSEG_FREE; 589 shmsegs[i].shm_perm.seq = 0; 590 } 591 shm_last_free = 0; 592 shm_nused = 0; 593 shm_committed = 0; 594} |