Changeset 566 for trunk/kernel/syscalls/sys_thread_create.c
- Timestamp:
- Oct 4, 2018, 11:50:21 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_thread_create.c
r506 r566 35 35 #include <kmem.h> 36 36 #include <process.h> 37 #include <spinlock.h>38 37 #include <dqdt.h> 39 38 #include <rpc.h> … … 41 40 #include <syscalls.h> 42 41 43 /////////////////////////////////////////////////// 44 int sys_thread_create( 45 struct thread_s * new_thread, 46 const struct pthread_attr_s * user_attr, 47 const void * start_func, 48 const void * start_args ) 42 ///////////////////////////////////////////////////////// 43 int sys_thread_create( trdid_t * trdid_ptr, 44 struct pthread_attr_s * user_attr, 45 void * start_func, 46 void * start_args ) 49 47 { 50 48 pthread_attr_t kern_attr; // copy of pthread attributes in kernel space 51 49 thread_t * parent; // pointer on thread executing the pthread_create 52 xptr_t parent_xp; // extended pointer on created thread 50 xptr_t parent_xp; // extended pointer on calling thread 51 cxy_t child_cxy; // created child thread cluster identifier 53 52 thread_t * child_ptr; // pointer on created child thread 54 53 xptr_t child_xp; // extended pointer on created thread … … 56 55 process_t * process; // pointer on local process descriptor 57 56 vseg_t * vseg; // required for user space checking 58 cxy_t target_cxy; // target cluster identifier59 57 error_t error; 60 58 … … 69 67 tm_start = hal_get_cycles(); 70 68 if( DEBUG_SYS_THREAD_CREATE < tm_start ) 71 printk("\n[DBG] %s : thread %x (cxy %x) enter / process %x/ cycle %d\n",72 __FUNCTION__, parent , local_cxy, process->pid, (uint32_t)tm_start );69 printk("\n[DBG] %s : thread %x in process %x enter / cycle %d\n", 70 __FUNCTION__, parent->trdid, process->pid, (uint32_t)tm_start ); 73 71 #endif 74 72 75 73 // check trdid buffer in user space 76 error = vmm_get_vseg( process , (intptr_t) new_thread, &vseg );74 error = vmm_get_vseg( process , (intptr_t)trdid_ptr , &vseg ); 77 75 78 76 if ( error ) … … 80 78 81 79 #if DEBUG_SYSCALLS_ERROR 82 printk("\n[ERROR] in %s : t rdid buffer unmapped %x / thread %x / process%x\n",83 __FUNCTION__ , (intptr_t)new_thread, parent->trdid, process->pid);80 printk("\n[ERROR] in %s : thread %x in process %x / trdid buffer %x unmapped %x\n", 81 __FUNCTION__, parent->trdid, process->pid, (intptr_t)trdid_ptr ); 84 82 vmm_display( process , false ); 85 83 #endif … … 97 95 98 96 #if DEBUG_SYSCALLS_ERROR 99 printk("\n[ERROR] in %s : user_attr buffer unmapped %x / thread %x / process%x\n",100 __FUNCTION__ , (intptr_t)user_attr , parent->trdid , process->pid);97 printk("\n[ERROR] in %s : thread %x in process %x / user_attr buffer unmapped %x\n", 98 __FUNCTION__, parent->trdid, process->pid, (intptr_t)user_attr ); 101 99 vmm_display( process , false ); 102 100 #endif … … 115 113 116 114 #if DEBUG_SYSCALLS_ERROR 117 printk("\n[ERROR] in %s : start_func unmapped %x / thread %x / process%x\n",118 __FUNCTION__ , (intptr_t)start_func , parent->trdid , process->pid);115 printk("\n[ERROR] in %s : thread %x in process %x / start_func unmapped %x\n", 116 __FUNCTION__, parent->trdid, process->pid, (intptr_t)start_func ); 119 117 vmm_display( process , false ); 120 118 #endif … … 132 130 133 131 #if DEBUG_SYSCALLS_ERROR 134 printk("\n[ERROR] in %s : start_args buffer unmapped %x / thread %x / process%x\n",135 __FUNCTION__ , (intptr_t)start_args , parent->trdid , process->pid);132 printk("\n[ERROR] in %s : thread %x in process %x / start_args buffer unmapped %x\n", 133 __FUNCTION__, parent->trdid, process->pid, (intptr_t)start_args ); 136 134 vmm_display( process , false ); 137 135 #endif … … 141 139 } 142 140 143 // define attributes and target_cxy141 // define attributes and child_cxy 144 142 if( user_attr != NULL ) // user defined attributes 145 143 { 146 // check / get target_cxy144 // check / get child_cxy 147 145 if( kern_attr.attributes & PT_ATTR_CLUSTER_DEFINED ) 148 146 { … … 151 149 152 150 #if DEBUG_SYSCALLS_ERROR 153 printk("\n[ERROR] in %s : illegal target cluster = %x / thread %x / process%x\n",154 __FUNCTION__ , kern_attr.cxy, parent->trdid, process->pid);151 printk("\n[ERROR] in %s : thread %x in process %x / illegal target cluster %x\n", 152 __FUNCTION__, parent->trdid, process->pid, kern_attr.cxy ); 155 153 #endif 156 154 parent->errno = EINVAL; 157 155 return -1; 158 156 } 159 target_cxy = kern_attr.cxy;157 child_cxy = kern_attr.cxy; 160 158 } 161 159 else 162 160 { 163 target_cxy = dqdt_get_cluster_for_process();161 child_cxy = dqdt_get_cluster_for_process(); 164 162 } 165 163 } … … 167 165 { 168 166 kern_attr.attributes = PT_ATTR_DETACH | PT_ATTR_CLUSTER_DEFINED; 169 target_cxy = dqdt_get_cluster_for_process();167 child_cxy = dqdt_get_cluster_for_process(); 170 168 } 171 169 … … 173 171 // this returns "error", "child_ptr", and "child_xp" 174 172 175 if( target_cxy == local_cxy ) // target cluster is local173 if( child_cxy == local_cxy ) // target cluster is local 176 174 { 177 175 // create thread in local cluster … … 186 184 else // target cluster is remote 187 185 { 188 rpc_thread_user_create_client( target_cxy,186 rpc_thread_user_create_client( child_cxy, 189 187 process->pid, 190 188 start_func, … … 202 200 203 201 #if DEBUG_SYSCALLS_ERROR 204 printk("\n[ERROR] in %s : cannot create new thread / thread %x / process %x\n",202 printk("\n[ERROR] in %s : thread %x in process %x cannot create new thread\n", 205 203 __FUNCTION__ , parent->trdid, process->pid ); 206 204 #endif … … 210 208 211 209 // returns trdid to user space 212 trdid = hal_remote_l w( XPTR( target_cxy , &child_ptr->trdid ) );213 hal_copy_to_uspace( new_thread, &trdid , sizeof(pthread_t) );210 trdid = hal_remote_l32( XPTR( child_cxy , &child_ptr->trdid ) ); 211 hal_copy_to_uspace( trdid_ptr , &trdid , sizeof(pthread_t) ); 214 212 215 213 // activate new thread … … 221 219 tm_end = hal_get_cycles(); 222 220 if( DEBUG_SYS_THREAD_CREATE < tm_end ) 223 printk("\n[DBG] %s : thread %x (cxy %x) created thread %x (cxy %x) / process%x / cycle %d\n",224 __FUNCTION__, parent , local_cxy, child_ptr, target_cxy, process->pid, (uint32_t)tm_end );221 printk("\n[DBG] %s : thread %x in process %x created thread %x / cycle %d\n", 222 __FUNCTION__, parent->trdid, process->pid, child_ptr->trdid, (uint32_t)tm_end ); 225 223 #endif 226 224
Note: See TracChangeset
for help on using the changeset viewer.