+#if CONFIG_EMBEDDED
+int mach_do_background_thread(thread_t thread, int prio);
+
+int
+mach_do_background_thread(thread_t thread, int prio)
+{
+ int error = 0;
+ struct proc *curp = NULL;
+ struct proc *targetp = NULL;
+ kauth_cred_t ucred;
+
+ targetp = get_bsdtask_info(get_threadtask(thread));
+ if (!targetp) {
+ return KERN_INVALID_ARGUMENT;
+ }
+
+ curp = proc_self();
+ if (curp == PROC_NULL) {
+ return KERN_FAILURE;
+ }
+
+ ucred = kauth_cred_proc_ref(curp);
+
+ if (suser(ucred, NULL) && curp != targetp) {
+ error = KERN_PROTECTION_FAILURE;
+ goto out;
+ }
+
+ error = do_background_thread(curp, thread, prio);
+ if (!error) {
+ (void) do_background_socket(curp, thread, prio);
+ } else {
+ if (error == EPERM) {
+ error = KERN_PROTECTION_FAILURE;
+ } else {
+ error = KERN_FAILURE;
+ }
+ }
+
+out:
+ proc_rele(curp);
+ kauth_cred_unref(&ucred);
+ return error;
+}
+#endif /* CONFIG_EMBEDDED */
+
+#if CONFIG_EMBEDDED
+/*
+ * If the thread or its proc has been put into the background
+ * with setpriority(PRIO_DARWIN_{THREAD,PROCESS}, *, PRIO_DARWIN_BG),
+ * report that status.
+ *
+ * Returns: PRIO_DARWIN_BG if background
+ * 0 if foreground
+ */
+int
+uthread_get_background_state(uthread_t uth)
+{
+ proc_t p = uth->uu_proc;
+ if (p && (p->p_lflag & P_LBACKGROUND))
+ return PRIO_DARWIN_BG;
+
+ if (uth->uu_flag & UT_BACKGROUND)
+ return PRIO_DARWIN_BG;
+
+ return 0;
+}
+#endif /* CONFIG_EMBEDDED */