Changeset 204 for trunk/kernel/libk/elf.c
- Timestamp:
- Jul 17, 2017, 8:42:59 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/libk/elf.c
r157 r204 75 75 /////////////////////////////////////////////////////////////////////////////////////// 76 76 // This function loads the .elf header in the buffer allocated by the caller. 77 /////////////////////////////////////////////////////////////////////////////////////// 77 78 // @ file : extended pointer on the remote file descriptor. 78 79 // @ buffer : pointer on buffer allocated by the caller. 79 80 // @ size : number of bytes to read. 80 81 /////////////////////////////////////////////////////////////////////////////////////// 81 static error_t elf_header_ read( xptr_t file_xp,82 static error_t elf_header_load( xptr_t file_xp, 82 83 void * buffer, 83 84 uint32_t size ) … … 114 115 } 115 116 return 0; 116 } 117 118 } // end elf_header_load() 117 119 118 120 /////////////////////////////////////////////////////////////////////////////////////// 119 121 // This function registers in the process VMM the CODE and DATA segments. 122 /////////////////////////////////////////////////////////////////////////////////////// 120 123 // @ file : extended pointer on the remote file descriptor. 121 124 // @ segs_base : local pointer on buffer containing the segments descriptors array … … 212 215 213 216 return 0; 214 } 217 218 } // end elf_segments_load() 215 219 216 220 /////////////////////////////////////////////// … … 218 222 process_t * process) 219 223 { 220 char path_copy[CONFIG_VFS_MAX_PATH_LENGTH];221 224 kmem_req_t req; // kmem request for program header 222 uint32_t length; // actual path length223 225 Elf32_Ehdr header; // local buffer for .elf header 224 226 void * segs_base; // pointer on buffer for segment descriptors array … … 229 231 error_t error; 230 232 231 // get path length from user space 232 length = hal_strlen_from_uspace( pathname ); 233 234 if( length >= CONFIG_VFS_MAX_PATH_LENGTH ) 235 { 236 printk("\n[ERROR] in %s : pathname length too long\n", __FUNCTION__ ); 237 return -1; 238 } 239 240 // make a local copy for pathname 241 hal_copy_from_uspace( path_copy , pathname , length+1 ); 233 elf_dmsg("\n[INFO] %s : enter for %s\n", __FUNCTION__ , pathname ); 234 235 // avoid GCC warning 236 file_xp = XPTR_NULL; 237 file_id = -1; 242 238 243 239 // open file 244 file_xp = XPTR_NULL; // avoid GCC warning245 file_id = -1;246 247 240 error = vfs_open( process->vfs_cwd_xp, 248 path _copy,241 pathname, 249 242 O_RDONLY, 250 243 0, … … 253 246 if( error ) 254 247 { 255 printk("\n[ERROR] in %s : failed to open executable file %s\n", 256 __FUNCTION__ , path_copy ); 257 return -1; 258 } 248 printk("\n[ERROR] in %s : failed to open file %s\n", __FUNCTION__ , pathname ); 249 return -1; 250 } 251 252 elf_dmsg("\n[INFO] %s : file %s open\n", __FUNCTION__ , pathname ); 259 253 260 254 // load header in local buffer 261 error = elf_header_ read( file_xp ,255 error = elf_header_load( file_xp , 262 256 &header, 263 257 sizeof(Elf32_Ehdr) ); 264 258 if( error ) 265 259 { 266 vfs_close( file_xp , file_id ); 267 return -1; 268 } 269 270 elf_dmsg("\n[INFO] %s loaded elf header for %s\n", __FUNCTION__ , path_copy ); 260 printk("\n[ERROR] in %s : cannot get header file %s\n", __FUNCTION__ , pathname ); 261 vfs_close( file_xp , file_id ); 262 return -1; 263 } 264 265 elf_dmsg("\n[INFO] %s : loaded elf header for %s\n", __FUNCTION__ , pathname ); 271 266 272 267 if( header.e_phnum == 0 ) … … 320 315 } 321 316 322 elf_dmsg("\n[INFO] %s loaded segments descriptors for %s \n", __FUNCTION__ , path _copy);317 elf_dmsg("\n[INFO] %s loaded segments descriptors for %s \n", __FUNCTION__ , pathname ); 323 318 324 319 // register loadable segments in process VMM … … 346 341 347 342 elf_dmsg("\n[INFO] %s successfully completed / entry point = %x for %s]\n", 348 __FUNCTION__, (uint32_t) header.e_entry , path _copy);343 __FUNCTION__, (uint32_t) header.e_entry , pathname ); 349 344 350 345 return 0; 351 } 352 346 347 } // end elf_load_process() 348
Note: See TracChangeset
for help on using the changeset viewer.