vserver 2.0 rc7
[linux-2.6.git] / arch / um / kernel / skas / mem_user.c
1 /* 
2  * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3  * Licensed under the GPL
4  */
5
6 #include <errno.h>
7 #include <sys/mman.h>
8 #include "mem_user.h"
9 #include "mem.h"
10 #include "user.h"
11 #include "os.h"
12 #include "proc_mm.h"
13
14 void map(int fd, unsigned long virt, unsigned long len, int r, int w,
15          int x, int phys_fd, unsigned long long offset)
16 {
17         struct proc_mm_op map;
18         int prot, n;
19
20         prot = (r ? PROT_READ : 0) | (w ? PROT_WRITE : 0) | 
21                 (x ? PROT_EXEC : 0);
22
23         map = ((struct proc_mm_op) { .op        = MM_MMAP,
24                                      .u         = 
25                                      { .mmap    = 
26                                        { .addr          = virt,
27                                          .len           = len,
28                                          .prot          = prot,
29                                          .flags         = MAP_SHARED | 
30                                                           MAP_FIXED,
31                                          .fd            = phys_fd,
32                                          .offset        = offset
33                                        } } } );
34         n = os_write_file(fd, &map, sizeof(map));
35         if(n != sizeof(map)) 
36                 printk("map : /proc/mm map failed, err = %d\n", -n);
37 }
38
39 int unmap(int fd, void *addr, unsigned long len)
40 {
41         struct proc_mm_op unmap;
42         int n;
43
44         unmap = ((struct proc_mm_op) { .op      = MM_MUNMAP,
45                                        .u       = 
46                                        { .munmap        = 
47                                          { .addr        = (unsigned long) addr,
48                                            .len         = len } } } );
49         n = os_write_file(fd, &unmap, sizeof(unmap));
50         if(n != sizeof(unmap)) {
51                 if(n < 0)
52                         return(n);
53                 else if(n > 0)
54                         return(-EIO);
55         }
56
57         return(0);
58 }
59
60 int protect(int fd, unsigned long addr, unsigned long len, int r, int w, 
61             int x, int must_succeed)
62 {
63         struct proc_mm_op protect;
64         int prot, n;
65
66         prot = (r ? PROT_READ : 0) | (w ? PROT_WRITE : 0) | 
67                 (x ? PROT_EXEC : 0);
68
69         protect = ((struct proc_mm_op) { .op    = MM_MPROTECT,
70                                        .u       = 
71                                        { .mprotect      = 
72                                          { .addr        = (unsigned long) addr,
73                                            .len         = len,
74                                            .prot        = prot } } } );
75
76         n = os_write_file(fd, &protect, sizeof(protect));
77         if(n != sizeof(protect)) {
78                 if(n == 0) return(0);
79
80                 if(must_succeed)
81                         panic("protect failed, err = %d", -n);
82
83                 return(-EIO);
84         }
85
86         return(0);
87 }
88
89 void before_mem_skas(unsigned long unused)
90 {
91 }
92
93 /*
94  * Overrides for Emacs so that we follow Linus's tabbing style.
95  * Emacs will notice this stuff at the end of the file and automatically
96  * adjust the settings for this buffer only.  This must remain at the end
97  * of the file.
98  * ---------------------------------------------------------------------------
99  * Local variables:
100  * c-file-style: "linux"
101  * End:
102  */