ReactOS 0.4.15-dev-7918-g2a2556c
virtmem.c File Reference
#include "precomp.h"
#include <debug.h>
Include dependency graph for virtmem.c:

Go to the source code of this file.

Classes

struct  _PAGEFILE
 
struct  _VIRTMEM
 

Macros

#define NDEBUG
 
#define MEGABYTE   (1024 * 1024)
 
#define MINIMUM_PAGEFILE_SIZE   2
 
#define MAXIMUM_PAGEFILE_SIZE32   (4UL * 1024 - 1)
 
#define MAXIMUM_PAGEFILE_SIZE64   (16UL * 1024 * 1024 - 1)
 
#define MAXIMUM_PAGEFILE_SIZE   MAXIMUM_PAGEFILE_SIZE32
 

Typedefs

typedef struct _PAGEFILE PAGEFILE
 
typedef struct _PAGEFILEPPAGEFILE
 
typedef struct _VIRTMEM VIRTMEM
 
typedef struct _VIRTMEMPVIRTMEM
 

Functions

static __inline UINT GetMaxPageFileSize (_In_ PPAGEFILE PageFile)
 
static BOOL ReadPageFileSettings (PVIRTMEM pVirtMem)
 
static VOID GetPageFileSizes (LPTSTR lpPageFiles, LPINT lpInitialSize, LPINT lpMaximumSize)
 
static VOID ParseMemSettings (PVIRTMEM pVirtMem)
 
static VOID WritePageFileSettings (PVIRTMEM pVirtMem)
 
static VOID SetListBoxColumns (HWND hwndListBox)
 
static VOID OnNoPagingFile (PVIRTMEM pVirtMem)
 
static VOID OnSysManSize (PVIRTMEM pVirtMem)
 
static VOID OnCustom (PVIRTMEM pVirtMem)
 
static BOOL OnSelChange (PVIRTMEM pVirtMem)
 
static VOID InitPagefileList (PVIRTMEM pVirtMem)
 
static VOID UpdatePagefileEntry (PVIRTMEM pVirtMem, INT ListIndex, INT DriveIndex)
 
static VOID OnSet (PVIRTMEM pVirtMem)
 
static VOID OnVirtMemDialogOk (PVIRTMEM pVirtMem)
 
static VOID OnInitVirtMemDialog (HWND hwnd, PVIRTMEM pVirtMem)
 
static VOID OnDestroy (PVIRTMEM pVirtMem)
 
INT_PTR CALLBACK VirtMemDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 

Variables

static LPCTSTR lpKey = _T("SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Memory Management")
 

Macro Definition Documentation

◆ MAXIMUM_PAGEFILE_SIZE

#define MAXIMUM_PAGEFILE_SIZE   MAXIMUM_PAGEFILE_SIZE32

Definition at line 59 of file virtmem.c.

◆ MAXIMUM_PAGEFILE_SIZE32

#define MAXIMUM_PAGEFILE_SIZE32   (4UL * 1024 - 1)

Definition at line 31 of file virtmem.c.

◆ MAXIMUM_PAGEFILE_SIZE64

#define MAXIMUM_PAGEFILE_SIZE64   (16UL * 1024 * 1024 - 1)

Definition at line 32 of file virtmem.c.

◆ MEGABYTE

#define MEGABYTE   (1024 * 1024)

Definition at line 22 of file virtmem.c.

◆ MINIMUM_PAGEFILE_SIZE

#define MINIMUM_PAGEFILE_SIZE   2

Definition at line 28 of file virtmem.c.

◆ NDEBUG

#define NDEBUG

Definition at line 18 of file virtmem.c.

Typedef Documentation

◆ PAGEFILE

◆ PPAGEFILE

◆ PVIRTMEM

◆ VIRTMEM

Function Documentation

◆ GetMaxPageFileSize()

static __inline UINT GetMaxPageFileSize ( _In_ PPAGEFILE  PageFile)
static

Definition at line 89 of file virtmem.c.

91{
92#ifdef _M_IX86
93 /* For x86 PAE-enabled systems, where the maximum pagefile size is
94 * greater than 4 GB, verify also that the drive's filesystem on which
95 * the pagefile is stored can support it. */
96 if (SharedUserData->ProcessorFeatures[PF_PAE_ENABLED] && PageFile->bIsNotFAT)
97 return min(PageFile->FreeSize, MAXIMUM_PAGEFILE_SIZE_PAE);
98#endif
99 return min(PageFile->FreeSize, MAXIMUM_PAGEFILE_SIZE);
100}
#define MAXIMUM_PAGEFILE_SIZE
Definition: virtmem.c:59
#define min(a, b)
Definition: monoChain.cc:55
#define SharedUserData
#define PF_PAE_ENABLED
Definition: ketypes.h:133

Referenced by OnSelChange(), and OnSet().

◆ GetPageFileSizes()

