blob: d600042da7ed77d831f30375702aa411e98a6cae [file] [log] [blame]
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00001/*
2 * LDT copy
3 *
4 * Copyright 1995 Alexandre Julliard
5 */
6
Alexandre Julliardac9c9b01996-07-28 18:50:11 +00007#ifndef __WINE_LDT_H
8#define __WINE_LDT_H
9
Jim Aston2e1cafa1999-03-14 16:35:05 +000010#include "windef.h"
Alexandre Julliarde2abbb11995-03-19 17:39:39 +000011
12enum 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(). */
21typedef struct
22{
23 unsigned long base; /* base address */
Alexandre Julliard18f92e71996-07-17 20:02:21 +000024 unsigned long limit; /* segment limit (in pages or bytes) */
Alexandre Julliarde2abbb11995-03-19 17:39:39 +000025 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 Julliardbd34d4f1995-06-20 19:08:12 +000031extern void LDT_BytesToEntry( const unsigned long *buffer, ldt_entry *content);
32extern void LDT_EntryToBytes( unsigned long *buffer, const ldt_entry *content);
Alexandre Julliarde2abbb11995-03-19 17:39:39 +000033extern int LDT_GetEntry( int entry, ldt_entry *content );
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +000034extern int LDT_SetEntry( int entry, const ldt_entry *content );
Alexandre Julliardaf0bae51995-10-03 17:06:08 +000035extern void LDT_Print( int start, int length );
Alexandre Julliarde2abbb11995-03-19 17:39:39 +000036
37
38 /* This structure is used to build the local copy of the LDT. */
39typedef 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
47extern ldt_copy_entry ldt_copy[LDT_SIZE];
48
Alexandre Julliarde2991ea1995-07-29 13:09:43 +000049#define __AHSHIFT 3 /* don't change! */
Alexandre Julliarde2abbb11995-03-19 17:39:39 +000050#define __AHINCR (1 << __AHSHIFT)
51
Alexandre Julliard2787be81995-05-22 18:23:01 +000052#define SELECTOR_TO_ENTRY(sel) (((int)(sel) & 0xffff) >> __AHSHIFT)
Alexandre Julliarde2abbb11995-03-19 17:39:39 +000053#define ENTRY_TO_SELECTOR(i) ((i) ? (((int)(i) << __AHSHIFT) | 7) : 0)
Alexandre Julliarde2991ea1995-07-29 13:09:43 +000054#define IS_LDT_ENTRY_FREE(i) (!(ldt_flags_copy[(i)] & LDT_FLAGS_ALLOCATED))
Alexandre Julliarde2abbb11995-03-19 17:39:39 +000055#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 Julliarde2abbb11995-03-19 17:39:39 +000058
Alexandre Julliardac9c9b01996-07-28 18:50:11 +000059/* Convert a segmented ptr (16:16) to a linear (32) pointer */
Alexandre Julliard1285c2f1996-05-06 16:06:24 +000060
Alexandre Julliardac9c9b01996-07-28 18:50:11 +000061#define PTR_SEG_OFF_TO_LIN(seg,off) \
Alexandre Julliard46ea8b31998-05-03 19:01:20 +000062 ((void*)(GET_SEL_BASE(seg) + (unsigned int)(off)))
Alexandre Julliard770eb512000-09-24 20:47:50 +000063#define PTR_REAL_TO_LIN(seg,off) \
64 ((void*)(((unsigned int)(seg) << 4) + LOWORD(off)))
Alexandre Julliardac9c9b01996-07-28 18:50:11 +000065#define PTR_SEG_TO_LIN(ptr) \
Alexandre Julliard46ea8b31998-05-03 19:01:20 +000066 PTR_SEG_OFF_TO_LIN(SELECTOROF(ptr),OFFSETOF(ptr))
Alexandre Julliardac9c9b01996-07-28 18:50:11 +000067#define PTR_SEG_OFF_TO_SEGPTR(seg,off) \
Alexandre Julliard46ea8b31998-05-03 19:01:20 +000068 ((SEGPTR)MAKELONG(off,seg))
Alexandre Julliard03468f71998-02-15 19:40:49 +000069#define PTR_SEG_OFF_TO_HUGEPTR(seg,off) \
Alexandre Julliard46ea8b31998-05-03 19:01:20 +000070 PTR_SEG_OFF_TO_SEGPTR( (seg) + (HIWORD(off) << __AHSHIFT), LOWORD(off) )
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +000071
Andreas Mohra00b49f1998-12-07 10:48:09 +000072#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 Julliardbd34d4f1995-06-20 19:08:12 +000077extern 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 Julliarde2991ea1995-07-29 13:09:43 +000084#define LDT_FLAGS_ALLOCATED 0x80 /* Segment is allocated (no longer free) */
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +000085
86#define GET_SEL_FLAGS(sel) (ldt_flags_copy[SELECTOR_TO_ENTRY(sel)])
Alexandre Julliarde2abbb11995-03-19 17:39:39 +000087
Alexandre Julliard46ea8b31998-05-03 19:01:20 +000088#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 Julliardac9c9b01996-07-28 18:50:11 +000096#endif /* __WINE_LDT_H */