From 9d7bf8b0f9f723bfe5066a36b9e2c25cab659754 Mon Sep 17 00:00:00 2001 From: jyelon Date: Fri, 28 Jan 2022 12:48:59 -0500 Subject: [PATCH] Set ADDR_NO_RANDOMIZE on linux for determinism --- luprex/core/cpp/driver-common.cpp | 1 + luprex/core/cpp/driver-linux.cpp | 11 +++++++++++ luprex/core/cpp/driver-mingw.cpp | 4 ++++ luprex/core/cpp/main.cpp | 4 +--- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/luprex/core/cpp/driver-common.cpp b/luprex/core/cpp/driver-common.cpp index 4ca10a19..392d7aff 100644 --- a/luprex/core/cpp/driver-common.cpp +++ b/luprex/core/cpp/driver-common.cpp @@ -435,6 +435,7 @@ public: } void drive(DrivenEngine *de, int argc, char *argv[]) { + disable_randomization(argc, argv); socket_init(); SSL_load_error_strings(); ERR_load_crypto_strings(); diff --git a/luprex/core/cpp/driver-linux.cpp b/luprex/core/cpp/driver-linux.cpp index 2c90d9ff..c27db184 100644 --- a/luprex/core/cpp/driver-linux.cpp +++ b/luprex/core/cpp/driver-linux.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -232,6 +233,16 @@ static void fill_stdio_pollfd(PollVector &pollvec, int &mstimeout, bool read_con stdiopoll.events = POLLIN; } +static void disable_randomization(int argc, char *argv[]) { + const int old_personality = personality(ADDR_NO_RANDOMIZE); + if (!(old_personality & ADDR_NO_RANDOMIZE)) { + const int new_personality = personality(ADDR_NO_RANDOMIZE); + if (new_personality & ADDR_NO_RANDOMIZE) { + execv(argv[0], argv); + } + } +} + class MonoClock { private: struct timespec base_; diff --git a/luprex/core/cpp/driver-mingw.cpp b/luprex/core/cpp/driver-mingw.cpp index ff4ca8c5..d16e3689 100644 --- a/luprex/core/cpp/driver-mingw.cpp +++ b/luprex/core/cpp/driver-mingw.cpp @@ -252,6 +252,10 @@ static void fill_stdio_pollfd(PollVector &pollvec, int &mstimeout, bool read_con if (mstimeout > 100) mstimeout = 100; } +static void disable_randomization(int argc, char *argv[]) { + // Do nothing. +} + class MonoClock { public: double freq_; diff --git a/luprex/core/cpp/main.cpp b/luprex/core/cpp/main.cpp index 9d1a3712..2e6356c8 100644 --- a/luprex/core/cpp/main.cpp +++ b/luprex/core/cpp/main.cpp @@ -45,8 +45,6 @@ int main(int argc, char **argv) } } if (engine == nullptr) usage(); - // Remove one argument from the argument vector, - // so that it looks like a normal argument vector. - driver_drive(engine.get(), argc - 1, argv + 1); + driver_drive(engine.get(), argc, argv); }