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_display.c

    r438 r440  
    22 * sys_display.c - display the current state of a kernel structure on TXT0
    33 *
    4  * Author    Alain Greiner (2016,2017)
     4 * Author    Alain Greiner (2016,2017,2018)
    55 * 
    66 * Copyright (c) UPMC Sorbonne Universites
     
    3838{
    3939
     40    error_t     error;
     41    vseg_t    * vseg;
     42
     43    thread_t  * this    = CURRENT_THREAD;
     44    process_t * process = this->process;
     45
    4046#if DEBUG_SYS_DISPLAY
    4147uint64_t    tm_start;
    4248uint64_t    tm_end;
    43 thread_t  * this;
    44 this     = CURRENT_THREAD;
    4549tm_start = hal_get_cycles();
    4650if( DEBUG_SYS_DISPLAY < tm_start )
     
    4953#endif
    5054
     55    ////////////////////////////
    5156    if( type == DISPLAY_STRING )
    5257    {
    53         paddr_t   paddr;
    5458        char      kbuf[256];
    5559        uint32_t  length;
    5660
    5761        char    * string = (char *)arg0;
    58  
     62
    5963        // check string in user space
    60         if( vmm_v2p_translate( false , string , &paddr ) )
    61         {
    62             printk("\n[ERROR] in %s : string buffer %x unmapped\n",
    63             __FUNCTION__ , string );
     64        error = vmm_get_vseg( process , (intptr_t)arg0 , &vseg );
     65
     66        if( error )
     67        {
     68
     69#if DEBUG_SYSCALLS_ERROR
     70printk("\n[ERROR] in %s : string buffer %x unmapped / thread %x / process %x\n",
     71__FUNCTION__ , (intptr_t)arg0 , this->trdid , process->pid );
     72#endif
     73            this->errno = EINVAL;
    6474            return -1;
    6575        }
     
    6777        // ckeck string length
    6878        length = hal_strlen_from_uspace( string );
     79
    6980        if( length >= 256 )
    7081        {
    71             printk("\n[ERROR] in %s : string length %d too large\n",
    72             __FUNCTION__ , length );
    73             return -1;
    74         }
    75 
    76         // copy string in kernel space
     82
     83#if DEBUG_SYSCALLS_ERROR
     84printk("\n[ERROR] in %s : string length %d too large / thread %x / process %x\n",
     85__FUNCTION__ , length , this->trdid , process->pid );
     86#endif
     87            this->errno = EINVAL;
     88            return -1;
     89        }
     90
     91        // copy string to kernel space
    7792        hal_strcpy_from_uspace( kbuf , string , 256 );
    7893
    7994        // print message on TXT0 kernel terminal
    80         printk("\n[USER] %s / cycle %d\n", kbuf, (uint32_t)hal_get_cycles() );
    81     }
     95        printk("\n%s / cycle %d\n", kbuf, (uint32_t)hal_get_cycles() );
     96    }
     97    //////////////////////////////
    8298    else if( type == DISPLAY_VMM )
    8399    {
     
    89105            if( process_xp == XPTR_NULL )
    90106        {
    91             printk("\n[ERROR] in %s : undefined PID %x\n",
    92             __FUNCTION__ , pid );
     107
     108#if DEBUG_SYSCALLS_ERROR
     109printk("\n[ERROR] in %s : undefined pid argument %d / thread %x / process %x\n",
     110__FUNCTION__ , pid , this->trdid , process->pid );
     111#endif
     112            this->errno = EINVAL;
    93113            return -1;
    94114        }
     
    108128        }
    109129    }
     130    ////////////////////////////////
    110131    else if( type == DISPLAY_SCHED )
    111132    {
     
    113134        lid_t lid = (lid_t)arg1;
    114135
    115         // check cluster argument
     136        // check cxy argument
    116137            if( cluster_is_undefined( cxy ) )
    117138        {
    118             printk("\n[ERROR] in %s : undefined cluster identifier %x\n",
    119             __FUNCTION__ , cxy );
    120             return -1;
    121         }
    122 
    123         // check core argument
     139
     140#if DEBUG_SYSCALLS_ERROR
     141printk("\n[ERROR] in %s : illegal cxy argument %x / thread %x / process %x\n",
     142__FUNCTION__ , cxy , this->trdid , process->pid );
     143#endif
     144            this->errno = EINVAL;
     145            return -1;
     146        }
     147
     148        // check lid argument
    124149        if( lid >= LOCAL_CLUSTER->cores_nr )
    125150        {
    126             printk("\n[ERROR] in %s : undefined local index %d\n",
    127             __FUNCTION__ , lid );
     151
     152#if DEBUG_SYSCALLS_ERROR
     153printk("\n[ERROR] in %s : illegal lid argument %x / thread %x / process %x\n",
     154__FUNCTION__ , lid , this->trdid , process->pid );
     155#endif
     156            this->errno = EINVAL;
    128157            return -1;
    129158        }
     
    138167        }
    139168    }
     169    ////////////////////////////////////////////
    140170    else if( type == DISPLAY_CLUSTER_PROCESSES )
    141171    {
    142172        cxy_t cxy = (cxy_t)arg0;
    143173
    144         // check cluster argument
     174        // check cxy argument
    145175            if( cluster_is_undefined( cxy ) )
    146176        {
    147             printk("\n[ERROR] in %s : undefined cluster identifier %x\n",
    148             __FUNCTION__ , cxy );
     177
     178#if DEBUG_SYSCALLS_ERROR
     179printk("\n[ERROR] in %s : illegal cxy argument %x / thread %x / process %x\n",
     180__FUNCTION__ , cxy , this->trdid , process->pid );
     181#endif
     182            this->errno = EINVAL;
    149183            return -1;
    150184        }
     
    152186        cluster_processes_display( cxy );
    153187    }
     188    ////////////////////////////////////////
    154189    else if( type == DISPLAY_TXT_PROCESSES )
    155190    {
     
    159194            if( txt_id >= LOCAL_CLUSTER->nb_txt_channels )
    160195        {
    161             printk("\n[ERROR] in %s : undefined TXT channel %x\n",
    162             __FUNCTION__ , txt_id );
     196
     197#if DEBUG_SYSCALLS_ERROR
     198printk("\n[ERROR] in %s : illegal txt_id argument %d / thread %x / process %x\n",
     199__FUNCTION__ , txt_id , this->trdid , process->pid );
     200#endif
     201            this->errno = EINVAL;
    163202            return -1;
    164203        }
     
    166205        process_txt_display( txt_id );
    167206    }
     207    //////////////////////////////
    168208    else if( type == DISPLAY_VFS )
    169209    {
    170         // call kernel function
    171         process_t * process = CURRENT_THREAD->process;
    172210        vfs_display( process->vfs_root_xp );
    173211    }
     212    ////////////////////////////////
    174213    else if( type == DISPLAY_CHDEV )
    175214    {
    176215        chdev_dir_display();
    177216    }
     217    ////
    178218    else
    179219    {
    180         printk("\n[ERROR] in %s : undefined display type %x\n",
    181         __FUNCTION__ , type );
     220
     221#if DEBUG_SYSCALLS_ERROR
     222printk("\n[ERROR] in %s : undefined display type %x / thread %x / process %x\n",
     223        __FUNCTION__ , type , this->trdid , process->pid );
     224#endif
     225        this->errno = EINVAL;
    182226        return -1;
    183227    }
Note: See TracChangeset for help on using the changeset viewer.