2 * Definitions for the Wine library
4 * Copyright 2000 Alexandre Julliard
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.
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.
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
21 #ifndef __WINE_WINE_LIBRARY_H
22 #define __WINE_WINE_LIBRARY_H
25 #include <sys/types.h>
30 #ifdef __WINE_WINE_TEST_H
31 #error This file should not be used in Wine tests
34 #ifdef __WINE_USE_MSVCRT
35 #error This file should not be used with msvcrt headers
44 extern const char *wine_get_build_dir(void);
45 extern const char *wine_get_config_dir(void);
46 extern const char *wine_get_data_dir(void);
47 extern const char *wine_get_server_dir(void);
48 extern const char *wine_get_user_name(void);
49 extern const char *wine_get_version(void);
50 extern const char *wine_get_build_id(void);
51 extern void wine_init_argv0_path( const char *argv0
);
52 extern void wine_exec_wine_binary( const char *name
, char **argv
, const char *env_var
);
56 typedef void (*load_dll_callback_t
)( void *, const char * );
58 extern void *wine_dlopen( const char *filename
, int flag
, char *error
, size_t errorsize
);
59 extern void *wine_dlsym( void *handle
, const char *symbol
, char *error
, size_t errorsize
);
60 extern int wine_dlclose( void *handle
, char *error
, size_t errorsize
);
61 extern void wine_dll_set_callback( load_dll_callback_t load
);
62 extern void *wine_dll_load( const char *filename
, char *error
, int errorsize
, int *file_exists
);
63 extern void *wine_dll_load_main_exe( const char *name
, char *error
, int errorsize
,
64 int test_only
, int *file_exists
);
65 extern void wine_dll_unload( void *handle
);
66 extern const char *wine_dll_enum_load_path( unsigned int index
);
67 extern int wine_dll_get_owner( const char *name
, char *buffer
, int size
, int *file_exists
);
69 extern int __wine_main_argc
;
70 extern char **__wine_main_argv
;
71 extern WCHAR
**__wine_main_wargv
;
72 extern void __wine_dll_register( const IMAGE_NT_HEADERS
*header
, const char *filename
);
73 extern void wine_init( int argc
, char *argv
[], char *error
, int error_size
);
77 extern void DECLSPEC_NORETURN
wine_switch_to_stack( void (*func
)(void *), void *arg
, void *stack
);
78 extern int wine_call_on_stack( int (*func
)(void *), void *arg
, void *stack
);
82 extern void *wine_anon_mmap( void *start
, size_t size
, int prot
, int flags
);
83 extern void wine_mmap_add_reserved_area( void *addr
, size_t size
);
84 extern void wine_mmap_remove_reserved_area( void *addr
, size_t size
, int unmap
);
85 extern int wine_mmap_is_in_reserved_area( void *addr
, size_t size
);
86 extern int wine_mmap_enum_reserved_areas( int (*enum_func
)(void *base
, size_t size
, void *arg
),
87 void *arg
, int top_down
);
93 extern void wine_ldt_init_locking( void (*lock_func
)(void), void (*unlock_func
)(void) );
94 extern void wine_ldt_get_entry( unsigned short sel
, LDT_ENTRY
*entry
);
95 extern int wine_ldt_set_entry( unsigned short sel
, const LDT_ENTRY
*entry
);
96 extern int wine_ldt_is_system( unsigned short sel
);
97 extern void *wine_ldt_get_ptr( unsigned short sel
, unsigned long offset
);
98 extern unsigned short wine_ldt_alloc_entries( int count
);
99 extern unsigned short wine_ldt_realloc_entries( unsigned short sel
, int oldcount
, int newcount
);
100 extern void wine_ldt_free_entries( unsigned short sel
, int count
);
101 extern unsigned short wine_ldt_alloc_fs(void);
102 extern void wine_ldt_init_fs( unsigned short sel
, const LDT_ENTRY
*entry
);
103 extern void wine_ldt_free_fs( unsigned short sel
);
105 /* the local copy of the LDT */
106 extern struct __wine_ldt_copy
108 void *base
[8192]; /* base address or 0 if entry is free */
109 unsigned long limit
[8192]; /* limit in bytes or 0 if entry is free */
110 unsigned char flags
[8192]; /* flags (defined below) */
113 #define WINE_LDT_FLAGS_DATA 0x13 /* Data segment */
114 #define WINE_LDT_FLAGS_STACK 0x17 /* Stack segment */
115 #define WINE_LDT_FLAGS_CODE 0x1b /* Code segment */
116 #define WINE_LDT_FLAGS_TYPE_MASK 0x1f /* Mask for segment type */
117 #define WINE_LDT_FLAGS_32BIT 0x40 /* Segment is 32-bit (code or stack) */
118 #define WINE_LDT_FLAGS_ALLOCATED 0x80 /* Segment is allocated (no longer free) */
120 /* helper functions to manipulate the LDT_ENTRY structure */
121 static inline void wine_ldt_set_base( LDT_ENTRY
*ent
, const void *base
)
123 ent
->BaseLow
= (WORD
)(ULONG_PTR
)base
;
124 ent
->HighWord
.Bits
.BaseMid
= (BYTE
)((ULONG_PTR
)base
>> 16);
125 ent
->HighWord
.Bits
.BaseHi
= (BYTE
)((ULONG_PTR
)base
>> 24);
127 static inline void wine_ldt_set_limit( LDT_ENTRY
*ent
, unsigned int limit
)
129 if ((ent
->HighWord
.Bits
.Granularity
= (limit
>= 0x100000))) limit
>>= 12;
130 ent
->LimitLow
= (WORD
)limit
;
131 ent
->HighWord
.Bits
.LimitHi
= (limit
>> 16);
133 static inline void *wine_ldt_get_base( const LDT_ENTRY
*ent
)
135 return (void *)(ent
->BaseLow
|
136 (ULONG_PTR
)ent
->HighWord
.Bits
.BaseMid
<< 16 |
137 (ULONG_PTR
)ent
->HighWord
.Bits
.BaseHi
<< 24);
139 static inline unsigned int wine_ldt_get_limit( const LDT_ENTRY
*ent
)
141 unsigned int limit
= ent
->LimitLow
| (ent
->HighWord
.Bits
.LimitHi
<< 16);
142 if (ent
->HighWord
.Bits
.Granularity
) limit
= (limit
<< 12) | 0xfff;
145 static inline void wine_ldt_set_flags( LDT_ENTRY
*ent
, unsigned char flags
)
147 ent
->HighWord
.Bits
.Dpl
= 3;
148 ent
->HighWord
.Bits
.Pres
= 1;
149 ent
->HighWord
.Bits
.Type
= flags
;
150 ent
->HighWord
.Bits
.Sys
= 0;
151 ent
->HighWord
.Bits
.Reserved_0
= 0;
152 ent
->HighWord
.Bits
.Default_Big
= (flags
& WINE_LDT_FLAGS_32BIT
) != 0;
154 static inline unsigned char wine_ldt_get_flags( const LDT_ENTRY
*ent
)
156 unsigned char ret
= ent
->HighWord
.Bits
.Type
;
157 if (ent
->HighWord
.Bits
.Default_Big
) ret
|= WINE_LDT_FLAGS_32BIT
;
160 static inline int wine_ldt_is_empty( const LDT_ENTRY
*ent
)
162 const DWORD
*dw
= (const DWORD
*)ent
;
163 return (dw
[0] | dw
[1]) == 0;
166 /* segment register access */
168 # if defined(__GNUC__) && ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 2)))
169 # define __DEFINE_GET_SEG(seg) \
170 static FORCEINLINE unsigned short wine_get_##seg(void) \
171 { unsigned short res; __asm__ __volatile__("movw %%" #seg ",%w0" : "=r"(res)); return res; }
172 # define __DEFINE_SET_SEG(seg) \
173 static FORCEINLINE void wine_set_##seg(int val) \
174 { __asm__("movw %w0,%%" #seg : : "r" (val)); }
175 # elif defined(_MSC_VER)
176 # define __DEFINE_GET_SEG(seg) \
177 static inline unsigned short wine_get_##seg(void) \
178 { unsigned short res; __asm { mov res, seg } return res; }
179 # define __DEFINE_SET_SEG(seg) \
180 static inline void wine_set_##seg(unsigned short val) { __asm { mov seg, val } }
181 # else /* __GNUC__ || _MSC_VER */
182 # define __DEFINE_GET_SEG(seg) extern unsigned short wine_get_##seg(void);
183 # define __DEFINE_SET_SEG(seg) extern void wine_set_##seg(unsigned int);
184 # endif /* __GNUC__ || _MSC_VER */
194 #undef __DEFINE_GET_SEG
195 #undef __DEFINE_SET_SEG
197 #endif /* __i386__ */
203 #endif /* __WINE_WINE_LIBRARY_H */