Changeset 457 for trunk/kernel/syscalls


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

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

Location:
trunk/kernel/syscalls
Files:
50 edited

Legend:

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

    r445 r457  
    2929 ******************************************************************************************/
    3030
    31 typedef unsigned int      sem_t;
    3231typedef unsigned int      pthread_cond_t;
    3332typedef unsigned int      pthread_condattr_t;
     
    5655    PT_ATTR_CORE_DEFINED    = 0x0004,  /*! user defined core index in cluster             */
    5756};
    58 
    59 /*******************************************************************************************
    60  * This enum defines the operation mnemonics for operations on POSIX unnamed semaphores.
    61  ******************************************************************************************/
    62 
    63 typedef enum
    64 {
    65         SEM_INIT,
    66         SEM_DESTROY,
    67         SEM_GETVALUE,
    68         SEM_WAIT,
    69         SEM_POST,
    70 }
    71 sem_operation_t;
    7257
    7358/*******************************************************************************************
  • trunk/kernel/syscalls/shared_include/syscalls_numbers.h

    r444 r457  
    6262    SYS_TRACE          = 47,
    6363    SYS_FG             = 48,
    64     SYS_UNDEFINED_49   = 49,   ///
     64    SYS_IS_FG          = 49,
    6565
    6666        SYSCALLS_NR        = 50,
  • trunk/kernel/syscalls/sys_alarm.c

    r23 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <thread.h>
    2626#include <printk.h>
  • trunk/kernel/syscalls/sys_barrier.c

    r440 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_special.h>
    2626#include <errno.h>
  • trunk/kernel/syscalls/sys_chdir.c

    r407 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_uspace.h>
    2626#include <chdev.h>
  • trunk/kernel/syscalls/sys_chmod.c

    r407 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_uspace.h>
    2626#include <vfs.h>
  • trunk/kernel/syscalls/sys_close.c

    r124 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_special.h>
    2727#include <vfs.h>
  • trunk/kernel/syscalls/sys_closedir.c

    r407 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <vfs.h>
    2626#include <printk.h>
  • trunk/kernel/syscalls/sys_condvar.c

    r440 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_special.h>
    2626#include <errno.h>
  • trunk/kernel/syscalls/sys_creat.c

    r407 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <vfs.h>
    2626#include <syscalls.h>
  • trunk/kernel/syscalls/sys_display.c

    r450 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_uspace.h>
    2626#include <errno.h>
  • trunk/kernel/syscalls/sys_exec.c

    r441 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_uspace.h>
    2727#include <errno.h>
     
    152152// It build an exec_info_t structure containing all informations
    153153// required to initialize the new process descriptor and the associated thread.
    154 // It includes the process main() arguments, the environment variables,
     154// It includes the new process main() arguments, the environment variables,
    155155// and the pathname to the new process .elf file.
    156156// It calls the process_exec_get_strings() functions to copy the main() arguments and
    157157// the environment variables from user buffers to the exec_info_t structure, allocate
    158158// and call the process_make_exec() function.
    159 // As it must destroy all parent process copies, and all parent threads in all clusters,
    160 // the process_make_exec() function must be executed in the parent owner cluster,
    161 // and this sys_exec() function uses a RPC to access the owner cluster if required.
     159// As it must destroy all process copies, and all othert threads in all clusters,
     160// the process_make_exec() function must be executed in the owner cluster.
    162161//
    163162// TODO : the args & envs arguments are not supported yet : both must be NULL  [AG]
     
    187186    "args not supported yet\n" );
    188187
    189     // get owner cluster
    190 
    191188    // check pathname length
    192189    if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH )
     
    205202#if DEBUG_SYS_EXEC
    206203uint64_t      tm_start;
    207 uint64_t      tm_end;
    208204tm_start = hal_get_cycles();
    209205if( DEBUG_SYS_EXEC < tm_start )
    210206printk("\n[DBG] %s : thread %x in process %x enter for path <%s> / cycle = %d\n",
    211 __FUNCTION__, this, pid, exec_info.path, (uint32_t)tm_start );
     207__FUNCTION__, this->trdid, pid, exec_info.path, (uint32_t)tm_start );
    212208#endif
    213209
     
    220216#if DEBUG_SYSCALLS_ERROR
    221217printk("\n[ERROR] in %s : thread %x in process %x cannot access args\n",
    222 __FUNCTION__ , this, pid );
     218__FUNCTION__ , this->trdid, pid );
    223219#endif
    224220            this->errno = EINVAL;
     
    235231#if DEBUG_SYCALLS_ERROR
    236232printk("\n[ERROR] in %s : thread %x in process %x cannot access envs\n",
    237 __FUNCTION__ , this, pid );
     233__FUNCTION__ , this->trdid, pid );
    238234#endif
    239235            this->errno = EINVAL;
     
    250246#if DEBUG_SYSCALLS_ERROR
    251247printk("\n[ERROR] in %s : thread %x in process %x cannot create process for <%s>\n",
    252 __FUNCTION__, this, pid, exec_info.path );
     248__FUNCTION__, this->trdid, pid, exec_info.path );
    253249#endif
    254250        this->errno = error;
     
    256252    }
    257253
    258 #if DEBUG_SYS_EXEC
    259 tm_end = hal_get_cycles();
    260 if( DEBUG_SYS_EXEC < tm_end )
    261 printk("\n[DBG] %s : thread %x in process %x exit / cost = %d / cycle %d\n",
    262 __FUNCTION__, this, pid, (uint32_t)(tm_end - tm_start), (uint32_t)tm_end );
    263 #endif
    264 
    265     // In case of success, this calling thread deschedules, causing suicide,
    266     // because a new process descriptor and its associated main thread
    267     // have been created by the process_make_exec() function, and the
    268     // BLOCKED_GLOBAL & FLAG_REQ_DELETE bits have been set for the calling thread.
    269     sched_yield( "old process suicide in sys_exec()" );
     254    assert( false , __FUNCTION__, "we should not execute this code" );
    270255
    271256    return 0; 
  • trunk/kernel/syscalls/sys_exit.c

    r446 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_irqmask.h>
    2727#include <errno.h>
     
    5959tm_start = hal_get_cycles();
    6060if( DEBUG_SYS_EXIT < tm_start )
    61 printk("\n[DBG] %s : thread %x enter / process %x / status %x / cycle %d\n",
    62 __FUNCTION__ , this, pid , status , (uint32_t)tm_start );
     61printk("\n[DBG] %s : thread %x in process %x enter / status %x / cycle %d\n",
     62__FUNCTION__, this->trdid, process->pid , status , (uint32_t)tm_start );
    6363#endif
    6464
     
    7070#if (DEBUG_SYS_EXIT & 1)
    7171if( DEBUG_SYS_EXIT < tm_start )
    72 printk("\n[DBG] %s : thread %x get owner process %x in cluster %x\n",
    73 __FUNCTION__ , this, owner_ptr, owner_cxy );
     72printk("\n[DBG] %s : thread %x in process %x get owner process %x in cluster %x\n",
     73__FUNCTION__, this->trdid, process->pid, owner_ptr, owner_cxy );
    7474#endif
    7575
    76     // get pointer on the process main thread
     76    // get local pointer on the process main thread
    7777    main_ptr  = hal_remote_lpt( XPTR( owner_cxy , &owner_ptr->th_tbl[0] ) );
    7878
     
    8484#if (DEBUG_SYS_EXIT & 1)
    8585if( DEBUG_SYS_EXIT < tm_start )
    86 printk("\n[DBG] %s : thread %x get parent process %x in cluster %x\n",
    87 __FUNCTION__ , this, parent_ptr, parent_cxy );
     86printk("\n[DBG] %s : thread %x in process %x get parent process %x in cluster %x\n",
     87__FUNCTION__, this->trdid, process->pid, parent_ptr, parent_cxy );
    8888#endif
    8989
     
    9999
    100100#if( DEBUG_SYS_EXIT & 1)
    101 if( tm_start > DEBUG_SYS_EXIT )
    102 printk("\n[DBG] %s : thread %x removed process %x from TXT list\n",
    103 __FUNCTION__ , this, pid );
     101if( DEBUG_SYS_EXIT < tm_start )
     102printk("\n[DBG] %s : thread %x in process %x detached process from TXT\n",
     103__FUNCTION__, this->trdid, process->pid );
    104104#endif
    105105
     
    107107    // but the main thread and this calling thread
    108108    hal_enable_irq( &save_sr );
    109     process_sigaction( pid , DELETE_ALL_THREADS );
     109    process_sigaction( process->pid , DELETE_ALL_THREADS );
    110110    hal_restore_irq( save_sr );
    111111
    112112#if( DEBUG_SYS_EXIT & 1)
    113 if( tm_start > DEBUG_SYS_EXIT )
    114 printk("\n[DBG] %s : thread %x deleted threads for process %x\n",
    115 __FUNCTION__ , this, pid );
     113if( DEBUG_SYS_EXIT < tm_start )
     114printk("\n[DBG] %s : thread %x in process %x deleted all threads but itself\n",
     115__FUNCTION__, this->trdid, process->pid );
    116116#endif
    117117
     
    122122#if( DEBUG_SYS_EXIT & 1)
    123123if( tm_start > DEBUG_SYS_EXIT )
    124 printk("\n[DBG] %s : calling thread %x marked iself for delete in process %x\n",
    125 __FUNCTION__ , this, pid );
     124printk("\n[DBG] %s : thread %x in process %x marked iself for delete\n",
     125__FUNCTION__, this->trdid, process->pid );
    126126#endif
    127127        thread_delete( XPTR( local_cxy , this ) , pid , true );
     
    133133#if( DEBUG_SYS_EXIT & 1)
    134134if( tm_start > DEBUG_SYS_EXIT )
    135 printk("\n[DBG] %s : thread %x blocked main thread for process %x\n",
    136 __FUNCTION__, this , pid );
     135printk("\n[DBG] %s : thread %x in process %x blocked main thread\n",
     136__FUNCTION__, this->trdid, process->pid );
    137137#endif
    138138
     
    144144#if( DEBUG_SYS_EXIT & 1)
    145145if( tm_start > DEBUG_SYS_EXIT )
    146 printk("\n[DBG] %s : thread %x set exit status in process %x / term_state %x\n",
    147 __FUNCTION__ , this, pid, term_state );
     146printk("\n[DBG] %s : thread %x in process %x set exit status %x in owner process\n",
     147__FUNCTION__, this->trdid, process->pid, term_state );
    148148#endif
    149149
    150     // take the children lock and unblock the parent process main thread
     150    // unblock the parent process main thread
    151151    remote_spinlock_lock( children_lock_xp );
    152152    thread_unblock( parent_main_xp , THREAD_BLOCKED_WAIT );
     
    155155#if( DEBUG_SYS_EXIT & 1)
    156156if( tm_start > DEBUG_SYS_EXIT )
    157 printk("\n[DBG] %s : thread %x in cluster %x unblock parent main thread %x in cluster %x\n",
    158 __FUNCTION__ , this, local_cxy, parent_main_ptr, parent_cxy );
     157printk("\n[DBG] %s : thread %x in process %x unblock parent main thread in process %x\n",
     158__FUNCTION__ , this->trdid, process->pid,
     159hal_remote_lw( XPTR( parent_cxy , &parent_ptr->pid) ) );
    159160#endif
    160161
     
    164165tm_end = hal_get_cycles();
    165166if( DEBUG_SYS_EXIT < tm_end )
    166 printk("\n[DBG] %s : thread %x exit / process %x / status %x / cost = %d / cycle %d\n",
    167 __FUNCTION__, this, pid, status, (uint32_t)(tm_end - tm_start), (uint32_t)tm_end );
     167printk("\n[DBG] %s : thread %x in process %x exit / status %x / cost = %d / cycle %d\n",
     168__FUNCTION__, this->trdid, process->pid, status,
     169(uint32_t)(tm_end - tm_start), (uint32_t)tm_end );
    168170#endif
    169171
  • trunk/kernel/syscalls/sys_fg.c

    r446 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_irqmask.h>
    2727#include <errno.h>
  • trunk/kernel/syscalls/sys_fork.c

    r440 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_context.h>
    2727#include <hal_switch.h>
     
    7070tm_start = hal_get_cycles();
    7171if( DEBUG_SYS_FORK < tm_start )
    72 printk("\n[DBG] %s : parent_thread %x enter / parent_pid %x / cycle =  %d\n",
    73 __FUNCTION__, parent_thread_ptr, parent_pid, (uint32_t)tm_start );
     72printk("\n[DBG] %s : thread %x in process %x enter / cycle =  %d\n",
     73__FUNCTION__, parent_thread_ptr->trdid, parent_pid, (uint32_t)tm_start );
    7474#endif
    7575
     
    106106#if (DEBUG_SYS_FORK & 1 )
    107107if( DEBUG_SYS_FORK < tm_start )
    108 printk("\n[DBG] %s : parent_thread %x selected cluster %x\n",
    109 __FUNCTION__, parent_thread_ptr, child_cxy );
     108printk("\n[DBG] %s : thread %x in process %x selected cluster %x\n",
     109__FUNCTION__, parent_thread_ptr->trdid, parent_pid, child_cxy );
    110110#endif
    111111
     
    165165tm_end = hal_get_cycles();
    166166if( DEBUG_SYS_FORK < tm_end )
    167 printk("\n[DBG] %s : parent_thread %x on cluster %x exit / cost = %d / cycle %d\n",
    168 __FUNCTION__, parent_thread_ptr, parent_cxy, (uint32_t)(tm_end - tm_start), (uint32_t)tm_end );
     167printk("\n[DBG] %s : process %x exit / cost = %d / cycle %d\n",
     168__FUNCTION__, parent_pid, (uint32_t)(tm_end - tm_start), (uint32_t)tm_end );
    169169#endif
    170 
    171170        return child_pid;
    172171    }
     
    177176tm_end = hal_get_cycles();
    178177if( DEBUG_SYS_FORK < tm_end )
    179 printk("\n[DBG] %s : child_thread %x on cluster %x exit / cost = %d / cycle %d\n",
    180 __FUNCTION__, child_thread_ptr, child_cxy, (uint32_t)(tm_end - tm_start), (uint32_t)tm_end );
     178printk("\n[DBG] %s : process %x exit / cost = %d / cycle %d\n",
     179__FUNCTION__, child_pid, (uint32_t)(tm_end - tm_start), (uint32_t)tm_end );
    181180#endif
    182 
    183181        return 0;
    184182    }
  • trunk/kernel/syscalls/sys_get_config.c

    r440 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_uspace.h>
    2626#include <hal_special.h>
  • trunk/kernel/syscalls/sys_get_core.c

    r440 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_uspace.h>
    2626#include <hal_special.h>
  • trunk/kernel/syscalls/sys_get_cycle.c

    r440 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_uspace.h>
    2626#include <hal_special.h>
  • trunk/kernel/syscalls/sys_getcwd.c

    r440 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_uspace.h>
    2727#include <hal_special.h>
  • trunk/kernel/syscalls/sys_isatty.c

    r438 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_uspace.h>
    2727#include <hal_irqmask.h>
  • trunk/kernel/syscalls/sys_kill.c

    r448 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_irqmask.h>
    2727#include <errno.h>
  • trunk/kernel/syscalls/sys_lseek.c

    r23 r457  
    2222
    2323#include <kernel_config.h>
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_uspace.h>
    2626#include <errno.h>
  • trunk/kernel/syscalls/sys_mkdir.c

    r407 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_uspace.h>
    2626#include <vfs.h>
  • trunk/kernel/syscalls/sys_mkfifo.c

    r407 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_uspace.h>
    2626#include <printk.h>
  • trunk/kernel/syscalls/sys_mmap.c

    r440 r457  
    2323 */
    2424
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_uspace.h>
    2727#include <hal_irqmask.h>
  • trunk/kernel/syscalls/sys_munmap.c

    r438 r457  
    2323 */
    2424
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_uspace.h>
    2727#include <shared_syscalls.h>
  • trunk/kernel/syscalls/sys_mutex.c

    r440 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_special.h>
    2626#include <errno.h>
  • trunk/kernel/syscalls/sys_open.c

    r407 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_uspace.h>
    2727#include <errno.h>
  • trunk/kernel/syscalls/sys_opendir.c

    r407 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <thread.h>
    2626#include <process.h>
  • trunk/kernel/syscalls/sys_pipe.c

    r407 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <vfs.h>
    2626#include <process.h>
  • trunk/kernel/syscalls/sys_read.c

    r450 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_uspace.h>
    2727#include <hal_irqmask.h>
  • trunk/kernel/syscalls/sys_readdir.c

    r407 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_uspace.h>
    2727#include <errno.h>
  • trunk/kernel/syscalls/sys_rmdir.c

    r407 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_uspace.h>
    2626#include <printk.h>
  • trunk/kernel/syscalls/sys_sem.c

    r440 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_uspace.h>
     26#include <shared_semaphore.h>
    2627#include <errno.h>
    2728#include <thread.h>
     
    3132#include <syscalls.h>
    3233
     34#if DEBUG_SYS_SEM
     35//////////////////////////////////////////////////
     36static char * sys_sem_op_str( uint32_t operation )
     37{
     38        if     ( operation == SEM_INIT     ) return "INIT";
     39        else if( operation == SEM_WAIT     ) return "WAIT";
     40        else if( operation == SEM_POST     ) return "POST";
     41        else if( operation == SEM_GETVALUE ) return "GETVALUE";
     42        else if( operation == SEM_DESTROY  ) return "DESTROY";
     43        else                                 return "undefined";
     44}
     45#endif
     46
    3347//////////////////////////////////
    34 int sys_sem( void         * vaddr,        // semaphore virtual  address
    35              uint32_t       operation,    // requested operation type
    36              uint32_t     * value )       // pointer on in/out argument
     48int sys_sem( void         * vaddr,            // semaphore virtual  address
     49             uint32_t       operation,        // requested operation type
     50             uint32_t       init_value,       // initial value
     51             uint32_t     * current_value )   // pointer on current value buffer
    3752{
    38         uint32_t         data;   
    3953        vseg_t         * vseg;
    4054    error_t          error;
     55    uint32_t         current;     // semaphore current value
     56    xptr_t           sem_xp;      // extended pointer on semaphore
    4157
    4258    thread_t       * this    = CURRENT_THREAD;
    4359    process_t      * process = this->process;
     60
     61#if DEBUG_SYS_SEM
     62uint64_t    tm_start;
     63uint64_t    tm_end;
     64tm_start = hal_get_cycles();
     65if( DEBUG_SYS_SEM < tm_start )
     66printk("\n[DBG] %s : thread %x in process %x enter for %s / cycle %d\n",
     67__FUNCTION__, this->trdid, process->pid, sys_sem_op_str( operation ), (uint32_t)tm_start );
     68#endif
    4469
    4570    // check vaddr in user vspace
     
    4974
    5075#if DEBUG_SYSCALLS_ERROR
    51 printk("\n[ERROR] in %s : unmapped semaphore %x / thread %x / process %x\n",
    52 __FUNCTION__ , (intptr_t)vaddr, this->trdid, process->pid );
    53 vmm_display( process , false );
    54 #endif
    55         this->errno = EINVAL;
    56         return -1;
    57     }
    58 
    59     // check value in user vspace
    60         error = vmm_get_vseg( process , (intptr_t)value , &vseg );
    61         if( error )
    62     {
    63 
    64 #if DEBUG_SYSCALLS_ERROR
    65 printk("\n[ERROR] in %s : unmapped value %x / thread %x / process %x\n",
     76printk("\n[ERROR] in %s : unmapped semaphore pointer %x / thread %x in process %x\n",
    6677__FUNCTION__ , (intptr_t)vaddr, this->trdid, process->pid );
    6778vmm_display( process , false );
     
    7788            case SEM_INIT:
    7889        {
    79             // get argument
    80                     hal_copy_from_uspace( &data , value , sizeof(uint32_t) );
    81 
    82             // call init function
    83             error = remote_sem_create( (intptr_t)vaddr , data );
     90            // call relevant kernel function to initialize semaphore
     91            error = remote_sem_create( (intptr_t)vaddr ,
     92                                       init_value,
     93                                       XPTR( local_cxy , &sem_xp ) );
    8494
    8595            if ( error )
    8696            {
    87                 printk("\n[ERROR] in %s : cannot create semaphore = %x\n",
    88                        __FUNCTION__ , (intptr_t)value );
    89                 this->errno = error;
    90                 return -1;
    91             }
     97
     98#if DEBUG_SYSCALLS_ERROR
     99printk("\n[ERROR] in %s : cannot create semaphore / thread %x in process %x\n",
     100__FUNCTION__, this->trdid, process->pid );
     101#endif
     102                this->errno = ENOMEM;
     103                return -1;
     104            }
     105
    92106            break;
    93107        }
     
    95109        case SEM_GETVALUE:
    96110        {
    97             // get extended pointer on remote semaphore
    98             xptr_t sem_xp = remote_sem_from_vaddr( (intptr_t)vaddr );
    99 
    100             if( sem_xp == XPTR_NULL )     // user error
    101             {
    102 
    103 #if DEBUG_SYSCALLS_ERROR
    104 printk("\n[ERROR] in %s : semaphore %x not registered / thread %x / process %x\n",
    105 __FUNCTION__ , (intptr_t)value, this->trdid, process->pid );
    106 #endif
    107                 this->errno = EINVAL;
    108                 return -1;
    109             }
    110             else                          // success
    111             {
    112                 // get semaphore current value
    113                         remote_sem_get_value( sem_xp , &data );
     111            // check current_value buffer in user vspace
     112                error = vmm_get_vseg( process , (intptr_t)current_value , &vseg );
     113            if( error )
     114            {
     115
     116#if DEBUG_SYSCALLS_ERROR
     117printk("\n[ERROR] in %s : unmapped buffer for current value %x / thread %x in process %x\n",
     118__FUNCTION__ , (intptr_t)current_value, this->trdid, process->pid );
     119vmm_display( process , false );
     120#endif
     121                this->errno = EINVAL;
     122                return -1;
     123            }
     124
     125            // get extended pointer on remote semaphore
     126            sem_xp = remote_sem_from_vaddr( (intptr_t)vaddr );
     127
     128            // check semaphore registered
     129            if( sem_xp == XPTR_NULL )
     130            {
     131
     132#if DEBUG_SYSCALLS_ERROR
     133printk("\n[ERROR] in %s : semaphore %x not registered / thread %x in process %x\n",
     134__FUNCTION__ , (intptr_t)vaddr, this->trdid, process->pid );
     135#endif
     136                this->errno = EINVAL;
     137                return -1;
     138            }
     139
     140            // call relevant kernel function to get semaphore current value
     141                    remote_sem_get_value( sem_xp , &current );
    114142 
    115                 // return value to user
    116                 hal_copy_to_uspace( value , &data , sizeof(uint32_t) );
    117             }
     143            // return value to user
     144            hal_copy_to_uspace( current_value , &current , sizeof(uint32_t) );
     145
    118146            break;
    119147        }
     
    122150        { 
    123151            // get extended pointer on remote semaphore
    124             xptr_t sem_xp = remote_sem_from_vaddr( (intptr_t)vaddr );
    125 
    126             if( sem_xp == XPTR_NULL )     // user error
    127             {
    128 
    129 #if DEBUG_SYSCALLS_ERROR
    130 printk("\n[ERROR] in %s : semaphore %x not registered / thread %x / process %x\n",
    131 __FUNCTION__ , (intptr_t)value, this->trdid, process->pid );
    132 #endif
    133                 this->errno = EINVAL;
    134                 return -1;
    135             }
    136             else                          // success
    137             {
    138                 // wait semaphore available
    139                 remote_sem_wait( sem_xp );
    140             }
     152            sem_xp = remote_sem_from_vaddr( (intptr_t)vaddr );
     153
     154            // check semaphore registered
     155            if( sem_xp == XPTR_NULL )
     156            {
     157
     158#if DEBUG_SYSCALLS_ERROR
     159printk("\n[ERROR] in %s : semaphore %x not registered / thread %x in process %x\n",
     160__FUNCTION__ , (intptr_t)vaddr, this->trdid, process->pid );
     161#endif
     162                this->errno = EINVAL;
     163                return -1;
     164            }
     165
     166            // call relevant kernel function to wait semaphore available
     167            remote_sem_wait( sem_xp );
     168           
    141169            break;
    142170        }
     
    145173        {
    146174            // get extended pointer on remote semaphore
    147             xptr_t sem_xp = remote_sem_from_vaddr( (intptr_t)vaddr );
    148 
    149             if( sem_xp == XPTR_NULL )     // user error
    150             {
    151 
    152 #if DEBUG_SYSCALLS_ERROR
    153 printk("\n[ERROR] in %s : semaphore %x not registered / thread %x / process %x\n",
    154 __FUNCTION__ , (intptr_t)value, this->trdid, process->pid );
    155 #endif
    156                 this->errno = EINVAL;
    157                 return -1;
    158             }
    159             else                          // success
    160             {
    161                 // release semaphore
    162                 remote_sem_post( sem_xp );
    163             }
     175            sem_xp = remote_sem_from_vaddr( (intptr_t)vaddr );
     176
     177            // check semaphore registered
     178            if( sem_xp == XPTR_NULL )
     179            {
     180
     181#if DEBUG_SYSCALLS_ERROR
     182printk("\n[ERROR] in %s : semaphore %x not registered / thread %x in process %x\n",
     183__FUNCTION__ , (intptr_t)vaddr, this->trdid, process->pid );
     184#endif
     185                this->errno = EINVAL;
     186                return -1;
     187            }
     188
     189            // call relevant kernel function to release semaphore
     190            remote_sem_post( sem_xp );
     191
    164192                        break;
    165193        }
     
    168196        {
    169197            // get extended pointer on remote semaphore
    170             xptr_t sem_xp = remote_sem_from_vaddr( (intptr_t)vaddr );
    171 
    172             if( sem_xp == XPTR_NULL )     // user error
    173             {
    174 
    175 #if DEBUG_SYSCALLS_ERROR
    176 printk("\n[ERROR] in %s : semaphore %x not registered / thread %x / process %x\n",
    177 __FUNCTION__ , (intptr_t)value, this->trdid, process->pid );
    178 #endif
    179                 this->errno = EINVAL;
    180                 return -1;
    181             }
    182             else                          // success
    183             {
    184                 // destroy semaphore
    185                 remote_sem_destroy( sem_xp );
    186             }
     198            sem_xp = remote_sem_from_vaddr( (intptr_t)vaddr );
     199
     200            // check semaphore registered
     201            if( sem_xp == XPTR_NULL )
     202            {
     203
     204#if DEBUG_SYSCALLS_ERROR
     205printk("\n[ERROR] in %s : semaphore %x not registered / thread %x in process %x\n",
     206__FUNCTION__ , (intptr_t)vaddr, this->trdid, process->pid );
     207#endif
     208                this->errno = EINVAL;
     209                return -1;
     210            }
     211
     212            // destroy semaphore
     213            remote_sem_destroy( sem_xp );
     214
    187215            break;
    188216            }   
     
    190218            default:  // undefined operation                       
    191219        {
    192             printk("\n[PANIC] in %s : illegal operation type\n", __FUNCTION__ );
    193             hal_core_sleep();
     220
     221#if DEBUG_SYSCALLS_ERROR
     222printk("\n[ERROR] in %s : undefined operation type %d / thread %x in process %x\n",
     223__FUNCTION__ , operation, this->trdid, process->pid );
     224#endif
     225            this->errno = EINVAL;
     226            return -1;
    194227        }
    195228        }
    196229
     230    hal_fence();
     231
     232#if DEBUG_SYS_SEM
     233tm_end = hal_get_cycles();
     234if( DEBUG_SYS_SEM < tm_end )
     235{
     236    cxy_t          sem_cxy = GET_CXY( sem_xp );
     237    remote_sem_t * sem_ptr = GET_PTR( sem_xp );
     238    uint32_t       value   = hal_remote_lw( XPTR( sem_cxy , &sem_ptr->count ) );
     239    printk("\n[DBG] %s : thread %x in process %x exit for %s / value %d / cost = %d / cycle %d\n",
     240    __FUNCTION__, this->trdid, process->pid, sys_sem_op_str( operation ), value,
     241    (uint32_t)(tm_end - tm_start), (uint32_t)tm_end );
     242}
     243#endif
     244
    197245    return 0;
    198246
  • trunk/kernel/syscalls/sys_signal.c

    r435 r457  
    2323 */
    2424
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <errno.h>
    2727#include <thread.h>
  • trunk/kernel/syscalls/sys_stat.c

    r440 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_uspace.h>
    2626#include <hal_special.h>
  • trunk/kernel/syscalls/sys_thread_cancel.c

    r443 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_irqmask.h>
    2626#include <hal_remote.h>
  • trunk/kernel/syscalls/sys_thread_create.c

    r440 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_uspace.h>
    2727#include <printk.h>
  • trunk/kernel/syscalls/sys_thread_detach.c

    r23 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_remote.h>
    2626#include <hal_special.h>
  • trunk/kernel/syscalls/sys_thread_exit.c

    r440 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_irqmask.h>
    2626#include <thread.h>
  • trunk/kernel/syscalls/sys_thread_join.c

    r438 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_remote.h>
    2626#include <hal_special.h>
  • trunk/kernel/syscalls/sys_thread_wakeup.c

    r438 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <thread.h>
    2626#include <printk.h>
  • trunk/kernel/syscalls/sys_thread_yield.c

    r445 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_special.h>
    2626#include <scheduler.h>
  • trunk/kernel/syscalls/sys_timeofday.c

    r440 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_uspace.h>
    2626#include <thread.h>
  • trunk/kernel/syscalls/sys_trace.c

    r443 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_special.h>
    2626#include <printk.h>
  • trunk/kernel/syscalls/sys_unlink.c

    r407 r457  
    2121 */
    2222
    23 #include <hal_types.h>
     23#include <hal_kernel_types.h>
    2424#include <hal_uspace.h>
    2525#include <vfs.h>
  • trunk/kernel/syscalls/sys_utls.c

    r23 r457  
    2323 */
    2424
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <errno.h>
    2727#include <thread.h>
  • trunk/kernel/syscalls/sys_wait.c

    r446 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_uspace.h>
    2626#include <hal_irqmask.h>
  • trunk/kernel/syscalls/sys_write.c

    r443 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_uspace.h>
    2727#include <hal_irqmask.h>
  • trunk/kernel/syscalls/syscalls.h

    r445 r457  
    22 * syscalls.h - Kernel side services for syscall handling.
    33 *
    4  * Author     Alain Greiner (2016,2017)
     4 * Author     Alain Greiner (2016,2017,2018)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
     
    2525#define _SYSCALLS_H_
    2626
    27 #include <hal_types.h>
     27#include <hal_kernel_types.h>
    2828#include <shared_syscalls.h>
    2929
     
    116116 * and the code implementing the operations is in the remore_sem.c file.
    117117 ******************************************************************************************
    118  * @ vaddr     : semaphore virtual address in user space == identifier.
    119  * @ operation : SEM_INIT / SEM_DESTROY / SEM_GETVALUE / SEM_POST / SEM_WAIT.
    120  * @ value     : pointer on in/out argument in user space.
     118 * @ vaddr         : semaphore virtual address in user space == identifier.
     119 * @ operation     : SEM_INIT / SEM_DESTROY / SEM_GETVALUE / SEM_POST / SEM_WAIT.
     120 * @ init_value    : initial semaphore value.
     121 * @ current_value : pointer on buffer for current semaphore value.
    121122 * @ return 0 if success / return -1 if failure.
    122123 *****************************************************************************************/
    123124int sys_sem( void       * vaddr,
    124125             uint32_t     operation,
    125              uint32_t   * value );
     126             uint32_t     init_value,
     127             uint32_t   * current_value );
    126128
    127129/******************************************************************************************
     
    584586
    585587/******************************************************************************************
     588 * [44] TBD
     589 ******************************************************************************************
     590 * @ cxy    : cluster identifier.
     591 * @ lid    : core local index.
     592 * @ return 0 if success / return -1 if failure.
     593 *****************************************************************************************/
     594int sys_place( uint32_t cxy,
     595               uint32_t lid );
     596
     597/******************************************************************************************
    586598 * [45] This function block the calling thread on the THREAD_BLOCKED_GLOBAL condition,
    587599 * and deschedule.
     
    624636
    625637/******************************************************************************************
    626  * [49] TBD
    627  ******************************************************************************************
    628  * @ cxy    : cluster identifier.
    629  * @ lid    : core local index.
    630  * @ return 0 if success / return -1 if failure.
    631  *****************************************************************************************/
    632 int sys_place( uint32_t cxy,
    633                uint32_t lid );
     638 * [49] This function returns a non-zero value in the <is_fg> buffer when the process
     639 * identified by the <pid> argument is the current TXT owner.
     640 ******************************************************************************************
     641 * @ pid      : process identifier.
     642 * @ is_fg    : pointer on buffer.
     643 * @ return 0 if success / return -1 if failure.
     644 *****************************************************************************************/
     645int sys_is_fg( pid_t      pid,
     646               uint32_t * is_fg );
    634647
    635648#endif  // _SYSCALLS_H_
Note: See TracChangeset for help on using the changeset viewer.