kern_return_t thread_create_workq( task_t task, thread_continue_t thread_return, thread_t *new_thread) { kern_return_t result; thread_t thread; if (task == TASK_NULL || task == kernel_task) return (KERN_INVALID_ARGUMENT); result = thread_create_internal(task, -1, thread_return, TH_OPTION_NOCRED | TH_OPTION_NOSUSP, &thread); if (result != KERN_SUCCESS) return (result); thread->user_stop_count = 1; thread_hold(thread); if (task->suspend_count > 0) thread_hold(thread); task_unlock(task); lck_mtx_unlock(&tasks_threads_lock); *new_thread = thread; return (KERN_SUCCESS); }
/* * kernel_thread_create: * * Create a thread in the kernel task * to execute in kernel context. */ kern_return_t kernel_thread_create( thread_continue_t continuation, void *parameter, integer_t priority, thread_t *new_thread) { kern_return_t result; thread_t thread; task_t task = kernel_task; result = thread_create_internal(task, priority, continuation, TH_OPTION_NONE, &thread); if (result != KERN_SUCCESS) return (result); task_unlock(task); lck_mtx_unlock(&tasks_threads_lock); stack_alloc(thread); assert(thread->kernel_stack != 0); #if CONFIG_EMBEDDED if (priority > BASEPRI_KERNEL) #endif thread->reserved_stack = thread->kernel_stack; thread->parameter = parameter; if(debug_task & 1) kprintf("kernel_thread_create: thread = %p continuation = %p\n", thread, continuation); *new_thread = thread; return (result); }
static kern_return_t thread_create_internal2( task_t task, thread_t *new_thread, boolean_t from_user) { kern_return_t result; thread_t thread; if (task == TASK_NULL || task == kernel_task) return (KERN_INVALID_ARGUMENT); result = thread_create_internal(task, -1, (thread_continue_t)thread_bootstrap_return, TH_OPTION_NONE, &thread); if (result != KERN_SUCCESS) return (result); thread->user_stop_count = 1; thread_hold(thread); if (task->suspend_count > 0) thread_hold(thread); if (from_user) extmod_statistics_incr_thread_create(task); task_unlock(task); lck_mtx_unlock(&tasks_threads_lock); *new_thread = thread; return (KERN_SUCCESS); }
kern_return_t thread_create( task_t task, thread_t *new_thread) { kern_return_t result; thread_t thread; if (task == TASK_NULL || task == kernel_task) return (KERN_INVALID_ARGUMENT); result = thread_create_internal(task, -1, (thread_continue_t)thread_bootstrap_return, &thread); if (result != KERN_SUCCESS) return (result); thread->user_stop_count = 1; thread_hold(thread); if (task->suspend_count > 0) thread_hold(thread); task_unlock(task); mutex_unlock(&tasks_threads_lock); *new_thread = thread; return (KERN_SUCCESS); }
static kern_return_t thread_create_running_internal2( register task_t task, int flavor, thread_state_t new_state, mach_msg_type_number_t new_state_count, thread_t *new_thread, boolean_t from_user) { register kern_return_t result; thread_t thread; if (task == TASK_NULL || task == kernel_task) return (KERN_INVALID_ARGUMENT); result = thread_create_internal(task, -1, (thread_continue_t)thread_bootstrap_return, TH_OPTION_NONE, &thread); if (result != KERN_SUCCESS) return (result); result = machine_thread_set_state( thread, flavor, new_state, new_state_count); if (result != KERN_SUCCESS) { task_unlock(task); lck_mtx_unlock(&tasks_threads_lock); thread_terminate(thread); thread_deallocate(thread); return (result); } thread_mtx_lock(thread); thread_start_internal(thread); thread_mtx_unlock(thread); if (from_user) extmod_statistics_incr_thread_create(task); task_unlock(task); lck_mtx_unlock(&tasks_threads_lock); *new_thread = thread; return (result); }