2 * LDT manipulation functions
4 * Copyright 1993 Robert J. Amstadt
5 * Copyright 1995 Alexandre Julliard
16 #include "wine/library.h"
22 #ifdef HAVE_SYS_SYSCALL_H
23 # include <sys/syscall.h>
28 unsigned int entry_number
;
29 unsigned long base_addr
;
31 unsigned int seg_32bit
: 1;
32 unsigned int contents
: 2;
33 unsigned int read_exec_only
: 1;
34 unsigned int limit_in_pages
: 1;
35 unsigned int seg_not_present
: 1;
38 static inline int modify_ldt( int func
, struct modify_ldt_s
*ptr
,
43 __asm__
__volatile__( "pushl %%ebx\n\t"
48 : "0" (SYS_modify_ldt
),
53 __asm__
__volatile__("int $0x80"
55 : "0" (SYS_modify_ldt
),
60 if (res
>= 0) return res
;
67 #if defined(__svr4__) || defined(_SCO_DS)
68 #include <sys/sysi86.h>
69 extern int sysi86(int,void*);
75 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
76 #include <machine/segments.h>
78 extern int i386_get_ldt(int, union descriptor
*, int);
79 extern int i386_set_ldt(int, union descriptor
*, int);
80 #endif /* __NetBSD__ || __FreeBSD__ || __OpenBSD__ */
84 /* local copy of the LDT */
85 struct __wine_ldt_copy wine_ldt_copy
;
88 /***********************************************************************
91 * Retrieve an LDT entry.
93 void wine_ldt_get_entry( unsigned short sel
, LDT_ENTRY
*entry
)
96 wine_ldt_set_base( entry
, wine_ldt_copy
.base
[index
] );
97 wine_ldt_set_limit( entry
, wine_ldt_copy
.limit
[index
] );
98 wine_ldt_set_flags( entry
, wine_ldt_copy
.flags
[index
] );
102 /***********************************************************************
107 int wine_ldt_set_entry( unsigned short sel
, const LDT_ENTRY
*entry
)
109 int ret
= 0, index
= sel
>> 3;
111 /* Entry 0 must not be modified; its base and limit are always 0 */
112 if (!index
) return 0;
118 struct modify_ldt_s ldt_info
;
120 ldt_info
.entry_number
= index
;
121 ldt_info
.base_addr
= (unsigned long)wine_ldt_get_base(entry
);
122 ldt_info
.limit
= entry
->LimitLow
| (entry
->HighWord
.Bits
.LimitHi
<< 16);
123 ldt_info
.seg_32bit
= entry
->HighWord
.Bits
.Default_Big
;
124 ldt_info
.contents
= (entry
->HighWord
.Bits
.Type
>> 2) & 3;
125 ldt_info
.read_exec_only
= !(entry
->HighWord
.Bits
.Type
& 2);
126 ldt_info
.limit_in_pages
= entry
->HighWord
.Bits
.Granularity
;
127 ldt_info
.seg_not_present
= !entry
->HighWord
.Bits
.Pres
;
129 if ((ret
= modify_ldt(1, &ldt_info
, sizeof(ldt_info
))) < 0)
130 perror( "modify_ldt" );
134 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
136 ret
= i386_set_ldt(index
, (union descriptor
*)entry
, 1);
139 perror("i386_set_ldt");
140 fprintf( stderr
, "Did you reconfigure the kernel with \"options USER_LDT\"?\n" );
144 #endif /* __NetBSD__ || __FreeBSD__ || __OpenBSD__ */
146 #if defined(__svr4__) || defined(_SCO_DS)
150 ldt_mod
.bo
= (unsigned long)wine_ldt_get_base(entry
);
151 ldt_mod
.ls
= entry
->LimitLow
| (entry
->HighWord
.Bits
.LimitHi
<< 16);
152 ldt_mod
.acc1
= entry
->HighWord
.Bytes
.Flags1
;
153 ldt_mod
.acc2
= entry
->HighWord
.Bytes
.Flags2
>> 4;
154 if ((ret
= sysi86(SI86DSCR
, &ldt_mod
)) == -1) perror("sysi86");
158 #endif /* __i386__ */
162 wine_ldt_copy
.base
[index
] = wine_ldt_get_base(entry
);
163 wine_ldt_copy
.limit
[index
] = wine_ldt_get_limit(entry
);
164 wine_ldt_copy
.flags
[index
] = (entry
->HighWord
.Bits
.Type
|
165 (entry
->HighWord
.Bits
.Default_Big
? WINE_LDT_FLAGS_32BIT
: 0) |
166 (wine_ldt_copy
.flags
[index
] & WINE_LDT_FLAGS_ALLOCATED
));