annotate loader/ext.c @ 113:f6f8f53b75ad

common FIFO code moved to fifo.c
author arpi_esp
date Fri, 16 Mar 2001 00:06:50 +0000
parents 3b5f5d1c5041
children 28091b3caff9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1 /********************************************************
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
2 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
3 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
4 * Stub functions for Wine module
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
5 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
6 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
7 ********************************************************/
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
8 #include <config.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
9 #ifdef HAVE_MALLOC_H
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
10 #include <malloc.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
11 #else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
12 #include <stdlib.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
13 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
14 #include <stdio.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
15 #include <unistd.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
16 #include <sys/mman.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
17 #include <errno.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
18 #include <fcntl.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
19 #include <string.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
20 #include <stdarg.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
21 #include <wine/windef.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
22 //#include <wine/winbase.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
23 int dbg_header_err( const char *dbg_channel, const char *func )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
24 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
25 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
26 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
27 int dbg_header_warn( const char *dbg_channel, const char *func )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
28 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
29 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
30 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
31 int dbg_header_fixme( const char *dbg_channel, const char *func )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
32 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
33 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
34 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
35 int dbg_header_trace( const char *dbg_channel, const char *func )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
36 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
37 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
38 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
39 int dbg_vprintf( const char *format, ... )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
40 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
41 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
42 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
43 int __vprintf( const char *format, ... )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
44 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
45 #ifdef DETAILED_OUT
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
46 va_list va;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
47 va_start(va, format);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
48 vprintf(format, va);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
49 va_end(va);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
50 fflush(stdout);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
51 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
55 int GetProcessHeap()
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
56 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
57 return 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
58 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
59
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
60 void* HeapAlloc(int heap, int flags, int size)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
61 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
62 if(flags & 0x8)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
63 return calloc(size, 1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
64 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
65 return malloc(size);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
66 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
67
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
68 int HeapFree(int heap, int flags, void* mem)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
69 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
70 free(mem);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
71 return 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
72 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
73
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
74 static int last_error;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
75
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
76 int GetLastError()
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
77 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
78 return last_error;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
79 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
80
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
81 int SetLastError(int error)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
82 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
83 return last_error=error;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
84 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
85
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
86 int ReadFile(int handle, void* mem, unsigned long size, long* result, long flags)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
87 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
88 *result=read(handle, mem, size);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
89 return *result;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
90 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
91 int lstrcmpiA(const char* c1, const char* c2)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
92 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
93 return strcasecmp(c1,c2);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
94 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
95 int lstrcpynA(char* dest, const char* src, int num)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
96 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
97 return strncmp(dest,src,num);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
98 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
99 int lstrlenA(const char* s)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
100 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
101 return strlen(s);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
102 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
103 int lstrlenW(const short* s)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
104 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
105 int l;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
106 if(!s)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
107 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
108 l=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
109 while(s[l])
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
110 l++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
111 return l;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
112 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
113 int lstrcpynWtoA(char* dest, const char* src, int count)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
114 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
115 int moved=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
116 if((dest==0) || (src==0))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
117 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
118 while(moved<count)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
119 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
120 *dest=*src;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
121 moved++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
122 if(*src==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
123 return moved;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
124 src++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
125 dest++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
126 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
127 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
128 int wcsnicmp(const unsigned short* s1, const unsigned short* s2, int n)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
129 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
130 if(s1==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
131 return;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
132 if(s2==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
133 return;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
134 while(n>0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
135 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
136 if(*s1<*s2)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
137 return -1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
138 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
139 if(*s1>*s2)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
140 return 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
141 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
142 if(*s1==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
143 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
144 s1++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
145 s2++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
146 n--;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
147 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
148 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
149 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
150
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
151
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
152 int IsBadReadPtr(void* data, int size)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
153 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
154 if(size==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
155 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
156 if(data==NULL)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
157 return 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
158 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
159 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
160 char* HEAP_strdupA(const char* string)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
161 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
162 // return strdup(string);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
163 char* answ=malloc(strlen(string)+1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
164 strcpy(answ, string);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
165 return answ;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
166 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
167 short* HEAP_strdupAtoW(void* heap, void* hz, const char* string)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
168 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
169 int size, i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
170 short* answer;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
171 if(string==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
172 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
173 size=strlen(string);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
174 answer=malloc(size+size+2);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
175 for(i=0; i<=size; i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
176 answer[i]=(short)string[i];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
177 return answer;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
178 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
179 char* HEAP_strdupWtoA(void* heap, void* hz, const short* string)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
180 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
181 int size, i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
182 char* answer;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
183 if(string==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
184 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
185 size=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
186 while(string[size])
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
187 size++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
188 answer=malloc(size+2);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
189 for(i=0; i<=size; i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
190 answer[i]=(char)string[i];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
191 return answer;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
192 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
193
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
194 /***********************************************************************
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
195 * FILE_dommap
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
196 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
197
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
198 //#define MAP_PRIVATE
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
199 //#define MAP_SHARED
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
200 #undef MAP_ANON
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
201 LPVOID FILE_dommap( int unix_handle, LPVOID start,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
202 DWORD size_high, DWORD size_low,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
203 DWORD offset_high, DWORD offset_low,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
204 int prot, int flags )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
205 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
206 int fd = -1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
207 int pos;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
208 LPVOID ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
209
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
210 if (size_high || offset_high)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
211 printf("offsets larger than 4Gb not supported\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
212
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
213 if (unix_handle == -1)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
214 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
215 #ifdef MAP_ANON
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
216 // printf("Anonymous\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
217 flags |= MAP_ANON;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
218 #else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
219 static int fdzero = -1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
220
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
221 if (fdzero == -1)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
222 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
223 if ((fdzero = open( "/dev/zero", O_RDONLY )) == -1)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
224 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
225 perror( "/dev/zero: open" );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
226 exit(1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
227 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
228 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
229 fd = fdzero;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
230 #endif /* MAP_ANON */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
231 /* Linux EINVAL's on us if we don't pass MAP_PRIVATE to an anon mmap */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
232 #ifdef MAP_SHARED
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
233 flags &= ~MAP_SHARED;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
234 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
235 #ifdef MAP_PRIVATE
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
236 flags |= MAP_PRIVATE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
237 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
238 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
239 else fd = unix_handle;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
240 // printf("fd %x, start %x, size %x, pos %x, prot %x\n",fd,start,size_low, offset_low, prot);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
241 // if ((ret = mmap( start, size_low, prot,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
242 // flags, fd, offset_low )) != (LPVOID)-1)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
243 if ((ret = mmap( start, size_low, prot,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
244 MAP_PRIVATE | MAP_FIXED, fd, offset_low )) != (LPVOID)-1)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
245 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
246 // printf("address %08x\n", *(int*)ret);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
247 // printf("%x\n", ret);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
248 return ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
249 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
250
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
251 // printf("mmap %d\n", errno);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
252
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
253 /* mmap() failed; if this is because the file offset is not */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
254 /* page-aligned (EINVAL), or because the underlying filesystem */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
255 /* does not support mmap() (ENOEXEC), we do it by hand. */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
256
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
257 if (unix_handle == -1) return ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
258 if ((errno != ENOEXEC) && (errno != EINVAL)) return ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
259 if (prot & PROT_WRITE)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
260 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
261 /* We cannot fake shared write mappings */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
262 #ifdef MAP_SHARED
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
263 if (flags & MAP_SHARED) return ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
264 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
265 #ifdef MAP_PRIVATE
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
266 if (!(flags & MAP_PRIVATE)) return ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
267 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
268 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
269 /* printf( "FILE_mmap: mmap failed (%d), faking it\n", errno );*/
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
270 /* Reserve the memory with an anonymous mmap */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
271 ret = FILE_dommap( -1, start, size_high, size_low, 0, 0,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
272 PROT_READ | PROT_WRITE, flags );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
273 if (ret == (LPVOID)-1)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
274 // {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
275 // perror(
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
276 return ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
277 /* Now read in the file */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
278 if ((pos = lseek( fd, offset_low, SEEK_SET )) == -1)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
279 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
280 FILE_munmap( ret, size_high, size_low );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
281 // printf("lseek\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
282 return (LPVOID)-1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
283 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
284 read( fd, ret, size_low );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
285 lseek( fd, pos, SEEK_SET ); /* Restore the file pointer */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
286 mprotect( ret, size_low, prot ); /* Set the right protection */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
287 // printf("address %08x\n", *(int*)ret);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
288 return ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
289 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
290
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
291
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
292 /***********************************************************************
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
293 * FILE_munmap
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
294 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
295 int FILE_munmap( LPVOID start, DWORD size_high, DWORD size_low )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
296 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
297 if (size_high)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
298 printf("offsets larger than 4Gb not supported\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
299 return munmap( start, size_low );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
300 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
301 static int mapping_size=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
302
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
303 struct file_mapping_s;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
304 typedef struct file_mapping_s
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
305 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
306 int mapping_size;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
307 char* name;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
308 HANDLE handle;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
309 struct file_mapping_s* next;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
310 struct file_mapping_s* prev;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
311 }file_mapping;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
312 static file_mapping* fm=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
313
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
314
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
315
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
316 #define PAGE_NOACCESS 0x01
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
317 #define PAGE_READONLY 0x02
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
318 #define PAGE_READWRITE 0x04
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
319 #define PAGE_WRITECOPY 0x08
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
320 #define PAGE_EXECUTE 0x10
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
321 #define PAGE_EXECUTE_READ 0x20
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
322 #define PAGE_EXECUTE_READWRITE 0x40
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
323 #define PAGE_EXECUTE_WRITECOPY 0x80
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
324 #define PAGE_GUARD 0x100
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
325 #define PAGE_NOCACHE 0x200
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
326
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
327 HANDLE CreateFileMappingA(int hFile, void* lpAttr,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
328 DWORD flProtect, DWORD dwMaxHigh, DWORD dwMaxLow, const char* name)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
329 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
330 unsigned int len;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
331 HANDLE answer;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
332 int anon=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
333 int mmap_access=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
334 if(hFile<0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
335 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
336 anon=1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
337 hFile=open("/dev/zero", O_RDWR);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
338 if(hFile<0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
339 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
340 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
341 if(!anon)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
342 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
343 len=lseek(hFile, 0, SEEK_END);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
344 lseek(hFile, 0, SEEK_SET);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
345 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
346 else len=dwMaxLow;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
347
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
348 if(flProtect & PAGE_READONLY)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
349 mmap_access |=PROT_READ;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
350 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
351 mmap_access |=PROT_READ|PROT_WRITE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
352
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
353 answer=(HANDLE)mmap(NULL, len, mmap_access, MAP_PRIVATE, hFile, 0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
354 if(anon)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
355 close(hFile);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
356 if(answer!=(HANDLE)-1)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
357 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
358 if(fm==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
359 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
360 fm=malloc(sizeof(file_mapping));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
361 fm->prev=NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
362 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
363 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
364 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
365 fm->next=malloc(sizeof(file_mapping));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
366 fm->next->prev=fm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
367 fm=fm->next;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
368 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
369 fm->next=NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
370 fm->handle=answer;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
371 if(name)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
372 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
373 fm->name=malloc(strlen(name)+1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
374 strcpy(fm->name, name);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
375 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
376 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
377 fm->name=NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
378 fm->mapping_size=len;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
379
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
380 if(anon)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
381 close(hFile);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
382 return answer;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
383 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
384 return (HANDLE)0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
385 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
386 int UnmapViewOfFile(HANDLE handle)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
387 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
388 file_mapping* p;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
389 int result;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
390 if(fm==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
391 return (HANDLE)0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
392 for(p=fm; p; p=p->next)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
393 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
394 if(p->handle==handle)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
395 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
396 result=munmap((void*)handle, p->mapping_size);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
397 if(p->next)p->next->prev=p->prev;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
398 if(p->prev)p->prev->next=p->next;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
399 if(p->name)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
400 free(p->name);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
401 if(p==fm)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
402 fm=p->prev;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
403 free(p);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
404 return result;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
405 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
406 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
407 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
408 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
409 //static int va_size=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
410 struct virt_alloc_s;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
411 typedef struct virt_alloc_s
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
412 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
413 int mapping_size;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
414 char* address;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
415 struct virt_alloc_s* next;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
416 struct virt_alloc_s* prev;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
417 int state;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
418 }virt_alloc;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
419 static virt_alloc* vm=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
420 #define MEM_COMMIT 0x00001000
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
421 #define MEM_RESERVE 0x00002000
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
422
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
423 void* VirtualAlloc(void* address, DWORD size, DWORD type, DWORD protection)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
424 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
425 void* answer;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
426 int fd=open("/dev/zero", O_RDWR);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
427 size=(size+0xffff)&(~0xffff);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
428 // printf("VirtualAlloc(0x%08X, %d)\n", address
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
429 if(address!=0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
430 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
431 //check whether we can allow to allocate this
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
432 virt_alloc* str=vm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
433 while(str)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
434 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
435 if((unsigned)address>=(unsigned)str->address+str->mapping_size)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
436 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
437 str=str->prev;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
438 continue;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
439 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
440 if((unsigned)address+size<(unsigned)str->address)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
441 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
442 str=str->prev;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
443 continue;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
444 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
445 if(str->state==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
446 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
447 #warning FIXME
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
448 if(((unsigned)address+size<(unsigned)str->address+str->mapping_size) && (type & MEM_COMMIT))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
449 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
450 close(fd);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
451 return address; //returning previously reserved memory
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
452 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
453 return NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
454 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
455 close(fd);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
456 return NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
457 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
458 answer=mmap(address, size, PROT_READ | PROT_WRITE | PROT_EXEC,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
459 MAP_FIXED | MAP_PRIVATE, fd, 0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
460 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
461 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
462 answer=mmap(address, size, PROT_READ | PROT_WRITE | PROT_EXEC,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
463 MAP_PRIVATE, fd, 0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
464 // answer=FILE_dommap(-1, address, 0, size, 0, 0,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
465 // PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
466 close(fd);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
467 if(answer==(void*)-1)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
468 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
469 printf("Error no %d\n", errno);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
470 printf("VirtualAlloc(0x%08X, %d) failed\n", address, size);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
471 return NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
472 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
473 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
474 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
475 virt_alloc *new_vm=malloc(sizeof(virt_alloc));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
476 new_vm->mapping_size=size;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
477 new_vm->address=answer;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
478 new_vm->prev=vm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
479 if(type == MEM_RESERVE)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
480 new_vm->state=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
481 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
482 new_vm->state=1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
483 if(vm)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
484 vm->next=new_vm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
485 vm=new_vm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
486 vm->next=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
487 // if(va_size!=0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
488 // printf("Multiple VirtualAlloc!\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
489 // printf("answer=0x%08x\n", answer);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
490 return answer;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
491 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
492 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
493 int VirtualFree(void* address, int t1, int t2)//not sure
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
494 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
495 virt_alloc* str=vm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
496 int answer;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
497 while(str)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
498 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
499 if(address!=str->address)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
500 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
501 str=str->prev;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
502 continue;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
503 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
504 answer=munmap(str->address, str->mapping_size);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
505 if(str->next)str->next->prev=str->prev;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
506 if(str->prev)str->prev->next=str->next;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
507 if(vm==str)vm=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
508 free(str);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
509 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
510 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
511 return -1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
512 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
513
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
514 int WideCharToMultiByte(unsigned int codepage, long flags, const short* src,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
515 int srclen,char* dest, int destlen, const char* defch, int* used_defch)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
516 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
517 int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
518 if(src==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
519 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
520 for(i=0; i<srclen; i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
521 printf("%c", src[i]);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
522 printf("\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
523 if(dest==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
524 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
525 for(i=0; i<srclen; i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
526 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
527 src++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
528 if(*src==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
529 return i+1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
530 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
531 return srclen+1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
532 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
533 if(used_defch)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
534 *used_defch=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
535 for(i=0; i<min(srclen, destlen); i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
536 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
537 *dest=(char)*src;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
538 dest++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
539 src++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
540 if(*src==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
541 return i+1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
542 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
543 return min(srclen, destlen);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
544 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
545 int MultiByteToWideChar(unsigned int codepage,long flags, const char* src, int srclen,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
546 short* dest, int destlen)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
547 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
548 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
549 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
550 HANDLE OpenFileMappingA(long access, long prot, char* name)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
551 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
552 file_mapping* p;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
553 if(fm==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
554 return (HANDLE)0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
555 if(name==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
556 return (HANDLE)0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
557 for(p=fm; p; p=p->prev)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
558 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
559 if(p->name==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
560 continue;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
561 if(strcmp(p->name, name)==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
562 return p->handle;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
563 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
564 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
565 }