static VOID GetPageFileSizes ( LPTSTR  lpPageFiles,
LPINT  lpInitialSize,
LPINT  lpMaximumSize 
)
static

Definition at line 158 of file virtmem.c.

161{
162 UINT i = 0;
163
164 *lpInitialSize = -1;
165 *lpMaximumSize = -1;
166
167 while (*lpPageFiles != _T('\0'))
168 {
169 if (*lpPageFiles == _T(' '))
170 {
171 lpPageFiles++;
172
173 switch (i)
174 {
175 case 0:
176 *lpInitialSize = (INT)_ttoi(lpPageFiles);
177 i = 1;
178 break;
179
180 case 1:
181 *lpMaximumSize = (INT)_ttoi(lpPageFiles);
182 return;
183 }
184 }
185
186 lpPageFiles++;
187 }
188}
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int UINT
Definition: ndis.h:50
#define INT
Definition: polytest.cpp:20
#define _T(x)
Definition: vfdio.h:22
#define _ttoi
Definition: xmlstorage.h:195

Referenced by ParseMemSettings().

◆ InitPagefileList()

static VOID InitPagefileList ( PVIRTMEM  pVirtMem)
static

Definition at line 392 of file virtmem.c.

393{
394 INT Index;
395 UINT i;
396 PPAGEFILE PageFile;
397 TCHAR szSize[64];
398 TCHAR szDisplayString[256];
399
400 for (i = 0; i < _countof(pVirtMem->PageFile); i++)
401 {
402 PageFile = &pVirtMem->PageFile[i];
403
404 if (PageFile->bUsed)
405 {
406 if ((PageFile->NewMinSize == -1) &&
407 (PageFile->NewMaxSize == -1))
408 {
411 szSize,
412 _countof(szSize));
413 }
414 else if ((PageFile->NewMinSize == 0) &&
415 (PageFile->NewMaxSize == 0))
416 {
419 szSize,
420 _countof(szSize));
421 }
422 else
423 {
424 _stprintf(szSize, _T("%d - %d"),
425 PageFile->NewMinSize,
426 PageFile->NewMaxSize);
427 }
428
429 _stprintf(szDisplayString,
430 _T("%s [%s]\t%s"),
431 PageFile->szDrive,
432 PageFile->pszVolume ? PageFile->pszVolume : _T(""),
433 szSize);
434
435 Index = SendMessage(pVirtMem->hListBox, LB_ADDSTRING, (WPARAM)0, (LPARAM)szDisplayString);
437 }
438 }
439
440 SendMessage(pVirtMem->hListBox, LB_SETCURSEL, (WPARAM)0, (LPARAM)0);
441
442 OnSelChange(pVirtMem);
443}
static BOOL OnSelChange(PVIRTMEM pVirtMem)
Definition: virtmem.c:615
HINSTANCE hApplet
Definition: access.c:17
#define IDS_PAGEFILE_NONE
Definition: resource.h:52
#define IDS_PAGEFILE_SYSTEM
Definition: resource.h:53
#define _stprintf
Definition: utility.h:124
#define _countof(array)
Definition: sndvol32.h:68
TCHAR szDrive[3]
Definition: virtmem.c:65
LPTSTR pszVolume
Definition: virtmem.c:66
INT NewMinSize
Definition: virtmem.c:69
BOOL bUsed
Definition: virtmem.c:73
INT NewMaxSize
Definition: virtmem.c:70
PAGEFILE PageFile[26]
Definition: virtmem.c:83
HWND hListBox
Definition: virtmem.c:79
int32_t INT
Definition: typedefs.h:58
_In_ WDFCOLLECTION _In_ ULONG Index
LONG_PTR LPARAM
Definition: windef.h:208
UINT_PTR WPARAM
Definition: windef.h:207
#define LB_ADDSTRING
Definition: winuser.h:2031
#define SendMessage
Definition: winuser.h:5843
#define LB_SETITEMDATA
Definition: winuser.h:2065
#define LoadString
Definition: winuser.h:5819
#define LB_SETCURSEL
Definition: winuser.h:2063
char TCHAR
Definition: xmlstorage.h:189

Referenced by OnInitVirtMemDialog().

◆ OnCustom()

static VOID OnCustom ( PVIRTMEM  pVirtMem)
static

Definition at line 381 of file virtmem.c.

382{
383 /* Enable the page file custom size boxes */
386}
#define TRUE
Definition: types.h:120
#define IDC_INITIALSIZE
Definition: resource.h:162
#define IDC_MAXSIZE
Definition: resource.h:163
HWND hSelf
Definition: virtmem.c:78
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)

Referenced by OnSelChange(), and VirtMemDlgProc().

◆ OnDestroy()

static VOID OnDestroy ( PVIRTMEM  pVirtMem)
static

Definition at line 803 of file virtmem.c.

