Skip to content

Commit d016500

Browse files
Init all loaded module infos at the initialization of dataflow
Load all preloaded modules at dataflow init
1 parent f7b598c commit d016500

File tree

3 files changed

+36
-13
lines changed

3 files changed

+36
-13
lines changed

tracer/src/Datadog.Tracer.Native/cor_profiler.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,8 @@ HRESULT STDMETHODCALLTYPE CorProfiler::Initialize(IUnknown* cor_profiler_info_un
270270

271271
if (isIastEnabled || isRaspEnabled)
272272
{
273-
_dataflow = new iast::Dataflow(info_, rejit_handler, runtime_information_);
273+
auto modules = module_ids.Get();
274+
_dataflow = new iast::Dataflow(info_, rejit_handler, modules.Ref(), runtime_information_);
274275
}
275276
else
276277
{
@@ -2076,7 +2077,8 @@ int CorProfiler::RegisterIastAspects(WCHAR** aspects, int aspectsLength, UINT32
20762077
if (dataflow == nullptr && IsCallSiteManagedActivationEnabled())
20772078
{
20782079
Logger::Debug("Creating Dataflow.");
2079-
dataflow = new iast::Dataflow(info_, rejit_handler, runtime_information_);
2080+
auto modules = module_ids.Get();
2081+
dataflow = new iast::Dataflow(info_, rejit_handler, modules.Ref(), runtime_information_);
20802082
}
20812083

20822084
if (dataflow != nullptr)

tracer/src/Datadog.Tracer.Native/iast/dataflow.cpp

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ AspectFilter* ModuleAspects::GetFilter(DataflowAspectFilterValue filterValue)
158158

159159
//--------------------
160160

161-
Dataflow::Dataflow(ICorProfilerInfo* profiler, std::shared_ptr<RejitHandler> rejitHandler,
161+
Dataflow::Dataflow(ICorProfilerInfo* profiler,
162+
std::shared_ptr<RejitHandler> rejitHandler,
163+
std::vector<ModuleID> moduleIds,
162164
const RuntimeInformation& runtimeInfo) :
163165
Rejitter(rejitHandler, RejitterPriority::Low, false)
164166
{
@@ -178,7 +180,8 @@ Dataflow::Dataflow(ICorProfilerInfo* profiler, std::shared_ptr<RejitHandler> rej
178180
_profiler = nullptr;
179181
trace::Logger::Error("Dataflow::Dataflow -> Something very wrong happened, as QI on ICorProfilerInfo3 failed. Disabling Dataflow. HRESULT : ", Hex(hr));
180182
}
181-
}
183+
184+
_preLoadedModuleIds = moduleIds;
182185

183186
Dataflow::~Dataflow()
184187
{
@@ -379,6 +382,19 @@ HRESULT Dataflow::AppDomainShutdown(AppDomainID appDomainId)
379382

380383
HRESULT Dataflow::ModuleLoaded(ModuleID moduleId, ModuleInfo** pModuleInfo)
381384
{
385+
ENTER_FUNC
386+
387+
// Retrieve all already modules at once to mimic initialization from creation behavior
388+
if (_preLoadedModuleIds.size() > 0)
389+
{
390+
CSGUARD(_cs);
391+
for (auto const& id : _preLoadedModuleIds)
392+
{
393+
GetModuleInfo(id);
394+
}
395+
_preLoadedModuleIds.clear();
396+
}
397+
382398
GetModuleInfo(moduleId);
383399
return S_OK;
384400
}
@@ -526,20 +542,21 @@ ModuleInfo* Dataflow::GetModuleInfo(ModuleID id)
526542
}
527543

528544
// Retrieve module information if not found
545+
const int pathLen = 2048;
529546
LPCBYTE pbBaseLoadAddr;
530-
WCHAR wszPath[300];
531-
ULONG cchNameIn = 300;
532-
ULONG cchNameOut;
547+
ULONG pathOut;
548+
WCHAR wszName[pathLen];
549+
WCHAR wszPath[pathLen];
533550
AssemblyID assemblyId;
534551
AppDomainID appDomainId;
535552
ModuleID modIDDummy;
536-
WCHAR wszName[1024];
537553

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

552-
hr = _profiler->GetAssemblyInfo(assemblyId, 1024, nullptr, wszName, &appDomainId, &modIDDummy);
569+
pathOut = 0;
570+
hr = _profiler->GetAssemblyInfo(assemblyId, pathLen, &pathOut, wszName, &appDomainId, &modIDDummy);
553571
if (FAILED(hr))
554572
{
555-
trace::Logger::Error("Dataflow::GetModuleInfo -> GetAssemblyInfo failed for ModuleId ", id, " AssemblyId ", assemblyId);
573+
trace::Logger::Error("Dataflow::GetModuleInfo -> GetAssemblyInfo failed for ModuleId ", id, " AssemblyId ",
574+
assemblyId, " hr:", Hex(hr));
556575
_modules[id] = nullptr;
557576
return nullptr;
558577
}

tracer/src/Datadog.Tracer.Native/iast/dataflow.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,16 @@ namespace iast
5252
friend class ModuleInfo;
5353
friend class ModuleAspects;
5454
public:
55-
Dataflow(ICorProfilerInfo* profiler, std::shared_ptr<RejitHandler> rejitHandler, const RuntimeInformation& runtimeInfo);
55+
Dataflow(ICorProfilerInfo* profiler, std::shared_ptr<RejitHandler> rejitHandler, std::vector<ModuleID> moduleIds,
56+
const RuntimeInformation& runtimeInfo);
5657
virtual ~Dataflow();
5758
private:
5859
CS _cs;
5960
ICorProfilerInfo3* _profiler = nullptr;
6061
COR_PRF_RUNTIME_TYPE m_runtimeType = COR_PRF_DESKTOP_CLR;
6162
VersionInfo m_runtimeVersion = VersionInfo{4, 0, 0, 0};
6263

64+
std::vector<ModuleID> _preLoadedModuleIds;
6365
std::map<ModuleID, ModuleInfo*> _modules;
6466
std::map<AppDomainID, AppDomainInfo*> _appDomains;
6567

0 commit comments

Comments
 (0)