4 * Copyright 1995 Alexandre Julliard
18 /* This structure represents a real LDT entry. */
19 /* It is used by get_ldt_entry() and set_ldt_entry(). */
22 unsigned long base
; /* base address */
23 unsigned long limit
; /* segment limit (in pages or bytes) */
24 int seg_32bit
; /* is segment 32-bit? */
25 int read_only
; /* is segment read-only? */
26 int limit_in_pages
; /* is the limit in pages or bytes? */
27 enum seg_type type
; /* segment type */
29 void LDT_BytesToEntry( const unsigned long *buffer
, ldt_entry
*content
);
30 void LDT_EntryToBytes( unsigned long *buffer
, const ldt_entry
*content
);
31 int LDT_GetEntry( int entry
, ldt_entry
*content
);
32 int LDT_SetEntry( int entry
, const ldt_entry
*content
);
33 void LDT_Print( int start
, int length
);
36 /* This structure is used to build the local copy of the LDT. */
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 */
45 extern ldt_copy_entry ldt_copy
[LDT_SIZE
];
47 #define AHSHIFT 3 /* don't change! */
48 #define AHINCR (1 << AHSHIFT)
50 #define SELECTOR_TO_ENTRY(sel) (((int)(sel) & 0xffff) >> AHSHIFT)
51 #define ENTRY_TO_SELECTOR(i) ((i) ? (((int)(i) << AHSHIFT) | 7) : 0)
52 #define IS_LDT_ENTRY_FREE(i) (!(ldt_flags_copy[(i)] & LDT_FLAGS_ALLOCATED))
53 #define IS_SELECTOR_FREE(sel) (IS_LDT_ENTRY_FREE(SELECTOR_TO_ENTRY(sel)))
54 #define GET_SEL_BASE(sel) (ldt_copy[SELECTOR_TO_ENTRY(sel)].base)
55 #define GET_SEL_LIMIT(sel) (ldt_copy[SELECTOR_TO_ENTRY(sel)].limit)
57 /* Convert a segmented ptr (16:16) to a linear (32) pointer */
59 #define PTR_SEG_OFF_TO_LIN(seg,off) \
60 ((void*)(GET_SEL_BASE(seg) + (unsigned int)(off)))
61 #define PTR_SEG_TO_LIN(ptr) \
62 PTR_SEG_OFF_TO_LIN(SELECTOROF(ptr),OFFSETOF(ptr))
63 #define PTR_SEG_OFF_TO_SEGPTR(seg,off) \
64 ((SEGPTR)MAKELONG(off,seg))
65 #define PTR_SEG_OFF_TO_HUGEPTR(seg,off) \
66 PTR_SEG_OFF_TO_SEGPTR( (seg) + (HIWORD(off) << AHSHIFT), LOWORD(off) )
68 #define W32S_APPLICATION() (PROCESS_Current()->flags & PDB32_WIN32S_PROC)
69 #define W32S_OFFSET 0x10000
70 #define W32S_APP2WINE(addr, offset) ((addr)? (DWORD)(addr) + (DWORD)(offset) : 0)
71 #define W32S_WINE2APP(addr, offset) ((addr)? (DWORD)(addr) - (DWORD)(offset) : 0)
73 extern unsigned char ldt_flags_copy
[LDT_SIZE
];
75 #define LDT_FLAGS_TYPE 0x03 /* Mask for segment type */
76 #define LDT_FLAGS_READONLY 0x04 /* Segment is read-only (data) */
77 #define LDT_FLAGS_EXECONLY 0x04 /* Segment is execute-only (code) */
78 #define LDT_FLAGS_32BIT 0x08 /* Segment is 32-bit (code or stack) */
79 #define LDT_FLAGS_BIG 0x10 /* Segment is big (limit is in pages) */
80 #define LDT_FLAGS_ALLOCATED 0x80 /* Segment is allocated (no longer free) */
82 #define GET_SEL_FLAGS(sel) (ldt_flags_copy[SELECTOR_TO_ENTRY(sel)])
84 #define FIRST_LDT_ENTRY_TO_ALLOC 17
86 /* Determine if sel is a system selector (i.e. not managed by Wine) */
87 #define IS_SELECTOR_SYSTEM(sel) \
88 (!((sel) & 4) || (SELECTOR_TO_ENTRY(sel) < FIRST_LDT_ENTRY_TO_ALLOC))
89 #define IS_SELECTOR_32BIT(sel) \
90 (IS_SELECTOR_SYSTEM(sel) || (GET_SEL_FLAGS(sel) & LDT_FLAGS_32BIT))
92 #endif /* MPLAYER_LDT_H */