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 | d01defedf6fb29fd939cd04544f1a4df863c5b1a (patch) | |
tree | 733a2dc8defcffee4d3f267bfee7926ae8789a36 /llvm/lib/System/Unix | |
parent | 66cb162f92c156717c7800dbc9d636cc57ec15ab (diff) | |
download | bcm5719-llvm-d01defedf6fb29fd939cd04544f1a4df863c5b1a.tar.gz bcm5719-llvm-d01defedf6fb29fd939cd04544f1a4df863c5b1a.zip |
Add possibility to set memory limit for binaries run via libSystem. This
is especially needed for bugpoint. This partly implements PR688
llvm-svn: 34349
Diffstat (limited to 'llvm/lib/System/Unix')
-rw-r--r-- | llvm/lib/System/Unix/Program.inc | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/llvm/lib/System/Unix/Program.inc b/llvm/lib/System/Unix/Program.inc index 5961dae5ad0..77d74a18c67 100644 --- a/llvm/lib/System/Unix/Program.inc +++ b/llvm/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); |