Skip to content

Commit 08422af

Browse files
committed
Fix for IBC profile data on Linux - Build the full command line for FEATURE_PAL
Added public static function GetManagedCommandLine() andSaveManagedCommandLine() Add helper method Append_Next_Item Moved GetManagedCommandLine and SaveManagedCommandLine to ceeload to link crossgen Cleanup, codereview feedback
1 parent 58a26df commit 08422af

File tree

6 files changed

+101
-68
lines changed

6 files changed

+101
-68
lines changed

src/vm/ceeload.cpp

Lines changed: 88 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@
7474
#include "peimagelayout.inl"
7575
#include "ildbsymlib.h"
7676

77-
7877
#if defined(PROFILING_SUPPORTED)
7978
#include "profilermetadataemitvalidator.h"
8079
#endif
@@ -11653,6 +11652,91 @@ static bool GetBasename(LPCWSTR _src, __out_ecount(dstlen) __out_z LPWSTR _dst,
1165311652
return true;
1165411653
}
1165511654

11655+
static LPCWSTR s_pCommandLine = NULL;
11656+
11657+
// Rerieve the full command line for the current process.
11658+
LPCWSTR GetManagedCommandLine()
11659+
{
11660+
LIMITED_METHOD_CONTRACT;
11661+
return s_pCommandLine;
11662+
}
11663+
11664+
void Append_Next_Item(LPWSTR* ppCursor, SIZE_T* pRemainingLen, LPCWSTR pItem, bool addSpace)
11665+
{
11666+
// read the writeback args and setup pCursor and remainingLen
11667+
LPWSTR pCursor = *ppCursor;
11668+
SIZE_T remainingLen = *pRemainingLen;
11669+
11670+
// Calculate the length of pItem
11671+
SIZE_T itemLen = wcslen(pItem);
11672+
11673+
// Append pItem at pCursor
11674+
wcscpy_s(pCursor, remainingLen, pItem);
11675+
pCursor += itemLen;
11676+
remainingLen -= itemLen;
11677+
11678+
// Also append a space after pItem, if requested
11679+
if (addSpace)
11680+
{
11681+
// Append a space at pCursor
11682+
wcscpy_s(pCursor, remainingLen, W(" "));
11683+
pCursor += 1;
11684+
remainingLen -= 1;
11685+
}
11686+
11687+
// writeback and update ppCursor and pRemainingLen
11688+
*ppCursor = pCursor;
11689+
*pRemainingLen = remainingLen;
11690+
}
11691+
11692+
void SaveManagedCommandLine(LPCWSTR pwzAssemblyPath, int argc, LPCWSTR *argv)
11693+
{
11694+
CONTRACTL
11695+
{
11696+
NOTHROW;
11697+
GC_NOTRIGGER;
11698+
MODE_ANY;
11699+
}
11700+
CONTRACTL_END;
11701+
11702+
// Get the command line.
11703+
LPCWSTR osCommandLine = GetCommandLineW();
11704+
11705+
#ifndef FEATURE_PAL
11706+
// On Windows, osCommandLine contains the executable and all arguments.
11707+
s_pCommandLine = osCommandLine;
11708+
#else
11709+
// On UNIX, the PAL doesn't have the command line arguments, so we must build the command line.
11710+
// osCommandLine contains the full path to the executable.
11711+
SIZE_T commandLineLen = (wcslen(osCommandLine) + 1);
11712+
11713+
// We will append pwzAssemblyPath to the 'corerun' osCommandLine
11714+
commandLineLen += (wcslen(pwzAssemblyPath) + 1);
11715+
11716+
for (int i = 0; i < argc; i++)
11717+
{
11718+
commandLineLen += (wcslen(argv[i]) + 1);
11719+
}
11720+
commandLineLen++; // Add 1 for the null-termination
11721+
11722+
// Allocate a new string for the command line.
11723+
LPWSTR pNewCommandLine = new WCHAR[commandLineLen];
11724+
SIZE_T remainingLen = commandLineLen;
11725+
LPWSTR pCursor = pNewCommandLine;
11726+
11727+
Append_Next_Item(&pCursor, &remainingLen, osCommandLine, true);
11728+
Append_Next_Item(&pCursor, &remainingLen, pwzAssemblyPath, true);
11729+
11730+
for (int i = 0; i < argc; i++)
11731+
{
11732+
bool moreArgs = (i < (argc-1));
11733+
Append_Next_Item(&pCursor, &remainingLen, argv[i], moreArgs);
11734+
}
11735+
11736+
s_pCommandLine = pNewCommandLine;
11737+
#endif
11738+
}
11739+
1165611740
static void ProfileDataAllocateScenarioInfo(ProfileEmitter * pEmitter, LPCSTR scopeName, GUID* pMvid)
1165711741
{
1165811742
CONTRACTL
@@ -11681,7 +11765,9 @@ static void ProfileDataAllocateScenarioInfo(ProfileEmitter * pEmitter, LPCSTR sc
1168111765
// Allocate and initialize the scenario header section
1168211766
//
1168311767
{
11684-
LPCWSTR pCmdLine = GetCommandLineW();
11768+
// Get the managed command line.
11769+
LPCWSTR pCmdLine = GetManagedCommandLine();
11770+
1168511771
S_SIZE_T cCmdLine = S_SIZE_T(wcslen(pCmdLine));
1168611772
cCmdLine += 1;
1168711773
if (cCmdLine.IsOverflow())

src/vm/ceeload.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3419,4 +3419,9 @@ struct VASigCookieEx : public VASigCookie
34193419
const BYTE *m_pArgs; // pointer to first unfixed unmanaged arg
34203420
};
34213421

3422+
// Rerieve the full command line for the current process.
3423+
LPCWSTR GetManagedCommandLine();
3424+
// Save the command line for the current process.
3425+
void SaveManagedCommandLine(LPCWSTR pwzAssemblyPath, int argc, LPCWSTR *argv);
3426+
34223427
#endif // !CEELOAD_H_

src/vm/ceemain.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -770,8 +770,9 @@ void EEStartupHelper(COINITIEE fFlags)
770770

771771
#ifndef CROSSGEN_COMPILE
772772

773-
774-
#ifdef FEATURE_PREJIT
773+
// Cross-process named objects are not supported in PAL
774+
// (see CorUnix::InternalCreateEvent - src/pal/src/synchobj/event.cpp.272)
775+
#if defined(FEATURE_PREJIT) && !defined(FEATURE_PAL)
775776
// Initialize the sweeper thread.
776777
if (g_pConfig->GetZapBBInstr() != NULL)
777778
{
@@ -785,7 +786,7 @@ void EEStartupHelper(COINITIEE fFlags)
785786
_ASSERTE(hBBSweepThread);
786787
g_BBSweep.SetBBSweepThreadHandle(hBBSweepThread);
787788
}
788-
#endif // FEATURE_PREJIT
789+
#endif // FEATURE_PREJIT && FEATURE_PAL
789790

790791
#ifdef FEATURE_INTERPRETER
791792
Interpreter::Initialize();
@@ -2604,7 +2605,6 @@ INT32 GetLatchedExitCode (void)
26042605
return LatchedExitCode;
26052606
}
26062607

2607-
26082608
// ---------------------------------------------------------------------------
26092609
// Impl for UtilLoadStringRC Callback: In VM, we let the thread decide culture
26102610
// Return an int uniquely describing which language this thread is using for ui.

src/vm/corhost.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@
3939
#include "dwreport.h"
4040
#endif // !FEATURE_PAL
4141

42-
#include "stringarraylist.h"
43-
#ifdef FEATURE_PERFTRACING
44-
#include "eventpipe.h"
45-
#endif // FEATURE_PERFTRACING
46-
4742
#ifdef FEATURE_COMINTEROP
4843
#include "winrttypenameconverter.h"
4944
#endif
@@ -343,10 +338,8 @@ void SetCommandLineArgs(LPCWSTR pwzAssemblyPath, int argc, LPCWSTR* argv)
343338
}
344339
CONTRACTL_END;
345340

