+ /*
+ * Thread inherits credential from the creating thread, if both
+ * are in the same task.
+ *
+ * If the creating thread has no credential or is from another
+ * task we can leave the new thread credential NULL. If it needs
+ * one later, it will be lazily assigned from the task's process.
+ */
+ uth_parent = (struct uthread *)get_bsdthread_info(current_thread());
+ if ((task == current_task()) &&
+ (uth_parent != NULL) &&
+ (uth_parent->uu_ucred != NOCRED)) {
+ uth->uu_ucred = uth_parent->uu_ucred;
+ kauth_cred_ref(uth->uu_ucred);
+ /* the credential we just inherited is an assumed credential */
+ if (uth_parent->uu_flag & UT_SETUID)
+ uth->uu_flag |= UT_SETUID;
+ } else {
+ uth->uu_ucred = NOCRED;
+ }
+
+ if (task != kernel_task) {
+