Changeset 23 for trunk/kernel/libk/elf.c


Ignore:
Timestamp:
Jun 18, 2017, 10:06:41 PM (7 years ago)
Author:
alain
Message:

Introduce syscalls.

File:
1 edited

Legend:

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

    r14 r23  
    3131#include <vfs.h>
    3232#include <elf.h>
     33#include <syscalls.h>
    3334
    3435
     
    8586
    8687    // load .elf header
    87         count = vfs_read( file_xp , buffer , size );
     88        count = vfs_move( true ,
     89                      file_xp,
     90                      buffer,
     91                      size );
    8892
    8993        if( count != size )
     
    163167
    164168        // 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 );
    166173
    167174                if( error )
     
    210217                          process_t * process)
    211218{
     219    char         path_copy[CONFIG_VFS_MAX_PATH_LENGTH];
    212220        kmem_req_t   req;              // kmem request for program header
    213     char         path_copy[256];   // local copy of pathname
    214221        uint32_t     length;           // actual path length
    215222        Elf32_Ehdr   header;           // local buffer for .elf header
     
    217224    uint32_t     segs_size;        // size of buffer for segment descriptors array 
    218225        xptr_t       file_xp;          // extended pointer on created file descriptor
     226    uint32_t     file_id;          // file descriptor index (unused)
    219227    uint32_t     count;            // bytes counter
    220228        error_t      error;
     
    223231        length = hal_strlen_from_uspace( pathname );
    224232
    225     if( length > 255 )
     233    if( length >= CONFIG_VFS_MAX_PATH_LENGTH )
    226234    {
    227235        printk("\n[ERROR] in %s : pathname length too long\n", __FUNCTION__ );
     
    234242    // open file
    235243    file_xp = XPTR_NULL;  // avoid GCC warning
     244    file_id = -1;
    236245
    237246        error = vfs_open( process->vfs_cwd_xp,
    238247                      path_copy,
    239                       VFS_O_RDONLY,
    240                       &file_xp );
     248                      O_RDONLY,
     249                      0,
     250                      &file_xp,
     251                      &file_id );
    241252        if( error )
    242253        {
     
    252263        if( error )
    253264    {
    254         vfs_close( file_xp , &count );
     265        vfs_close( file_xp , file_id );
    255266        return -1;
    256267    }
     
    261272        {
    262273                printk("\n[ERROR] in %s : no segments found\n", __FUNCTION__ );
    263         vfs_close( file_xp , &count );
     274        vfs_close( file_xp , file_id );
    264275                return -1;
    265276        }
     
    277288    {
    278289                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 );
    280291        return -1;
    281292    }
    282293
    283294    // 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 );
    285296
    286297        if( error )
    287298        {
    288299                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 );
    290301            req.ptr = segs_base;
    291302            kmem_free( &req );
     
    294305
    295306    // load seg descriptors array to local buffer
    296         count = vfs_read( file_xp,
     307        count = vfs_move( true,
     308                      file_xp,
    297309                      segs_base,
    298310                      segs_size );
     
    301313        {
    302314                printk("\n[ERROR] in %s : cannot read segments descriptors\n", __FUNCTION__ );
    303         vfs_close( file_xp , &count );
     315        vfs_close( file_xp , file_id );
    304316            req.ptr = segs_base;
    305317            kmem_free( &req );
     
    316328        if( error )
    317329    {
    318         vfs_close( file_xp , &count );
     330        vfs_close( file_xp , file_id );
    319331            req.ptr = segs_base;
    320332            kmem_free( &req );
Note: See TracChangeset for help on using the changeset viewer.