Skip to content

Commit

Permalink
Fix mutex in PAL Events for virtual nanoCLR (#2957)
Browse files Browse the repository at this point in the history
***NO_CI***
  • Loading branch information
josesimoes committed Jun 12, 2024
1 parent 5cdd337 commit e1e8413
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 112 deletions.
30 changes: 29 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,6 @@ jobs:
- job: Run_UnitTests_mscorlib
condition: >-
and(
succeeded('Check_Code_Style'),
succeeded('Build_nanoCLR_CLI'),
ne(dependencies.Check_Build_Options.outputs['BuildOptions.SKIP_BUILD'], true),
or(
Expand Down Expand Up @@ -1284,6 +1283,35 @@ jobs:
unitTestRunsettings: '$(System.DefaultWorkingDirectory)\nf-interpreter\targets\netcore\pipeline_tests.runsettings'
packagesDirectory: '$(Build.SourcesDirectory)/CoreLibrary/packages'

- task: CopyFiles@2
condition: succeededOrFailed()
displayName: Copy vstest dump files
inputs:
SourceFolder: 'D:\a\_temp\'
Contents: '**/*.dmp'
TargetFolder: '$(Build.ArtifactStagingDirectory)/vstest_dumps'
flattenFolders: true

- powershell: |
$dumpPath = "$(Build.ArtifactStagingDirectory)/vstest_dumps"
$hasFiles = $false
if (Test-Path $dumpPath -PathType Container) {
$fileCount = (Get-ChildItem $dumpPath -File | Measure-Object).Count
$hasFiles = $fileCount -gt 0
}
echo "##vso[task.setvariable variable=hasFiles;isOutput=true]$hasFiles"
displayName: 'Check for dump files'
name: checkFiles
- task: PublishPipelineArtifact@1
condition: eq(variables['hasFiles'], 'true')
displayName: Publish vstest dump files
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)/vstest_dumps'
artifactName: VsTestCrashDumps
artifactType: pipeline

######################
# generate change log
- job: Generate_change_log
Expand Down
14 changes: 7 additions & 7 deletions src/CLR/Core/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@

#include <nanoCLR_Runtime.h>
#include <nanoCLR_Checks.h>
//#include <nanoCLR_Diagnostics.h>
// #include <nanoCLR_Diagnostics.h>
#include <nanoCLR_Hardware.h>
//#include <nanoCLR_Stream.h>
//#include <nanoCLR_Xml.h>
//#include <nanoCLR_Application.h>
// #include <nanoCLR_Stream.h>
// #include <nanoCLR_Xml.h>
#include <nanoCLR_Application.h>
//
//#include <nanoCLR_ParseOptions.h>
// #include <nanoCLR_ParseOptions.h>
//
#include <corlib_native.h>
//#include <SPOT_native.h>
//#include <SPOT_hardware_native.h>
// #include <SPOT_native.h>
// #include <SPOT_hardware_native.h>
#include <nanoCLR_Runtime__HeapBlock.h>

#endif // NANOCLR_CORE_H
1 change: 0 additions & 1 deletion src/CLR/Include/nanoCLR_Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ typedef struct CLR_SETTINGS
#if defined(VIRTUAL_DEVICE)
bool PerformGarbageCollection;
bool PerformHeapCompaction;
CLR_RT_StringVector StartArgs;
#endif

} CLR_SETTINGS;
Expand Down
47 changes: 1 addition & 46 deletions targets/netcore/nanoFramework.nanoCLR/CLRStartup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,12 @@ struct Settings

//--//

HRESULT Initialize(CLR_SETTINGS params)
HRESULT Initialize(CLR_SETTINGS const &params)
{
NANOCLR_HEADER();

m_clrOptions = params;

#if defined(PLATFORM_WINDOWS_EMULATOR)

CLR_UINT32 clockFrequencyBaseline = 27000000;
CLR_UINT32 clockFrequency = CPU_SystemClock();
double clockFrequencyRatio = 1;

if (clockFrequency > 0)
{
clockFrequencyRatio = (double)clockFrequencyBaseline / (double)clockFrequency;
}

g_HAL_Configuration_Windows.ProductType = HAL_Configuration_Windows::Product_Aux;
g_HAL_Configuration_Windows.SlowClockPerSecond = 32768;
g_HAL_Configuration_Windows.TicksPerMethodCall = (CLR_UINT64)(45.0 * clockFrequencyRatio);
g_HAL_Configuration_Windows.TicksPerOpcode = (CLR_UINT64)(5.0 * clockFrequencyRatio);
g_HAL_Configuration_Windows.GraphHeapEnabled = false;
#endif

NANOCLR_CHECK_HRESULT(CLR_RT_ExecutionEngine::CreateInstance(params));
#if !defined(BUILD_RTM)
CLR_Debug::Printf("Created EE.\r\n");
Expand Down Expand Up @@ -362,32 +344,6 @@ struct Settings
m_assemblies.clear(); // CLR_RT_ParseOptions::BufferMap m_assemblies;
}

struct Command_Call : CLR_RT_ParseOptions::Command
{
typedef HRESULT (Settings::*FPN)(CLR_RT_ParseOptions::ParameterList *params);

Settings &m_parent;
FPN m_call;

Command_Call(Settings &parent, FPN call, const wchar_t *szName, const wchar_t *szDescription)
: CLR_RT_ParseOptions::Command(szName, szDescription), m_parent(parent), m_call(call)
{
}

virtual HRESULT Execute()
{
return (m_parent.*m_call)(&m_params);
}
};

#define PARAM_GENERIC(parm1Name, parm1Desc) \
param = new CLR_RT_ParseOptions::Parameter_Generic(parm1Name, parm1Desc); \
cmd->m_params.push_back(param)
#define OPTION_CALL(fpn, optName, optDesc) \
cmd = new Command_Call(*this, &Settings::fpn, optName, optDesc); \
m_commands.push_back(cmd)
#define PARAM_EXTRACT_STRING(lst, index) ((CLR_RT_ParseOptions::Parameter_Generic *)(*lst)[index])->m_data.c_str()

HRESULT CheckAssemblyFormat(CLR_RECORD_ASSEMBLY *header, const wchar_t *src)
{
NANOCLR_HEADER();
Expand Down Expand Up @@ -564,7 +520,6 @@ void nanoCLR_SetConfigureCallback(ConfigureRuntimeCallback configureRuntimeCallb
void ClrStartup(CLR_SETTINGS params)
{
NATIVE_PROFILE_CLR_STARTUP();
// Settings settings;
ASSERT(sizeof(CLR_RT_HeapBlock_Raw) == sizeof(struct CLR_RT_HeapBlock));
bool softReboot;

Expand Down
6 changes: 2 additions & 4 deletions targets/netcore/nanoFramework.nanoCLR/nanoCLR_native.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@

#else

#pragma comment( \
lib, \
"WireProtocol.lib") // UNDONE: FIXME: SUPPORT_ComputeCRC required by TypeSystem.cpp, CLR_RT_HeapBlock
#pragma comment(lib, "WireProtocol.lib")

#pragma comment(lib, "Debugger_stub.lib")
#pragma comment(lib, "Diagnostics_stub.lib")
Expand Down Expand Up @@ -107,7 +105,7 @@ void nanoCLR_Run(NANO_CLR_SETTINGS nanoClrSettings)
BlockStorageList_InitializeDevices();

CLR_SETTINGS clrSettings;
ZeroMemory(&clrSettings, sizeof(clrSettings));
ZeroMemory(&clrSettings, sizeof(CLR_SETTINGS));

clrSettings.MaxContextSwitches = nanoClrSettings.MaxContextSwitches;
clrSettings.WaitForDebugger = nanoClrSettings.WaitForDebugger;
Expand Down
4 changes: 3 additions & 1 deletion targets/win32/Include/Win32TimerQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ class Timer
{
auto err = ::GetLastError();
if (ERROR_IO_PENDING != err)
throw std::exception("Internal error: DeleteTimerQueueTimer() FAILED!", err);
{
CLR_Debug::Printf("Internal error: DeleteTimerQueueTimer() FAILED!\r\n");
}
}
}

Expand Down
5 changes: 1 addition & 4 deletions targets/win32/nanoCLR/CLRStartup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct Settings : CLR_RT_ParseOptions

//--//

HRESULT Initialize(CLR_SETTINGS params)
HRESULT Initialize(CLR_SETTINGS const &params)
{
NANOCLR_HEADER();

Expand Down Expand Up @@ -119,8 +119,6 @@ struct Settings : CLR_RT_ParseOptions
// clear flag (in case EE wasn't restarted)
CLR_EE_DBG_CLR(StateResolutionFailed);

NANOCLR_CHECK_HRESULT(ProcessOptions(m_clrOptions.StartArgs));

#if !defined(BUILD_RTM)
CLR_Debug::Printf("Loading Assemblies.\r\n");
#endif
Expand Down Expand Up @@ -596,7 +594,6 @@ HRESULT ClrLoadDAT(const wchar_t *szDatFilePath)
void ClrStartup(CLR_SETTINGS params)
{
NATIVE_PROFILE_CLR_STARTUP();
// Settings settings;
ASSERT(sizeof(CLR_RT_HeapBlock_Raw) == sizeof(struct CLR_RT_HeapBlock));
bool softReboot;

Expand Down
8 changes: 3 additions & 5 deletions targets/win32/nanoCLR/Various.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,23 +146,21 @@ void __cdecl HAL_AddSoftRebootHandler(ON_SOFT_REBOOT_HANDLER handler)

bool g_fDoNotUninitializeDebuggerPort = false;

void __cdecl nanoHAL_Initialize(void)
void nanoHAL_Initialize(void)
{
HAL_CONTINUATION::InitializeList();
HAL_COMPLETION::InitializeList();

Events_Initialize();
}

void __cdecl nanoHAL_Uninitialize(bool isPoweringDown)
void nanoHAL_Uninitialize(bool isPoweringDown)
{
(void)isPoweringDown;

int i;

// UNDONE: FIXME: CPU_GPIO_Uninitialize();

for (i = 0; i < ARRAYSIZE(s_rebootHandlers); i++)
for (int i = 0; i < ARRAYSIZE(s_rebootHandlers); i++)
{
if (s_rebootHandlers[i] != NULL)
{
Expand Down
14 changes: 1 addition & 13 deletions targets/win32/nanoCLR/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@

#else

#pragma comment( \
lib, \
"WireProtocol.lib") // UNDONE: FIXME: SUPPORT_ComputeCRC required by TypeSystem.cpp, CLR_RT_HeapBlock
#pragma comment(lib, "WireProtocol.lib")

#pragma comment(lib, "Debugger_stub.lib")
#pragma comment(lib, "Diagnostics_stub.lib")
Expand Down Expand Up @@ -87,16 +85,6 @@ int _tmain(int argc, _TCHAR *argv[])
clrSettings.WaitForDebugger = false;
clrSettings.EnterDebuggerLoopAfterExit = false;

// fill arguments from command line
clrSettings.StartArgs.resize(argc - 1);

std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;

for (int i = 0; i < argc - 1; i++)
{
clrSettings.StartArgs[i] = converter.from_bytes(argv[1 + i]);
}

ClrStartup(clrSettings);

#if !defined(BUILD_RTM)
Expand Down
Loading

0 comments on commit e1e8413

Please sign in to comment.