Лабораторная работа № 7

  • View
    347

  • Download
    3

Embed Size (px)

Text of Лабораторная работа № 7

1. 2. 3. v Windows Win32 Windows NT RAM -1-

4. v v

-2-

1. .

2. . : , , , . : , ( , ), ( ). : new delete C++ ( ). , . . : , . 10 , 12, . . :

-3-

, , , , .. , , . , . . - , . . . , : 1. . 2. , . 3. . . : a) . 1000 , 700 , 300 , 600 . b) . 3*20, 5*40, 7*80, 11*160, 13*320 . . . ,

-4-

3. WINDOWS WIN32 , , , , . , . ? ? ? , , . , Win32. Win32 4 . 32- 0x00000000 0xFFFFFFFF. , , 4 294 967 296 , . MS-DOS 16- Windows . , , , . , , , . , , , , , , . . Win32 , . - , ,

-5-

. , , . Windows NT , , . , . Windows 95 , , , , , , . - Windows 95, Windows NT, . , , , 16- Windows. , . , - 0x12345678, . 0x12345678, , , . , , , ., , , . , , , , , . , . , - , , .-6-

Win32 4- -. , Windows NT. Windows NT . 3-1 , Windows NT.

. 3-1. Win32- Windows NT-7-

1. 0x00000000 0x0000FFFF ( 64 ) Windows NT, , 4 Windows 95. . 2. 0x00010000 0x7FFEFFFF 2 147 352 576 (2 64 64 ) . 0x00400000 0x7FFFFFFF Windows 95. Win32- DLL: KERNEL32.DLL, USER32.DLL, GDI32.DLL ADVAPI32.DLL. DLL . . , , . 3. 0x7FFF0000 0x7FFFFFFF ( 64 ) 0x00000000 0x0000FFFF, . . . Microsoft , . : Win32- , (), , , . , :

BYTE bBuf[70000]; DWORD dwNumBytesWritten; BOOL WriteProcessMemory(hProcess, 0x7FFEEE90, bBuf, sizeof(bBuf), &dwNumBytesWritten); -8-

, WriteProcessMemory , , , , 0x80000000. , WriteProcessMemory, , , , . , Microsoft 0x7FFF0000 0x7FFFFFFF, . 4. 0x80000000 0xFFFFFFFF ( 2 ) Windows NT Executive, . Windows 95 Windows NT . , . , , Windows NT 2 . - MIPS R4000, . , Microsoft Win32 Windows NT -, , 2 Win32 Windows NT.

-9-

, , (). , , -

, Win32- VirtualAlloc. (reserving). (allocation granularity). , 86, MIPS, Alpha PowerPC 64 . , , , , , . , . , . , . , Win32 86, MIPS PowerPC 4 , DEC Alpha 8 . 10 , . , 86, MIPS PowerPC 12 , Alpha 16 . . , . (releasing) VirtuaFree.

- 10 -

, , (process environment block, ). , , . - . , , , (thread environment blocks, TEBs). . : . , , ,

- -, 64 . , , .

- 11 -

, . (committing physical storage). , VirtualAlloc. , . , , 64 . . 3-2 , . : . , . 3-2 , 86, MIPS PowerPC ( 4 ), DEC Alpha ( 8 ). , , , . (decommitting physical storage) VirtualFree.

- 12 -

. 3-2.

- 13 -

16- Windows (random access memory, RAM), . , 16 , , 16 . 16- Windows . , ( ) , , . . , 16- Windows , (swap files), . , . 16 Windows 386 . , . 16 , 20 , , 36 . , 36 . . , , 16- Windows . , , , .- 14 -

Windows 95 Windows NT Windows 3.1. , . Win32- , (paging files). , , - ( VirtualAlloc), , . , , . . , , . (. . 3-3). , , . , . , , , - . (page fault), , . ; , . , ; . , , , ,

- 15 -

. : , . ( , , , .) , , .

. 3-3. - 16 -

Windows NT , , .NT, , , . , Control Panel, System, Performance Virtual Memory Change. , , , , , , , , ( ) , . , . : . , , , -. -, : - , (image) - . , . (. . - DLL-), , (memory-mapped file). DLL - 17 -

. , ( Win32-) . - DLL- , Windows 95 Windows NT . ; . , , , . , , . - - DLL- , , , . , , . , . , (CD-ROM ), /SWAPRUN:CD /SWAPRUN:NET.

- 18 -

, VirtualAlloc, : , PAGE_NOACCESS . PAGE_READONLY . PAGE_READWRITE . . . . . PAGE_WRITECOPY , . . PAGE_EXECUTE_WRITECOPY , .

PAGE_EXECUTE

