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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #ifndef __WINE_WINE_LIBRARY_H
22 #define __WINE_WINE_LIBRARY_H
24 #include <sys/types.h>
29 extern const char *wine_get_config_dir(void);
30 extern const char *wine_get_server_dir(void);
31 extern const char *wine_get_user_name(void);
35 typedef void (*load_dll_callback_t
)( void *, const char * );
37 extern void *wine_dlopen( const char *filename
, int flag
, char *error
, int errorsize
);
38 extern void *wine_dlsym( void *handle
, const char *symbol
, char *error
, int errorsize
);
39 extern int wine_dlclose( void *handle
, char *error
, int errorsize
);
40 extern void wine_dll_set_callback( load_dll_callback_t load
);
41 extern void *wine_dll_load( const char *filename
, char *error
, int errorsize
);
42 extern void *wine_dll_load_main_exe( const char *name
, char *error
, int errorsize
, int test_only
);
43 extern void wine_dll_unload( void *handle
);
45 extern int __wine_main_argc
;
46 extern char **__wine_main_argv
;
47 extern WCHAR
**__wine_main_wargv
;
51 extern const char * (*__wine_dbgstr_an
)( const char * s
, int n
);
52 extern const char * (*__wine_dbgstr_wn
)( const WCHAR
*s
, int n
);
53 extern const char * (*__wine_dbg_vsprintf
)( const char *format
, va_list args
);
54 extern int (*__wine_dbg_vprintf
)( const char *format
, va_list args
);
55 extern int (*__wine_dbg_vlog
)( unsigned int cls
, const char *channel
,
56 const char *function
, const char *format
, va_list args
);
58 extern void wine_dbg_add_option( const char *name
, unsigned char set
, unsigned char clear
);
59 extern int wine_dbg_parse_options( const char *str
);
63 extern void *wine_anon_mmap( void *start
, size_t size
, int prot
, int flags
);
66 extern int* (*wine_errno_location
)(void);
67 extern int* (*wine_h_errno_location
)(void);
71 extern void wine_ldt_init_locking( void (*lock_func
)(void), void (*unlock_func
)(void) );
72 extern void wine_ldt_get_entry( unsigned short sel
, LDT_ENTRY
*entry
);
73 extern int wine_ldt_set_entry( unsigned short sel
, const LDT_ENTRY
*entry
);
74 extern void *wine_ldt_get_ptr( unsigned short sel
, unsigned int offset
);
75 extern unsigned short wine_ldt_alloc_entries( int count
);
76 extern unsigned short wine_ldt_realloc_entries( unsigned short sel
, int oldcount
, int newcount
);
77 extern void wine_ldt_free_entries( unsigned short sel
, int count
);
79 extern unsigned short wine_ldt_alloc_fs(void);
80 extern void wine_ldt_init_fs( unsigned short sel
, const LDT_ENTRY
*entry
);
81 extern void wine_ldt_free_fs( unsigned short sel
);
83 static inline unsigned short wine_ldt_alloc_fs(void) { return 0x0b; /* pseudo GDT selector */ }
84 static inline void wine_ldt_init_fs( unsigned short sel
, const LDT_ENTRY
*entry
) { }
85 static inline void wine_ldt_free_fs( unsigned short sel
) { }
89 /* the local copy of the LDT */
91 # ifdef WINE_EXPORT_LDT_COPY
92 # define WINE_LDT_EXTERN __declspec(dllexport)
94 # define WINE_LDT_EXTERN __declspec(dllimport)
97 # define WINE_LDT_EXTERN extern
100 WINE_LDT_EXTERN
struct __wine_ldt_copy
102 void *base
[8192]; /* base address or 0 if entry is free */
103 unsigned long limit
[8192]; /* limit in bytes or 0 if entry is free */
104 unsigned char flags
[8192]; /* flags (defined below) */
107 #define WINE_LDT_FLAGS_DATA 0x13 /* Data segment */
108 #define WINE_LDT_FLAGS_STACK 0x17 /* Stack segment */
109 #define WINE_LDT_FLAGS_CODE 0x1b /* Code segment */
110 #define WINE_LDT_FLAGS_TYPE_MASK 0x1f /* Mask for segment type */
111 #define WINE_LDT_FLAGS_32BIT 0x40 /* Segment is 32-bit (code or stack) */
112 #define WINE_LDT_FLAGS_ALLOCATED 0x80 /* Segment is allocated (no longer free) */
114 #define WINE_LDT_FIRST_ENTRY 17
116 /* helper functions to manipulate the LDT_ENTRY structure */
117 inline static void wine_ldt_set_base( LDT_ENTRY
*ent
, const void *base
)
119 ent
->BaseLow
= (WORD
)(unsigned long)base
;
120 ent
->HighWord
.Bits
.BaseMid
= (BYTE
)((unsigned long)base
>> 16);
121 ent
->HighWord
.Bits
.BaseHi
= (BYTE
)((unsigned long)base
>> 24);
123 inline static void wine_ldt_set_limit( LDT_ENTRY
*ent
, unsigned int limit
)
125 if ((ent
->HighWord
.Bits
.Granularity
= (limit
>= 0x100000))) limit
>>= 12;
126 ent
->LimitLow
= (WORD
)limit
;
127 ent
->HighWord
.Bits
.LimitHi
= (limit
>> 16);
129 inline static void *wine_ldt_get_base( const LDT_ENTRY
*ent
)
131 return (void *)(ent
->BaseLow
|
132 (unsigned long)ent
->HighWord
.Bits
.BaseMid
<< 16 |
133 (unsigned long)ent
->HighWord
.Bits
.BaseHi
<< 24);
135 inline static unsigned int wine_ldt_get_limit( const LDT_ENTRY
*ent
)
137 unsigned int limit
= ent
->LimitLow
| (ent
->HighWord
.Bits
.LimitHi
<< 16);
138 if (ent
->HighWord
.Bits
.Granularity
) limit
= (limit
<< 12) | 0xfff;
141 inline static void wine_ldt_set_flags( LDT_ENTRY
*ent
, unsigned char flags
)
143 ent
->HighWord
.Bits
.Dpl
= 3;
144 ent
->HighWord
.Bits
.Pres
= 1;
145 ent
->HighWord
.Bits
.Type
= flags
;
146 ent
->HighWord
.Bits
.Sys
= 0;
147 ent
->HighWord
.Bits
.Reserved_0
= 0;
148 ent
->HighWord
.Bits
.Default_Big
= (flags
& WINE_LDT_FLAGS_32BIT
) != 0;
150 inline static unsigned char wine_ldt_get_flags( const LDT_ENTRY
*ent
)
152 unsigned char ret
= ent
->HighWord
.Bits
.Type
;
153 if (ent
->HighWord
.Bits
.Default_Big
) ret
|= WINE_LDT_FLAGS_32BIT
;
156 inline static int wine_ldt_is_empty( const LDT_ENTRY
*ent
)
158 const DWORD
*dw
= (const DWORD
*)ent
;
159 return (dw
[0] | dw
[1]) == 0;
162 /* segment register access */
166 # define __DEFINE_GET_SEG(seg) \
167 extern inline unsigned short wine_get_##seg(void) \
168 { unsigned short res; __asm__("movw %%" #seg ",%w0" : "=r"(res)); return res; }
169 # define __DEFINE_SET_SEG(seg) \
170 extern inline void wine_set_##seg(int val) { __asm__("movw %w0,%%" #seg : : "r" (val)); }
171 # elif defined(_MSC_VER)
172 # define __DEFINE_GET_SEG(seg) \
173 extern inline unsigned short wine_get_##seg(void) \
174 { unsigned short res; __asm { mov res, seg } return res; }
175 # define __DEFINE_SET_SEG(seg) \
176 extern inline void wine_set_##seg(unsigned short val) { __asm { mov seg, val } }
177 # else /* __GNUC__ || _MSC_VER */
178 # define __DEFINE_GET_SEG(seg) extern unsigned short wine_get_##seg(void);
179 # define __DEFINE_SET_SEG(seg) extern void wine_set_##seg(unsigned int);
180 # endif /* __GNUC__ || _MSC_VER */
182 # define __DEFINE_GET_SEG(seg) inline static unsigned short wine_get_##seg(void) { return 0; }
183 # define __DEFINE_SET_SEG(seg) inline static void wine_set_##seg(int val) { /* nothing */ }
184 #endif /* __i386__ */
194 #undef __DEFINE_GET_SEG
195 #undef __DEFINE_SET_SEG
197 #endif /* __WINE_WINE_LIBRARY_H */