From 7db379458e1fdefd05327fe7a50a979412e94b9a Mon Sep 17 00:00:00 2001 From: Charles Betros Date: Tue, 3 Nov 2015 14:17:57 -0600 Subject: [PATCH 1/5] Revert the FAT test kernel. --- Tests/Cosmos.Kernel.Tests.Fat/Kernel.cs | 166 ++++++++++-------------- 1 file changed, 65 insertions(+), 101 deletions(-) diff --git a/Tests/Cosmos.Kernel.Tests.Fat/Kernel.cs b/Tests/Cosmos.Kernel.Tests.Fat/Kernel.cs index bd1d53ee3..f12f06055 100644 --- a/Tests/Cosmos.Kernel.Tests.Fat/Kernel.cs +++ b/Tests/Cosmos.Kernel.Tests.Fat/Kernel.cs @@ -9,40 +9,6 @@ using Sys = Cosmos.System; namespace Cosmos.Kernel.Tests.Fat { - public class TestClass - { - private Stream xStream; - private static global::Cosmos.Debug.Kernel.Debugger mDebugger = new global::Cosmos.Debug.Kernel.Debugger("User", "Test"); - - public TestClass(string aTest) - { - // throw new Exception("Test can not be null."); - //throw new Exception(); - - //mDebugger.Send("In TestClass::ctor(string)"); - Console.WriteLine("Before Initialize"); - xStream = Initialize(aTest); - } - - private Stream Initialize(string aTest) - { - //mDebugger.Send("In TestClass::Intialize(string)"); - if (aTest == null) - { - // mDebugger.Send("In TestClass::Intialize(string). aTest is null."); - throw new ArgumentNullException("aTest", "Test can not be null."); - } - - //if (aTest.Length == 0) - //{ - // mDebugger.Send("In TestClass::Intialize(string). aTest is empty."); - // throw new ArgumentException("Test can not be empty."); - //} - - return Stream.Null; - } - } - public class Kernel : Sys.Kernel { private VFSBase myVFS; @@ -50,8 +16,8 @@ namespace Cosmos.Kernel.Tests.Fat protected override void BeforeRun() { Console.WriteLine("Cosmos booted successfully, now start testing"); - //myVFS = new Sys.SentinelVFS(); - //VFSManager.RegisterVFS(myVFS); + myVFS = new Sys.SentinelVFS(); + VFSManager.RegisterVFS(myVFS); } private global::Cosmos.Debug.Kernel.Debugger mDebugger = new global::Cosmos.Debug.Kernel.Debugger("User", "Test"); @@ -62,82 +28,80 @@ namespace Cosmos.Kernel.Tests.Fat { mDebugger.Send("Run"); - string xString = null; - var x = new TestClass(xString); - //var x = new TestClass(); - //string xContents; - //Assert.IsTrue(Path.GetDirectoryName(@"0:\test") == @"0:\", @"Path.GetDirectoryName(@'0:\test') == @'0:\'"); - //Assert.IsTrue(Path.GetFileName(@"0:\test") == @"test", @"Path.GetFileName(@'0:\test') == @'test'"); + bool xTest; + string xContents; + Assert.IsTrue(Path.GetDirectoryName(@"0:\test") == @"0:\", @"Path.GetDirectoryName(@'0:\test') == @'0:\'"); + Assert.IsTrue(Path.GetFileName(@"0:\test") == @"test", @"Path.GetFileName(@'0:\test') == @'test'"); - //mDebugger.Send("File exist check:"); - //xTest = File.Exists(@"0:\Kudzu.txt"); - //Assert.IsTrue(xTest, @"\Kudzu.txt not found!"); + mDebugger.Send("File exist check:"); + xTest = File.Exists(@"0:\Kudzu.txt"); + Assert.IsTrue(xTest, @"\Kudzu.txt not found!"); - //mDebugger.Send("Directory exist check:"); - //xTest = Directory.Exists(@"0:\test"); - //Console.WriteLine("After test"); - //Assert.IsTrue(xTest, "Folder does not exist!"); + mDebugger.Send("Directory exist check:"); + xTest = Directory.Exists(@"0:\test"); + Console.WriteLine("After test"); + Assert.IsTrue(xTest, "Folder does not exist!"); - //mDebugger.Send("File contents of Kudzu.txt: "); - //xContents = File.ReadAllText(@"0:\Kudzu.txt"); - //mDebugger.Send("Contents retrieved"); - //mDebugger.Send(xContents); - //Assert.IsTrue(xContents == "Hello Cosmos", "Contents of Kudzu.txt was read incorrectly!"); + mDebugger.Send("File contents of Kudzu.txt: "); + xContents = File.ReadAllText(@"0:\Kudzu.txt"); + mDebugger.Send("Contents retrieved"); + mDebugger.Send(xContents); + Assert.IsTrue(xContents == "Hello Cosmos", "Contents of Kudzu.txt was read incorrectly!"); - // Test if null or empty string throws exception. - //try - //{ - // using (var xFS = new FileStream(null, FileMode.Open)) - // { - // xFS.SetLength(5); - // } - //} - //catch (Exception ex) - //{ - // mDebugger.Send("Exception occurred:" + ex.Message); - //} + //Test if null or empty string throws exception. + try + { + using (var xFS = new FileStream(null, FileMode.Open)) + { + xFS.SetLength(5); + } + } + catch (Exception ex) + { + mDebugger.Send("Exception occurred:" + ex.Message); + } - //using (var xFS = new FileStream(@"0:\Kudzu.txt", FileMode.Open)) - //{ - // xFS.SetLength(5); - //} - //mDebugger.Send("File made smaller"); - //xContents = File.ReadAllText(@"0:\Kudzu.txt"); - //mDebugger.Send("Contents retrieved"); - //mDebugger.Send(xContents); - //Assert.IsTrue(xContents == "Hello", "Contents of Kudzu.txt was read incorrectly!"); + using (var xFS = new FileStream(@"0:\Kudzu.txt", FileMode.Open)) + { + xFS.SetLength(5); + } + mDebugger.Send("File made smaller"); + xContents = File.ReadAllText(@"0:\Kudzu.txt"); + mDebugger.Send("Contents retrieved"); + mDebugger.Send(xContents); + Assert.IsTrue(xContents == "Hello", "Contents of Kudzu.txt was read incorrectly!"); + + using (var xFS = new FileStream(@"0:\Kudzu.txt", FileMode.Create)) + { + xFS.SetLength(5); + } + mDebugger.Send("File made smaller"); + xContents = File.ReadAllText(@"0:\Kudzu.txt"); + mDebugger.Send("Contents retrieved"); + mDebugger.Send(xContents); + Assert.IsTrue(xContents == "Hello", "Contents of Kudzu.txt was read incorrectly!"); //using (var xFS = new FileStream(@"0:\Kudzu.txt", FileMode.Create)) //{ - // xFS.SetLength(5); + // mDebugger.Send("Start writing"); + // var xStr = "Test FAT Write."; + // var xBuff = xStr.GetUtf8Bytes(0, (uint) xStr.Length); + // xFS.Write(xBuff, 0, xBuff.Length); + // mDebugger.Send("---- Data written"); + // xFS.Position = 0; + // xFS.Read(xBuff, 0, xBuff.Length); + // mDebugger.Send(xBuff.GetUtf8String(0, (uint)xBuff.Length)); //} - //mDebugger.Send("File made smaller"); + + + //mDebugger.Send("Write to file now"); + //File.WriteAllText(@"0:\Kudzu.txt", "Test FAT write."); + //mDebugger.Send("Text written"); //xContents = File.ReadAllText(@"0:\Kudzu.txt"); - //mDebugger.Send("Contents retrieved"); + + //mDebugger.Send("Contents retrieved after writing"); //mDebugger.Send(xContents); - //Assert.IsTrue(xContents == "Hello", "Contents of Kudzu.txt was read incorrectly!"); - - ////using (var xFS = new FileStream(@"0:\Kudzu.txt", FileMode.Create)) - ////{ - //// mDebugger.Send("Start writing"); - //// var xStr = "Test FAT Write."; - //// var xBuff = xStr.GetUtf8Bytes(0, (uint) xStr.Length); - //// xFS.Write(xBuff, 0, xBuff.Length); - //// mDebugger.Send("---- Data written"); - //// xFS.Position = 0; - //// xFS.Read(xBuff, 0, xBuff.Length); - //// mDebugger.Send(xBuff.GetUtf8String(0, (uint)xBuff.Length)); - ////} - - - ////mDebugger.Send("Write to file now"); - ////File.WriteAllText(@"0:\Kudzu.txt", "Test FAT write."); - ////mDebugger.Send("Text written"); - ////xContents = File.ReadAllText(@"0:\Kudzu.txt"); - - ////mDebugger.Send("Contents retrieved after writing"); - ////mDebugger.Send(xContents); - ////Assert.IsTrue(xContents == "Test FAT write.", "Contents of Kudzu.txt was written incorrectly!"); + //Assert.IsTrue(xContents == "Test FAT write.", "Contents of Kudzu.txt was written incorrectly!"); TestController.Completed(); } From c746643255472bd1dc7f11677b7cea31f91d649d Mon Sep 17 00:00:00 2001 From: Charles Betros Date: Wed, 4 Nov 2015 22:26:38 -0600 Subject: [PATCH 2/5] These were removed somehow? --- source/Cosmos.System.Plugs/System/IO/DirectoryInfoImpl.cs | 4 ++-- source/Cosmos.System.Plugs/System/IO/DriveInfoImpl.cs | 2 +- source/Cosmos.System.Plugs/System/IO/FileImpl.cs | 2 +- source/Cosmos.System.Plugs/System/IO/FileStreamImpl.cs | 4 ++-- source/Cosmos.System.Plugs/System/IO/PathImpl.cs | 5 +++-- source/Cosmos.System.Plugs/System/IO/StreamReaderImpl.cs | 4 +--- 6 files changed, 10 insertions(+), 11 deletions(-) diff --git a/source/Cosmos.System.Plugs/System/IO/DirectoryInfoImpl.cs b/source/Cosmos.System.Plugs/System/IO/DirectoryInfoImpl.cs index 10db1c9a5..124d63ce5 100644 --- a/source/Cosmos.System.Plugs/System/IO/DirectoryInfoImpl.cs +++ b/source/Cosmos.System.Plugs/System/IO/DirectoryInfoImpl.cs @@ -8,7 +8,7 @@ using Directory = Cosmos.System.FileSystem.Listing.Directory; namespace SentinelKernel.System.Plugs.System.IO { - [Plug(Target=typeof(DirectoryInfo))] + [Plug(Target = typeof(DirectoryInfo))] [PlugField(FieldId = "$$Storage$$", FieldType = typeof(Directory))] [PlugField(FieldId = "$$FullPath$$", FieldType = typeof(string))] public static class DirectoryInfoImpl @@ -77,7 +77,7 @@ namespace SentinelKernel.System.Plugs.System.IO //} //return files; - */ + */ } public static string ToString([FieldAccess(Name = "$$Path$$")] ref string aPath) diff --git a/source/Cosmos.System.Plugs/System/IO/DriveInfoImpl.cs b/source/Cosmos.System.Plugs/System/IO/DriveInfoImpl.cs index dac96c38c..134d1f4bf 100644 --- a/source/Cosmos.System.Plugs/System/IO/DriveInfoImpl.cs +++ b/source/Cosmos.System.Plugs/System/IO/DriveInfoImpl.cs @@ -13,7 +13,7 @@ namespace SentinelKernel.System.Plugs.System.IO [PlugMethod(Signature = "System_Void__System_IO_DriveInfo__ctor_System_String_")] public static void Ctor(DriveInfo aThis, string aDriveName) { - + } public static string get_DriveFormat(ref DriveInfo aThis) diff --git a/source/Cosmos.System.Plugs/System/IO/FileImpl.cs b/source/Cosmos.System.Plugs/System/IO/FileImpl.cs index 640a6ca22..3002f4960 100644 --- a/source/Cosmos.System.Plugs/System/IO/FileImpl.cs +++ b/source/Cosmos.System.Plugs/System/IO/FileImpl.cs @@ -40,7 +40,7 @@ namespace SentinelKernel.System.Plugs.System.IO { using (var xFS = new FileStream(aFile, FileMode.Create)) { - var xBuff = aText.GetUtf8Bytes(0, (uint) aText.Length); + var xBuff = aText.GetUtf8Bytes(0, (uint)aText.Length); xFS.Write(xBuff, 0, xBuff.Length); } } diff --git a/source/Cosmos.System.Plugs/System/IO/FileStreamImpl.cs b/source/Cosmos.System.Plugs/System/IO/FileStreamImpl.cs index 25b5c9e05..ee4fc9a62 100644 --- a/source/Cosmos.System.Plugs/System/IO/FileStreamImpl.cs +++ b/source/Cosmos.System.Plugs/System/IO/FileStreamImpl.cs @@ -11,8 +11,8 @@ namespace SentinelKernel.System.Plugs.System.IO { using Cosmos.System.FileSystem; - [Plug(Target = typeof (IO::FileStream))] - [PlugField(FieldId = "$$InnerStream$$", FieldType = typeof (IO::Stream))] + [Plug(Target = typeof(IO::FileStream))] + [PlugField(FieldId = "$$InnerStream$$", FieldType = typeof(IO::Stream))] public class FileStreamImpl { // This plug basically forwards all calls to the $$InnerStream$$ stream, which is supplied by the file system. diff --git a/source/Cosmos.System.Plugs/System/IO/PathImpl.cs b/source/Cosmos.System.Plugs/System/IO/PathImpl.cs index 476934431..2226a0671 100644 --- a/source/Cosmos.System.Plugs/System/IO/PathImpl.cs +++ b/source/Cosmos.System.Plugs/System/IO/PathImpl.cs @@ -9,8 +9,9 @@ using Cosmos.System.FileSystem.VFS; namespace SentinelKernel.System.Plugs.System.IO { - [Plug(Target=typeof(Path))] - public static class PathImpl { + [Plug(Target = typeof(Path))] + public static class PathImpl + { public static void Cctor( [FieldAccess(Name = "System.Char System.IO.Path.AltDirectorySeparatorChar")] ref char aAltDirectorySeparatorChar, [FieldAccess(Name = "System.Char System.IO.Path.DirectorySeparatorChar")] ref char aDirectorySeparatorChar, diff --git a/source/Cosmos.System.Plugs/System/IO/StreamReaderImpl.cs b/source/Cosmos.System.Plugs/System/IO/StreamReaderImpl.cs index 844aad131..82246d385 100644 --- a/source/Cosmos.System.Plugs/System/IO/StreamReaderImpl.cs +++ b/source/Cosmos.System.Plugs/System/IO/StreamReaderImpl.cs @@ -6,14 +6,12 @@ using Cosmos.IL2CPU.Plugs; namespace Cosmos.System.Plugs.System.IO { - /* [Plug(Target = typeof(global::System.IO.StreamReader))] public static class StreamReaderImpl { public static void CheckAsyncTaskInProgress(global::System.IO.StreamReader aThis) { - // for now do nothing + // for now do nothing } } - */ } From f09ef07ccab21bda8ea0fe0a8dac58bb1a633a73 Mon Sep 17 00:00:00 2001 From: Charles Betros Date: Wed, 4 Nov 2015 22:26:57 -0600 Subject: [PATCH 3/5] Added Exception tests. --- .../AssemblyInfo.cs | 36 ++++++ .../Cosmos.Compiler.Tests.Exceptions.csproj | 59 +++++++++ ...osmos.Compiler.Tests.ExceptionsBoot.Cosmos | 47 ++++++++ .../Kernel.cs | 112 ++++++++++++++++++ 4 files changed, 254 insertions(+) create mode 100644 Tests/Cosmos.Compiler.Tests.Exceptions/AssemblyInfo.cs create mode 100644 Tests/Cosmos.Compiler.Tests.Exceptions/Cosmos.Compiler.Tests.Exceptions.csproj create mode 100644 Tests/Cosmos.Compiler.Tests.Exceptions/Cosmos.Compiler.Tests.ExceptionsBoot.Cosmos create mode 100644 Tests/Cosmos.Compiler.Tests.Exceptions/Kernel.cs diff --git a/Tests/Cosmos.Compiler.Tests.Exceptions/AssemblyInfo.cs b/Tests/Cosmos.Compiler.Tests.Exceptions/AssemblyInfo.cs new file mode 100644 index 000000000..6848b03ad --- /dev/null +++ b/Tests/Cosmos.Compiler.Tests.Exceptions/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System; +using System.Reflection; +using System.Resources; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Package Name")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Company")] +[assembly: AssemblyProduct("Package Name")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] +[assembly: ComVisible(false)] +[assembly: CLSCompliant(false)] +[assembly: NeutralResourcesLanguage("en-US")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] + + + diff --git a/Tests/Cosmos.Compiler.Tests.Exceptions/Cosmos.Compiler.Tests.Exceptions.csproj b/Tests/Cosmos.Compiler.Tests.Exceptions/Cosmos.Compiler.Tests.Exceptions.csproj new file mode 100644 index 000000000..a69558c26 --- /dev/null +++ b/Tests/Cosmos.Compiler.Tests.Exceptions/Cosmos.Compiler.Tests.Exceptions.csproj @@ -0,0 +1,59 @@ + + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {9DF5C0A9-B91C-4647-B939-E47513743A0C} + Library + Properties + Cosmos.Compiler.Tests.Exceptions + Cosmos.Compiler.Tests.Exceptions + 512 + v4.5 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + x86 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + {E6D3B644-C487-472D-A978-C1A82D0C099B} + Cosmos.TestRunner.TestController + + + + + \ No newline at end of file diff --git a/Tests/Cosmos.Compiler.Tests.Exceptions/Cosmos.Compiler.Tests.ExceptionsBoot.Cosmos b/Tests/Cosmos.Compiler.Tests.Exceptions/Cosmos.Compiler.Tests.ExceptionsBoot.Cosmos new file mode 100644 index 000000000..b135511d3 --- /dev/null +++ b/Tests/Cosmos.Compiler.Tests.Exceptions/Cosmos.Compiler.Tests.ExceptionsBoot.Cosmos @@ -0,0 +1,47 @@ + + + + Debug + 2.0 + {85e13410-c85a-4b0c-bee5-f9a120ecc94e} + false + Cosmos.Compiler.Tests.ExceptionsBoot + elf + v4.5 + + + VMware + + true + Source + User + False + false + Player + bin\Debug\ + Cosmos.Compiler.Tests.ExceptionsBoot + Use VMware Player or Workstation to deploy and debug. + ISO + VMware + Pipe: Cosmos\Serial + + + + Cosmos.Compiler.Tests.Exceptions + {9df5c0a9-b91c-4647-b939-e47513743a0c} + + + + + + + + + + \ No newline at end of file diff --git a/Tests/Cosmos.Compiler.Tests.Exceptions/Kernel.cs b/Tests/Cosmos.Compiler.Tests.Exceptions/Kernel.cs new file mode 100644 index 000000000..5fc61e2ea --- /dev/null +++ b/Tests/Cosmos.Compiler.Tests.Exceptions/Kernel.cs @@ -0,0 +1,112 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Sys = Cosmos.System; + +namespace Cosmos.Compiler.Tests.Exceptions +{ + using Cosmos.TestRunner; + + public class Kernel : Sys.Kernel + { + private global::Cosmos.Debug.Kernel.Debugger mDebugger = new global::Cosmos.Debug.Kernel.Debugger("User", "Test"); + + protected override void BeforeRun() + { + Console.WriteLine("Cosmos booted successfully, now start testing"); + } + + protected override void Run() + { + mDebugger.Send("Run"); + + TestSimpleException(); + + mDebugger.Send("START: Test throw Exception() in method and catch in caller."); + try + { + TestReturnSimpleException(); + } + catch (Exception ex) + { + Console.WriteLine("Caught exception."); + mDebugger.Send("EXCEPTION: " + ex.Message); + } + finally + { + Console.WriteLine("Finally"); + mDebugger.Send("EXCEPTION: Finally"); + } + mDebugger.Send("END:"); + + mDebugger.Send("START: Test throw nested Exception() in method and catch in caller."); + try + { + TestThrowNestedException(); + } + catch (Exception ex) + { + Console.WriteLine("Caught exception."); + mDebugger.Send("EXCEPTION: " + ex.Message); + } + finally + { + Console.WriteLine("Finally"); + mDebugger.Send("EXCEPTION: Finally"); + } + mDebugger.Send("END:"); + + TestController.Completed(); + } + + private void TestSimpleException() + { + mDebugger.Send("START: Test throw Exception() in method and catch in callee."); + try + { + throw new Exception("throw new Exception()"); + } + catch (Exception ex) + { + Console.WriteLine("Caught exception."); + mDebugger.Send("EXCEPTION: " + ex.Message); + } + mDebugger.Send("END:"); + } + + private void TestReturnSimpleException() + { + throw new Exception("throw new Exception()"); + } + + private void TestThrowNestedException() + { + try + { + try + { + TestArgumentNullException(null); + } + catch (ArgumentNullException ex) + { + Console.WriteLine("Caught nested exception."); + mDebugger.Send("EXCEPTION: " + ex.Message); + } + TestReturnSimpleException(); + } + catch (Exception ex) + { + Console.WriteLine("Caught exception."); + mDebugger.Send("EXCEPTION: " + ex.Message); + } + } + + private void TestArgumentNullException(string arg) + { + if (arg == null) + { + throw new ArgumentNullException(arg, "arg can not be null."); + } + } + } +} From e735e05e034e9e287a1d916fa89a6a2381838df8 Mon Sep 17 00:00:00 2001 From: Charles Betros Date: Wed, 4 Nov 2015 22:28:25 -0600 Subject: [PATCH 4/5] Added Exception tests. --- source/Cosmos.sln | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/source/Cosmos.sln b/source/Cosmos.sln index 8236cce02..37dec4c97 100644 --- a/source/Cosmos.sln +++ b/source/Cosmos.sln @@ -253,6 +253,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cosmos.Kernel.Tests.Fat", " EndProject Project("{471EC4BB-E47E-4229-A789-D1F5F83B52D4}") = "Cosmos.Kernel.Tests.FatBoot", "..\Tests\Cosmos.Kernel.Tests.Fat\Cosmos.Kernel.Tests.FatBoot.Cosmos", "{C006CC79-7FFD-45F1-AD8C-57AC879CC29F}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cosmos.Compiler.Tests.Exceptions", "..\Tests\Cosmos.Compiler.Tests.Exceptions\Cosmos.Compiler.Tests.Exceptions.csproj", "{9DF5C0A9-B91C-4647-B939-E47513743A0C}" +EndProject +Project("{471EC4BB-E47E-4229-A789-D1F5F83B52D4}") = "Cosmos.Compiler.Tests.ExceptionsBoot", "..\Tests\Cosmos.Compiler.Tests.Exceptions\Cosmos.Compiler.Tests.ExceptionsBoot.Cosmos", "{85E13410-C85A-4B0C-BEE5-F9A120ECC94E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -1338,6 +1342,38 @@ Global {C006CC79-7FFD-45F1-AD8C-57AC879CC29F}.Release|Mixed Platforms.Build.0 = Debug|x86 {C006CC79-7FFD-45F1-AD8C-57AC879CC29F}.Release|x86.ActiveCfg = Debug|x86 {C006CC79-7FFD-45F1-AD8C-57AC879CC29F}.Release|x86.Build.0 = Debug|x86 + {9DF5C0A9-B91C-4647-B939-E47513743A0C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9DF5C0A9-B91C-4647-B939-E47513743A0C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9DF5C0A9-B91C-4647-B939-E47513743A0C}.Debug|Itanium.ActiveCfg = Debug|Any CPU + {9DF5C0A9-B91C-4647-B939-E47513743A0C}.Debug|Itanium.Build.0 = Debug|Any CPU + {9DF5C0A9-B91C-4647-B939-E47513743A0C}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {9DF5C0A9-B91C-4647-B939-E47513743A0C}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {9DF5C0A9-B91C-4647-B939-E47513743A0C}.Debug|x86.ActiveCfg = Debug|Any CPU + {9DF5C0A9-B91C-4647-B939-E47513743A0C}.Debug|x86.Build.0 = Debug|Any CPU + {9DF5C0A9-B91C-4647-B939-E47513743A0C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9DF5C0A9-B91C-4647-B939-E47513743A0C}.Release|Any CPU.Build.0 = Release|Any CPU + {9DF5C0A9-B91C-4647-B939-E47513743A0C}.Release|Itanium.ActiveCfg = Release|Any CPU + {9DF5C0A9-B91C-4647-B939-E47513743A0C}.Release|Itanium.Build.0 = Release|Any CPU + {9DF5C0A9-B91C-4647-B939-E47513743A0C}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {9DF5C0A9-B91C-4647-B939-E47513743A0C}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {9DF5C0A9-B91C-4647-B939-E47513743A0C}.Release|x86.ActiveCfg = Release|Any CPU + {9DF5C0A9-B91C-4647-B939-E47513743A0C}.Release|x86.Build.0 = Release|Any CPU + {85E13410-C85A-4B0C-BEE5-F9A120ECC94E}.Debug|Any CPU.ActiveCfg = Debug|x86 + {85E13410-C85A-4B0C-BEE5-F9A120ECC94E}.Debug|Any CPU.Build.0 = Debug|x86 + {85E13410-C85A-4B0C-BEE5-F9A120ECC94E}.Debug|Itanium.ActiveCfg = Debug|x86 + {85E13410-C85A-4B0C-BEE5-F9A120ECC94E}.Debug|Itanium.Build.0 = Debug|x86 + {85E13410-C85A-4B0C-BEE5-F9A120ECC94E}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {85E13410-C85A-4B0C-BEE5-F9A120ECC94E}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {85E13410-C85A-4B0C-BEE5-F9A120ECC94E}.Debug|x86.ActiveCfg = Debug|x86 + {85E13410-C85A-4B0C-BEE5-F9A120ECC94E}.Debug|x86.Build.0 = Debug|x86 + {85E13410-C85A-4B0C-BEE5-F9A120ECC94E}.Release|Any CPU.ActiveCfg = Debug|x86 + {85E13410-C85A-4B0C-BEE5-F9A120ECC94E}.Release|Any CPU.Build.0 = Debug|x86 + {85E13410-C85A-4B0C-BEE5-F9A120ECC94E}.Release|Itanium.ActiveCfg = Debug|x86 + {85E13410-C85A-4B0C-BEE5-F9A120ECC94E}.Release|Itanium.Build.0 = Debug|x86 + {85E13410-C85A-4B0C-BEE5-F9A120ECC94E}.Release|Mixed Platforms.ActiveCfg = Debug|x86 + {85E13410-C85A-4B0C-BEE5-F9A120ECC94E}.Release|Mixed Platforms.Build.0 = Debug|x86 + {85E13410-C85A-4B0C-BEE5-F9A120ECC94E}.Release|x86.ActiveCfg = Debug|x86 + {85E13410-C85A-4B0C-BEE5-F9A120ECC94E}.Release|x86.Build.0 = Debug|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1439,5 +1475,7 @@ Global {DC374FBC-4005-472F-BBF4-CEA608B86FB2} = {A06B122A-4AB7-4090-B41A-35028A293450} {A0893493-D4F0-4B9F-9826-86319E143D86} = {DC374FBC-4005-472F-BBF4-CEA608B86FB2} {C006CC79-7FFD-45F1-AD8C-57AC879CC29F} = {DC374FBC-4005-472F-BBF4-CEA608B86FB2} + {9DF5C0A9-B91C-4647-B939-E47513743A0C} = {F104F6BC-EF8E-4408-A786-D570D7565231} + {85E13410-C85A-4B0C-BEE5-F9A120ECC94E} = {F104F6BC-EF8E-4408-A786-D570D7565231} EndGlobalSection EndGlobal From 7565bb6a30a47227e1e553da5a96f7a5676cbd3a Mon Sep 17 00:00:00 2001 From: Charles Betros Date: Wed, 4 Nov 2015 22:31:38 -0600 Subject: [PATCH 5/5] Exceptions were causing stack corruptions. --- source/Cosmos.IL2CPU/IL/Call.cs | 12 +++++------ source/Cosmos.IL2CPU/IL/Callvirt.cs | 32 +++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/source/Cosmos.IL2CPU/IL/Call.cs b/source/Cosmos.IL2CPU/IL/Call.cs index 04adfcea2..43e94ffc3 100644 --- a/source/Cosmos.IL2CPU/IL/Call.cs +++ b/source/Cosmos.IL2CPU/IL/Call.cs @@ -130,10 +130,10 @@ namespace Cosmos.IL2CPU.X86.IL { { var xStackOffsetBefore = aCurrent.StackOffsetBeforeExecution; - uint xParmSize = 0; - foreach (var parameter in aTargetMethod.GetParameters()) + uint xPopSize = 0; + foreach (var type in aCurrent.StackPopTypes) { - xParmSize += Align(SizeOfType(parameter.ParameterType), 4); + xPopSize += Align(SizeOfType(type), 4); } var xResultSize = xReturnSize; @@ -142,7 +142,7 @@ namespace Cosmos.IL2CPU.X86.IL { xResultSize += 4 - (xResultSize % 4); } - if (xStackOffsetBefore > (xParmSize + xResultSize)) + if (xStackOffsetBefore > (xPopSize + xResultSize)) { if (xResultSize > 0) { @@ -154,9 +154,9 @@ namespace Cosmos.IL2CPU.X86.IL { } } - if (xParmSize > 0) + if (xPopSize > 0) { - var xExtraStack = aCurrent.StackOffsetBeforeExecution - xParmSize - xResultSize; + var xExtraStack = xStackOffsetBefore - xPopSize - xResultSize; new Comment("Cleanup extra stack"); // cleanup result values for (int i = 0; i < xExtraStack / 4; i++) diff --git a/source/Cosmos.IL2CPU/IL/Callvirt.cs b/source/Cosmos.IL2CPU/IL/Callvirt.cs index ca9a74a5a..02f56a983 100644 --- a/source/Cosmos.IL2CPU/IL/Callvirt.cs +++ b/source/Cosmos.IL2CPU/IL/Callvirt.cs @@ -173,14 +173,42 @@ namespace Cosmos.IL2CPU.X86.IL ILOp.EmitExceptionLogic(Assembler, aMethod, aOp, true, delegate() { + var xStackOffsetBefore = aOp.StackOffsetBeforeExecution; + + uint xPopSize = 0; + foreach (var type in aOp.StackPopTypes) + { + xPopSize += Align(SizeOfType(type), 4); + } + var xResultSize = xReturnSize; if (xResultSize % 4 != 0) { xResultSize += 4 - (xResultSize % 4); } - for (int i = 0; i < xResultSize / 4; i++) + + if (xStackOffsetBefore > (xPopSize + xResultSize)) { - new CPUx86.Add {DestinationReg = CPUx86.Registers.ESP, SourceValue = 4}; + if (xResultSize > 0) + { + new Comment("Cleanup return"); + // cleanup result values + for (int i = 0; i < xResultSize / 4; i++) + { + new CPUx86.Add { DestinationReg = CPUx86.Registers.ESP, SourceValue = 4 }; + } + } + + if (xPopSize > 0) + { + var xExtraStack = xStackOffsetBefore - xPopSize - xResultSize; + new Comment("Cleanup extra stack"); + // cleanup result values + for (int i = 0; i < xExtraStack / 4; i++) + { + new CPUx86.Add { DestinationReg = CPUx86.Registers.ESP, SourceValue = 4 }; + } + } } }); new Label(xCurrentMethodLabel + ".NoExceptionAfterCall");