Skip to content
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
6 changes: 4 additions & 2 deletions tracer/src/Datadog.Tracer.Native/cor_profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ HRESULT STDMETHODCALLTYPE CorProfiler::Initialize(IUnknown* cor_profiler_info_un

if (isIastEnabled || isRaspEnabled)
{
_dataflow = new iast::Dataflow(info_, rejit_handler, runtime_information_);
auto modules = module_ids.Get();
_dataflow = new iast::Dataflow(info_, rejit_handler, modules.Ref(), runtime_information_);
}
else
{
Expand Down Expand Up @@ -2076,7 +2077,8 @@ int CorProfiler::RegisterIastAspects(WCHAR** aspects, int aspectsLength, UINT32
if (dataflow == nullptr && IsCallSiteManagedActivationEnabled())
{
Logger::Debug("Creating Dataflow.");
dataflow = new iast::Dataflow(info_, rejit_handler, runtime_information_);
auto modules = module_ids.Get();
dataflow = new iast::Dataflow(info_, rejit_handler, modules.Ref(), runtime_information_);
}

if (dataflow != nullptr)
Expand Down
41 changes: 30 additions & 11 deletions tracer/src/Datadog.Tracer.Native/iast/dataflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ AspectFilter* ModuleAspects::GetFilter(DataflowAspectFilterValue filterValue)
//--------------------

Dataflow::Dataflow(ICorProfilerInfo* profiler, std::shared_ptr<RejitHandler> rejitHandler,
const RuntimeInformation& runtimeInfo) :
std::vector<ModuleID> moduleIds, const RuntimeInformation& runtimeInfo) :
Rejitter(rejitHandler, RejitterPriority::Low, false)
{
m_runtimeType = runtimeInfo.runtime_type;
Expand All @@ -169,15 +169,20 @@ Dataflow::Dataflow(ICorProfilerInfo* profiler, std::shared_ptr<RejitHandler> rej
this->_setILOnJit = trace::IsEditAndContinueEnabled();
if (this->_setILOnJit)
{
trace::Logger::Info("Dataflow detected Edit and Continue feature (COMPLUS_ForceEnc != 0) : Enabling SetILCode in JIT event.");
trace::Logger::Info(
"Dataflow detected Edit and Continue feature (COMPLUS_ForceEnc != 0) : Enabling SetILCode in JIT event.");
}

HRESULT hr = profiler->QueryInterface(__uuidof(ICorProfilerInfo3), (void**) &_profiler);
if (FAILED(hr))
{
_profiler = nullptr;
trace::Logger::Error("Dataflow::Dataflow -> Something very wrong happened, as QI on ICorProfilerInfo3 failed. Disabling Dataflow. HRESULT : ", Hex(hr));
trace::Logger::Error("Dataflow::Dataflow -> Something very wrong happened, as QI on ICorProfilerInfo3 failed. "
"Disabling Dataflow. HRESULT : ",
Hex(hr));
}

_preLoadedModuleIds = moduleIds;
}

Dataflow::~Dataflow()
Expand Down Expand Up @@ -379,6 +384,17 @@ HRESULT Dataflow::AppDomainShutdown(AppDomainID appDomainId)

HRESULT Dataflow::ModuleLoaded(ModuleID moduleId, ModuleInfo** pModuleInfo)
{
CSGUARD(_cs);
// Retrieve all already modules at once to mimic initialization from creation behavior
if (_preLoadedModuleIds.size() > 0)
{
for (auto const& id : _preLoadedModuleIds)
{
GetModuleInfo(id);
}
_preLoadedModuleIds.clear();
}

GetModuleInfo(moduleId);
return S_OK;
}
Expand Down Expand Up @@ -526,20 +542,21 @@ ModuleInfo* Dataflow::GetModuleInfo(ModuleID id)
}

// Retrieve module information if not found
const int pathLen = 2048;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the change on the length? you had 300 before.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to erase the shadow of a buffer overrun

LPCBYTE pbBaseLoadAddr;
WCHAR wszPath[300];
ULONG cchNameIn = 300;
ULONG cchNameOut;
ULONG pathOut;
WCHAR wszName[pathLen];
WCHAR wszPath[pathLen];
AssemblyID assemblyId;
AppDomainID appDomainId;
ModuleID modIDDummy;
WCHAR wszName[1024];

DWORD dwModuleFlags;
HRESULT hr = _profiler->GetModuleInfo2(id, &pbBaseLoadAddr, cchNameIn, &cchNameOut, wszPath, &assemblyId, &dwModuleFlags);
pathOut = 0;
HRESULT hr = _profiler->GetModuleInfo2(id, &pbBaseLoadAddr, pathLen, &pathOut, wszPath, &assemblyId, &dwModuleFlags);
if (FAILED(hr))
{
trace::Logger::Error("Dataflow::GetModuleInfo -> GetModuleInfo2 failed for ModuleId ", id);
trace::Logger::Error("Dataflow::GetModuleInfo -> GetModuleInfo2 failed for ModuleId ", id, " hr:", Hex(hr));
_modules[id] = nullptr;
return nullptr;
}
Expand All @@ -549,10 +566,12 @@ ModuleInfo* Dataflow::GetModuleInfo(ModuleID id)
return nullptr;
} // Ignore any Windows Runtime modules. We cannot obtain writeable metadata interfaces on them or instrument their IL

hr = _profiler->GetAssemblyInfo(assemblyId, 1024, nullptr, wszName, &appDomainId, &modIDDummy);
pathOut = 0;
hr = _profiler->GetAssemblyInfo(assemblyId, pathLen, &pathOut, wszName, &appDomainId, &modIDDummy);
if (FAILED(hr))
{
trace::Logger::Error("Dataflow::GetModuleInfo -> GetAssemblyInfo failed for ModuleId ", id, " AssemblyId ", assemblyId);
trace::Logger::Error("Dataflow::GetModuleInfo -> GetAssemblyInfo failed for ModuleId ", id, " AssemblyId ",
assemblyId, " hr:", Hex(hr));
_modules[id] = nullptr;
return nullptr;
}
Expand Down
4 changes: 3 additions & 1 deletion tracer/src/Datadog.Tracer.Native/iast/dataflow.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@ namespace iast
friend class ModuleInfo;
friend class ModuleAspects;
public:
Dataflow(ICorProfilerInfo* profiler, std::shared_ptr<RejitHandler> rejitHandler, const RuntimeInformation& runtimeInfo);
Dataflow(ICorProfilerInfo* profiler, std::shared_ptr<RejitHandler> rejitHandler, std::vector<ModuleID> moduleIds,
const RuntimeInformation& runtimeInfo);
virtual ~Dataflow();
private:
CS _cs;
ICorProfilerInfo3* _profiler = nullptr;
COR_PRF_RUNTIME_TYPE m_runtimeType = COR_PRF_DESKTOP_CLR;
VersionInfo m_runtimeVersion = VersionInfo{4, 0, 0, 0};

std::vector<ModuleID> _preLoadedModuleIds;
std::map<ModuleID, ModuleInfo*> _modules;
std::map<AppDomainID, AppDomainInfo*> _appDomains;

Expand Down
Loading