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

Introduce syscalls.

File:
1 edited

Legend:

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

    r1 r23  
    22 * sys_sem.c - Acces a POSIX unamed semaphore.
    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
    2324#include <hal_types.h>
    24 #include <hal_uspace.
     25#include <hal_uspace.h>
     26#include <errno.h>
     27#include <thread.h>
     28#include <printk.h>
     29#include <vmm.h>
    2530#include <remote_sem.h>
     31#include <syscalls.h>
    2632
    2733//////////////////////////////////
     
    3137{
    3238        uint32_t             data;   
    33         error_t              error;
     39        paddr_t              paddr;
     40    error_t              error;
    3441
    35     thread_t           * this      = CURRENT_THREAD;
    36         process_t          * process   = CURRENT_PROCESS;
     42    thread_t           * this = CURRENT_THREAD;
    3743
    3844    // check vaddr in user vspace
    39         error = vmm_check_address( process , vaddr , sizeof(unsigned long) );
    40         if( error ) 
     45        error = vmm_v2p_translate( false , vaddr , &paddr );
     46        if( error )
    4147    {
     48        printk("\n[ERROR] in %s : illegal semaphore virtual address = %x\n",
     49               __FUNCTION__ , (intptr_t)vaddr );
    4250        this->errno = error;
    4351        return -1;
     
    4553
    4654    // check value in user vspace
    47     error = vmm_check_address( process , value , sizeof(int*) );
    48         if( error ) 
     55        error = vmm_v2p_translate( false , value , &paddr );
     56        if( error )
    4957    {
     58        printk("\n[ERROR] in %s : illegal argument virtual address = %x\n",
     59               __FUNCTION__ , (intptr_t)value );
    5060        this->errno = error;
    5161        return -1;   
     
    6272
    6373            // call init function
    64             error = remote_sem_init( (intptr_t)vaddr , data );
     74            error = remote_sem_create( (intptr_t)vaddr , data );
    6575
    6676            if ( error )
    6777            {
     78                printk("\n[ERROR] in %s : cannot create semaphore = %x\n",
     79                       __FUNCTION__ , (intptr_t)value );
    6880                this->errno = error;
    6981                return -1;
     
    7991            if( sem_xp == XPTR_NULL )     // user error
    8092            {
     93                printk("\n[ERROR] in %s : semaphore %x not registered\n",
     94                       __FUNCTION__ , (intptr_t)value );
    8195                this->errno = EINVAL;
    8296                return -1;
     
    100114            if( sem_xp == XPTR_NULL )     // user error
    101115            {
     116                printk("\n[ERROR] in %s : semaphore %x not registered\n",
     117                       __FUNCTION__ , (intptr_t)value );
    102118                this->errno = EINVAL;
    103119                return -1;
     
    118134            if( sem_xp == XPTR_NULL )     // user error
    119135            {
     136                printk("\n[ERROR] in %s : semaphore %x not registered\n",
     137                       __FUNCTION__ , (intptr_t)value );
    120138                this->errno = EINVAL;
    121139                return -1;
     
    136154            if( sem_xp == XPTR_NULL )     // user error
    137155            {
     156                printk("\n[ERROR] in %s : semaphore %x not registered\n",
     157                       __FUNCTION__ , (intptr_t)value );
    138158                this->errno = EINVAL;
    139159                return -1;
     
    149169            default:  // undefined operation                       
    150170        {
    151                     this->errno = EINVAL;
    152             return -1;
     171            printk("\n[PANIC] in %s : illegal operation type\n", __FUNCTION__ );
     172            hal_core_sleep();
    153173        }
    154174        }
Note: See TracChangeset for help on using the changeset viewer.