-
Notifications
You must be signed in to change notification settings - Fork 29
/
largepage.hpp
54 lines (47 loc) · 1.27 KB
/
largepage.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef _RAR_LARGEPAGE_
#define _RAR_LARGEPAGE_
class LargePageAlloc
{
private:
static constexpr const wchar *LOCKMEM_SWITCH=L"isetup_privilege_lockmem";
void* new_large(size_t Size);
bool delete_large(void *Addr);
#ifdef _WIN_ALL
std::vector<void*> LargeAlloc;
SIZE_T PageSize;
#endif
bool UseLargePages;
public:
LargePageAlloc();
void AllowLargePages(bool Allow);
static bool IsPrivilegeAssigned();
static bool AssignPrivilege();
static bool AssignPrivilegeBySid(const std::wstring &Sid);
static bool AssignConfirmation();
static bool ProcessSwitch(CommandData *Cmd,const wchar *Switch)
{
if (Switch[0]==LOCKMEM_SWITCH[0])
{
size_t Length=wcslen(LOCKMEM_SWITCH);
if (wcsncmp(Switch,LOCKMEM_SWITCH,Length)==0)
{
LargePageAlloc::AssignPrivilegeBySid(Switch+Length);
return true;
}
}
return false;
}
template <class T> T* new_l(size_t Size,bool Clear=false)
{
T *Allocated=(T*)new_large(Size*sizeof(T));
if (Allocated==nullptr)
Allocated=Clear ? new T[Size]{} : new T[Size];
return Allocated;
}
template <class T> void delete_l(T *Addr)
{
if (!delete_large(Addr))
delete[] Addr;
}
};
#endif