annotate loader/ldt_keeper.c @ 5872:02576893af2a

OpenBSD, NetBSD portability patches by Bj«Órn Sandell <biorn@dce.chalmers.se> Marcus <core@antbear.org> Bernd Ernesti <mplayer@lists.veego.de>
author arpi
date Sat, 27 Apr 2002 22:42:27 +0000
parents 710424e1a656
children 174e2a58b4cd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
1 /**
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
2 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
3 * This file MUST be in main library because LDT must
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
4 * be modified before program creates first thread
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
5 * - avifile includes this file from C++ code
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
6 * and initializes it at the start of player!
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
7 */
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
8
2139
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
9 #include "ldt_keeper.h"
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
10
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
11 #include <string.h>
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
12 #include <stdlib.h>
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
13 #include <errno.h>
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
14 #include <fcntl.h>
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
15 #include <sys/mman.h>
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
16 #include <sys/types.h>
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
17 #include <stdio.h>
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
18 #include <unistd.h>
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
19 #ifdef __linux__
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
20 #include <asm/unistd.h>
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
21 #include <asm/ldt.h>
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
22 #else
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
23 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
5872
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents: 5747
diff changeset
24 #include <machine/segments.h>
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
25 #include <machine/sysarch.h>
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
26 #endif
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
27
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
28 #ifdef __svr4__
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
29 #include <sys/segment.h>
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
30 #include <sys/sysi86.h>
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
31
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
32 /* solaris x86: add missing prototype for sysi86() */
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
33 #ifdef __cplusplus
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
34 extern "C" {
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
35 #endif
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
36 extern int sysi86(int, void*);
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
37 #ifdef __cplusplus
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
38 }
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
39 #endif
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
40
2139
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
41 #ifndef NUMSYSLDTS /* SunOS 2.5.1 does not define NUMSYSLDTS */
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
42 #define NUMSYSLDTS 6 /* Let's hope the SunOS 5.8 value is OK */
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
43 #endif
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
44
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
45 #define TEB_SEL_IDX NUMSYSLDTS
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
46 #endif
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
47
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
48 #define LDT_ENTRIES 8192
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
49 #define LDT_ENTRY_SIZE 8
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
50 #pragma pack(4)
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
51 struct modify_ldt_ldt_s {
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
52 unsigned int entry_number;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
53 unsigned long base_addr;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
54 unsigned int limit;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
55 unsigned int seg_32bit:1;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
56 unsigned int contents:2;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
57 unsigned int read_exec_only:1;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
58 unsigned int limit_in_pages:1;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
59 unsigned int seg_not_present:1;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
60 unsigned int useable:1;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
61 };
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
62
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
63 #define MODIFY_LDT_CONTENTS_DATA 0
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
64 #define MODIFY_LDT_CONTENTS_STACK 1
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
65 #define MODIFY_LDT_CONTENTS_CODE 2
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
66 #endif
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
67
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
68
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
69 /* user level (privilege level: 3) ldt (1<<2) segment selector */
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
70 #define LDT_SEL(idx) ((idx) << 3 | 1 << 2 | 3)
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
71
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
72 #ifndef TEB_SEL_IDX
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
73 #define TEB_SEL_IDX 1
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
74 #endif
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
75 #define TEB_SEL LDT_SEL(TEB_SEL_IDX)
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
76
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
77 /**
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
78 *
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
79 * This should be performed before we create first thread. See remarks
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
80 * for write_ldt(), linux/kernel/ldt.c.
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
81 *
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
82 */
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
83
2779
0ecadf56dc05 Eugene's fixes to work with QuickTime.qts
arpi
parents: 2139
diff changeset
84 void* fs_seg = NULL;
2139
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
85 static char* prev_struct = NULL;
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
86 /**
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
87 * here is a small logical problem with Restore for multithreaded programs -
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
88 * in C++ we use static class for this...
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
89 */
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
90
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
91 #ifdef __cplusplus
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
92 extern "C"
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
93 #endif
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
94 void Setup_FS_Segment(void)
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
95 {
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
96 __asm__ __volatile__(
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
97 "movl %0,%%eax; movw %%ax, %%fs" : : "i" (TEB_SEL)
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
98 );
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
99 }
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
100
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
101 #ifdef __linux__
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
102 /* XXX: why is this routine from libc redefined here? */
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
103 /* NOTE: the redefined version ignores the count param, count is hardcoded as 16 */
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
104 static int LDT_Modify( int func, struct modify_ldt_ldt_s *ptr,
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
105 unsigned long count )
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
106 {
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
107 int res;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
108 #ifdef __PIC__
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
109 __asm__ __volatile__( "pushl %%ebx\n\t"
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
110 "movl %2,%%ebx\n\t"
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
111 "int $0x80\n\t"
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
112 "popl %%ebx"
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
113 : "=a" (res)
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
114 : "0" (__NR_modify_ldt),
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
115 "r" (func),
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
116 "c" (ptr),
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
117 "d"(16)//sizeof(*ptr) from kernel point of view
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
118 :"esi" );
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
119 #else
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
120 __asm__ __volatile__("int $0x80"
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
121 : "=a" (res)
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
122 : "0" (__NR_modify_ldt),
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
123 "b" (func),
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
124 "c" (ptr),
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
125 "d"(16)
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
126 :"esi");
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
127 #endif /* __PIC__ */
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
128 if (res >= 0) return res;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
129 errno = -res;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
130 return -1;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
131 }
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
132 #endif
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
133
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
134 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
135 static void LDT_EntryToBytes( unsigned long *buffer, const struct modify_ldt_ldt_s *content )
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
136 {
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
137 *buffer++ = ((content->base_addr & 0x0000ffff) << 16) |
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
138 (content->limit & 0x0ffff);
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
139 *buffer = (content->base_addr & 0xff000000) |
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
140 ((content->base_addr & 0x00ff0000)>>16) |
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
141 (content->limit & 0xf0000) |
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
142 (content->contents << 10) |
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
143 ((content->read_exec_only == 0) << 9) |
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
144 ((content->seg_32bit != 0) << 22) |
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
145 ((content->limit_in_pages != 0) << 23) |
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
146 0xf000;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
147 }
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
148 #endif
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
149
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
150 void Setup_LDT_Keeper(void)
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
151 {
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
152 struct modify_ldt_ldt_s array;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
153 int fd;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
154 int ret;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
155
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
156 if (fs_seg)
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
157 return;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
158
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
159 prev_struct = 0;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
160 fd = open("/dev/zero", O_RDWR);
3775
aa1491f8167b /dev/zero bad permissions error message
arpi
parents: 2779
diff changeset
161 if(fd<0){
aa1491f8167b /dev/zero bad permissions error message
arpi
parents: 2779
diff changeset
162 perror( "Cannot open /dev/zero for READ+WRITE. Check permissions! error: " );
aa1491f8167b /dev/zero bad permissions error message
arpi
parents: 2779
diff changeset
163 return;
aa1491f8167b /dev/zero bad permissions error message
arpi
parents: 2779
diff changeset
164 }
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
165 fs_seg = mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE, MAP_PRIVATE,
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
166 fd, 0);
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
167 if(fs_seg==(void*)-1)
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
168 {
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
169 perror("ERROR: Couldn't allocate memory for fs segment");
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
170 return;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
171 }
5747
710424e1a656 commented out debug msg
alex
parents: 3775
diff changeset
172 // printf("fs seg %p\n", fs_seg);
2779
0ecadf56dc05 Eugene's fixes to work with QuickTime.qts
arpi
parents: 2139
diff changeset
173 *(void**)((char*)fs_seg+0x18) = fs_seg;
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
174 array.base_addr=(int)fs_seg;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
175 array.entry_number=TEB_SEL_IDX;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
176 array.limit=array.base_addr+getpagesize()-1;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
177 array.seg_32bit=1;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
178 array.read_exec_only=0;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
179 array.seg_not_present=0;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
180 array.contents=MODIFY_LDT_CONTENTS_DATA;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
181 array.limit_in_pages=0;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
182 #ifdef __linux__
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
183 ret=LDT_Modify(0x1, &array, sizeof(struct modify_ldt_ldt_s));
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
184 if(ret<0)
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
185 {
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
186 perror("install_fs");
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
187 printf("Couldn't install fs segment, expect segfault\n");
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
188 }
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
189 #endif /*linux*/
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
190
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
191 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
192 {
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
193 unsigned long d[2];
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
194
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
195 LDT_EntryToBytes( d, &array );
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
196 ret = i386_set_ldt(array.entry_number, (union descriptor *)d, 1);
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
197 if (ret < 0)
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
198 {
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
199 perror("install_fs");
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
200 printf("Couldn't install fs segment, expect segfault\n");
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
201 printf("Did you reconfigure the kernel with \"options USER_LDT\"?\n");
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
202 }
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
203 printf("Set_LDT\n");
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
204 }
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
205 #endif /* __NetBSD__ || __FreeBSD__ || __OpenBSD__ */
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
206
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
207 #if defined(__svr4__)
2070
c1edbb8bfc0c (solaris x86) C++ style variable declaration not at the start of a block does
jkeil
parents: 2069
diff changeset
208 {
2139
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
209 struct ssd ssd;
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
210 ssd.sel = TEB_SEL;
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
211 ssd.bo = array.base_addr;
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
212 ssd.ls = array.limit - array.base_addr;
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
213 ssd.acc1 = ((array.read_exec_only == 0) << 1) |
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
214 (array.contents << 2) |
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
215 0xf0; /* P(resent) | DPL3 | S */
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
216 ssd.acc2 = 0x4; /* byte limit, 32-bit segment */
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
217 if (sysi86(SI86DSCR, &ssd) < 0) {
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
218 perror("sysi86(SI86DSCR)");
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
219 printf("Couldn't install fs segment, expect segfault\n");
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
220 }
2070
c1edbb8bfc0c (solaris x86) C++ style variable declaration not at the start of a block does
jkeil
parents: 2069
diff changeset
221 }
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
222 #endif
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
223
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
224 Setup_FS_Segment();
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
225
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
226 prev_struct = (char*)malloc(sizeof(char) * 8);
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
227 *(void**)array.base_addr = prev_struct;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
228 close(fd);
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
229 }
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
230
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
231 void Restore_LDT_Keeper(void)
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
232 {
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
233 if (fs_seg == 0)
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
234 return;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
235 if (prev_struct)
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
236 free(prev_struct);
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
237 munmap((char*)fs_seg, getpagesize());
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
238 fs_seg = 0;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
239 }