void seminit(void) { int i, sz; vaddr_t v; mutex_init(&semlock, MUTEX_DEFAULT, IPL_NONE); cv_init(&sem_realloc_cv, "semrealc"); sem_realloc_state = false; semtot = 0; sem_waiters = 0; /* Allocate the wired memory for our structures */ sz = ALIGN(seminfo.semmni * sizeof(struct semid_ds)) + ALIGN(seminfo.semmns * sizeof(struct __sem)) + ALIGN(seminfo.semmni * sizeof(kcondvar_t)) + ALIGN(seminfo.semmnu * seminfo.semusz); sz = round_page(sz); v = uvm_km_alloc(kernel_map, sz, 0, UVM_KMF_WIRED|UVM_KMF_ZERO); if (v == 0) panic("sysv_sem: cannot allocate memory"); sema = (void *)v; sem = (void *)((uintptr_t)sema + ALIGN(seminfo.semmni * sizeof(struct semid_ds))); semcv = (void *)((uintptr_t)sem + ALIGN(seminfo.semmns * sizeof(struct __sem))); semu = (void *)((uintptr_t)semcv + ALIGN(seminfo.semmni * sizeof(kcondvar_t))); for (i = 0; i < seminfo.semmni; i++) { sema[i]._sem_base = 0; sema[i].sem_perm.mode = 0; cv_init(&semcv[i], "semwait"); } for (i = 0; i < seminfo.semmnu; i++) { struct sem_undo *suptr = SEMU(semu, i); suptr->un_proc = NULL; } semu_list = NULL; exithook_establish(semexit, NULL); sysvipcinit(); }
void msginit(void) { int i, sz; vaddr_t v; /* * msginfo.msgssz should be a power of two for efficiency reasons. * It is also pretty silly if msginfo.msgssz is less than 8 * or greater than about 256 so ... */ i = 8; while (i < 1024 && i != msginfo.msgssz) i <<= 1; if (i != msginfo.msgssz) { panic("msginfo.msgssz = %d, not a small power of 2", msginfo.msgssz); } if (msginfo.msgseg > 32767) { panic("msginfo.msgseg = %d > 32767", msginfo.msgseg); } /* Allocate the wired memory for our structures */ sz = ALIGN(msginfo.msgmax) + ALIGN(msginfo.msgseg * sizeof(struct msgmap)) + ALIGN(msginfo.msgtql * sizeof(struct __msg)) + ALIGN(msginfo.msgmni * sizeof(kmsq_t)); sz = round_page(sz); v = uvm_km_alloc(kernel_map, sz, 0, UVM_KMF_WIRED|UVM_KMF_ZERO); if (v == 0) panic("sysv_msg: cannot allocate memory"); msgpool = (void *)v; msgmaps = (void *)((uintptr_t)msgpool + ALIGN(msginfo.msgmax)); msghdrs = (void *)((uintptr_t)msgmaps + ALIGN(msginfo.msgseg * sizeof(struct msgmap))); msqs = (void *)((uintptr_t)msghdrs + ALIGN(msginfo.msgtql * sizeof(struct __msg))); for (i = 0; i < (msginfo.msgseg - 1); i++) msgmaps[i].next = i + 1; msgmaps[msginfo.msgseg - 1].next = -1; free_msgmaps = 0; nfree_msgmaps = msginfo.msgseg; for (i = 0; i < (msginfo.msgtql - 1); i++) { msghdrs[i].msg_type = 0; msghdrs[i].msg_next = &msghdrs[i + 1]; } i = msginfo.msgtql - 1; msghdrs[i].msg_type = 0; msghdrs[i].msg_next = NULL; free_msghdrs = &msghdrs[0]; for (i = 0; i < msginfo.msgmni; i++) { cv_init(&msqs[i].msq_cv, "msgwait"); /* Implies entry is available */ msqs[i].msq_u.msg_qbytes = 0; /* Reset to a known value */ msqs[i].msq_u.msg_perm._seq = 0; } mutex_init(&msgmutex, MUTEX_DEFAULT, IPL_NONE); cv_init(&msg_realloc_cv, "msgrealc"); msg_realloc_state = false; sysvipcinit(); }