mirror of
https://github.com/RPCSX/llvm.git
synced 2025-04-13 21:40:26 +00:00
Support: chunk writing on Linux
This is a workaround for large file writes. It has been witnessed that write(2) failing with EINVAL (22) due to a large value (>2G). Thanks to James Knight for the help with coming up with a sane test case. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@305846 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
84b3660bac
commit
ce9c73a84d
@ -449,11 +449,22 @@ bool llvm::sys::commandLineFitsWithinSystemLimits(StringRef Program, ArrayRef<co
|
|||||||
size_t ArgLength = Program.size() + 1;
|
size_t ArgLength = Program.size() + 1;
|
||||||
for (ArrayRef<const char*>::iterator I = Args.begin(), E = Args.end();
|
for (ArrayRef<const char*>::iterator I = Args.begin(), E = Args.end();
|
||||||
I != E; ++I) {
|
I != E; ++I) {
|
||||||
ArgLength += strlen(*I) + 1;
|
size_t length = strlen(*I);
|
||||||
|
|
||||||
|
// Ensure that we do not exceed the MAX_ARG_STRLEN constant on Linux, which
|
||||||
|
// does not have a constant unlike what the man pages would have you
|
||||||
|
// believe. Since this limit is pretty high, perform the check
|
||||||
|
// unconditionally rather than trying to be aggressive and limiting it to
|
||||||
|
// Linux only.
|
||||||
|
if (length >= (32 * 4096))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
ArgLength += length + 1;
|
||||||
if (ArgLength > size_t(HalfArgMax)) {
|
if (ArgLength > size_t(HalfArgMax)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -548,7 +548,11 @@ void raw_fd_ostream::write_impl(const char *Ptr, size_t Size) {
|
|||||||
pos += Size;
|
pos += Size;
|
||||||
|
|
||||||
#ifndef LLVM_ON_WIN32
|
#ifndef LLVM_ON_WIN32
|
||||||
|
#if defined(__linux__)
|
||||||
|
bool ShouldWriteInChunks = true;
|
||||||
|
#else
|
||||||
bool ShouldWriteInChunks = false;
|
bool ShouldWriteInChunks = false;
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
// Writing a large size of output to Windows console returns ENOMEM. It seems
|
// Writing a large size of output to Windows console returns ENOMEM. It seems
|
||||||
// that, prior to Windows 8, WriteFile() is redirecting to WriteConsole(), and
|
// that, prior to Windows 8, WriteFile() is redirecting to WriteConsole(), and
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include "llvm/Config/config.h"
|
#include "llvm/Config/config.h"
|
||||||
#include "llvm/Support/FileSystem.h"
|
#include "llvm/Support/FileSystem.h"
|
||||||
#include "llvm/Support/Path.h"
|
#include "llvm/Support/Path.h"
|
||||||
|
#include "llvm/Support/Program.h"
|
||||||
#include "llvm/Support/StringSaver.h"
|
#include "llvm/Support/StringSaver.h"
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
@ -546,6 +547,11 @@ TEST(CommandLineTest, GetRegisteredSubcommands) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(CommandLineTest, ArgumentLimit) {
|
||||||
|
std::string args(32 * 4096, 'a');
|
||||||
|
EXPECT_FALSE(llvm::sys::commandLineFitsWithinSystemLimits("cl", args.data()));
|
||||||
|
}
|
||||||
|
|
||||||
TEST(CommandLineTest, ResponseFiles) {
|
TEST(CommandLineTest, ResponseFiles) {
|
||||||
llvm::SmallString<128> TestDir;
|
llvm::SmallString<128> TestDir;
|
||||||
std::error_code EC =
|
std::error_code EC =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user