Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows: compile and stability fixes #2253

Merged
merged 4 commits into from
Aug 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Builds/VisualStudio/stellar-core.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,10 @@ exit /b 0
<ClCompile Include="..\..\src\historywork\BatchDownloadWork.cpp" />
<ClCompile Include="..\..\src\herder\QuorumIntersectionCheckerImpl.cpp" />
<ClCompile Include="..\..\src\herder\test\QuorumIntersectionTests.cpp" />
<ClCompile Include="..\..\src\test\FuzzerImpl.cpp" />
<ClCompile Include="..\..\src\transactions\simulation\SimulationMergeOpFrame.cpp" />
<ClCompile Include="..\..\src\transactions\simulation\SimulationTransactionFrame.cpp" />
<ClCompile Include="..\..\src\util\FileSystemException.cpp" />
<ClCompile Include="..\..\src\work\BatchWork.cpp" />
<ClCompile Include="..\..\src\historywork\DownloadBucketsWork.cpp" />
<ClCompile Include="..\..\src\historywork\FetchRecentQsetsWork.cpp" />
Expand Down Expand Up @@ -618,6 +620,7 @@ exit /b 0
<ClInclude Include="..\..\src\historywork\BatchDownloadWork.h" />
<ClInclude Include="..\..\src\herder\QuorumIntersectionChecker.h" />
<ClInclude Include="..\..\src\herder\QuorumIntersectionCheckerImpl.h" />
<ClInclude Include="..\..\src\test\FuzzerImpl.h" />
<ClInclude Include="..\..\src\transactions\simulation\SimulationMergeOpFrame.h" />
<ClInclude Include="..\..\src\transactions\simulation\SimulationTransactionFrame.h" />
<ClInclude Include="..\..\src\work\BatchWork.h" />
Expand Down
9 changes: 9 additions & 0 deletions Builds/VisualStudio/stellar-core.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,12 @@
<ClCompile Include="..\..\src\transactions\simulation\SimulationTransactionFrame.cpp">
<Filter>transactions\simulation</Filter>
</ClCompile>
<ClCompile Include="..\..\src\test\FuzzerImpl.cpp">
<Filter>test</Filter>
</ClCompile>
<ClCompile Include="..\..\src\util\FileSystemException.cpp">
<Filter>util</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\lib\util\easylogging++.h">
Expand Down Expand Up @@ -1691,6 +1697,9 @@
<ClInclude Include="..\..\src\transactions\simulation\SimulationTransactionFrame.h">
<Filter>transactions\simulation</Filter>
</ClInclude>
<ClInclude Include="..\..\src\test\FuzzerImpl.h">
<Filter>test</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\..\AUTHORS" />
Expand Down
6 changes: 3 additions & 3 deletions src/main/CommandLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ fileNameParser(std::string& string)
}

