summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_prot.c
diff options
context:
space:
mode:
authoralfred <alfred@FreeBSD.org>2000-11-27 00:09:16 +0000
committeralfred <alfred@FreeBSD.org>2000-11-27 00:09:16 +0000
commit614730a418012f55d510bf89ab1df3fab14b7747 (patch)
tree57a101f268b3e4a50a17e3a2dcbe046f30900c6c /sys/kern/kern_prot.c
parenta7e1babad983a776bddcb27872f4d6fec405f1b7 (diff)
downloadFreeBSD-src-614730a418012f55d510bf89ab1df3fab14b7747.zip
FreeBSD-src-614730a418012f55d510bf89ab1df3fab14b7747.tar.gz
ucred system overhaul:
1) mpsafe (protect the refcount with a mutex). 2) reduce duplicated code by removing the inlined crdup() from crcopy() and make crcopy() call crdup(). 3) use M_ZERO flag when allocating initial structs instead of calling bzero after allocation. 4) expand the size of the refcount from a u_short to an u_int, by using shorts we might have an overflow. Glanced at by: jake
Diffstat (limited to 'sys/kern/kern_prot.c')
-rw-r--r--sys/kern/kern_prot.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c
index ab1578b..b241270 100644
--- a/sys/kern/kern_prot.c
+++ b/sys/kern/kern_prot.c
@@ -1131,9 +1131,9 @@ crget()
{
register struct ucred *cr;
- MALLOC(cr, struct ucred *, sizeof(*cr), M_CRED, M_WAITOK);
- bzero((caddr_t)cr, sizeof(*cr));
+ MALLOC(cr, struct ucred *, sizeof(*cr), M_CRED, M_WAITOK|M_ZERO);
cr->cr_ref = 1;
+ mtx_init(&cr->cr_mtx, "ucred", MTX_DEF);
return (cr);
}
@@ -1145,7 +1145,10 @@ void
crfree(cr)
struct ucred *cr;
{
+
+ mtx_enter(&cr->cr_mtx, MTX_DEF);
if (--cr->cr_ref == 0) {
+ mtx_destroy(&cr->cr_mtx);
/*
* Some callers of crget(), such as nfs_statfs(),
* allocate a temporary credential, but don't
@@ -1154,6 +1157,8 @@ crfree(cr)
if (cr->cr_uidinfo != NULL)
uifree(cr->cr_uidinfo);
FREE((caddr_t)cr, M_CRED);
+ } else {
+ mtx_exit(&cr->cr_mtx, MTX_DEF);
}
}
@@ -1166,13 +1171,14 @@ crcopy(cr)
{
struct ucred *newcr;
- if (cr->cr_ref == 1)
+ mtx_enter(&cr->cr_mtx, MTX_DEF);
+ if (cr->cr_ref == 1) {
+ mtx_exit(&cr->cr_mtx, MTX_DEF);
return (cr);
- newcr = crget();
- *newcr = *cr;
- uihold(newcr->cr_uidinfo);
+ }
+ mtx_exit(&cr->cr_mtx, MTX_DEF);
+ newcr = crdup(cr);
crfree(cr);
- newcr->cr_ref = 1;
return (newcr);
}
@@ -1185,8 +1191,9 @@ crdup(cr)
{
struct ucred *newcr;
- newcr = crget();
+ MALLOC(newcr, struct ucred *, sizeof(*cr), M_CRED, M_WAITOK);
*newcr = *cr;
+ mtx_init(&newcr->cr_mtx, "ucred", MTX_DEF);
uihold(newcr->cr_uidinfo);
newcr->cr_ref = 1;
return (newcr);
OpenPOWER on IntegriCloud