Changeset d4f439f in rtems-libbsd


Ignore:
Timestamp:
Mar 7, 2012, 9:10:49 PM (7 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.11, 5283630d2c9d40deb0183696d278e02644fe4326, freebsd-9.3, bc2ba9a9cdc7381c2a4f2ae6ee303be636f31368
Children:
cbffdb7f
Parents:
b23aecc
Message:

Add rmlock - almost links

Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • Makefile

    rb23aecc rd4f439f  
    266266        rtems/freebsd/rtems/rtems-bsd-lock.c \
    267267        rtems/freebsd/rtems/rtems-bsd-sx.c \
     268        rtems/freebsd/rtems/rtems-bsd-rmlock.c \
    268269        rtems/freebsd/rtems/rtems-bsd-rwlock.c \
    269270        rtems/freebsd/rtems/rtems-bsd-generic.c \
  • rtems/freebsd/rtems/rtems-bsd-prot.c

    rb23aecc rd4f439f  
    2525#include <rtems/freebsd/sys/types.h>
    2626#include <rtems/freebsd/sys/systm.h>
     27#include <rtems/freebsd/vm/uma.h>
    2728#include <rtems/freebsd/sys/malloc.h>
    2829#include <rtems/freebsd/sys/ucred.h>
     30#include <rtems/freebsd/sys/refcount.h>
    2931
    3032static MALLOC_DEFINE(M_CRED, "cred", "credentials");
     33
     34static void crextend(struct ucred *cr, int n);
     35static void crsetgroups_locked(struct ucred *cr, int ngrp,
     36    gid_t *groups);
     37
     38
    3139
    3240/*
     
    141149  return (newcr);
    142150}
     151
     152/*
     153 * Extend the passed in credential to hold n items.
     154 */
     155static void
     156crextend(struct ucred *cr, int n)
     157{
     158        int cnt;
     159
     160        /* Truncate? */
     161        if (n <= cr->cr_agroups)
     162                return;
     163
     164        /*
     165         * We extend by 2 each time since we're using a power of two
     166         * allocator until we need enough groups to fill a page.
     167         * Once we're allocating multiple pages, only allocate as many
     168         * as we actually need.  The case of processes needing a
     169         * non-power of two number of pages seems more likely than
     170         * a real world process that adds thousands of groups one at a
     171         * time.
     172         */
     173        if ( n < PAGE_SIZE / sizeof(gid_t) ) {
     174                if (cr->cr_agroups == 0)
     175                        cnt = MINALLOCSIZE / sizeof(gid_t);
     176                else
     177                        cnt = cr->cr_agroups * 2;
     178
     179                while (cnt < n)
     180                        cnt *= 2;
     181        } else
     182                cnt = roundup2(n, PAGE_SIZE / sizeof(gid_t));
     183
     184        /* Free the old array. */
     185        if (cr->cr_groups)
     186                free(cr->cr_groups, M_CRED);
     187
     188        cr->cr_groups = malloc(cnt * sizeof(gid_t), M_CRED, M_WAITOK | M_ZERO);
     189        cr->cr_agroups = cnt;
     190}
     191
     192/*
     193 * Copy groups in to a credential, preserving any necessary invariants.
     194 * Currently this includes the sorting of all supplemental gids.
     195 * crextend() must have been called before hand to ensure sufficient
     196 * space is available.
     197 */
     198static void
     199crsetgroups_locked(struct ucred *cr, int ngrp, gid_t *groups)
     200{
     201        int i;
     202        int j;
     203        gid_t g;
     204       
     205        KASSERT(cr->cr_agroups >= ngrp, ("cr_ngroups is too small"));
     206
     207        bcopy(groups, cr->cr_groups, ngrp * sizeof(gid_t));
     208        cr->cr_ngroups = ngrp;
     209
     210        /*
     211         * Sort all groups except cr_groups[0] to allow groupmember to
     212         * perform a binary search.
     213         *
     214         * XXX: If large numbers of groups become common this should
     215         * be replaced with shell sort like linux uses or possibly
     216         * heap sort.
     217         */
     218        for (i = 2; i < ngrp; i++) {
     219                g = cr->cr_groups[i];
     220                for (j = i-1; j >= 1 && g < cr->cr_groups[j]; j--)
     221                        cr->cr_groups[j + 1] = cr->cr_groups[j];
     222                cr->cr_groups[j + 1] = g;
     223        }
     224}
     225
     226/*
     227 * Copy groups in to a credential after expanding it if required.
     228 * Truncate the list to (ngroups_max + 1) if it is too large.
     229 */
     230void
     231crsetgroups(struct ucred *cr, int ngrp, gid_t *groups)
     232{
     233
     234        if (ngrp > ngroups_max + 1)
     235                ngrp = ngroups_max + 1;
     236
     237        crextend(cr, ngrp);
     238        crsetgroups_locked(cr, ngrp, groups);
     239}
     240
  • testsuite/link01/test.c

    rb23aecc rd4f439f  
    1010#include <rtems/freebsd/bsd.h>
    1111
     12/* needed by rtems-bsd-resource.c */
    1213int maxproc;
     14
     15/* needed by rtems-bsd-prot.c */
    1316int ngroups_max;
    1417
     18/* needed by rtems-bsd-prot.c */
    1519void prison_hold() {}
    1620void prison_free() {}
    1721
     22/* needed by rtems-bsd-init-with-irq.c */
    1823void rtems_interrupt_server_initialize(void) { }
    1924
Note: See TracChangeset for help on using the changeset viewer.