You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stdcxx.apache.org by fa...@apache.org on 2007/06/19 09:03:13 UTC
svn commit: r548616 - in /incubator/stdcxx/trunk/etc/config/src:
GLOBAL_BAD_ALLOC.cpp NEW_THROWS.cpp STD_BAD_ALLOC.cpp proclimits.h
Author: faridz
Date: Tue Jun 19 00:03:12 2007
New Revision: 548616
URL: http://svn.apache.org/viewvc?view=rev&rev=548616
Log:
2007-06-19 Farid Zaripov <Fa...@epam.com>
* proclimits.h: New file with process limit functions
* NEW_THROWS.cpp: #included "proclimits.h"
* GLOBAL_BAD_ALLOC.cpp: Ditto
* STD_BAD_ALLOC.cpp: Ditto
Added:
incubator/stdcxx/trunk/etc/config/src/proclimits.h (with props)
Modified:
incubator/stdcxx/trunk/etc/config/src/GLOBAL_BAD_ALLOC.cpp
incubator/stdcxx/trunk/etc/config/src/NEW_THROWS.cpp
incubator/stdcxx/trunk/etc/config/src/STD_BAD_ALLOC.cpp
Modified: incubator/stdcxx/trunk/etc/config/src/GLOBAL_BAD_ALLOC.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/etc/config/src/GLOBAL_BAD_ALLOC.cpp?view=diff&rev=548616&r1=548615&r2=548616
==============================================================================
--- incubator/stdcxx/trunk/etc/config/src/GLOBAL_BAD_ALLOC.cpp (original)
+++ incubator/stdcxx/trunk/etc/config/src/GLOBAL_BAD_ALLOC.cpp Tue Jun 19 00:03:12 2007
@@ -7,9 +7,12 @@
#endif // !_RWSTD_NO_NEW_THROWS && !_RWSTD_NO_NEW_OFLOW_SAFE
#ifndef _RWSTD_NO_SETRLIMIT
-# include <sys/resource.h> // for setrlimit()
+// test for setrlimit() presence before compiling current file
#endif
+// proclimits.h must be included only after #if[n]def _RWSTD_NO_SETRLIMIT
+#include "proclimits.h"
+
#ifndef _RWSTD_NO_HONOR_STD
# ifdef _RWSTD_NO_STD_TERMINATE
@@ -74,12 +77,7 @@
# else // if defined (_RWSTD_NO_NEW_OFLOW_SAFE)
-#ifndef _RWSTD_NO_SETRLIMIT
-
- struct rlimit rl = { 0, 0 };
- setrlimit (RLIMIT_DATA, &rl);
-
-#endif // _RWSTD_NO_SETRLIMIT
+ limit_memory (0);
for (unsigned long n = 1UL << (sizeof (long) * 8 - 1);
0 != n; n |= (n >> 1)) {
Modified: incubator/stdcxx/trunk/etc/config/src/NEW_THROWS.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/etc/config/src/NEW_THROWS.cpp?view=diff&rev=548616&r1=548615&r2=548616
==============================================================================
--- incubator/stdcxx/trunk/etc/config/src/NEW_THROWS.cpp (original)
+++ incubator/stdcxx/trunk/etc/config/src/NEW_THROWS.cpp Tue Jun 19 00:03:12 2007
@@ -5,9 +5,11 @@
#include <stdio.h>
#ifndef _RWSTD_NO_SETRLIMIT
-# include <sys/resource.h> // for setrlimit()
+// test for setrlimit() presence before compiling current file
#endif // _RWSTD_NO_SETRLIMIT
+// proclimits.h must be included only after #if[n]def _RWSTD_NO_SETRLIMIT
+#include "proclimits.h"
#if 2 == __GNUG__
# ifndef _RWSTD_NO_HONOR_STD
@@ -84,15 +86,9 @@
// by passing it a smaller argument
printf ("#define _RWSTD_NO_NEW_OFLOW_SAFE\n");
-#ifndef _RWSTD_NO_SETRLIMIT
-
// decrease resource limit to a minimum to induce a failure
// without unreasonably stressing the system
-
- struct rlimit rl = { 0, 0 };
- setrlimit (RLIMIT_DATA, &rl);
-
-#endif // _RWSTD_NO_SETRLIMIT
+ limit_memory (0);
p = (void*)1;
Modified: incubator/stdcxx/trunk/etc/config/src/STD_BAD_ALLOC.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/etc/config/src/STD_BAD_ALLOC.cpp?view=diff&rev=548616&r1=548615&r2=548616
==============================================================================
--- incubator/stdcxx/trunk/etc/config/src/STD_BAD_ALLOC.cpp (original)
+++ incubator/stdcxx/trunk/etc/config/src/STD_BAD_ALLOC.cpp Tue Jun 19 00:03:12 2007
@@ -7,9 +7,12 @@
#endif // !_RWSTD_NO_NEW_THROWS && !_RWSTD_NO_NEW_OFLOW_SAFE
#ifndef _RWSTD_NO_SETRLIMIT
-# include <sys/resource.h> // for setrlimit()
+// test for setrlimit() presence before compiling current file
#endif
+// proclimits.h must be included only after #if[n]def _RWSTD_NO_SETRLIMIT
+#include "proclimits.h"
+
#ifndef _RWSTD_NO_HONOR_STD
# ifdef _RWSTD_NO_STD_TERMINATE
@@ -81,12 +84,7 @@
# else // if defined (_RWSTD_NO_NEW_OFLOW_SAFE)
-#ifndef _RWSTD_NO_SETRLIMIT
-
- struct rlimit rl = { 0, 0 };
- setrlimit (RLIMIT_DATA, &rl);
-
-#endif // _RWSTD_NO_SETRLIMIT
+ limit_memory (0);
for (unsigned long n = 1UL << (sizeof (long) * 8 - 1);
0 != n; n |= (n >> 1)) {
Added: incubator/stdcxx/trunk/etc/config/src/proclimits.h
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/etc/config/src/proclimits.h?view=auto&rev=548616
==============================================================================
--- incubator/stdcxx/trunk/etc/config/src/proclimits.h (added)
+++ incubator/stdcxx/trunk/etc/config/src/proclimits.h Tue Jun 19 00:03:12 2007
@@ -0,0 +1,57 @@
+// proclimits.h must be included in .cpp file
+// only after #if[n]def _RWSTD_NO_SETRLIMIT line
+
+#if !defined (_RWSTD_NO_SETRLIMIT)
+
+# include <sys/resource.h> // for setrlimit()
+
+void limit_memory (unsigned long limit)
+{
+ struct rlimit rl = { limit, limit };
+ setrlimit (RLIMIT_DATA, &rl);
+}
+
+#elif defined (_WIN32)
+
+# ifndef _WIN32_WINNT
+# define _WIN32_WINNT 0x0500
+# endif
+
+# if _WIN32_WINNT >= 0x0500
+
+// Job Objects available only in Windows 2000 and later
+
+# include <windows.h>
+
+void limit_memory (unsigned long limit)
+{
+ SYSTEM_INFO info;
+ GetSystemInfo (&info);
+
+ HANDLE hJob = CreateJobObject (NULL, NULL);
+ if (hJob) {
+ if (AssignProcessToJobObject (hJob, GetCurrentProcess ())) {
+ JOBOBJECT_EXTENDED_LIMIT_INFORMATION job_info = { 0 };
+ job_info.BasicLimitInformation.LimitFlags =
+ JOB_OBJECT_LIMIT_PROCESS_MEMORY;
+ job_info.ProcessMemoryLimit =
+ limit > info.dwPageSize ? limit : info.dwPageSize;
+ SetInformationJobObject (hJob,
+ JobObjectExtendedLimitInformation,
+ &job_info, sizeof (job_info));
+ }
+ CloseHandle (hJob);
+ }
+}
+
+# else // _WIN32_WINNT < 0x0500
+
+void limit_memory (unsigned long) { /* no-op */ }
+
+# endif // _WIN32_WINNT
+
+#else // _RWSTD_NO_SETRLIMIT && !_WIN32
+
+void limit_memory (unsigned long) { /* no-op */ }
+
+#endif // _RWSTD_NO_SETRLIMIT
Propchange: incubator/stdcxx/trunk/etc/config/src/proclimits.h
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/stdcxx/trunk/etc/config/src/proclimits.h
------------------------------------------------------------------------------
svn:keywords = Id