4 * Copyright 1995 Alexandre Julliard
19 /* This structure represents a real LDT entry. */
20 /* It is used by get_ldt_entry() and set_ldt_entry(). */
23 unsigned long base
; /* base address */
24 unsigned long limit
; /* segment limit (in pages or bytes) */
25 int seg_32bit
; /* is segment 32-bit? */
26 int read_only
; /* is segment read-only? */
27 int limit_in_pages
; /* is the limit in pages or bytes? */
28 enum seg_type type
; /* segment type */
31 extern void LDT_BytesToEntry( const unsigned long *buffer
, ldt_entry
*content
);
32 extern void LDT_EntryToBytes( unsigned long *buffer
, const ldt_entry
*content
);
33 extern int LDT_GetEntry( int entry
, ldt_entry
*content
);
34 extern int LDT_SetEntry( int entry
, const ldt_entry
*content
);
35 extern void LDT_Print( int start
, int length
);
38 /* This structure is used to build the local copy of the LDT. */
41 unsigned long base
; /* base address or 0 if entry is free */
42 unsigned long limit
; /* limit in bytes or 0 if entry is free */
47 extern ldt_copy_entry ldt_copy
[LDT_SIZE
];
49 #define __AHSHIFT 3 /* don't change! */
50 #define __AHINCR (1 << __AHSHIFT)
52 #define SELECTOR_TO_ENTRY(sel) (((int)(sel) & 0xffff) >> __AHSHIFT)
53 #define ENTRY_TO_SELECTOR(i) ((i) ? (((int)(i) << __AHSHIFT) | 7) : 0)
54 #define IS_LDT_ENTRY_FREE(i) (!(ldt_flags_copy[(i)] & LDT_FLAGS_ALLOCATED))
55 #define IS_SELECTOR_FREE(sel) (IS_LDT_ENTRY_FREE(SELECTOR_TO_ENTRY(sel)))
56 #define GET_SEL_BASE(sel) (ldt_copy[SELECTOR_TO_ENTRY(sel)].base)
57 #define GET_SEL_LIMIT(sel) (ldt_copy[SELECTOR_TO_ENTRY(sel)].limit)
59 /* Convert a segmented ptr (16:16) to a linear (32) pointer */
61 #define PTR_SEG_OFF_TO_LIN(seg,off) \
62 ((void*)(GET_SEL_BASE(seg) + (unsigned int)(off)))
63 #define PTR_SEG_TO_LIN(ptr) \
64 PTR_SEG_OFF_TO_LIN(SELECTOROF(ptr),OFFSETOF(ptr))
65 #define PTR_SEG_OFF_TO_SEGPTR(seg,off) \
66 ((SEGPTR)MAKELONG(off,seg))
67 #define PTR_SEG_OFF_TO_HUGEPTR(seg,off) \
68 PTR_SEG_OFF_TO_SEGPTR( (seg) + (HIWORD(off) << __AHSHIFT), LOWORD(off) )
70 extern unsigned char ldt_flags_copy
[LDT_SIZE
];
72 #define LDT_FLAGS_TYPE 0x03 /* Mask for segment type */
73 #define LDT_FLAGS_READONLY 0x04 /* Segment is read-only (data) */
74 #define LDT_FLAGS_EXECONLY 0x04 /* Segment is execute-only (code) */
75 #define LDT_FLAGS_32BIT 0x08 /* Segment is 32-bit (code or stack) */
76 #define LDT_FLAGS_BIG 0x10 /* Segment is big (limit is in pages) */
77 #define LDT_FLAGS_ALLOCATED 0x80 /* Segment is allocated (no longer free) */
79 #define GET_SEL_FLAGS(sel) (ldt_flags_copy[SELECTOR_TO_ENTRY(sel)])
81 #define FIRST_LDT_ENTRY_TO_ALLOC 17
83 /* Determine if sel is a system selector (i.e. not managed by Wine) */
84 #define IS_SELECTOR_SYSTEM(sel) \
85 (!((sel) & 4) || (SELECTOR_TO_ENTRY(sel) < FIRST_LDT_ENTRY_TO_ALLOC))
86 #define IS_SELECTOR_32BIT(sel) \
87 (IS_SELECTOR_SYSTEM(sel) || (GET_SEL_FLAGS(sel) & LDT_FLAGS_32BIT))
89 #endif /* __WINE_LDT_H */