home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Troubleshooting Netware Systems
/
CSTRIAL0196.BIN
/
attach
/
msj
/
v10n04
/
memman.exe
/
PHYS16.C
< prev
next >
Wrap
C/C++ Source or Header
|
1995-04-01
|
4KB
|
135 lines
#include <windows.h>
#include "descript.h"
BOOL FAR PASCAL __export DllEntryPoint (DWORD dwReason,
WORD hInst,
WORD wDS,
WORD wHeapSize,
DWORD dwReserved1,
WORD wReserved2);
BOOL FAR PASCAL phystk_ThunkConnect16( LPSTR pszDll16,
LPSTR pszDll32,
WORD hInst,
DWORD dwReason);
int FAR PASCAL LibMain (HANDLE hInstance,
WORD wDataSeg,
WORD wHeapSize,
LPSTR lpszCmdLine)
{
if (wHeapSize != 0) // If DLL data seg is MOVEABLE
UnlockData (0);
return (1);
}
BOOL FAR PASCAL __export DllEntryPoint (DWORD dwReason,
WORD hInst,
WORD wDS,
WORD wHeapSize,
DWORD dwReserved1,
WORD wReserved2)
{
OutputDebugString("In 16bit DllEntryPoint: Calling phystk_ThunkConnect16\r\n");
if (!phystk_ThunkConnect16( "PHYS16.DLL",
"PHYS32.DLL",
hInst,
dwReason))
{
OutputDebugString("In 16bit DllEntryPoint: phystk_ThunkConnect16 ret FALSE\r\n");
return FALSE;
}
OutputDebugString("In 16bit DllEntryPoint: phystk_ThunkConnect16 ret TRUE\r\n");
return TRUE;
}
LPVOID AllocatePhysicalMemoryPtr( DWORD physAddress, DWORD len )
{
DWORD linearMappingAddress;
WORD mappingSelector;
WORD ourDS;
__asm mov [ourDS], ds
mappingSelector = AllocSelector( ourDS );
if ( !mappingSelector )
return 0;
__asm mov ax, 0800h
__asm mov bx, word ptr [physAddress+2]
__asm mov cx, word ptr [physAddress]
__asm mov si, word ptr [len+2]
__asm mov di, word ptr [len]
__asm int 31h
__asm jc error
__asm mov word ptr [linearMappingAddress+2], bx
__asm mov word ptr [linearMappingAddress], cx
SetSelectorBase( mappingSelector, linearMappingAddress );
SetSelectorLimit( mappingSelector, len );
return MAKELP( mappingSelector, 0 );
error:
FreeSelector( mappingSelector );
return 0;
}
void FreePhysicalMemoryPtr( LPVOID physPtr )
{
DWORD linearMappingAddress = GetSelectorBase( SELECTOROF(physPtr) );
__asm mov ax, 0801h
__asm mov bx, word ptr [linearMappingAddress+2]
__asm mov cx, word ptr [linearMappingAddress]
__asm int 31h
FreeSelector( SELECTOROF(physPtr) );
}
DWORD GetCR3(void); // A helper function prototype
DWORD WINAPI __export GetPhysicalAddrFromLinear( DWORD linear )
{
DWORD pageDirBasePhys;
LPDWORD lpPageDirBase;
LPDWORD lpPageDir;
LPDWORD lpPageTableBase;
LPDWORD lpPageTable;
DWORD retValue;
pageDirBasePhys = GetCR3();
lpPageDirBase = AllocatePhysicalMemoryPtr( pageDirBasePhys, 0x1000 );
lpPageDir = &lpPageDirBase[ linear >> 22 ];
lpPageTableBase
= AllocatePhysicalMemoryPtr( *lpPageDir & 0xFFFFF000, 0x1000 );
FreePhysicalMemoryPtr( lpPageDirBase );
lpPageTable = &lpPageTableBase[ (linear >> 12) & 0x000003FF ];
retValue = (*lpPageTable & 0xFFFFF000) + (linear & 0x00000FFF);
FreePhysicalMemoryPtr( lpPageTableBase );
return retValue;
}
DWORD WINAPI __export GetPageAttributes( DWORD linear )
{
DWORD pageDirBasePhys;
LPDWORD lpPageDirBase;
LPDWORD lpPageDir;
LPDWORD lpPageTableBase;
LPDWORD lpPageTable;
DWORD retValue;
pageDirBasePhys = GetCR3();
lpPageDirBase = AllocatePhysicalMemoryPtr( pageDirBasePhys, 0x1000 );
lpPageDir = &lpPageDirBase[ linear >> 22 ];
lpPageTableBase
= AllocatePhysicalMemoryPtr( *lpPageDir & 0xFFFFF000, 0x1000 );
FreePhysicalMemoryPtr( lpPageDirBase );
lpPageTable = &lpPageTableBase[ (linear >> 12) & 0x000003FF ];
retValue = *lpPageTable & 0x00000FFF;
FreePhysicalMemoryPtr( lpPageTableBase );
return retValue;
}