Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 1 | /* |
| 2 | * LDT copy |
| 3 | * |
| 4 | * Copyright 1995 Alexandre Julliard |
| 5 | */ |
| 6 | |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 7 | #ifndef __WINE_LDT_H |
| 8 | #define __WINE_LDT_H |
| 9 | |
Jim Aston | 2e1cafa | 1999-03-14 16:35:05 +0000 | [diff] [blame] | 10 | #include "windef.h" |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 11 | |
| 12 | enum seg_type |
| 13 | { |
| 14 | SEGMENT_DATA = 0, |
| 15 | SEGMENT_STACK = 1, |
| 16 | SEGMENT_CODE = 2 |
| 17 | }; |
| 18 | |
| 19 | /* This structure represents a real LDT entry. */ |
| 20 | /* It is used by get_ldt_entry() and set_ldt_entry(). */ |
| 21 | typedef struct |
| 22 | { |
| 23 | unsigned long base; /* base address */ |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 24 | unsigned long limit; /* segment limit (in pages or bytes) */ |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 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 */ |
| 29 | } ldt_entry; |
| 30 | |
Alexandre Julliard | bd34d4f | 1995-06-20 19:08:12 +0000 | [diff] [blame] | 31 | extern void LDT_BytesToEntry( const unsigned long *buffer, ldt_entry *content); |
| 32 | extern void LDT_EntryToBytes( unsigned long *buffer, const ldt_entry *content); |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 33 | extern int LDT_GetEntry( int entry, ldt_entry *content ); |
Alexandre Julliard | bd34d4f | 1995-06-20 19:08:12 +0000 | [diff] [blame] | 34 | extern int LDT_SetEntry( int entry, const ldt_entry *content ); |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 35 | extern void LDT_Print( int start, int length ); |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 36 | |
| 37 | |
| 38 | /* This structure is used to build the local copy of the LDT. */ |
| 39 | typedef struct |
| 40 | { |
| 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 */ |
| 43 | } ldt_copy_entry; |
| 44 | |
| 45 | #define LDT_SIZE 8192 |
| 46 | |
| 47 | extern ldt_copy_entry ldt_copy[LDT_SIZE]; |
| 48 | |
Alexandre Julliard | e2991ea | 1995-07-29 13:09:43 +0000 | [diff] [blame] | 49 | #define __AHSHIFT 3 /* don't change! */ |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 50 | #define __AHINCR (1 << __AHSHIFT) |
| 51 | |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 52 | #define SELECTOR_TO_ENTRY(sel) (((int)(sel) & 0xffff) >> __AHSHIFT) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 53 | #define ENTRY_TO_SELECTOR(i) ((i) ? (((int)(i) << __AHSHIFT) | 7) : 0) |
Alexandre Julliard | e2991ea | 1995-07-29 13:09:43 +0000 | [diff] [blame] | 54 | #define IS_LDT_ENTRY_FREE(i) (!(ldt_flags_copy[(i)] & LDT_FLAGS_ALLOCATED)) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 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) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 58 | |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 59 | /* Convert a segmented ptr (16:16) to a linear (32) pointer */ |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 60 | |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 61 | #define PTR_SEG_OFF_TO_LIN(seg,off) \ |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 62 | ((void*)(GET_SEL_BASE(seg) + (unsigned int)(off))) |
Alexandre Julliard | 770eb51 | 2000-09-24 20:47:50 +0000 | [diff] [blame] | 63 | #define PTR_REAL_TO_LIN(seg,off) \ |
| 64 | ((void*)(((unsigned int)(seg) << 4) + LOWORD(off))) |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 65 | #define PTR_SEG_TO_LIN(ptr) \ |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 66 | PTR_SEG_OFF_TO_LIN(SELECTOROF(ptr),OFFSETOF(ptr)) |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 67 | #define PTR_SEG_OFF_TO_SEGPTR(seg,off) \ |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 68 | ((SEGPTR)MAKELONG(off,seg)) |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 69 | #define PTR_SEG_OFF_TO_HUGEPTR(seg,off) \ |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 70 | PTR_SEG_OFF_TO_SEGPTR( (seg) + (HIWORD(off) << __AHSHIFT), LOWORD(off) ) |
Alexandre Julliard | bd34d4f | 1995-06-20 19:08:12 +0000 | [diff] [blame] | 71 | |
Andreas Mohr | a00b49f | 1998-12-07 10:48:09 +0000 | [diff] [blame] | 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 | |
Alexandre Julliard | bd34d4f | 1995-06-20 19:08:12 +0000 | [diff] [blame] | 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) */ |
Alexandre Julliard | e2991ea | 1995-07-29 13:09:43 +0000 | [diff] [blame] | 84 | #define LDT_FLAGS_ALLOCATED 0x80 /* Segment is allocated (no longer free) */ |
Alexandre Julliard | bd34d4f | 1995-06-20 19:08:12 +0000 | [diff] [blame] | 85 | |
| 86 | #define GET_SEL_FLAGS(sel) (ldt_flags_copy[SELECTOR_TO_ENTRY(sel)]) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 87 | |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 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 | |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 96 | #endif /* __WINE_LDT_H */ |