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

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

[syscalls] add interface in implementation.

Add const where possible, fix protoypes to follow interface.

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