804{
805 UINT i;
806
807 for (i = 0; i < _countof(pVirtMem->PageFile); i++)
808 {
809 if (pVirtMem->PageFile[i].pszVolume != NULL)
810 HeapFree(GetProcessHeap(), 0, pVirtMem->PageFile[i].pszVolume);
811 }
812
813 if (pVirtMem->szPagingFiles)
814 HeapFree(GetProcessHeap(), 0, pVirtMem->szPagingFiles);
815
816 HeapFree(GetProcessHeap(), 0, pVirtMem);
817}
#define NULL
Definition: types.h:112
#define GetProcessHeap()
Definition: compat.h:736
#define HeapFree(x, y, z)
Definition: compat.h:735
LPTSTR szPagingFiles
Definition: virtmem.c:80

Referenced by VirtMemDlgProc().

◆ OnInitVirtMemDialog()

static VOID OnInitVirtMemDialog ( HWND  hwnd,
PVIRTMEM  pVirtMem 
)
static

Definition at line 769 of file virtmem.c.

770{
771 UINT i;
772 PPAGEFILE PageFile;
773
774 pVirtMem->hSelf = hwnd;
776 pVirtMem->bModified = FALSE;
777
778 SetListBoxColumns(pVirtMem->hListBox);
779
780 for (i = 0; i < _countof(pVirtMem->PageFile); i++)
781 {
782 PageFile = &pVirtMem->PageFile[i];
783 PageFile->bUsed = FALSE;
784 PageFile->OldMinSize = -1;
785 PageFile->OldMaxSize = -1;
786 PageFile->NewMinSize = -1;
787 PageFile->NewMaxSize = -1;
788 PageFile->FreeSize = 0;
789 PageFile->bIsNotFAT = TRUE; /* Suppose this is not a FAT volume */
790 }
791
792 /* Load the pagefile systems from the reg */
793 ReadPageFileSettings(pVirtMem);
794
795 /* Parse our settings and set up dialog */
796 ParseMemSettings(pVirtMem);
797
798 InitPagefileList(pVirtMem);
799}
static BOOL ReadPageFileSettings(PVIRTMEM pVirtMem)
Definition: virtmem.c:105
static VOID InitPagefileList(PVIRTMEM pVirtMem)
Definition: virtmem.c:392
static VOID SetListBoxColumns(HWND hwndListBox)
Definition: virtmem.c:353
static VOID ParseMemSettings(PVIRTMEM pVirtMem)
Definition: virtmem.c:192
#define FALSE
Definition: types.h:117
#define IDC_PAGEFILELIST
Definition: resource.h:157
UINT FreeSize
Definition: virtmem.c:71
INT OldMinSize
Definition: virtmem.c:67
BOOL bIsNotFAT
Definition: virtmem.c:72
INT OldMaxSize
Definition: virtmem.c:68
BOOL bModified
Definition: virtmem.c:82
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023

Referenced by VirtMemDlgProc().

◆ OnNoPagingFile()

static VOID OnNoPagingFile ( PVIRTMEM  pVirtMem)
static

Definition at line 363 of file virtmem.c.

364{
365 /* Disable the page file custom size boxes */
368}

Referenced by OnSelChange(), and VirtMemDlgProc().

◆ OnSelChange()

static BOOL OnSelChange ( PVIRTMEM  pVirtMem)
static

Definition at line 615 of file virtmem.c.

