Changeset 433 for trunk/kernel/syscalls/sys_exec.c
- Timestamp:
- Feb 14, 2018, 3:40:19 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_exec.c
r421 r433 149 149 ///////////////////////////////////////////////////////////////////////////////////////// 150 150 // Implementation note: 151 // This function build an exec_info_t structure containing all informations 151 // This function must be called by the main thread (thread 0 in owner cluster). 152 // IT build an exec_info_t structure containing all informations 152 153 // required to initialize the new process descriptor and the associated thread. 153 // It includes the process PID (unchanged), main() arguments,environment variables,154 // It includes the process main() arguments, the environment variables, 154 155 // and the pathname to the new process .elf file. 155 156 // It calls the process_exec_get_strings() functions to copy the main() arguments and … … 169 170 error_t error; 170 171 171 // get parent processpid172 // get calling thread, process, & pid 172 173 thread_t * this = CURRENT_THREAD; 173 174 process_t * process = this->process; 174 175 pid_t pid = process->pid; 175 176 176 #if CONFIG_SYSCALL_DEBUG 177 assert( (CXY_FROM_PID( pid ) == local_cxy) , __FUNCTION__ , 178 "must be called in the owner cluster\n"); 179 180 assert( (LTID_FROM_TRDID( this->trdid ) == 0) , __FUNCTION__ , 181 "must be called by the main thread\n"); 182 183 assert( (args == NULL) , __FUNCTION__ , 184 "args not supported yet\n" ); 185 186 assert( (envs == NULL) , __FUNCTION__ , 187 "args not supported yet\n" ); 188 189 // get owner cluster 190 191 // check pathname length 192 if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH ) 193 { 194 195 #if CONFIG_DEBUG_SYSCALLS_ERROR 196 printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ ); 197 #endif 198 this->errno = ENFILE; 199 return -1; 200 } 201 202 // copy pathname in exec_info structure (kernel space) 203 hal_strcpy_from_uspace( exec_info.path , pathname , CONFIG_VFS_MAX_PATH_LENGTH ); 204 205 #if CONFIG_DEBUG_SYS_EXEC 177 206 uint64_t tm_start; 178 207 uint64_t tm_end; 179 208 tm_start = hal_get_cycles(); 180 printk("\n[DBG] %s : core[%x,%d] enter / process %x / cycle = %d\n", 181 __FUNCTION__, local_cxy, this->core->lid, pid, (uint32_t)tm_start ); 182 #endif 183 184 // get owner cluster 185 cxy_t owner_cxy = CXY_FROM_PID( pid ); 186 187 // check pathname length 188 if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH ) 189 { 190 printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ ); 191 this->errno = ENFILE; 192 return -1; 193 } 194 195 // copy pathname in exec_info structure (kernel space) 196 hal_strcpy_from_uspace( exec_info.path , pathname , CONFIG_VFS_MAX_PATH_LENGTH ); 197 198 // check args argument 199 assert( (args == NULL) , __FUNCTION__ , 200 "args not supported yet\n" ); 201 202 // check envs argument 203 assert( (envs == NULL) , __FUNCTION__ , 204 "args not supported yet\n" ); 209 if( CONFIG_DEBUG_SYS_EXEC < tm_start ) 210 printk("\n[DBG] %s : thread %x enter / process %x / path %s / cycle = %d\n", 211 __FUNCTION__, this, pid, exec_info.path, (uint32_t)tm_start ); 212 #endif 205 213 206 214 // check and store args in exec_info structure if required … … 209 217 if( process_exec_get_strings( &exec_info , true , args ) ) 210 218 { 211 printk("\n[ERROR] in %s : cannot access args\n", __FUNCTION__ ); 219 220 #if CONFIG_DEBUG_SYSCALLS_ERROR 221 printk("\n[ERROR] in %s : cannot access args\n", __FUNCTION__ ); 222 #endif 212 223 this->errno = error; 213 224 return -1; … … 220 231 if( process_exec_get_strings( &exec_info , false , envs ) ) 221 232 { 222 printk("\n[ERROR] in %s : cannot access envs\n", __FUNCTION__ ); 233 234 #if CONFIG_DEBUG_SYCALLS_ERROR 235 printk("\n[ERROR] in %s : cannot access envs\n", __FUNCTION__ ); 236 #endif 223 237 this->errno = error; 224 238 return -1; … … 226 240 } 227 241 228 // register PID in exec_info 229 exec_info.pid = pid; 230 231 // call process_make_exec (local or remote) 232 if( owner_cxy == local_cxy ) 233 { 234 error = process_make_exec( &exec_info ); 235 } 236 else 237 { 238 rpc_process_make_exec_client( owner_cxy, 239 &exec_info, 240 &error ); 241 } 242 // call relevant kernel function 243 error = process_make_exec( &exec_info ); 242 244 243 245 if( error ) 244 246 { 245 printk("\n[ERROR] in %s : cannot create new process %x in cluster %x\n", 246 __FUNCTION__, pid, owner_cxy ); 247 248 #if CONFIG_DEBUG_SYSCALLS_ERROR 249 printk("\n[ERROR] in %s : cannot create process %x in cluster %x\n", 250 __FUNCTION__, pid, CXY_FROM_PID( pid ); 251 #endif 247 252 this->errno = error; 248 253 return -1; 249 254 } 250 255 251 #if CONFIG_ SYSCALL_DEBUG256 #if CONFIG_DEBUG_SYS_EXEC 252 257 tm_end = hal_get_cycles(); 253 printk("\n[DBG] %s : core[%x,%d] exit / process %x / path = %s / cost = %d / cycle %d\n", 254 __FUNCTION__, local_cxy, this->core->lid, pid, exec_info.path, 255 (uint32_t)(tm_end - tm_start) , (uint32_t)tm_end ); 256 #endif 257 258 return 0; 258 if( CONFIG_DEBUG_SYS_EXEC < tm_end ) 259 printk("\n[DBG] %s : thread %x exit / process %x / cost = %d / cycle %d\n", 260 __FUNCTION__, this, pid, (uint32_t)(tm_end - tm_start), (uint32_t)tm_end ); 261 #endif 262 263 // deschedule <=> old thread suicide because the BLOCKED_GLOBAL 264 // and the FLAG_REQ_DELETE have been set by process_make_exec() 265 sched_yield( "old process suicide in sys_exec()" ); 266 267 assert( false , __FUNCTION__ , "This code should not be executed\n" ); 268 269 return 0; 259 270 260 271 } // end sys_exec()
Note: See TracChangeset
for help on using the changeset viewer.