-/* $OpenBSD: kern_fork.c,v 1.238 2021/12/10 05:34:42 guenther Exp $ */
+/* $OpenBSD: kern_fork.c,v 1.239 2022/03/17 14:23:34 visa Exp $ */
/* $NetBSD: kern_fork.c,v 1.29 1996/02/09 18:59:34 christos Exp $ */
/*
/* give the process the same creds as the initial thread */
pr->ps_ucred = p->p_ucred;
crhold(pr->ps_ucred);
- KASSERT(p->p_ucred->cr_ref >= 2); /* new thread and new process */
+ /* new thread and new process */
+ KASSERT(p->p_ucred->cr_refcnt.r_refs >= 2);
LIST_INIT(&pr->ps_children);
LIST_INIT(&pr->ps_orphans);
-/* $OpenBSD: kern_prot.c,v 1.78 2021/10/24 00:02:25 jsg Exp $ */
+/* $OpenBSD: kern_prot.c,v 1.79 2022/03/17 14:23:34 visa Exp $ */
/* $NetBSD: kern_prot.c,v 1.33 1996/02/09 18:59:42 christos Exp $ */
/*
inline void
crset(struct ucred *newcr, const struct ucred *cr)
{
- KASSERT(cr->cr_ref > 0);
+ KASSERT(cr->cr_refcnt.r_refs > 0);
memcpy(
(char *)newcr + offsetof(struct ucred, cr_startcopy),
(const char *)cr + offsetof(struct ucred, cr_startcopy),
struct ucred *cr;
cr = pool_get(&ucred_pool, PR_WAITOK|PR_ZERO);
- cr->cr_ref = 1;
+ refcnt_init(&cr->cr_refcnt);
return (cr);
}
struct ucred *
crhold(struct ucred *cr)
{
- atomic_inc_int(&cr->cr_ref);
+ refcnt_take(&cr->cr_refcnt);
return (cr);
}
void
crfree(struct ucred *cr)
{
-
- if (atomic_dec_int_nv(&cr->cr_ref) == 0)
+ if (refcnt_rele(&cr->cr_refcnt))
pool_put(&ucred_pool, cr);
}
{
struct ucred *newcr;
- if (cr->cr_ref == 1)
+ if (!refcnt_shared(&cr->cr_refcnt))
return (cr);
newcr = crget();
*newcr = *cr;
crfree(cr);
- newcr->cr_ref = 1;
+ refcnt_init(&newcr->cr_refcnt);
return (newcr);
}
newcr = crget();
*newcr = *cr;
- newcr->cr_ref = 1;
+ refcnt_init(&newcr->cr_refcnt);
return (newcr);
}
{
if (xcr->cr_ngroups < 0 || xcr->cr_ngroups > NGROUPS_MAX)
return (EINVAL);
- cr->cr_ref = 1;
+ refcnt_init(&cr->cr_refcnt);
cr->cr_uid = xcr->cr_uid;
cr->cr_gid = xcr->cr_gid;
cr->cr_ngroups = xcr->cr_ngroups;
-/* $OpenBSD: nfs_socket.c,v 1.139 2022/02/22 01:15:02 guenther Exp $ */
+/* $OpenBSD: nfs_socket.c,v 1.140 2022/03/17 14:23:34 visa Exp $ */
/* $NetBSD: nfs_socket.c,v 1.27 1996/04/15 20:20:00 thorpej Exp $ */
/*
nfsm_adv(nfsm_rndup(len));
nfsm_dissect(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
memset(&nd->nd_cr, 0, sizeof (struct ucred));
- nd->nd_cr.cr_ref = 1;
+ refcnt_init(&nd->nd_cr.cr_refcnt);
nd->nd_cr.cr_uid = fxdr_unsigned(uid_t, *tl++);
nd->nd_cr.cr_gid = fxdr_unsigned(gid_t, *tl++);
len = fxdr_unsigned(int, *tl);
-/* $OpenBSD: ucred.h,v 1.13 2018/06/21 13:58:21 visa Exp $ */
+/* $OpenBSD: ucred.h,v 1.14 2022/03/17 14:23:34 visa Exp $ */
/* $NetBSD: ucred.h,v 1.12 1995/06/01 22:44:50 jtc Exp $ */
/*
#ifndef _SYS_UCRED_H_
#define _SYS_UCRED_H_
+#include <sys/refcnt.h>
#include <sys/syslimits.h>
/*
* Credentials.
*/
struct ucred {
- u_int cr_ref; /* reference count */
+ struct refcnt cr_refcnt; /* reference count */
/* The following fields are all copied by crset() */
#define cr_startcopy cr_uid