wined3d: Add sincos support to arb shaders.
[wine] / include / wine / library.h
1 /*
2  * Definitions for the Wine library
3  *
4  * Copyright 2000 Alexandre Julliard
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #ifndef __WINE_WINE_LIBRARY_H
22 #define __WINE_WINE_LIBRARY_H
23
24 #include <stdarg.h>
25 #include <sys/types.h>
26
27 #include <windef.h>
28 #include <winbase.h>
29
30 #ifdef __WINE_WINE_TEST_H
31 #error This file should not be used in Wine tests
32 #endif
33
34 /* configuration */
35
36 extern const char *wine_get_build_dir(void);
37 extern const char *wine_get_config_dir(void);
38 extern const char *wine_get_data_dir(void);
39 extern const char *wine_get_server_dir(void);
40 extern const char *wine_get_user_name(void);
41 extern void wine_init_argv0_path( const char *argv0 );
42 extern void wine_exec_wine_binary( const char *name, char **argv, const char *env_var );
43
44 /* dll loading */
45
46 typedef void (*load_dll_callback_t)( void *, const char * );
47
48 extern void *wine_dlopen( const char *filename, int flag, char *error, size_t errorsize );
49 extern void *wine_dlsym( void *handle, const char *symbol, char *error, size_t errorsize );
50 extern int wine_dlclose( void *handle, char *error, size_t errorsize );
51 extern void wine_dll_set_callback( load_dll_callback_t load );
52 extern void *wine_dll_load( const char *filename, char *error, int errorsize, int *file_exists );
53 extern void *wine_dll_load_main_exe( const char *name, char *error, int errorsize,
54                                      int test_only, int *file_exists );
55 extern void wine_dll_unload( void *handle );
56 extern const char *wine_dll_enum_load_path( unsigned int index );
57 extern int wine_dll_get_owner( const char *name, char *buffer, int size, int *file_exists );
58
59 extern int __wine_main_argc;
60 extern char **__wine_main_argv;
61 extern WCHAR **__wine_main_wargv;
62 extern char **__wine_main_environ;
63 extern void __wine_dll_register( const IMAGE_NT_HEADERS *header, const char *filename );
64 extern void wine_init( int argc, char *argv[], char *error, int error_size );
65
66 /* portability */
67
68 extern void DECLSPEC_NORETURN wine_switch_to_stack( void (*func)(void *), void *arg, void *stack );
69 extern void wine_set_pe_load_area( void *base, size_t size );
70 extern void wine_free_pe_load_area(void);
71
72 /* memory mappings */
73
74 extern void *wine_anon_mmap( void *start, size_t size, int prot, int flags );
75 extern void wine_mmap_add_reserved_area( void *addr, size_t size );
76 extern void wine_mmap_remove_reserved_area( void *addr, size_t size, int unmap );
77 extern int wine_mmap_is_in_reserved_area( void *addr, size_t size );
78 extern int wine_mmap_enum_reserved_areas( int (*enum_func)(void *base, size_t size, void *arg),
79                                           void *arg, int top_down );
80
81 /* LDT management */
82
83 extern void wine_ldt_init_locking( void (*lock_func)(void), void (*unlock_func)(void) );
84 extern void wine_ldt_get_entry( unsigned short sel, LDT_ENTRY *entry );
85 extern int wine_ldt_set_entry( unsigned short sel, const LDT_ENTRY *entry );
86 extern int wine_ldt_is_system( unsigned short sel );
87 extern void *wine_ldt_get_ptr( unsigned short sel, unsigned long offset );
88 extern unsigned short wine_ldt_alloc_entries( int count );
89 extern unsigned short wine_ldt_realloc_entries( unsigned short sel, int oldcount, int newcount );
90 extern void wine_ldt_free_entries( unsigned short sel, int count );
91 #ifdef __i386__
92 extern unsigned short wine_ldt_alloc_fs(void);
93 extern void wine_ldt_init_fs( unsigned short sel, const LDT_ENTRY *entry );
94 extern void wine_ldt_free_fs( unsigned short sel );
95 #else  /* __i386__ */
96 static inline unsigned short wine_ldt_alloc_fs(void) { return 0x0b; /* pseudo GDT selector */ }
97 static inline void wine_ldt_init_fs( unsigned short sel, const LDT_ENTRY *entry ) { }
98 static inline void wine_ldt_free_fs( unsigned short sel ) { }
99 #endif  /* __i386__ */
100
101
102 /* the local copy of the LDT */
103 #ifdef __CYGWIN__
104 # ifdef WINE_EXPORT_LDT_COPY
105 #  define WINE_LDT_EXTERN __declspec(dllexport)
106 # else
107 #  define WINE_LDT_EXTERN __declspec(dllimport)
108 # endif
109 #else
110 # define WINE_LDT_EXTERN extern
111 #endif
112
113 WINE_LDT_EXTERN struct __wine_ldt_copy
114 {
115     void         *base[8192];  /* base address or 0 if entry is free   */
116     unsigned long limit[8192]; /* limit in bytes or 0 if entry is free */
117     unsigned char flags[8192]; /* flags (defined below) */
118 } wine_ldt_copy;
119
120 #define WINE_LDT_FLAGS_DATA      0x13  /* Data segment */
121 #define WINE_LDT_FLAGS_STACK     0x17  /* Stack segment */
122 #define WINE_LDT_FLAGS_CODE      0x1b  /* Code segment */
123 #define WINE_LDT_FLAGS_TYPE_MASK 0x1f  /* Mask for segment type */
124 #define WINE_LDT_FLAGS_32BIT     0x40  /* Segment is 32-bit (code or stack) */
125 #define WINE_LDT_FLAGS_ALLOCATED 0x80  /* Segment is allocated (no longer free) */
126
127 /* helper functions to manipulate the LDT_ENTRY structure */
128 static inline void wine_ldt_set_base( LDT_ENTRY *ent, const void *base )
129 {
130     ent->BaseLow               = (WORD)(unsigned long)base;
131     ent->HighWord.Bits.BaseMid = (BYTE)((unsigned long)base >> 16);
132     ent->HighWord.Bits.BaseHi  = (BYTE)((unsigned long)base >> 24);
133 }
134 static inline void wine_ldt_set_limit( LDT_ENTRY *ent, unsigned int limit )
135 {
136     if ((ent->HighWord.Bits.Granularity = (limit >= 0x100000))) limit >>= 12;
137     ent->LimitLow = (WORD)limit;
138     ent->HighWord.Bits.LimitHi = (limit >> 16);
139 }
140 static inline void *wine_ldt_get_base( const LDT_ENTRY *ent )
141 {
142     return (void *)(ent->BaseLow |
143                     (unsigned long)ent->HighWord.Bits.BaseMid << 16 |
144                     (unsigned long)ent->HighWord.Bits.BaseHi << 24);
145 }
146 static inline unsigned int wine_ldt_get_limit( const LDT_ENTRY *ent )
147 {
148     unsigned int limit = ent->LimitLow | (ent->HighWord.Bits.LimitHi << 16);
149     if (ent->HighWord.Bits.Granularity) limit = (limit << 12) | 0xfff;
150     return limit;
151 }
152 static inline void wine_ldt_set_flags( LDT_ENTRY *ent, unsigned char flags )
153 {
154     ent->HighWord.Bits.Dpl         = 3;
155     ent->HighWord.Bits.Pres        = 1;
156     ent->HighWord.Bits.Type        = flags;
157     ent->HighWord.Bits.Sys         = 0;
158     ent->HighWord.Bits.Reserved_0  = 0;
159     ent->HighWord.Bits.Default_Big = (flags & WINE_LDT_FLAGS_32BIT) != 0;
160 }
161 static inline unsigned char wine_ldt_get_flags( const LDT_ENTRY *ent )
162 {
163     unsigned char ret = ent->HighWord.Bits.Type;
164     if (ent->HighWord.Bits.Default_Big) ret |= WINE_LDT_FLAGS_32BIT;
165     return ret;
166 }
167 static inline int wine_ldt_is_empty( const LDT_ENTRY *ent )
168 {
169     const DWORD *dw = (const DWORD *)ent;
170     return (dw[0] | dw[1]) == 0;
171 }
172
173 /* segment register access */
174
175 #ifdef __i386__
176 # ifdef __GNUC__
177 #  define __DEFINE_GET_SEG(seg) \
178     extern inline unsigned short wine_get_##seg(void); \
179     extern inline unsigned short wine_get_##seg(void) \
180     { unsigned short res; __asm__ __volatile__("movw %%" #seg ",%w0" : "=r"(res)); return res; }
181 #  define __DEFINE_SET_SEG(seg) \
182     extern inline void wine_set_##seg(int val); \
183     extern inline void wine_set_##seg(int val) { __asm__("movw %w0,%%" #seg : : "r" (val)); }
184 # elif defined(_MSC_VER)
185 #  define __DEFINE_GET_SEG(seg) \
186     extern inline unsigned short wine_get_##seg(void); \
187     extern inline unsigned short wine_get_##seg(void) \
188     { unsigned short res; __asm { mov res, seg } return res; }
189 #  define __DEFINE_SET_SEG(seg) \
190     extern inline void wine_set_##seg(unsigned short val); \
191     extern inline void wine_set_##seg(unsigned short val) { __asm { mov seg, val } }
192 # else  /* __GNUC__ || _MSC_VER */
193 #  define __DEFINE_GET_SEG(seg) extern unsigned short wine_get_##seg(void);
194 #  define __DEFINE_SET_SEG(seg) extern void wine_set_##seg(unsigned int);
195 # endif /* __GNUC__ || _MSC_VER */
196 #else  /* __i386__ */
197 # define __DEFINE_GET_SEG(seg) static inline unsigned short wine_get_##seg(void) { return 0; }
198 # define __DEFINE_SET_SEG(seg) static inline void wine_set_##seg(int val) { /* nothing */ }
199 #endif  /* __i386__ */
200
201 __DEFINE_GET_SEG(cs)
202 __DEFINE_GET_SEG(ds)
203 __DEFINE_GET_SEG(es)
204 __DEFINE_GET_SEG(fs)
205 __DEFINE_GET_SEG(gs)
206 __DEFINE_GET_SEG(ss)
207 __DEFINE_SET_SEG(fs)
208 __DEFINE_SET_SEG(gs)
209 #undef __DEFINE_GET_SEG
210 #undef __DEFINE_SET_SEG
211
212 #endif  /* __WINE_WINE_LIBRARY_H */