Changeset 407 for trunk/kernel/syscalls


Ignore:
Timestamp:
Nov 7, 2017, 3:08:12 PM (5 years ago)
Author:
alain
Message:

First implementation of fork/exec.

Location:
trunk/kernel/syscalls
Files:
27 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/kernel/syscalls/sys_chdir.c

    r301 r407  
    4141    process_t * process = this->process;
    4242
    43     // get pathname copy in kernel space
    44     error = hal_strcpy_from_uspace( kbuf, pathname, CONFIG_VFS_MAX_PATH_LENGTH );
    45 
    46     if( error )
     43    // check pathname length
     44    if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH )
    4745    {
    48         printk("\n[ERROR] in %s : pathname too long for thread %x in process %x\n",
    49                __FUNCTION__ , this->trdid , process->pid );
     46        printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ );
    5047        this->errno = ENFILE;
    5148        return -1;
    5249    }
     50
     51    // copy pathname in kernel space
     52    hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH );
    5353
    5454    // get cluster and local pointer on reference process
  • trunk/kernel/syscalls/sys_chmod.c

    r302 r407  
    4040    process_t * process = this->process;
    4141
    42     // get pathname copy in kernel space
    43     error = hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH );
    44 
    45     if( error )
     42    // check pathname length
     43    if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH )
    4644    {
    4745        printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ );
     
    4947        return -1;
    5048    }
     49
     50    // copy pathname in kernel space
     51    hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH );
    5152
    5253    // get cluster and local pointer on reference process
  • trunk/kernel/syscalls/sys_closedir.c

    r23 r407  
    2424#include <hal_types.h>
    2525#include <vfs.h>
     26#include <printk.h>
    2627#include <thread.h>
    27 #include <printk.h>
    2828#include <process.h>
     29#include <errno.h>
     30#include <syscalls.h>
     31#include <shared_syscalls.h>
    2932
    30 /////////////////////////////////////
    31 int sys_closedir ( uint32_t file_id )
     33///////////////////////////////
     34int sys_closedir ( DIR * dirp )
    3235{
    33         error_t        error;
    34         xptr_t         file_xp;   // extended pointer on searched directory file descriptor
    35 
    36         thread_t     * this     = CURRENT_THREAD;
    37         process_t    * process  = this->process;
    38 
    39     // check file_id argument
    40         if( file_id >= CONFIG_PROCESS_FILE_MAX_NR )
    41         {
    42         printk("\n[ERROR] in %s : illegal file descriptor index %d\n",
    43                __FUNCTION__ , file_id );
    44         this->errno = EBADFD;
    45                 return -1;
    46         }
    47 
    48     // get extended pointer on remote file descriptor
    49     file_xp = process_fd_get_xptr( process , file_id );
    50 
    51     if( file_xp == XPTR_NULL )
    52     {
    53         printk("\n[ERROR] in %s : undefined file descriptor index = %d\n",
    54                __FUNCTION__ , file_id );
    55                 this->errno = EBADFD;
    56                 return -1;
    57     }
    58 
    59     // call relevant VFS function
    60         error  = vfs_close( file_xp , file_id );
    61 
    62         if( error )
    63         {
    64         printk("\n[ERROR] in %s : cannot close the directory = %d\n",
    65                __FUNCTION__ , file_id );
    66                 this->errno = error;
    67                 return -1;
    68         }
    69 
    70         return 0;
    71 
     36    printk("\n[ERROR] in %s : not implemented yet\n", __FUNCTION__ );
     37    CURRENT_THREAD->errno = ENOMEM;
     38    return -1;
    7239}  // end sys_closedir()
  • trunk/kernel/syscalls/sys_creat.c

    r23 r407  
    2525#include <vfs.h>
    2626#include <syscalls.h>
     27#include <shared_syscalls.h>
    2728
    2829////////////////////////////////////
  • trunk/kernel/syscalls/sys_exec.c

    r406 r407  
    3838
    3939////////////////////////////////////////////////i//////////////////////////////////////
    40 // This static function is called by the sys_exec() function to register the .elf
    41 // pathname in the exec_info  structure, from a string stored in user space.
    42 ////////////////////////////////////////////////i//////////////////////////////////////
    43 // @ exec_info : pointer on the exec_info structure.
    44 // @ pathname  : string containing the path to the .elf file (user space).
    45 // return 0 if success / non-zero if one string too long, or too many strings.
    46 ///////////////////////////////////////////////////////////////////////////////////////
    47 static error_t process_exec_get_path( exec_info_t  * exec_info,
    48                                       char         * pathname )
    49 {
    50     error_t error;
    51 
    52     // copy string to exec_info
    53     error = hal_strcpy_from_uspace( &exec_info->path[0] , pathname ,
    54                                     CONFIG_VFS_MAX_PATH_LENGTH );
    55     if( error )
    56         return EINVAL;
    57 
    58     return 0;
    59 }
    60 
    61 ////////////////////////////////////////////////i//////////////////////////////////////
    6240// This static function is called twice by the sys_exec() function :
    6341// - to register the main() arguments (args) in the exec_info structure.
     
    7149// to store the (args) and (envs) strings are configuration parameters.
    7250///////////////////////////////////////////////////////////////////////////////////////
    73 // @ exec_info : pointer on the exec_info structure.
    74 // @ is_args   : true if called for (args) / false if called for (envs).
    75 // @ pointers  : array of pointers on the strings (in user space).
     51// @ exec_info   : pointer on the exec_info structure.
     52// @ is_args     : true if called for (args) / false if called for (envs).
     53// @ u_pointers  : array of pointers on the strings (in user space).
    7654// @ return 0 if success / non-zero if too many strings or no more memory.
    7755///////////////////////////////////////////////////////////////////////////////////////
     
    173151// This function build an exec_info_t structure containing all informations
    174152// required to create the new process descriptor and the associated thread.
    175 // It calls the static process_exec_get_path() and process_exec_get_strings() functions
    176 // to copy the .elf pathname, the main() arguments and the environment variables from
    177 // user buffers to the exec_info_t structure, and call the process_make_exec() function.
     153// It calls the process_exec_get_strings() functions to copy the main() arguments and
     154// the environment variables from user buffers to the exec_info_t structure, allocate
     155// and call the process_make_exec() function.
     156// Finally, it destroys the calling thread and process.
     157// TODO : the args & envs arguments are not supported yet : both must be NULL
    178158/////////////////////////////////////////////////////////////////////////////////////////
    179 int sys_exec( char  * filename,     // .elf file pathname
     159int sys_exec( char  * pathname,     // .elf file pathname
    180160              char ** args,         // process arguments
    181161              char ** envs )        // environment variables
    182162{
    183     exec_info_t  exec_info;         // structure to pass to process_make_exec()
    184     error_t      error;
    185     paddr_t      paddr;
    186 
     163    exec_info_t   exec_info;        // structure to pass to process_make_exec()
     164    error_t       error;
     165
     166        uint64_t      tm_start;
     167        uint64_t      tm_end;
     168
     169        tm_start = hal_get_cycles();
     170
     171    // get pointers on parent process and thread
    187172    thread_t   * this    = CURRENT_THREAD;
    188173    process_t  * process = this->process;
    189 
    190     // check argument fileme
    191     error = vmm_v2p_translate( false , filename , &paddr );
     174    pid_t        pid     = process->pid;
     175
     176exec_dmsg("\n[DBG] %s : core[%x,%d] enters for process %x / cycle %d\n",
     177__FUNCTION__, local_cxy, this->core->lid, pid, (uint32_t)hal_get_cycles() );
     178
     179sched_display( 0 );
     180
     181    // check pathname length
     182    if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH )
     183    {
     184        printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ );
     185        this->errno = ENFILE;
     186        return -1;
     187    }
     188
     189    // copy pathname in exec_info structure (kernel space)
     190    hal_strcpy_from_uspace( exec_info.path , pathname , CONFIG_VFS_MAX_PATH_LENGTH );
     191    // check args argument
     192    assert( (args == NULL) , __FUNCTION__ ,
     193    "args not supported yet\n" );
     194
     195    // check envs argument
     196    assert( (envs == NULL) , __FUNCTION__ ,
     197    "args not supported yet\n" );
     198
     199    // compute client_cxy (local cluster) and server_cxy (target cluster)
     200    cxy_t     cxy_server = CXY_FROM_PID( pid );
     201    cxy_t     cxy_client = local_cxy;
     202
     203    // register parent process in exec_info
     204    exec_info.parent_xp   = process->ref_xp;
     205
     206    // new process keep the parent process PID
     207    exec_info.keep_pid   = true;
     208
     209    // check and store args in exec_info structure if required
     210    if( args != NULL )
     211    {
     212        if( process_exec_get_strings( &exec_info , true , args ) )
     213        {
     214            printk("\n[ERROR] in %s : cannot access args\n", __FUNCTION__ );
     215            this->errno = error;
     216            return -1;
     217        }
     218    }
     219
     220    // check and store envs in exec_info structure if required
     221    if( envs != NULL )
     222    {
     223        if( process_exec_get_strings( &exec_info , false , envs ) )
     224        {
     225            printk("\n[ERROR] in %s : cannot access envs\n", __FUNCTION__ );
     226            this->errno = error;
     227            return -1;
     228        }
     229    }
     230
     231    // call process_make_exec (local or remote)
     232    if( cxy_server == cxy_client )
     233    {
     234        error = process_make_exec( &exec_info );
     235    }
     236    else
     237    {
     238        rpc_process_exec_client( cxy_server , &exec_info , &error );
     239    }
    192240
    193241    if( error )
    194242    {
    195         printk("\n[ERROR] in %s : filename unmapped\n", __FUNCTION__ );
    196         this->errno = EINVAL;
    197         return -1;
    198     }
    199 
    200     // check argument fileme
    201     error = vmm_v2p_translate( false , args , &paddr );
    202 
    203     if( error )
    204     {
    205         printk("\n[ERROR] in %s : args unmapped\n", __FUNCTION__ );
    206         this->errno = EINVAL;
    207         return -1;
    208     }
    209 
    210     // check argument fileme
    211     error = vmm_v2p_translate( false , envs , &paddr );
    212 
    213     if( error )
    214     {
    215         printk("\n[ERROR] in %s : envs unmapped\n", __FUNCTION__ );
    216         this->errno = EINVAL;
    217         return -1;
    218     }
    219 
    220     // compute client_cxy (local cluster) and server_cxy (target cluster)
    221     cxy_t     cxy_server = CXY_FROM_PID( process->pid );
    222     cxy_t     cxy_client = local_cxy;
    223     bool_t    is_local   = (cxy_server == cxy_client);
    224 
    225     exec_dmsg("\n[DMSG] %s starts for process %x on core %d in cluster %x"
    226                  " / target_cluster = %x / cycle %d\n",
    227                  __FUNCTION__, process->pid , CURRENT_CORE->lid,
    228                  cxy_client, cxy_server, hal_get_cycles());
    229 
    230     // register reference parent process in exec_info
    231     exec_info.parent_xp   = process->ref_xp;
    232 
    233     // check pathname and store it in exec_info structure
    234     error = process_exec_get_path( &exec_info , filename );
    235 
    236     if ( error )
    237     {
    238         printk("\n[ERROR] in %s : elf pathname too long\n", __FUNCTION__ );
     243        printk("\n[ERROR] in %s : cannot create new process %x in cluster %x\n",
     244        __FUNCTION__, pid, cxy_server );
    239245        this->errno = error;
    240246        return -1;
    241247    }
    242248
    243     // check and store args in exec_info structure
    244     error = process_exec_get_strings( &exec_info , true , args );
    245 
    246     if( error )
    247     {
    248         printk("\n[ERROR] in %s : cannot access args\n", __FUNCTION__ );
    249         this->errno = error;
    250         return -1;
    251     }
    252 
    253     // check and store envs in exec_info structure
    254     error = process_exec_get_strings( &exec_info , false , envs );
    255 
    256     if( error )
    257     {
    258         printk("\n[ERROR] in %s : cannot access envs\n", __FUNCTION__ );
    259         this->errno = error;
    260         return -1;
    261     }
    262 
    263     exec_dmsg("\n[DMSG] %s starts exec for process %x at cycle %d\n",
    264               __FUNCTION__, process->pid, hal_get_cycles() );
    265 
    266     if( is_local )  error = process_make_exec( &exec_info );
    267     else            rpc_process_exec_client( cxy_server , &exec_info , &error );
    268 
    269     if( error )
    270     {
    271         printk("\n[ERROR] in %s : cannot create new process %x\n",
    272                __FUNCTION__ , process->pid );
    273         this->errno = error;
    274         return -1;
    275     }
    276 
    277     exec_dmsg("\n[DMSG] %s completes exec for process %x at cycle %d\n",
    278               __FUNCTION__, process->pid , hal_get_cycles() );
    279 
    280     // delete the calling thread an process
    281     thread_kill( CURRENT_THREAD );
    282     process_kill( CURRENT_THREAD->process );
     249    // FIXME delete the local process descriptor
     250    // process_kill( process );
     251
     252    tm_end = hal_get_cycles();
     253
     254exec_dmsg("\n[DBG] %s : core[%x,%d] exit for process %x / cycle %d\n"
     255"     pathname = %s / cost = %d\n",
     256__FUNCTION__, local_cxy, this->core->lid, pid, (uint32_t)tm_start,
     257exec_info.path , (uint32_t)(tm_end - tm_start) );
    283258
    284259    return 0;
  • trunk/kernel/syscalls/sys_fork.c

    r406 r407  
    2424#include <kernel_config.h>
    2525#include <hal_types.h>
     26#include <hal_context.h>
     27#include <hal_switch.h>
    2628#include <hal_atomic.h>
    2729#include <errno.h>
     
    4547    pid_t                child_pid;       // child process identifier
    4648        thread_t           * child_thread;    // pointer on child main thread descriptor
    47     trdid_t              child_trdid;     // child main thread identifier
    48     lid_t                child_core_lid;  // core local index for the child main thread
    49     cxy_t                target_cxy;      // final target cluster for forked child process
     49    cxy_t                target_cxy;      // target cluster for forked child process
    5050        error_t              error;
     51
     52        uint64_t      tm_start;
     53        uint64_t      tm_end;
     54
     55        tm_start = hal_get_cycles();
    5156
    5257    // get pointers on parent process and thread
     
    5560    parent_pid     = parent_process->pid;
    5661
     62fork_dmsg("\n[DBG] %s : core[%x,%d] enters for process %x / cycle %d\n",
     63__FUNCTION__ , local_cxy , parent_thread->core->lid , parent_pid , (uint32_t)tm_start );
     64
    5765    // check parent process children number
    5866        if( hal_atomic_add( &parent_process->children_nr , 1 ) >= CONFIG_PROCESS_MAX_CHILDREN )
     
    6169            hal_atomic_add ( &parent_process->children_nr , -1 );
    6270        return EAGAIN;
    63         }
    64 
    65         fork_dmsg("\n[DMSG] %s : enters for process %d at cycle [%d]\n",
    66                   __FUNCTION__, parent_process->pid, hal_get_cycles());
    67 
    68     // save FPU state in fpu_context if parent process is FPU owner
    69     // because we want the child process to share the FPU context
    70         if( CURRENT_CORE->fpu_owner == parent_thread )
    71         {
    72                 hal_fpu_context_save( parent_thread );
    73                 fork_dmsg("\n[DMSG] %s : save FPU\n", __FUNCTION__);
    7471        }
    7572
     
    9592        }
    9693
    97         fork_dmsg("INFO : %s select target_cluster = %x\n",
    98               __FUNCTION__ , target_cxy );
     94//printk("\n[DBG] %s : core[%x,%d] for process %x selects target_cluster = %x\n",
     95//__FUNCTION__ , local_cxy , parent_thread->core->lid , parent_pid , target_cxy );
    9996
    10097    // allocates memory in local cluster for the child process descriptor
     
    127124
    128125    // initialize and register the child process descriptor
    129     process_reference_init( child_process , child_pid , parent_pid );
    130 
    131         fork_dmsg("\n[DMSG] : %s created child process : pid = %x / ppid = %x\n",
    132               __FUNCTION__, child_pid , parent_pid );
     126    process_reference_init( child_process , child_pid , XPTR(local_cxy, parent_process) );
    133127
    134128    // initialises child process standard files structures
     
    148142                            XPTR( local_cxy , &parent_process->fd_array ) );
    149143
    150         fork_dmsg("\n[DMSG] %s : duplicated child process from parent process\n",
    151                   __FUNCTION__ );
    152 
    153     // replicates virtual memory manager
     144//printk("\n[DBG] %s : core[%x,%d] for process %x created child process %x\n",
     145//__FUNCTION__ , local_cxy , parent_thread->core->lid , parent_pid , child_pid );
     146
     147    // replicate VMM
    154148        error = vmm_copy( child_process , parent_process );
    155149
     
    162156    }
    163157 
    164         fork_dmsg("\n[DMSG] %s : parent vmm duplicated in child process\n", __FUNCTION__ );
    165 
    166     // create child main thread descriptor in local cluster
    167     error = thread_user_fork( parent_process , &child_thread );
    168 
     158//printk("\n[DBG] %s : core[%x,%d] for process %x duplicated vmm in child process\n",
     159//__FUNCTION__ , local_cxy , parent_thread->core->lid , parent_pid );
     160//vmm_display( parent_process , true );
     161//vmm_display( child_process , true );
     162
     163    // create child main thread in local cluster
     164    error = thread_user_fork( child_process,
     165                              parent_thread->u_stack_size,
     166                              parent_thread->u_stack_base,
     167                              &child_thread );
    169168        if( error )
    170169    {
    171             printk("\n[ERROR] in %s : cannot duplicate thread\n", __FUNCTION__ );
     170            printk("\n[ERROR] in %s : cannot duplicate main thread\n", __FUNCTION__ );
    172171            hal_atomic_add( &parent_process->children_nr , -1 );
    173172        process_destroy( child_process );
     
    175174    }
    176175
    177     // register child thread in child process, and get a TRDID
    178     spinlock_lock( &child_process->th_lock );
    179     error = process_register_thread( child_process, child_thread , &child_trdid );
    180     spinlock_unlock( &child_process->th_lock );
    181 
    182     if( error )
    183     {
    184         printk("\n[ERROR] in %s : cannot register thread\n", __FUNCTION__ );
    185             hal_atomic_add ( &parent_process->children_nr , -1 );
    186         thread_destroy( child_thread );
    187         process_destroy( child_process );
    188         return EAGAIN;
    189     }
    190  
    191     // get a local core to execute child thread
    192     child_core_lid = cluster_select_local_core();
    193 
    194         // Update child thread descriptor
    195         child_thread->core    = &LOCAL_CLUSTER->core_tbl[child_core_lid];
    196         child_thread->process = child_process;
    197     child_thread->trdid   = child_trdid;
    198 
    199         fork_dmsg("\n[DMSG] %s : initialised child main thread\n", __FUNCTION__ );
    200 
    201     // register local child thread into local child process th_tbl[]
    202     // we don't use the th_lock because there is no concurrent access
    203     ltid_t ltid = LTID_FROM_TRDID( child_trdid );
    204         child_process->th_tbl[ltid] = child_thread;
    205         child_process->th_nr = 1;
    206 
    207     // register child thread in scheduler
    208         sched_register_thread( child_thread->core , child_thread );
    209  
    210         fork_dmsg("\n[DMSG] %s : registered main thread in scheduler\n", __FUNCTION__);
     176//printk("\n[DBG] %s : core[%x,%d] initialised child main thread\n",
     177//__FUNCTION__ , local_cxy , parent_thread->core->lid );
    211178
    212179        // update DQDT for the child thread
    213180    dqdt_local_update_threads( 1 );
    214181
    215         fork_dmsg("\n[DMSG] %s : completed / parent pid = %x / child pid = %x / at cycle [%d]\n",
    216                   __FUNCTION__, parent_process->pid, child_process->pid, hal_get_cycles() );
    217 
    218         return child_process->pid;
     182    // set child_thread FPU_context from parent_thread register values
     183    // only when the parent process is the FPU owner
     184        if( CURRENT_THREAD->core->fpu_owner == parent_thread )
     185        {
     186                hal_fpu_context_save( child_thread->fpu_context );
     187        }
     188
     189    // set child_thread CPU context from parent_thread register values
     190    hal_do_cpu_save( child_thread->cpu_context,
     191                     child_thread,
     192                     (int)((intptr_t)child_thread - (intptr_t)parent_thread) );
     193
     194
     195    // from this point, both parent and child threads execute the following code
     196    // but child execute it only when it has been unblocked by its parent
     197
     198    thread_t * current = CURRENT_THREAD;
     199
     200    if( current == parent_thread )
     201    {
     202        // parent_thread unblock child_thread
     203        thread_unblock( XPTR( local_cxy , child_thread ) , THREAD_BLOCKED_GLOBAL );
     204
     205        tm_end = hal_get_cycles();
     206
     207fork_dmsg("\n[DBG] %s : core[%x,%d] parent_process %x exit / cycle %d\n"
     208"     child_process %x / child_thread = %x / cost = %d\n",
     209__FUNCTION__, local_cxy, parent_thread->core->lid,  parent_pid, (uint32_t)tm_start,
     210child_pid, child_thread->trdid , (uint32_t)(tm_end - tm_start) );
     211
     212        return child_pid;
     213    }
     214        else  // current == child_thread
     215    {
     216        assert( (current == child_thread) , __FUNCTION__ ,
     217        "current thread %x is not the child thread %x\n", current , child_thread );
     218
     219fork_dmsg("\n[DBG] %s : core[%x,%d] child process %x exit / cycle %d\n",
     220__FUNCTION__, local_cxy, parent_thread->core->lid, child_pid, (uint32_t)hal_get_cycles() );
     221
     222        return 0;
     223    }
    219224
    220225}  // end sys_fork()
  • trunk/kernel/syscalls/sys_get_cycle.c

    r405 r407  
    11/*
    2  * sys_clock: get calling core cycles count
     2 * sys_get_cycle.c - get calling core cycles count.
    33 *
    44 * Author    Alain Greiner (2016,2017)
     
    3232#include <printk.h>
    3333
    34 //////////////////////////////////
    35 int sys_clock (uint64_t * cycles )
     34//////////////////////////////////////
     35int sys_get_cycle ( uint64_t * cycle )
    3636{
    3737        error_t   error;
    3838    paddr_t   paddr;
    39         uint64_t  k_cycles;
     39        uint64_t  k_cycle;
    4040
    4141    thread_t  * this    = CURRENT_THREAD;
     
    4343
    4444    // check buffer in user space
    45     error = vmm_v2p_translate( false , cycles , &paddr );
     45    error = vmm_v2p_translate( false , cycle , &paddr );
    4646
    4747        if( error )
     
    5454
    5555    // call relevant core function
    56         k_cycles = hal_get_cycles();
     56        k_cycle = hal_get_cycles();
    5757
    5858    // copy to user space
    59         hal_copy_to_uspace( cycles , &k_cycles , sizeof(uint64_t) );
     59        hal_copy_to_uspace( cycle , &k_cycle , sizeof(uint64_t) );
    6060
    6161        return 0;
    6262
    63 }  // end sys_clock()
     63}  // end sys_get_cycle()
  • trunk/kernel/syscalls/sys_mkdir.c

    r303 r407  
    11/*
    2  * sys_mkdir.c - Create a new directory
     2 * sys_mkdir.c - Create a new directory in file system.
    33 *
    44 * Author    Alain Greiner (2016,2017)
     
    5050    }
    5151
    52     // get pathname copy in kernel space
    53     error = hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH );
    54 
    55     if( error )
     52    // check pathname length
     53    if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH )
    5654    {
    5755        printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ );
     
    5957        return -1;
    6058    }
     59
     60    // copy pathname in kernel space
     61    hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH );
    6162
    6263    // get cluster and local pointer on reference process
  • trunk/kernel/syscalls/sys_mkfifo.c

    r304 r407  
    4848    }
    4949
    50     // get pathname copy in kernel space
    51     error = hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH );
    52 
    53     if( error )
     50    // check pathname length
     51    if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH )
    5452    {
    5553        printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ );
     
    5755        return -1;
    5856    }
     57
     58    // copy pathname in kernel space
     59    hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH );
    5960
    6061    // get cluster and local pointer on reference process
  • trunk/kernel/syscalls/sys_mmap.c

    r23 r407  
    2424
    2525#include <hal_types.h>
     26#include <hal_uspace.h>
     27#include <shared_syscalls.h>
    2628#include <errno.h>
    2729#include <thread.h>
    2830#include <printk.h>
     31#include <mapper.h>
    2932#include <vfs.h>
    3033#include <process.h>
    3134#include <vmm.h>
    3235
    33 ///////////////////////////////////
     36//////////////////////////////////
    3437int sys_mmap( mmap_attr_t * attr )
    3538{
    36     printk("\n[WARNING] function %s not implemented\n", __FUNCTION__ );
    37     return 0;
    38 /*   
    39         error_t err;
    40         uint_t count;
    41         struct thread_s *this;
    42         struct process_s *process;
    43         struct vfs_file_s *file;
    44         mmap_attr_t attr;
    45         size_t isize;
    46         int retval;
     39    vseg_t      * vseg;
     40    cxy_t         vseg_cxy;
     41    vseg_type_t   vseg_type;
     42    mmap_attr_t   k_attr;       // attributes copy in kernel space
     43    xptr_t        mapper_xp;
     44    error_t       error;
     45    paddr_t       paddr;        // unused, but required for user space checking
     46
     47        uint64_t      tm_start;
     48        uint64_t      tm_end;
     49
     50        tm_start = hal_get_cycles();
     51
     52        thread_t    * this    = CURRENT_THREAD;
     53        process_t   * process = this->process;
     54
     55    // check arguments in user space
     56    error = vmm_v2p_translate( false , attr , &paddr );
     57
     58    if ( error )
     59    {
     60        printk("\n[ERROR] in %s : arguments not in used space = %x\n",
     61        __FUNCTION__ , (intptr_t)attr );
     62                this->errno = EINVAL;
     63                return -1;
     64    }
     65
     66    // copy arguments from uspace
     67    hal_copy_from_uspace( &k_attr , attr , sizeof(mmap_attr_t) );
     68
     69    // get fdid, offset, and length arguments
     70    uint32_t fdid   = k_attr.fdid;
     71    uint32_t offset = k_attr.offset;
     72    uint32_t length = k_attr.length;
     73
     74    // get flags
     75    bool_t     map_fixed   = ( (k_attr.flags & MAP_FIXED)   != 0 );
     76    bool_t     map_anon    = ( (k_attr.flags & MAP_ANON)    != 0 );
     77    bool_t     map_remote  = ( (k_attr.flags & MAP_REMOTE)  != 0 );
     78    bool_t     map_shared  = ( (k_attr.flags & MAP_SHARED)  != 0 );
     79    bool_t     map_private = ( (k_attr.flags & MAP_PRIVATE) != 0 );
     80
     81    // MAP_FIXED not supported
     82    if( map_fixed )
     83    {
     84        printk("\n[ERROR] in %s : MAP_FIXED not supported\n", __FUNCTION__ );
     85        this->errno = EINVAL;
     86        return -1;
     87    }
     88
     89    if( map_shared == map_private )
     90    {
     91        printk("\n[ERROR] in %s : MAP_SHARED xor MAP_PRIVATE\n", __FUNCTION__ );
     92        this->errno = EINVAL;
     93        return -1;
     94    }
     95
     96    // FIXME handle Copy_On_Write for MAP_PRIVATE...
     97
     98    // get access rigths
     99    bool_t     prot_read   = ( (k_attr.prot & PROT_READ )   != 0 );
     100    bool_t     prot_write  = ( (k_attr.prot & PROT_WRITE)   != 0 );
     101
     102    // test mmap type : can be FILE / ANON / REMOTE
     103
     104    if( (map_anon == false) && (map_remote == false) )   // FILE
     105    {
     106            // FIXME: handle concurent delete of file by another thread closing it
     107
     108                if( fdid >= CONFIG_PROCESS_FILE_MAX_NR )
     109                {
     110                        printk("\n[ERROR] in %s: bad file descriptor = %d\n", __FUNCTION__ , fdid );
     111            this->errno = EBADFD;
     112            return -1;
     113        }
     114
     115        // get extended pointer on file descriptor
     116        xptr_t file_xp = process_fd_get_xptr( process , fdid );
     117
     118        if( file_xp == XPTR_NULL )
     119        {
     120                        printk("\n[ERROR] in %s: file %d not found\n", __FUNCTION__ , fdid );
     121            this->errno = EBADFD;
     122            return -1;
     123        }
     124
     125        // get file cluster and local pointer
     126        cxy_t        file_cxy = GET_CXY( file_xp );
     127        vfs_file_t * file_ptr = (vfs_file_t *)GET_PTR( file_xp );
     128
     129        // get inode pointer, mapper pointer and file attributes
     130        vfs_inode_t * inode_ptr  = hal_remote_lpt(XPTR(file_cxy , &file_ptr->inode ));
     131        uint32_t      file_attr  = hal_remote_lw (XPTR(file_cxy , &file_ptr->attr  ));
     132        mapper_t    * mapper_ptr = hal_remote_lpt(XPTR(file_cxy , &file_ptr->mapper));
     133
     134        // get file size
     135                uint32_t size = hal_remote_lw( XPTR( file_cxy , &inode_ptr->size ) );
     136
     137        // chek offset and length arguments
     138                if( (offset + length) > size)
     139                {
     140                        printk("\n[ERROR] in %s: offset (%d) + len (%d) >= file's size (%d)\n",
     141                        __FUNCTION__, k_attr.offset, k_attr.length, size );
     142            this->errno = ERANGE;
     143            return -1;
     144                }
     145
     146        // check access rights
     147                if( (prot_read  && !(file_attr & FD_ATTR_READ_ENABLE)) ||
     148                    (prot_write && !(file_attr & FD_ATTR_WRITE_ENABLE)) )
     149                {
     150                        printk("\n[ERROR] in %s: prot = %x / file_attr = %x)\n",
     151                        __FUNCTION__ , k_attr.prot , file_attr );
     152                        this->errno = EACCES;
     153                        return -1;
     154                }
     155
     156                // increment file refcount
     157                vfs_file_count_up( file_xp );
     158
     159        mapper_xp = XPTR( file_cxy , mapper_ptr );
     160        vseg_type = VSEG_TYPE_FILE;
     161        vseg_cxy  = file_cxy;
     162    }
     163    else                                                // ANON or REMOTE
     164    {
     165        // no mapper for ANON or REMOTE
     166        mapper_xp = XPTR_NULL;
     167
     168        if( map_anon )
     169        {
     170            vseg_type = VSEG_TYPE_ANON;
     171            vseg_cxy  = local_cxy;
     172        }
     173        else
     174        {
     175            vseg_type = VSEG_TYPE_REMOTE;
     176            vseg_cxy  = k_attr.fdid;
    47177 
    48         this = current_thread;
    49         process = this->process;
    50         err  = EINVAL;
    51         file = NULL;
    52 
    53         if((err = cpu_copy_from_uspace(&attr, attr, sizeof(mmap_attr_t))))
    54         {
    55                 printk(INFO, "%s: failed, copying from uspace @%x\n",
    56                        __FUNCTION__,
    57                        attr);
    58 
    59                 this->info.errno = EFAULT;
    60                 return (int)VM_FAILED;
    61         }
    62 
    63         if((attr.flags  & VM_REG_HEAP)                     ||
    64            ((attr.flags & VM_REG_PVSH) == VM_REG_PVSH)     ||
    65            ((attr.flags & VM_REG_PVSH) == 0)               ||
    66            (attr.length == 0)                              ||
    67            (attr.offset & PMM_PAGE_MASK)                   ||
    68            ((attr.addr != NULL) && (((uint_t)attr.addr & PMM_PAGE_MASK)          ||
    69                                 (NOT_IN_USPACE(attr.length + (uint_t)attr.addr)) ||
    70                                 (NOT_IN_USPACE((uint_t)attr.addr)) )))
    71         {
    72                 printk(INFO, "%s: failed, we don't like flags (%x), length (%d), or addr (%x)\n",
    73                        __FUNCTION__,
    74                        attr.flags,
    75                        attr.length,
    76                        attr.addr);
    77      
    78                 this->info.errno = EINVAL;
    79                 return (int)VM_FAILED;
    80         }
    81    
    82         if(attr.flags & VM_REG_ANON)
    83         {
    84                 attr.offset = 0;
    85                 attr.addr   = (attr.flags & VM_REG_FIXED) ? attr.addr : NULL;
    86         }
    87         else
    88         {     
    89                 // FIXME: possible concurent delete of file from another bugy thread closing it
    90                 if((attr.fd >= CONFIG_TASK_FILE_MAX_NR) || (process_fd_lookup(process, attr.fd, &file)))
    91                 {
    92                         printk(INFO, "%s: failed, bad file descriptor (%d)\n",
    93                                __FUNCTION__,
    94                                attr.fd);
    95 
    96                         this->info.errno = EBADFD;
    97                         return (int)VM_FAILED;
    98                 }
    99      
    100                 //atomic_add(&file->f_count, 1);
    101                 vfs_file_up(file);//FIXME coalsce access to remote node info
    102      
    103                 //FIXME: does we really to get the size...
    104                 isize = vfs_inode_size_get_remote(file->f_inode.ptr, file->f_inode.cid);
    105                 if((attr.offset + attr.length) > isize)
    106                 {
    107                         printk(INFO, "%s: failed, offset (%d) + len (%d) >= file's size (%d)\n",
    108                                __FUNCTION__,
    109                                attr.offset,
    110                                attr.length,
    111                                isize);
    112 
    113                         this->info.errno = ERANGE;
    114                         goto SYS_MMAP_FILE_ERR;
    115                 }
    116 
    117                 if(((attr.prot & VM_REG_RD) && !(VFS_IS(file->f_flags, VFS_O_RDONLY)))   ||
    118                    ((attr.prot & VM_REG_WR) && !(VFS_IS(file->f_flags, VFS_O_WRONLY)))   ||
    119                    ((attr.prot & VM_REG_WR) && (VFS_IS(file->f_flags, VFS_O_APPEND))))//    ||
    120                         //(!(attr.prot & VM_REG_RD) && (attr.flags & VM_REG_PRIVATE)))
    121                 {
    122                         printk(INFO, "%s: failed, EACCES prot (%x), f_flags (%x)\n",
    123                                __FUNCTION__,
    124                                attr.prot,
    125                                file->f_flags);
    126 
    127                         this->info.errno = EACCES;
    128                         goto SYS_MMAP_FILE_ERR;
    129                 }
    130         }
    131 
    132         retval = (int) vmm_mmap(process,
    133                                 file,
    134                                 attr.addr,
    135                                 attr.length,
    136                                 attr.prot,
    137                                 attr.flags,
    138                                 attr.offset);
    139    
    140         if((retval != (int)VM_FAILED) || (attr.flags & VM_REG_ANON))
    141                 return retval;
    142 
    143 SYS_MMAP_FILE_ERR:
    144         printk(INFO, "%s: Failed, Droping file count \n",
    145                __FUNCTION__);
    146    
    147         vfs_close( file , &count );
    148 
    149         if(count == 1) process_fd_put( process , attr.fd );
    150 
    151         return (int)VM_FAILED;
    152 */
     178            if( cluster_is_undefined( vseg_cxy ) )
     179            {
     180                printk("\n[ERROR] in %s : illegal cxy for MAP_REMOTE\n", __FUNCTION__ );
     181                this->errno = EINVAL;
     182                return -1;
     183            }
     184        }
     185    }
     186
     187    // get reference process cluster and local pointer
     188    xptr_t      ref_xp  = process->ref_xp;
     189    cxy_t       ref_cxy = GET_CXY( ref_xp );
     190    process_t * ref_ptr = (process_t *)GET_PTR( ref_xp );
     191
     192    // create the vseg in reference cluster
     193    if( local_cxy == ref_cxy )
     194    {
     195        vseg = vmm_create_vseg( process,
     196                                vseg_type,
     197                                0,               // base address unused for mmap()
     198                                length,
     199                                offset,
     200                                0,               // file_size unused for mmap()
     201                                mapper_xp,
     202                                vseg_cxy );
     203    }
     204    else
     205    {
     206        rpc_vmm_create_vseg_client( ref_cxy,
     207                                    ref_ptr,
     208                                    vseg_type,
     209                                    0,            // base address unused for mmap()
     210                                    length,
     211                                    offset,
     212                                    0,            // file size unused for mmap()
     213                                    mapper_xp,
     214                                    vseg_cxy,
     215                                    &vseg );
     216    }
     217   
     218    if( vseg == NULL )
     219    {
     220        printk("\n[ERROR] in %s : cannot create vseg\n", __FUNCTION__ );
     221        this->errno = ENOMEM;
     222        return -1;
     223    }
     224
     225    // copy vseg base address to user space
     226    hal_copy_to_uspace( &attr->addr , &vseg->min , sizeof(intptr_t) );
     227
     228    tm_end = hal_get_cycles();
     229
     230syscall_dmsg("\n[DBG] %s : core[%x,%d] created vseg %s in cluster %x / cycle %d\n"
     231"      base = %x / length = %x / cost = %d\n",
     232__FUNCTION__, local_cxy , this->core->lid , vseg_type_str(vseg->type) ,
     233vseg->cxy , (uint32_t)tm_start , vseg->min , length , (uint32_t)(tm_end - tm_start) );
     234
     235        return 0;
     236
    153237}  // end sys_mmap()
     238
  • trunk/kernel/syscalls/sys_open.c

    r305 r407  
    5555    }
    5656
    57     // get pathname copy in kernel space
    58     error = hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH );
    59 
    60     if( error )
     57    // check pathname length
     58    if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH )
    6159    {
    6260        printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ );
     
    6563    }
    6664
     65    // copy pathname in kernel space
     66    hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH );
     67
    6768    // get cluster and local pointer on reference process
    6869    xptr_t      ref_xp  = process->ref_xp;
     
    7071    cxy_t       ref_cxy = GET_CXY( ref_xp );
    7172
    72     // get extended pointer on cwd inode
    73     xptr_t cwd_xp = hal_remote_lwd( XPTR( ref_cxy , &ref_ptr->vfs_cwd_xp ) );
    74 
    7573    // get the cwd lock in read mode from reference process
    7674    remote_rwlock_rd_lock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) );
    7775
    7876    // call the relevant VFS function
    79     error = vfs_open( cwd_xp,
     77    error = vfs_open( process,
    8078                      kbuf,
    8179                      flags,
  • trunk/kernel/syscalls/sys_opendir.c

    r23 r407  
    2323
    2424#include <hal_types.h>
     25#include <thread.h>
     26#include <process.h>
     27#include <printk.h>
     28#include <errno.h>
    2529#include <vfs.h>
    2630#include <syscalls.h>
     31#include <shared_syscalls.h>
    2732
    2833///////////////////////////////////
    29 int sys_opendir ( char * pathname )
     34int sys_opendir ( char *  pathname,
     35                  DIR  ** dirp )
    3036{
    31         uint32_t   mode  = 0;
    32     uint32_t   flags = O_DIR;
    33 
    34     return sys_open( pathname , flags , mode );
    35 }
     37    printk("\n[ERROR] in %s : not implemented yet\n", __FUNCTION__ );
     38    CURRENT_THREAD->errno = ENOMEM;
     39    return -1;
     40}  // end sys opendir()
  • trunk/kernel/syscalls/sys_pipe.c

    r23 r407  
    3636    this->errno = ENOSYS;
    3737    return -1;
    38 
    3938}
  • trunk/kernel/syscalls/sys_read.c

    r313 r407  
    3333#include <process.h>
    3434
    35 /* TODO: user page(s) need to be locked  [AG] */
     35// TODO: concurrent user page(s) munmap need to be handled [AG]
     36
     37// instrumentation
     38extern uint32_t enter_sys_read;
     39extern uint32_t enter_devfs_move;
     40extern uint32_t enter_txt_read;
     41extern uint32_t enter_chdev_cmd;
     42extern uint32_t enter_chdev_server;
     43extern uint32_t enter_tty_cmd;
     44extern uint32_t enter_tty_isr;
     45extern uint32_t exit_tty_isr;
     46extern uint32_t exit_tty_cmd;
     47extern uint32_t exit_chdev_server;
     48extern uint32_t exit_chdev_cmd;
     49extern uint32_t exit_txt_read;
     50extern uint32_t exit_devfs_move;
     51extern uint32_t exit_sys_read;
     52
    3653
    3754/////////////////////////////////
    3855int sys_read( uint32_t   file_id,
    39               void     * buf,
     56              void     * vaddr,
    4057              uint32_t   count )
    4158{
     
    4360    paddr_t      paddr;       // required for user space checking
    4461        xptr_t       file_xp;     // remote file extended pointer
     62    uint32_t     nbytes;      // number of bytes actually read
     63
     64        uint32_t     tm_start;
     65        uint32_t     tm_end;
     66
     67        tm_start = hal_get_cycles();
     68
     69#if CONFIG_READ_START
     70enter_sys_read = tm_start;
     71#endif
    4572
    4673        thread_t  *  this    = CURRENT_THREAD;
     
    5178        {
    5279        printk("\n[ERROR] in %s : illegal file descriptor index = %d\n",
    53                __FUNCTION__ , file_id );
     80        __FUNCTION__ , file_id );
    5481                this->errno = EBADFD;
    5582                return -1;
     
    5784
    5885    // check user buffer in user space
    59     error = vmm_v2p_translate( false , buf , &paddr );
     86    error = vmm_v2p_translate( false , vaddr , &paddr );
    6087
    6188    if ( error )
    6289    {
    6390        printk("\n[ERROR] in %s : user buffer unmapped = %x\n",
    64                __FUNCTION__ , (intptr_t)buf );
     91        __FUNCTION__ , (intptr_t)vaddr );
    6592                this->errno = EINVAL;
    6693                return -1;
     
    7299    if( file_xp == XPTR_NULL )
    73100    {
    74         printk("\n[ERROR] in %s : undefined file descriptor index = %d\n",
    75                __FUNCTION__ , file_id );
     101        printk("\n[ERROR] in %s : undefined file descriptor index = %d in process %x\n",
     102        __FUNCTION__ , file_id , process->pid );
    76103        this->errno = EBADFD;
    77104        return -1;
     
    86113    if( (attr & FD_ATTR_READ_ENABLE) == 0 )
    87114        {
    88         printk("\n[ERROR] in %s : file %d not readable\n",
    89                __FUNCTION__ , file_id );
     115        printk("\n[ERROR] in %s : file %d not readable in process %x\n",
     116        __FUNCTION__ , file_id , process->pid );
    90117                this->errno = EBADFD;
    91118                return -1;
    92119        }
    93120   
    94     // transfer count bytes directly from mapper to user buffer
    95     error = vfs_user_move( true,               // to_buffer
    96                            file_xp ,
    97                            buf,
    98                            count );
     121    // get file type
     122    vfs_inode_type_t type = hal_remote_lw( XPTR( file_cxy , &file_ptr->type ) );
    99123
    100     if( error )
     124    // action depend on file type
     125    if( type == INODE_TYPE_FILE )      // transfer count bytes from file mapper
    101126    {
    102         printk("\n[ERROR] in %s cannot read data from file %d\n",
    103                __FUNCTION__ , file_id );
     127        nbytes = vfs_user_move( true,               // from mapper to buffer
     128                                file_xp,
     129                                vaddr,
     130                                count );
     131    }
     132    else if( type == INODE_TYPE_DEV )  // transfer count bytes from device
     133    {
     134        nbytes = devfs_user_move( true,             // from device to buffer
     135                                  file_xp,
     136                                  vaddr,
     137                                  count );
     138    }
     139    else
     140    {
     141        nbytes = 0;
     142        panic("file type %d non supported yet", type );
     143    }
     144
     145    if( nbytes != count )
     146    {
     147        printk("\n[ERROR] in %s cannot read data from file %d in process %x\n",
     148        __FUNCTION__ , file_id , process->pid );
    104149        this->errno = error;
    105150        return -1;
     
    108153    hal_fence();
    109154
    110         return 0;
     155    tm_end = hal_get_cycles();
     156
     157#if CONFIG_READ_DEBUG
     158exit_sys_read = tm_end;
     159
     160printk("\n@@@@@@@@@@@@ timing ro read character %c\n"
     161" - enter_sys_read     = %d / delta %d\n"
     162" - enter_devfs_move   = %d / delta %d\n"
     163" - enter_txt_read     = %d / delta %d\n"
     164" - enter_chdev_cmd    = %d / delta %d\n"
     165" - enter_chdev_server = %d / delta %d\n"
     166" - enter_tty_cmd      = %d / delta %d\n"
     167" - enter_tty_isr      = %d / delta %d\n"
     168" - exit_tty_isr       = %d / delta %d\n"
     169" - exit_tty_cmd       = %d / delta %d\n"
     170" - exit_chdev_server  = %d / delta %d\n"
     171" - exit_chdev_cmd     = %d / delta %d\n"
     172" - exit_txt_read      = %d / delta %d\n"
     173" - exit_devfs_move    = %d / delta %d\n"
     174" - exit_sys_read      = %d / delta %d\n",
     175*((char *)(intptr_t)paddr) ,
     176enter_sys_read     , 0 ,
     177enter_devfs_move   , enter_devfs_move   - enter_sys_read     ,
     178enter_txt_read     , enter_txt_read     - enter_devfs_move   ,
     179enter_chdev_cmd    , enter_chdev_cmd    - enter_txt_read     ,
     180enter_chdev_server , enter_chdev_server - enter_chdev_cmd    ,
     181enter_tty_cmd      , enter_tty_cmd      - enter_chdev_server ,
     182enter_tty_isr      , enter_tty_isr      - enter_tty_cmd      ,
     183exit_tty_isr       , exit_tty_isr       - enter_tty_isr      ,
     184exit_tty_cmd       , exit_tty_cmd       - exit_tty_isr       ,
     185exit_chdev_server  , exit_chdev_server  - exit_tty_cmd       ,
     186exit_chdev_cmd     , exit_chdev_cmd     - exit_chdev_server  ,
     187exit_txt_read      , exit_txt_read      - exit_chdev_cmd     ,
     188exit_devfs_move    , exit_devfs_move    - exit_txt_read      ,
     189exit_sys_read      , exit_sys_read      - exit_devfs_move    );
     190#endif
     191
     192syscall_dmsg("\n[DBG] %s : core[%x,%d] / thread %x / nbytes = %d / cycle %d\n"
     193" first byte = %c / file_id = %d / cost = %d\n",
     194__FUNCTION__ , local_cxy , this->core->lid , this->trdid , nbytes , tm_start ,
     195*((char *)(intptr_t)paddr) , file_id , tm_end - tm_start );
     196 
     197        return nbytes;
    111198
    112199}  // end sys_read()
  • trunk/kernel/syscalls/sys_readdir.c

    r23 r407  
    3131#include <process.h>
    3232#include <syscalls.h>
     33#include <shared_syscalls.h>
    3334
    34 //////////////////////////////////////////
    35 int sys_readdir ( uint32_t       file_id,
    36                   vfs_dirent_t * dirent )
     35///////////////////////////////////////
     36int sys_readdir( DIR            * dirp,
     37                 struct dirent ** dentp )
    3738{
    38         error_t        error;
    39     paddr_t        paddr;
    40         xptr_t         file_xp;    // extended pointer on searched directory file descriptor
    41     vfs_dirent_t   k_dirent;   // kernel copy of dirent
    42 
    43         thread_t     * this     = CURRENT_THREAD;
    44         process_t    * process  = this->process;
    45 
    46     // check file_id argument
    47         if( file_id >= CONFIG_PROCESS_FILE_MAX_NR )
    48         {
    49         printk("\n[ERROR] in %s : illegal file descriptor index\n", __FUNCTION__ );
    50         this->errno = EBADFD;
    51                 return -1;
    52         }
    53 
    54     // check dirent structure in user space
    55     error = vmm_v2p_translate( false , dirent , &paddr );
    56 
    57     if ( error )
    58     {
    59         printk("\n[ERROR] in %s : user buffer for dirent unmapped = %x\n",
    60                __FUNCTION__ , (intptr_t)dirent );
    61                 this->errno = EFAULT;
    62                 return -1;
    63     }
    64 
    65     // get extended pointer on remote file descriptor
    66     file_xp = process_fd_get_xptr( process , file_id );
    67 
    68     if( file_xp == XPTR_NULL )
    69     {
    70         printk("\n[ERROR] in %s : undefined file descriptor index = %d\n",
    71                __FUNCTION__ , file_id );
    72             this->errno = EBADFD;
    73         return -1;
    74     }
    75  
    76     // call the relevant VFS function
    77         error = vfs_readdir( file_xp , &k_dirent );
    78 
    79         if( error )
    80         {
    81         printk("\n[ERROR] in %s : cannot access directory %d\n",
    82                __FUNCTION__ , file_id );
    83                 this->errno = error;
    84                 return -1;
    85         }
    86    
    87     // copy dirent to user space
    88     hal_copy_to_uspace( dirent , &k_dirent , sizeof(vfs_dirent_t) );
    89 
    90         return 0;
    91 
     39    printk("\n[ERROR] in %s : not implemented yet\n", __FUNCTION__ );
     40    CURRENT_THREAD->errno = ENOMEM;
     41    return -1;
    9242}  // end sys_readdir()
  • trunk/kernel/syscalls/sys_rmdir.c

    r305 r407  
    4040        process_t * process = this->process;
    4141
    42     // get pathname copy in kernel space
    43     error = hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH );
    44 
    45     if( error )
     42    // check pathname length
     43    if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH )
    4644    {
    4745        printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ );
    48                 this->errno = ENFILE;
     46        this->errno = ENFILE;
    4947        return -1;
    5048    }
     49
     50    // copy pathname in kernel space
     51    hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH );
    5152
    5253    // get cluster and local pointer on reference process
  • trunk/kernel/syscalls/sys_signal.c

    r406 r407  
    4545        this->process->sig_mgr.sigactions[sig_id] = handler;
    4646
    47         signal_dmsg("\n[DMSG] %s : handler @%x has been registred for signal %d\n",
     47        signal_dmsg("\n[DBG] %s : handler @%x has been registred for signal %d\n",
    4848                    __FUNCTION__ , handler , sig_id );
    4949
  • trunk/kernel/syscalls/sys_stat.c

    r124 r407  
    3232#include <process.h>
    3333
    34 //////////////////////////////////////////
    35 int sys_stat( uint32_t            file_id,
    36               struct vfs_stat_s * stat )
     34/////////////////////////////////////
     35int sys_stat( char        * pathname,
     36              struct stat * u_stat )
    3737{
    38     error_t           error;
    39     paddr_t           paddr;
    40     struct vfs_stat_s k_stat;
    41     xptr_t            file_xp;
     38    error_t       error;
     39    paddr_t       paddr;
     40    struct stat   k_stat;       // kernel space
     41    xptr_t        file_xp;
     42    char          kbuf[CONFIG_VFS_MAX_PATH_LENGTH];
    4243       
    4344        thread_t  * this    = CURRENT_THREAD;
     
    4546
    4647    // check stat structure in user space
    47     error = vmm_v2p_translate( false , stat , &paddr );
     48    error = vmm_v2p_translate( false , u_stat , &paddr );
    4849
    4950        if( error )
     
    5556        }       
    5657
    57     // get extended pointer on remote file descriptor
    58     file_xp = process_fd_get_xptr( process , file_id );
    59 
    60     if( file_xp == XPTR_NULL )
     58    // check pathname length
     59    if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH )
    6160    {
    62         printk("\n[ERROR] in %s : undefined file descriptor for thread %x in process %x\n",
    63                __FUNCTION__ , this->trdid , process->pid );
    64         this->errno = EBADFD;
     61        printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ );
     62        this->errno = ENFILE;
    6563        return -1;
    6664    }
    6765
    68     // call the relevant VFS function
     66    // copy pathname in kernel space
     67    hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH );
     68
     69    // get cluster and local pointer on reference process
     70    xptr_t      ref_xp  = process->ref_xp;
     71    process_t * ref_ptr = (process_t *)GET_PTR( ref_xp );
     72    cxy_t       ref_cxy = GET_CXY( ref_xp );
     73
     74    // get extended pointer on cwd inode
     75    xptr_t cwd_xp = hal_remote_lwd( XPTR( ref_cxy , &ref_ptr->vfs_cwd_xp ) );
     76
     77    // get the cwd lock in read mode from reference process
     78    remote_rwlock_rd_lock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) );
     79
     80    // get extended pointer on remote file descriptor
     81    error = vfs_lookup( cwd_xp,
     82                        pathname,
     83                        0,
     84                        &file_xp );
     85
     86    // release the cwd lock
     87    remote_rwlock_rd_unlock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) );
     88
     89    if( error )
     90    {
     91        printk("\n[ERROR] in %s : cannot found file <%s> for thread %x in process %x\n",
     92               __FUNCTION__ , pathname , this->trdid , process->pid );
     93        this->errno = error;
     94        return -1;
     95    }
     96
     97    // call VFS function to get stat info
    6998    error = vfs_stat( file_xp,
    7099                      &k_stat );
    71100    if( error )
    72101        {
    73         printk("\n[ERROR] in %s : cannot access file %d for thread %x in process %x\n",
    74                __FUNCTION__ , file_id , this->trdid , process->pid );
     102        printk("\n[ERROR] in %s : cannot get stats for file %s\n",
     103               __FUNCTION__ , pathname );
    75104                this->errno = error;
    76105                return -1;
    77106        }
    78107   
    79     // copy stat to user space
    80     hal_copy_to_uspace( stat , &k_stat , sizeof(struct vfs_stat_s) );
     108    // copy k_stat to u_stat
     109    hal_copy_to_uspace( u_stat , &k_stat , sizeof(struct stat) );
    81110
    82111    hal_fence();
  • trunk/kernel/syscalls/sys_thread_create.c

    r406 r407  
    4040
    4141
    42 //////////////////////////////////////////////////////////////////////////////////////////
    43 // This function implements the pthread_create system call
    44 //////////////////////////////////////////////////////////////////////////////////////////
    45 int sys_thread_create ( thread_t       * new_thread,    // [out] argument
    46                         pthread_attr_t * user_attr,     // [in] argument
    47                         void           * start_func,    // [in] argument
    48                         void           * start_arg )    // [in] argument
     42///////////////////////////////////////////////////
     43int sys_thread_create ( pthread_t      * trdid_ptr,
     44                        pthread_attr_t * user_attr,
     45                        void           * start_func,
     46                        void           * start_arg )
    4947{
    50         pthread_attr_t   k_attr;           // copy of pthread attributes in kernel space
     48        pthread_attr_t   kern_attr;        // copy of pthread attributes in kernel space
    5149        thread_t       * parent;           // pointer on thread executing the pthread_create
    5250        xptr_t           parent_xp;        // extended pointer on created thread
     
    5654        process_t      * process;          // pointer on local process descriptor
    5755        paddr_t          paddr;            // unused, required by vmm_v2p_translate()
     56    cxy_t            target_cxy;       // target cluster identifier
    5857        error_t          error;
    5958
     
    6362        tm_start = hal_get_cycles();
    6463
    65         // get parent thead pointer, extended pointer, and process pointer
     64        // get parent thead pointer, extended pointer, and process
    6665        parent     = CURRENT_THREAD;
    6766        parent_xp  = XPTR( local_cxy , parent );
    6867        process    = parent->process;
    6968
    70         // check user_attr in user space
    71         error = vmm_v2p_translate( false , user_attr , &paddr );
     69        // check user_attr in user space & copy to kernel space
     70    if( user_attr != NULL )
     71    {
     72            error = vmm_v2p_translate( false , user_attr , &paddr );
    7273
    73         if( error )
    74         {
    75                 printk("\n[ERROR] in %s : user_attr unmapped\n", __FUNCTION__ );
    76                 parent->errno = EINVAL;
    77                 return -1;
    78         }
     74            if( error )
     75            {
     76                    printk("\n[ERROR] in %s : user_attr unmapped\n", __FUNCTION__ );
     77                    parent->errno = EINVAL;
     78                    return -1;
     79            }
     80       
     81            hal_copy_from_uspace( &kern_attr , user_attr , sizeof(pthread_attr_t) );
     82    }
    7983
    8084        // check start_func in user space
     
    98102        }
    99103
    100         // copy user_attr structure from user space to kernel space
    101         hal_copy_from_uspace( &k_attr , user_attr , sizeof(pthread_attr_t) );
    102 
    103         // check/set "cxy" attribute
    104         if( k_attr.attributes & PT_ATTR_CLUSTER_DEFINED )
     104        // check / define attributes an target_cxy
     105    if( user_attr != NULL )                      // user defined attributes
     106    {
     107            // check / get target_cxy
     108            if( kern_attr.attributes & PT_ATTR_CLUSTER_DEFINED )
     109            {
     110                    if( cluster_is_undefined( kern_attr.cxy ) )
     111                    {
     112                            printk("\n[ERROR] in %s : illegal target cluster = %x\n",
     113                            __FUNCTION__ , kern_attr.cxy );
     114                            parent->errno = EINVAL;
     115                            return -1;
     116            }
     117            target_cxy = kern_attr.cxy;
     118                }
     119        else
     120        {
     121            target_cxy = dqdt_get_cluster_for_process();
     122        }
     123        }
     124        else                                        // set default attributes
    105125        {
    106                 if( cluster_is_undefined( k_attr.cxy ) )
    107                 {
    108                         printk("\n[ERROR] in %s : illegal target cluster attribute = %x\n",
    109                                __FUNCTION__ , k_attr.cxy );
    110                         parent->errno = EINVAL;
    111                         return -1;
    112                 }
    113         }
    114         else
    115         {
    116                 k_attr.cxy = dqdt_get_cluster_for_process();
     126        kern_attr.attributes = PT_ATTR_DETACH | PT_ATTR_CLUSTER_DEFINED;
     127        target_cxy           = dqdt_get_cluster_for_process();
    117128        }
    118129
    119130        // create the thread, using a RPC if required
    120         // this returns "error", "child", and "child_xp"
     131        // this returns "error", "child_ptr", and "child_xp"
    121132
    122         if( k_attr.cxy == local_cxy )                         // target cluster is local
     133        if( target_cxy == local_cxy )                         // target cluster is local
    123134        {
    124135                // create thread in local cluster
     
    126137                                            start_func,
    127138                                            start_arg,
    128                                             &k_attr,
     139                                            &kern_attr,
    129140                                            &child_ptr );
    130141
     
    133144        else                                                 // target cluster is remote
    134145        {
    135                 rpc_thread_user_create_client( k_attr.cxy,
     146                rpc_thread_user_create_client( target_cxy,
    136147                                               process->pid,
    137148                                               start_func,
    138149                                               start_arg,
    139                                                &k_attr,
     150                                               &kern_attr,
    140151                                               &child_xp,
    141152                                               &error );
     
    152163
    153164        // returns trdid to user space
    154         trdid = hal_remote_lw( XPTR( k_attr.cxy , &child_ptr->trdid ) );
    155         hal_copy_to_uspace( new_thread , &trdid , sizeof(pthread_t) );
     165        trdid = hal_remote_lw( XPTR( target_cxy , &child_ptr->trdid ) );
     166        hal_copy_to_uspace( trdid_ptr , &trdid , sizeof(pthread_t) );
    156167
    157         // register new-thread in parent-thread children list if required
    158         if( (k_attr.attributes & PT_ATTR_DETACH) == 0 )
    159             thread_child_parent_link( parent_xp , child_xp );
     168    // register child in parent if required
     169    if( user_attr != NULL )
     170    {
     171            if( (kern_attr.attributes & PT_ATTR_DETACH) == 0 )
     172                thread_child_parent_link( parent_xp , child_xp );
     173    }
     174
     175    // activate new thread
     176        thread_unblock( child_xp , THREAD_BLOCKED_GLOBAL );
     177
     178    hal_fence();
    160179
    161180        tm_end = hal_get_cycles();
    162181
    163         thread_dmsg("\n[DMSG] %s created thread %x for process %x in cluster %x\n"
    164                     "  start_cycle = %d / end_cycle = %d\n",
    165                        trdid , process->pid , k_attr.cxy , tm_start , tm_end );
     182syscall_dmsg("\n[DBG] %s : core[%x,%d] created thread %x for process %x / cycle %d\n"
     183"      cluster %x / cost = %d cycles\n",
     184__FUNCTION__ , local_cxy , parent->core->lid , trdid , process->pid , tm_end ,
     185target_cxy , tm_end - tm_start );
     186
    166187        return 0;
    167 }
    168188
     189}  // end sys_thread_create()
     190
  • trunk/kernel/syscalls/sys_thread_exit.c

    r296 r407  
    3838    reg_t       irq_state;
    3939
    40     // register the exit_value in thread descriptor
     40    // register the exit_value pointer in thread descriptor
    4141    this->exit_value = exit_value;
    4242
    43     // we enter the join loop to wait the join
    44     // only if thread is joinable
     43    // enter the join loop to wait the join if thread is joinable
    4544    if( (this->flags & THREAD_FLAG_DETACHED) == 0 )
    4645    {
     
    7473
    7574                // deschedule
    76                 sched_yield( NULL );
     75                sched_yield();
    7776            }     
    7877        }
  • trunk/kernel/syscalls/sys_thread_join.c

    r296 r407  
    138138
    139139            // deschedule
    140             sched_yield( NULL );
     140            sched_yield();
    141141        }
    142142    }
  • trunk/kernel/syscalls/sys_thread_sleep.c

    r406 r407  
    3232    thread_t * this = CURRENT_THREAD;
    3333
    34     thread_dmsg("\n[DMSG] %s : thread %x in process %x goes to sleep at cycle %d\n",
     34    thread_dmsg("\n[DBG] %s : thread %x in process %x goes to sleep at cycle %d\n",
    3535                __FUNCTION__, this->trdid, this->process->pid, hal_get_cycles() );
    3636
    3737    thread_block( this , THREAD_BLOCKED_GLOBAL );
    38     sched_yield( NULL );
     38    sched_yield();
    3939
    40     thread_dmsg("\n[DMSG] %s : thread %x in process %x resume at cycle\n",
     40    thread_dmsg("\n[DBG] %s : thread %x in process %x resume at cycle\n",
    4141                __FUNCTION__, this->trdid, this->process->pid, hal_get_cycles() );
    4242
  • trunk/kernel/syscalls/sys_thread_yield.c

    r296 r407  
    2727int sys_thread_yield()
    2828{
    29         sched_yield( NULL );
     29        sched_yield();
    3030        return 0;
    3131}
  • trunk/kernel/syscalls/sys_timeofday.c

    r124 r407  
    3030#include <vmm.h>
    3131#include <core.h>
    32 #include <time.h>
     32#include <shared_syscalls.h>
    3333
    3434////////////////////////////////////////
  • trunk/kernel/syscalls/sys_trace.c

    r406 r407  
    4949        // desactivate thread trace TODO
    5050
    51             printk("\n[DMSG] %s : trace OFF  for thread %x in process %x\n",
     51            printk("\n[DBG] %s : trace OFF  for thread %x in process %x\n",
    5252               __FUNCTION__ , trdid , pid );
    5353    }
     
    5656        // activate thread trace TODO
    5757                   
    58             printk("\n[DMSG] %s : trace ON for thread %x in process %x\n",
     58            printk("\n[DBG] %s : trace ON for thread %x in process %x\n",
    5959               __FUNCTION__ , trdid , pid );
    6060    }
  • trunk/kernel/syscalls/sys_unlink.c

    r305 r407  
    3737    process_t    * process  = this->process;
    3838
    39     // get pathname copy in kernel space
    40     error = hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH );
    41 
    42     if( error )
     39    // check pathname length
     40    if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH )
    4341    {
    4442        printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ );
     
    4644        return -1;
    4745    }
     46
     47    // copy pathname in kernel space
     48    hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH );
    4849
    4950    // get cluster and local pointer on reference process
  • trunk/kernel/syscalls/sys_write.c

    r315 r407  
    3232#include <process.h>
    3333
    34 /* TODO: user page(s) need to be locked [AG] */
     34/* TODO: concurrent user page(s) unmap need to be handled [AG] */
    3535
    3636//////////////////////////////////
    3737int sys_write( uint32_t   file_id,
    38                void     * buf,
     38               void     * vaddr,
    3939               uint32_t   count )
    4040{
    4141    error_t      error;
    42     paddr_t      paddr;                // required for user space checking
     42    paddr_t      paddr;                // unused, but required for user space checking
    4343        xptr_t       file_xp;              // remote file extended pointer
     44    uint32_t     nbytes;               // number of bytes actually written
     45
     46        uint32_t     tm_start;
     47        uint32_t     tm_end;
     48
     49        tm_start = hal_get_cycles();
    4450
    4551        thread_t   * this = CURRENT_THREAD;
     
    5561
    5662    // check user buffer in user space
    57     error = vmm_v2p_translate( false , buf , &paddr );
     63    error = vmm_v2p_translate( false , vaddr , &paddr );
    5864
    5965    if ( error )
    6066    {
    6167        printk("\n[ERROR] in %s : user buffer unmapped = %x\n",
    62                __FUNCTION__ , (intptr_t)buf );
     68        __FUNCTION__ , (intptr_t)vaddr );
    6369                this->errno = EINVAL;
    6470                return -1;
     
    7076    if( file_xp == XPTR_NULL )
    7177    {
    72         printk("\n[ERROR] in %s : undefined file descriptor index = %d\n",
    73                __FUNCTION__ , file_id );
     78        printk("\n[ERROR] in %s : undefined file descriptor index = %d in process %x\n",
     79        __FUNCTION__ , file_id , process->pid );
    7480                this->errno = EBADFD;
    7581                return -1;
     
    8490    if( (attr & FD_ATTR_WRITE_ENABLE) == 0 )
    8591        {
    86         printk("\n[ERROR] in %s : file %d not writable\n",
    87                __FUNCTION__ , file_id );
     92        printk("\n[ERROR] in %s : file %d not writable in process %x\n",
     93        __FUNCTION__ , file_id , process->pid );
    8894                this->errno = EBADFD;
    8995                return -1;
    9096        }
    9197   
    92     // transfer count bytes directly from user buffer to mapper
    93     error = vfs_user_move( false,               // from buffer
    94                            file_xp,
    95                            buf ,
    96                            count );
     98    // get file type
     99    vfs_inode_type_t type = hal_remote_lw( XPTR( file_cxy , &file_ptr->type ) );
    97100
    98     if( error )
     101    // action depend on file type
     102    if( type == INODE_TYPE_FILE )      // transfer count bytes to file mapper
    99103    {
    100         printk("\n[ERROR] in %s cannot read data from file %d\n",
    101                __FUNCTION__ , file_id );
     104        nbytes = vfs_user_move( false,               // from buffer to mapper
     105                                file_xp,
     106                                vaddr,
     107                                count );
     108    }
     109    else if( type == INODE_TYPE_DEV )  // transfer count bytes to device
     110    {
     111        nbytes = devfs_user_move( false,             // from buffer to device
     112                                 file_xp,
     113                                 vaddr,
     114                                 count );
     115    }
     116    else
     117    {
     118        nbytes = 0;
     119        panic("file type %d non supported", type );
     120    }
     121
     122    if( nbytes != count )
     123    {
     124        printk("\n[ERROR] in %s cannot write data to file %d in process %x\n",
     125        __FUNCTION__ , file_id , process->pid );
    102126        this->errno = error;
    103127        return -1;
     
    106130    hal_fence();
    107131
    108         return 0;
     132    tm_end = hal_get_cycles();
     133
     134syscall_dmsg("\n[DBG] %s : core[%x,%d] / thread %x / nbytes = %d / cycle %d\n"
     135" first byte = %c / file_id = %d / cost = %d\n",
     136__FUNCTION__ , local_cxy , this->core->lid , this->trdid , nbytes , tm_start ,
     137*((char *)(intptr_t)paddr) , file_id , tm_end - tm_start );
     138 
     139        return nbytes;
    109140
    110141}  // end sys_write()
  • trunk/kernel/syscalls/syscalls.h

    r279 r407  
    11/*
    2  * syscalls.h - kernel services definition
     2 * syscalls.h - Kernel side services for syscall handling.
    33 *
    44 * Author     Alain Greiner (2016,2017)
     
    2626
    2727#include <hal_types.h>
    28 #include <time.h>
    29 
    30 /*****   Forward declarations  *****/
     28#include <shared_syscalls.h>
     29
     30/**   Forward declarations  *****/
    3131
    3232struct thread_s;                  // defined in thread.h
     
    3636struct mmap_attr_s;               // defined in vmm.h
    3737
    38 /******************************************************************************************
    39  * This enum defines the mnemonics for the syscall indexes.
    40  * It must be kept consistent with the array defined in do_syscalls.c
    41  *****************************************************************************************/
    42 enum
    43 {
    44         SYS_THREAD_EXIT    = 0,
    45         SYS_MMAP           = 1,
    46         SYS_THREAD_CREATE  = 2,
    47         SYS_THREAD_JOIN    = 3,
    48         SYS_THREAD_DETACH  = 4,
    49         SYS_THREAD_YIELD   = 5,
    50         SYS_SEM            = 6,
    51         SYS_CONDVAR        = 7,
    52         SYS_BARRIER        = 8,
    53         SYS_MUTEX          = 9,
    54 
    55         SYS_SLEEP          = 10,
    56         SYS_WAKEUP         = 11,
    57         SYS_OPEN           = 12,
    58         SYS_CREAT          = 13,
    59         SYS_READ           = 14,
    60         SYS_WRITE          = 15,
    61         SYS_LSEEK          = 16,
    62         SYS_CLOSE          = 17,
    63         SYS_UNLINK         = 18,   
    64         SYS_PIPE           = 19,
    65 
    66         SYS_CHDIR          = 20,
    67         SYS_MKDIR          = 21,
    68         SYS_MKFIFO         = 22,   
    69         SYS_OPENDIR        = 23,
    70         SYS_READDIR        = 24,
    71         SYS_CLOSEDIR       = 25,
    72         SYS_GETCWD         = 26,
    73         SYS_CLOCK          = 27,
    74         SYS_ALARM          = 28,   
    75         SYS_RMDIR          = 29,
    76 
    77         SYS_UTLS           = 30, 
    78         SYS_CHMOD          = 31,
    79         SYS_SIGNAL         = 32,
    80         SYS_TIMEOFDAY      = 33,
    81         SYS_KILL           = 34,
    82         SYS_GETPID         = 35,
    83         SYS_FORK           = 36,
    84         SYS_EXEC           = 37,
    85         SYS_STAT           = 38,     
    86         SYS_TRACE          = 39,
    87        
    88         SYSCALLS_NR        = 40,
    89 };
    90 
    91 
    92 /********************************************************************************************/
    93 /********************    system calls    ****************************************************/
    94 /********************************************************************************************/
    95 
    96 /*********************************************************************************************
    97  * [0] This function terminates the execution of the calling user thread value,
     38/******************************************************************************************
     39 * [0] This function terminates the execution of the calling user thread,
    9840 * and makes the exit_value pointer available to any successful pthread_join() with the
    9941 * terminating thread.
    100  *********************************************************************************************
    101  * @ exit_vallue  : [out] pointer to to the parrent thread if attached.
    102  * @ return 0 if success / return -1 if failure.
    103  ********************************************************************************************/
     42 ******************************************************************************************
     43 * @ exit_vallue  : pointer to be returned to parent thread if thead is attached.
     44 * @ return 0 if success / return -1 if failure.
     45 *****************************************************************************************/
    10446int sys_thread_exit( void * exit_value );
    10547
    106 /*********************************************************************************************
    107  * [1] This function map physical memory (or a file) in the calling thread virtual space.
    108  * The <attr> argument is a pointer on a structure containing arguments, defined in vmm.h.
    109  * TODO not implemented yet...
    110  *********************************************************************************************
    111  * @ attr       : pointer on attributes structure.
    112  * @ return 0 if success / return -1 if failure.
    113  ********************************************************************************************/
    114 int sys_mmap( struct mmap_attr_s * attr );
    115 
    116 /*********************************************************************************************
     48/******************************************************************************************
     49 * [1] This function calls the scheduler for the core running the calling thread.
     50 ******************************************************************************************
     51 * @ x_size   : [out] number of clusters in a row.
     52 * @ y_size   : [out] number of clusters in a column.
     53 * @ ncores   : [out] number of cores per cluster.
     54 * @ return always 0.
     55 *****************************************************************************************/
     56int sys_thread_yield();
     57
     58/******************************************************************************************
    11759 * [2] This function creates a new user thread. The <user_attr> argument is a pointer
    11860 * on astructure containing the thread attributes, defined in thread.h file.
    119  *********************************************************************************************
     61 ******************************************************************************************
    12062 * @ new_thread  : [out] local pointer on created thread descriptor.
    12163 * @ user_attr   : [in]  pointer on thread attributes structure.
     
    12365 * @ start_args  : [in]  pointer on start function arguments.
    12466 * @ return 0 if success / return -1 if failure.
    125  ********************************************************************************************/
     67 *****************************************************************************************/
    12668int sys_thread_create( struct thread_s        * new_thread,
    12769                       struct pthread_attr_s  * user_attr,
     
    12971                       void                   * start_args );
    13072
    131 /*********************************************************************************************
     73/******************************************************************************************
    13274 * [3] This blocking function suspend execution of the calling thread until completion
    13375 * of another target thread identified by the <trdid> argument.
    13476 * If the <exit_value> argument is not NULL, the value passed to pthread_exit() by the
    13577 * target thread is stored in the location referenced by exit_value.
    136  *********************************************************************************************
     78 ******************************************************************************************
    13779 * @ trdid     : [in]  target thread identifier.
    13880 * @ thread    : [out] buffer for exit_value returned by target thread.
    13981 * @ return 0 if success / return -1 if failure.
    140  ********************************************************************************************/
     82 *****************************************************************************************/
    14183int sys_thread_join( trdid_t    trdid,
    14284                     void    ** exit_value );
    14385
    144 /*********************************************************************************************
     86/******************************************************************************************
    14587 * [4] This function detach a joinable thread.
    146  *********************************************************************************************
    147  * @ trdid   : thread identifier.
    148  * @ return 0 if success / return -1 if failure.
    149  ********************************************************************************************/
     88 ******************************************************************************************
     89 * @ trdid   : thread identifier.i
     90 * @ return 0 if success / return -1 if failure.
     91 *****************************************************************************************/
    15092int sys_thread_detach( trdid_t  trdid );
    15193
    152 /*********************************************************************************************
    153  * [5] This function calls the scheduler for the core running the calling thread.
    154  *********************************************************************************************
    155  * @ return always 0.
    156  ********************************************************************************************/
    157 int sys_thread_yield();
    158 
    159 /*********************************************************************************************
     94/******************************************************************************************
     95 * [5] This slot is not used.
     96 *****************************************************************************************/
     97
     98/******************************************************************************************
    16099 * [6] This function implement all operations on a POSIX unnamed semaphore,
    161100 * that can be shared by threads running in different clusters.
    162101 * The kernel structure representing a remote semaphore is in the remote_sem.h file,
    163102 * and the code implementing the operations is in the remore_sem.c file.
    164  *********************************************************************************************
     103 ******************************************************************************************
    165104 * @ vaddr     : semaphore virtual address in user space == identifier.
    166105 * @ operation : SEM_INIT / SEM_DESTROY / SEM_GETVALUE / SEM_POST / SEM_WAIT.
    167106 * @ value     : pointer on in/out argument in user space.
    168107 * @ return 0 if success / return -1 if failure.
    169  ********************************************************************************************/
     108 *****************************************************************************************/
    170109int sys_sem( void       * vaddr,
    171110             uint32_t     operation,
    172111             uint32_t   * value );
    173112
    174 typedef enum
    175 {
    176         SEM_INIT,
    177         SEM_DESTROY,
    178         SEM_GETVALUE,
    179         SEM_WAIT,
    180         SEM_POST,
    181 }
    182 sem_operation_t;
    183 
    184 /*********************************************************************************************
     113/******************************************************************************************
    185114 * [7] This function implement all operations on a POSIX condition variable.
    186115 * The kernel structure representing a cond_var is defined in the remote_cv.h file,
    187116 * The code implementing the operations is defined in the remote_cv.c file.
    188  *********************************************************************************************
     117 ******************************************************************************************
    189118 * @ vaddr     : condvar virtual address in user space == identifier.
    190119 * @ operation : operation type (see below).
    191120 * @ attr      : mutex virtual address in user space == identifier.
    192121 * @ return 0 if success / return -1 if failure.
    193  ********************************************************************************************/
     122 *****************************************************************************************/
    194123int sys_condvar( void     * condvar,
    195124                 uint32_t   operation,
    196125                 void     * mutex );
    197126
    198 typedef enum
    199 {
    200         CONDVAR_INIT,
    201         CONDVAR_DESTROY,
    202     CONDVAR_WAIT,
    203     CONDVAR_SIGNAL,
    204     CONDVAR_BROADCAST,
    205 }
    206 condvar_operation_t;
    207 
    208 /*********************************************************************************************
     127/******************************************************************************************
    209128 * [8] This function implement all operations on a POSIX barrier.
    210129 * The kernel structure representing a barrier is defined in the remote_barrier.h file.
    211130 * The code implementting the operations is defined in the remote_barrier.c file.
    212  *********************************************************************************************
     131 ******************************************************************************************
    213132 * @ vaddr     : barrier virtual address in user space == identifier.
    214133 * @ operation : BARRIER_INIT / BARRIER_DESTROY / BARRIER_WAIT.
    215134 * @ count     : number of expected threads (only used by BARRIER_INIT operation).
    216135 * @ return 0 if success / return -1 if failure.
    217  ********************************************************************************************/
     136 *****************************************************************************************/
    218137int sys_barrier( void     * vaddr,
    219138                 uint32_t   operation,
    220139                 uint32_t   count );
    221140
    222 typedef enum
    223 {
    224         BARRIER_INIT,
    225         BARRIER_DESTROY,
    226         BARRIER_WAIT,
    227 }
    228 barrier_operation_t;
    229 
    230 /*********************************************************************************************
     141/******************************************************************************************
    231142 * [9] This function implement all operations on a POSIX mutex.
    232143 * The kernel structure representing a barrier is defined in the remote_barrier.h file.
    233144 * The code implementting the operations is defined in the remote_barrier.c file.
    234  *********************************************************************************************
     145 ******************************************************************************************
    235146 * @ vaddr     : mutex virtual address in user space == identifier.
    236147 * @ operation : MUTEX_INIT / MUTEX_DESTROY / MUTEX_LOCK / MUTEX_UNLOCK
    237148 * @ attr      : mutex attributes (non supported yet => must be 0).
    238149 * @ return 0 if success / return -1 if failure.
    239  ********************************************************************************************/
     150 *****************************************************************************************/
    240151int sys_mutex( void     * vaddr,
    241152               uint32_t   operation,
    242153               uint32_t   count );
    243154
    244 typedef enum
    245 {
    246         MUTEX_INIT,
    247         MUTEX_DESTROY,
    248         MUTEX_LOCK,
    249         MUTEX_UNLOCK,
    250 }
    251 mutex_operation_t;
    252 
    253 /*********************************************************************************************
    254  * [10] This function block the calling thread on the THREAD_BLOCKED_GLOBAL condition,
    255  * and deschedule.
    256  *********************************************************************************************
    257  * @ return 0 if success / returns -1 if failure.
    258  ********************************************************************************************/
    259 int sys_thread_sleep();
    260 
    261 /*********************************************************************************************
    262  * [11] This function unblock the thread identified by its <trdid> from the
    263  * THREAD_BLOCKED_GLOBAL condition.
    264  *********************************************************************************************
    265  * @ trdid  : target thread identifier.
    266  * @ return 0 if success / return -1 if failure.
    267  ********************************************************************************************/
    268 int sys_thread_wakeup();
    269 
    270 /*********************************************************************************************
    271  * [12] This function open or create a file.
    272  *********************************************************************************************
     155/******************************************************************************************
     156 * [10] This slot not allocated yet
     157 ******************************************************************************************
     158 * @ return 0 if success / returns -1 if failure.
     159 *****************************************************************************************/
     160
     161/******************************************************************************************
     162 * [11] This function rmove an existing mapping defined by the <addr> and <size>
     163 * arguments in user space.
     164 ******************************************************************************************
     165 * @ addr  : base address in user space.
     166 * # size  : number of bytes.
     167 * @ return 0 if success / return -1 if failure.
     168 *****************************************************************************************/
     169int sys_munmap( void     * addr,
     170                uint32_t   size );
     171
     172/******************************************************************************************
     173 * [12] This function open or create an open file descriptor.
     174 ******************************************************************************************
    273175 * @ pathname   : pathname (can be relative or absolute).
    274176 * @ flags      : bit vector attributes (see below).
    275177 * @ mode       : access rights.
    276178 * @ return file descriptor index in fd_array if success / return -1 if failure.
    277  ********************************************************************************************/
     179 *****************************************************************************************/
    278180int sys_open( char    * pathname,
    279181              uint32_t  flags,
    280182              uint32_t  mode );
    281183
    282 typedef enum
    283 {
    284     O_RDONLY   = 0x0010000,    /*! open file in read-only mode                              */
    285     O_WRONLY   = 0x0020000,    /*! open file in write-only mode                             */
    286     O_RDWR     = 0x0030000,    /*! open file in read/write mode                             */
    287     O_NONBLOCK = 0x0040000,    /*! do not block if data non available                       */
    288     O_APPEND   = 0x0080000,    /*! append on each write                                     */
    289     O_CREAT    = 0x0100000,    /*! create file if it does not exist                         */
    290     O_TRUNC    = 0x0200000,    /*! file length is forced to 0                               */
    291     O_EXCL     = 0x0400000,    /*! error if VFS_O_CREAT and file exist                      */
    292     O_SYNC         = 0x0800000,    /*! synchronize File System on each write                    */
    293     O_CLOEXEC  = 0x1000000,    /*! set the close-on-exec flag in file descriptor            */
    294     O_DIR      = 0x2000000,    /*! new file descriptor is for a directory                   */
    295 }
    296 open_attributes_t;
    297 
    298 /*********************************************************************************************
    299  * [13] This function creates a new file as specified by the arguments.
    300  * This function is obsolete, you should use open() with 0_CREATE.
    301  *********************************************************************************************
    302  * @ pathname   : pathname (can be relative or absolute).
    303  * @ mode       : access rights.
    304  ********************************************************************************************/
    305 int sys_creat( char     * pathname,
    306                uint32_t   mode );
    307 
    308 /*********************************************************************************************
     184/******************************************************************************************
     185 * [13] This function map physical memory (or a file) in the calling thread virtual space.
     186 * The <attr> argument is a pointer on a structure for arguments (see shared_syscalls.h).
     187 ******************************************************************************************
     188 * @ attr       : pointer on attributes structure.
     189 * @ return 0 if success / return -1 if failure.
     190 *****************************************************************************************/
     191int sys_mmap( mmap_attr_t * attr );
     192
     193/******************************************************************************************
    309194 * [14] This function read bytes from an open file identified by its file descriptor.
    310  * This file can be a regular file or character oriented device.
    311  *********************************************************************************************
     195 * The file can be a regular file or character oriented device.
     196 ******************************************************************************************
    312197 * @ file_id  : open file index in fd_array.
    313198 * @ buf      : buffer virtual address in user space.
    314199 * @ count    : number of bytes.
    315200 * @ return number of bytes actually read if success / returns -1 if failure.
    316  ********************************************************************************************/
     201 *****************************************************************************************/
    317202int sys_read( uint32_t   file_id,
    318203              void     * buf,
    319204              uint32_t   count );
    320205
    321 /*********************************************************************************************
     206/******************************************************************************************
    322207 * [15] This function writes bytes to an open file identified by its file descriptor.
    323  * This file can be a regular file or character oriented device.
    324  *********************************************************************************************
     208 * The file can be a regular file or character oriented device.
     209 ******************************************************************************************
    325210 * @ file_id  : open file index in fd_array.
    326211 * @ buf      : buffer virtual address in user space.
    327212 * @ count    : number of bytes.
    328213 * @ return number of bytes actually written if success / returns -1 if failure.
    329  ********************************************************************************************/
     214 *****************************************************************************************/
    330215int sys_write( uint32_t   file_id,
    331216               void     * buf,
    332217               uint32_t   count );
    333218
    334 /*********************************************************************************************
    335  * [16] This function epositions the offset of the file descriptor identified by <file_id>,
    336  * according to the operation type defined by the <whence> and <offset> arguments.
    337  *********************************************************************************************
     219/******************************************************************************************
     220 * [16] This function repositions the offset of the file descriptor identified by <file_id>,
     221 * according to the operation type defined by the <whence> argument.
     222 ******************************************************************************************
    338223 * @ file_id  : open file index in fd_array.
    339  * @ offset   : buffer virtual address in user space.
     224 * @ offset   : used to compute new offset value.
    340225 * @ whence   : operation type (see below).
    341226 * @ return 0 if success / returns -1 if failure.
    342  ********************************************************************************************/
     227 *****************************************************************************************/
    343228int sys_lseek( xptr_t    file_id,
    344229               uint32_t  offset,
    345230               uint32_t  whence );
    346231
    347 typedef enum
    348 {
    349     SEEK_SET  = 0,     /*! new_offset <= offset                                             */
    350     SEEK_CUR  = 1,     /*! new_offset <= current_offset + offset                            */
    351     SEEK_END  = 2,     /*! new_iffset <= current_size + offset                              */
    352 }
    353 lseek_operation_t;
    354 
    355 /*********************************************************************************************
     232/******************************************************************************************
    356233 * [17] This function release the memory allocated for the file descriptor identified by
    357234 * the <file_id> argument, and remove the fd array_entry in all copies of the process
    358235 * descriptor.
    359  *********************************************************************************************
     236 ******************************************************************************************
    360237  file_id   : file descriptor index in fd_array.
    361238 * @ return 0 if success / returns -1 if failure.
    362  ********************************************************************************************/
     239 *****************************************************************************************/
    363240int sys_close( uint32_t file_id );
    364241
    365 /*********************************************************************************************
    366  * [18] This function removes a directory entry identified by the <pathname> from its
     242/******************************************************************************************
     243 * [18] This function removes a directory entry identified by the <pathname> from the
    367244 * directory, and decrement the link count of the file referenced by the link.
    368245 * If the link count reduces to zero, and no process has the file open, then all resources
     
    370247 * the last link is removed, the link is removed, but the removal of the file is delayed
    371248 * until all references to it have been closed.
    372  *********************************************************************************************
    373  * @ pathname   : pathname (can be relative or absolute).
    374  * @ return 0 if success / returns -1 if failure.
    375  ********************************************************************************************/
     249 ******************************************************************************************
     250 * @ pathname   : pathname (can be relative or absolute).
     251 * @ return 0 if success / returns -1 if failure.
     252 *****************************************************************************************/
    376253int sys_unlink( char * pathname );
    377254
    378 /*********************************************************************************************
     255/******************************************************************************************
    379256 * [19] This function creates in the calling thread cluster an unnamed pipe, and two
    380257 * (read and write) file descriptors.
    381  *********************************************************************************************
     258 * TODO not implemented yet...
     259 ******************************************************************************************
    382260 * @ file_id[0] : [out] read only file descriptor index.
    383261 * @ file_id[1] : [out] write only file descriptor index.
    384262 * @ return 0 if success / return -1 if failure.
    385  ********************************************************************************************/
     263 *****************************************************************************************/
    386264int sys_pipe( uint32_t file_id[2] );
    387265
    388 /*********************************************************************************************
     266/******************************************************************************************
    389267 * [20] This function change the current working directory in reference process descriptor.
    390  *********************************************************************************************
    391  * @ pathname   : pathname (can be relative or absolute).
    392  * @ return 0 if success / returns -1 if failure.
    393  ********************************************************************************************/
     268 ******************************************************************************************
     269 * @ pathname   : pathname (can be relative or absolute).
     270 * @ return 0 if success / returns -1 if failure.
     271 *****************************************************************************************/
    394272int sys_chdir( char * pathname );
    395273
    396 /*********************************************************************************************
     274/******************************************************************************************
    397275 * [21] This function creates a new directory in file system.
    398  *********************************************************************************************
     276 ******************************************************************************************
    399277 * @ pathname   : pathname (can be relative or absolute).
    400278 * @ mode       : access rights (as defined in chmod).
    401279 * @ return 0 if success / returns -1 if failure.
    402  ********************************************************************************************/
     280 *****************************************************************************************/
    403281int sys_mkdir( char    * pathname,
    404282               uint32_t  mode );
    405283
    406 /*********************************************************************************************
     284/******************************************************************************************
    407285 * [22] This function creates a named FIFO file in the calling thread cluster.
    408286 * The associated read and write file descriptors mut be be  explicitely created
    409  * using the sy_open() function.
    410  *********************************************************************************************
     287 * using the sys_open() function.
     288 ******************************************************************************************
    411289 * @ pathname   : pathname (can be relative or absolute).
    412290 * @ mode       : access rights (as defined in chmod).
    413291 * @ return 0 if success / returns -1 if failure.
    414  ********************************************************************************************/
     292 *****************************************************************************************/
    415293int sys_mkfifo( char     * pathname,
    416294                uint32_t   mode );
    417295
    418 /*********************************************************************************************
    419  * [23] This function open a directory, that must exist in the file system.
    420  *********************************************************************************************
    421  * @ pathname   : pathname (can be relative or absolute).
    422  * @ return file descriptor index in fd_array if success / return -1 if failure.
    423  ********************************************************************************************/
    424 int sys_opendir( char * pathname );
    425 
    426 /*********************************************************************************************
    427  * [24] This function returns in the structure pointed by the <dirent> argument various
    428  * information about an entry of the directory identified by the <file_id> argument.
    429  *********************************************************************************************
    430  * @ file_id   : file descriptor index of the searched directory.
    431  * @ dirent    : pointer on a dirent structure in user space.
    432  * @ return 0 if success / returns -1 if failure.
    433  ********************************************************************************************/
    434 int sys_readdir( uint32_t              file_id,
    435                  struct vfs_dirent_s * dirent );
    436 
    437 /*********************************************************************************************
    438  * [25] This function close the file descriptor previouly open by the opendir() function.
    439  *********************************************************************************************
    440  * @ file_id   : file descriptor index of the searched directory.
    441  * @ return 0 if success / returns -1 if failure.
    442  ********************************************************************************************/
    443 int sys_closedir( uint32_t file_id );
    444 
    445 /*********************************************************************************************
     296/******************************************************************************************
     297 * [23] This function open a directory, that must exist in the file system, returning
     298 * a DIR pointer on the directory in user space.
     299 ******************************************************************************************
     300 * @ pathname   : pathname (can be relative or absolute).
     301 * @ dirp       : [out] buffer for pointer on user directory (DIR).
     302 * @ return 0 if success / returns -1 if failure.
     303 *****************************************************************************************/
     304int sys_opendir( char * pathname,
     305                 DIR ** dirp );
     306
     307/******************************************************************************************
     308 * [24] This function returns an user pointer on the dirent structure describing the
     309 * next directory entry in the directory identified by the <dirp> argument.
     310 ******************************************************************************************
     311 * @ dirp     : user pointer identifying the searched directory.
     312 * @ dentp    : [out] buffer for pointer on user direntory entry (dirent).
     313 * @ return O if success / returns -1 if failure.
     314 *****************************************************************************************/
     315int sys_readdir( DIR            * dirp,
     316                 struct dirent ** dentp );
     317
     318/******************************************************************************************
     319 * [25] This function closes the directory identified by the <dirp> argument, and releases
     320 * all structures associated with the <dirp> pointer.
     321 ******************************************************************************************
     322 * @ dirp     : user pointer identifying the directory.
     323 * @ return 0 if success / returns -1 if failure.
     324 *****************************************************************************************/
     325int sys_closedir( DIR * dirp );
     326
     327/******************************************************************************************
    446328 * [26] This function returns the pathname of the current working directory.
    447  *********************************************************************************************
     329 ******************************************************************************************
    448330 * buf     : buffer addres in user space.
    449331 * nbytes  : user buffer size in bytes.
    450332 * @ return 0 if success / returns -1 if failure.
    451  ********************************************************************************************/
     333 *****************************************************************************************/
    452334int sys_getcwd( char     * buf,
    453335                uint32_t   nbytes );
    454336
    455 /*********************************************************************************************
    456  * [27] This function returns in a 64 bits user buffer the calling core cycles count.
    457  * It uses both the hardware register and the core descriptor cycles count tos take
    458  * into account a possible harware register overflow  in 32 bits architectures.
    459  *********************************************************************************************
    460  * cyles    : [out] address of buffer in user space.
    461  ********************************************************************************************/
    462 int sys_clock( uint64_t * cycles );
    463 
    464 /*********************************************************************************************
     337/******************************************************************************************
     338 * [27] This slot is not used.
     339 *****************************************************************************************/
     340
     341/******************************************************************************************
    465342 * [28] This function forces the calling thread to sleep, for a fixed number of cycles.
    466  *********************************************************************************************
     343 ******************************************************************************************
    467344 * cycles   : number of cycles.
    468  ********************************************************************************************/
     345 *****************************************************************************************/
    469346int sys_alarm( uint32_t cycles );
    470347
    471 /*********************************************************************************************
    472  * [29] This undefined function does nothing.
    473  *********************************************************************************************
    474  * @ pathname   : pathname (can be relative or absolute).
    475  * @ return 0 if success / returns -1 if failure.
    476  ********************************************************************************************/
     348/******************************************************************************************
     349 * [29] This function removes a directory file whose name is given by <pathname>.
     350 * The directory must not have any entries other than `.' and `..'.
     351 ******************************************************************************************
     352 * @ pathname   : pathname (can be relative or absolute).
     353 * @ return 0 if success / returns -1 if failure.
     354 *****************************************************************************************/
    477355int sys_rmdir( char * pathname );
    478356
    479 /*********************************************************************************************
     357/******************************************************************************************
    480358 * [30] This function implement the operations related to User Thread Local Storage.
    481359 * It is actually implemented as an uint32_t variable in the thread descriptor.
    482  *********************************************************************************************
     360 ******************************************************************************************
    483361 * @ operation  : UTLS operation type as defined below.
    484362 * @ value      : argument value for the UTLS_SET operation.
    485363 * @ return value for the UTLS_GET and UTLS_GET_ERRNO / return -1 if failure.
    486  ********************************************************************************************/
     364 *****************************************************************************************/
    487365int sys_utls( uint32_t operation,
    488366              uint32_t value );
    489367
    490 typedef enum
    491 {
    492     UTLS_SET       = 1,
    493     UTLS_GET       = 2,
    494     UTLS_GET_ERRNO = 3,
    495 }
    496 utls_operation_t;
    497 
    498 /*********************************************************************************************
     368/******************************************************************************************
    499369 * [31] This function change the acces rights for the file/dir identified by the
    500370 * pathname argument.
    501  *********************************************************************************************
     371 ******************************************************************************************
    502372 * @ pathname   : pathname (can be relative or absolute).
    503373 * @ rights     : acces rights.
    504374 * @ return 0 if success / returns -1 if failure.
    505  ********************************************************************************************/
     375 *****************************************************************************************/
    506376int sys_chmod( char     * pathname,
    507377               uint32_t   rights );
    508378
    509 /*********************************************************************************************
     379/******************************************************************************************
    510380 * [32] This function associate a specific signal handler to a given signal type.
    511381 * Tee handlers for the SIGKILL and SIGSTOP signals cannot be redefined.
    512  *********************************************************************************************
     382 ******************************************************************************************
    513383 * @ sig_id    : index defining signal type (from 1 to 31).
    514384 * @ handler   : pointer on fonction implementing the specific handler.
    515385 * @ return 0 if success / returns -1 if failure.
    516  ********************************************************************************************/
     386 *****************************************************************************************/
    517387int sys_signal( uint32_t   sig_id,
    518388                void     * handler );
    519389
    520 /*********************************************************************************************
     390/******************************************************************************************
    521391 * [33] This function returns in the structure <tv>, defined in the time.h file,
    522392 * the current time (in seconds & micro-seconds).
    523393 * It is computed from the calling core descriptor.
    524394 * The timezone is not supported.
    525  *********************************************************************************************
     395 ******************************************************************************************
    526396 * @ tv      : pointer on the timeval structure.
    527397 * @ tz      : pointer on the timezone structure : must be NULL.       
    528398 * @ return 0 if success / returns -1 if failure.
    529  ********************************************************************************************/
     399 *****************************************************************************************/
    530400int sys_timeofday( struct timeval  * tv,
    531401                   struct timezone * tz );
    532402
    533 /*********************************************************************************************
     403/******************************************************************************************
    534404 * [34] This function implements the "kill" system call.
    535405 * It register the signal defined by the <sig_id> argument in all thread descriptors
     
    537407 * containing threads for the target process.
    538408 * It can be executed by any thread running in any cluster, as this function uses
    539  * remote access to traverse the list of process copies in the owner cluster,
     409 * remote access to traverse the list of process copies stored in the owner cluster,
    540410 * and the RPC_SIGNAL_RISE to signal the remote threads.
    541  *********************************************************************************************
     411 ******************************************************************************************
    542412 * @ pid      : target process identifier.
    543413 * @ sig_id   : index defining the signal type (from 1 to 31).
    544414 * @ return 0 if success / returns -1 if failure.
    545  ********************************************************************************************/
     415 *****************************************************************************************/
    546416int sys_kill( pid_t    pid,
    547417              uint32_t sig_id );
    548418
    549 /*********************************************************************************************
     419/******************************************************************************************
    550420 * [35] This function implements the "getpid" system call.
    551  *********************************************************************************************
    552  * @ returns the PID for the calling thread.
    553  ********************************************************************************************/
     421 ******************************************************************************************
     422 * @ returns the process PID for the calling thread.
     423 *****************************************************************************************/
    554424int sys_getpid();
    555425
    556 /*********************************************************************************************
     426/******************************************************************************************
    557427 * [36] This function implement the "fork" system call.
    558428 * The calling process descriptor (parent process), and the associated thread descriptor are
     
    560430 * is registered in another target cluster, that is the new process owner.
    561431 * The child process and the associated main thread will be migrated to the target cluster
    562  * later, when the child process makes an "exec" or any other system call. 
     432 * later, when the child process makes an "exec" or any other system call... TODO [AG]
    563433 * The target cluster depends on the "fork_user" flag and "fork_cxy" variable that can be
    564434 * stored in the calling thread descriptor by the specific fork_place() system call.
    565435 * If not, the sys_fork() function makes a query to the DQDT to select the target cluster.
    566  *********************************************************************************************
    567  * @ returns child process PID if success / returns -1 if failure
    568  ********************************************************************************************/
     436 ******************************************************************************************
     437 * @ if success, returns child process PID to parent, and return O to child.
     438 * @ if failure, returns -1 to parent / no child process is created.
     439 *****************************************************************************************/
    569440int sys_fork();
    570441
    571 /*********************************************************************************************
    572  * [37] This function implement the "exec" system call.
    573  * It is executed in the client cluster, but the new process descriptor and main thread
    574  * must be created in a server cluster, that is generally another cluster.
    575  * - if the server_cluster is the client cluster, call directly the process_make_exec()
     442/******************************************************************************************
     443 * [37] This function implement the "exec" system call, that creates a new process
     444 * descriptor.
     445 * It is executed in the client cluster, but the new process descriptor and the main
     446 * thread are created in a server cluster, that is generally another cluster.
     447 * - if the server_cluster is the client cluster, it calls directly the process_make_exec()
    576448 *   function to create a new process, and launch a new thread in local cluster.
    577  * - if the target_cluster is remote, call rpc_process_exec_client() to execute the
    578  *   process_make_exec() on the remote cluster.
     449 * - if the target_cluster is remote, it calls the rpc_process_exec_client() to execute
     450 *   process_signedmake_exec() on the remote cluster.
    579451 * In both case this function build an exec_info_t structure containing all informations
    580452 * required to build the new process descriptor and the associated thread.
    581453 * Finally, the calling process and thread are deleted.
    582  *********************************************************************************************
    583  * @ filename : string pointer on .elf filename (virtual pointer in user space)
    584  * @ argv     : array of strings on process arguments (virtual pointers in user space)
    585  * @ envp     : array of strings on Renvironment variables (virtual pointers in user space)
     454 ******************************************************************************************
     455 * @ filename : string pointer on .elf filename (pointer in user space)
     456 * @ argv     : array of strings on process arguments (pointers in user space)
     457 * @ envp     : array of strings on environment variables (pointers in user space)
    586458 * @ returns O if success / returns -1 if failure.
    587  ********************************************************************************************/
     459 *****************************************************************************************/
    588460int sys_exec( char  * filename,
    589461              char ** argv,
    590462              char ** envp );
    591463
    592 /*********************************************************************************************
    593  * [38] This function  returns in the <stat> structure, defined in the vfs.h file,
    594  * various informations on the file/directory identified by the <file_id> argument.
    595  *********************************************************************************************
    596  * @ file_id   : file descriptor index in fd_array.
    597  * @ stat      : pointer on the stat structure.
     464/******************************************************************************************
     465 * [38] This function  returns in the <stat> structure, defined in the "shared_syscalls.h"
     466 * file, various informations on the file/directory identified by the <pathname> argument.
     467 ******************************************************************************************
     468 * @ pathname  : user pointer on file pathname.
     469 * @ stat      : user pointer on the stat structure.
    598470 * @ returns O if success / returns -1 if failure.
    599  ********************************************************************************************/
    600 int sys_stat( uint32_t            file_id,
    601               struct vfs_stat_s * stat );
    602 
    603 /*********************************************************************************************
    604  * [39] This function is used to activate / desactivate Rthe trace for a thread
     471 *****************************************************************************************/
     472int sys_stat( const char  * pathname,
     473              struct stat * stat );
     474
     475/******************************************************************************************
     476 * [39] This non-standard function is used to activate / desactivate the trace for a thread
    605477 * identified by the <trdid> and <pid> arguments.
    606  * It can be called by any other thread.
    607  *********************************************************************************************
     478 * It can be called by any other thread in the same process.
     479 ******************************************************************************************
    608480 * @ operation  : operation type as defined below.
    609481 * @ pid        : process identifier.
    610482 * @ trdid      : thread identifier.
    611483 * @ returns O if success / returns -1 if failure.
    612  ********************************************************************************************/
     484 *****************************************************************************************/
    613485int sys_trace( uint32_t operation,
    614486               pid_t    pid,
    615487               uint32_t trdid );
    616488
    617 typedef enum
    618 {
    619     TRACE_ON       = 0,
    620     TRACE_OFF      = 1,
    621 }
    622 trace_operation_t;
     489/******************************************************************************************
     490 * [40] This function returns the hardware platform parameters.
     491 ******************************************************************************************
     492 * @ x_size   : [out] number of clusters in a row.
     493 * @ y_size   : [out] number of clusters in a column.
     494 * @ ncores   : [out] number of cores per cluster.
     495 * @ return 0 if success / return -1 if illegal arguments
     496 *****************************************************************************************/
     497int sys_get_config( uint32_t * x_size,
     498                    uint32_t * y_size,
     499                    uint32_t * ncores );
     500
     501/******************************************************************************************
     502 * [41] This function returns the calling core cluster and local index.
     503 ******************************************************************************************
     504 * @ cxy      : [out] cluster identifier (fixed format)
     505 * @ lid      : [out] core local index in cluster.
     506 * @ return 0 if success / return -1 if illegal arguments
     507 *****************************************************************************************/
     508int sys_get_core( uint32_t * cxy,
     509                  uint32_t * lid );
     510
     511/******************************************************************************************
     512 * [42] This function returns in a 64 bits user buffer the calling core cycles count.
     513 * It uses both the hardware register and the core descriptor cycles count to take
     514 * into account a possible harware register overflow  in 32 bits architectures.
     515 ******************************************************************************************
     516 * cycle    : [out] address of buffer in user space.
     517 * @ return 0 if success / return -1 if illegal arguments
     518 *****************************************************************************************/
     519int sys_get_cycle( uint64_t * cycle );
     520
     521/******************************************************************************************
     522 * [43] This debug function displays on the kernel terminal the current state of a
     523 * scheduler identified by the <cxy> and <lid> arguments.
     524 ******************************************************************************************
     525 * cxy      : [in] target cluster identifier.
     526 * lid      : [in] target core local index.
     527 * @ return 0 if success / return -1 if illegal arguments
     528 *****************************************************************************************/
     529int sys_get_sched( uint32_t  cxy,
     530                   uint32_t  lid );
     531
     532/******************************************************************************************
     533 * [44] This debug function requires the kernel to display on the kernel terminal a message
     534 * containing the thread / process / core identifiers, and the cause of panic,
     535 * as defined by the <string> argument.
     536 ******************************************************************************************
     537 * string   : [in] message to be displayed.
     538 * @ return always 0.
     539 *****************************************************************************************/
     540int sys_panic( char * string );
     541
     542/******************************************************************************************
     543 * [45] This function block the calling thread on the THREAD_BLOCKED_GLOBAL condition,
     544 * and deschedule.
     545 ******************************************************************************************
     546 * @ return 0 if success / returns -1 if failure.
     547 *****************************************************************************************/
     548int sys_thread_sleep();
     549
     550/******************************************************************************************
     551 * [46] This function unblock the thread identified by its <trdid> from the
     552 * THREAD_BLOCKED_GLOBAL condition.
     553 ******************************************************************************************
     554 * @ trdid  : target thread identifier.
     555 * @ return 0 if success / return -1 if failure.
     556 *****************************************************************************************/
     557int sys_thread_wakeup();
    623558
    624559
Note: See TracChangeset for help on using the changeset viewer.