Ignore:
Timestamp:
May 3, 2018, 5:51:22 PM (6 years ago)
Author:
alain
Message:

1/ Fix a bug in the Multithreaded "sort" applicationr:
The pthread_create() arguments must be declared as global variables.
2/ The exit syscall can be called by any thread of a process..

File:
1 edited

Legend:

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

    r438 r440  
    5353        trdid_t          trdid;            // created thread identifier
    5454        process_t      * process;          // pointer on local process descriptor
    55         paddr_t          paddr;            // unused, required by vmm_v2p_translate()
     55        vseg_t         * vseg;             // required for user space checking
    5656    cxy_t            target_cxy;       // target cluster identifier
    5757        error_t          error;
     
    6767tm_start = hal_get_cycles();
    6868if( DEBUG_SYS_THREAD_CREATE < tm_start )
    69 printk("\n[DBG] %s : thread %x enter / process %x / cycle %d\n"
    70 __FUNCTION__ , parent , process->pid, (uint32_t)tm_start );
    71 #endif
    72 
    73         // check user_attr in user space & copy to kernel space
     69printk("\n[DBG] %s : thread %x (cxy %x) enter / process %x / cycle %d\n",
     70__FUNCTION__, parent, local_cxy, process->pid, (uint32_t)tm_start );
     71#endif
     72
     73    // check trdid buffer in user space
     74    error = vmm_get_vseg( process , (intptr_t)trdid_ptr , &vseg );
     75
     76    if ( error )
     77    {
     78
     79#if DEBUG_SYSCALLS_ERROR
     80printk("\n[ERROR] in %s : trdid buffer unmapped %x / thread %x / process %x\n",
     81__FUNCTION__ , (intptr_t)trdid_ptr, parent->trdid, process->pid );
     82vmm_display( process , false );
     83#endif
     84                parent->errno = EINVAL;
     85                return -1;
     86    }
     87
     88        // check user_attr buffer in user space & copy to kernel space
    7489    if( user_attr != NULL )
    7590    {
    76             error = vmm_v2p_translate( false , user_attr , &paddr );
     91            error = vmm_get_vseg( process , (intptr_t)user_attr , &vseg );
    7792
    7893            if( error )
     
    8095
    8196#if DEBUG_SYSCALLS_ERROR
    82 printk("\n[ERROR] in %s : user_attr unmapped\n", __FUNCTION__ );
     97printk("\n[ERROR] in %s : user_attr buffer unmapped %x / thread %x / process %x\n",
     98__FUNCTION__ , (intptr_t)user_attr , parent->trdid , process->pid );
     99vmm_display( process , false );
    83100#endif
    84101                    parent->errno = EINVAL;
     
    90107
    91108        // check start_func in user space
    92         error = vmm_v2p_translate( false , start_func , &paddr );
    93 
    94         if( error )
    95         {
    96 
    97 #if DEBUG_SYSCALLS_ERROR
    98 printk("\n[ERROR] in %s : start_func unmapped\n", __FUNCTION__ );
    99 #endif
    100                 parent->errno = EINVAL;
    101                 return -1;
    102         }
    103 
    104         // check start_arg in user space
    105         if( start_arg != NULL ) error = vmm_v2p_translate( false , start_arg , &paddr );
    106 
    107         if( error )
    108         {
    109 
    110 #if DEBUG_SYSCALLS_ERROR
    111 printk("\n[ERROR] in %s : start_arg unmapped\n", __FUNCTION__ );
    112 #endif
    113                 parent->errno = EINVAL;
    114                 return -1;
    115         }
    116 
    117         // check / define attributes an target_cxy
     109        error = vmm_get_vseg( process , (intptr_t)start_func , &vseg );
     110
     111    if( error )
     112    {
     113
     114#if DEBUG_SYSCALLS_ERROR
     115printk("\n[ERROR] in %s : start_func unmapped %x / thread %x / process %x\n",
     116__FUNCTION__ , (intptr_t)start_func , parent->trdid , process->pid );
     117vmm_display( process , false );
     118#endif
     119        parent->errno = EINVAL;
     120            return -1;
     121        }
     122
     123        // check start_arg buffer in user space
     124        if( start_arg != NULL )
     125    {
     126        error = vmm_get_vseg( process , (intptr_t)start_arg , &vseg );
     127
     128            if( error )
     129            {
     130
     131#if DEBUG_SYSCALLS_ERROR
     132printk("\n[ERROR] in %s : start_arg buffer unmapped %x / thread %x / process %x\n",
     133__FUNCTION__ , (intptr_t)start_arg , parent->trdid , process->pid );
     134vmm_display( process , false );
     135#endif
     136                    parent->errno = EINVAL;
     137                    return -1;
     138        }
     139        }
     140
     141    // define attributes and target_cxy
    118142    if( user_attr != NULL )                      // user defined attributes
    119143    {
     
    125149
    126150#if DEBUG_SYSCALLS_ERROR
    127 printk("\n[ERROR] in %s : illegal target cluster = %x\n", __FUNCTION__ , kern_attr.cxy );
     151printk("\n[ERROR] in %s : illegal target cluster = %x / thread %x / process %x\n",
     152__FUNCTION__ , kern_attr.cxy, parent->trdid, process->pid );
    128153#endif
    129154                            parent->errno = EINVAL;
     
    175200
    176201#if DEBUG_SYSCALLS_ERROR
    177 printk("\n[ERROR] in %s : cannot create thread\n", __FUNCTION__ );
    178 #endif
    179                 return ENOMEM;
     202printk("\n[ERROR] in %s : cannot create new thread / thread %x / process %x\n",
     203__FUNCTION__ , parent->trdid, process->pid );
     204#endif
     205                parent->errno = ENOMEM;
     206                return -1;
    180207        }
    181208
     
    184211        hal_copy_to_uspace( trdid_ptr , &trdid , sizeof(pthread_t) );
    185212
    186     // register child in parent if required
    187     if( user_attr != NULL )
    188     {
    189             if( (kern_attr.attributes & PT_ATTR_DETACH) == 0 )
    190                 thread_child_parent_link( parent_xp , child_xp );
    191     }
    192 
    193213    // activate new thread
    194214        thread_unblock( child_xp , THREAD_BLOCKED_GLOBAL );
     
    199219tm_end = hal_get_cycles();
    200220if( DEBUG_SYS_THREAD_CREATE < tm_end )
    201 printk("\n[DBG] %s : thread %x created thread %x for process %x in cluster %x / cycle %d\n"
    202 __FUNCTION__, parent, child_ptr, process->pid, target_cxy, (uint32_t)tm_end );
     221printk("\n[DBG] %s : thread %x (cxy %x) created thread %x (cxy %x) / process %x / cycle %d\n",
     222__FUNCTION__, parent, local_cxy, child_ptr, target_cxy, process->pid, (uint32_t)tm_end );
    203223#endif
    204224
Note: See TracChangeset for help on using the changeset viewer.