616{
617 INT Index;
618 UINT DriveIndex;
619 PPAGEFILE PageFile;
620 MEMORYSTATUSEX MemoryStatus;
621 ULARGE_INTEGER FreeDiskSpace;
622 UINT i, PageFileSizeMb;
623 TCHAR szMegabytes[8];
624 TCHAR szBuffer[64];
625 TCHAR szText[MAX_PATH];
626 WIN32_FIND_DATA fdata = {0};
627 HANDLE hFind;
628 ULARGE_INTEGER pfSize;
629
630 Index = (INT)SendDlgItemMessage(pVirtMem->hSelf,
633 0,
634 0);
635 if (Index >= 0 && Index < pVirtMem->Count)
636 {
637 DriveIndex = SendDlgItemMessage(pVirtMem->hSelf,
640 (WPARAM)Index,
641 0);
642
643 PageFile = &pVirtMem->PageFile[DriveIndex];
644
647 szMegabytes,
648 _countof(szMegabytes));
649
650 /* Set drive letter */
651 SetDlgItemText(pVirtMem->hSelf, IDC_DRIVE,
652 PageFile->szDrive);
653
654 /* Set available disk space */
655 if (GetDiskFreeSpaceEx(PageFile->szDrive,
656 NULL, NULL, &FreeDiskSpace))
657 {
658 PageFile->FreeSize = (UINT)(FreeDiskSpace.QuadPart / MEGABYTE);
659 _stprintf(szBuffer, szMegabytes, PageFile->FreeSize);
660 SetDlgItemText(pVirtMem->hSelf, IDC_SPACEAVAIL, szBuffer);
661 }
662
663 if (PageFile->NewMinSize == -1 &&
664 PageFile->NewMaxSize == -1)
665 {
666 /* No pagefile */
667 OnNoPagingFile(pVirtMem);
669 }
670 else if (PageFile->NewMinSize == 0 &&
671 PageFile->NewMaxSize == 0)
672 {
673 /* System managed size */
674 OnSysManSize(pVirtMem);
676 }
677 else
678 {
679 /* Custom size */
680
681 /* Enable and fill the custom values */
682 OnCustom(pVirtMem);
683
684 SetDlgItemInt(pVirtMem->hSelf,
686 PageFile->NewMinSize,
687 FALSE);
688
689 SetDlgItemInt(pVirtMem->hSelf,
691 PageFile->NewMaxSize,
692 FALSE);
693
694 CheckDlgButton(pVirtMem->hSelf,
697 }
698
699 /* Set minimum pagefile size */
700 _stprintf(szBuffer, szMegabytes, MINIMUM_PAGEFILE_SIZE);
701 SetDlgItemText(pVirtMem->hSelf, IDC_MINIMUM, szBuffer);
702
703 /* Set recommended pagefile size */
704 MemoryStatus.dwLength = sizeof(MemoryStatus);
705 if (GlobalMemoryStatusEx(&MemoryStatus))
706 {
707 UINT FreeMemMb, RecoMemMb;
708 UINT maxPageFileSize = GetMaxPageFileSize(PageFile);
709
710 FreeMemMb = (UINT)(MemoryStatus.ullTotalPhys / MEGABYTE);
711 /* The recommended VM size is 150% of free memory */
712 RecoMemMb = FreeMemMb + (FreeMemMb / 2);
713 if (RecoMemMb > maxPageFileSize)
714 RecoMemMb = maxPageFileSize;
715 _stprintf(szBuffer, szMegabytes, RecoMemMb);
716 SetDlgItemText(pVirtMem->hSelf, IDC_RECOMMENDED, szBuffer);
717 }
718
719 /* Set current pagefile size */
720 PageFileSizeMb = 0;
721
722 for (i = 0; i < pVirtMem->Count; i++)
723 {
724 _stprintf(szText,
725 _T("%c:\\pagefile.sys"),
726 pVirtMem->PageFile[i].szDrive[0]);
727
728 hFind = FindFirstFile(szText, &fdata);
729 if (hFind == INVALID_HANDLE_VALUE)
730 {
731 // FIXME: MsgBox error?
732 DPRINT1("Unable to read PageFile size: %ls due to error %d\n",
733 szText, GetLastError());
734 }
735 else
736 {
737 pfSize.LowPart = fdata.nFileSizeLow;
738 pfSize.HighPart = fdata.nFileSizeHigh;
739 PageFileSizeMb += pfSize.QuadPart / MEGABYTE;
740 FindClose(hFind);
741 }
742 }
743
744 _stprintf(szBuffer, szMegabytes, PageFileSizeMb);
745 SetDlgItemText(pVirtMem->hSelf, IDC_CURRENT, szBuffer);
746 }
747
748 return TRUE;
749}
#define DPRINT1
Definition: precomp.h:8
static VOID OnSysManSize(PVIRTMEM pVirtMem)
Definition: virtmem.c:372
static __inline UINT GetMaxPageFileSize(_In_ PPAGEFILE PageFile)
Definition: virtmem.c:89
static VOID OnCustom(PVIRTMEM pVirtMem)
Definition: virtmem.c:381
#define MEGABYTE
Definition: virtmem.c:22
#define MINIMUM_PAGEFILE_SIZE
Definition: virtmem.c:28
static VOID OnNoPagingFile(PVIRTMEM pVirtMem)
Definition: virtmem.c:363
#define IDC_NOPAGEFILE
Definition: resource.h:165
#define IDC_SYSMANSIZE
Definition: resource.h:164
#define IDC_MINIMUM
Definition: resource.h:168
#define IDC_CURRENT
Definition: resource.h:170
#define IDC_SPACEAVAIL
Definition: resource.h:160
#define IDC_RECOMMENDED
Definition: resource.h:169
#define IDC_CUSTOM
Definition: resource.h:161
#define IDS_PAGEFILE_MB
Definition: resource.h:51
#define IDC_DRIVE
Definition: resource.h:159
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define MAX_PATH
Definition: compat.h:34
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502
BOOL NTAPI GlobalMemoryStatusEx(LPMEMORYSTATUSEX lpBuffer)
Definition: heapmem.c:1272
int Count
Definition: noreturn.cpp:7
$ULONG LowPart
Definition: ntbasedef.h:569
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
$ULONG HighPart
Definition: ntbasedef.h:570
UINT Count
Definition: virtmem.c:81
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define GetDiskFreeSpaceEx
Definition: winbase.h:3808
#define FindFirstFile
Definition: winbase.h:3782
#define LB_GETITEMDATA
Definition: winuser.h:2041
BOOL WINAPI CheckDlgButton(_In_ HWND, _In_ int, _In_ UINT)
BOOL WINAPI SetDlgItemInt(_In_ HWND, _In_ int, _In_ UINT, _In_ BOOL)
#define LB_GETCURSEL
Definition: winuser.h:2039
#define SendDlgItemMessage
Definition: winuser.h:5842
#define SetDlgItemText
Definition: winuser.h:5849
#define BST_CHECKED
Definition: winuser.h:197