346-
// Send the command line to EventPipe.
347-
#ifdef FEATURE_PERFTRACING
348-
EventPipe::SaveCommandLine(pwzAssemblyPath, argc, argv);
349-
#endif // FEATURE_PERFTRACING
341+
// Record the command line.
342+
SaveManagedCommandLine(pwzAssemblyPath, argc, argv);
350343

351344
// Send the command line to System.Environment.
352345
struct _gc

src/vm/eventpipe.cpp

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "eventtracebase.h"
2020
#include "sampleprofiler.h"
2121
#include "win32threadpool.h"
22+
#include "ceemain.h"
2223

2324
#ifdef FEATURE_PAL
2425
#include "pal.h"
@@ -33,7 +34,6 @@ EventPipeSession *EventPipe::s_pSession = NULL;
3334
EventPipeBufferManager *EventPipe::s_pBufferManager = NULL;
3435
EventPipeFile *EventPipe::s_pFile = NULL;
3536
EventPipeEventSource *EventPipe::s_pEventSource = NULL;
36-
LPCWSTR EventPipe::s_pCommandLine = NULL;
3737
HANDLE EventPipe::s_fileSwitchTimerHandle = NULL;
3838
ULONGLONG EventPipe::s_lastFlushSwitchTime = 0;
3939

