annotate loader/setup_FS.c @ 999:92833c9472e8

Continue implementation of the network streaming part.
author bertrand
date Mon, 04 Jun 2001 17:52:33 +0000
parents 1f7c824033fb
children 72cacd3b8f30
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
236
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
1 #include <string.h>
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
2 #include <stdlib.h>
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
3 #include <errno.h>
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
4 #include <fcntl.h>
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
5 #include <sys/mman.h>
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
6 #include <sys/types.h>
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
7 #include <stdio.h>
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
8 #include <unistd.h>
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
9
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
10 #ifdef __linux__
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
11 #include <asm/unistd.h>
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
12 #include <asm/ldt.h>
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
13 #else
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
14
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
15 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
16 #include <machine/sysarch.h>
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
17 #endif
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
18
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
19 #ifdef __svr4__
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
20 #include <sys/segment.h>
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
21 #include <sys/sysi86.h>
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
22 /* solaris x86: add missing prototype for sysi86() */
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
23 extern int sysi86(int, void*);
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
24 #define TEB_SEL_IDX NUMSYSLDTS
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
25 #endif
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
26
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
27 #define LDT_ENTRIES 8192
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
28 #define LDT_ENTRY_SIZE 8
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
29 #pragma pack(4)
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
30 struct modify_ldt_ldt_s {
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
31 unsigned int entry_number;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
32 unsigned long base_addr;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
33 unsigned int limit;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
34 unsigned int seg_32bit:1;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
35 unsigned int contents:2;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
36 unsigned int read_exec_only:1;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
37 unsigned int limit_in_pages:1;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
38 unsigned int seg_not_present:1;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
39 unsigned int useable:1;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
40 };
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
41
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
42 #define MODIFY_LDT_CONTENTS_DATA 0
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
43 #define MODIFY_LDT_CONTENTS_STACK 1
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
44 #define MODIFY_LDT_CONTENTS_CODE 2
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
45 #endif
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
46
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
47
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
48 /* user level (privilege level: 3) ldt (1<<2) segment selector */
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
49 #define LDT_SEL(idx) ((idx) << 3 | 1 << 2 | 3)
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
50
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
51 #ifndef TEB_SEL_IDX
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
52 #define TEB_SEL_IDX 1
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
53 #endif
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
54
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
55 #define TEB_SEL LDT_SEL(TEB_SEL_IDX)
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
56
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
57 void setup_FS_Segment()
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
58 {
340
1f7c824033fb less, and more informal printfs
arpi_esp
parents: 236
diff changeset
59 #ifdef DETAILED_OUT
236
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
60 printf("Setup FS...");fflush(stdout);
340
1f7c824033fb less, and more informal printfs
arpi_esp
parents: 236
diff changeset
61 #endif
236
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
62 __asm__ __volatile__(
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
63 "movl %0,%%eax; movw %%ax, %%fs" : : "i" (TEB_SEL)
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
64 );
340
1f7c824033fb less, and more informal printfs
arpi_esp
parents: 236
diff changeset
65 #ifdef DETAILED_OUT
236
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
66 printf("OK!\n");
340
1f7c824033fb less, and more informal printfs
arpi_esp
parents: 236
diff changeset
67 #endif
236
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
68 }
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
69
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
70
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
71 /**
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
72 *
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
73 * This should be performed before we create first thread. See remarks
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
74 * for write_ldt(), linux/kernel/ldt.c.
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
75 *
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
76 */
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
77
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
78 static void* fs_seg=NULL;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
79
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
80 #ifdef __linux__
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
81 /* XXX: why is this routine from libc redefined here? */
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
82 /* NOTE: the redefined version ignores the count param, count is hardcoded as 16 */
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
83 static int modify_ldt( int func, struct modify_ldt_ldt_s *ptr,
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
84 unsigned long count )
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
85 {
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
86 int res;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
87 #ifdef __PIC__
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
88 __asm__ __volatile__( "pushl %%ebx\n\t"
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
89 "movl %2,%%ebx\n\t"
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
90 "int $0x80\n\t"
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
91 "popl %%ebx"
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
92 : "=a" (res)
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
93 : "0" (__NR_modify_ldt),
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
94 "r" (func),
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
95 "c" (ptr),
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
96 "d"(16)//sizeof(*ptr) from kernel point of view
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
97 :"esi" );
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
98 #else
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
99 __asm__ __volatile__("int $0x80"
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
100 : "=a" (res)
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
101 : "0" (__NR_modify_ldt),
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
102 "b" (func),
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
103 "c" (ptr),
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
104 "d"(16)
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
105 :"esi");
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
106 #endif /* __PIC__ */
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
107 if (res >= 0) return res;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
108 errno = -res;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
109 return -1;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
110 }
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
111 #endif
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
112
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
113 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
114 static void LDT_EntryToBytes( unsigned long *buffer, const struct modify_ldt_ldt_s *content )
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
115 {
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
116 *buffer++ = ((content->base_addr & 0x0000ffff) << 16) |
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
117 (content->limit & 0x0ffff);
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
118 *buffer = (content->base_addr & 0xff000000) |
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
119 ((content->base_addr & 0x00ff0000)>>16) |
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
120 (content->limit & 0xf0000) |
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
121 (content->contents << 10) |
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
122 ((content->read_exec_only == 0) << 9) |
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
123 ((content->seg_32bit != 0) << 22) |
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
124 ((content->limit_in_pages != 0) << 23) |
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
125 0xf000;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
126 }
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
127 #endif
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
128
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
129 void Setup_LDT_Keeper(){
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
130 struct modify_ldt_ldt_s array;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
131 int fd;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
132 int ret;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
133 void* prev_struct;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
134
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
135 if(fs_seg) return; // already set!
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
136
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
137 fd=open("/dev/zero", O_RDWR);
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
138 fs_seg=mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE, MAP_PRIVATE,
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
139 fd, 0);
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
140 if(fs_seg==(void*)-1)
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
141 {
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
142 perror("ERROR: Couldn't allocate memory for fs segment");
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
143 return;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
144 }
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
145 array.base_addr=(int)fs_seg;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
146 array.entry_number=TEB_SEL_IDX;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
147 array.limit=array.base_addr+getpagesize()-1;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
148 array.seg_32bit=1;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
149 array.read_exec_only=0;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
150 array.seg_not_present=0;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
151 array.contents=MODIFY_LDT_CONTENTS_DATA;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
152 array.limit_in_pages=0;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
153 #ifdef __linux__
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
154 ret=modify_ldt(0x1, &array, sizeof(struct modify_ldt_ldt_s));
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
155 if(ret<0)
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
156 {
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
157 perror("install_fs");
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
158 printf("Couldn't install fs segment, expect segfault\n");
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
159 }
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
160 #endif /*linux*/
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
161
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
162 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
163 {
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
164 unsigned long d[2];
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
165
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
166 LDT_EntryToBytes( d, &array );
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
167 ret = i386_set_ldt(array.entry_number, (union descriptor *)d, 1);
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
168 if (ret < 0)
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
169 {
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
170 perror("install_fs");
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
171 printf("Couldn't install fs segment, expect segfault\n");
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
172 printf("Did you reconfigure the kernel with \"options USER_LDT\"?\n");
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
173 }
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
174 printf("Set_LDT\n");
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
175 }
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
176 #endif /* __NetBSD__ || __FreeBSD__ || __OpenBSD__ */
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
177
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
178 #if defined(__svr4__)
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
179 struct ssd ssd;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
180 ssd.sel = TEB_SEL;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
181 ssd.bo = array.base_addr;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
182 ssd.ls = array.limit - array.base_addr;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
183 ssd.acc1 = ((array.read_exec_only == 0) << 1) |
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
184 (array.contents << 2) |
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
185 0xf0; /* P(resent) | DPL3 | S */
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
186 ssd.acc2 = 0x4; /* byte limit, 32-bit segment */
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
187 if (sysi86(SI86DSCR, &ssd) < 0) {
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
188 perror("sysi86(SI86DSCR)");
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
189 printf("Couldn't install fs segment, expect segfault\n");
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
190 }
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
191 #endif
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
192
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
193 setup_FS_Segment();
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
194
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
195 prev_struct=malloc(8);
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
196 *(void**)array.base_addr=prev_struct;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
197 close(fd);
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
198 }
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
199
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
200 void Restore_LDT_Keeper()
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
201 {
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
202 if(fs_seg==0) return;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
203 munmap((char*)fs_seg, getpagesize());
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
204 }
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
205