Referenced by InitPagefileList(), and VirtMemDlgProc().

◆ OnSet()

static VOID OnSet ( PVIRTMEM  pVirtMem)
static

Definition at line 492 of file virtmem.c.

493{
494 INT Index;
495 UINT MinSize = -1;
496 UINT MaxSize = -1;
497 BOOL bTranslated;
498 UINT DriveIndex;
499 PPAGEFILE PageFile;
500
501 Index = (INT)SendDlgItemMessage(pVirtMem->hSelf,
504 0,
505 0);
506 if (Index >= 0 && Index < pVirtMem->Count)
507 {
508 DriveIndex = SendDlgItemMessage(pVirtMem->hSelf,
511 (WPARAM)Index,
512 0);
513
514 PageFile = &pVirtMem->PageFile[DriveIndex];
515
516 /* Check if custom settings are checked */
517 if (IsDlgButtonChecked(pVirtMem->hSelf,
519 {
520 UINT maxPageFileSize;
521
522 MinSize = GetDlgItemInt(pVirtMem->hSelf,
524 &bTranslated,
525 FALSE);
526 if (!bTranslated)
527 {
529 NULL,
533 return;
534 }
535
536 MaxSize = GetDlgItemInt(pVirtMem->hSelf,
538 &bTranslated,
539 FALSE);
540 if (!bTranslated)
541 {
543 NULL,
547 return;
548 }
549
550 maxPageFileSize = GetMaxPageFileSize(PageFile);
551
552 /* Check the valid range of the minimum size */
553 if ((MinSize < MINIMUM_PAGEFILE_SIZE) ||
554 (MinSize > maxPageFileSize))
555 {
557 NULL,
561 maxPageFileSize);
562 return;
563 }
564
565 /* Check the valid range of the maximum size */
566 if ((MaxSize < MinSize) ||
567 (MaxSize > maxPageFileSize))
568 {
570 NULL,
574 maxPageFileSize);
575 return;
576 }
577
578 // TODO: Check how much disk space would remain after
579 // storing a pagefile of a certain size. Warn/error out
580 // if less than 5 MB would remain.
581
582 PageFile->NewMinSize = MinSize;
583 PageFile->NewMaxSize = MaxSize;
584 PageFile->bUsed = TRUE;
585 }
586 else if (IsDlgButtonChecked(pVirtMem->hSelf,
588 {
589 /* No pagefile */
590 PageFile->NewMinSize = -1;
591 PageFile->NewMaxSize = -1;
592 PageFile->bUsed = TRUE;
593 }
594 else
595 {
596 /* System managed size*/
597 PageFile->NewMinSize = 0;
598 PageFile->NewMaxSize = 0;
599 PageFile->bUsed = TRUE;
600 }
601
602 /* Set the modified flag if min or max size has changed */
603 if ((PageFile->OldMinSize != PageFile->NewMinSize) ||
604 (PageFile->OldMaxSize != PageFile->NewMaxSize))
605 {
606 pVirtMem->bModified = TRUE;
607 }
608
609 UpdatePagefileEntry(pVirtMem, Index, DriveIndex);
610 }
611}
VOID ResourceMessageBox(HINSTANCE hInstance, HWND hwnd, UINT uType, UINT uCaptionId, UINT uMessageId)
Definition: misc.c:282
static VOID UpdatePagefileEntry(PVIRTMEM pVirtMem, INT ListIndex, INT DriveIndex)
Definition: virtmem.c:447
#define IDS_WARNINITIALRANGE
Definition: resource.h:49
#define IDS_WARNMAXIMUMRANGE
Definition: resource.h:50
#define IDS_MESSAGEBOXTITLE
Definition: resource.h:46
#define IDS_WARNMAXIMUMSIZE
Definition: resource.h:48
#define IDS_WARNINITIALSIZE
Definition: resource.h:47
unsigned int BOOL
Definition: ntddk_ex.h:94
UINT WINAPI IsDlgButtonChecked(_In_ HWND, _In_ int)
#define MB_OK
Definition: winuser.h:790
#define MB_ICONWARNING
Definition: winuser.h:786
UINT WINAPI GetDlgItemInt(_In_ HWND, _In_ int, _Out_opt_ PBOOL, _In_ BOOL)

Referenced by VirtMemDlgProc().

◆ OnSysManSize()

static VOID OnSysManSize ( PVIRTMEM  pVirtMem)
static

Definition at line 372 of file virtmem.c.

373{
374 /* Disable the page file custom size boxes */
377}

Referenced by OnSelChange(), and VirtMemDlgProc().

◆ OnVirtMemDialogOk()

static VOID OnVirtMemDialogOk ( PVIRTMEM  pVirtMem)
static

Definition at line 753 of file virtmem.c.

754{
755 if (pVirtMem->bModified != FALSE)
756 {
758 NULL,
762
763 WritePageFileSettings(pVirtMem);
764 }
765}
static VOID WritePageFileSettings(PVIRTMEM pVirtMem)
Definition: virtmem.c:272
#define IDS_INFOREBOOT
Definition: resource.h:54
#define MB_ICONINFORMATION
Definition: winuser.h:802

Referenced by VirtMemDlgProc().

◆ ParseMemSettings()

static VOID ParseMemSettings ( PVIRTMEM  pVirtMem)
static

Definition at line 192 of file virtmem.c.

193{
194 TCHAR szDrives[1024]; // All drives
195 LPTSTR DrivePtr = szDrives;
196 TCHAR szDrive[3]; // Single drive
197 TCHAR szVolume[MAX_PATH + 1];
198 TCHAR szFSName[MAX_PATH + 1];
199 INT MinSize;
200 INT MaxSize;
201 INT DriveLen;
202 INT Len;
203 UINT PgCnt = 0;
204 PPAGEFILE PageFile;
205
206 DriveLen = GetLogicalDriveStrings(_countof(szDrives) - 1,
207 szDrives);
208
209 while (DriveLen != 0)
210 {
211 Len = lstrlen(DrivePtr) + 1;
212 DriveLen -= Len;
213
214 DrivePtr = _tcsupr(DrivePtr);
215
216 /* Copy the 'X:' portion */
217 lstrcpyn(szDrive, DrivePtr, _countof(szDrive));
218
219 if (GetDriveType(DrivePtr) == DRIVE_FIXED)
220 {
221 MinSize = -1;
222 MaxSize = -1;
223
224 /* Does drive match the one in the registry ? */
225 if (_tcsnicmp(pVirtMem->szPagingFiles, szDrive, 2) == 0)
226 {
228 &MinSize,
229 &MaxSize);
230 }
231
232 PageFile = &pVirtMem->PageFile[PgCnt];
233 PageFile->OldMinSize = MinSize;
234 PageFile->OldMaxSize = MaxSize;
235 PageFile->NewMinSize = MinSize;
236 PageFile->NewMaxSize = MaxSize;
237 PageFile->bIsNotFAT = TRUE; /* Suppose this is not a FAT volume */
238 PageFile->bUsed = TRUE;
239 lstrcpy(PageFile->szDrive, szDrive);
240
241 /* Get the volume label if there is one */
242 if (GetVolumeInformation(DrivePtr,
243 szVolume, _countof(szVolume),
244 NULL, NULL, NULL,
245 szFSName, _countof(szFSName)))
246 {
248 (_tcslen(szVolume) + 1) * sizeof(TCHAR));
249 if (PageFile->pszVolume != NULL)
250 _tcscpy(PageFile->pszVolume, szVolume);
251
252 /*
253 * Check whether the volume is FAT, which cannot support files
254 * larger than 4GB (for FAT32 and FATX, and less for FAT16).
255 * This will limit the maximum size of the pagefile this volume
256 * can contain (see GetMaxPageFileSize()).
257 */
258 PageFile->bIsNotFAT = (_tcsnicmp(szFSName, _T("FAT"), 3) != 0);
259 }
260
261 PgCnt++;
262 }
263
264 DrivePtr += Len;
265 }
266
267 pVirtMem->Count = PgCnt;
268}
static VOID GetPageFileSizes(LPTSTR lpPageFiles, LPINT lpInitialSize, LPINT lpMaximumSize)
Definition: virtmem.c:158
#define Len
Definition: deflate.h:82
#define HeapAlloc
Definition: compat.h:733
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define _tcscpy
Definition: tchar.h:623
#define _tcsupr
Definition: tchar.h:1467
#define lstrcpyn
Definition: winbase.h:3875
#define GetVolumeInformation
Definition: winbase.h:3853
#define GetDriveType
Definition: winbase.h:3812
#define GetLogicalDriveStrings
Definition: winbase.h:3822
#define lstrcpy
Definition: winbase.h:3874
#define lstrlen
Definition: winbase.h:3876
#define DRIVE_FIXED
Definition: winbase.h:252
#define _tcsnicmp
Definition: xmlstorage.h:207
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define _tcslen
Definition: xmlstorage.h:198

