Files
seta75D 2e8a93c394 Init
2021-10-11 18:20:23 -03:00

114 lines
1.8 KiB
C

#ifndef lint
static char sccsid[] = "@(#)kern_prot.c 1.1 92/07/30 Copyr 1983 Sun Micro";
#endif
/*
* System calls related to processes and protection
*/
#include <machine/reg.h>
#include <sys/param.h>
#include "boot/systm.h"
#include <sys/user.h>
#include <sys/vfs.h>
#include "boot/vnode.h"
#include <sys/proc.h>
#include <sys/timeb.h>
#include <sys/times.h>
#include <sys/reboot.h>
#include <sys/buf.h>
#include <sys/acct.h>
#undef u
extern struct user u;
/*
* Routines to allocate and free credentials structures
*/
int cractive = 0;
struct credlist {
union {
struct ucred cru_cred;
struct credlist *cru_next;
} cl_U;
#define cl_cred cl_U.cru_cred
#define cl_next cl_U.cru_next
};
struct credlist *crfreelist = NULL;
/*
* Allocate a zeroed cred structure and crhold it.
*/
struct ucred *
crget()
{
register struct ucred *cr;
if (crfreelist) {
cr = &crfreelist->cl_cred;
crfreelist = ((struct credlist *)cr)->cl_next;
} else {
cr = (struct ucred *)kmem_alloc((u_int)sizeof(*cr));
}
bzero((caddr_t)cr, sizeof(*cr));
crhold(cr);
cractive++;
return(cr);
}
/*
* Free a cred structure.
* Throws away space when ref count gets to 0.
*/
void
crfree(cr)
struct ucred *cr;
{
int s = spl6();
if (--cr->cr_ref != 0) {
(void) splx(s);
return;
}
((struct credlist *)cr)->cl_next = crfreelist;
crfreelist = (struct credlist *)cr;
cractive--;
(void) splx(s);
}
/*
* Copy cred structure to a new one and free the old one.
*/
struct ucred *
crcopy(cr)
struct ucred *cr;
{
struct ucred *newcr;
newcr = crget();
*newcr = *cr;
crfree(cr);
newcr->cr_ref = 1;
return(newcr);
}
/*
* Dup cred struct to a new held one.
*/
struct ucred *
crdup(cr)
struct ucred *cr;
{
struct ucred *newcr;
newcr = crget();
*newcr = *cr;
newcr->cr_ref = 1;
return(newcr);
}