Commit b5448369 authored by Alexandre Julliard's avatar Alexandre Julliard

krnl386: Avoid using the LDT definitions from libwine.

parent a02d2773
......@@ -319,7 +319,7 @@ static void DOSMEM_InitSegments(void)
/*
* PM / offset N*5: Interrupt N in 16-bit protected mode.
*/
int16_sel = GLOBAL_Alloc( GMEM_FIXED, 5 * 256, 0, WINE_LDT_FLAGS_CODE );
int16_sel = GLOBAL_Alloc( GMEM_FIXED, 5 * 256, 0, LDT_FLAGS_CODE );
ptr = GlobalLock16( int16_sel );
for(i=0; i<256; i++) {
/*
......@@ -340,7 +340,7 @@ static void DOSMEM_InitSegments(void)
* PM / offset 3: Stub which swaps back to 32-bit application code/stack.
* PM / offset 5: Stub which enables interrupts
*/
relay_code_sel = GLOBAL_Alloc( GMEM_FIXED, sizeof(relay), 0, WINE_LDT_FLAGS_CODE );
relay_code_sel = GLOBAL_Alloc( GMEM_FIXED, sizeof(relay), 0, LDT_FLAGS_CODE );
ptr = GlobalLock16( relay_code_sel );
memcpy( ptr, relay, sizeof(relay) );
GlobalUnlock16( relay_code_sel );
......@@ -472,11 +472,11 @@ BOOL DOSMEM_Init(void)
vectored_handler = AddVectoredExceptionHandler(FALSE, dosmem_handler);
DOSMEM_0000H = GLOBAL_CreateBlock( GMEM_FIXED, DOSMEM_sysmem,
DOSMEM_64KB, 0, WINE_LDT_FLAGS_DATA );
DOSMEM_64KB, 0, LDT_FLAGS_DATA );
DOSMEM_BiosDataSeg = GLOBAL_CreateBlock( GMEM_FIXED, DOSMEM_sysmem + 0x400,
0x100, 0, WINE_LDT_FLAGS_DATA );
0x100, 0, LDT_FLAGS_DATA );
DOSMEM_BiosSysSeg = GLOBAL_CreateBlock( GMEM_FIXED, DOSMEM_dosmem + 0xf0000,
DOSMEM_64KB, 0, WINE_LDT_FLAGS_DATA );
DOSMEM_64KB, 0, LDT_FLAGS_DATA );
return TRUE;
}
......
......@@ -144,7 +144,7 @@ HGLOBAL16 GLOBAL_CreateBlock( WORD flags, void *ptr, DWORD size,
pArena->flags = flags & GA_MOVEABLE;
if (flags & GMEM_DISCARDABLE) pArena->flags |= GA_DISCARDABLE;
if (flags & GMEM_DDESHARE) pArena->flags |= GA_IPCSHARE;
if (!(selflags & (WINE_LDT_FLAGS_CODE^WINE_LDT_FLAGS_DATA))) pArena->flags |= GA_DGROUP;
if (!(selflags & (LDT_FLAGS_CODE ^ LDT_FLAGS_DATA))) pArena->flags |= GA_DGROUP;
pArena->selCount = selcount;
if (selcount > 1) /* clear the next arena blocks */
memset( pArena + 1, 0, (selcount - 1) * sizeof(GLOBALARENA) );
......@@ -260,7 +260,7 @@ HGLOBAL16 WINAPI GlobalAlloc16(
STACK16FRAME *frame = CURRENT_STACK16;
owner = GetExePtr( frame->cs );
}
return GLOBAL_Alloc( flags, size, owner, WINE_LDT_FLAGS_DATA );
return GLOBAL_Alloc( flags, size, owner, LDT_FLAGS_DATA );
}
......@@ -785,7 +785,7 @@ DWORD WINAPI GlobalDOSAlloc16(
WORD wSelector;
GLOBALARENA *pArena;
wSelector = GLOBAL_CreateBlock(GMEM_FIXED, lpBlock, size, hModule, WINE_LDT_FLAGS_DATA );
wSelector = GLOBAL_CreateBlock(GMEM_FIXED, lpBlock, size, hModule, LDT_FLAGS_DATA );
pArena = GET_ARENA_PTR(wSelector);
pArena->flags |= GA_DOSMEM;
return MAKELONG(wSelector,uParagraph);
......
......@@ -174,7 +174,6 @@ static BYTE *INSTR_GetOperandAddr( CONTEXT *context, BYTE *instr,
int long_addr, int segprefix, int *len )
{
int mod, rm, base = 0, index = 0, ss = 0, seg = 0, off;
LDT_ENTRY entry;
#define GET_VAL(val,type) \
{ *val = *(type *)instr; instr += sizeof(type); *len += sizeof(type); }
......@@ -317,10 +316,9 @@ static BYTE *INSTR_GetOperandAddr( CONTEXT *context, BYTE *instr,
/* Make sure the segment and offset are valid */
if (ldt_is_system(seg)) return (BYTE *)(base + (index << ss));
if ((seg & 7) != 7) return NULL;
if (!ldt_get_entry( seg, &entry )) return NULL;
if (wine_ldt_is_empty( &entry )) return NULL;
if (wine_ldt_get_limit(&entry) < (base + (index << ss))) return NULL;
return (BYTE *)wine_ldt_get_base(&entry) + base + (index << ss);
if (!ldt_is_valid( seg )) return NULL;
if (ldt_get_limit( seg ) < (base + (index << ss))) return NULL;
return (BYTE *)ldt_get_base( seg ) + base + (index << ss);
#undef GET_VAL
}
......
......@@ -240,20 +240,16 @@ void WINAPI DOSVM_Int31Handler( CONTEXT *context )
case 0x0006: /* Get selector base address */
TRACE( "get selector base address (0x%04x)\n", BX_reg(context) );
if (!ldt_is_valid( BX_reg(context) ))
{
LDT_ENTRY entry;
if (!ldt_get_entry( BX_reg(context), &entry ) || wine_ldt_is_empty(&entry))
{
context->Eax = 0x8022; /* invalid selector */
SET_CFLAG(context);
}
else
{
void *base = wine_ldt_get_base(&entry);
SET_CX( context, HIWORD(base) );
SET_DX( context, LOWORD(base) );
}
context->Eax = 0x8022; /* invalid selector */
SET_CFLAG(context);
}
else
{
void *base = ldt_get_base( BX_reg(context) );
SET_CX( context, HIWORD(base) );
SET_DX( context, LOWORD(base) );
}
break;
......
......@@ -129,7 +129,7 @@ BOOL WINAPI KERNEL_DllEntryPoint( DWORD reasion, HINSTANCE16 inst, WORD ds,
#define SET_ENTRY_POINT( num, addr ) \
NE_SetEntryPoint( inst, (num), GLOBAL_CreateBlock( GMEM_FIXED, \
DOSMEM_MapDosToLinear(addr), 0x10000, inst, \
WINE_LDT_FLAGS_DATA ))
LDT_FLAGS_DATA ))
SET_ENTRY_POINT( 174, 0xa0000 ); /* KERNEL.174: __A000H */
SET_ENTRY_POINT( 181, 0xb0000 ); /* KERNEL.181: __B000H */
......
......@@ -232,8 +232,26 @@ extern void NE_DllProcessAttach( HMODULE16 hModule ) DECLSPEC_HIDDEN;
extern void NE_CallUserSignalProc( HMODULE16 hModule, UINT16 code ) DECLSPEC_HIDDEN;
/* selector.c */
#define LDT_SIZE 8192
struct ldt_copy
{
void *base[LDT_SIZE];
unsigned int limit[LDT_SIZE];
unsigned char flags[LDT_SIZE];
};
extern const struct ldt_copy *ldt_copy DECLSPEC_HIDDEN;
#define LDT_FLAGS_DATA 0x13 /* Data segment */
#define LDT_FLAGS_CODE 0x1b /* Code segment */
#define LDT_FLAGS_32BIT 0x40 /* Segment is 32-bit (code or stack) */
static inline void *ldt_get_base( WORD sel ) { return ldt_copy->base[sel >> 3]; }
static inline unsigned int ldt_get_limit( WORD sel ) { return ldt_copy->limit[sel >> 3]; }
static inline unsigned char ldt_get_flags( WORD sel ) { return ldt_copy->flags[sel >> 3]; }
extern void init_selectors(void) DECLSPEC_HIDDEN;
extern BOOL ldt_is_system( WORD sel ) DECLSPEC_HIDDEN;
extern BOOL ldt_is_valid( WORD sel ) DECLSPEC_HIDDEN;
extern void *ldt_get_ptr( WORD sel, DWORD offset ) DECLSPEC_HIDDEN;
extern BOOL ldt_get_entry( WORD sel, LDT_ENTRY *entry ) DECLSPEC_HIDDEN;
extern void ldt_set_entry( WORD sel, LDT_ENTRY entry ) DECLSPEC_HIDDEN;
......@@ -241,7 +259,7 @@ extern WORD SELECTOR_AllocBlock( const void *base, DWORD size, unsigned char fla
extern WORD SELECTOR_ReallocBlock( WORD sel, const void *base, DWORD size ) DECLSPEC_HIDDEN;
extern void SELECTOR_FreeBlock( WORD sel ) DECLSPEC_HIDDEN;
#define IS_SELECTOR_32BIT(sel) \
(ldt_is_system(sel) || (wine_ldt_copy.flags[LOWORD(sel) >> 3] & WINE_LDT_FLAGS_32BIT))
(ldt_is_system(sel) || (ldt_copy->flags[LOWORD(sel) >> 3] & LDT_FLAGS_32BIT))
/* relay16.c */
extern int relay_call_from_16( void *entry_point, unsigned char *args16, CONTEXT *context ) DECLSPEC_HIDDEN;
......
......@@ -1785,8 +1785,8 @@ HANDLE WINAPI Local32Init16( WORD segment, DWORD tableSize,
nrBlocks = (totSize + 0x7fff) >> 15;
selectorTable = HeapAlloc( header->heap, 0, nrBlocks * 2 );
selectorEven = SELECTOR_AllocBlock( base, totSize, WINE_LDT_FLAGS_DATA );
selectorOdd = SELECTOR_AllocBlock( base + 0x8000, totSize - 0x8000, WINE_LDT_FLAGS_DATA );
selectorEven = SELECTOR_AllocBlock( base, totSize, LDT_FLAGS_DATA );
selectorOdd = SELECTOR_AllocBlock( base + 0x8000, totSize - 0x8000, LDT_FLAGS_DATA );
if ( !selectorTable || !selectorEven || !selectorOdd )
{
HeapFree( header->heap, 0, selectorTable );
......
......@@ -921,7 +921,7 @@ static HMODULE16 NE_DoLoadBuiltinModule( const IMAGE_DOS_HEADER *mz_header, cons
}
patch_code_segment( pModule );
*(void **)mz_header->e_res2 = &wine_ldt_copy;
*(const void **)mz_header->e_res2 = ldt_copy->base;
return hInstance;
}
......
......@@ -1018,8 +1018,8 @@ BOOL NE_CreateSegment( NE_MODULE *pModule, int segnum )
if ( segnum == SELECTOROF(pModule->ne_sssp) ) minsize += pModule->ne_stack;
if ( segnum == pModule->ne_autodata ) minsize += pModule->ne_heap;
selflags = (pSeg->flags & NE_SEGFLAGS_DATA) ? WINE_LDT_FLAGS_DATA : WINE_LDT_FLAGS_CODE;
if (pSeg->flags & NE_SEGFLAGS_32BIT) selflags |= WINE_LDT_FLAGS_32BIT;
selflags = (pSeg->flags & NE_SEGFLAGS_DATA) ? LDT_FLAGS_DATA : LDT_FLAGS_CODE;
if (pSeg->flags & NE_SEGFLAGS_32BIT) selflags |= LDT_FLAGS_32BIT;
pSeg->hSeg = GLOBAL_Alloc( NE_Ne2MemFlags(pSeg->flags), minsize, pModule->self, selflags );
if (!pSeg->hSeg) return FALSE;
......
......@@ -107,7 +107,7 @@ SNOOP16_RegisterDLL(HMODULE16 hModule,LPCSTR name) {
TRACE("hmod=%x, name=%s\n", hModule, name);
if (!snr) {
xsnr=GLOBAL_Alloc(GMEM_ZEROINIT,2*sizeof(*snr),0,WINE_LDT_FLAGS_CODE|WINE_LDT_FLAGS_32BIT);
xsnr=GLOBAL_Alloc(GMEM_ZEROINIT,2*sizeof(*snr),0,LDT_FLAGS_CODE | LDT_FLAGS_32BIT);
snr = GlobalLock16(xsnr);
snr[0].pushbp = 0x5566;
snr[0].pusheax = 0x50;
......@@ -152,7 +152,7 @@ SNOOP16_RegisterDLL(HMODULE16 hModule,LPCSTR name) {
strcpy( (*dll)->name, name );
if ((q=strrchr((*dll)->name,'.')))
*q='\0';
(*dll)->funhandle = GlobalHandleToSel16(GLOBAL_Alloc(GMEM_ZEROINIT,65535,0,WINE_LDT_FLAGS_CODE));
(*dll)->funhandle = GlobalHandleToSel16(GLOBAL_Alloc(GMEM_ZEROINIT,65535,0,LDT_FLAGS_CODE));
(*dll)->funs = GlobalLock16((*dll)->funhandle);
if (!(*dll)->funs) {
HeapFree(GetProcessHeap(),0,*dll);
......@@ -270,7 +270,7 @@ static void WINAPI SNOOP16_Entry(FARPROC proc, LPBYTE args, CONTEXT *context) {
rets = &((*rets)->next);
}
if (!*rets) {
HANDLE16 hand = GlobalHandleToSel16(GLOBAL_Alloc(GMEM_ZEROINIT,65535,0,WINE_LDT_FLAGS_CODE));
HANDLE16 hand = GlobalHandleToSel16(GLOBAL_Alloc(GMEM_ZEROINIT,65535,0,LDT_FLAGS_CODE));
*rets = GlobalLock16(hand);
(*rets)->rethandle = hand;
i = 0; /* entry 0 is free */
......
......@@ -201,7 +201,7 @@ static SEGPTR TASK_AllocThunk(void)
if (!sel) /* Allocate a new segment */
{
sel = GLOBAL_Alloc( GMEM_FIXED, FIELD_OFFSET( THUNKS, thunks[MIN_THUNKS] ),
pTask->hPDB, WINE_LDT_FLAGS_CODE );
pTask->hPDB, LDT_FLAGS_CODE );
if (!sel) return 0;
TASK_CreateThunks( sel, 0, MIN_THUNKS );
pThunk->next = sel;
......@@ -300,7 +300,7 @@ static TDB *TASK_Create( NE_MODULE *pModule, UINT16 cmdShow, LPCSTR cmdline, BYT
/* Allocate a selector for the PDB */
pTask->hPDB = GLOBAL_CreateBlock( GMEM_FIXED, &pTask->pdb, sizeof(PDB16),
hModule, WINE_LDT_FLAGS_DATA );
hModule, LDT_FLAGS_DATA );
/* Fill the PDB */
......@@ -341,7 +341,7 @@ static TDB *TASK_Create( NE_MODULE *pModule, UINT16 cmdShow, LPCSTR cmdline, BYT
/* Allocate a code segment alias for the TDB */
pTask->hCSAlias = GLOBAL_CreateBlock( GMEM_FIXED, pTask, sizeof(TDB),
pTask->hPDB, WINE_LDT_FLAGS_CODE );
pTask->hPDB, LDT_FLAGS_CODE );
/* Default DTA overwrites command line */
......
......@@ -1075,7 +1075,7 @@ AllocSLCallback(
*(DWORD*)(thunk+18) = GetCurrentProcessId();
sel = SELECTOR_AllocBlock( thunk, 32, WINE_LDT_FLAGS_CODE );
sel = SELECTOR_AllocBlock( thunk, 32, LDT_FLAGS_CODE );
return (sel<<16)|0;
}
......@@ -1617,7 +1617,7 @@ static BOOL THUNK_Init(void)
ThunkletHeap = HeapCreate( HEAP_CREATE_ENABLE_EXECUTE, 0x10000, 0x10000 );
if (!ThunkletHeap) return FALSE;
ThunkletCodeSel = SELECTOR_AllocBlock( ThunkletHeap, 0x10000, WINE_LDT_FLAGS_CODE );
ThunkletCodeSel = SELECTOR_AllocBlock( ThunkletHeap, 0x10000, LDT_FLAGS_CODE );
thunk = HeapAlloc( ThunkletHeap, 0, 5 );
if (!thunk) return FALSE;
......@@ -2048,8 +2048,7 @@ SEGPTR WINAPI Get16DLLAddress(HMODULE16 handle, LPSTR func_name)
if (!code_sel32)
{
if (!ThunkletHeap) THUNK_Init();
code_sel32 = SELECTOR_AllocBlock( ThunkletHeap, 0x10000,
WINE_LDT_FLAGS_CODE | WINE_LDT_FLAGS_32BIT );
code_sel32 = SELECTOR_AllocBlock( ThunkletHeap, 0x10000, LDT_FLAGS_CODE | LDT_FLAGS_32BIT );
if (!code_sel32) return 0;
}
if (!(thunk = HeapAlloc( ThunkletHeap, 0, 32 ))) return 0;
......
......@@ -59,7 +59,7 @@ BOOL WOWTHUNK_Init(void)
/* allocate the code selector for CallTo16 routines */
WORD codesel = SELECTOR_AllocBlock( __wine_call16_start,
(BYTE *)(&CallTo16_TebSelector + 1) - __wine_call16_start,
WINE_LDT_FLAGS_CODE | WINE_LDT_FLAGS_32BIT );
LDT_FLAGS_CODE | LDT_FLAGS_32BIT );
if (!codesel) return FALSE;
/* Patch the return addresses for CallTo16 routines */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment