]> git.saurik.com Git - apple/xnu.git/blobdiff - security/mac_label.c
xnu-7195.101.1.tar.gz
[apple/xnu.git] / security / mac_label.c
index 0f4e21524cb2531d3f574247725471addb7ea746..aeb2d871b550d56bed72cef0e2d4953e37470f8d 100644 (file)
 #include <sys/systm.h>
 #include <security/mac_internal.h>
 
-static zone_t zone_label;
-
-void
-mac_labelzone_init(void)
-{
-
-       zone_label = zinit(sizeof(struct label),
-           8192 * sizeof(struct label),
-           sizeof(struct label), "MAC Labels");
-       zone_change(zone_label, Z_EXPAND, TRUE);
-       zone_change(zone_label, Z_EXHAUST, FALSE);
-}
+static ZONE_DECLARE(zone_label, "MAC Labels", sizeof(struct label), ZC_ZFREE_CLEARMEM);
 
 struct label *
 mac_labelzone_alloc(int flags)
 {
+       int zflags = Z_ZERO | (flags & MAC_NOWAIT);
        struct label *l;
 
-       if (flags & MAC_NOWAIT) 
-               l = (struct label *) zalloc_noblock(zone_label);
-       else
-               l = (struct label *) zalloc(zone_label);
-       if (l == NULL)
-               return (NULL);
-
-       bzero(l, sizeof(struct label));
-       l->l_flags = MAC_FLAG_INITIALIZED;
-       return (l);
+       static_assert(MAC_NOWAIT == Z_NOWAIT);
+       l = zalloc_flags(zone_label, zflags);
+       if (l) {
+               l->l_flags = MAC_FLAG_INITIALIZED;
+       }
+       return l;
 }
 
 void
 mac_labelzone_free(struct label *l)
 {
-
-       if (l == NULL)
+       if (l == NULL) {
                panic("Free of NULL MAC label\n");
+       }
 
-       if ((l->l_flags & MAC_FLAG_INITIALIZED) == 0)
+       if ((l->l_flags & MAC_FLAG_INITIALIZED) == 0) {
                panic("Free of uninitialized label\n");
+       }
        bzero(l, sizeof(struct label));
        zfree(zone_label, l);
 }
@@ -88,7 +75,7 @@ mac_label_get(struct label *l, int slot)
 {
        KASSERT(l != NULL, ("mac_label_get: NULL label"));
 
-       return ((intptr_t) (l->l_perpolicy[slot].l_ptr));
+       return (intptr_t) (l->l_perpolicy[slot].l_ptr);
 }
 
 void
@@ -98,4 +85,3 @@ mac_label_set(struct label *l, int slot, intptr_t v)
 
        l->l_perpolicy[slot].l_ptr = (void *) v;
 }
-