Release 960414
[wine.git] / include / ldt.h
blobb02b2cde70812976ee1524dbf2355f2124bf341b
1 /*
2 * LDT copy
4 * Copyright 1995 Alexandre Julliard
5 */
7 #ifndef _WINE_LDT_H
8 #define _WINE_LDT_H
10 enum seg_type
12 SEGMENT_DATA = 0,
13 SEGMENT_STACK = 1,
14 SEGMENT_CODE = 2
17 /* This structure represents a real LDT entry. */
18 /* It is used by get_ldt_entry() and set_ldt_entry(). */
19 typedef struct
21 unsigned long base; /* base address */
22 unsigned long limit; /* segment limit */
23 int seg_32bit; /* is segment 32-bit? */
24 int read_only; /* is segment read-only? */
25 int limit_in_pages; /* is the limit in pages or bytes? */
26 enum seg_type type; /* segment type */
27 } ldt_entry;
29 extern void LDT_BytesToEntry( const unsigned long *buffer, ldt_entry *content);
30 extern void LDT_EntryToBytes( unsigned long *buffer, const ldt_entry *content);
31 extern int LDT_GetEntry( int entry, ldt_entry *content );
32 extern int LDT_SetEntry( int entry, const ldt_entry *content );
33 extern void LDT_Print( int start, int length );
36 /* This structure is used to build the local copy of the LDT. */
37 typedef struct
39 unsigned long base; /* base address or 0 if entry is free */
40 unsigned long limit; /* limit in bytes or 0 if entry is free */
41 } ldt_copy_entry;
43 #define LDT_SIZE 8192
45 extern ldt_copy_entry ldt_copy[LDT_SIZE];
47 #define __AHSHIFT 3 /* don't change! */
48 #define __AHINCR (1 << __AHSHIFT)
50 #ifndef WINELIB
51 #define SELECTOR_TO_ENTRY(sel) (((int)(sel) & 0xffff) >> __AHSHIFT)
52 #define ENTRY_TO_SELECTOR(i) ((i) ? (((int)(i) << __AHSHIFT) | 7) : 0)
53 #define IS_LDT_ENTRY_FREE(i) (!(ldt_flags_copy[(i)] & LDT_FLAGS_ALLOCATED))
54 #define IS_SELECTOR_FREE(sel) (IS_LDT_ENTRY_FREE(SELECTOR_TO_ENTRY(sel)))
55 #define GET_SEL_BASE(sel) (ldt_copy[SELECTOR_TO_ENTRY(sel)].base)
56 #define GET_SEL_LIMIT(sel) (ldt_copy[SELECTOR_TO_ENTRY(sel)].limit)
57 #else
58 /* Complain if these are used in WineLib */
59 #define SELECTOR_TO_ENTRY(sel) error.error
60 #define ENTRY_TO_SELECTOR(i) error.error
61 #define IS_LDT_ENTRY_FREE(i) error.error
62 #define IS_SELECTOR_FREE(sel) error.error
63 #define GET_SEL_BASE(sel) error.error
64 #define GET_SEL_LIMIT(sel) error.error
65 #endif
67 #ifndef WINELIB
68 /* Convert a segmented ptr (16:16) to a linear (32) pointer */
69 #define PTR_SEG_TO_LIN(ptr) \
70 ((void*)(GET_SEL_BASE((int)(ptr) >> 16) + ((int)(ptr) & 0xffff)))
72 #define PTR_SEG_OFF_TO_LIN(seg,off) \
73 ((void*)(GET_SEL_BASE(seg) + (unsigned int)(off)))
74 #else
75 #define PTR_SEG_TO_LIN(ptr) ((void*)(ptr))
76 #define PTR_SEG_OFF_TO_LIN(seg,off) ((void*)((char*)(seg)+(int)(off)))
77 #endif
80 extern unsigned char ldt_flags_copy[LDT_SIZE];
82 #define LDT_FLAGS_TYPE 0x03 /* Mask for segment type */
83 #define LDT_FLAGS_READONLY 0x04 /* Segment is read-only (data) */
84 #define LDT_FLAGS_EXECONLY 0x04 /* Segment is execute-only (code) */
85 #define LDT_FLAGS_32BIT 0x08 /* Segment is 32-bit (code or stack) */
86 #define LDT_FLAGS_BIG 0x10 /* Segment is big (limit is in pages) */
87 #define LDT_FLAGS_ALLOCATED 0x80 /* Segment is allocated (no longer free) */
89 #define GET_SEL_FLAGS(sel) (ldt_flags_copy[SELECTOR_TO_ENTRY(sel)])
91 #endif /* _WINE_LDT_H */