PAGE_EXECUTE_READ PAGE_EXECUTE_READWRITE

86, MIPS, PowerPC Alpha PAGE_EXECUTE , Win32 . . PAGE_EXECUTE , - 19 -

. , Windows NT . Windows 95 3 : PAGE_NOACCESS, PAGE_READONLY

PAGE_READWRITE.

, , , : PAGE_WRITECOPY

PAGE_EXECUTE_WRITECOPY.

. Win32 , . . , , ! , (copy-onwrite). - , : 1. . 2. . 3. , , , 2. 4. .

- 20 -

, . , , VirtualAlloc ER

PAGE_WRITECOPY VirtualAlloc

PAGE_EXECUTE_WRITECOPY. a GetLastError ,

ROR_INVALID_PARAMETER. - DLL-.

,

Windows 95 . , Windows 95 , . , : GE_NOCACHE PAGE_GUARD. ( PAGE_NOACCESS) OR. PAGE_NOCACHE . , ; , . PAGE_GUARD . Windows NT . Windows 95 PAGE_NOCACHE PAGE_GUARD.

- 21 -

Win32-, . , Win32 , , Win32. ( ) GetSystemlnfo:

VOID GetSystemInfo(LPSYSTEM_INFO IpSystemInfo);

GetSystemInfo SYSTEM_INFO, :

typedef struct _ SYSTEM_INFO{ union{ DWORD dwOemId; struct{ WORD wProcessorArchitecture; WORD wReserved; }; }; DWORD dwPageSize; LPVOID IpMinimumApplicationAddress; LPVOID IpMaximumApplicationAddress; DWORD dwActiveProcessorMask; DWORD dwNumberOfProcessors; DWORD dwProcessorType; DWORD dwAllocationGranularity; WORD wProcessorLevel; WORD wProcessorRevision; } SYSTEM_INFO, *LPSYSTEM_INFO; - 22 //

; . GetSystemInfo , . . :

- 23 -

. 86, MIPS PowerPC 4096, Alpha 8192 . . Windows 95 4 194 304, 0x00400000, 65 536, 64

dwPageSize

IpMinimumApplicationAddress

4

. Windows NT

0x00010000,

. , . Windows 95 2 147 483 647, 0x7FFFFFFF, 2 IpMaximumApplicationAddress , , . Windows NT 2 147 418 111, 0x7FFEFFFF, 64 2 . dwAllocationGranularity .

64 Win32.

- 24 -

Win32- GlobalMemoryStatus :

VOID GlobalMemoryStatus(LPMEMORYSTATUS lpmstMemStat);

GlobalMemoryStatus , - 16- Windows. Win32 , GlobalAlloc 16- Windows Win32. GlobalMemoryStatus MEMORY-STATUS. :

typedef struct _MEMORYSTATUS{ DWORD dwLength; DWORD dwMemoryLoad; DWORD dwTotalPhys; DWORD dwAvailPhys; DWORD dwTotalPageFile; DWORD dwAvailPageFile; DWORD dwTotalVirtual; DWORD dwAvailVirtual; } MEMORYSTATUS , *LPMEMORYSTATUS;

GlobalMemoryStatus dwLength , . . sizeof(MEMORYSTATUS). Win32 API, . GlobalMemoryStatus .

- 25 -

Win32 , : , . Win32- VirtualQuery:

DWORD VirtualQuery(UPVOID IpAddress, PMEMORY_BASIC_INFORMATION lpBuffer, DWORD dwLength);

VirtualQuery (IpAddress) , . lpBuffer MEMORY_BASIC_INFORMATION, . WINNT.H :

typedef struct _MEMORY_BASIC_INFORMATION { PVOID BaseAddress; PVOID AllocationBase; DWORD AllocationProtect; DWORD RegionSize; DWORD State; DWORD Protect; DWORD Type; } MEMORY_BASIC_INFORMATION, *PMEMORY_BASIC_INFORMATION;

dwLength

MEMORY_BASIC_INFORMATION. VirtualQuery , . , IpAddress, , , . :

- 26 -

BaseAddress

, IpAddress, , . , , IpAddress. , . ( ) , BaseAddress , , , , IpAddress. (MEM_FREE, MEM_RESERVE _1) , , , , , IpAddress. Protect MEM_FREE, Type

AllocationBase

AllocationProtect

RegionSize

State

AllocationBase,

AllocationProtect,

. MEM_RESERVE, Protect. (PAGE_*) , , , Protect , , IpAddress.

(MEM_IMAGE,MEM_MAPPED MEM_PRIVATE), , , , , , IpAddress. Windows 95 MEM_PRIVATE.

- 27 -

Win32 : 1. ; 2. ( ) ; 3. . . Win32-, , , (