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