Changeset 23 for trunk/kernel/syscalls/sys_thread_create.c
- Timestamp:
- Jun 18, 2017, 10:06:41 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_thread_create.c
r14 r23 2 2 * sys_thread_create.c - creates a new user thread 3 3 * 4 * Author Ghassan Almaless (2008,2009,2010,2011,2012) 5 * Mohamed lamine Karaoui (2015) 6 * Alain Greiner (2016) 4 * Author Alain Greiner (2016,2017) 7 5 * 8 6 * Copyright (c) UPMC Sorbonne Universites … … 26 24 #include <kernel_config.h> 27 25 #include <hal_types.h> 26 #include <hal_uspace.h> 28 27 #include <printk.h> 29 28 #include <errno.h> … … 38 37 #include <spinlock.h> 39 38 #include <dqdt.h> 39 #include <rpc.h> 40 40 41 41 … … 46 46 pthread_attr_t * user_attr, // [in] argument 47 47 void * start_func, // [in] argument 48 void * start_arg s )// [in] argument48 void * start_arg ) // [in] argument 49 49 { 50 pthread_attr_t attr;// copy of pthread attributes in kernel space50 pthread_attr_t k_attr; // copy of pthread attributes in kernel space 51 51 thread_t * parent; // pointer on thread executing the pthread_create 52 xptr_t xp_parent; // extended pointer on created thread53 thread_t * child ;// pointer on created child thread54 xptr_t xp_child; // extended pointer on created thread52 xptr_t parent_xp; // extended pointer on created thread 53 thread_t * child_ptr; // pointer on created child thread 54 xptr_t child_xp; // extended pointer on created thread 55 55 trdid_t trdid; // created thread identifier 56 56 process_t * process; // pointer on local process descriptor 57 paddr_t paddr; // unused, required by vmm_v2p_translate() 57 58 error_t error; 58 59 … … 64 65 // get parent thead pointer, extended pointer, and process pointer 65 66 parent = CURRENT_THREAD; 66 xp_parent= XPTR( local_cxy , parent );67 parent_xp = XPTR( local_cxy , parent ); 67 68 process = parent->process; 68 69 69 // check user_attr & start_func arguments 70 if( user_attr == NULL ) 70 // check user_attr in user space 71 error = vmm_v2p_translate( false , user_attr , &paddr ); 72 73 if( error ) 71 74 { 72 printk("\n[ERROR] in %s : user_attr is NULL\n", __FUNCTION__ ); 73 return EINVAL; 74 } 75 if( start_func== NULL ) 76 { 77 printk("\n[ERROR] in %s : start_func is NULL\n", __FUNCTION__ ); 78 return EINVAL; 75 printk("\n[ERROR] in %s : user_attr unmapped\n", __FUNCTION__ ); 76 parent->errno = EINVAL; 77 return -1; 79 78 } 80 79 81 // copy user_attr structure to kernel space 82 hal_copy_from_uspace( &attr , user_attr , sizeof(pthread_attr_t) ); 80 // check start_func in user space 81 error = vmm_v2p_translate( false , start_func , &paddr ); 82 83 if( error ) 84 { 85 printk("\n[ERROR] in %s : start_func unmapped\n", __FUNCTION__ ); 86 parent->errno = EINVAL; 87 return -1; 88 } 89 90 // check start_arg in user space 91 if( start_arg != NULL ) error = vmm_v2p_translate( false , start_arg , &paddr ); 92 93 if( error ) 94 { 95 printk("\n[ERROR] in %s : start_arg unmapped\n", __FUNCTION__ ); 96 parent->errno = EINVAL; 97 return -1; 98 } 99 100 // copy user_attr structure from user space to kernel space 101 hal_copy_from_uspace( &k_attr , user_attr , sizeof(pthread_attr_t) ); 83 102 84 103 // check/set "cxy" attribute 85 if( attr.flags & PT_FLAG_CLUSTER_DEFINED )104 if( k_attr.attributes & PT_ATTR_CLUSTER_DEFINED ) 86 105 { 87 if( cluster_is_undefined( attr.cxy ) )106 if( cluster_is_undefined( k_attr.cxy ) ) 88 107 { 89 printk("\n[ERROR] in %s : illegal target cluster = %x\n", 90 __FUNCTION__ , attr.cxy ); 91 return = EINVAL; 108 printk("\n[ERROR] in %s : illegal target cluster attribute = %x\n", 109 __FUNCTION__ , k_attr.cxy ); 110 parent->errno = EINVAL; 111 return -1; 92 112 } 93 113 } 94 114 else 95 115 { 96 attr.cxy = dqdt_get_cluster_for_process();116 k_attr.cxy = dqdt_get_cluster_for_process(); 97 117 } 98 118 99 // set "pid", "start_func" & "start_args" attributes100 attr.pid = process->pid;101 attr.start_func = start_func;102 attr.start_args = start_args;103 104 119 // create the thread, using a RPC if required 105 // this returns "error", "child", and "xp_child" 106 if( attr.cxy == local_cxy ) // target cluster is local 120 // this returns "error", "child", and "child_xp" 121 122 if( k_attr.cxy == local_cxy ) // target cluster is local 107 123 { 108 // allocate a stack from local VMM109 vseg_t * vseg = vmm_create_vseg( process,110 0,111 0,112 VSEG_TYPE_STACK,113 local_cxy );114 if( vseg == NULL )115 {116 printk("\n[ERROR] in %s for : cannot create stack vseg\n", __FUNCTION__ );117 return = EINVAL;118 }119 124 120 125 // create thread in local cluster 121 error = thread_user_create( &child, 122 &attr, 123 vseg->min, 124 vseg->max - vseg->min ); 126 error = thread_user_create( process->pid, 127 start_func, 128 start_arg, 129 &k_attr, 130 &child_ptr ); 125 131 126 xp_child = XPTR( local_cxy , thread);132 child_xp = XPTR( local_cxy , child_ptr ); 127 133 } 128 134 else // target cluster is remote 129 135 { 130 rpc_thread_user_create( attr.cxy , &attr , &error , &xp_child ); 131 child = (thread_t *)GET_PTR( xp_child ); 136 rpc_thread_user_create_client( k_attr.cxy, 137 process->pid, 138 start_func, 139 start_arg, 140 &k_attr, 141 &child_xp, 142 &error ); 143 144 child_ptr = (thread_t *)GET_PTR( child_xp ); 132 145 } 133 146 … … 140 153 141 154 // returns trdid to user space 142 trdid = hal_remote_lw( XPTR( attr.cxy , &child->trdid ) );155 trdid = hal_remote_lw( XPTR( k_attr.cxy , &child_ptr->trdid ) ); 143 156 hal_copy_to_uspace( new_thread , &trdid , sizeof(pthread_t) ); 144 157 145 158 // register new-thread in parent-thread children list if required 146 if( attr.flags & PT_FLAG_DETACH == 0 ) thread_child_parent_link( xp_parent , xp_child ); 159 if( (k_attr.attributes & PT_ATTR_DETACH) == 0 ) 160 thread_child_parent_link( parent_xp , child_xp ); 147 161 148 162 tm_end = hal_time_stamp(); … … 150 164 thread_dmsg("\n[INFO] %s created thread %x for process %x in cluster %x\n" 151 165 " start_cycle = %d / end_cycle = %d\n", 152 trdid , process->pid , attr.cxy , tm_start , tm_end );166 trdid , process->pid , k_attr.cxy , tm_start , tm_end ); 153 167 return 0; 154 168
Note: See TracChangeset
for help on using the changeset viewer.