MCPcopy Create free account
hub / github.com/RenderKit/embree / win_enable_selockmemoryprivilege

Function win_enable_selockmemoryprivilege

common/sys/alloc.cpp:132–161  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

130namespace embree
131{
132 bool win_enable_selockmemoryprivilege (bool verbose)
133 {
134 HANDLE hToken;
135 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES, &hToken)) {
136 if (verbose) std::cout << "WARNING: OpenProcessToken failed while trying to enable SeLockMemoryPrivilege: " << GetLastError() << std::endl;
137 return false;
138 }
139
140 TOKEN_PRIVILEGES tp;
141 tp.PrivilegeCount = 1;
142 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
143
144 if (!LookupPrivilegeValueW(nullptr, L"SeLockMemoryPrivilege", &tp.Privileges[0].Luid)) {
145 if (verbose) std::cout << "WARNING: LookupPrivilegeValue failed while trying to enable SeLockMemoryPrivilege: " << GetLastError() << std::endl;
146 return false;
147 }
148
149 SetLastError(ERROR_SUCCESS);
150 if (!AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(tp), nullptr, 0)) {
151 if (verbose) std::cout << "WARNING: AdjustTokenPrivileges failed while trying to enable SeLockMemoryPrivilege" << std::endl;
152 return false;
153 }
154
155 if (GetLastError() == ERROR_NOT_ALL_ASSIGNED) {
156 if (verbose) std::cout << "WARNING: AdjustTokenPrivileges failed to enable SeLockMemoryPrivilege: Add SeLockMemoryPrivilege for current user and run process in elevated mode (Run as administrator)." << std::endl;
157 return false;
158 }
159
160 return true;
161 }
162
163 bool os_init(bool hugepages, bool verbose)
164 {

Callers 1

DeviceMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected