MCPcopy Create free account
hub / github.com/HelenOS/helenos / sys_thread_create

Function sys_thread_create

kernel/generic/src/proc/thread.c:1002–1074  ·  view source on GitHub ↗

Process syscall to create new thread. * */

Source from the content-addressed store, hash-verified

1000 *
1001 */
1002sys_errno_t sys_thread_create(uspace_ptr_uspace_arg_t uspace_uarg, uspace_ptr_char uspace_name,
1003 size_t name_len, uspace_ptr_thread_id_t uspace_thread_id)
1004{
1005 if (name_len > THREAD_NAME_BUFLEN - 1)
1006 name_len = THREAD_NAME_BUFLEN - 1;
1007
1008 char namebuf[THREAD_NAME_BUFLEN];
1009 errno_t rc = copy_from_uspace(namebuf, uspace_name, name_len);
1010 if (rc != EOK)
1011 return (sys_errno_t) rc;
1012
1013 namebuf[name_len] = 0;
1014
1015 /*
1016 * In case of failure, kernel_uarg will be deallocated in this function.
1017 * In case of success, kernel_uarg will be freed in uinit().
1018 */
1019 uspace_arg_t *kernel_uarg =
1020 (uspace_arg_t *) malloc(sizeof(uspace_arg_t));
1021 if (!kernel_uarg)
1022 return (sys_errno_t) ENOMEM;
1023
1024 rc = copy_from_uspace(kernel_uarg, uspace_uarg, sizeof(uspace_arg_t));
1025 if (rc != EOK) {
1026 free(kernel_uarg);
1027 return (sys_errno_t) rc;
1028 }
1029
1030 thread_t *thread = thread_create(uinit, kernel_uarg, TASK,
1031 THREAD_FLAG_USPACE | THREAD_FLAG_NOATTACH, namebuf);
1032 if (thread) {
1033 if (uspace_thread_id) {
1034 rc = copy_to_uspace(uspace_thread_id, &thread->tid,
1035 sizeof(thread->tid));
1036 if (rc != EOK) {
1037 /*
1038 * We have encountered a failure, but the thread
1039 * has already been created. We need to undo its
1040 * creation now.
1041 */
1042
1043 /*
1044 * The new thread structure is initialized, but
1045 * is still not visible to the system.
1046 * We can safely deallocate it.
1047 */
1048 slab_free(thread_cache, thread);
1049 free(kernel_uarg);
1050
1051 return (sys_errno_t) rc;
1052 }
1053 }
1054
1055#ifdef CONFIG_UDEBUG
1056 /*
1057 * Generate udebug THREAD_B event and attach the thread.
1058 * This must be done atomically (with the debug locks held),
1059 * otherwise we would either miss some thread or receive

Callers

nothing calls this directly

Calls 9

copy_from_uspaceFunction · 0.85
copy_to_uspaceFunction · 0.85
slab_freeFunction · 0.85
thread_attachFunction · 0.85
thread_readyFunction · 0.85
thread_createFunction · 0.70
mallocFunction · 0.50
freeFunction · 0.50

Tested by

no test coverage detected