Added add_queue/remove_queue to server object operations.
[wine/multimedia.git] / include / ldt.h
blob1e9d7db0154d3d732953188c20778a02bcd95daf
1 /*
2 * LDT copy
4 * Copyright 1995 Alexandre Julliard
5 */
7 #ifndef __WINE_LDT_H
8 #define __WINE_LDT_H
10 #include "wintypes.h"
12 enum seg_type
14 SEGMENT_DATA = 0,
15 SEGMENT_STACK = 1,
16 SEGMENT_CODE = 2
19 /* This structure represents a real LDT entry. */
20 /* It is used by get_ldt_entry() and set_ldt_entry(). */
21 typedef struct
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 */
29 } ldt_entry;
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. */
39 typedef struct
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;
45 #define LDT_SIZE 8192
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 #define W32S_APPLICATION() (PROCESS_Current()->flags & PDB32_WIN32S_PROC)
71 #define W32S_OFFSET 0x10000
72 #define W32S_APP2WINE(addr, offset) ((addr)? (DWORD)(addr) + (DWORD)(offset) : 0)
73 #define W32S_WINE2APP(addr, offset) ((addr)? (DWORD)(addr) - (DWORD)(offset) : 0)
75 extern unsigned char ldt_flags_copy[LDT_SIZE];
77 #define LDT_FLAGS_TYPE 0x03 /* Mask for segment type */
78 #define LDT_FLAGS_READONLY 0x04 /* Segment is read-only (data) */
79 #define LDT_FLAGS_EXECONLY 0x04 /* Segment is execute-only (code) */
80 #define LDT_FLAGS_32BIT 0x08 /* Segment is 32-bit (code or stack) */
81 #define LDT_FLAGS_BIG 0x10 /* Segment is big (limit is in pages) */
82 #define LDT_FLAGS_ALLOCATED 0x80 /* Segment is allocated (no longer free) */
84 #define GET_SEL_FLAGS(sel) (ldt_flags_copy[SELECTOR_TO_ENTRY(sel)])
86 #define FIRST_LDT_ENTRY_TO_ALLOC 17
88 /* Determine if sel is a system selector (i.e. not managed by Wine) */
89 #define IS_SELECTOR_SYSTEM(sel) \
90 (!((sel) & 4) || (SELECTOR_TO_ENTRY(sel) < FIRST_LDT_ENTRY_TO_ALLOC))
91 #define IS_SELECTOR_32BIT(sel) \
92 (IS_SELECTOR_SYSTEM(sel) || (GET_SEL_FLAGS(sel) & LDT_FLAGS_32BIT))
94 #endif /* __WINE_LDT_H */