sysv_shm.c (92723) | sysv_shm.c (100511) |
---|---|
1/* $FreeBSD: head/sys/kern/sysv_shm.c 92723 2002-03-19 21:25:46Z alfred $ */ | 1/* $FreeBSD: head/sys/kern/sysv_shm.c 100511 2002-07-22 16:12:55Z 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: --- 190 unchanged lines hidden (view full) --- 200{ 201 struct shm_handle *shm_handle; 202 size_t size; 203 204 GIANT_REQUIRED; 205 206 shm_handle = shmseg->shm_internal; 207 vm_object_deallocate(shm_handle->shm_object); | 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: --- 190 unchanged lines hidden (view full) --- 200{ 201 struct shm_handle *shm_handle; 202 size_t size; 203 204 GIANT_REQUIRED; 205 206 shm_handle = shmseg->shm_internal; 207 vm_object_deallocate(shm_handle->shm_object); |
208 free((caddr_t)shm_handle, M_SHM); | 208 free(shm_handle, M_SHM); |
209 shmseg->shm_internal = NULL; 210 size = round_page(shmseg->shm_segsz); 211 shm_committed -= btoc(size); 212 shm_nused--; 213 shmseg->shm_perm.mode = SHMSEG_FREE; 214} 215 216static int --- 98 unchanged lines hidden (view full) --- 315 return (ENOSYS); 316 mtx_lock(&Giant); 317 shmmap_s = (struct shmmap_state *)p->p_vmspace->vm_shm; 318 if (shmmap_s == NULL) { 319 size = shminfo.shmseg * sizeof(struct shmmap_state); 320 shmmap_s = malloc(size, M_SHM, M_WAITOK); 321 for (i = 0; i < shminfo.shmseg; i++) 322 shmmap_s[i].shmid = -1; | 209 shmseg->shm_internal = NULL; 210 size = round_page(shmseg->shm_segsz); 211 shm_committed -= btoc(size); 212 shm_nused--; 213 shmseg->shm_perm.mode = SHMSEG_FREE; 214} 215 216static int --- 98 unchanged lines hidden (view full) --- 315 return (ENOSYS); 316 mtx_lock(&Giant); 317 shmmap_s = (struct shmmap_state *)p->p_vmspace->vm_shm; 318 if (shmmap_s == NULL) { 319 size = shminfo.shmseg * sizeof(struct shmmap_state); 320 shmmap_s = malloc(size, M_SHM, M_WAITOK); 321 for (i = 0; i < shminfo.shmseg; i++) 322 shmmap_s[i].shmid = -1; |
323 p->p_vmspace->vm_shm = (caddr_t)shmmap_s; | 323 p->p_vmspace->vm_shm = shmmap_s; |
324 } 325 shmseg = shm_find_segment_by_shmid(uap->shmid); 326 if (shmseg == NULL) { 327 error = EINVAL; 328 goto done2; 329 } 330 error = ipcperm(td, &shmseg->shm_perm, 331 (uap->shmflg & SHM_RDONLY) ? IPC_R : IPC_R|IPC_W); --- 106 unchanged lines hidden (view full) --- 438 outbuf.shm_segsz = shmseg->shm_segsz; 439 outbuf.shm_cpid = shmseg->shm_cpid; 440 outbuf.shm_lpid = shmseg->shm_lpid; 441 outbuf.shm_nattch = shmseg->shm_nattch; 442 outbuf.shm_atime = shmseg->shm_atime; 443 outbuf.shm_dtime = shmseg->shm_dtime; 444 outbuf.shm_ctime = shmseg->shm_ctime; 445 outbuf.shm_handle = shmseg->shm_internal; | 324 } 325 shmseg = shm_find_segment_by_shmid(uap->shmid); 326 if (shmseg == NULL) { 327 error = EINVAL; 328 goto done2; 329 } 330 error = ipcperm(td, &shmseg->shm_perm, 331 (uap->shmflg & SHM_RDONLY) ? IPC_R : IPC_R|IPC_W); --- 106 unchanged lines hidden (view full) --- 438 outbuf.shm_segsz = shmseg->shm_segsz; 439 outbuf.shm_cpid = shmseg->shm_cpid; 440 outbuf.shm_lpid = shmseg->shm_lpid; 441 outbuf.shm_nattch = shmseg->shm_nattch; 442 outbuf.shm_atime = shmseg->shm_atime; 443 outbuf.shm_dtime = shmseg->shm_dtime; 444 outbuf.shm_ctime = shmseg->shm_ctime; 445 outbuf.shm_handle = shmseg->shm_internal; |
446 error = copyout((caddr_t)&outbuf, uap->ubuf, sizeof(outbuf)); | 446 error = copyout(&outbuf, uap->ubuf, sizeof(outbuf)); |
447 if (error) 448 goto done2; 449 break; 450 default: 451 /* XXX casting to (sy_call_t *) is bogus, as usual. */ 452 error = ((sy_call_t *)shmctl)(td, uap); 453 break; 454 } --- 25 unchanged lines hidden (view full) --- 480 struct shmid_ds inbuf; 481 struct shmid_ds *shmseg; 482 483 if (!jail_sysvipc_allowed && jailed(td->td_ucred)) 484 return (ENOSYS); 485 mtx_lock(&Giant); 486 switch (uap->cmd) { 487 case IPC_INFO: | 447 if (error) 448 goto done2; 449 break; 450 default: 451 /* XXX casting to (sy_call_t *) is bogus, as usual. */ 452 error = ((sy_call_t *)shmctl)(td, uap); 453 break; 454 } --- 25 unchanged lines hidden (view full) --- 480 struct shmid_ds inbuf; 481 struct shmid_ds *shmseg; 482 483 if (!jail_sysvipc_allowed && jailed(td->td_ucred)) 484 return (ENOSYS); 485 mtx_lock(&Giant); 486 switch (uap->cmd) { 487 case IPC_INFO: |
488 error = copyout( (caddr_t)&shminfo, uap->buf, sizeof( shminfo ) ); | 488 error = copyout(&shminfo, uap->buf, sizeof(shminfo)); |
489 if (error) 490 goto done2; 491 td->td_retval[0] = shmalloced; 492 goto done2; 493 case SHM_INFO: { 494 struct shm_info shm_info; 495 shm_info.used_ids = shm_nused; 496 shm_info.shm_rss = 0; /*XXX where to get from ? */ 497 shm_info.shm_tot = 0; /*XXX where to get from ? */ 498 shm_info.shm_swp = 0; /*XXX where to get from ? */ 499 shm_info.swap_attempts = 0; /*XXX where to get from ? */ 500 shm_info.swap_successes = 0; /*XXX where to get from ? */ | 489 if (error) 490 goto done2; 491 td->td_retval[0] = shmalloced; 492 goto done2; 493 case SHM_INFO: { 494 struct shm_info shm_info; 495 shm_info.used_ids = shm_nused; 496 shm_info.shm_rss = 0; /*XXX where to get from ? */ 497 shm_info.shm_tot = 0; /*XXX where to get from ? */ 498 shm_info.shm_swp = 0; /*XXX where to get from ? */ 499 shm_info.swap_attempts = 0; /*XXX where to get from ? */ 500 shm_info.swap_successes = 0; /*XXX where to get from ? */ |
501 error = copyout( (caddr_t)&shm_info, uap->buf, sizeof( shm_info ) ); | 501 error = copyout(&shm_info, uap->buf, sizeof(shm_info)); |
502 if (error) 503 goto done2; 504 td->td_retval[0] = shmalloced; 505 goto done2; 506 } 507 } 508 if( (uap->cmd) == SHM_STAT ) 509 shmseg = shm_find_segment_by_shmidx(uap->shmid); --- 4 unchanged lines hidden (view full) --- 514 goto done2; 515 } 516 switch (uap->cmd) { 517 case SHM_STAT: 518 case IPC_STAT: 519 error = ipcperm(td, &shmseg->shm_perm, IPC_R); 520 if (error) 521 goto done2; | 502 if (error) 503 goto done2; 504 td->td_retval[0] = shmalloced; 505 goto done2; 506 } 507 } 508 if( (uap->cmd) == SHM_STAT ) 509 shmseg = shm_find_segment_by_shmidx(uap->shmid); --- 4 unchanged lines hidden (view full) --- 514 goto done2; 515 } 516 switch (uap->cmd) { 517 case SHM_STAT: 518 case IPC_STAT: 519 error = ipcperm(td, &shmseg->shm_perm, IPC_R); 520 if (error) 521 goto done2; |
522 error = copyout((caddr_t)shmseg, uap->buf, sizeof(inbuf)); | 522 error = copyout(shmseg, uap->buf, sizeof(inbuf)); |
523 if (error) 524 goto done2; 525 else if( (uap->cmd) == SHM_STAT ) 526 td->td_retval[0] = IXSEQ_TO_IPCID( uap->shmid, shmseg->shm_perm ); 527 break; 528 case IPC_SET: 529 error = ipcperm(td, &shmseg->shm_perm, IPC_M); 530 if (error) 531 goto done2; | 523 if (error) 524 goto done2; 525 else if( (uap->cmd) == SHM_STAT ) 526 td->td_retval[0] = IXSEQ_TO_IPCID( uap->shmid, shmseg->shm_perm ); 527 break; 528 case IPC_SET: 529 error = ipcperm(td, &shmseg->shm_perm, IPC_M); 530 if (error) 531 goto done2; |
532 error = copyin(uap->buf, (caddr_t)&inbuf, sizeof(inbuf)); | 532 error = copyin(uap->buf, &inbuf, sizeof(inbuf)); |
533 if (error) 534 goto done2; 535 shmseg->shm_perm.uid = inbuf.shm_perm.uid; 536 shmseg->shm_perm.gid = inbuf.shm_perm.gid; 537 shmseg->shm_perm.mode = 538 (shmseg->shm_perm.mode & ~ACCESSPERMS) | 539 (inbuf.shm_perm.mode & ACCESSPERMS); 540 shmseg->shm_ctime = time_second; --- 43 unchanged lines hidden (view full) --- 584 shmseg = &shmsegs[segnum]; 585 if (shmseg->shm_perm.mode & SHMSEG_REMOVED) { 586 /* 587 * This segment is in the process of being allocated. Wait 588 * until it's done, and look the key up again (in case the 589 * allocation failed or it was freed). 590 */ 591 shmseg->shm_perm.mode |= SHMSEG_WANTED; | 533 if (error) 534 goto done2; 535 shmseg->shm_perm.uid = inbuf.shm_perm.uid; 536 shmseg->shm_perm.gid = inbuf.shm_perm.gid; 537 shmseg->shm_perm.mode = 538 (shmseg->shm_perm.mode & ~ACCESSPERMS) | 539 (inbuf.shm_perm.mode & ACCESSPERMS); 540 shmseg->shm_ctime = time_second; --- 43 unchanged lines hidden (view full) --- 584 shmseg = &shmsegs[segnum]; 585 if (shmseg->shm_perm.mode & SHMSEG_REMOVED) { 586 /* 587 * This segment is in the process of being allocated. Wait 588 * until it's done, and look the key up again (in case the 589 * allocation failed or it was freed). 590 */ 591 shmseg->shm_perm.mode |= SHMSEG_WANTED; |
592 error = tsleep((caddr_t)shmseg, PLOCK | PCATCH, "shmget", 0); | 592 error = tsleep(shmseg, PLOCK | PCATCH, "shmget", 0); |
593 if (error) 594 return error; 595 return EAGAIN; 596 } 597 if ((uap->shmflg & (IPC_CREAT | IPC_EXCL)) == (IPC_CREAT | IPC_EXCL)) 598 return EEXIST; 599 error = ipcperm(td, &shmseg->shm_perm, mode); 600 if (error) --- 75 unchanged lines hidden (view full) --- 676 shm_committed += btoc(size); 677 shm_nused++; 678 if (shmseg->shm_perm.mode & SHMSEG_WANTED) { 679 /* 680 * Somebody else wanted this key while we were asleep. Wake 681 * them up now. 682 */ 683 shmseg->shm_perm.mode &= ~SHMSEG_WANTED; | 593 if (error) 594 return error; 595 return EAGAIN; 596 } 597 if ((uap->shmflg & (IPC_CREAT | IPC_EXCL)) == (IPC_CREAT | IPC_EXCL)) 598 return EEXIST; 599 error = ipcperm(td, &shmseg->shm_perm, mode); 600 if (error) --- 75 unchanged lines hidden (view full) --- 676 shm_committed += btoc(size); 677 shm_nused++; 678 if (shmseg->shm_perm.mode & SHMSEG_WANTED) { 679 /* 680 * Somebody else wanted this key while we were asleep. Wake 681 * them up now. 682 */ 683 shmseg->shm_perm.mode &= ~SHMSEG_WANTED; |
684 wakeup((caddr_t)shmseg); | 684 wakeup(shmseg); |
685 } 686 td->td_retval[0] = shmid; 687 return 0; 688} 689 690/* 691 * MPSAFE 692 */ --- 60 unchanged lines hidden (view full) --- 753 struct proc *p1, *p2; 754{ 755 struct shmmap_state *shmmap_s; 756 size_t size; 757 int i; 758 759 size = shminfo.shmseg * sizeof(struct shmmap_state); 760 shmmap_s = malloc(size, M_SHM, M_WAITOK); | 685 } 686 td->td_retval[0] = shmid; 687 return 0; 688} 689 690/* 691 * MPSAFE 692 */ --- 60 unchanged lines hidden (view full) --- 753 struct proc *p1, *p2; 754{ 755 struct shmmap_state *shmmap_s; 756 size_t size; 757 int i; 758 759 size = shminfo.shmseg * sizeof(struct shmmap_state); 760 shmmap_s = malloc(size, M_SHM, M_WAITOK); |
761 bcopy((caddr_t)p1->p_vmspace->vm_shm, (caddr_t)shmmap_s, size); 762 p2->p_vmspace->vm_shm = (caddr_t)shmmap_s; | 761 bcopy(p1->p_vmspace->vm_shm, shmmap_s, size); 762 p2->p_vmspace->vm_shm = shmmap_s; |
763 for (i = 0; i < shminfo.shmseg; i++, shmmap_s++) 764 if (shmmap_s->shmid != -1) 765 shmsegs[IPCID_TO_IX(shmmap_s->shmid)].shm_nattch++; 766} 767 768static void 769shmexit_myhook(p) 770 struct proc *p; 771{ 772 struct shmmap_state *shmmap_s; 773 int i; 774 775 GIANT_REQUIRED; 776 777 shmmap_s = (struct shmmap_state *)p->p_vmspace->vm_shm; 778 for (i = 0; i < shminfo.shmseg; i++, shmmap_s++) 779 if (shmmap_s->shmid != -1) 780 shm_delete_mapping(p, shmmap_s); | 763 for (i = 0; i < shminfo.shmseg; i++, shmmap_s++) 764 if (shmmap_s->shmid != -1) 765 shmsegs[IPCID_TO_IX(shmmap_s->shmid)].shm_nattch++; 766} 767 768static void 769shmexit_myhook(p) 770 struct proc *p; 771{ 772 struct shmmap_state *shmmap_s; 773 int i; 774 775 GIANT_REQUIRED; 776 777 shmmap_s = (struct shmmap_state *)p->p_vmspace->vm_shm; 778 for (i = 0; i < shminfo.shmseg; i++, shmmap_s++) 779 if (shmmap_s->shmid != -1) 780 shm_delete_mapping(p, shmmap_s); |
781 free((caddr_t)p->p_vmspace->vm_shm, M_SHM); | 781 free(p->p_vmspace->vm_shm, M_SHM); |
782 p->p_vmspace->vm_shm = NULL; 783} 784 785static void 786shmrealloc(void) 787{ 788 int i; 789 struct shmid_ds *newsegs; --- 101 unchanged lines hidden --- | 782 p->p_vmspace->vm_shm = NULL; 783} 784 785static void 786shmrealloc(void) 787{ 788 int i; 789 struct shmid_ds *newsegs; --- 101 unchanged lines hidden --- |