Referenced by OnInitVirtMemDialog().

◆ ReadPageFileSettings()

static BOOL ReadPageFileSettings ( PVIRTMEM  pVirtMem)
static

Definition at line 105 of file virtmem.c.

106{
107 BOOL bRet = FALSE;
108 HKEY hkey = NULL;
109 DWORD dwType;
110 DWORD dwDataSize;
111
113 lpKey,
114 0,
115 NULL,
118 NULL,
119 &hkey,
121 {
122 if (RegQueryValueEx(hkey,
123 _T("PagingFiles"),
124 NULL,
125 &dwType,
126 NULL,
127 &dwDataSize) == ERROR_SUCCESS)
128 {
131 dwDataSize);
132 if (pVirtMem->szPagingFiles != NULL)
133 {
134 if (RegQueryValueEx(hkey,
135 _T("PagingFiles"),
136 NULL,
137 &dwType,
138 (PBYTE)pVirtMem->szPagingFiles,
139 &dwDataSize) == ERROR_SUCCESS)
140 {
141 bRet = TRUE;
142 }
143 }
144 }
145 }
146
147 if (!bRet)
148 ShowLastWin32Error(pVirtMem->hSelf);
149
150 if (hkey != NULL)
151 RegCloseKey(hkey);
152
153 return bRet;
154}
#define RegCloseKey(hKey)
Definition: registry.h:49
static LPCTSTR lpKey
Definition: virtmem.c:102
#define ERROR_SUCCESS
Definition: deptool.c:10
unsigned long DWORD
Definition: ntddk_ex.h:95
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
BYTE * PBYTE
Definition: pedump.c:66
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define RegCreateKeyEx
Definition: winreg.h:501
#define RegQueryValueEx
Definition: winreg.h:524
void ShowLastWin32Error(HWND hwndParent)
Definition: winutils.c:11

