forked from OSchip/llvm-project
Revert "[Windows] Fix limit on command line size"
This reverts commit d4020ef7c4
. It broke
LLDB buildbot: http://lab.llvm.org:8011/builders/lldb-x64-windows-ninja/builds/17702.
This commit is contained in:
parent
b9fc20ebe7
commit
ac0edc5588
|
@ -218,7 +218,7 @@ namespace sys {
|
||||||
/// to build a single flat command line appropriate for calling CreateProcess
|
/// to build a single flat command line appropriate for calling CreateProcess
|
||||||
/// on
|
/// on
|
||||||
/// Windows.
|
/// Windows.
|
||||||
ErrorOr<std::wstring> flattenWindowsCommandLine(ArrayRef<StringRef> Args);
|
std::string flattenWindowsCommandLine(ArrayRef<StringRef> Args);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -189,14 +189,7 @@ static bool Execute(ProcessInfo &PI, StringRef Program,
|
||||||
// Windows wants a command line, not an array of args, to pass to the new
|
// Windows wants a command line, not an array of args, to pass to the new
|
||||||
// process. We have to concatenate them all, while quoting the args that
|
// process. We have to concatenate them all, while quoting the args that
|
||||||
// have embedded spaces (or are empty).
|
// have embedded spaces (or are empty).
|
||||||
auto Result = flattenWindowsCommandLine(Args);
|
std::string Command = flattenWindowsCommandLine(Args);
|
||||||
if (std::error_code ec = Result.getError()) {
|
|
||||||
SetLastError(ec.value());
|
|
||||||
MakeErrMsg(ErrMsg,
|
|
||||||
std::string("Unable to convert command-line to UTF-16"));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
std::wstring Command = *Result;
|
|
||||||
|
|
||||||
// The pointer to the environment block for the new process.
|
// The pointer to the environment block for the new process.
|
||||||
std::vector<wchar_t> EnvBlock;
|
std::vector<wchar_t> EnvBlock;
|
||||||
|
@ -278,8 +271,14 @@ static bool Execute(ProcessInfo &PI, StringRef Program,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<wchar_t> CommandUtf16(Command.size() + 1, 0);
|
SmallVector<wchar_t, MAX_PATH> CommandUtf16;
|
||||||
std::copy(Command.begin(), Command.end(), CommandUtf16.begin());
|
if (std::error_code ec = windows::UTF8ToUTF16(Command, CommandUtf16)) {
|
||||||
|
SetLastError(ec.value());
|
||||||
|
MakeErrMsg(ErrMsg,
|
||||||
|
std::string("Unable to convert command-line to UTF-16"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
BOOL rc = CreateProcessW(ProgramUtf16.data(), CommandUtf16.data(), 0, 0,
|
BOOL rc = CreateProcessW(ProgramUtf16.data(), CommandUtf16.data(), 0, 0,
|
||||||
TRUE, CREATE_UNICODE_ENVIRONMENT,
|
TRUE, CREATE_UNICODE_ENVIRONMENT,
|
||||||
EnvBlock.empty() ? 0 : EnvBlock.data(), 0, &si,
|
EnvBlock.empty() ? 0 : EnvBlock.data(), 0, &si,
|
||||||
|
@ -377,7 +376,7 @@ static std::string quoteSingleArg(StringRef Arg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
ErrorOr<std::wstring> sys::flattenWindowsCommandLine(ArrayRef<StringRef> Args) {
|
std::string sys::flattenWindowsCommandLine(ArrayRef<StringRef> Args) {
|
||||||
std::string Command;
|
std::string Command;
|
||||||
for (StringRef Arg : Args) {
|
for (StringRef Arg : Args) {
|
||||||
if (argNeedsQuotes(Arg))
|
if (argNeedsQuotes(Arg))
|
||||||
|
@ -388,11 +387,7 @@ ErrorOr<std::wstring> sys::flattenWindowsCommandLine(ArrayRef<StringRef> Args) {
|
||||||
Command.push_back(' ');
|
Command.push_back(' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
SmallVector<wchar_t, MAX_PATH> CommandUtf16;
|
return Command;
|
||||||
if (std::error_code ec = windows::UTF8ToUTF16(Command, CommandUtf16))
|
|
||||||
return ec;
|
|
||||||
|
|
||||||
return std::wstring(CommandUtf16.begin(), CommandUtf16.end());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ProcessInfo sys::Wait(const ProcessInfo &PI, unsigned SecondsToWait,
|
ProcessInfo sys::Wait(const ProcessInfo &PI, unsigned SecondsToWait,
|
||||||
|
@ -537,16 +532,12 @@ llvm::sys::writeFileWithEncoding(StringRef FileName, StringRef Contents,
|
||||||
|
|
||||||
bool llvm::sys::commandLineFitsWithinSystemLimits(StringRef Program,
|
bool llvm::sys::commandLineFitsWithinSystemLimits(StringRef Program,
|
||||||
ArrayRef<StringRef> Args) {
|
ArrayRef<StringRef> Args) {
|
||||||
// The documentation on CreateProcessW states that the size of the argument
|
// The documented max length of the command line passed to CreateProcess.
|
||||||
// lpCommandLine must not be greater than 32767 characters, including the
|
static const size_t MaxCommandStringLength = 32768;
|
||||||
// Unicode terminating null character. We use smaller value to reduce risk
|
|
||||||
// of getting invalid command line due to unaccounted factors.
|
|
||||||
static const size_t MaxCommandStringLength = 32000;
|
|
||||||
SmallVector<StringRef, 8> FullArgs;
|
SmallVector<StringRef, 8> FullArgs;
|
||||||
FullArgs.push_back(Program);
|
FullArgs.push_back(Program);
|
||||||
FullArgs.append(Args.begin(), Args.end());
|
FullArgs.append(Args.begin(), Args.end());
|
||||||
auto Result = flattenWindowsCommandLine(FullArgs);
|
std::string Result = flattenWindowsCommandLine(FullArgs);
|
||||||
assert(!Result.getError());
|
return (Result.size() + 1) <= MaxCommandStringLength;
|
||||||
return (Result->size() + 1) <= MaxCommandStringLength;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -763,18 +763,6 @@ TEST(CommandLineTest, DefaultOptions) {
|
||||||
TEST(CommandLineTest, ArgumentLimit) {
|
TEST(CommandLineTest, ArgumentLimit) {
|
||||||
std::string args(32 * 4096, 'a');
|
std::string args(32 * 4096, 'a');
|
||||||
EXPECT_FALSE(llvm::sys::commandLineFitsWithinSystemLimits("cl", args.data()));
|
EXPECT_FALSE(llvm::sys::commandLineFitsWithinSystemLimits("cl", args.data()));
|
||||||
std::string args2(256, 'a');
|
|
||||||
EXPECT_TRUE(llvm::sys::commandLineFitsWithinSystemLimits("cl", args2.data()));
|
|
||||||
if (Triple(sys::getProcessTriple()).isOSWindows()) {
|
|
||||||
// We use 32000 as a limit for command line length. Program name ('cl'),
|
|
||||||
// separating spaces and termination null character occupy 5 symbols.
|
|
||||||
std::string long_arg(32000 - 5, 'b');
|
|
||||||
EXPECT_TRUE(
|
|
||||||
llvm::sys::commandLineFitsWithinSystemLimits("cl", long_arg.data()));
|
|
||||||
long_arg += 'b';
|
|
||||||
EXPECT_FALSE(
|
|
||||||
llvm::sys::commandLineFitsWithinSystemLimits("cl", long_arg.data()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(CommandLineTest, ResponseFileWindows) {
|
TEST(CommandLineTest, ResponseFileWindows) {
|
||||||
|
|
Loading…
Reference in New Issue