Skip to content

Commit

Permalink
Replace custom semaphore with stdlib variant
Browse files Browse the repository at this point in the history
  • Loading branch information
Dorian Eikenberg committed Feb 28, 2024
1 parent 847be20 commit 5f0f485
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
4 changes: 2 additions & 2 deletions plugins/inmemoryscanner/src/lib/Scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ namespace InMemoryScanner

// The semaphore protects the yara rules from being accessed more than YR_MAX_THREADS (32 atm.) times in
// parallel.
semaphore.wait();
semaphore.acquire();
auto results = yaraInterface->scanMemory(memoryRegionDescriptor.base, mappedRegions);
semaphore.notify();
semaphore.release();

logger->debug("End scanMemory");

Expand Down
6 changes: 2 additions & 4 deletions plugins/inmemoryscanner/src/lib/Scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
#include "Dumping.h"
#include "IYaraInterface.h"
#include "OutputXML.h"
#include "Semaphore.h"
#include <condition_variable>
#include <memory>
#include <semaphore>
#include <span>
#include <vmicore/plugins/PluginInterface.h>
#include <yara/limits.h> // NOLINT(modernize-deprecated-headers)
Expand Down Expand Up @@ -37,8 +36,7 @@ namespace InMemoryScanner
std::unique_ptr<IDumping> dumping;
std::unique_ptr<VmiCore::ILogger> logger;
std::unique_ptr<VmiCore::ILogger> inMemResultsLogger;
Semaphore<std::mutex, std::condition_variable> semaphore =
Semaphore<std::mutex, std::condition_variable>(YR_MAX_THREADS);
std::counting_semaphore<> semaphore{YR_MAX_THREADS};

[[nodiscard]] bool shouldRegionBeScanned(const VmiCore::MemoryRegion& memoryRegionDescriptor);

Expand Down

0 comments on commit 5f0f485

Please sign in to comment.