Referenced by OnInitVirtMemDialog().

◆ SetListBoxColumns()

static VOID SetListBoxColumns ( HWND  hwndListBox)
static

Definition at line 353 of file virtmem.c.

354{
355 RECT rect = {0, 0, 103, 0};
356 MapDialogRect(hwndListBox, &rect);
357
358 SendMessage(hwndListBox, LB_SETTABSTOPS, (WPARAM)1, (LPARAM)&rect.right);
359}
& rect
Definition: startmenu.cpp:1413
BOOL WINAPI MapDialogRect(_In_ HWND, _Inout_ LPRECT)
#define LB_SETTABSTOPS
Definition: winuser.h:2069

Referenced by OnInitVirtMemDialog().

◆ UpdatePagefileEntry()

static VOID UpdatePagefileEntry ( PVIRTMEM  pVirtMem,
INT  ListIndex,
INT  DriveIndex 
)
static

Definition at line 447 of file virtmem.c.

450{
451 PPAGEFILE PageFile = &pVirtMem->PageFile[DriveIndex];
452 TCHAR szSize[64];
453 TCHAR szDisplayString[256];
454
455 if ((PageFile->NewMinSize == -1) &&
456 (PageFile->NewMaxSize == -1))
457 {
460 szSize,
461 _countof(szSize));
462 }
463 else if ((PageFile->NewMinSize == 0) &&
464 (PageFile->NewMaxSize == 0))
465 {
468 szSize,
469 _countof(szSize));
470 }
471 else
472 {
473 _stprintf(szSize,
474 _T("%d - %d"),
475 PageFile->NewMinSize,
476 PageFile->NewMaxSize);
477 }
478
479 _stprintf(szDisplayString,
480 _T("%s [%s]\t%s"),
481 PageFile->szDrive,
482 PageFile->pszVolume ? PageFile->pszVolume : _T(""),
483 szSize);
484
485 SendMessage(pVirtMem->hListBox, LB_DELETESTRING, (WPARAM)ListIndex, 0);
486 SendMessage(pVirtMem->hListBox, LB_INSERTSTRING, (WPARAM)ListIndex, (LPARAM)szDisplayString);
487 SendMessage(pVirtMem->hListBox, LB_SETCURSEL, (WPARAM)ListIndex, 0);
488}
#define LB_DELETESTRING
Definition: winuser.h:2032
#define LB_INSERTSTRING
Definition: winuser.h:2053

Referenced by OnSet().

◆ VirtMemDlgProc()

