Skip to content

Commit 55d50c0

Browse files
committed
fix: constexpr variable change, fixed unused variables, instantiation replacement for sha256 constructor
1 parent e4f2cac commit 55d50c0

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/cli.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ struct SHA256 {
150150
u32 s[8] = {}; // from h0 to h7
151151

152152
// Initialize state to SHA-256 IVs so that compiler doesn't complain
153-
void init() {
153+
SHA256() {
154154
len = 0;
155155
bits = 0;
156156
s[0] = 0x6a09e667;
@@ -291,10 +291,11 @@ static std::string exe_path() {
291291
std::string compute_self_sha256() {
292292
std::string path = exe_path();
293293
if (path.empty()) return {};
294+
294295
std::ifstream ifs(path, std::ios::binary);
295296
if (!ifs) return {};
297+
296298
SHA256 sha;
297-
sha.init();
298299

299300
std::vector<char> chunk(64 * 1024);
300301
while (ifs) {
@@ -307,9 +308,12 @@ std::string compute_self_sha256() {
307308

308309
u8 digest[32];
309310
sha.final(digest);
310-
static const char hex[] = "0123456789abcdef";
311+
311312
std::string out;
312313
out.reserve(64);
314+
315+
static constexpr char hex[] = "0123456789abcdef";
316+
313317
for (int i = 0; i < 32; ++i) {
314318
out.push_back(hex[(digest[i] >> 4) & 0xF]);
315319
out.push_back(hex[digest[i] & 0xF]);

src/vmaware.hpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@
375375
#include <type_traits>
376376
#include <stdexcept>
377377
#include <numeric>
378+
#include <atomic>
378379

379380
#if (WINDOWS)
380381
#include <windows.h>
@@ -4661,11 +4662,15 @@ struct VM {
46614662
#endif
46624663
};
46634664

4664-
thread_local u32 aux = 0;
4665-
auto cpuid = [&](unsigned int leaf) noexcept -> u64 {
46664665
#if (MSVC)
4666+
thread_local u32 aux = 0;
4667+
#endif
4668+
4669+
auto cpuid = [&](unsigned int leaf) noexcept -> u64 {
4670+
#if (MSVC)
46674671
// make regs volatile so writes cannot be optimized out, if this isn't added and the code is compiled in release mode, cycles would be around 40 even under Hyper-V
46684672
volatile int regs[4]{};
4673+
46694674
// ensure the CPU pipeline is drained of previous loads before we start the clock
46704675
_mm_lfence();
46714676

@@ -4904,8 +4909,10 @@ struct VM {
49044909

49054910
const u64 a = t1_start.load(std::memory_order_acquire);
49064911
const u64 b = t1_end.load(std::memory_order_acquire);
4907-
const u64 c = t2_start.load(std::memory_order_acquire);
4908-
const u64 d = t2_end.load(std::memory_order_acquire);
4912+
#ifdef __VMAWARE_DEBUG__
4913+
const u64 c = t2_start.load(std::memory_order_acquire);
4914+
const u64 d = t2_end.load(std::memory_order_acquire);
4915+
#endif
49094916
const u64 acc = t2_accum.load(std::memory_order_acquire);
49104917

49114918
const u64 t1_delta = (b > a) ? (b - a) : 0;

0 commit comments

Comments
 (0)