Changeset 457 for trunk/kernel/libk/elf.c
- Timestamp:
- Aug 2, 2018, 11:47:13 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/libk/elf.c
r441 r457 23 23 24 24 #include <kernel_config.h> 25 #include <hal_ types.h>25 #include <hal_kernel_types.h> 26 26 #include <hal_special.h> 27 27 #include <hal_uspace.h> … … 210 210 } // end elf_segments_register() 211 211 212 ////////////////////////////////////////////// /213 error_t elf_load_process( char * pathname,214 process_t * process )212 ////////////////////////////////////////////// 213 error_t elf_load_process( xptr_t file_xp, 214 process_t * process ) 215 215 { 216 216 kmem_req_t req; // kmem request for program header … … 218 218 void * segs_base; // pointer on buffer for segment descriptors array 219 219 uint32_t segs_size; // size of buffer for segment descriptors array 220 xptr_t file_xp; // extended pointer on created file descriptor 221 uint32_t file_id; // file descriptor index (unused) 220 char name[CONFIG_VFS_MAX_NAME_LENGTH]; 222 221 error_t error; 223 222 223 // get file name for error reporting and debug 224 cxy_t file_cxy = GET_CXY( file_xp ); 225 vfs_file_t * file_ptr = GET_PTR( file_xp ); 226 vfs_inode_t * inode = hal_remote_lpt( XPTR( file_cxy , &file_ptr->inode ) ); 227 vfs_inode_get_name( XPTR( file_cxy , inode ) , name ); 228 224 229 #if DEBUG_ELF_LOAD 225 uint32_t cycle = (uint32_t)hal_get_cycles(); 226 if( DEBUG_ELF_LOAD < cycle ) 227 printk("\n[DBG] %s : thread %d enter for <%s> / cycle %d\n", 228 __FUNCTION__, CURRENT_THREAD, pathname, cycle ); 229 #endif 230 231 // avoid GCC warning 232 file_xp = XPTR_NULL; 233 file_id = -1; 234 235 // open file 236 error = vfs_open( process, 237 pathname, 238 O_RDONLY, 239 0, 240 &file_xp, 241 &file_id ); 242 if( error ) 243 { 244 printk("\n[ERROR] in %s : failed to open file <%s>\n", __FUNCTION__ , pathname ); 245 return -1; 246 } 247 248 #if (DEBUG_ELF_LOAD & 1) 249 if( DEBUG_ELF_LOAD < cycle ) 250 printk("\n[DBG] %s : open file <%s>\n", __FUNCTION__, pathname ); 230 uint32_t cycle = (uint32_t)hal_get_cycles(); 231 if( DEBUG_ELF_LOAD < cycle ) 232 printk("\n[DBG] %s : thread %d in process %x enter for <%s> / cycle %d\n", 233 __FUNCTION__, CURRENT_THREAD->trdid, process->pid, name, cycle ); 251 234 #endif 252 235 … … 257 240 if( error ) 258 241 { 259 printk("\n[ERROR] in %s : cannot get header for <%s>\n", __FUNCTION__ , pathname ); 260 vfs_close( file_xp , file_id ); 242 printk("\n[ERROR] in %s : cannot get header for <%s>\n", __FUNCTION__ , name ); 261 243 return -1; 262 244 } … … 264 246 #if (DEBUG_ELF_LOAD & 1) 265 247 if( DEBUG_ELF_LOAD < cycle ) 266 printk("\n[DBG] %s : loaded elf header for <%s>\n", __FUNCTION__ , pathname );248 printk("\n[DBG] %s : loaded elf header for <%s>\n", __FUNCTION__ , name ); 267 249 #endif 268 250 … … 270 252 { 271 253 printk("\n[ERROR] in %s : no segments found\n", __FUNCTION__ ); 272 vfs_close( file_xp , file_id );273 254 return -1; 274 255 } … … 286 267 { 287 268 printk("\n[ERROR] in %s : no memory for segment descriptors\n", __FUNCTION__ ); 288 vfs_close( file_xp , file_id );289 269 return -1; 290 270 } … … 296 276 { 297 277 printk("\n[ERROR] in %s : cannot seek for descriptors array\n", __FUNCTION__ ); 298 vfs_close( file_xp , file_id );299 278 req.ptr = segs_base; 300 279 kmem_free( &req ); … … 304 283 #if (DEBUG_ELF_LOAD & 1) 305 284 if( DEBUG_ELF_LOAD < cycle ) 306 printk("\n[DBG] %s : segments array allocated for <%s>\n", __FUNCTION__ , pathname );285 printk("\n[DBG] %s : segments array allocated for <%s>\n", __FUNCTION__ , name ); 307 286 #endif 308 287 … … 316 295 { 317 296 printk("\n[ERROR] in %s : cannot read segments descriptors\n", __FUNCTION__ ); 318 vfs_close( file_xp , file_id );319 297 req.ptr = segs_base; 320 298 kmem_free( &req ); … … 324 302 #if (DEBUG_ELF_LOAD & 1) 325 303 if( DEBUG_ELF_LOAD < cycle ) 326 printk("\n[DBG] %s loaded segments descriptors for <%s>\n", __FUNCTION__ , pathname );304 printk("\n[DBG] %s loaded segments descriptors for <%s>\n", __FUNCTION__ , name ); 327 305 #endif 328 306 … … 334 312 if( error ) 335 313 { 336 vfs_close( file_xp , file_id );337 314 req.ptr = segs_base; 338 315 kmem_free( &req ); … … 353 330 cycle = (uint32_t)hal_get_cycles(); 354 331 if( DEBUG_ELF_LOAD < cycle ) 355 printk("\n[DBG] %s : thread % dexit for <%s> / entry_point %x / cycle %d\n",356 __FUNCTION__, CURRENT_THREAD , pathname, header.e_entry, cycle );332 printk("\n[DBG] %s : thread %x in process %x exit for <%s> / entry_point %x / cycle %d\n", 333 __FUNCTION__, CURRENT_THREAD->trdid, process->pid, name, header.e_entry, cycle ); 357 334 #endif 358 335
Note: See TracChangeset
for help on using the changeset viewer.