Author: faridz
Date: Wed Jul 25 05:37:56 2007
New Revision: 559425
URL: http://svn.apache.org/viewvc?view=rev&rev=559425
Log:
2007-07-25 Farid Zaripov <[EMAIL PROTECTED]>
* cmdopt.cpp [_WIN32]: #define RLIMIT_AS (for limit process memory on
Windows).
* exec.cpp (exec_file) [_WIN32]: Create process in suspended state.
Limit process memory if needed. Set start time as time before resuming
process.
Modified:
incubator/stdcxx/trunk/util/cmdopt.cpp
incubator/stdcxx/trunk/util/exec.cpp
Modified: incubator/stdcxx/trunk/util/cmdopt.cpp
URL:
http://svn.apache.org/viewvc/incubator/stdcxx/trunk/util/cmdopt.cpp?view=diff&rev=559425&r1=559424&r2=559425
==============================================================================
--- incubator/stdcxx/trunk/util/cmdopt.cpp (original)
+++ incubator/stdcxx/trunk/util/cmdopt.cpp Wed Jul 25 05:37:56 2007
@@ -73,6 +73,14 @@
const char suffix_sep = '.';
const size_t exe_suffix_len = 4; /* strlen(".exe") == 4 */
const float TICKS_PER_SEC = 10000000; /* 100 nanosecond units in a second */
+
+# ifndef _WIN32_WINNT
+# define _WIN32_WINNT 0x0500
+# endif
+
+# if _WIN32_WINNT >= 0x0500
+# define RLIMIT_AS
+# endif
#endif
static const char
Modified: incubator/stdcxx/trunk/util/exec.cpp
URL:
http://svn.apache.org/viewvc/incubator/stdcxx/trunk/util/exec.cpp?view=diff&rev=559425&r1=559424&r2=559425
==============================================================================
--- incubator/stdcxx/trunk/util/exec.cpp (original)
+++ incubator/stdcxx/trunk/util/exec.cpp Wed Jul 25 05:37:56 2007
@@ -45,8 +45,10 @@
# include <sys/resource.h> /* for setlimit(), RLIMIT_CORE, ... */
# endif
#else
-# include <windows.h> /* for PROCESS_INFORMATION, ... */
-# include <process.h> /* for CreateProcess, ... */
+# ifndef _WIN32_WINNT
+# define _WIN32_WINNT 0x0500
+# endif
+# include <windows.h> /* for PROCESS_INFORMATION, CreateProcess, ... */
# ifndef SIGTRAP
# define SIGTRAP 5 // STATUS_BREAKPOINT translated into SIGTRAP
# endif
@@ -1203,12 +1205,9 @@
UINT old_mode = SetErrorMode (SEM_FAILCRITICALERRORS
| SEM_NOGPFAULTERRORBOX);
- /* Check the wall clock before creating the process */
- GetSystemTimeAsFileTime(&start);
-
- /* Create the child process */
+ /* Create the child process in suspended state */
if (0 == CreateProcess (options->argv [0], merged, 0, 0, 1,
- CREATE_NEW_PROCESS_GROUP, 0, 0, &context, &child)) {
+ CREATE_NEW_PROCESS_GROUP | CREATE_SUSPENDED, 0, 0, &context, &child)) {
/* record the status if we failed to create the process */
result->status = ST_SYSTEM_ERROR;
warn_last_error ("Creating child process");;
@@ -1230,6 +1229,41 @@
/* Return if we failed to create the child process */
if (ST_SYSTEM_ERROR == result->status)
return;
+
+#if _WIN32_WINNT >= 0x0500
+ if (options->as) {
+ if (HANDLE hJob = CreateJobObject (NULL, NULL)) {
+ if (AssignProcessToJobObject (hJob, child.hProcess)) {
+ JOBOBJECT_EXTENDED_LIMIT_INFORMATION job_info = { 0 };
+
+ job_info.BasicLimitInformation.LimitFlags =
+ JOB_OBJECT_LIMIT_PROCESS_MEMORY;
+
+ const rw_rlimit* as = options->as;
+ job_info.ProcessMemoryLimit =
+ as->rlim_cur < as->rlim_max ? as->rlim_cur : as->rlim_max;
+
+ if (!SetInformationJobObject (hJob,
+
JobObjectExtendedLimitInformation,
+ &job_info, sizeof (job_info)))
+ warn_last_error ("Setting process limits");
+ }
+ else
+ warn_last_error ("Assigning process to job object");
+
+ if (!CloseHandle (hJob))
+ warn_last_error ("Closing job object handle");
+ }
+ else
+ warn_last_error ("Creating job object");
+ }
+#endif // _WIN32_WINNT >= 0x0500
+
+ /* Check the wall clock before resuming the process */
+ GetSystemTimeAsFileTime(&start);
+
+ if (DWORD (-1) == ResumeThread (child.hThread))
+ warn_last_error ("Resuming process");
if (0 == CloseHandle (child.hThread))
warn_last_error ("Closing child main thread handle");