comparison loader/ldt_keeper.c @ 21290:efc774a1e5a4

fix compilation for win32 dll codec support for intel osx
author nplourde
date Mon, 27 Nov 2006 02:44:06 +0000
parents 2de480457872
children 363c84953547
comparison
equal deleted inserted replaced
21289:fdd55cd8eb2a 21290:efc774a1e5a4
27 #include <sys/mman.h> 27 #include <sys/mman.h>
28 #include <sys/types.h> 28 #include <sys/types.h>
29 #include <stdio.h> 29 #include <stdio.h>
30 #include <unistd.h> 30 #include <unistd.h>
31 #include "osdep/mmap_anon.h" 31 #include "osdep/mmap_anon.h"
32 #include "mp_msg.h"
33 #include "help_mp.h"
32 #ifdef __linux__ 34 #ifdef __linux__
33 #include <asm/unistd.h> 35 #include <asm/unistd.h>
34 #include <asm/ldt.h> 36 #include <asm/ldt.h>
35 // 2.5.xx+ calls this user_desc: 37 // 2.5.xx+ calls this user_desc:
36 #include <linux/version.h> 38 #include <linux/version.h>
101 103
102 /* user level (privilege level: 3) ldt (1<<2) segment selector */ 104 /* user level (privilege level: 3) ldt (1<<2) segment selector */
103 #define LDT_SEL(idx) ((idx) << 3 | 1 << 2 | 3) 105 #define LDT_SEL(idx) ((idx) << 3 | 1 << 2 | 3)
104 106
105 /* i got this value from wine sources, it's the first free LDT entry */ 107 /* i got this value from wine sources, it's the first free LDT entry */
106 #if defined(__FreeBSD__) && defined(LDT_AUTO_ALLOC) 108 #if (defined(__APPLE__) || defined(__FreeBSD__)) && defined(LDT_AUTO_ALLOC)
107 #define TEB_SEL_IDX LDT_AUTO_ALLOC 109 #define TEB_SEL_IDX LDT_AUTO_ALLOC
110 #define USE_LDT_AA
108 #endif 111 #endif
109 112
110 #ifndef TEB_SEL_IDX 113 #ifndef TEB_SEL_IDX
111 #define TEB_SEL_IDX 17 114 #define TEB_SEL_IDX 17
112 #endif 115 #endif
166 return -1; 169 return -1;
167 } 170 }
168 #endif 171 #endif
169 #endif 172 #endif
170 173
171 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) 174 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__APPLE__)
172 static void LDT_EntryToBytes( unsigned long *buffer, const struct modify_ldt_ldt_s *content ) 175 static void LDT_EntryToBytes( unsigned long *buffer, const struct modify_ldt_ldt_s *content )
173 { 176 {
174 *buffer++ = ((content->base_addr & 0x0000ffff) << 16) | 177 *buffer++ = ((content->base_addr & 0x0000ffff) << 16) |
175 (content->limit & 0x0ffff); 178 (content->limit & 0x0ffff);
176 *buffer = (content->base_addr & 0xff000000) | 179 *buffer = (content->base_addr & 0xff000000) |
193 ldt_fs_t* ldt_fs = (ldt_fs_t*) malloc(sizeof(ldt_fs_t)); 196 ldt_fs_t* ldt_fs = (ldt_fs_t*) malloc(sizeof(ldt_fs_t));
194 197
195 if (!ldt_fs) 198 if (!ldt_fs)
196 return NULL; 199 return NULL;
197 200
201 #ifdef __APPLE__
202 if (getenv("DYLD_BIND_AT_LAUNCH") == NULL)
203 mp_msg(MSGT_LOADER, MSGL_WARN, MSGTR_LOADER_DYLD_Warning);
204 #endif /* __APPLE__ */
205
198 fs_seg= 206 fs_seg=
199 ldt_fs->fs_seg = mmap_anon(NULL, getpagesize(), PROT_READ | PROT_WRITE, MAP_PRIVATE, 0); 207 ldt_fs->fs_seg = mmap_anon(NULL, getpagesize(), PROT_READ | PROT_WRITE, MAP_PRIVATE, 0);
200 if (ldt_fs->fs_seg == (void*)-1) 208 if (ldt_fs->fs_seg == (void*)-1)
201 { 209 {
202 perror("ERROR: Couldn't allocate memory for fs segment"); 210 perror("ERROR: Couldn't allocate memory for fs segment");
221 perror("install_fs"); 229 perror("install_fs");
222 printf("Couldn't install fs segment, expect segfault\n"); 230 printf("Couldn't install fs segment, expect segfault\n");
223 } 231 }
224 #endif /*linux*/ 232 #endif /*linux*/
225 233
226 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) 234 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__APPLE__)
227 { 235 {
228 unsigned long d[2]; 236 unsigned long d[2];
229 237
230 LDT_EntryToBytes( d, &array ); 238 LDT_EntryToBytes( d, &array );
231 #if defined(__FreeBSD__) && defined(LDT_AUTO_ALLOC) 239 #ifdef USE_LDT_AA
232 ret = i386_set_ldt(LDT_AUTO_ALLOC, (union descriptor *)d, 1); 240 ret = i386_set_ldt(LDT_AUTO_ALLOC, (union descriptor *)d, 1);
233 array.entry_number = ret; 241 array.entry_number = ret;
234 fs_ldt = ret; 242 fs_ldt = ret;
235 #else 243 #else
236 ret = i386_set_ldt(array.entry_number, (union descriptor *)d, 1); 244 ret = i386_set_ldt(array.entry_number, (union descriptor *)d, 1);
243 #ifdef __OpenBSD__ 251 #ifdef __OpenBSD__
244 printf("On newer OpenBSD systems did you set machdep.userldt to 1?\n"); 252 printf("On newer OpenBSD systems did you set machdep.userldt to 1?\n");
245 #endif 253 #endif
246 } 254 }
247 } 255 }
248 #endif /* __NetBSD__ || __FreeBSD__ || __OpenBSD__ || __DragonFly__ */ 256 #endif /* __NetBSD__ || __FreeBSD__ || __OpenBSD__ || __DragonFly__ || __APPLE__ */
249 257
250 #if defined(__svr4__) 258 #if defined(__svr4__)
251 { 259 {
252 struct ssd ssd; 260 struct ssd ssd;
253 ssd.sel = LDT_SEL(TEB_SEL_IDX); 261 ssd.sel = LDT_SEL(TEB_SEL_IDX);