annotate loader/setup_FS.c @ 1733:220f86ac8c15

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