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