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

Last change on this file since 485 was 457, checked in by alain, 6 years ago

This version modifies the exec syscall and fixes a large number of small bugs.
The version number has been updated (0.1)

File size: 2.1 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 <shared_syscalls.h>
28#include <errno.h>
29#include <thread.h>
30#include <printk.h>
31#include <mapper.h>
32#include <vfs.h>
33#include <process.h>
34#include <vmm.h>
35
36////////////////////////////////
37int sys_munmap( void     * vaddr,
38                uint32_t   size )
39{
40    error_t       error;
41
42        thread_t    * this    = CURRENT_THREAD;
43        process_t   * process = this->process;
44
45#if DEBUG_SYS_MUNMAP
46uint64_t tm_start;
47uint64_t tm_end;
48tm_start = hal_get_cycles();
49if( DEBUG_SYS_MUNMAP < tm_start )
50printk("\n[DBG] %s : thread %x enter / process %x / cycle %d\n"
51__FUNCTION__ , this, process->pid, (uint32_t)tm_start );
52#endif
53
54    // call relevant kernel function
55    error = vmm_resize_vseg( process , (intptr_t)vaddr , (intptr_t)size );
56
57    if ( error )
58    {
59
60#if DEBUG_SYSCALLS_ERROR
61printk("\n[ERROR] in %s : cannot remove mapping\n", __FUNCTION__ );
62#endif
63                this->errno = EINVAL;
64                return -1;
65    }
66
67#if DEBUG_SYS_MUNMAP
68tm_end = hal_get_cycles();
69if( DEBUG_SYS_MUNMAP < tm_start )
70printk("\n[DBG] %s : thread %x exit / process %x / cycle %d\n"
71__FUNCTION__ , this, process->pid, (uint32_t)tm_end );
72#endif
73
74    return 0;
75
76}  // end sys_munmap()
77
Note: See TracBrowser for help on using the repository browser.