source: trunk/kernel/syscalls/sys_munmap.c @ 623

Last change on this file since 623 was 623, checked in by alain, 5 years ago

Introduce three new types of vsegs (KCODE,KDATA,KDEV)
to map the kernel vsegs in the process VSL and GPT.
This now used by both the TSAR and the I86 architectures.

File size: 3.0 KB
Line 
1/*
2 * sys_munmap.c - unmap a mapping from process virtual address space
3 *
4 * Authors       Ghassan Almaless (2008,2009,2010,2011,2012)
5 *               Alain Greiner (2016,2017,2018)
6 *
7 * Copyright (c) UPMC Sorbonne Universites
8 *
9 * This file is part of ALMOS-MKH.
10 *
11 * ALMOS-MKH is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 2.0 of the License.
14 *
15 * ALMOS-MKH is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25#include <hal_kernel_types.h>
26#include <hal_uspace.h>
27#include <hal_irqmask.h>
28#include <shared_syscalls.h>
29#include <errno.h>
30#include <thread.h>
31#include <printk.h>
32#include <mapper.h>
33#include <vfs.h>
34#include <process.h>
35#include <vmm.h>
36
37#include <syscalls.h>
38
39////////////////////////////////
40int sys_munmap( void     * vaddr,
41                uint32_t   size )
42{
43    error_t       error;
44    vseg_t      * vseg;
45    reg_t         save_sr;      // required to enable IRQs
46
47        thread_t    * this    = CURRENT_THREAD;
48        process_t   * process = this->process;
49
50#if (DEBUG_SYS_MUNMAP || CONFIG_INSTRUMENTATION_SYSCALLS)
51uint64_t     tm_start = hal_get_cycles();
52#endif
53
54#if DEBUG_SYS_MUNMAP
55if( DEBUG_SYS_MUNMAP < tm_start )
56printk("\n[DBG] %s : thread %x enter / process %x / cycle %d\n",
57__FUNCTION__ , this, process->pid, (uint32_t)tm_start );
58#endif
59
60    // check user buffer is mapped
61    error = vmm_get_vseg( process , (intptr_t)vaddr, &vseg );
62
63    if( error )
64    {
65
66#if DEBUG_SYSCALLS_ERROR
67printk("\n[ERROR] in %s : thread[%x,%x] / user buffer unmapped %x\n",
68__FUNCTION__ , process->pid, this->trdid, (intptr_t)vaddr );
69vmm_display( process , false );
70#endif
71                this->errno = EINVAL;
72                return -1;
73    }
74
75    // enable IRQs
76    hal_enable_irq( &save_sr );
77
78    // call relevant kernel function
79    error = vmm_resize_vseg( process , (intptr_t)vaddr , (intptr_t)size );
80
81    if ( error )
82    {
83
84#if DEBUG_SYSCALLS_ERROR
85printk("\n[ERROR] in %s : cannot remove mapping\n", __FUNCTION__ );
86#endif
87                this->errno = EINVAL;
88                return -1;
89    }
90
91    // restore IRQs
92    hal_restore_irq( save_sr );
93
94#if (DEBUG_SYS_MUNMAP || CONFIG_INSTRUMENTATION_SYSCALLS)
95uint64_t     tm_end = hal_get_cycles();
96#endif
97
98#if CONFIG_INSTRUMENTATION_SYSCALLS
99hal_atomic_add( &syscalls_cumul_cost[SYS_MUNMAP] , tm_end - tm_start );
100hal_atomic_add( &syscalls_occurences[SYS_MUNMAP] , 1 );
101#endif
102
103#if DEBUG_SYS_MUNMAP
104if( DEBUG_SYS_MUNMAP < tm_start )
105printk("\n[DBG] %s : thread %x exit / process %x / cycle %d\n",
106__FUNCTION__ , this, process->pid, (uint32_t)tm_end );
107#endif
108
109    return 0;
110
111}  // end sys_munmap()
112
Note: See TracBrowser for help on using the repository browser.