@@ -223,12 +223,6 @@ void EventPipe::Shutdown()
223223
delete s_pEventSource;
224224
s_pEventSource = NULL;
225225

226-
// On Windows, this is just a pointer to the return value from
227-
// GetCommandLineW(), so don't attempt to free it.
228-
#ifdef FEATURE_PAL
229-
delete[] s_pCommandLine;
230-
s_pCommandLine = NULL;
231-
#endif
232226
}
233227

234228
EventPipeSessionID EventPipe::Enable(
@@ -393,7 +387,7 @@ void EventPipe::DisableInternal(EventPipeSessionID id, EventPipeProviderCallback
393387
SampleProfiler::Disable();
394388

395389
// Log the process information event.
396-
s_pEventSource->SendProcessInfo(s_pCommandLine);
390+
s_pEventSource->SendProcessInfo(GetManagedCommandLine());
397391

398392
// Log the runtime information event.
399393
ETW::InfoLog::RuntimeInformation(ETW::InfoLog::InfoStructs::Normal);
@@ -914,47 +908,6 @@ StackWalkAction EventPipe::StackWalkCallback(CrawlFrame *pCf, StackContents *pDa
914908
return SWA_CONTINUE;
915909
}
916910

917-
void EventPipe::SaveCommandLine(LPCWSTR pwzAssemblyPath, int argc, LPCWSTR *argv)
918-
{
919-
CONTRACTL
920-
{
921-
THROWS;
922-
GC_TRIGGERS;
923-
MODE_COOPERATIVE;
924-
PRECONDITION(pwzAssemblyPath != NULL);
925-
PRECONDITION(argc <= 0 || argv != NULL);
926-
}
927-
CONTRACTL_END;
928-
929-
// Get the command line.
930-
LPCWSTR osCommandLine = GetCommandLineW();
931-
932-
#ifndef FEATURE_PAL
933-
// On Windows, osCommandLine contains the executable and all arguments.
934-
s_pCommandLine = osCommandLine;
935-
#else
936-
// On UNIX, the PAL doesn't have the command line arguments, so we must build the command line.
937-
// osCommandLine contains the full path to the executable.
938-
SString commandLine(osCommandLine);
939-
commandLine.Append((WCHAR)' ');
940-
commandLine.Append(pwzAssemblyPath);
941-
942-
for (int i = 0; i < argc; i++)
943-
{
944-
commandLine.Append((WCHAR)' ');
945-
commandLine.Append(argv[i]);
946-
}
947-
948-
// Allocate a new string for the command line.
949-
SIZE_T commandLineLen = commandLine.GetCount();
950-
WCHAR *pCommandLine = new WCHAR[commandLineLen + 1];
951-
wcsncpy(pCommandLine, commandLine.GetUnicode(), commandLineLen);
952-
pCommandLine[commandLineLen] = '\0';
953-
954-
s_pCommandLine = pCommandLine;
955-
#endif
956-
}
957-
958911
EventPipeEventInstance *EventPipe::GetNextEvent()
959912
{
960913
CONTRACTL

src/vm/eventpipe.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,6 @@ class EventPipe
299299
// Get the managed call stack for the specified thread.
300300
static bool WalkManagedStackForThread(Thread *pThread, StackContents &stackContents);
301301

302-
// Save the command line for the current process.
303-
static void SaveCommandLine(LPCWSTR pwzAssemblyPath, int argc, LPCWSTR *argv);
304-
305302
// Get next event.
306303
static EventPipeEventInstance *GetNextEvent();
307304

@@ -350,7 +347,6 @@ class EventPipe
350347
static EventPipeBufferManager *s_pBufferManager;
351348
static EventPipeFile *s_pFile;
352349
static EventPipeEventSource *s_pEventSource;
353-
static LPCWSTR s_pCommandLine;
354350
static HANDLE s_fileSwitchTimerHandle;
355351
static ULONGLONG s_lastFlushSwitchTime;
356352
};

0 commit comments

Comments
 (0)