Ignore:
Timestamp:
Aug 2, 2018, 11:47:13 AM (6 years ago)
Author:
alain
Message:

This version modifies the exec syscall and fixes a large number of small bugs.
The version number has been updated (0.1)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/libk/elf.c

    r441 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_special.h>
    2727#include <hal_uspace.h>
     
    210210} // end elf_segments_register()
    211211
    212 ///////////////////////////////////////////////
    213 error_t elf_load_process( char      * pathname,
    214                           process_t * process)
     212//////////////////////////////////////////////
     213error_t elf_load_process( xptr_t      file_xp,
     214                          process_t * process )
    215215{
    216216        kmem_req_t   req;              // kmem request for program header
     
    218218        void       * segs_base;        // pointer on buffer for segment descriptors array
    219219        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];
    222221        error_t      error;
    223222
     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   
    224229#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 );
     230uint32_t      cycle = (uint32_t)hal_get_cycles();
     231if( DEBUG_ELF_LOAD < cycle )
     232printk("\n[DBG] %s : thread %d in process %x enter for <%s> / cycle %d\n",
     233__FUNCTION__, CURRENT_THREAD->trdid, process->pid, name, cycle );
    251234#endif
    252235
     
    257240        if( error )
    258241        {
    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 );
    261243                return -1;
    262244        }
     
    264246#if (DEBUG_ELF_LOAD & 1)
    265247if( DEBUG_ELF_LOAD < cycle )
    266 printk("\n[DBG] %s : loaded elf header for <%s>\n", __FUNCTION__ , pathname );
     248printk("\n[DBG] %s : loaded elf header for <%s>\n", __FUNCTION__ , name );
    267249#endif
    268250
     
    270252        {
    271253                printk("\n[ERROR] in %s : no segments found\n", __FUNCTION__ );
    272                 vfs_close( file_xp , file_id );
    273254                return -1;
    274255        }
     
    286267        {
    287268                printk("\n[ERROR] in %s : no memory for segment descriptors\n", __FUNCTION__ );
    288                 vfs_close( file_xp , file_id );
    289269                return -1;
    290270        }
     
    296276        {
    297277                printk("\n[ERROR] in %s : cannot seek for descriptors array\n", __FUNCTION__ );
    298                 vfs_close( file_xp , file_id );
    299278                req.ptr = segs_base;
    300279                kmem_free( &req );
     
    304283#if (DEBUG_ELF_LOAD & 1)
    305284if( DEBUG_ELF_LOAD < cycle )
    306 printk("\n[DBG] %s : segments array allocated for <%s>\n", __FUNCTION__ , pathname );
     285printk("\n[DBG] %s : segments array allocated for <%s>\n", __FUNCTION__ , name );
    307286#endif
    308287
     
    316295        {
    317296                printk("\n[ERROR] in %s : cannot read segments descriptors\n", __FUNCTION__ );
    318                 vfs_close( file_xp , file_id );
    319297                req.ptr = segs_base;
    320298                kmem_free( &req );
     
    324302#if (DEBUG_ELF_LOAD & 1)
    325303if( DEBUG_ELF_LOAD < cycle )
    326 printk("\n[DBG] %s loaded segments descriptors for <%s>\n", __FUNCTION__ , pathname );
     304printk("\n[DBG] %s loaded segments descriptors for <%s>\n", __FUNCTION__ , name );
    327305#endif
    328306
     
    334312        if( error )
    335313        {
    336                 vfs_close( file_xp , file_id );
    337314                req.ptr = segs_base;
    338315                kmem_free( &req );
     
    353330cycle = (uint32_t)hal_get_cycles();
    354331if( DEBUG_ELF_LOAD < cycle )
    355 printk("\n[DBG] %s : thread %d exit for <%s> / entry_point %x / cycle %d\n",
    356 __FUNCTION__, CURRENT_THREAD, pathname, header.e_entry, cycle );
     332printk("\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 );
    357334#endif
    358335
Note: See TracChangeset for help on using the changeset viewer.