annotate loader/setup_FS.c @ 1632:77cf72182c7f

status management
author arpi
date Wed, 22 Aug 2001 19:43:23 +0000
parents d8c1b0b38edc
children 73c8f54305b1
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>
1307
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 1020
diff changeset
13 #else /* !__linux__ */
236
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
1307
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 1020
diff changeset
25 #endif /* __svr4__ */
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 1020
diff changeset
26
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 1020
diff changeset
27
236
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
28
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
29 #define LDT_ENTRIES 8192
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
30 #define LDT_ENTRY_SIZE 8
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
31 #pragma pack(4)
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
32 struct modify_ldt_ldt_s {
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
33 unsigned int entry_number;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
34 unsigned long base_addr;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
35 unsigned int limit;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
36 unsigned int seg_32bit:1;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
37 unsigned int contents:2;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
38 unsigned int read_exec_only:1;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
39 unsigned int limit_in_pages:1;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
40 unsigned int seg_not_present:1;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
41 unsigned int useable:1;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
42 };
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
43
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
44 #define MODIFY_LDT_CONTENTS_DATA 0
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
45 #define MODIFY_LDT_CONTENTS_STACK 1
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
46 #define MODIFY_LDT_CONTENTS_CODE 2
1307
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 1020
diff changeset
47 #endif /* !__linux__ */
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 1020
diff changeset
48
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 1020
diff changeset
49 #include "setup_FS.h"
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 1020
diff changeset
50
236
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
51
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
52
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
53 /* user level (privilege level: 3) ldt (1<<2) segment selector */
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
54 #define LDT_SEL(idx) ((idx) << 3 | 1 << 2 | 3)
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
55
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
56 #ifndef TEB_SEL_IDX
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
57 #define TEB_SEL_IDX 1
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
58 #endif
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
59
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
60 #define TEB_SEL LDT_SEL(TEB_SEL_IDX)
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
61
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
62 void setup_FS_Segment()
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
63 {
340
1f7c824033fb less, and more informal printfs
arpi_esp
parents: 236
diff changeset
64 #ifdef DETAILED_OUT
236
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
65 printf("Setup FS...");fflush(stdout);
340
1f7c824033fb less, and more informal printfs
arpi_esp
parents: 236
diff changeset
66 #endif
236
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
67 __asm__ __volatile__(
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
68 "movl %0,%%eax; movw %%ax, %%fs" : : "i" (TEB_SEL)
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
69 );
340
1f7c824033fb less, and more informal printfs
arpi_esp
parents: 236
diff changeset
70 #ifdef DETAILED_OUT
236
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
71 printf("OK!\n");
340
1f7c824033fb less, and more informal printfs
arpi_esp
parents: 236
diff changeset
72 #endif
236
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
73 }
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
74
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 * This should be performed before we create first thread. See remarks
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
79 * for write_ldt(), linux/kernel/ldt.c.
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
80 *
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
81 */
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
82
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
83 static void* fs_seg=NULL;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
84
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
85 #ifdef __linux__
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
86 /* XXX: why is this routine from libc redefined here? */
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
87 /* 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
88 static int modify_ldt( int func, struct modify_ldt_ldt_s *ptr,
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
89 unsigned long count )
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
90 {
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
91 int res;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
92 #ifdef __PIC__
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
93 __asm__ __volatile__( "pushl %%ebx\n\t"
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
94 "movl %2,%%ebx\n\t"
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
95 "int $0x80\n\t"
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
96 "popl %%ebx"
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
97 : "=a" (res)
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
98 : "0" (__NR_modify_ldt),
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
99 "r" (func),
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
100 "c" (ptr),
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
101 "d"(16)//sizeof(*ptr) from kernel point of view
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
102 :"esi" );
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
103 #else
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
104 __asm__ __volatile__("int $0x80"
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
105 : "=a" (res)
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
106 : "0" (__NR_modify_ldt),
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
107 "b" (func),
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
108 "c" (ptr),
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
109 "d"(16)
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
110 :"esi");
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
111 #endif /* __PIC__ */
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
112 if (res >= 0) return res;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
113 errno = -res;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
114 return -1;
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 #endif
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
117
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
118 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
119 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
120 {
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
121 *buffer++ = ((content->base_addr & 0x0000ffff) << 16) |
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
122 (content->limit & 0x0ffff);
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
123 *buffer = (content->base_addr & 0xff000000) |
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
124 ((content->base_addr & 0x00ff0000)>>16) |
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
125 (content->limit & 0xf0000) |
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
126 (content->contents << 10) |
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
127 ((content->read_exec_only == 0) << 9) |
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
128 ((content->seg_32bit != 0) << 22) |
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
129 ((content->limit_in_pages != 0) << 23) |
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
130 0xf000;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
131 }
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
132 #endif
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
133
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
134 void Setup_LDT_Keeper(){
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
135 struct modify_ldt_ldt_s array;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
136 int fd;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
137 int ret;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
138 void* prev_struct;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
139
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
140 if(fs_seg) return; // already set!
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 fd=open("/dev/zero", O_RDWR);
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
143 fs_seg=mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE, MAP_PRIVATE,
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
144 fd, 0);
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
145 if(fs_seg==(void*)-1)
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
146 {
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
147 perror("ERROR: Couldn't allocate memory for fs segment");
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
148 return;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
149 }
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
150 array.base_addr=(int)fs_seg;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
151 array.entry_number=TEB_SEL_IDX;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
152 array.limit=array.base_addr+getpagesize()-1;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
153 array.seg_32bit=1;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
154 array.read_exec_only=0;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
155 array.seg_not_present=0;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
156 array.contents=MODIFY_LDT_CONTENTS_DATA;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
157 array.limit_in_pages=0;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
158 #ifdef __linux__
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
159 ret=modify_ldt(0x1, &array, sizeof(struct modify_ldt_ldt_s));
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
160 if(ret<0)
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 perror("install_fs");
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
163 printf("Couldn't install fs segment, expect segfault\n");
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
164 }
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
165 #endif /*linux*/
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
166
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
167 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
168 {
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
169 unsigned long d[2];
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
170
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
171 LDT_EntryToBytes( d, &array );
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
172 ret = i386_set_ldt(array.entry_number, (union descriptor *)d, 1);
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
173 if (ret < 0)
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
174 {
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
175 perror("install_fs");
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
176 printf("Couldn't install fs segment, expect segfault\n");
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
177 printf("Did you reconfigure the kernel with \"options USER_LDT\"?\n");
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
178 }
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
179 printf("Set_LDT\n");
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
180 }
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
181 #endif /* __NetBSD__ || __FreeBSD__ || __OpenBSD__ */
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
182
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
183 #if defined(__svr4__)
1020
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 340
diff changeset
184 {
236
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
185 struct ssd ssd;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
186 ssd.sel = TEB_SEL;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
187 ssd.bo = array.base_addr;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
188 ssd.ls = array.limit - array.base_addr;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
189 ssd.acc1 = ((array.read_exec_only == 0) << 1) |
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
190 (array.contents << 2) |
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
191 0xf0; /* P(resent) | DPL3 | S */
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
192 ssd.acc2 = 0x4; /* byte limit, 32-bit segment */
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
193 if (sysi86(SI86DSCR, &ssd) < 0) {
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
194 perror("sysi86(SI86DSCR)");
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
195 printf("Couldn't install fs segment, expect segfault\n");
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
196 }
1020
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 340
diff changeset
197 }
236
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
198 #endif
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 setup_FS_Segment();
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 prev_struct=malloc(8);
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
203 *(void**)array.base_addr=prev_struct;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
204 close(fd);
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
205 }
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
206
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
207 void Restore_LDT_Keeper()
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
208 {
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
209 if(fs_seg==0) return;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
210 munmap((char*)fs_seg, getpagesize());
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
211 }
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
212