clara::Opt
processIDParser(uint& num)
processIDParser(int& num)
{
return clara::Opt{num, "PROCESS-ID"}["--process_id"](
"for spawning multiple instances in fuzzing parallelization");
Expand Down Expand Up @@ -899,7 +899,7 @@ runFuzz(CommandLineArgs const& args)
el::Level logLevel{el::Level::Info};
std::vector<std::string> metrics;
std::string fileName;
uint processID = 0;
int processID = 0;
FuzzerMode fuzzerMode{FuzzerMode::OVERLAY};
std::string fuzzerModeArg = "overlay";

Expand All @@ -920,7 +920,7 @@ runGenFuzz(CommandLineArgs const& args)
std::string fileName;
FuzzerMode fuzzerMode{FuzzerMode::OVERLAY};
std::string fuzzerModeArg = "overlay";
uint processID = 0;
int processID = 0;

return runWithHelp(
args,
Expand Down
4 changes: 3 additions & 1 deletion src/process/ProcessManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ ProcessManagerImpl::ProcessManagerImpl(Application& app)
: mMaxProcesses(app.getConfig().MAX_CONCURRENT_SUBPROCESSES)
, mIOContext(app.getClock().getIOContext())
, mSigChild(mIOContext)
, mTmpDir(
std::make_unique<TmpDir>(app.getTmpDirManager().tmpDir("process")))
{
}

Expand Down Expand Up @@ -373,7 +375,7 @@ ProcessExitEvent::Impl::run()
cmd, // Command line
nullptr, // Process handle not inheritable
nullptr, // Thread handle not inheritable
TRUE, // Inherit file handles
FALSE, // only inherit handles from `iH`
CREATE_NEW_PROCESS_GROUP | // Create a new process group
EXTENDED_STARTUPINFO_PRESENT, // use STARTUPINFOEX
nullptr, // Use parent's environment block
Expand Down
14 changes: 8 additions & 6 deletions src/test/FuzzerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,13 @@ TransactionFuzzer::initialize()
// such that we have a pregenerated account for the last few bits of the
// 32nd byte of a public key, thus account creation is over a deterministic
// range of public keys
for (int i = 0; i < mNumAccounts; ++i)
for (unsigned int i = 0; i < mNumAccounts; ++i)
{
PublicKey publicKey;
uint256 accountID;
accountID.at(31) = i;
// NB: need to map to more bytes if we have more accounts at some point
assert(i <= std::numeric_limits<uint8_t>::max());
accountID.at(31) = static_cast<uint8_t>(i);
publicKey.ed25519() = accountID;

// manually construct ledger entries, "creating" each account
Expand Down Expand Up @@ -239,9 +241,9 @@ TransactionFuzzer::genFuzz(std::string const& filename)
out.open(filename);
autocheck::generator<Operation> gen;
xdr::xvector<Operation> ops;
auto numops =
autocheck::generator<uint>()(FUZZER_INITIAL_CORPUS_MAX_OPERATIONS);
for (int i = 0; i < numops; ++i)
auto numops = autocheck::generator<unsigned int>()(
FUZZER_INITIAL_CORPUS_MAX_OPERATIONS);
for (unsigned int i = 0; i < numops; ++i)
{
Operation op = gen(FUZZER_INITIAL_CORPUS_OPERATION_GEN_UPPERBOUND);
while (isBadTransactionFuzzerInput(op))
Expand Down Expand Up @@ -379,7 +381,7 @@ generator_t::operator()(stellar::PublicKey& t) const
// [0,NUMBER_OF_PREGENERATED_ACCOUNTS] inclusive. This allows us to generate
// some transactions with a source account/destination account that does
// not exist.
t.ed25519().at(31) = autocheck::generator<uint>()(
t.ed25519().at(31) = autocheck::generator<unsigned int>()(
stellar::FuzzUtils::NUMBER_OF_PREGENERATED_ACCOUNTS);
}
} // namespace xdr
Expand Down
8 changes: 4 additions & 4 deletions src/test/FuzzerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct Operation;
class TransactionFuzzer : public Fuzzer
{
public:
TransactionFuzzer(int numAccounts, int processID)
TransactionFuzzer(unsigned int numAccounts, int processID)
: mNumAccounts(numAccounts), mProcessID(processID)
{
}
Expand All @@ -31,14 +31,14 @@ class TransactionFuzzer : public Fuzzer
private:
std::shared_ptr<Application> mApp;
PublicKey mSourceAccountID;
int mNumAccounts;
unsigned int mNumAccounts;
int mProcessID;
};

class OverlayFuzzer : public Fuzzer
{
const uint ACCEPTOR_INDEX = 0;
const uint INITIATOR_INDEX = 1;
const int ACCEPTOR_INDEX = 0;
const int INITIATOR_INDEX = 1;

public:
OverlayFuzzer()
Expand Down
6 changes: 5 additions & 1 deletion src/test/fuzz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ namespace stellar

namespace FuzzUtils
{
unsigned int const NUMBER_OF_PREGENERATED_ACCOUNTS = 16;

std::unique_ptr<Fuzzer>
createFuzzer(int processID, FuzzerMode fuzzerMode)
{
Expand All @@ -41,14 +43,16 @@ createFuzzer(int processID, FuzzerMode fuzzerMode)
case FuzzerMode::TRANSACTION:
return std::make_unique<TransactionFuzzer>(
NUMBER_OF_PREGENERATED_ACCOUNTS, processID);
default:
abort();
}
}
}

#define PERSIST_MAX 1000000
void
fuzz(std::string const& filename, el::Level logLevel,
std::vector<std::string> const& metrics, uint processID,
std::vector<std::string> const& metrics, int processID,
FuzzerMode fuzzerMode)
{
auto fuzzer = FuzzUtils::createFuzzer(processID, fuzzerMode);
Expand Down
4 changes: 2 additions & 2 deletions src/test/fuzz.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ enum class FuzzerMode

namespace FuzzUtils
{
static auto const NUMBER_OF_PREGENERATED_ACCOUNTS = 16;
extern unsigned int const NUMBER_OF_PREGENERATED_ACCOUNTS;
std::unique_ptr<Fuzzer> createFuzzer(int processID, FuzzerMode fuzzerMode);
}

void fuzz(std::string const& filename, el::Level logLevel,
std::vector<std::string> const& metrics, uint processID,
std::vector<std::string> const& metrics, int processID,
FuzzerMode fuzzerMode);
}
45 changes: 45 additions & 0 deletions src/util/FileSystemException.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#pragma once

// Copyright 2019 Stellar Development Foundation and contributors. Licensed
// under the Apache License, Version 2.0. See the COPYING file at the root
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0

#include "FileSystemException.h"
#include "util/format.h"

namespace stellar
{

#ifdef _WIN32

static std::string
getLastErrorString()
{
std::string res;

DWORD constexpr bufSize = 512;
char buf[bufSize + 1];
DWORD dw = ::GetLastError();

DWORD sz = ::FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, dw, 0, (LPTSTR)buf, bufSize, NULL);
if (sz == 0)
{
res = fmt::format("Error code {}", dw);
}
else
{
buf[sz] = 0;
res = std::string(buf);
}
return res;
}

void
FileSystemException::failWithGetLastError(std::string msg)
{
failWith(msg + ", " + getLastErrorString());
}
#endif
}
6 changes: 1 addition & 5 deletions src/util/FileSystemException.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ class FileSystemException : public std::runtime_error
failWith(msg + std::strerror(errno));
}
#ifdef _WIN32
static void
failWithGetLastError(std::string msg)
{
failWith(msg + ", code " + std::to_string(GetLastError()));
}
static void failWithGetLastError(std::string msg);
#endif // _WIN32
explicit FileSystemException(std::string const& msg)
: std::runtime_error{msg}
Expand Down