INT_PTR CALLBACK VirtMemDlgProc ( HWND  hwndDlg,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 821 of file virtmem.c.

825{
826 PVIRTMEM pVirtMem;
827
829
830 pVirtMem = (PVIRTMEM)GetWindowLongPtr(hwndDlg, DWLP_USER);
831
832 switch (uMsg)
833 {
834 case WM_INITDIALOG:
835 {
836 pVirtMem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(VIRTMEM));
837 if (pVirtMem == NULL)
838 {
839 EndDialog(hwndDlg, 0);
840 return FALSE;
841 }
842
843 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pVirtMem);
844
845 OnInitVirtMemDialog(hwndDlg, pVirtMem);
846 break;
847 }
848
849 case WM_DESTROY:
850 OnDestroy(pVirtMem);
851 break;
852
853 case WM_COMMAND:
854 switch (LOWORD(wParam))
855 {
856 case IDCANCEL:
857 EndDialog(hwndDlg, 0);
858 return TRUE;
859
860 case IDOK:
861 OnVirtMemDialogOk(pVirtMem);
862 EndDialog(hwndDlg, pVirtMem->bModified);
863 return TRUE;
864
865 case IDC_NOPAGEFILE:
866 OnNoPagingFile(pVirtMem);
867 return TRUE;
868
869 case IDC_SYSMANSIZE:
870 OnSysManSize(pVirtMem);
871 return TRUE;
872
873 case IDC_CUSTOM:
874 OnCustom(pVirtMem);
875 return TRUE;
876
877 case IDC_SET:
878 OnSet(pVirtMem);
879 return TRUE;
880
881 case IDC_PAGEFILELIST:
882 switch (HIWORD(wParam))
883 {
884 case LBN_SELCHANGE:
885 OnSelChange(pVirtMem);
886 return TRUE;
887 }
888 break;
889 }
890 break;
891 }
892
893 return FALSE;
894}
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
static VOID OnInitVirtMemDialog(HWND hwnd, PVIRTMEM pVirtMem)
Definition: virtmem.c:769
struct _VIRTMEM * PVIRTMEM
static VOID OnDestroy(PVIRTMEM pVirtMem)
Definition: virtmem.c:803
static VOID OnVirtMemDialogOk(PVIRTMEM pVirtMem)
Definition: virtmem.c:753
static VOID OnSet(PVIRTMEM pVirtMem)
Definition: virtmem.c:492
#define IDC_SET
Definition: resource.h:166
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define LOWORD(l)
Definition: pedump.c:82
#define GetWindowLongPtr
Definition: treelist.c:73
#define SetWindowLongPtr
Definition: treelist.c:70
#define HIWORD(l)
Definition: typedefs.h:247
#define DWLP_USER
Definition: winuser.h:872
#define IDCANCEL
Definition: winuser.h:831
#define WM_COMMAND
Definition: winuser.h:1740
#define WM_INITDIALOG
Definition: winuser.h:1739
#define IDOK
Definition: winuser.h:830
#define LBN_SELCHANGE
Definition: winuser.h:2075
#define WM_DESTROY
Definition: winuser.h:1609
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)

Referenced by AdvancedPageProc().

◆ WritePageFileSettings()

static VOID WritePageFileSettings ( PVIRTMEM  pVirtMem)
static

Definition at line 272 of file virtmem.c.

273{
274 BOOL bErr = TRUE;
275 HKEY hk = NULL;
276 TCHAR szText[256];
277 TCHAR szPagingFiles[2048];
278 UINT i, nPos = 0;
279 PPAGEFILE PageFile;
280
281 for (i = 0; i < pVirtMem->Count; ++i)
282 {
283 PageFile = &pVirtMem->PageFile[i];
284
285 if (PageFile->bUsed &&
286 PageFile->NewMinSize != -1 &&
287 PageFile->NewMaxSize != -1)
288 {
289 _stprintf(szText,
290 _T("%s\\pagefile.sys %i %i"),
291 PageFile->szDrive,
292 PageFile->NewMinSize,
293 PageFile->NewMaxSize);
294
295 /* Add it to our overall registry string */
296 lstrcpy(szPagingFiles + nPos, szText);
297
298 /* Record the position where the next string will start */
299 nPos += (UINT)lstrlen(szText) + 1;
300
301 /* Add another NULL for REG_MULTI_SZ */
302 szPagingFiles[nPos] = _T('\0');
303 nPos++;
304 }
305 }
306
308 lpKey,
309 0,
310 NULL,
312 KEY_WRITE,
313 NULL,
314 &hk,
316 {
317 if (RegSetValueEx(hk,
318 _T("PagingFiles"),
319 0,
321 (LPBYTE)szPagingFiles,
322 (DWORD)nPos * sizeof(TCHAR)) == ERROR_SUCCESS)
323 {
324 bErr = FALSE;
325 }
326
327 RegCloseKey(hk);
328 }
329
330 if (bErr == FALSE)
331 {
332 /* Delete obsolete paging files on the next boot */
333 for (i = 0; i < _countof(pVirtMem->PageFile); i++)
334 {
335 if (pVirtMem->PageFile[i].OldMinSize != -1 &&
336 pVirtMem->PageFile[i].NewMinSize == -1)
337 {
338 _stprintf(szText,
339 _T("%s\\pagefile.sys"),
340 pVirtMem->PageFile[i].szDrive);
341
343 }
344 }
345 }
346
347 if (bErr)
348 ShowLastWin32Error(pVirtMem->hSelf);
349}
#define REG_MULTI_SZ
Definition: nt_native.h:1501
#define KEY_WRITE
Definition: nt_native.h:1031
unsigned char * LPBYTE
Definition: typedefs.h:53
#define MoveFileEx
Definition: winbase.h:3878
#define MOVEFILE_DELAY_UNTIL_REBOOT
Definition: winbase.h:400
#define RegSetValueEx
Definition: winreg.h:533

Referenced by OnVirtMemDialogOk().

Variable Documentation

◆ lpKey