MCPcopy Create free account
hub / github.com/avast/retdec / limitSystemMemoryOnWindows

Function limitSystemMemoryOnWindows

src/utils/memory.cpp:80–99  ·  view source on GitHub ↗

* @brief Implementation of @c limitSystemMemory() on Windows. */

Source from the content-addressed store, hash-verified

78* @brief Implementation of @c limitSystemMemory() on Windows.
79*/
80bool limitSystemMemoryOnWindows(std::size_t limit) {
81 // On Windows 7, AssignProcessToJobObject() fails when the current process
82 // has already been attached to a job. Therefore, we have to remember the
83 // job and use it in all subsequent calls to limitSystemMemoryOnWindows().
84 // This is not thread safe, but limitSystemMemory() is already marked as
85 // not reentrant, so we are OK.
86 static auto jobHandle = assignProcessToNewJob();
87
88 JOBOBJECT_EXTENDED_LIMIT_INFORMATION extendedInfo{};
89 extendedInfo.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_PROCESS_MEMORY;
90 extendedInfo.ProcessMemoryLimit = limit;
91
92 auto succeeded = SetInformationJobObject(
93 jobHandle,
94 JobObjectExtendedLimitInformation,
95 &extendedInfo,
96 sizeof(extendedInfo)
97 );
98 return succeeded;
99}
100
101#elif defined(OS_MACOS)
102

Callers 1

limitSystemMemoryFunction · 0.85

Calls 1

assignProcessToNewJobFunction · 0.85

Tested by

no test coverage detected