Changeset 623 for trunk/kernel/syscalls


Ignore:
Timestamp:
Mar 6, 2019, 4:37:15 PM (5 years ago)
Author:
alain
Message:

Introduce three new types of vsegs (KCODE,KDATA,KDEV)
to map the kernel vsegs in the process VSL and GPT.
This now used by both the TSAR and the I86 architectures.

Location:
trunk/kernel/syscalls
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/syscalls/shared_include/shared_almos.h

    r611 r623  
    5353    DISPLAY_BUSYLOCKS         = 8,
    5454    DISPLAY_MAPPER            = 9,
     55    DISPLAY_BARRIER           = 10,
    5556}
    5657display_type_t;
  • trunk/kernel/syscalls/shared_include/shared_mman.h

    r594 r623  
    22 * shred_mman.h - Shared structures & mnemonics used by the <mman.h> user library.
    33 *
    4  * Author  Alain Greiner (2016,2017,2018)
     4 * Author  Alain Greiner (2016,2017,2018,2019)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
     
    2626
    2727/*******************************************************************************************
    28  * These structure are used by the mmap() syscall().
     28 * This structure is used by the mmap() syscall().
    2929 ******************************************************************************************/
    3030
  • trunk/kernel/syscalls/sys_creat.c

    r457 r623  
    22 * sys_creat.c - create a file
    33 *
    4  * Author    Alain Greiner (2016,2017)
     4 * Author    Alain Greiner (2016,2017,2017,2019)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
  • trunk/kernel/syscalls/sys_display.c

    r619 r623  
    3131#include <string.h>
    3232#include <shared_syscalls.h>
     33#include <remote_barrier.h>
    3334#include <vfs.h>
    3435#include <mapper.h>
     
    5354    else if( type == DISPLAY_BUSYLOCKS         ) return "BUSYLOCKS";
    5455    else if( type == DISPLAY_MAPPER            ) return "MAPPER";
     56    else if( type == DISPLAY_BARRIER           ) return "BARRIER";
    5557    else                                         return "undefined";
    5658}
     
    8183#endif
    8284
    83     ////////////////////////////
    84     if( type == DISPLAY_STRING )
     85    switch( type )
    8586    {
    86         char      kbuf[512];
    87         uint32_t  length;
    88 
    89         char    * string = (char *)arg0;
    90 
    91         // check string in user space
    92         error = vmm_get_vseg( process , (intptr_t)arg0 , &vseg );
    93 
    94         if( error )
    95         {
     87        ////////////////////
     88        case DISPLAY_STRING:
     89        {
     90            char      kbuf[512];
     91            uint32_t  length;
     92
     93            char    * string = (char *)arg0;
     94
     95            // check string in user space
     96            error = vmm_get_vseg( process , (intptr_t)arg0 , &vseg );
     97
     98            if( error )
     99            {
    96100
    97101#if DEBUG_SYSCALLS_ERROR
     
    99103__FUNCTION__ , (intptr_t)arg0 );
    100104#endif
     105                this->errno = EINVAL;
     106                return -1;
     107            }
     108
     109            // ckeck string length
     110            length = hal_strlen_from_uspace( string );
     111
     112            if( length >= 512 )
     113            {
     114
     115#if DEBUG_SYSCALLS_ERROR
     116printk("\n[ERROR] in %s for STRING : string length %d too large\n",
     117__FUNCTION__ , length );
     118#endif
     119                this->errno = EINVAL;
     120                return -1;
     121            }
     122
     123            // copy string to kernel space
     124            hal_strcpy_from_uspace( kbuf , string , 512 );
     125
     126            // print message on TXT0 kernel terminal
     127            printk("\n%s / cycle %d\n", kbuf, (uint32_t)hal_get_cycles() );
     128
     129            break;
     130        }
     131        /////////////////
     132        case DISPLAY_VMM:
     133        {
     134            cxy_t cxy = (cxy_t)arg0;
     135            pid_t pid = (pid_t)arg1;
     136
     137            // check cxy argument
     138                if( cluster_is_undefined( cxy ) )
     139            {
     140
     141#if DEBUG_SYSCALLS_ERROR
     142printk("\n[ERROR] in %s for VMM : process %x in cluster %x not found\n",
     143__FUNCTION__ , pid , cxy );
     144#endif
     145                this->errno = EINVAL;
     146                return -1;
     147            }
     148
     149            // get extended pointer on process PID in cluster CXY
     150            xptr_t process_xp = cluster_get_process_from_pid_in_cxy( cxy , pid );
     151
     152                if( process_xp == XPTR_NULL )
     153            {
     154
     155#if DEBUG_SYSCALLS_ERROR
     156printk("\n[ERROR] in %s for VMM : process %x in cluster %x not found\n",
     157__FUNCTION__ , pid , cxy );
     158#endif
     159                this->errno = EINVAL;
     160                return -1;
     161            }
     162
     163            // get local pointer on process
     164            process_t * process = (process_t *)GET_PTR( process_xp );
     165
     166            // call kernel function
     167            if( cxy == local_cxy )
     168            {
     169                    vmm_display( process , true );
     170            }
     171            else
     172            {
     173                rpc_vmm_display_client( cxy , process , true );
     174            }
     175
     176            break;
     177        }
     178        ///////////////////
     179        case DISPLAY_SCHED:
     180        {
     181            cxy_t cxy = (cxy_t)arg0;
     182            lid_t lid = (lid_t)arg1;
     183
     184            // check cxy argument
     185                if( cluster_is_undefined( cxy ) )
     186            {
     187
     188#if DEBUG_SYSCALLS_ERROR
     189printk("\n[ERROR] in %s for SCHED : illegal cxy argument %x\n",
     190__FUNCTION__ , cxy );
     191#endif
     192                this->errno = EINVAL;
     193                return -1;
     194            }
     195
     196            // check lid argument
     197            if( lid >= LOCAL_CLUSTER->cores_nr )
     198            {
     199
     200#if DEBUG_SYSCALLS_ERROR
     201printk("\n[ERROR] in %s for SCHED : illegal lid argument %x\n",
     202__FUNCTION__ , lid );
     203#endif
     204                this->errno = EINVAL;
     205                return -1;
     206            }
     207
     208            if( cxy == local_cxy )
     209            {
     210                    sched_display( lid );
     211            }
     212            else
     213            {
     214                sched_remote_display( cxy , lid );
     215            }
     216
     217            break;
     218        }
     219        ///////////////////////////////
     220        case DISPLAY_CLUSTER_PROCESSES:
     221        {
     222            cxy_t  cxy   = (cxy_t)arg0;
     223            bool_t owned = (bool_t)arg1;
     224
     225            // check cxy argument
     226                if( cluster_is_undefined( cxy ) )
     227            {
     228
     229#if DEBUG_SYSCALLS_ERROR
     230printk("\n[ERROR] in %s for CLUSTER_PROCESSES : illegal cxy argument %x\n",
     231__FUNCTION__ , cxy );
     232#endif
     233                this->errno = EINVAL;
     234                return -1;
     235            }
     236
     237            cluster_processes_display( cxy , owned );
     238
     239            break;
     240        }
     241        /////////////////
     242        case DISPLAY_VFS:
     243        {
     244            vfs_display( process->vfs_root_xp );
     245
     246            break;
     247        }
     248        ///////////////////
     249        case DISPLAY_CHDEV:
     250        {
     251            chdev_dir_display();
     252
     253            break;
     254        }
     255        ///////////////////////////
     256        case DISPLAY_TXT_PROCESSES:
     257        {
     258            uint32_t txt_id = (uint32_t)arg0;
     259
     260            // check argument
     261                if( txt_id >= LOCAL_CLUSTER->nb_txt_channels )
     262            {
     263
     264#if DEBUG_SYSCALLS_ERROR
     265printk("\n[ERROR] in %s for TXT_PROCESSES : illegal txt_id argument %d\n",
     266__FUNCTION__ , txt_id );
     267#endif
     268                this->errno = EINVAL;
     269                return -1;
     270            }
     271
     272            process_txt_display( txt_id );
     273
     274            break;
     275        }
     276        //////////////////
     277        case DISPLAY_DQDT:
     278        {
     279            dqdt_display();
     280
     281            break;
     282        }
     283        ///////////////////////
     284        case DISPLAY_BUSYLOCKS:
     285        {
     286            pid_t   pid   = (pid_t)arg0;
     287            trdid_t trdid = (trdid_t)arg1;
     288
     289            // get extended pointer on target thread
     290            xptr_t thread_xp = thread_get_xptr( pid , trdid );
     291
     292            if( thread_xp == XPTR_NULL )
     293            {
     294
     295#if DEBUG_SYSCALLS_ERROR
     296printk("\n[ERROR] in %s for BUSYLOCKS : thread[%x,%x] not found\n",
     297__FUNCTION__ , pid, trdid );
     298#endif
     299                this->errno = EINVAL;
     300                return -1;
     301            }
     302
     303            thread_display_busylocks( thread_xp , __FUNCTION__ );
     304
     305            break;
     306        }
     307        ////////////////////
     308        case DISPLAY_MAPPER:
     309        {
     310            xptr_t        root_inode_xp;
     311            xptr_t        inode_xp;
     312            cxy_t         inode_cxy;
     313            vfs_inode_t * inode_ptr;
     314            xptr_t        mapper_xp;
     315            mapper_t    * mapper_ptr;
     316
     317            char          kbuf[CONFIG_VFS_MAX_PATH_LENGTH];
     318
     319            char     * path    = (char *)arg0;
     320            uint32_t   page_id = (uint32_t)arg1;
     321            uint32_t   nbytes  = (uint32_t)arg2;
     322
     323            // check pathname length
     324            if( hal_strlen_from_uspace( path ) >= CONFIG_VFS_MAX_PATH_LENGTH )
     325            {
     326
     327#if DEBUG_SYSCALLS_ERROR
     328printk("\n[ERROR] in %s for MAPPER : pathname too long\n",
     329 __FUNCTION__ );
     330#endif
     331                this->errno = ENFILE;
     332                return -1;
     333            }
     334
     335            // copy pathname in kernel space
     336            hal_strcpy_from_uspace( kbuf , path , CONFIG_VFS_MAX_PATH_LENGTH );
     337
     338            // compute root inode for pathname
     339            if( kbuf[0] == '/' )                        // absolute path
     340            {
     341                // use extended pointer on VFS root inode
     342                root_inode_xp = process->vfs_root_xp;
     343            }
     344            else                                        // relative path
     345            {
     346                // get cluster and local pointer on reference process
     347                xptr_t      ref_xp  = process->ref_xp;
     348                process_t * ref_ptr = (process_t *)GET_PTR( ref_xp );
     349                cxy_t       ref_cxy = GET_CXY( ref_xp );
     350
     351                // get extended pointer on CWD inode
     352                root_inode_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->cwd_xp ) );
     353            }
     354
     355            // get extended pointer on target inode
     356            error = vfs_lookup( root_inode_xp,
     357                                kbuf,
     358                                0,
     359                                &inode_xp,
     360                                NULL );
     361            if( error )
     362                {
     363
     364#if DEBUG_SYSCALLS_ERROR
     365printk("\n[ERROR] in %s for MAPPER : cannot found inode <%s>\n",
     366__FUNCTION__ , kbuf );
     367#endif
     368                        this->errno = ENFILE;
     369                        return -1;
     370                }
     371   
     372            // get target inode cluster and local pointer
     373            inode_cxy = GET_CXY( inode_xp );
     374            inode_ptr = GET_PTR( inode_xp );
     375
     376            // get extended pointer on target mapper
     377            mapper_ptr = hal_remote_lpt( XPTR( inode_cxy , &inode_ptr->mapper ) );
     378            mapper_xp  = XPTR( inode_cxy , mapper_ptr );
     379
     380            // display mapper
     381            error = mapper_display_page( mapper_xp , page_id , nbytes );
     382
     383            if( error )
     384                {
     385
     386#if DEBUG_SYSCALLS_ERROR
     387printk("\n[ERROR] in %s for MAPPER : cannot display page %d\n",
     388__FUNCTION__ , page_id );
     389#endif
     390                        this->errno = ENFILE;
     391                        return -1;
     392                }
     393
     394            break;
     395        }
     396        /////////////////////
     397        case DISPLAY_BARRIER:
     398        {
     399            // get target process PID
     400            pid_t pid = (pid_t)arg0;
     401
     402            // get pointers on owner process
     403            xptr_t      process_xp  = cluster_get_reference_process_from_pid( pid );
     404            process_t * process_ptr = GET_PTR( process_xp );
     405            cxy_t       process_cxy = GET_CXY( process_xp );
     406
     407            if( process_xp == XPTR_NULL )
     408            {
     409
     410#if DEBUG_SYSCALLS_ERROR
     411printk("\n[ERROR] in %s for BARRIER : process %x not found\n",
     412__FUNCTION__ , pid );
     413#endif
     414                this->errno = EINVAL;
     415                return -1;
     416            }
     417
     418            // get extended pointer on root of list of barriers
     419            xptr_t root_xp = XPTR( process_cxy , &process_ptr->barrier_root );
     420
     421            if( xlist_is_empty( root_xp ) )
     422            {
     423
     424#if DEBUG_SYSCALLS_ERROR
     425printk("\n[ERROR] in %s for BARRIER : no registered barrier in process %x\n",
     426__FUNCTION__ , pid );
     427#endif
     428                this->errno = EINVAL;
     429                return -1;
     430            }
     431
     432            // get extended pointer on first registered generic barrier descriptor
     433            xptr_t gen_barrier_xp  = XLIST_FIRST( root_xp , generic_barrier_t , list );
     434
     435            // display barrier state
     436            generic_barrier_display( gen_barrier_xp );
     437
     438            break;
     439        }
     440        ////////
     441        default:
     442        {
     443
     444#if DEBUG_SYSCALLS_ERROR
     445printk("\n[ERROR] in %s : undefined display type %d\n",
     446        __FUNCTION__ , type );
     447#endif
    101448            this->errno = EINVAL;
    102449            return -1;
    103450        }
    104 
    105         // ckeck string length
    106         length = hal_strlen_from_uspace( string );
    107 
    108         if( length >= 512 )
    109         {
    110 
    111 #if DEBUG_SYSCALLS_ERROR
    112 printk("\n[ERROR] in %s for STRING : string length %d too large\n",
    113 __FUNCTION__ , length );
    114 #endif
    115             this->errno = EINVAL;
    116             return -1;
    117         }
    118 
    119         // copy string to kernel space
    120         hal_strcpy_from_uspace( kbuf , string , 512 );
    121 
    122         // print message on TXT0 kernel terminal
    123         printk("\n%s / cycle %d\n", kbuf, (uint32_t)hal_get_cycles() );
    124     }
    125     //////////////////////////////
    126     else if( type == DISPLAY_VMM )
    127     {
    128         cxy_t cxy = (cxy_t)arg0;
    129         pid_t pid = (pid_t)arg1;
    130 
    131         // check cxy argument
    132             if( cluster_is_undefined( cxy ) )
    133         {
    134 
    135 #if DEBUG_SYSCALLS_ERROR
    136 printk("\n[ERROR] in %s for VMM : process %x in cluster %x not found\n",
    137 __FUNCTION__ , pid , cxy );
    138 #endif
    139             this->errno = EINVAL;
    140             return -1;
    141         }
    142 
    143         // get extended pointer on process PID in cluster CXY
    144         xptr_t process_xp = cluster_get_process_from_pid_in_cxy( cxy , pid );
    145 
    146             if( process_xp == XPTR_NULL )
    147         {
    148 
    149 #if DEBUG_SYSCALLS_ERROR
    150 printk("\n[ERROR] in %s for VMM : process %x in cluster %x not found\n",
    151 __FUNCTION__ , pid , cxy );
    152 #endif
    153             this->errno = EINVAL;
    154             return -1;
    155         }
    156 
    157         // get local pointer on process
    158         process_t * process = (process_t *)GET_PTR( process_xp );
    159 
    160         // call kernel function
    161         if( cxy == local_cxy )
    162         {
    163                 vmm_display( process , true );
    164         }
    165         else
    166         {
    167             rpc_vmm_display_client( cxy , process , true );
    168         }
    169     }
    170     ////////////////////////////////
    171     else if( type == DISPLAY_SCHED )
    172     {
    173         cxy_t cxy = (cxy_t)arg0;
    174         lid_t lid = (lid_t)arg1;
    175 
    176         // check cxy argument
    177             if( cluster_is_undefined( cxy ) )
    178         {
    179 
    180 #if DEBUG_SYSCALLS_ERROR
    181 printk("\n[ERROR] in %s for SCHED : illegal cxy argument %x\n",
    182 __FUNCTION__ , cxy );
    183 #endif
    184             this->errno = EINVAL;
    185             return -1;
    186         }
    187 
    188         // check lid argument
    189         if( lid >= LOCAL_CLUSTER->cores_nr )
    190         {
    191 
    192 #if DEBUG_SYSCALLS_ERROR
    193 printk("\n[ERROR] in %s for SCHED : illegal lid argument %x\n",
    194 __FUNCTION__ , lid );
    195 #endif
    196             this->errno = EINVAL;
    197             return -1;
    198         }
    199 
    200         if( cxy == local_cxy )
    201         {
    202                 sched_display( lid );
    203         }
    204         else
    205         {
    206             sched_remote_display( cxy , lid );
    207         }
    208     }
    209     ////////////////////////////////////////////
    210     else if( type == DISPLAY_CLUSTER_PROCESSES )
    211     {
    212         cxy_t  cxy   = (cxy_t)arg0;
    213         bool_t owned = (bool_t)arg1;
    214 
    215         // check cxy argument
    216             if( cluster_is_undefined( cxy ) )
    217         {
    218 
    219 #if DEBUG_SYSCALLS_ERROR
    220 printk("\n[ERROR] in %s for CLUSTER_PROCESSES : illegal cxy argument %x\n",
    221 __FUNCTION__ , cxy );
    222 #endif
    223             this->errno = EINVAL;
    224             return -1;
    225         }
    226 
    227         cluster_processes_display( cxy , owned );
    228     }
    229     //////////////////////////////
    230     else if( type == DISPLAY_VFS )
    231     {
    232         vfs_display( process->vfs_root_xp );
    233     }
    234     ////////////////////////////////
    235     else if( type == DISPLAY_CHDEV )
    236     {
    237         chdev_dir_display();
    238     }
    239     ////////////////////////////////////////
    240     else if( type == DISPLAY_TXT_PROCESSES )
    241     {
    242         uint32_t txt_id = (uint32_t)arg0;
    243 
    244         // check argument
    245             if( txt_id >= LOCAL_CLUSTER->nb_txt_channels )
    246         {
    247 
    248 #if DEBUG_SYSCALLS_ERROR
    249 printk("\n[ERROR] in %s for TXT_PROCESSES : illegal txt_id argument %d\n",
    250 __FUNCTION__ , txt_id );
    251 #endif
    252             this->errno = EINVAL;
    253             return -1;
    254         }
    255 
    256         process_txt_display( txt_id );
    257     }
    258     ///////////////////////////////
    259     else if( type == DISPLAY_DQDT )
    260     {
    261         dqdt_display();
    262     }
    263     ////////////////////////////////////
    264     else if( type == DISPLAY_BUSYLOCKS )
    265     {
    266         pid_t   pid   = (pid_t)arg0;
    267         trdid_t trdid = (trdid_t)arg1;
    268 
    269         // get extended pointer on target thread
    270         xptr_t thread_xp = thread_get_xptr( pid , trdid );
    271 
    272         if( thread_xp == XPTR_NULL )
    273         {
    274 
    275 #if DEBUG_SYSCALLS_ERROR
    276 printk("\n[ERROR] in %s for BUSYLOCKS : thread[%x,%x] not found\n",
    277 __FUNCTION__ , pid, trdid );
    278 #endif
    279             this->errno = EINVAL;
    280             return -1;
    281         }
    282 
    283         thread_display_busylocks( thread_xp , __FUNCTION__ );
    284     }
    285     /////////////////////////////////
    286     else if( type == DISPLAY_MAPPER )
    287     {
    288         xptr_t        root_inode_xp;
    289         xptr_t        inode_xp;
    290         cxy_t         inode_cxy;
    291         vfs_inode_t * inode_ptr;
    292         xptr_t        mapper_xp;
    293         mapper_t    * mapper_ptr;
    294 
    295         char          kbuf[CONFIG_VFS_MAX_PATH_LENGTH];
    296 
    297         char     * path    = (char *)arg0;
    298         uint32_t   page_id = (uint32_t)arg1;
    299         uint32_t   nbytes  = (uint32_t)arg2;
    300 
    301         // check pathname length
    302         if( hal_strlen_from_uspace( path ) >= CONFIG_VFS_MAX_PATH_LENGTH )
    303         {
    304 
    305 #if DEBUG_SYSCALLS_ERROR
    306 printk("\n[ERROR] in %s for MAPPER : pathname too long\n",
    307  __FUNCTION__ );
    308 #endif
    309             this->errno = ENFILE;
    310             return -1;
    311         }
    312 
    313         // copy pathname in kernel space
    314         hal_strcpy_from_uspace( kbuf , path , CONFIG_VFS_MAX_PATH_LENGTH );
    315 
    316         // compute root inode for pathname
    317         if( kbuf[0] == '/' )                        // absolute path
    318         {
    319             // use extended pointer on VFS root inode
    320             root_inode_xp = process->vfs_root_xp;
    321         }
    322         else                                        // relative path
    323         {
    324             // get cluster and local pointer on reference process
    325             xptr_t      ref_xp  = process->ref_xp;
    326             process_t * ref_ptr = (process_t *)GET_PTR( ref_xp );
    327             cxy_t       ref_cxy = GET_CXY( ref_xp );
    328 
    329             // use extended pointer on CWD inode
    330             root_inode_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->cwd_xp ) );
    331         }
    332 
    333         // get extended pointer on target inode
    334         error = vfs_lookup( root_inode_xp,
    335                             kbuf,
    336                             0,
    337                             &inode_xp,
    338                             NULL );
    339         if( error )
    340             {
    341 
    342 #if DEBUG_SYSCALLS_ERROR
    343 printk("\n[ERROR] in %s for MAPPER : cannot found inode <%s>\n",
    344 __FUNCTION__ , kbuf );
    345 #endif
    346                     this->errno = ENFILE;
    347                     return -1;
    348             }
    349    
    350         // get target inode cluster and local pointer
    351         inode_cxy = GET_CXY( inode_xp );
    352         inode_ptr = GET_PTR( inode_xp );
    353 
    354         // get extended pointer on target mapper
    355         mapper_ptr = hal_remote_lpt( XPTR( inode_cxy , &inode_ptr->mapper ) );
    356         mapper_xp  = XPTR( inode_cxy , mapper_ptr );
    357 
    358         // display mapper
    359         error = mapper_display_page( mapper_xp , page_id , nbytes );
    360 
    361         if( error )
    362             {
    363 
    364 #if DEBUG_SYSCALLS_ERROR
    365 printk("\n[ERROR] in %s for MAPPER : cannot display page %d\n",
    366 __FUNCTION__ , page_id );
    367 #endif
    368                     this->errno = ENFILE;
    369                     return -1;
    370             }
    371     }
    372     ////
    373     else
    374     {
    375 
    376 #if DEBUG_SYSCALLS_ERROR
    377 printk("\n[ERROR] in %s : undefined display type %d\n",
    378         __FUNCTION__ , type );
    379 #endif
    380         this->errno = EINVAL;
    381         return -1;
    382     }
     451    }  // end switch on type
    383452
    384453#if (DEBUG_SYS_DISPLAY || CONFIG_INSTRUMENTATION_SYSCALLS)
  • trunk/kernel/syscalls/sys_mmap.c

    r611 r623  
    5656
    5757#if DEBUG_SYS_MMAP
    58 tm_start = hal_get_cycles();
    59 if ( DEBUG_SYS_MMAP < tm_start )
     58if( DEBUG_SYS_MMAP < tm_start )
    6059printk("\n[%s] thread[%x,%x] enter / cycle %d\n",
    6160__FUNCTION__, process->pid, this->trdid, (uint32_t)tm_start );
     
    314313#endif
    315314
     315#if CONFIG_INSTRUMENTATION_SYSCALLS
     316hal_atomic_add( &syscalls_cumul_cost[SYS_MMAP] , tm_end - tm_start );
     317hal_atomic_add( &syscalls_occurences[SYS_MMAP] , 1 );
     318#endif
     319
    316320#if DEBUG_SYS_MMAP
    317 if ( DEBUG_SYS_MMAP < tm_start )
     321if ( DEBUG_SYS_MMAP < tm_end )
    318322printk("\n[%s] thread[%x,%x] exit / %s / cxy %x / base %x / size %d / cycle %d\n",
    319323__FUNCTION__, process->pid, this->trdid,
  • trunk/kernel/syscalls/sys_munmap.c

    r506 r623  
    2525#include <hal_kernel_types.h>
    2626#include <hal_uspace.h>
     27#include <hal_irqmask.h>
    2728#include <shared_syscalls.h>
    2829#include <errno.h>
     
    4142{
    4243    error_t       error;
     44    vseg_t      * vseg;
     45    reg_t         save_sr;      // required to enable IRQs
    4346
    4447        thread_t    * this    = CURRENT_THREAD;
    4548        process_t   * process = this->process;
    4649
     50#if (DEBUG_SYS_MUNMAP || CONFIG_INSTRUMENTATION_SYSCALLS)
     51uint64_t     tm_start = hal_get_cycles();
     52#endif
     53
    4754#if DEBUG_SYS_MUNMAP
    48 uint64_t tm_start;
    49 uint64_t tm_end;
    50 tm_start = hal_get_cycles();
    5155if( DEBUG_SYS_MUNMAP < tm_start )
    52 printk("\n[DBG] %s : thread %x enter / process %x / cycle %d\n"
     56printk("\n[DBG] %s : thread %x enter / process %x / cycle %d\n",
    5357__FUNCTION__ , this, process->pid, (uint32_t)tm_start );
    5458#endif
     59
     60    // check user buffer is mapped
     61    error = vmm_get_vseg( process , (intptr_t)vaddr, &vseg );
     62
     63    if( error )
     64    {
     65
     66#if DEBUG_SYSCALLS_ERROR
     67printk("\n[ERROR] in %s : thread[%x,%x] / user buffer unmapped %x\n",
     68__FUNCTION__ , process->pid, this->trdid, (intptr_t)vaddr );
     69vmm_display( process , false );
     70#endif
     71                this->errno = EINVAL;
     72                return -1;
     73    }
     74
     75    // enable IRQs
     76    hal_enable_irq( &save_sr );
    5577
    5678    // call relevant kernel function
     
    6789    }
    6890
     91    // restore IRQs
     92    hal_restore_irq( save_sr );
     93
     94#if (DEBUG_SYS_MUNMAP || CONFIG_INSTRUMENTATION_SYSCALLS)
     95uint64_t     tm_end = hal_get_cycles();
     96#endif
     97
     98#if CONFIG_INSTRUMENTATION_SYSCALLS
     99hal_atomic_add( &syscalls_cumul_cost[SYS_MUNMAP] , tm_end - tm_start );
     100hal_atomic_add( &syscalls_occurences[SYS_MUNMAP] , 1 );
     101#endif
     102
    69103#if DEBUG_SYS_MUNMAP
    70 tm_end = hal_get_cycles();
    71104if( DEBUG_SYS_MUNMAP < tm_start )
    72 printk("\n[DBG] %s : thread %x exit / process %x / cycle %d\n"
     105printk("\n[DBG] %s : thread %x exit / process %x / cycle %d\n",
    73106__FUNCTION__ , this, process->pid, (uint32_t)tm_end );
    74107#endif
  • trunk/kernel/syscalls/sys_place_fork.c

    r584 r623  
    22 * sys_get_core.c - get calling core cluster and local index.
    33 *
    4  * Author    Alain Greiner (2016,2017)
     4 * Author    Alain Greiner (2016,2017,2018,2019)
    55 * 
    66 * Copyright (c) UPMC Sorbonne Universites
  • trunk/kernel/syscalls/sys_write.c

    r610 r623  
    173173        }
    174174
    175         // update size field in inode if required
    176         xptr_t   size_xp    = XPTR( file_cxy , &inode_ptr->size );
    177         uint32_t inode_size = hal_remote_l32( size_xp );
    178         if ( (file_offset + count) > inode_size )
    179         {
    180             hal_remote_s32( size_xp , file_offset + count );
    181         }
     175        // update file size in inode descriptor
     176        // only if (file_offset + count) > current_size
     177        // note: the parent directory entry in mapper will
     178        // be updated by the close syscall     
     179        xptr_t inode_xp = XPTR( file_cxy , inode_ptr );
     180        vfs_inode_update_size( inode_xp , file_offset + count );
     181
    182182    }
    183183    else if( file_type == INODE_TYPE_DEV )  // write to TXT device
  • trunk/kernel/syscalls/syscalls.h

    r619 r623  
    236236/******************************************************************************************
    237237 * [15] This function writes bytes to an open file identified by its file descriptor.
    238  * The file can be a regular file or character oriented device.
     238 * The file can be a regular file or character oriented device. For a regular file,
     239 * the target inode "size" field is updated if (offset + count) is larger than the
     240 * current "size" value. The size value registered in the mappers of the parent(s)
     241 * directory are not modified and will be asynchronously updated when the file is closed.
    239242 * IRQs are enabled during this system call.
    240243 ******************************************************************************************
     
    329332
    330333/******************************************************************************************
    331  * [23] This function open a directory, that must exist in the file system, returning
    332  * a DIR pointer on the dirent array in user space.
     334 * [23] This function creates an user level directory descriptor (including the associated
     335 * array of user level dirents), and intialise it from the kernel directory mapper, that
     336 * contains all entries in this directory). The directory is identified by the <pathname>
     337 * argument. If the corresponding inode is missing in the Inode Tree, the inode is created,
     338 * but the directory must exist in the file system.
     339 * It returns a DIR pointer <dirp> on the dirent array in user space.
    333340 ******************************************************************************************
    334341 * @ pathname   : [in]  pathname (can be relative or absolute).
Note: See TracChangeset for help on using the changeset viewer.