Ignore:
Timestamp:
Jun 18, 2017, 10:06:41 PM (7 years ago)
Author:
alain
Message:

Introduce syscalls.

File:
1 edited

Legend:

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

    r1 r23  
    11/*
    2  * kern/sys_barrier.c - barrier service interface for userland
     2 * sys_barrier.c - Access a POSIX barrier.
    33 *
    4  * Copyright (c) 2008,2009,2010,2011,2012 Ghassan Almaless
    5  * Copyright (c) 2011,2012 UPMC Sorbonne Universites
     4 * authors       Alain Greiner (2016,2017)
    65 *
    7  * This file is part of ALMOS-kernel.
     6 * Copyright (c) UPMC Sorbonne Universites
    87 *
    9  * ALMOS-kernel is free software; you can redistribute it and/or modify it
     8 * This file is part of ALMOS-MKH.
     9 *
     10 * ALMOS-MKH is free software; you can redistribute it and/or modify it
    1011 * under the terms of the GNU General Public License as published by
    1112 * the Free Software Foundation; version 2.0 of the License.
    1213 *
    13  * ALMOS-kernel is distributed in the hope that it will be useful, but
     14 * ALMOS-MKH is distributed in the hope that it will be useful, but
    1415 * WITHOUT ANY WARRANTY; without even the implied warranty of
    1516 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     
    1718 *
    1819 * You should have received a copy of the GNU General Public License
    19  * along with ALMOS-kernel; if not, write to the Free Software Foundation,
     20 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
    2021 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
    2122 */
    2223
    23 #include <types.h>
     24#include <hal_types.h>
     25#include <hal_special.h>
    2426#include <errno.h>
    2527#include <thread.h>
    26 #include <task.h>
    27 #include <kmem.h>
     28#include <printk.h>
    2829#include <vmm.h>
    29 #include <kmagics.h>
    30 #include <barrier.h>
     30#include <syscalls.h>
     31#include <remote_barrier.h>
    3132
    32 int sys_barrier(struct barrier_s **barrier, uint_t operation, uint_t count)
     33//////////////////////////////////
     34int sys_barrier( void     * vaddr,
     35                 uint32_t   operation,
     36                 uint32_t   count )
    3337{
    34         kmem_req_t req;
    35         struct barrier_s *ibarrier;
    36         error_t err = EINVAL;
     38        error_t      error;
     39    paddr_t      paddr;
    3740 
    38         if((err = vmm_check_address("usr barrier ptr",
    39                                     current_task,
    40                                     barrier,
    41                                     sizeof(struct barrier_s*))))
    42                 goto SYS_BARRIER_END;
     41    thread_t   * this = CURRENT_THREAD;
    4342
    44         if((err = cpu_copy_from_uspace(&ibarrier, barrier, sizeof(struct barrier_s *))))
    45                 goto SYS_BARRIER_END;
     43    // check vaddr in user vspace
     44        error = vmm_v2p_translate( false , vaddr , &paddr );
     45        if( error )
     46    {
     47        printk("\n[ERROR] in %s : illegal barrier virtual address = %x\n",
     48               __FUNCTION__ , (intptr_t)vaddr );
     49        this->errno = error;
     50        return -1;
     51    }
    4652
    47         switch(operation)
     53    // execute requested operation
     54        switch( operation )
    4855        {
    49         case BARRIER_INIT_PRIVATE:
    50         case BARRIER_INIT_SHARED:
    51                 req.type  = KMEM_BARRIER;
    52                 req.size  = sizeof(*ibarrier);
    53                 req.flags = AF_USER;
     56        //////////////////
     57            case BARRIER_INIT:
     58        {
     59            error = remote_barrier_create( (intptr_t)vaddr , count );
     60   
     61                    if( error )
     62            {
     63                printk("\n[ERROR] in %s : cannot create barrier = %x\n",
     64                       __FUNCTION__ , (intptr_t)vaddr );
     65                this->errno = error;
     66                return -1;
     67            }
     68                        break;
     69        }
     70        //////////////////
     71            case BARRIER_WAIT:
     72        {
     73            xptr_t barrier_xp = remote_barrier_from_ident( (intptr_t)vaddr );
    5474
    55                 if((ibarrier = kmem_alloc(&req)) == NULL)
    56                 {
    57                         err = ENOMEM;
    58                         break;
    59                 }
    60    
    61                 if((err = barrier_init(ibarrier, count, operation)))
    62                         break;
    63    
    64                 if((err = cpu_copy_to_uspace(barrier, &ibarrier, sizeof(struct barrier_s *))))
    65                 {
    66                         req.ptr = ibarrier;
    67                         kmem_free(&req);
    68                 }
    69                 break;
     75            if( barrier_xp == XPTR_NULL )     // user error
     76            {
     77                printk("\n[ERROR] in %s : barrier %x not registered\n",
     78                       __FUNCTION__ , (intptr_t)vaddr );
     79                this->errno = EINVAL;
     80                return -1;
     81            }
     82            else                          // success
     83            {
     84                remote_barrier_wait( barrier_xp );
     85            }
     86            break;
     87        }
     88        /////////////////////
     89            case BARRIER_DESTROY:
     90        {
     91            xptr_t barrier_xp = remote_barrier_from_ident( (intptr_t)vaddr );
    7092
    71         case BARRIER_WAIT:
     93            if( barrier_xp == XPTR_NULL )     // user error
     94            {
     95                printk("\n[ERROR] in %s : barrier %x not registered\n",
     96                       __FUNCTION__ , (intptr_t)vaddr );
     97                this->errno = EINVAL;
     98                return -1;
     99            }
     100            else                          // success
     101            {
     102                remote_barrier_destroy( barrier_xp );
     103            }
     104            break;
     105        }
     106        ////////
     107            default:
     108        {
     109            printk("\n[PANIC] in %s : illegal operation type\n", __FUNCTION__ );
     110            hal_core_sleep();
     111        }
     112        }  // end switch
    72113
    73                 if((err = vmm_check_object(ibarrier, struct barrier_s, BARRIER_ID)))
    74                         break;
     114        return 0;
    75115
    76                 err = barrier_wait(ibarrier);
    77                 break;
     116}  // end sys_barrier()
    78117
    79         case BARRIER_DESTROY:
    80    
    81                 if((err = vmm_check_object(ibarrier, struct barrier_s, BARRIER_ID)))
    82                         break;
    83    
    84                 if((err = barrier_destroy(ibarrier)))
    85                         break;
    86    
    87                 req.type = KMEM_BARRIER;
    88                 req.ptr  = ibarrier;
    89                 kmem_free(&req);
    90                 return 0;
    91 
    92         default:
    93                 err = EINVAL;
    94         }
    95 
    96 SYS_BARRIER_END:
    97         current_thread->info.errno = err;
    98         return err;
    99 }
    100 
    101 KMEM_OBJATTR_INIT(barrier_kmem_init)
    102 {
    103         attr->type   = KMEM_BARRIER;
    104         attr->name   = "KCM Barrier";
    105         attr->size   = sizeof(struct barrier_s);
    106         attr->aligne = 0;
    107         attr->min    = CONFIG_BARRIER_MIN;
    108         attr->max    = CONFIG_BARRIER_MAX;
    109         attr->ctor   = NULL;
    110         attr->dtor   = NULL;
    111         return 0;
    112 }
Note: See TracChangeset for help on using the changeset viewer.