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

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

[syscall] Use assert instead of printk+hal_core_sleep.

File size: 3.5 KB
Line 
1/*
2 * sys_barrier.c - Access a POSIX barrier.
3 *
4 * authors       Alain Greiner (2016,2017,2018)
5 *
6 * Copyright (c) UPMC Sorbonne Universites
7 *
8 * This file is part of ALMOS-MKH.
9 *
10 * ALMOS-MKH is free software; you can redistribute it and/or modify it
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 *
14 * ALMOS-MKH is distributed in the hope that it will be useful, but
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
20 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#include <hal_kernel_types.h>
25#include <hal_special.h>
26#include <errno.h>
27#include <thread.h>
28#include <printk.h>
29#include <vmm.h>
30#include <syscalls.h>
31#include <remote_barrier.h>
32
33//////////////////////////////////
34int sys_barrier( void     * vaddr,
35                 uint32_t   operation,
36                 uint32_t   count )
37{
38        error_t      error;
39    vseg_t     * vseg;
40 
41    thread_t   * this    = CURRENT_THREAD;
42    process_t  * process = this->process;
43
44    // check vaddr in user vspace
45        error = vmm_get_vseg( process , (intptr_t)vaddr , &vseg );
46
47        if( error )
48    {
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
55        this->errno = error;
56        return -1;
57    }
58
59    // execute requested operation
60        switch( operation )
61        {
62        //////////////////
63            case BARRIER_INIT:
64        {
65            error = remote_barrier_create( (intptr_t)vaddr , count );
66   
67                    if( error )
68            {
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
74                this->errno = error;
75                return -1;
76            }
77                        break;
78        }
79        //////////////////
80            case BARRIER_WAIT:
81        {
82            xptr_t barrier_xp = remote_barrier_from_ident( (intptr_t)vaddr );
83
84            if( barrier_xp == XPTR_NULL )     // user error
85            {
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
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 );
104
105            if( barrier_xp == XPTR_NULL )     // user error
106            {
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
112                this->errno = EINVAL;
113                return -1;
114            }
115            else                          // success
116            {
117                remote_barrier_destroy( barrier_xp ); 
118            }
119            break;
120        }
121        ////////
122        default: {
123            assert ( false, "illegal operation type <%x>", operation );
124        }
125        }  // end switch
126
127        return 0;
128
129}  // end sys_barrier()
130
Note: See TracBrowser for help on using the repository browser.