desktop/Executable_soffice.mk | 4 + desktop/win32/source/officeloader/officeloader.cxx | 51 +++++++++++++++++++++ 2 files changed, 55 insertions(+)
New commits: commit f77b3510eadc1024108789087f0172bd198a5433 Author: Jan-Marek Glogowski <jan-marek.glogow...@extern.cib.de> AuthorDate: Wed Sep 11 14:35:19 2019 +0200 Commit: Thorsten Behrens <thorsten.behr...@cib.de> CommitDate: Fri Sep 13 21:28:50 2019 +0200 WIN allow setting a memory limit for soffice.bin This adds a Win32 section and two keys to the bootstrap.ini, which can be used to apply a memory limit to the soffice.bin process on Windows. Per default the limit won't affect any sub-processes, because the 2nd key adds JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK to the Jobs' flag list. To activte the limit, extend the bootstrap.ini like this: [Win32] LimitMaximumMemoryInMB=0 ExcludeChildProcessesFromLimit=true and adapt the values to your needs. Zero disables the limit. Reviewed-on: https://gerrit.libreoffice.org/78819 Tested-by: Jenkins Reviewed-by: Jan-Marek Glogowski <glo...@fbihome.de> (cherry picked from commit 6df7568e46b7f307ad6ae94730809fe63a6981a6) Change-Id: Ic474c6d6cdfe5ff3cfadbe6614030442171df1ae Reviewed-on: https://gerrit.libreoffice.org/78885 Reviewed-by: Thorsten Behrens <thorsten.behr...@cib.de> Tested-by: Thorsten Behrens <thorsten.behr...@cib.de> diff --git a/desktop/Executable_soffice.mk b/desktop/Executable_soffice.mk index d1847d7bf76a..5c9a081ff22e 100644 --- a/desktop/Executable_soffice.mk +++ b/desktop/Executable_soffice.mk @@ -11,6 +11,10 @@ $(eval $(call gb_Executable_Executable,soffice)) $(eval $(call gb_Executable_set_targettype_gui,soffice,YES)) +$(eval $(call gb_Executable_use_externals,soffice,\ + boost_headers \ +)) + $(eval $(call gb_Executable_use_system_win32_libs,soffice,\ advapi32 \ shell32 \ diff --git a/desktop/win32/source/officeloader/officeloader.cxx b/desktop/win32/source/officeloader/officeloader.cxx index cd471ca2a5f9..1108371d02f9 100644 --- a/desktop/win32/source/officeloader/officeloader.cxx +++ b/desktop/win32/source/officeloader/officeloader.cxx @@ -23,6 +23,9 @@ #include <stdlib.h> #include <desktop/exithelper.h> +#include <boost/property_tree/ptree.hpp> +#include <boost/property_tree/ini_parser.hpp> + #include "../loader.hxx" static LPWSTR *GetCommandArgs( int *pArgc ) @@ -65,6 +68,47 @@ int WINAPI wWinMain( HINSTANCE, HINSTANCE, LPWSTR, int ) cwdLen = 0; } + // read limit values from bootstrap.ini + unsigned int nMaxMemoryInMB = 0; + bool bExcludeChildProcesses = true; + + const WCHAR* szIniFile = L"\\bootstrap.ini"; + const size_t nDirLen = wcslen(szIniDirectory); + if (wcslen(szIniFile) + nDirLen < MAX_PATH) + { + WCHAR szBootstrapIni[MAX_PATH]; + wcscpy(szBootstrapIni, szIniDirectory); + wcscpy(&szBootstrapIni[nDirLen], szIniFile); + + try + { + boost::property_tree::ptree pt; + std::fstream aFile(szBootstrapIni); + boost::property_tree::ini_parser::read_ini(aFile, pt); + nMaxMemoryInMB = pt.get("Win32.LimitMaximumMemoryInMB", nMaxMemoryInMB); + bExcludeChildProcesses = pt.get("Win32.ExcludeChildProcessesFromLimit", bExcludeChildProcesses); + } + catch (...) + { + nMaxMemoryInMB = 0; + } + } + + // create a Windows JobObject with a memory limit + HANDLE hJobObject = NULL; + if (nMaxMemoryInMB > 0) + { + JOBOBJECT_EXTENDED_LIMIT_INFORMATION aJobLimit; + aJobLimit.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_JOB_MEMORY; + if (bExcludeChildProcesses) + aJobLimit.BasicLimitInformation.LimitFlags |= JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK; + aJobLimit.JobMemoryLimit = nMaxMemoryInMB * 1024 * 1024; + hJobObject = CreateJobObjectW(NULL, NULL); + if (hJobObject != NULL) + SetInformationJobObject(hJobObject, JobObjectExtendedLimitInformation, &aJobLimit, + sizeof(JOBOBJECT_EXTENDED_LIMIT_INFORMATION)); + } + do { if ( bFirst ) { @@ -157,6 +201,9 @@ int WINAPI wWinMain( HINSTANCE, HINSTANCE, LPWSTR, int ) { DWORD dwWaitResult; + if (hJobObject) + AssignProcessToJobObject(hJobObject, aProcessInfo.hProcess); + do { // On Windows XP it seems as the desktop calls WaitForInputIdle after "OpenWidth" so we have to do so @@ -180,6 +227,10 @@ int WINAPI wWinMain( HINSTANCE, HINSTANCE, LPWSTR, int ) } } while ( fSuccess && ( EXITHELPER_CRASH_WITH_RESTART == dwExitCode || EXITHELPER_NORMAL_RESTART == dwExitCode )); + + if (hJobObject) + CloseHandle(hJobObject); + delete[] lpCommandLine; LocalFree(argv); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits