Commit 204847e8 authored by Alexandre Julliard's avatar Alexandre Julliard

Use the wine_ldt_* functions directly in winedos instead of calling

SELECTOR_AllocBlock.
parent 89ba8760
...@@ -1159,4 +1159,3 @@ ...@@ -1159,4 +1159,3 @@
@ cdecl LOCAL_Size(long long) @ cdecl LOCAL_Size(long long)
@ cdecl LOCAL_Unlock(long long) @ cdecl LOCAL_Unlock(long long)
@ stdcall NE_DefResourceHandler(long long long) @ stdcall NE_DefResourceHandler(long long long)
@ cdecl SELECTOR_AllocBlock(ptr long long)
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
*/ */
#include "dosexe.h" #include "dosexe.h"
#include "selectors.h"
#include "wine/debug.h" #include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(dosmem); WINE_DEFAULT_DEBUG_CHANNEL(dosmem);
...@@ -83,12 +82,36 @@ LPVOID DOSVM_AllocUMB( DWORD size ) ...@@ -83,12 +82,36 @@ LPVOID DOSVM_AllocUMB( DWORD size )
} }
/**********************************************************************
* alloc_selector
*
* Allocate a selector corresponding to a real mode address.
* size must be < 64k.
*/
static WORD alloc_selector( void *base, DWORD size, unsigned char flags )
{
WORD sel = wine_ldt_alloc_entries( 1 );
if (sel)
{
LDT_ENTRY entry;
wine_ldt_set_base( &entry, base );
wine_ldt_set_limit( &entry, size - 1 );
wine_ldt_set_flags( &entry, flags );
wine_ldt_set_entry( sel, &entry );
}
return sel;
}
/*********************************************************************** /***********************************************************************
* DOSVM_AllocCodeUMB * DOSVM_AllocCodeUMB
* *
* Allocate upper memory block for storing code stubs. * Allocate upper memory block for storing code stubs.
* Initializes real mode segment and 16-bit protected mode selector * Initializes real mode segment and 16-bit protected mode selector
* for the allocated code block. * for the allocated code block.
*
* FIXME: should allocate a single PM selector for the whole UMB range.
*/ */
LPVOID DOSVM_AllocCodeUMB( DWORD size, WORD *segment, WORD *selector ) LPVOID DOSVM_AllocCodeUMB( DWORD size, WORD *segment, WORD *selector )
{ {
...@@ -98,7 +121,7 @@ LPVOID DOSVM_AllocCodeUMB( DWORD size, WORD *segment, WORD *selector ) ...@@ -98,7 +121,7 @@ LPVOID DOSVM_AllocCodeUMB( DWORD size, WORD *segment, WORD *selector )
*segment = (DWORD)ptr >> 4; *segment = (DWORD)ptr >> 4;
if (selector) if (selector)
*selector = SELECTOR_AllocBlock( ptr, size, WINE_LDT_FLAGS_CODE ); *selector = alloc_selector( ptr, size, WINE_LDT_FLAGS_CODE );
return ptr; return ptr;
} }
...@@ -119,7 +142,7 @@ LPVOID DOSVM_AllocDataUMB( DWORD size, WORD *segment, WORD *selector ) ...@@ -119,7 +142,7 @@ LPVOID DOSVM_AllocDataUMB( DWORD size, WORD *segment, WORD *selector )
*segment = (DWORD)ptr >> 4; *segment = (DWORD)ptr >> 4;
if (selector) if (selector)
*selector = SELECTOR_AllocBlock( ptr, size, WINE_LDT_FLAGS_DATA ); *selector = alloc_selector( ptr, size, WINE_LDT_FLAGS_DATA );
return ptr; return ptr;
} }
......
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
#include "wownt32.h" #include "wownt32.h"
#include "task.h" #include "task.h"
#include "dosexe.h" #include "dosexe.h"
#include "selectors.h"
#include "excpt.h" #include "excpt.h"
#include "wine/debug.h" #include "wine/debug.h"
...@@ -84,6 +83,27 @@ BOOL DOSVM_IsDos32(void) ...@@ -84,6 +83,27 @@ BOOL DOSVM_IsDos32(void)
/********************************************************************** /**********************************************************************
* alloc_pm_selector
*
* Allocate a 64k sized selector corresponding to a real mode segment.
*/
static WORD alloc_pm_selector( WORD seg, unsigned char flags )
{
WORD sel = wine_ldt_alloc_entries( 1 );
if (sel)
{
LDT_ENTRY entry;
wine_ldt_set_base( &entry, (void *)(seg << 4) );
wine_ldt_set_limit( &entry, 0xffff );
wine_ldt_set_flags( &entry, flags );
wine_ldt_set_entry( sel, &entry );
}
return sel;
}
/**********************************************************************
* dpmi_exception_handler * dpmi_exception_handler
* *
* Handle EXCEPTION_VM86_STI exceptions generated * Handle EXCEPTION_VM86_STI exceptions generated
...@@ -348,7 +368,7 @@ static void DPMI_CallRMCBProc( CONTEXT86 *context, RMCB *rmcb, WORD flag ) ...@@ -348,7 +368,7 @@ static void DPMI_CallRMCBProc( CONTEXT86 *context, RMCB *rmcb, WORD flag )
DWORD esp,edi; DWORD esp,edi;
INT_SetRealModeContext(MapSL(MAKESEGPTR( rmcb->regs_sel, rmcb->regs_ofs )), context); INT_SetRealModeContext(MapSL(MAKESEGPTR( rmcb->regs_sel, rmcb->regs_ofs )), context);
ss = SELECTOR_AllocBlock( (void *)(context->SegSs<<4), 0x10000, WINE_LDT_FLAGS_DATA ); ss = alloc_pm_selector( context->SegSs, WINE_LDT_FLAGS_DATA );
esp = context->Esp; esp = context->Esp;
FIXME("untested!\n"); FIXME("untested!\n");
...@@ -377,7 +397,7 @@ static void DPMI_CallRMCBProc( CONTEXT86 *context, RMCB *rmcb, WORD flag ) ...@@ -377,7 +397,7 @@ static void DPMI_CallRMCBProc( CONTEXT86 *context, RMCB *rmcb, WORD flag )
es = ctx.SegEs; es = ctx.SegEs;
edi = ctx.Edi; edi = ctx.Edi;
} }
FreeSelector16(ss); wine_ldt_free_entries( ss, 1 );
INT_GetRealModeContext( MapSL( MAKESEGPTR( es, edi )), context); INT_GetRealModeContext( MapSL( MAKESEGPTR( es, edi )), context);
#else #else
ERR("RMCBs only implemented for i386\n"); ERR("RMCBs only implemented for i386\n");
...@@ -567,19 +587,19 @@ static void StartPM( CONTEXT86 *context ) ...@@ -567,19 +587,19 @@ static void StartPM( CONTEXT86 *context )
RESET_CFLAG(context); RESET_CFLAG(context);
dpmi_flag = AX_reg(context); dpmi_flag = AX_reg(context);
/* our mode switch wrapper have placed the desired CS into DX */ /* our mode switch wrapper have placed the desired CS into DX */
cs = SELECTOR_AllocBlock( (void *)(DX_reg(context)<<4), 0x10000, WINE_LDT_FLAGS_CODE ); cs = alloc_pm_selector( context->Edx, WINE_LDT_FLAGS_CODE );
/* due to a flaw in some CPUs (at least mine), it is best to mark stack segments as 32-bit if they /* due to a flaw in some CPUs (at least mine), it is best to mark stack segments as 32-bit if they
can be used in 32-bit code. Otherwise, these CPUs may not set the high word of esp during a can be used in 32-bit code. Otherwise, these CPUs may not set the high word of esp during a
ring transition (from kernel code) to the 16-bit stack, and this causes trouble if executing ring transition (from kernel code) to the 16-bit stack, and this causes trouble if executing
32-bit code using this stack. */ 32-bit code using this stack. */
if (dpmi_flag & 1) selflags |= WINE_LDT_FLAGS_32BIT; if (dpmi_flag & 1) selflags |= WINE_LDT_FLAGS_32BIT;
ss = SELECTOR_AllocBlock( (void *)(context->SegSs<<4), 0x10000, selflags ); ss = alloc_pm_selector( context->SegSs, selflags );
/* do the same for the data segments, just in case */ /* do the same for the data segments, just in case */
if (context->SegDs == context->SegSs) ds = ss; if (context->SegDs == context->SegSs) ds = ss;
else ds = SELECTOR_AllocBlock( (void *)(context->SegDs<<4), 0x10000, selflags ); else ds = alloc_pm_selector( context->SegDs, selflags );
es = SELECTOR_AllocBlock( psp, 0x100, selflags ); es = alloc_pm_selector( DOSVM_psp, selflags );
/* convert environment pointer, as the spec says, but we're a bit lazy about the size here... */ /* convert environment pointer, as the spec says, but we're a bit lazy about the size here... */
psp->environment = SELECTOR_AllocBlock( (void *)(env_seg<<4), 0x10000, WINE_LDT_FLAGS_DATA ); psp->environment = alloc_pm_selector( env_seg, WINE_LDT_FLAGS_DATA );
pm_ctx = *context; pm_ctx = *context;
pm_ctx.SegCs = DOSVM_dpmi_segments->dpmi_sel; pm_ctx.SegCs = DOSVM_dpmi_segments->dpmi_sel;
...@@ -614,12 +634,12 @@ static void StartPM( CONTEXT86 *context ) ...@@ -614,12 +634,12 @@ static void StartPM( CONTEXT86 *context )
ExitThread( DPMI_retval ); ExitThread( DPMI_retval );
#if 0 #if 0
FreeSelector16(psp->environment); wine_ldt_free_entries( psp->environment, 1 );
psp->environment = env_seg; psp->environment = env_seg;
FreeSelector16(es); wine_ldt_free_entries(es,1);
if (ds != ss) FreeSelector16(ds); if (ds != ss) wine_ldt_free_entries(ds,1);
FreeSelector16(ss); wine_ldt_free_entries(ss,1);
FreeSelector16(cs); wine_ldt_free_entries(cs,1);
#endif #endif
} }
......
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