aboutsummaryrefslogtreecommitdiffstats
path: root/arch/um/kernel/skas/mem_user.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /arch/um/kernel/skas/mem_user.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'arch/um/kernel/skas/mem_user.c')
-rw-r--r--arch/um/kernel/skas/mem_user.c102
1 files changed, 102 insertions, 0 deletions
diff --git a/arch/um/kernel/skas/mem_user.c b/arch/um/kernel/skas/mem_user.c
new file mode 100644
index 000000000000..1310bf1e88d1
--- /dev/null
+++ b/arch/um/kernel/skas/mem_user.c
@@ -0,0 +1,102 @@
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
14void 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
39int 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
60int 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
89void 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 */