Moved HRASCONN from windef.h.
[wine] / include / wine / library.h
1 /*
2  * Definitions for the Wine library
3  *
4  * Copyright 2000 Alexandre Julliard
5  */
6
7 #ifndef __WINE_WINE_LIBRARY_H
8 #define __WINE_WINE_LIBRARY_H
9
10 #include <sys/types.h>
11 #include "winbase.h"
12
13 /* dll loading */
14
15 typedef void (*load_dll_callback_t)( void *, const char * );
16
17 extern void wine_dll_set_callback( load_dll_callback_t load );
18 extern void *wine_dll_load( const char *filename, char *error, int errorsize );
19 extern void *wine_dll_load_main_exe( const char *name, int search_path );
20 extern void wine_dll_unload( void *handle );
21
22 /* debugging */
23
24 extern void wine_dbg_add_option( const char *name, unsigned char set, unsigned char clear );
25
26 /* portability */
27
28 extern void *wine_anon_mmap( void *start, size_t size, int prot, int flags );
29
30 /* LDT management */
31
32 extern void wine_ldt_get_entry( unsigned short sel, LDT_ENTRY *entry );
33 extern int wine_ldt_set_entry( unsigned short sel, const LDT_ENTRY *entry );
34
35 /* the local copy of the LDT */
36 extern struct __wine_ldt_copy
37 {
38     void         *base[8192];  /* base address or 0 if entry is free   */
39     unsigned long limit[8192]; /* limit in bytes or 0 if entry is free */
40     unsigned char flags[8192]; /* flags (defined below) */
41 } wine_ldt_copy;
42
43 #define WINE_LDT_FLAGS_DATA      0x13  /* Data segment */
44 #define WINE_LDT_FLAGS_STACK     0x17  /* Stack segment */
45 #define WINE_LDT_FLAGS_CODE      0x1b  /* Code segment */
46 #define WINE_LDT_FLAGS_TYPE_MASK 0x1f  /* Mask for segment type */
47 #define WINE_LDT_FLAGS_32BIT     0x40  /* Segment is 32-bit (code or stack) */
48 #define WINE_LDT_FLAGS_ALLOCATED 0x80  /* Segment is allocated (no longer free) */
49
50 /* helper functions to manipulate the LDT_ENTRY structure */
51 inline static void wine_ldt_set_base( LDT_ENTRY *ent, const void *base )
52 {
53     ent->BaseLow               = (WORD)(unsigned long)base;
54     ent->HighWord.Bits.BaseMid = (BYTE)((unsigned long)base >> 16);
55     ent->HighWord.Bits.BaseHi  = (BYTE)((unsigned long)base >> 24);
56 }
57 inline static void wine_ldt_set_limit( LDT_ENTRY *ent, unsigned int limit )
58 {
59     if ((ent->HighWord.Bits.Granularity = (limit >= 0x100000))) limit >>= 12;
60     ent->LimitLow = (WORD)limit;
61     ent->HighWord.Bits.LimitHi = (limit >> 16);
62 }
63 inline static void *wine_ldt_get_base( const LDT_ENTRY *ent )
64 {
65     return (void *)(ent->BaseLow |
66                     (unsigned long)ent->HighWord.Bits.BaseMid << 16 |
67                     (unsigned long)ent->HighWord.Bits.BaseHi << 24);
68 }
69 inline static unsigned int wine_ldt_get_limit( const LDT_ENTRY *ent )
70 {
71     unsigned int limit = ent->LimitLow | (ent->HighWord.Bits.LimitHi << 16);
72     if (ent->HighWord.Bits.Granularity) limit = (limit << 12) | 0xfff;
73     return limit;
74 }
75 inline static void wine_ldt_set_flags( LDT_ENTRY *ent, unsigned char flags )
76 {
77     ent->HighWord.Bits.Dpl         = 3;
78     ent->HighWord.Bits.Pres        = 1;
79     ent->HighWord.Bits.Type        = flags;
80     ent->HighWord.Bits.Sys         = 0;
81     ent->HighWord.Bits.Reserved_0  = 0;
82     ent->HighWord.Bits.Default_Big = (flags & WINE_LDT_FLAGS_32BIT) != 0;
83 }
84 inline static unsigned char wine_ldt_get_flags( const LDT_ENTRY *ent )
85 {
86     unsigned char ret = ent->HighWord.Bits.Type;
87     if (ent->HighWord.Bits.Default_Big) ret |= WINE_LDT_FLAGS_32BIT;
88     return ret;
89 }
90
91 #endif  /* __WINE_WINE_LIBRARY_H */