source: trunk/kernel/syscalls/sys_barrier.c @ 574

Last change on this file since 574 was 508, checked in by viala@…, 6 years ago

[syscall] Use assert instead of printk+hal_core_sleep.

File size: 3.5 KB
RevLine 
[1]1/*
[23]2 * sys_barrier.c - Access a POSIX barrier.
[1]3 *
[440]4 * authors       Alain Greiner (2016,2017,2018)
[1]5 *
[23]6 * Copyright (c) UPMC Sorbonne Universites
[1]7 *
[23]8 * This file is part of ALMOS-MKH.
9 *
10 * ALMOS-MKH is free software; you can redistribute it and/or modify it
[1]11 * under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2.0 of the License.
13 *
[23]14 * ALMOS-MKH is distributed in the hope that it will be useful, but
[1]15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
[23]20 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
[1]21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
[457]24#include <hal_kernel_types.h>
[23]25#include <hal_special.h>
[1]26#include <errno.h>
27#include <thread.h>
[23]28#include <printk.h>
[1]29#include <vmm.h>
[23]30#include <syscalls.h>
31#include <remote_barrier.h>
[1]32
[23]33//////////////////////////////////
34int sys_barrier( void     * vaddr,
35                 uint32_t   operation,
36                 uint32_t   count )
[1]37{
[23]38        error_t      error;
[440]39    vseg_t     * vseg;
[1]40 
[440]41    thread_t   * this    = CURRENT_THREAD;
42    process_t  * process = this->process;
[1]43
[23]44    // check vaddr in user vspace
[440]45        error = vmm_get_vseg( process , (intptr_t)vaddr , &vseg );
46
[23]47        if( error )
48    {
[440]49
50#if DEBUG_SYSCALLS_ERROR
51printk("\n[ERROR] in %s : unmapped barrier %x / thread %x / process %x\n",
52__FUNCTION__ , (intptr_t)vaddr , this->trdid , process->pid );
53vmm_display( process , false );
54#endif
[23]55        this->errno = error;
56        return -1;
57    }
[1]58
[23]59    // execute requested operation
60        switch( operation )
[1]61        {
[23]62        //////////////////
63            case BARRIER_INIT:
64        {
65            error = remote_barrier_create( (intptr_t)vaddr , count );
[1]66   
[23]67                    if( error )
68            {
[440]69
70#if DEBUG_SYSCALLS_ERROR
71printk("\n[ERROR] in %s : cannot create barrier %x / thread %x / process %x\n",
72__FUNCTION__ , (intptr_t)vaddr , this->trdid , process->pid );
73#endif
[23]74                this->errno = error;
75                return -1;
76            }
[1]77                        break;
[23]78        }
79        //////////////////
80            case BARRIER_WAIT:
81        {
82            xptr_t barrier_xp = remote_barrier_from_ident( (intptr_t)vaddr );
[1]83
[23]84            if( barrier_xp == XPTR_NULL )     // user error
85            {
[440]86
87#if DEBUG_SYSCALLS_ERROR
88printk("\n[ERROR] in %s : barrier %x not registered / thread %x / process %x\n",
89__FUNCTION__ , (intptr_t)vaddr , this->trdid , process->pid );
90#endif
[23]91                this->errno = EINVAL;
92                return -1;
93            }
94            else                          // success
95            {
96                remote_barrier_wait( barrier_xp ); 
97            }
98            break;
99        }
100        /////////////////////
101            case BARRIER_DESTROY:
102        {
103            xptr_t barrier_xp = remote_barrier_from_ident( (intptr_t)vaddr );
[1]104
[23]105            if( barrier_xp == XPTR_NULL )     // user error
106            {
[440]107
108#if DEBUG_SYSCALLS_ERROR
109printk("\n[ERROR] in %s : barrier %x not registered / thread %x / process %x\n",
110__FUNCTION__ , (intptr_t)vaddr , this->trdid , process->pid );
111#endif
[23]112                this->errno = EINVAL;
113                return -1;
114            }
115            else                          // success
116            {
117                remote_barrier_destroy( barrier_xp ); 
118            }
119            break;
120        }
121        ////////
[508]122        default: {
123            assert ( false, "illegal operation type <%x>", operation );
[23]124        }
125        }  // end switch
[1]126
[23]127        return 0;
[1]128
[23]129}  // end sys_barrier()
[1]130
Note: See TracBrowser for help on using the repository browser.