annotate loader/ldt_keeper.c @ 10879:27f8546f53c4

Added Matroska file extensions to the GUI. Patch by t0nik@yandex.ru.
author mosu
date Wed, 17 Sep 2003 09:42:25 +0000
parents e9e5dca4af9e
children 698fe63084d3
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!
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
7 * it might sound like a hack and it really is - but
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
8 * as aviplay is deconding video with more than just one
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
9 * thread currently it's necessary to do it this way
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
10 * this might change in the future
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
11 */
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
12
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
13 /* applied some modification to make make our xine friend more happy */
2139
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
14 #include "ldt_keeper.h"
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
15
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
16 #include <string.h>
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
17 #include <stdlib.h>
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
18 #include <errno.h>
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
19 #include <fcntl.h>
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
20 #include <sys/mman.h>
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
21 #include <sys/types.h>
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
22 #include <stdio.h>
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
23 #include <unistd.h>
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
24 #ifdef __linux__
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
25 #include <asm/unistd.h>
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
26 #include <asm/ldt.h>
8213
9d3e1476ecd0 2.5.47+ support
arpi
parents: 7386
diff changeset
27 // 2.5.xx+ calls this user_desc:
9d3e1476ecd0 2.5.47+ support
arpi
parents: 7386
diff changeset
28 #include <linux/version.h>
9d3e1476ecd0 2.5.47+ support
arpi
parents: 7386
diff changeset
29 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,47)
9d3e1476ecd0 2.5.47+ support
arpi
parents: 7386
diff changeset
30 #define modify_ldt_ldt_s user_desc
9d3e1476ecd0 2.5.47+ support
arpi
parents: 7386
diff changeset
31 #endif
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
32 /* prototype it here, so we won't depend on kernel headers */
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
33 #ifdef __cplusplus
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
34 extern "C" {
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
35 #endif
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
36 int modify_ldt(int func, void *ptr, unsigned long bytecount);
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
37 #ifdef __cplusplus
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
38 }
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
39 #endif
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
40 #else
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
41 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
5872
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents: 5747
diff changeset
42 #include <machine/segments.h>
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
43 #include <machine/sysarch.h>
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
44 #endif
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
45
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
46 #ifdef __svr4__
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
47 #include <sys/segment.h>
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
48 #include <sys/sysi86.h>
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
49
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
50 /* solaris x86: add missing prototype for sysi86() */
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
51 #ifdef __cplusplus
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
52 extern "C" {
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
53 #endif
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
54 int sysi86(int, void*);
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
55 #ifdef __cplusplus
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
56 }
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
57 #endif
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
58
2139
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
59 #ifndef NUMSYSLDTS /* SunOS 2.5.1 does not define NUMSYSLDTS */
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
60 #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
61 #endif
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 TEB_SEL_IDX NUMSYSLDTS
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
64 #endif
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
65
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
66 #define LDT_ENTRIES 8192
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
67 #define LDT_ENTRY_SIZE 8
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
68 #pragma pack(4)
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
69 struct modify_ldt_ldt_s {
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
70 unsigned int entry_number;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
71 unsigned long base_addr;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
72 unsigned int limit;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
73 unsigned int seg_32bit:1;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
74 unsigned int contents:2;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
75 unsigned int read_exec_only:1;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
76 unsigned int limit_in_pages:1;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
77 unsigned int seg_not_present:1;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
78 unsigned int useable:1;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
79 };
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
80
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
81 #define MODIFY_LDT_CONTENTS_DATA 0
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
82 #define MODIFY_LDT_CONTENTS_STACK 1
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
83 #define MODIFY_LDT_CONTENTS_CODE 2
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
84 #endif
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
85
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 /* user level (privilege level: 3) ldt (1<<2) segment selector */
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
88 #define LDT_SEL(idx) ((idx) << 3 | 1 << 2 | 3)
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
89
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
90 /* i got this value from wine sources, it's the first free LDT entry */
10821
e9e5dca4af9e FreeBSD 5.0 (libkse/libthr) support by Dan Eischen <eischen@vigrid.com>
alex
parents: 8223
diff changeset
91 #if defined(__FreeBSD__) && defined(LDT_AUTO_ALLOC)
e9e5dca4af9e FreeBSD 5.0 (libkse/libthr) support by Dan Eischen <eischen@vigrid.com>
alex
parents: 8223
diff changeset
92 #define TEB_SEL_IDX LDT_AUTO_ALLOC
e9e5dca4af9e FreeBSD 5.0 (libkse/libthr) support by Dan Eischen <eischen@vigrid.com>
alex
parents: 8223
diff changeset
93 #endif
e9e5dca4af9e FreeBSD 5.0 (libkse/libthr) support by Dan Eischen <eischen@vigrid.com>
alex
parents: 8223
diff changeset
94
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
95 #ifndef TEB_SEL_IDX
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
96 #define TEB_SEL_IDX 17
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
97 #endif
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
98
10821
e9e5dca4af9e FreeBSD 5.0 (libkse/libthr) support by Dan Eischen <eischen@vigrid.com>
alex
parents: 8223
diff changeset
99 static unsigned int fs_ldt = TEB_SEL_IDX;
e9e5dca4af9e FreeBSD 5.0 (libkse/libthr) support by Dan Eischen <eischen@vigrid.com>
alex
parents: 8223
diff changeset
100
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
101
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
102 /**
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
103 * here is a small logical problem with Restore for multithreaded programs -
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
104 * in C++ we use static class for this...
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
105 */
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 #ifdef __cplusplus
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
108 extern "C"
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
109 #endif
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
110 void Setup_FS_Segment(void)
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
111 {
10821
e9e5dca4af9e FreeBSD 5.0 (libkse/libthr) support by Dan Eischen <eischen@vigrid.com>
alex
parents: 8223
diff changeset
112 unsigned int ldt_desc = LDT_SEL(fs_ldt);
e9e5dca4af9e FreeBSD 5.0 (libkse/libthr) support by Dan Eischen <eischen@vigrid.com>
alex
parents: 8223
diff changeset
113
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
114 __asm__ __volatile__(
10821
e9e5dca4af9e FreeBSD 5.0 (libkse/libthr) support by Dan Eischen <eischen@vigrid.com>
alex
parents: 8223
diff changeset
115 "movl %0,%%eax; movw %%ax, %%fs" : : "r" (ldt_desc)
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
116 );
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
117 }
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
118
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
119 /* we don't need this - use modify_ldt instead */
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
120 #if 0
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
121 #ifdef __linux__
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
122 /* XXX: why is this routine from libc redefined here? */
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
123 /* 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
124 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
125 unsigned long count )
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
126 {
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
127 int res;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
128 #ifdef __PIC__
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
129 __asm__ __volatile__( "pushl %%ebx\n\t"
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
130 "movl %2,%%ebx\n\t"
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
131 "int $0x80\n\t"
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
132 "popl %%ebx"
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
133 : "=a" (res)
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
134 : "0" (__NR_modify_ldt),
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
135 "r" (func),
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
136 "c" (ptr),
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
137 "d"(16)//sizeof(*ptr) from kernel point of view
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
138 :"esi" );
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
139 #else
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
140 __asm__ __volatile__("int $0x80"
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
141 : "=a" (res)
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
142 : "0" (__NR_modify_ldt),
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
143 "b" (func),
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
144 "c" (ptr),
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
145 "d"(16)
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
146 :"esi");
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
147 #endif /* __PIC__ */
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
148 if (res >= 0) return res;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
149 errno = -res;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
150 return -1;
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 #endif
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
153 #endif
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
154
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
155 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
156 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
157 {
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
158 *buffer++ = ((content->base_addr & 0x0000ffff) << 16) |
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
159 (content->limit & 0x0ffff);
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
160 *buffer = (content->base_addr & 0xff000000) |
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
161 ((content->base_addr & 0x00ff0000)>>16) |
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
162 (content->limit & 0xf0000) |
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
163 (content->contents << 10) |
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
164 ((content->read_exec_only == 0) << 9) |
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
165 ((content->seg_32bit != 0) << 22) |
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
166 ((content->limit_in_pages != 0) << 23) |
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
167 0xf000;
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 #endif
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
170
8223
a88e53ef3029 exporting fs_seg
alex
parents: 8213
diff changeset
171 void* fs_seg=0;
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
172
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
173 ldt_fs_t* Setup_LDT_Keeper(void)
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
174 {
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
175 struct modify_ldt_ldt_s array;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
176 int ret;
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
177 ldt_fs_t* ldt_fs = (ldt_fs_t*) malloc(sizeof(ldt_fs_t));
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
178
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
179 if (!ldt_fs)
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
180 return NULL;
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
181
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
182 ldt_fs->fd = open("/dev/zero", O_RDWR);
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
183 if(ldt_fs->fd<0){
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
184 perror( "Cannot open /dev/zero for READ+WRITE. Check permissions! error: ");
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
185 return NULL;
3775
aa1491f8167b /dev/zero bad permissions error message
arpi
parents: 2779
diff changeset
186 }
8223
a88e53ef3029 exporting fs_seg
alex
parents: 8213
diff changeset
187 fs_seg=
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
188 ldt_fs->fs_seg = mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE, MAP_PRIVATE,
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
189 ldt_fs->fd, 0);
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
190 if (ldt_fs->fs_seg == (void*)-1)
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
191 {
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
192 perror("ERROR: Couldn't allocate memory for fs segment");
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
193 close(ldt_fs->fd);
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
194 free(ldt_fs);
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
195 return NULL;
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
196 }
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
197 *(void**)((char*)ldt_fs->fs_seg+0x18) = ldt_fs->fs_seg;
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
198 array.base_addr=(int)ldt_fs->fs_seg;
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
199 array.entry_number=TEB_SEL_IDX;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
200 array.limit=array.base_addr+getpagesize()-1;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
201 array.seg_32bit=1;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
202 array.read_exec_only=0;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
203 array.seg_not_present=0;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
204 array.contents=MODIFY_LDT_CONTENTS_DATA;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
205 array.limit_in_pages=0;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
206 #ifdef __linux__
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
207 //ret=LDT_Modify(0x1, &array, sizeof(struct modify_ldt_ldt_s));
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
208 ret=modify_ldt(0x1, &array, sizeof(struct modify_ldt_ldt_s));
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
209 if(ret<0)
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
210 {
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
211 perror("install_fs");
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
212 printf("Couldn't install fs segment, expect segfault\n");
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
213 }
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
214 #endif /*linux*/
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
215
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
216 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
217 {
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
218 unsigned long d[2];
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
219
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
220 LDT_EntryToBytes( d, &array );
10821
e9e5dca4af9e FreeBSD 5.0 (libkse/libthr) support by Dan Eischen <eischen@vigrid.com>
alex
parents: 8223
diff changeset
221 #if defined(__FreeBSD__) && defined(LDT_AUTO_ALLOC)
e9e5dca4af9e FreeBSD 5.0 (libkse/libthr) support by Dan Eischen <eischen@vigrid.com>
alex
parents: 8223
diff changeset
222 ret = i386_set_ldt(LDT_AUTO_ALLOC, (union descriptor *)d, 1);
e9e5dca4af9e FreeBSD 5.0 (libkse/libthr) support by Dan Eischen <eischen@vigrid.com>
alex
parents: 8223
diff changeset
223 array.entry_number = ret;
e9e5dca4af9e FreeBSD 5.0 (libkse/libthr) support by Dan Eischen <eischen@vigrid.com>
alex
parents: 8223
diff changeset
224 fs_ldt = ret;
e9e5dca4af9e FreeBSD 5.0 (libkse/libthr) support by Dan Eischen <eischen@vigrid.com>
alex
parents: 8223
diff changeset
225 #else
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
226 ret = i386_set_ldt(array.entry_number, (union descriptor *)d, 1);
10821
e9e5dca4af9e FreeBSD 5.0 (libkse/libthr) support by Dan Eischen <eischen@vigrid.com>
alex
parents: 8223
diff changeset
227 #endif
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
228 if (ret < 0)
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 perror("install_fs");
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
231 printf("Couldn't install fs segment, expect segfault\n");
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
232 printf("Did you reconfigure the kernel with \"options USER_LDT\"?\n");
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
233 }
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
234 }
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
235 #endif /* __NetBSD__ || __FreeBSD__ || __OpenBSD__ */
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
236
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
237 #if defined(__svr4__)
2070
c1edbb8bfc0c (solaris x86) C++ style variable declaration not at the start of a block does
jkeil
parents: 2069
diff changeset
238 {
2139
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
239 struct ssd ssd;
10821
e9e5dca4af9e FreeBSD 5.0 (libkse/libthr) support by Dan Eischen <eischen@vigrid.com>
alex
parents: 8223
diff changeset
240 ssd.sel = LDT_SEL(TEB_SEL_IDX);
2139
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
241 ssd.bo = array.base_addr;
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
242 ssd.ls = array.limit - array.base_addr;
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
243 ssd.acc1 = ((array.read_exec_only == 0) << 1) |
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
244 (array.contents << 2) |
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
245 0xf0; /* P(resent) | DPL3 | S */
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
246 ssd.acc2 = 0x4; /* byte limit, 32-bit segment */
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
247 if (sysi86(SI86DSCR, &ssd) < 0) {
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
248 perror("sysi86(SI86DSCR)");
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
249 printf("Couldn't install fs segment, expect segfault\n");
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
250 }
2070
c1edbb8bfc0c (solaris x86) C++ style variable declaration not at the start of a block does
jkeil
parents: 2069
diff changeset
251 }
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
252 #endif
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
253
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
254 Setup_FS_Segment();
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
255
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
256 ldt_fs->prev_struct = (char*)malloc(sizeof(char) * 8);
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
257 *(void**)array.base_addr = ldt_fs->prev_struct;
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
258
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
259 return ldt_fs;
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
260 }
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
261
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
262 void Restore_LDT_Keeper(ldt_fs_t* ldt_fs)
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
263 {
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
264 if (ldt_fs == NULL || ldt_fs->fs_seg == 0)
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
265 return;
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
266 if (ldt_fs->prev_struct)
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
267 free(ldt_fs->prev_struct);
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
268 munmap((char*)ldt_fs->fs_seg, getpagesize());
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
269 ldt_fs->fs_seg = 0;
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
270 close(ldt_fs->fd);
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
271 free(ldt_fs);
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
272 }