Changeset 23 for trunk/kernel/libk/elf.c
- Timestamp:
- Jun 18, 2017, 10:06:41 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/libk/elf.c
r14 r23 31 31 #include <vfs.h> 32 32 #include <elf.h> 33 #include <syscalls.h> 33 34 34 35 … … 85 86 86 87 // load .elf header 87 count = vfs_read( file_xp , buffer , size ); 88 count = vfs_move( true , 89 file_xp, 90 buffer, 91 size ); 88 92 89 93 if( count != size ) … … 163 167 164 168 // set seek on segment base in file 165 error = vfs_lseek( file_xp , offset , VFS_SEEK_SET , NULL ); 169 error = vfs_lseek( file_xp, 170 offset, 171 SEEK_SET, 172 NULL ); 166 173 167 174 if( error ) … … 210 217 process_t * process) 211 218 { 219 char path_copy[CONFIG_VFS_MAX_PATH_LENGTH]; 212 220 kmem_req_t req; // kmem request for program header 213 char path_copy[256]; // local copy of pathname214 221 uint32_t length; // actual path length 215 222 Elf32_Ehdr header; // local buffer for .elf header … … 217 224 uint32_t segs_size; // size of buffer for segment descriptors array 218 225 xptr_t file_xp; // extended pointer on created file descriptor 226 uint32_t file_id; // file descriptor index (unused) 219 227 uint32_t count; // bytes counter 220 228 error_t error; … … 223 231 length = hal_strlen_from_uspace( pathname ); 224 232 225 if( length > 255)233 if( length >= CONFIG_VFS_MAX_PATH_LENGTH ) 226 234 { 227 235 printk("\n[ERROR] in %s : pathname length too long\n", __FUNCTION__ ); … … 234 242 // open file 235 243 file_xp = XPTR_NULL; // avoid GCC warning 244 file_id = -1; 236 245 237 246 error = vfs_open( process->vfs_cwd_xp, 238 247 path_copy, 239 VFS_O_RDONLY, 240 &file_xp ); 248 O_RDONLY, 249 0, 250 &file_xp, 251 &file_id ); 241 252 if( error ) 242 253 { … … 252 263 if( error ) 253 264 { 254 vfs_close( file_xp , &count);265 vfs_close( file_xp , file_id ); 255 266 return -1; 256 267 } … … 261 272 { 262 273 printk("\n[ERROR] in %s : no segments found\n", __FUNCTION__ ); 263 vfs_close( file_xp , &count);274 vfs_close( file_xp , file_id ); 264 275 return -1; 265 276 } … … 277 288 { 278 289 printk("\n[ERROR] in %s : no memory for segment descriptors\n", __FUNCTION__ ); 279 vfs_close( file_xp , &count);290 vfs_close( file_xp , file_id ); 280 291 return -1; 281 292 } 282 293 283 294 // set seek pointer in file descriptor to access segment descriptors array 284 error = vfs_lseek( file_xp , header.e_phoff, VFS_SEEK_SET , NULL );295 error = vfs_lseek( file_xp , header.e_phoff, SEEK_SET , NULL ); 285 296 286 297 if( error ) 287 298 { 288 299 printk("\n[ERROR] in %s : cannot seek for descriptors array\n", __FUNCTION__ ); 289 vfs_close( file_xp , &count);300 vfs_close( file_xp , file_id ); 290 301 req.ptr = segs_base; 291 302 kmem_free( &req ); … … 294 305 295 306 // load seg descriptors array to local buffer 296 count = vfs_read( file_xp, 307 count = vfs_move( true, 308 file_xp, 297 309 segs_base, 298 310 segs_size ); … … 301 313 { 302 314 printk("\n[ERROR] in %s : cannot read segments descriptors\n", __FUNCTION__ ); 303 vfs_close( file_xp , &count);315 vfs_close( file_xp , file_id ); 304 316 req.ptr = segs_base; 305 317 kmem_free( &req ); … … 316 328 if( error ) 317 329 { 318 vfs_close( file_xp , &count);330 vfs_close( file_xp , file_id ); 319 331 req.ptr = segs_base; 320 332 kmem_free( &req );
Note: See TracChangeset
for help on using the changeset viewer.