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

Last change on this file since 624 was 624, checked in by alain, 3 years ago

Fix several bugs to use the instruction MMU in kernel mode
in replacement of the instruction address extension register,
and remove the "kentry" segment.

This version is running on the tsar_generic_iob" platform.

One interesting bug: the cp0_ebase defining the kernel entry point
(for interrupts, exceptions and syscalls) must be initialized
early in kernel_init(), because the VFS initialisation done by
kernel_ini() uses RPCs, and RPCs uses Inter-Processor-Interrup.

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 );
69hal_vmm_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.