Stub for OleLoadPictureEx.
[wine.git] / library / ldt.c
blobca4e062f6343ddd1c545f783f4475f1a66773a28
1 /*
2 * LDT manipulation functions
4 * Copyright 1993 Robert J. Amstadt
5 * Copyright 1995 Alexandre Julliard
6 */
8 #include "config.h"
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <string.h>
13 #include <errno.h>
15 #include "winbase.h"
16 #include "wine/library.h"
18 #ifdef __i386__
20 #ifdef linux
22 #ifdef HAVE_SYS_SYSCALL_H
23 # include <sys/syscall.h>
24 #endif
26 struct modify_ldt_s
28 unsigned int entry_number;
29 unsigned long base_addr;
30 unsigned int limit;
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,
39 unsigned long count )
41 int res;
42 #ifdef __PIC__
43 __asm__ __volatile__( "pushl %%ebx\n\t"
44 "movl %2,%%ebx\n\t"
45 "int $0x80\n\t"
46 "popl %%ebx"
47 : "=a" (res)
48 : "0" (SYS_modify_ldt),
49 "r" (func),
50 "c" (ptr),
51 "d" (count) );
52 #else
53 __asm__ __volatile__("int $0x80"
54 : "=a" (res)
55 : "0" (SYS_modify_ldt),
56 "b" (func),
57 "c" (ptr),
58 "d" (count) );
59 #endif /* __PIC__ */
60 if (res >= 0) return res;
61 errno = -res;
62 return -1;
65 #endif /* linux */
67 #if defined(__svr4__) || defined(_SCO_DS)
68 #include <sys/sysi86.h>
69 extern int sysi86(int,void*);
70 #ifndef __sun__
71 #include <sys/seg.h>
72 #endif
73 #endif
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__ */
82 #endif /* __i386__ */
84 /* local copy of the LDT */
85 struct __wine_ldt_copy wine_ldt_copy;
88 /***********************************************************************
89 * ldt_get_entry
91 * Retrieve an LDT entry.
93 void wine_ldt_get_entry( unsigned short sel, LDT_ENTRY *entry )
95 int index = sel >> 3;
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 /***********************************************************************
103 * ldt_set_entry
105 * Set an LDT entry.
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;
114 #ifdef __i386__
116 #ifdef linux
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" );
132 #endif /* linux */
134 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
136 ret = i386_set_ldt(index, (union descriptor *)entry, 1);
137 if (ret < 0)
139 perror("i386_set_ldt");
140 fprintf( stderr, "Did you reconfigure the kernel with \"options USER_LDT\"?\n" );
141 exit(1);
144 #endif /* __NetBSD__ || __FreeBSD__ || __OpenBSD__ */
146 #if defined(__svr4__) || defined(_SCO_DS)
148 struct ssd ldt_mod;
149 ldt_mod.sel = sel;
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");
156 #endif
158 #endif /* __i386__ */
160 if (ret >= 0)
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));
168 return ret;