#include <kern/backtrace.h>
#endif
+static LCK_MTX_DECLARE_ATTR(proc_klist_mlock, &proc_mlock_grp, &proc_lck_attr);
+
ZONE_DECLARE(pgrp_zone, "pgrp",
sizeof(struct pgrp), ZC_ZFREE_CLEARMEM);
ZONE_DECLARE(session_zone, "session",
sizeof(struct session), ZC_ZFREE_CLEARMEM);
+/*
+ * If you need accounting for KM_PROC consider using
+ * ZONE_VIEW_DEFINE to define a zone view.
+ */
+#define KM_PROC KHEAP_DEFAULT
typedef uint64_t unaligned_u64 __attribute__((aligned(1)));
LIST_REMOVE(uip, ui_hash);
retval = 0;
proc_list_unlock();
- FREE(uip, M_PROC);
+ kheap_free(KM_PROC, uip, sizeof(struct uidinfo));
goto out;
}
if (diff <= 0) {
goto out;
}
proc_list_unlock();
- MALLOC(newuip, struct uidinfo *, sizeof(*uip), M_PROC, M_WAITOK);
+ newuip = kheap_alloc(KM_PROC, sizeof(struct uidinfo), Z_WAITOK);
if (newuip == NULL) {
panic("chgproccnt: M_PROC zone depleted");
}
goto again;
out:
- if (newuip != NULL) {
- FREE(newuip, M_PROC);
- }
+ kheap_free(KM_PROC, newuip, sizeof(struct uidinfo));
return retval;
}
(((p->p_listflag & (P_LIST_DRAIN | P_LIST_DRAINWAIT)) == 0) ||
((p->p_listflag & P_LIST_REFWAIT) != 0))) {
if ((p->p_listflag & P_LIST_REFWAIT) != 0 && uthread_needs_to_wait_in_proc_refwait()) {
- msleep(&p->p_listflag, proc_list_mlock, 0, "proc_refwait", 0);
+ msleep(&p->p_listflag, &proc_list_mlock, 0, "proc_refwait", 0);
/*
* the proc might have been recycled since we dropped
* the proc list lock, get the proc again.
/* If someone else is controlling the (unreaped) zombie - wait */
if ((p->p_listflag & P_LIST_WAITING) != 0) {
- (void)msleep(&p->p_stat, proc_list_mlock, PWAIT, "waitcoll", 0);
+ (void)msleep(&p->p_stat, &proc_list_mlock, PWAIT, "waitcoll", 0);
goto again;
}
p->p_listflag |= P_LIST_WAITING;
/* Do not wait in ref drain for launchd exec */
while (p->p_refcount && !initexec) {
p->p_listflag |= P_LIST_DRAINWAIT;
- msleep(&p->p_refcount, proc_list_mlock, 0, "proc_refdrain", 0);
+ msleep(&p->p_refcount, &proc_list_mlock, 0, "proc_refdrain", 0);
}
p->p_listflag &= ~P_LIST_DRAIN;
if ((pp->p_listflag & (P_LIST_CHILDDRSTART | P_LIST_CHILDDRAINED)) == P_LIST_CHILDDRSTART) {
pp->p_listflag |= P_LIST_CHILDDRWAIT;
- msleep(&pp->p_childrencnt, proc_list_mlock, 0, "proc_parent", 0);
+ msleep(&pp->p_childrencnt, &proc_list_mlock, 0, "proc_parent", 0);
loopcnt++;
if (loopcnt == 5) {
parent = PROC_NULL;
/* wait for all that hold parentrefs to drop */
while (p->p_parentref > 0) {
p->p_listflag |= P_LIST_PARENTREFWAIT;
- msleep(&p->p_parentref, proc_list_mlock, 0, "proc_childdrainstart", 0);
+ msleep(&p->p_parentref, &proc_list_mlock, 0, "proc_childdrainstart", 0);
}
}
proc_pid(proc_t p)
{
if (p != NULL) {
+ proc_require(p, PROC_REQUIRE_ALLOW_KERNPROC);
return p->p_pid;
}
return -1;
proc_ppid(proc_t p)
{
if (p != NULL) {
+ proc_require(p, PROC_REQUIRE_ALLOW_KERNPROC);
return p->p_ppid;
}
return -1;
proc_original_ppid(proc_t p)
{
if (p != NULL) {
+ proc_require(p, PROC_REQUIRE_ALLOW_KERNPROC);
return p->p_original_ppid;
}
return -1;
proc_csflags(proc_t p, uint64_t *flags)
{
if (p && flags) {
+ proc_require(p, PROC_REQUIRE_ALLOW_KERNPROC);
*flags = (uint64_t)p->p_csflags;
return 0;
}
parent = proc_ref_locked(pp);
if ((parent == PROC_NULL) && (pp != PROC_NULL) && (pp->p_stat != SZOMB) && ((pp->p_listflag & P_LIST_EXITED) != 0) && ((pp->p_listflag & P_LIST_CHILDDRAINED) == 0)) {
pp->p_listflag |= P_LIST_CHILDLKWAIT;
- msleep(&pp->p_childrencnt, proc_list_mlock, 0, "proc_parent", 0);
+ msleep(&pp->p_childrencnt, &proc_list_mlock, 0, "proc_parent", 0);
goto loop;
}
proc_list_unlock();
sess->s_count = 1;
sess->s_ttypgrpid = NO_PID;
- lck_mtx_init(&sess->s_mlock, proc_mlock_grp, proc_lck_attr);
+ lck_mtx_init(&sess->s_mlock, &proc_mlock_grp, &proc_lck_attr);
bcopy(procsp->s_login, sess->s_login,
sizeof(sess->s_login));
}
pgrp->pg_id = pgid;
- lck_mtx_init(&pgrp->pg_mlock, proc_mlock_grp, proc_lck_attr);
+ lck_mtx_init(&pgrp->pg_mlock, &proc_mlock_grp, &proc_lck_attr);
LIST_INIT(&pgrp->pg_members);
proc_list_lock();
panic("pg_deleteref: freeing session in use");
}
proc_list_unlock();
- lck_mtx_destroy(&sessp->s_mlock, proc_mlock_grp);
+ lck_mtx_destroy(&sessp->s_mlock, &proc_mlock_grp);
zfree(session_zone, sessp);
} else {
proc_list_unlock();
}
- lck_mtx_destroy(&pgrp->pg_mlock, proc_mlock_grp);
+ lck_mtx_destroy(&pgrp->pg_mlock, &proc_mlock_grp);
zfree(pgrp_zone, pgrp);
}
return os_atomic_load(&p->p_vfs_iopolicy, relaxed) & P_VFS_IOPOLICY_IGNORE_CONTENT_PROTECTION;
}
+bool
+proc_ignores_node_permissions(proc_t p)
+{
+ return os_atomic_load(&p->p_vfs_iopolicy, relaxed) & P_VFS_IOPOLICY_IGNORE_NODE_PERMISSIONS;
+}
+
+bool
+proc_skip_mtime_update(proc_t p)
+{
+ return os_atomic_load(&p->p_vfs_iopolicy, relaxed) & P_VFS_IOPOLICY_SKIP_MTIME_UPDATE;
+}
+
#if CONFIG_COREDUMP
/*
* proc_core_name(name, uid, pid)
proc_list_lock();
pid_count_available = nprocs + 1; /* kernel_task not counted in nprocs */
assert(pid_count_available > 0);
- if (pidlist_nalloc(pl) > pid_count_available) {
+ if (pidlist_nalloc(pl) >= pid_count_available) {
break;
}
proc_list_unlock();
proc_list_unlock();
goto out;
}
- if (pidlist_nalloc(pl) > pid_count_available) {
+ if (pidlist_nalloc(pl) >= pid_count_available) {
break;
}
proc_list_unlock();
}
goto out;
}
- if (pidlist_nalloc(pl) > pid_count_available) {
+ if (pidlist_nalloc(pl) >= pid_count_available) {
break;
}
pgrp_unlock(pgrp);
while ((p->p_listflag & P_LIST_PGRPTRANS) == P_LIST_PGRPTRANS) {
p->p_listflag |= P_LIST_PGRPTRWAIT;
- (void)msleep(&p->p_pgrpid, proc_list_mlock, 0, "proc_pgrp", 0);
+ (void)msleep(&p->p_pgrpid, &proc_list_mlock, 0, "proc_pgrp", 0);
}
p->p_listflag |= P_LIST_PGRPTRANS;
while ((p->p_listflag & P_LIST_PGRPTRANS) == P_LIST_PGRPTRANS) {
p->p_listflag |= P_LIST_PGRPTRWAIT;
- (void)msleep(&p->p_pgrpid, proc_list_mlock, 0, "proc_pgrp", 0);
+ (void)msleep(&p->p_pgrpid, &proc_list_mlock, 0, "proc_pgrp", 0);
}
pgrp = p->p_pgrp;
/* wait during transitions */
while ((p->p_listflag & P_LIST_PGRPTRANS) == P_LIST_PGRPTRANS) {
p->p_listflag |= P_LIST_PGRPTRWAIT;
- (void)msleep(&p->p_pgrpid, proc_list_mlock, 0, "proc_pgrp", 0);
+ (void)msleep(&p->p_pgrpid, &proc_list_mlock, 0, "proc_pgrp", 0);
}
if ((p->p_pgrp != PGRP_NULL) && ((sess = p->p_pgrp->pg_session) != SESSION_NULL)) {
panic("session_rele: freeing session in use");
}
proc_list_unlock();
- lck_mtx_destroy(&sess->s_mlock, proc_mlock_grp);
+ lck_mtx_destroy(&sess->s_mlock, &proc_mlock_grp);
zfree(session_zone, sess);
} else {
proc_list_unlock();
void
proc_klist_lock(void)
{
- lck_mtx_lock(proc_klist_mlock);
+ lck_mtx_lock(&proc_klist_mlock);
}
void
proc_klist_unlock(void)
{
- lck_mtx_unlock(proc_klist_mlock);
+ lck_mtx_unlock(&proc_klist_mlock);
}
void