Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / arch / um / kernel / tt / mem_user.c
1 /* 
2  * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3  * Licensed under the GPL
4  */
5
6 #include <stdlib.h>
7 #include <stdio.h>
8 #include <unistd.h>
9 #include <string.h>
10 #include <errno.h>
11 #include <sys/mman.h>
12 #include "tt.h"
13 #include "mem_user.h"
14 #include "user_util.h"
15 #include "os.h"
16
17 void remap_data(void *segment_start, void *segment_end, int w)
18 {
19         void *addr;
20         unsigned long size;
21         int data, prot;
22
23         if(w) prot = PROT_WRITE;
24         else prot = 0;
25         prot |= PROT_READ | PROT_EXEC;
26         size = (unsigned long) segment_end - 
27                 (unsigned long) segment_start;
28         data = create_mem_file(size);
29         addr = mmap(NULL, size, PROT_WRITE | PROT_READ, MAP_SHARED, data, 0);
30         if(addr == MAP_FAILED){
31                 perror("mapping new data segment");
32                 exit(1);
33         }
34         memcpy(addr, segment_start, size);
35         if(switcheroo(data, prot, addr, segment_start, size) < 0){
36                 printf("switcheroo failed\n");
37                 exit(1);
38         }
39 }
40
41 /*
42  * Overrides for Emacs so that we follow Linus's tabbing style.
43  * Emacs will notice this stuff at the end of the file and automatically
44  * adjust the settings for this buffer only.  This must remain at the end
45  * of the file.
46  * ---------------------------------------------------------------------------
47  * Local variables:
48  * c-file-style: "linux"
49  * End:
50  */