annotate loader/wine/ldt.h @ 5944:1faf2566907b

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