FreeBSD/sys/kern/kern_prot.c
/*
 * Extend the passed in credential to hold n items.
 */
Extend the passed in credential to hold n items.
Extend the passed in credential to hold n items .
void
crextend(struct ucred *cr, int n)
{
	int cnt;
	if (n <= cr->cr_agroups)
		return;
	if ( n < PAGE_SIZE / sizeof(gid_t) ) {
		if (cr->cr_agroups == 0)
			cnt = MINALLOCSIZE / sizeof(gid_t);
		else
			cnt = cr->cr_agroups * 2;
		while (cnt < n)
			cnt *= 2;
	} else
		cnt = roundup2(n, PAGE_SIZE / sizeof(gid_t));
	if (cr->cr_groups != cr->cr_smallgroups)
		free(cr->cr_groups, M_CRED);
	cr->cr_groups = malloc(cnt * sizeof(gid_t), M_CRED, M_WAITOK | M_ZERO);
	cr->cr_agroups = cnt;
}
void crextend ( struct ucred * cr , int n ) { int cnt ; if ( n <= cr -> cr_agroups ) return ; if ( n < PAGE_SIZE / sizeof ( gid_t ) ) { if ( cr -> cr_agroups == 0 ) cnt = MINALLOCSIZE / sizeof ( gid_t ) ; else cnt = cr -> cr_agroups * 2 ; while ( cnt < n ) cnt *= 2 ; } else cnt = roundup2 ( n , PAGE_SIZE / sizeof ( gid_t ) ) ; if ( cr -> cr_groups != cr -> cr_smallgroups ) free ( cr -> cr_groups , M_CRED ) ; cr -> cr_groups = malloc ( cnt * sizeof ( gid_t ) , M_CRED , M_WAITOK | M_ZERO ) ; cr -> cr_agroups = cnt ; }
Extend the passed in credential to hold n items.
Extend the passed in credential to hold n items .
/* Truncate? */ /*
	 * We extend by 2 each time since we're using a power of two
	 * allocator until we need enough groups to fill a page.
	 * Once we're allocating multiple pages, only allocate as many
	 * as we actually need.  The case of processes needing a
	 * non-power of two number of pages seems more likely than
	 * a real world process that adds thousands of groups one at a
	 * time.
	 */ /* Free the old array. */