comparison loader/ldt_keeper.c @ 2139:e06cabbd1a9b

changes merged back from avifile cvs
author arpi
date Mon, 08 Oct 2001 22:26:14 +0000
parents c1edbb8bfc0c
children 0ecadf56dc05
comparison
equal deleted inserted replaced
2138:b2c97c56c50e 2139:e06cabbd1a9b
3 * This file MUST be in main library because LDT must 3 * This file MUST be in main library because LDT must
4 * be modified before program creates first thread 4 * be modified before program creates first thread
5 * - avifile includes this file from C++ code 5 * - avifile includes this file from C++ code
6 * and initializes it at the start of player! 6 * and initializes it at the start of player!
7 */ 7 */
8
9 #include "ldt_keeper.h"
8 10
9 #include <string.h> 11 #include <string.h>
10 #include <stdlib.h> 12 #include <stdlib.h>
11 #include <errno.h> 13 #include <errno.h>
12 #include <fcntl.h> 14 #include <fcntl.h>
13 #include <sys/mman.h> 15 #include <sys/mman.h>
14 #include <sys/types.h> 16 #include <sys/types.h>
15 #include <stdio.h> 17 #include <stdio.h>
16 #include <unistd.h> 18 #include <unistd.h>
17
18 #ifdef __linux__ 19 #ifdef __linux__
19 #include <asm/unistd.h> 20 #include <asm/unistd.h>
20 #include <asm/ldt.h> 21 #include <asm/ldt.h>
21 #else 22 #else
22 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) 23 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
34 extern int sysi86(int, void*); 35 extern int sysi86(int, void*);
35 #ifdef __cplusplus 36 #ifdef __cplusplus
36 } 37 }
37 #endif 38 #endif
38 39
39 #ifndef NUMSYSLDTS /* SunOS 2.5.1 does not define NUMSYSLDTS */ 40 #ifndef NUMSYSLDTS /* SunOS 2.5.1 does not define NUMSYSLDTS */
40 #define NUMSYSLDTS 6 /* Let's hope the SunOS 5.8 value is OK */ 41 #define NUMSYSLDTS 6 /* Let's hope the SunOS 5.8 value is OK */
41 #endif 42 #endif
42 43
43 #define TEB_SEL_IDX NUMSYSLDTS 44 #define TEB_SEL_IDX NUMSYSLDTS
44 #endif 45 #endif
45 46
70 #ifndef TEB_SEL_IDX 71 #ifndef TEB_SEL_IDX
71 #define TEB_SEL_IDX 1 72 #define TEB_SEL_IDX 1
72 #endif 73 #endif
73 #define TEB_SEL LDT_SEL(TEB_SEL_IDX) 74 #define TEB_SEL LDT_SEL(TEB_SEL_IDX)
74 75
75 #include "ldt_keeper.h"
76
77 /** 76 /**
78 * 77 *
79 * This should be performed before we create first thread. See remarks 78 * This should be performed before we create first thread. See remarks
80 * for write_ldt(), linux/kernel/ldt.c. 79 * for write_ldt(), linux/kernel/ldt.c.
81 * 80 *
82 */ 81 */
83 82
84 static void* fs_seg=NULL; 83 static void* fs_seg = NULL;
85 static char* prev_struct=NULL; 84 static char* prev_struct = NULL;
86 /** 85 /**
87 * here is a small logical problem with Restore for multithreaded programs - 86 * here is a small logical problem with Restore for multithreaded programs -
88 * in C++ we use static class for this... 87 * in C++ we use static class for this...
89 */ 88 */
90 89
198 } 197 }
199 #endif /* __NetBSD__ || __FreeBSD__ || __OpenBSD__ */ 198 #endif /* __NetBSD__ || __FreeBSD__ || __OpenBSD__ */
200 199
201 #if defined(__svr4__) 200 #if defined(__svr4__)
202 { 201 {
203 struct ssd ssd; 202 struct ssd ssd;
204 ssd.sel = TEB_SEL; 203 ssd.sel = TEB_SEL;
205 ssd.bo = array.base_addr; 204 ssd.bo = array.base_addr;
206 ssd.ls = array.limit - array.base_addr; 205 ssd.ls = array.limit - array.base_addr;
207 ssd.acc1 = ((array.read_exec_only == 0) << 1) | 206 ssd.acc1 = ((array.read_exec_only == 0) << 1) |
208 (array.contents << 2) | 207 (array.contents << 2) |
209 0xf0; /* P(resent) | DPL3 | S */ 208 0xf0; /* P(resent) | DPL3 | S */
210 ssd.acc2 = 0x4; /* byte limit, 32-bit segment */ 209 ssd.acc2 = 0x4; /* byte limit, 32-bit segment */
211 if (sysi86(SI86DSCR, &ssd) < 0) { 210 if (sysi86(SI86DSCR, &ssd) < 0) {
212 perror("sysi86(SI86DSCR)"); 211 perror("sysi86(SI86DSCR)");
213 printf("Couldn't install fs segment, expect segfault\n"); 212 printf("Couldn't install fs segment, expect segfault\n");
214 } 213 }
215 } 214 }
216 #endif 215 #endif
217 216
218 Setup_FS_Segment(); 217 Setup_FS_Segment();
219 218