+ return class;
+}
+
+/*
+ * Return a new class mask that allows changing the reserved class bit
+ * only if the current task is entitled to do so or if this is being done
+ * from the kernel task. If the current task is not allowed to make the
+ * change, the reserved bit is reverted to its previous state and the rest
+ * of the mask is left intact.
+ */
+static au_class_t
+au_class_protect(au_class_t old_class, au_class_t new_class)
+{
+ au_class_t result = new_class;
+
+ /* Check if the reserved class bit has been flipped */
+ if ((old_class & AU_CLASS_MASK_RESERVED) !=
+ (new_class & AU_CLASS_MASK_RESERVED)) {
+ task_t task = current_task();
+ if (task != kernel_task &&
+ !IOTaskHasEntitlement(task, AU_CLASS_RESERVED_ENTITLEMENT)) {
+ /*
+ * If the caller isn't entitled, revert the class bit:
+ * - First remove the reserved bit from the new_class mask
+ * - Next get the state of the old_class mask's reserved bit
+ * - Finally, OR the result from the first two operations
+ */
+ result = (new_class & ~AU_CLASS_MASK_RESERVED) |
+ (old_class & AU_CLASS_MASK_RESERVED);
+ }
+ }
+
+ return result;