diff options
author | Anton Korobeynikov <asl@math.spbu.ru> | 2007-02-16 19:11:07 +0000 |
---|---|---|
committer | Anton Korobeynikov <asl@math.spbu.ru> | 2007-02-16 19:11:07 +0000 |
commit | 9ba8a76f8baaa1092d60ccfbc04e7efdc207c98f (patch) | |
tree | a4d2b47d47b30c9f7416757f798b092bf1ea6909 /lib | |
parent | bdf44b929f6bd0983b0f0df0d2ae66610e81e149 (diff) | |
download | external_llvm-9ba8a76f8baaa1092d60ccfbc04e7efdc207c98f.zip external_llvm-9ba8a76f8baaa1092d60ccfbc04e7efdc207c98f.tar.gz external_llvm-9ba8a76f8baaa1092d60ccfbc04e7efdc207c98f.tar.bz2 |
Add possibility to set memory limit for binaries run via libSystem. This
is especially needed for bugpoint. This partly implements PR688
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34349 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Support/GraphWriter.cpp | 8 | ||||
-rw-r--r-- | lib/System/Unix/Program.inc | 30 | ||||
-rw-r--r-- | lib/System/Win32/Program.inc | 1 |
3 files changed, 35 insertions, 4 deletions
diff --git a/lib/Support/GraphWriter.cpp b/lib/Support/GraphWriter.cpp index ecf2bfd..31d8d79 100644 --- a/lib/Support/GraphWriter.cpp +++ b/lib/Support/GraphWriter.cpp @@ -29,7 +29,7 @@ void llvm::DisplayGraph(const sys::Path &Filename) { args.push_back(0); cerr << "Running 'Graphviz' program... " << std::flush; - if (sys::Program::ExecuteAndWait(Graphviz, &args[0],0,0,0,&ErrMsg)) { + if (sys::Program::ExecuteAndWait(Graphviz, &args[0],0,0,0,0,&ErrMsg)) { cerr << "Error viewing graph: " << ErrMsg << "\n"; } #elif (HAVE_GV && HAVE_DOT) @@ -49,7 +49,7 @@ void llvm::DisplayGraph(const sys::Path &Filename) { args.push_back(0); cerr << "Running 'dot' program... " << std::flush; - if (sys::Program::ExecuteAndWait(dot, &args[0],0,0,0,&ErrMsg)) { + if (sys::Program::ExecuteAndWait(dot, &args[0],0,0,0,0,&ErrMsg)) { cerr << "Error viewing graph: '" << ErrMsg << "\n"; } else { cerr << " done. \n"; @@ -61,7 +61,7 @@ void llvm::DisplayGraph(const sys::Path &Filename) { args.push_back(0); ErrMsg.clear(); - if (sys::Program::ExecuteAndWait(gv, &args[0],0,0,0,&ErrMsg)) { + if (sys::Program::ExecuteAndWait(gv, &args[0],0,0,0,0,&ErrMsg)) { cerr << "Error viewing graph: " << ErrMsg << "\n"; } } @@ -74,7 +74,7 @@ void llvm::DisplayGraph(const sys::Path &Filename) { args.push_back(0); cerr << "Running 'dotty' program... " << std::flush; - if (sys::Program::ExecuteAndWait(dotty, &args[0],0,0,0,&ErrMsg)) { + if (sys::Program::ExecuteAndWait(dotty, &args[0],0,0,0,0,&ErrMsg)) { cerr << "Error viewing graph: " << ErrMsg << "\n"; } else { #ifdef __MINGW32__ // Dotty spawns another app and doesn't wait until it returns diff --git a/lib/System/Unix/Program.inc b/lib/System/Unix/Program.inc index 5961dae..77d74a1 100644 --- a/lib/System/Unix/Program.inc +++ b/lib/System/Unix/Program.inc @@ -22,6 +22,9 @@ #if HAVE_SYS_STAT_H #include <sys/stat.h> #endif +#if HAVE_SYS_RESOURCE_H +#include <sys/resource.h> +#endif #if HAVE_SIGNAL_H #include <signal.h> #endif @@ -106,12 +109,34 @@ static void TimeOutHandler(int Sig) { Timeout = true; } +static void SetMemoryLimits (unsigned size) +{ +#if HAVE_SYS_RESOURCE_H + struct rlimit r; + __typeof__ (r.rlim_cur) limit = (__typeof__ (r.rlim_cur)) (size) * 1048576; + + // Heap size + getrlimit (RLIMIT_DATA, &r); + r.rlim_cur = limit; + setrlimit (RLIMIT_DATA, &r); + // Resident set size. + getrlimit (RLIMIT_RSS, &r); + r.rlim_cur = limit; + setrlimit (RLIMIT_RSS, &r); + // Virtual memory. + getrlimit (RLIMIT_AS, &r); + r.rlim_cur = limit; + setrlimit (RLIMIT_AS, &r); +#endif +} + int Program::ExecuteAndWait(const Path& path, const char** args, const char** envp, const Path** redirects, unsigned secondsToWait, + unsigned memoryLimit, std::string* ErrMsg) { if (!path.canExecute()) { @@ -160,6 +185,11 @@ Program::ExecuteAndWait(const Path& path, } } + // Set memory limits + if (memoryLimit!=0) { + SetMemoryLimits(memoryLimit); + } + // Execute! if (envp != 0) execve (path.c_str(), (char** const)args, (char**)envp); diff --git a/lib/System/Win32/Program.inc b/lib/System/Win32/Program.inc index e1ad155..86e6d58 100644 --- a/lib/System/Win32/Program.inc +++ b/lib/System/Win32/Program.inc @@ -104,6 +104,7 @@ Program::ExecuteAndWait(const Path& path, const char** envp, const Path** redirects, unsigned secondsToWait, + unsigned memoryLimit, std::string* ErrMsg) { if (!path.canExecute()) { if (ErrMsg) |