annotate loader/ext.c @ 284:1ddac77b0d43

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