* shmfd object management including creation and reference counting * routines. */
| 851 | * routines. |
| 852 | */ |
| 853 | struct shmfd * |
| 854 | shm_alloc(struct ucred *ucred, mode_t mode, bool largepage) |
| 855 | { |
| 856 | struct shmfd *shmfd; |
| 857 | |
| 858 | shmfd = malloc(sizeof(*shmfd), M_SHMFD, M_WAITOK | M_ZERO); |
| 859 | shmfd->shm_size = 0; |
| 860 | shmfd->shm_uid = ucred->cr_uid; |
| 861 | shmfd->shm_gid = ucred->cr_gid; |
| 862 | shmfd->shm_mode = mode; |
| 863 | if (largepage) { |
| 864 | shmfd->shm_object = phys_pager_allocate(NULL, |
| 865 | &shm_largepage_phys_ops, NULL, shmfd->shm_size, |
| 866 | VM_PROT_DEFAULT, 0, ucred); |
| 867 | shmfd->shm_lp_alloc_policy = SHM_LARGEPAGE_ALLOC_DEFAULT; |
| 868 | } else { |
| 869 | shmfd->shm_object = vm_pager_allocate(OBJT_SWAP, NULL, |
| 870 | shmfd->shm_size, VM_PROT_DEFAULT, 0, ucred); |
| 871 | } |
| 872 | KASSERT(shmfd->shm_object != NULL, ("shm_create: vm_pager_allocate")); |
| 873 | vfs_timestamp(&shmfd->shm_birthtime); |
| 874 | shmfd->shm_atime = shmfd->shm_mtime = shmfd->shm_ctime = |
| 875 | shmfd->shm_birthtime; |
| 876 | shmfd->shm_ino = alloc_unr64(&shm_ino_unr); |
| 877 | refcount_init(&shmfd->shm_refs, 1); |
| 878 | mtx_init(&shmfd->shm_mtx, "shmrl", NULL, MTX_DEF); |
| 879 | rangelock_init(&shmfd->shm_rl); |
| 880 | #ifdef MAC |
| 881 | mac_posixshm_init(shmfd); |
| 882 | mac_posixshm_create(ucred, shmfd); |
| 883 | #endif |
| 884 | |
| 885 | return (shmfd); |
| 886 | } |
| 887 | |
| 888 | struct shmfd * |
| 889 | shm_hold(struct shmfd *shmfd) |
no test coverage detected