annotate loader/ldt_keeper.c @ 28347:1f4b3aaefcd8

Avoid a division by 0 when using -oac mp3lame but no audio data actually is encoded.
author reimar
date Wed, 28 Jan 2009 12:46:05 +0000
parents b5a46071062a
children 0f1b5b68af32
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 */
15166
f5537cc95b02 Mark modified imported files as such to comply with GPL ¡ø2a.
diego
parents: 14537
diff changeset
14
f5537cc95b02 Mark modified imported files as such to comply with GPL ¡ø2a.
diego
parents: 14537
diff changeset
15 /*
18783
0783dd397f74 CVS --> Subversion in copyright notices
diego
parents: 18362
diff changeset
16 * Modified for use with MPlayer, detailed changelog at
0783dd397f74 CVS --> Subversion in copyright notices
diego
parents: 18362
diff changeset
17 * http://svn.mplayerhq.hu/mplayer/trunk/
15166
f5537cc95b02 Mark modified imported files as such to comply with GPL ¡ø2a.
diego
parents: 14537
diff changeset
18 */
f5537cc95b02 Mark modified imported files as such to comply with GPL ¡ø2a.
diego
parents: 14537
diff changeset
19
26105
c99d53b76ee5 Wrap '#include <sys/mman.h>' in HAVE_SYS_MMAN_H.
diego
parents: 26054
diff changeset
20 #include "config.h"
2139
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
21 #include "ldt_keeper.h"
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
22
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
23 #include <string.h>
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
24 #include <stdlib.h>
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
25 #include <errno.h>
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
26 #include <fcntl.h>
26105
c99d53b76ee5 Wrap '#include <sys/mman.h>' in HAVE_SYS_MMAN_H.
diego
parents: 26054
diff changeset
27 #ifdef HAVE_SYS_MMAN_H
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
28 #include <sys/mman.h>
26111
eb82d1524b6d #include osdep/mman.h if sys/mman.h is not available.
diego
parents: 26105
diff changeset
29 #else
eb82d1524b6d #include osdep/mman.h if sys/mman.h is not available.
diego
parents: 26105
diff changeset
30 #include "osdep/mmap.h"
26105
c99d53b76ee5 Wrap '#include <sys/mman.h>' in HAVE_SYS_MMAN_H.
diego
parents: 26054
diff changeset
31 #endif
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
32 #include <sys/types.h>
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
33 #include <stdio.h>
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
34 #include <unistd.h>
21187
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents: 18878
diff changeset
35 #include "osdep/mmap_anon.h"
21290
efc774a1e5a4 fix compilation for win32 dll codec support for intel osx
nplourde
parents: 21248
diff changeset
36 #include "mp_msg.h"
efc774a1e5a4 fix compilation for win32 dll codec support for intel osx
nplourde
parents: 21248
diff changeset
37 #include "help_mp.h"
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
38 #ifdef __linux__
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
39 #include <asm/unistd.h>
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
40 #include <asm/ldt.h>
8213
9d3e1476ecd0 2.5.47+ support
arpi
parents: 7386
diff changeset
41 // 2.5.xx+ calls this user_desc:
9d3e1476ecd0 2.5.47+ support
arpi
parents: 7386
diff changeset
42 #include <linux/version.h>
9d3e1476ecd0 2.5.47+ support
arpi
parents: 7386
diff changeset
43 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,47)
9d3e1476ecd0 2.5.47+ support
arpi
parents: 7386
diff changeset
44 #define modify_ldt_ldt_s user_desc
9d3e1476ecd0 2.5.47+ support
arpi
parents: 7386
diff changeset
45 #endif
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
46 /* prototype it here, so we won't depend on kernel headers */
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
47 #ifdef __cplusplus
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
48 extern "C" {
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
49 #endif
13351
698fe63084d3 declare modify_ldt with syscall3 macro for older glibcs patch by Mikulas Patocka <mikulas at artax.karlin.mff.cuni.cz>
faust3
parents: 10821
diff changeset
50 /// declare modify_ldt with the _syscall3 macro for older glibcs
13361
faust3
parents: 13351
diff changeset
51 #if defined(__GLIBC__) && (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ == 0))
13351
698fe63084d3 declare modify_ldt with syscall3 macro for older glibcs patch by Mikulas Patocka <mikulas at artax.karlin.mff.cuni.cz>
faust3
parents: 10821
diff changeset
52 _syscall3( int, modify_ldt, int, func, void *, ptr, unsigned long, bytecount );
698fe63084d3 declare modify_ldt with syscall3 macro for older glibcs patch by Mikulas Patocka <mikulas at artax.karlin.mff.cuni.cz>
faust3
parents: 10821
diff changeset
53 #else
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
54 int modify_ldt(int func, void *ptr, unsigned long bytecount);
13351
698fe63084d3 declare modify_ldt with syscall3 macro for older glibcs patch by Mikulas Patocka <mikulas at artax.karlin.mff.cuni.cz>
faust3
parents: 10821
diff changeset
55 #endif
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
56 #ifdef __cplusplus
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
57 }
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
58 #endif
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
59 #else
15566
3758536dcef3 DragonFly BSD support
diego
parents: 15166
diff changeset
60 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
5872
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents: 5747
diff changeset
61 #include <machine/segments.h>
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
62 #include <machine/sysarch.h>
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
63 #endif
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
64
26054
d9b11d83367f Add missing #includes for Mac OS X, fixes the warning
diego
parents: 25849
diff changeset
65 #if defined(__APPLE__)
d9b11d83367f Add missing #includes for Mac OS X, fixes the warning
diego
parents: 25849
diff changeset
66 #include <architecture/i386/table.h>
d9b11d83367f Add missing #includes for Mac OS X, fixes the warning
diego
parents: 25849
diff changeset
67 #include <i386/user_ldt.h>
d9b11d83367f Add missing #includes for Mac OS X, fixes the warning
diego
parents: 25849
diff changeset
68 #endif
d9b11d83367f Add missing #includes for Mac OS X, fixes the warning
diego
parents: 25849
diff changeset
69
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
70 #ifdef __svr4__
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
71 #include <sys/segment.h>
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
72 #include <sys/sysi86.h>
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
73
22715
363c84953547 check that definition of prototype of sysi86(int, void*) doesn't conflict; fixed compilation in opensolaris
nicodvb
parents: 21290
diff changeset
74 /* solaris x86: add missing prototype for sysi86(), but only when sysi86(int, void*) is known to be valid */
363c84953547 check that definition of prototype of sysi86(int, void*) doesn't conflict; fixed compilation in opensolaris
nicodvb
parents: 21290
diff changeset
75 #ifdef HAVE_SYSI86_iv
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
76 #ifdef __cplusplus
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
77 extern "C" {
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
78 #endif
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
79 int sysi86(int, void*);
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
80 #ifdef __cplusplus
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 #endif
18362
29b2221982b3 Add a check for sysi86() on Solaris systems, solving a build failure on Solaris
diego
parents: 17605
diff changeset
83 #endif
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
84
2139
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
85 #ifndef NUMSYSLDTS /* SunOS 2.5.1 does not define NUMSYSLDTS */
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
86 #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
87 #endif
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
88
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
89 #define TEB_SEL_IDX NUMSYSLDTS
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
90 #endif
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
91
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
92 #define LDT_ENTRIES 8192
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
93 #define LDT_ENTRY_SIZE 8
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
94 #pragma pack(4)
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
95 struct modify_ldt_ldt_s {
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
96 unsigned int entry_number;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
97 unsigned long base_addr;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
98 unsigned int limit;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
99 unsigned int seg_32bit:1;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
100 unsigned int contents:2;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
101 unsigned int read_exec_only:1;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
102 unsigned int limit_in_pages:1;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
103 unsigned int seg_not_present:1;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
104 unsigned int useable:1;
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 #define MODIFY_LDT_CONTENTS_DATA 0
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
108 #define MODIFY_LDT_CONTENTS_STACK 1
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
109 #define MODIFY_LDT_CONTENTS_CODE 2
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
110 #endif
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
111
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
112
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
113 /* user level (privilege level: 3) ldt (1<<2) segment selector */
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
114 #define LDT_SEL(idx) ((idx) << 3 | 1 << 2 | 3)
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
115
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
116 /* i got this value from wine sources, it's the first free LDT entry */
21290
efc774a1e5a4 fix compilation for win32 dll codec support for intel osx
nplourde
parents: 21248
diff changeset
117 #if (defined(__APPLE__) || defined(__FreeBSD__)) && defined(LDT_AUTO_ALLOC)
10821
e9e5dca4af9e FreeBSD 5.0 (libkse/libthr) support by Dan Eischen <eischen@vigrid.com>
alex
parents: 8223
diff changeset
118 #define TEB_SEL_IDX LDT_AUTO_ALLOC
21290
efc774a1e5a4 fix compilation for win32 dll codec support for intel osx
nplourde
parents: 21248
diff changeset
119 #define USE_LDT_AA
10821
e9e5dca4af9e FreeBSD 5.0 (libkse/libthr) support by Dan Eischen <eischen@vigrid.com>
alex
parents: 8223
diff changeset
120 #endif
e9e5dca4af9e FreeBSD 5.0 (libkse/libthr) support by Dan Eischen <eischen@vigrid.com>
alex
parents: 8223
diff changeset
121
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
122 #ifndef TEB_SEL_IDX
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
123 #define TEB_SEL_IDX 17
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
124 #endif
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
125
10821
e9e5dca4af9e FreeBSD 5.0 (libkse/libthr) support by Dan Eischen <eischen@vigrid.com>
alex
parents: 8223
diff changeset
126 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
127
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
128
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
129 /**
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
130 * here is a small logical problem with Restore for multithreaded programs -
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
131 * in C++ we use static class for this...
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
132 */
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 #ifdef __cplusplus
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
135 extern "C"
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
136 #endif
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
137 void Setup_FS_Segment(void)
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
138 {
10821
e9e5dca4af9e FreeBSD 5.0 (libkse/libthr) support by Dan Eischen <eischen@vigrid.com>
alex
parents: 8223
diff changeset
139 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
140
27757
b5a46071062a Replace all occurrences of '__volatile__' and '__volatile' by plain 'volatile'.
diego
parents: 26111
diff changeset
141 __asm__ volatile(
10821
e9e5dca4af9e FreeBSD 5.0 (libkse/libthr) support by Dan Eischen <eischen@vigrid.com>
alex
parents: 8223
diff changeset
142 "movl %0,%%eax; movw %%ax, %%fs" : : "r" (ldt_desc)
14212
540903a59fc0 add missing registers in clobber list, fixes bug #169
reimar
parents: 13361
diff changeset
143 :"eax"
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
144 );
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
145 }
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
146
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
147 /* we don't need this - use modify_ldt instead */
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
148 #if 0
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
149 #ifdef __linux__
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
150 /* XXX: why is this routine from libc redefined here? */
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
151 /* 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
152 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
153 unsigned long count )
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 int res;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
156 #ifdef __PIC__
27757
b5a46071062a Replace all occurrences of '__volatile__' and '__volatile' by plain 'volatile'.
diego
parents: 26111
diff changeset
157 __asm__ volatile( "pushl %%ebx\n\t"
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
158 "movl %2,%%ebx\n\t"
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
159 "int $0x80\n\t"
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
160 "popl %%ebx"
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
161 : "=a" (res)
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
162 : "0" (__NR_modify_ldt),
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
163 "r" (func),
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
164 "c" (ptr),
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
165 "d"(16)//sizeof(*ptr) from kernel point of view
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
166 :"esi" );
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
167 #else
27757
b5a46071062a Replace all occurrences of '__volatile__' and '__volatile' by plain 'volatile'.
diego
parents: 26111
diff changeset
168 __asm__ volatile("int $0x80"
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
169 : "=a" (res)
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
170 : "0" (__NR_modify_ldt),
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
171 "b" (func),
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
172 "c" (ptr),
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
173 "d"(16)
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
174 :"esi");
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
175 #endif /* __PIC__ */
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
176 if (res >= 0) return res;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
177 errno = -res;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
178 return -1;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
179 }
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
180 #endif
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
181 #endif
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
182
21290
efc774a1e5a4 fix compilation for win32 dll codec support for intel osx
nplourde
parents: 21248
diff changeset
183 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__APPLE__)
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
184 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
185 {
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
186 *buffer++ = ((content->base_addr & 0x0000ffff) << 16) |
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
187 (content->limit & 0x0ffff);
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
188 *buffer = (content->base_addr & 0xff000000) |
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
189 ((content->base_addr & 0x00ff0000)>>16) |
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
190 (content->limit & 0xf0000) |
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
191 (content->contents << 10) |
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
192 ((content->read_exec_only == 0) << 9) |
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
193 ((content->seg_32bit != 0) << 22) |
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
194 ((content->limit_in_pages != 0) << 23) |
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
195 0xf000;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
196 }
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
197 #endif
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
198
8223
a88e53ef3029 exporting fs_seg
alex
parents: 8213
diff changeset
199 void* fs_seg=0;
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
200
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
201 ldt_fs_t* Setup_LDT_Keeper(void)
2067
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 struct modify_ldt_ldt_s array;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
204 int ret;
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
205 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
206
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
207 if (!ldt_fs)
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
208 return NULL;
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
209
21290
efc774a1e5a4 fix compilation for win32 dll codec support for intel osx
nplourde
parents: 21248
diff changeset
210 #ifdef __APPLE__
efc774a1e5a4 fix compilation for win32 dll codec support for intel osx
nplourde
parents: 21248
diff changeset
211 if (getenv("DYLD_BIND_AT_LAUNCH") == NULL)
efc774a1e5a4 fix compilation for win32 dll codec support for intel osx
nplourde
parents: 21248
diff changeset
212 mp_msg(MSGT_LOADER, MSGL_WARN, MSGTR_LOADER_DYLD_Warning);
efc774a1e5a4 fix compilation for win32 dll codec support for intel osx
nplourde
parents: 21248
diff changeset
213 #endif /* __APPLE__ */
efc774a1e5a4 fix compilation for win32 dll codec support for intel osx
nplourde
parents: 21248
diff changeset
214
8223
a88e53ef3029 exporting fs_seg
alex
parents: 8213
diff changeset
215 fs_seg=
21248
2de480457872 Remove useless fd parameter for mmap_anon
reimar
parents: 21244
diff changeset
216 ldt_fs->fs_seg = mmap_anon(NULL, getpagesize(), PROT_READ | PROT_WRITE, MAP_PRIVATE, 0);
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
217 if (ldt_fs->fs_seg == (void*)-1)
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
218 {
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
219 perror("ERROR: Couldn't allocate memory for fs segment");
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
220 free(ldt_fs);
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
221 return NULL;
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
222 }
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
223 *(void**)((char*)ldt_fs->fs_seg+0x18) = ldt_fs->fs_seg;
14537
f832c3ec3e4b initialize modify_ldt struct to 0.
reimar
parents: 14212
diff changeset
224 memset(&array, 0, sizeof(array));
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
225 array.base_addr=(int)ldt_fs->fs_seg;
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
226 array.entry_number=TEB_SEL_IDX;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
227 array.limit=array.base_addr+getpagesize()-1;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
228 array.seg_32bit=1;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
229 array.read_exec_only=0;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
230 array.seg_not_present=0;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
231 array.contents=MODIFY_LDT_CONTENTS_DATA;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
232 array.limit_in_pages=0;
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
233 #ifdef __linux__
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
234 //ret=LDT_Modify(0x1, &array, sizeof(struct modify_ldt_ldt_s));
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
235 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
236 if(ret<0)
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
237 {
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
238 perror("install_fs");
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
239 printf("Couldn't install fs segment, expect segfault\n");
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
240 }
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
241 #endif /*linux*/
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
242
21290
efc774a1e5a4 fix compilation for win32 dll codec support for intel osx
nplourde
parents: 21248
diff changeset
243 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__APPLE__)
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
244 {
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
245 unsigned long d[2];
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
246
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
247 LDT_EntryToBytes( d, &array );
21290
efc774a1e5a4 fix compilation for win32 dll codec support for intel osx
nplourde
parents: 21248
diff changeset
248 #ifdef USE_LDT_AA
10821
e9e5dca4af9e FreeBSD 5.0 (libkse/libthr) support by Dan Eischen <eischen@vigrid.com>
alex
parents: 8223
diff changeset
249 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
250 array.entry_number = ret;
e9e5dca4af9e FreeBSD 5.0 (libkse/libthr) support by Dan Eischen <eischen@vigrid.com>
alex
parents: 8223
diff changeset
251 fs_ldt = ret;
e9e5dca4af9e FreeBSD 5.0 (libkse/libthr) support by Dan Eischen <eischen@vigrid.com>
alex
parents: 8223
diff changeset
252 #else
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
253 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
254 #endif
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
255 if (ret < 0)
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
256 {
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
257 perror("install_fs");
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
258 printf("Couldn't install fs segment, expect segfault\n");
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
259 printf("Did you reconfigure the kernel with \"options USER_LDT\"?\n");
17605
dcc1be050037 one more hint for openbsd
alex
parents: 15566
diff changeset
260 #ifdef __OpenBSD__
dcc1be050037 one more hint for openbsd
alex
parents: 15566
diff changeset
261 printf("On newer OpenBSD systems did you set machdep.userldt to 1?\n");
dcc1be050037 one more hint for openbsd
alex
parents: 15566
diff changeset
262 #endif
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
263 }
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
264 }
21290
efc774a1e5a4 fix compilation for win32 dll codec support for intel osx
nplourde
parents: 21248
diff changeset
265 #endif /* __NetBSD__ || __FreeBSD__ || __OpenBSD__ || __DragonFly__ || __APPLE__ */
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
266
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
267 #if defined(__svr4__)
2070
c1edbb8bfc0c (solaris x86) C++ style variable declaration not at the start of a block does
jkeil
parents: 2069
diff changeset
268 {
2139
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
269 struct ssd ssd;
10821
e9e5dca4af9e FreeBSD 5.0 (libkse/libthr) support by Dan Eischen <eischen@vigrid.com>
alex
parents: 8223
diff changeset
270 ssd.sel = LDT_SEL(TEB_SEL_IDX);
2139
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
271 ssd.bo = array.base_addr;
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
272 ssd.ls = array.limit - array.base_addr;
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
273 ssd.acc1 = ((array.read_exec_only == 0) << 1) |
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
274 (array.contents << 2) |
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
275 0xf0; /* P(resent) | DPL3 | S */
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
276 ssd.acc2 = 0x4; /* byte limit, 32-bit segment */
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
277 if (sysi86(SI86DSCR, &ssd) < 0) {
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
278 perror("sysi86(SI86DSCR)");
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
279 printf("Couldn't install fs segment, expect segfault\n");
e06cabbd1a9b changes merged back from avifile cvs
arpi
parents: 2070
diff changeset
280 }
2070
c1edbb8bfc0c (solaris x86) C++ style variable declaration not at the start of a block does
jkeil
parents: 2069
diff changeset
281 }
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
282 #endif
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
283
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
284 Setup_FS_Segment();
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
285
18878
3bf0d70b4c7f rm unnecesary casts from void* - part 2
reynaldo
parents: 18858
diff changeset
286 ldt_fs->prev_struct = malloc(8);
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
287 *(void**)array.base_addr = ldt_fs->prev_struct;
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
288
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
289 return ldt_fs;
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
290 }
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
291
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
292 void Restore_LDT_Keeper(ldt_fs_t* ldt_fs)
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
293 {
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
294 if (ldt_fs == NULL || ldt_fs->fs_seg == 0)
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
295 return;
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
296 if (ldt_fs->prev_struct)
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
297 free(ldt_fs->prev_struct);
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
298 munmap((char*)ldt_fs->fs_seg, getpagesize());
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
299 ldt_fs->fs_seg = 0;
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 5872
diff changeset
300 free(ldt_fs);
2067
a5a4143d5599 setup_FS.c -> ldt_keeper.c (avifile sync)
arpi
parents:
diff changeset
301 }