| 1 | /* $Id: ldt.h,v 1.1 1999-05-24 20:19:13 ktk Exp $ */
|
|---|
| 2 |
|
|---|
| 3 | /*
|
|---|
| 4 | * LDT copy
|
|---|
| 5 | *
|
|---|
| 6 | * Copyright 1995 Alexandre Julliard
|
|---|
| 7 | */
|
|---|
| 8 |
|
|---|
| 9 | #ifndef __WINE_LDT_H
|
|---|
| 10 | #define __WINE_LDT_H
|
|---|
| 11 |
|
|---|
| 12 | #include "windef.h"
|
|---|
| 13 |
|
|---|
| 14 | enum seg_type
|
|---|
| 15 | {
|
|---|
| 16 | SEGMENT_DATA = 0,
|
|---|
| 17 | SEGMENT_STACK = 1,
|
|---|
| 18 | SEGMENT_CODE = 2
|
|---|
| 19 | };
|
|---|
| 20 |
|
|---|
| 21 | /* This structure represents a real LDT entry. */
|
|---|
| 22 | /* It is used by get_ldt_entry() and set_ldt_entry(). */
|
|---|
| 23 | typedef struct
|
|---|
| 24 | {
|
|---|
| 25 | unsigned long base; /* base address */
|
|---|
| 26 | unsigned long limit; /* segment limit (in pages or bytes) */
|
|---|
| 27 | int seg_32bit; /* is segment 32-bit? */
|
|---|
| 28 | int read_only; /* is segment read-only? */
|
|---|
| 29 | int limit_in_pages; /* is the limit in pages or bytes? */
|
|---|
| 30 | enum seg_type type; /* segment type */
|
|---|
| 31 | } ldt_entry;
|
|---|
| 32 |
|
|---|
| 33 | extern void LDT_BytesToEntry( const unsigned long *buffer, ldt_entry *content);
|
|---|
| 34 | extern void LDT_EntryToBytes( unsigned long *buffer, const ldt_entry *content);
|
|---|
| 35 | extern int LDT_GetEntry( int entry, ldt_entry *content );
|
|---|
| 36 | extern int LDT_SetEntry( int entry, const ldt_entry *content );
|
|---|
| 37 | extern void LDT_Print( int start, int length );
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 | /* This structure is used to build the local copy of the LDT. */
|
|---|
| 41 | typedef struct
|
|---|
| 42 | {
|
|---|
| 43 | unsigned long base; /* base address or 0 if entry is free */
|
|---|
| 44 | unsigned long limit; /* limit in bytes or 0 if entry is free */
|
|---|
| 45 | } ldt_copy_entry;
|
|---|
| 46 |
|
|---|
| 47 | #define LDT_SIZE 8192
|
|---|
| 48 |
|
|---|
| 49 | extern ldt_copy_entry ldt_copy[LDT_SIZE];
|
|---|
| 50 |
|
|---|
| 51 | #define __AHSHIFT 3 /* don't change! */
|
|---|
| 52 | #define __AHINCR (1 << __AHSHIFT)
|
|---|
| 53 |
|
|---|
| 54 | #define SELECTOR_TO_ENTRY(sel) (((int)(sel) & 0xffff) >> __AHSHIFT)
|
|---|
| 55 | #define ENTRY_TO_SELECTOR(i) ((i) ? (((int)(i) << __AHSHIFT) | 7) : 0)
|
|---|
| 56 | #define IS_LDT_ENTRY_FREE(i) (!(ldt_flags_copy[(i)] & LDT_FLAGS_ALLOCATED))
|
|---|
| 57 | #define IS_SELECTOR_FREE(sel) (IS_LDT_ENTRY_FREE(SELECTOR_TO_ENTRY(sel)))
|
|---|
| 58 | #define GET_SEL_BASE(sel) (ldt_copy[SELECTOR_TO_ENTRY(sel)].base)
|
|---|
| 59 | #define GET_SEL_LIMIT(sel) (ldt_copy[SELECTOR_TO_ENTRY(sel)].limit)
|
|---|
| 60 |
|
|---|
| 61 | /* Convert a segmented ptr (16:16) to a linear (32) pointer */
|
|---|
| 62 |
|
|---|
| 63 | #define PTR_SEG_OFF_TO_LIN(seg,off) \
|
|---|
| 64 | ((void*)(GET_SEL_BASE(seg) + (unsigned int)(off)))
|
|---|
| 65 | #define PTR_SEG_TO_LIN(ptr) \
|
|---|
| 66 | PTR_SEG_OFF_TO_LIN(SELECTOROF(ptr),OFFSETOF(ptr))
|
|---|
| 67 | #define PTR_SEG_OFF_TO_SEGPTR(seg,off) \
|
|---|
| 68 | ((SEGPTR)MAKELONG(off,seg))
|
|---|
| 69 | #define PTR_SEG_OFF_TO_HUGEPTR(seg,off) \
|
|---|
| 70 | PTR_SEG_OFF_TO_SEGPTR( (seg) + (HIWORD(off) << __AHSHIFT), LOWORD(off) )
|
|---|
| 71 |
|
|---|
| 72 | #define W32S_APPLICATION() (PROCESS_Current()->flags & PDB32_WIN32S_PROC)
|
|---|
| 73 | #define W32S_OFFSET 0x10000
|
|---|
| 74 | #define W32S_APP2WINE(addr, offset) ((addr)? (DWORD)(addr) + (DWORD)(offset) : 0)
|
|---|
| 75 | #define W32S_WINE2APP(addr, offset) ((addr)? (DWORD)(addr) - (DWORD)(offset) : 0)
|
|---|
| 76 |
|
|---|
| 77 | extern unsigned char ldt_flags_copy[LDT_SIZE];
|
|---|
| 78 |
|
|---|
| 79 | #define LDT_FLAGS_TYPE 0x03 /* Mask for segment type */
|
|---|
| 80 | #define LDT_FLAGS_READONLY 0x04 /* Segment is read-only (data) */
|
|---|
| 81 | #define LDT_FLAGS_EXECONLY 0x04 /* Segment is execute-only (code) */
|
|---|
| 82 | #define LDT_FLAGS_32BIT 0x08 /* Segment is 32-bit (code or stack) */
|
|---|
| 83 | #define LDT_FLAGS_BIG 0x10 /* Segment is big (limit is in pages) */
|
|---|
| 84 | #define LDT_FLAGS_ALLOCATED 0x80 /* Segment is allocated (no longer free) */
|
|---|
| 85 |
|
|---|
| 86 | #define GET_SEL_FLAGS(sel) (ldt_flags_copy[SELECTOR_TO_ENTRY(sel)])
|
|---|
| 87 |
|
|---|
| 88 | #define FIRST_LDT_ENTRY_TO_ALLOC 17
|
|---|
| 89 |
|
|---|
| 90 | /* Determine if sel is a system selector (i.e. not managed by Wine) */
|
|---|
| 91 | #define IS_SELECTOR_SYSTEM(sel) \
|
|---|
| 92 | (!((sel) & 4) || (SELECTOR_TO_ENTRY(sel) < FIRST_LDT_ENTRY_TO_ALLOC))
|
|---|
| 93 | #define IS_SELECTOR_32BIT(sel) \
|
|---|
| 94 | (IS_SELECTOR_SYSTEM(sel) || (GET_SEL_FLAGS(sel) & LDT_FLAGS_32BIT))
|
|---|
| 95 |
|
|---|
| 96 | #endif /* __WINE_LDT_H */
|
|---|