source: trunk/kernel/syscalls/sys_mcntl.c @ 127

Last change on this file since 127 was 1, checked in by alain, 8 years ago

First import

File size: 2.7 KB
RevLine 
[1]1/*
2 * kern/sys_mcntl.c - lets the process control some aspect of its memory managment
3 *
4 * Copyright (c) 2008,2009,2010,2011,2012 Ghassan Almaless
5 * Copyright (c) 2011,2012 UPMC Sorbonne Universites
6 *
7 * This file is part of ALMOS-kernel.
8 *
9 * ALMOS-kernel is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2.0 of the License.
12 *
13 * ALMOS-kernel is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with ALMOS-kernel; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23#include <types.h>
24#include <errno.h>
25#include <syscall.h>
26#include <cluster.h>
27#include <cpu.h>
28#include <vmm.h>
29#include <pmm.h>
30#include <task.h>
31#include <thread.h>
32#include <page.h>
33
34/* TODO: implement the MCNTL_MOVE operation */
35int sys_mcntl(int op, uint_t vaddr, size_t len, minfo_t *pinfo)
36{
37        minfo_t uinfo;
38        pmm_page_info_t info;
39        struct ppm_s *ppm;
40        struct cluster_s *cluster;
41        error_t err;
42
43#if 0
44        err = cpu_copy_from_uspace(&uinfo, pinfo, sizeof(*pinfo));
45
46        if(err) goto SYS_MCNTL_ERR;
47#endif
48
49        if(op == MCNTL_L1_iFLUSH)
50        {
51                pmm_cache_flush(PMM_TEXT);
52                return 0;
53        }
54
55        if((vaddr == 0) || (op >= MCNTL_OPS_NR) || (pinfo == NULL))
56        {
57                err = EINVAL;
58                goto SYS_MCNTL_ERR;
59        }
60
61        vaddr = ARROUND_DOWN(vaddr, PMM_PAGE_SIZE);
62
63        if(NOT_IN_USPACE((uint_t)vaddr + (len * PMM_PAGE_SIZE)) || 
64           NOT_IN_USPACE((uint_t)pinfo + sizeof(*pinfo)))
65        {
66                err = EACCES;
67                goto SYS_MCNTL_ERR;
68        }
69
70        err = pmm_get_page(&current_task->vmm.pmm, vaddr, &info);
71
72        if(err) goto SYS_MCNTL_ERR;
73
74        ppm = pmm_ppn2ppm(info.ppn);
75
76        if(ppm->signature != PPM_ID)
77        {
78                err = EIO;
79                goto SYS_MCNTL_ERR;
80        }
81
82        cluster = ppm_get_cluster(ppm);
83
84        uinfo.mi_cid = cluster->id;
85        uinfo.mi_cx  = cluster->x_coord;
86        uinfo.mi_cy  = cluster->y_coord;
87        uinfo.mi_cz  = cluster->z_coord;
88
89        printk(INFO, "%s: cid %d, cx %d, cy %d, cz %d\n", 
90               __FUNCTION__,
91               uinfo.mi_cid,
92               uinfo.mi_cx,
93               uinfo.mi_cy,
94               uinfo.mi_cz);
95
96        err = cpu_copy_to_uspace(pinfo, &uinfo, sizeof(*pinfo));
97
98        if(err) 
99        { 
100                printk(INFO, "%s: error copying result to userland, err %d\n", 
101                       __FUNCTION__,
102                       err);
103
104                err = EBADE; 
105                goto SYS_MCNTL_ERR;
106        }
107
108        return 0;
109
110SYS_MCNTL_ERR:
111        printk(DEBUG, "DEBUG: %s: cpu %d, tid %x, vaddr %x, err %d\n", 
112               __FUNCTION__,
113               cpu_get_id(),
114               current_thread,
115               vaddr,
116               err);
117
118        current_thread->info.errno = err;
119        return err; 
120}
Note: See TracBrowser for help on using the repository browser.