/*
- * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
+ * Copyright (c) 2000-2019 Apple Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
#define MPRINTF(a)
#endif
-#define M_SYSVSEM M_TEMP
+#define KM_SYSVSEM KHEAP_DEFAULT
/* Hard system limits to avoid resource starvation / DOS attacks.
* These are not needed if we can make the semaphore pages swappable.
*/
static struct seminfo limitseminfo = {
- SEMMAP, /* # of entries in semaphore map */
- SEMMNI, /* # of semaphore identifiers */
- SEMMNS, /* # of semaphores in system */
- SEMMNU, /* # of undo structures in system */
- SEMMSL, /* max # of semaphores per id */
- SEMOPM, /* max # of operations per semop call */
- SEMUME, /* max # of undo entries per process */
- SEMUSZ, /* size in bytes of undo structure */
- SEMVMX, /* semaphore maximum value */
- SEMAEM /* adjust on exit max value */
+ .semmap = SEMMAP, /* # of entries in semaphore map */
+ .semmni = SEMMNI, /* # of semaphore identifiers */
+ .semmns = SEMMNS, /* # of semaphores in system */
+ .semmnu = SEMMNU, /* # of undo structures in system */
+ .semmsl = SEMMSL, /* max # of semaphores per id */
+ .semopm = SEMOPM, /* max # of operations per semop call */
+ .semume = SEMUME, /* max # of undo entries per process */
+ .semusz = SEMUSZ, /* size in bytes of undo structure */
+ .semvmx = SEMVMX, /* semaphore maximum value */
+ .semaem = SEMAEM /* adjust on exit max value */
};
/* Current system allocations. We use this structure to track how many
* and not allocate the memory for them up front.
*/
struct seminfo seminfo = {
- SEMMAP, /* Unused, # of entries in semaphore map */
- 0, /* # of semaphore identifiers */
- 0, /* # of semaphores in system */
- 0, /* # of undo entries in system */
- SEMMSL, /* max # of semaphores per id */
- SEMOPM, /* max # of operations per semop call */
- SEMUME, /* max # of undo entries per process */
- SEMUSZ, /* size in bytes of undo structure */
- SEMVMX, /* semaphore maximum value */
- SEMAEM /* adjust on exit max value */
+ .semmap = SEMMAP, /* Unused, # of entries in semaphore map */
+ .semmni = 0, /* # of semaphore identifiers */
+ .semmns = 0, /* # of semaphores in system */
+ .semmnu = 0, /* # of undo entries in system */
+ .semmsl = SEMMSL, /* max # of semaphores per id */
+ .semopm = SEMOPM, /* max # of operations per semop call */
+ .semume = SEMUME, /* max # of undo entries per process */
+ .semusz = SEMUSZ, /* size in bytes of undo structure */
+ .semvmx = SEMVMX, /* semaphore maximum value */
+ .semaem = SEMAEM /* adjust on exit max value */
};
static void semundo_clear(int semid, int semnum);
/* XXX casting to (sy_call_t *) is bogus, as usual. */
-static sy_call_t *semcalls[] = {
+static sy_call_t* const semcalls[] = {
(sy_call_t *)semctl, (sy_call_t *)semget,
(sy_call_t *)semop
};
struct sem_undo *semu = NULL; /* semaphore undo pool */
-void sysv_sem_lock_init(void);
-static lck_grp_t *sysv_sem_subsys_lck_grp;
-static lck_grp_attr_t *sysv_sem_subsys_lck_grp_attr;
-static lck_attr_t *sysv_sem_subsys_lck_attr;
-static lck_mtx_t sysv_sem_subsys_mutex;
+static LCK_GRP_DECLARE(sysv_sem_subsys_lck_grp, "sysv_sem_subsys_lock");
+static LCK_MTX_DECLARE(sysv_sem_subsys_mutex, &sysv_sem_subsys_lck_grp);
#define SYSV_SEM_SUBSYS_LOCK() lck_mtx_lock(&sysv_sem_subsys_mutex)
#define SYSV_SEM_SUBSYS_UNLOCK() lck_mtx_unlock(&sysv_sem_subsys_mutex)
-
-__private_extern__ void
-sysv_sem_lock_init( void )
-{
- sysv_sem_subsys_lck_grp_attr = lck_grp_attr_alloc_init();
-
- sysv_sem_subsys_lck_grp = lck_grp_alloc_init("sysv_sem_subsys_lock", sysv_sem_subsys_lck_grp_attr);
-
- sysv_sem_subsys_lck_attr = lck_attr_alloc_init();
- lck_mtx_init(&sysv_sem_subsys_mutex, sysv_sem_subsys_lck_grp, sysv_sem_subsys_lck_attr);
-}
-
static __inline__ user_time_t
sysv_semtime(void)
{
#ifdef SEM_DEBUG
printf("growing semu[] from %d to %d\n", seminfo.semmnu, newSize);
#endif
- MALLOC(newSemu, struct sem_undo *, sizeof(struct sem_undo) * newSize,
- M_SYSVSEM, M_WAITOK | M_ZERO);
+ newSemu = kheap_alloc(KM_SYSVSEM, sizeof(struct sem_undo) * newSize,
+ Z_WAITOK | Z_ZERO);
if (NULL == newSemu) {
#ifdef SEM_DEBUG
printf("allocation failed. no changes made.\n");
}
/*
* The new elements (from newSemu[i] to newSemu[newSize-1]) have their
- * "un_proc" set to 0 (i.e. NULL) by the M_ZERO flag to MALLOC() above,
- * so they're already marked as "not in use".
+ * "un_proc" set to 0 (i.e. NULL) by the Z_ZERO flag to kheap_alloc
+ * above, so they're already marked as "not in use".
*/
/* Clean up the old array */
- if (semu) {
- FREE(semu, M_SYSVSEM);
- }
+ kheap_free(KM_SYSVSEM, semu, sizeof(struct sem_undo) * seminfo.semmnu);
semu = newSemu;
seminfo.semmnu = newSize;
#ifdef SEM_DEBUG
printf("growing sema[] from %d to %d\n", seminfo.semmni, newSize);
#endif
- MALLOC(newSema, struct semid_kernel *,
- sizeof(struct semid_kernel) * newSize,
- M_SYSVSEM, M_WAITOK | M_ZERO);
+ newSema = kheap_alloc(KM_SYSVSEM, sizeof(struct semid_kernel) * newSize,
+ Z_WAITOK | Z_ZERO);
if (NULL == newSema) {
#ifdef SEM_DEBUG
printf("allocation failed. no changes made.\n");
/*
* The new elements (from newSema[i] to newSema[newSize-1]) have their
- * "sem_base" and "sem_perm.mode" set to 0 (i.e. NULL) by the M_ZERO
- * flag to MALLOC() above, so they're already marked as "not in use".
+ * "sem_base" and "sem_perm.mode" set to 0 (i.e. NULL) by the Z_ZERO
+ * flag to kheap_alloc above, so they're already marked as "not in use".
*/
/* Clean up the old array */
- if (sema) {
- FREE(sema, M_SYSVSEM);
- }
+ kheap_free(KM_SYSVSEM, sema,
+ sizeof(struct semid_kernel) * seminfo.semmni);
sema = newSema;
seminfo.semmni = newSize;
#ifdef SEM_DEBUG
printf("growing sem_pool array from %d to %d\n", seminfo.semmns, new_pool_size);
#endif
- MALLOC(new_sem_pool, struct sem *, sizeof(struct sem) * new_pool_size,
- M_SYSVSEM, M_WAITOK | M_ZERO | M_NULL);
+ new_sem_pool = kheap_alloc(KM_SYSVSEM, sizeof(struct sem) * new_pool_size,
+ Z_WAITOK | Z_ZERO);
if (NULL == new_sem_pool) {
#ifdef SEM_DEBUG
printf("allocation failed. no changes made.\n");
sem_pool = new_sem_pool;
/* clean up the old array */
- if (sem_free != NULL) {
- FREE(sem_free, M_SYSVSEM);
- }
+ kheap_free(KM_SYSVSEM, sem_free, sizeof(struct sem) * seminfo.semmns);
seminfo.semmns = new_pool_size;
#ifdef SEM_DEBUG
if (sueptr->une_adjval == 0) {
suptr->un_cnt--;
*suepptr = sueptr->une_next;
- FREE(sueptr, M_SYSVSEM);
- sueptr = NULL;
+ kheap_free(KM_SYSVSEM, sueptr, sizeof(struct undo));
}
return 0;
}
}
/* allocate a new semaphore undo entry */
- MALLOC(new_sueptr, struct undo *, sizeof(struct undo),
- M_SYSVSEM, M_WAITOK);
+ new_sueptr = kheap_alloc(KM_SYSVSEM, sizeof(struct undo), Z_WAITOK);
if (new_sueptr == NULL) {
return ENOMEM;
}
if (semnum == -1 || sueptr->une_num == semnum) {
suptr->un_cnt--;
*suepptr = sueptr->une_next;
- FREE(sueptr, M_SYSVSEM);
+ kheap_free(KM_SYSVSEM, sueptr, sizeof(struct undo));
sueptr = *suepptr;
continue;
}
#endif
suptr->un_cnt--;
suptr->un_ent = sueptr->une_next;
- FREE(sueptr, M_SYSVSEM);
- sueptr = NULL;
+ kheap_free(KM_SYSVSEM, sueptr, sizeof(struct undo));
}
}
union {
struct user32_IPCS_command u32;
struct user_IPCS_command u64;
- } ipcs;
- struct user32_semid_ds semid_ds32; /* post conversion, 32 bit version */
- struct user64_semid_ds semid_ds64; /* post conversion, 64 bit version */
+ } ipcs = { };
+ struct user32_semid_ds semid_ds32 = { }; /* post conversion, 32 bit version */
+ struct user64_semid_ds semid_ds64 = { }; /* post conversion, 64 bit version */
void *semid_dsp;
size_t ipcs_sz;
size_t semid_ds_sz;