Code Monkey home page Code Monkey logo

il2cpu's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

il2cpu's Issues

Fix StructLayout(LayoutKind.Sequential)

From @mterwoord on July 30, 2015 19:1

Right now, the only way to get control over struct layout, is to use LayoutKind.Explicit and the FieldOffsetAttribute, but this isn't portable between bitnesses.. See for example, the DataLookupEntry and related structs.

Copied from original issue: CosmosOS/Cosmos#173

SystemUInt32PrivateImplementationDetailsComputeStringHashSystemString redefined

SystemUInt32PrivateImplementationDetailsComputeStringHashSystemString redefined when nasm compiles. I try to compile Aura_OS from this branch: https://github.com/aura-systems/Aura-Operating-System/tree/impl-net5

After more investigation, it appears to be related to the FTP Server.

Actual Behaviour - What unexpectedly happens?

1>IL2CPU task took 00:02:26.0802791
1>bin\Debug\net5.0\Aura_OS.asm:988207: error: symbol `SystemUInt32PrivateImplementationDetailsComputeStringHashSystemString' redefined
1>bin\Debug\net5.0\Aura_OS.asm:988217: error: symbol `SystemUInt32PrivateImplementationDetailsComputeStringHashSystemString.IL_0000' redefined
1>bin\Debug\net5.0\Aura_OS.asm:988225: error: symbol `SystemUInt32PrivateImplementationDetailsComputeStringHashSystemString.IL_0001' redefined
1>bin\Debug\net5.0\Aura_OS.asm:988234: error: symbol `SystemUInt32PrivateImplementationDetailsComputeStringHashSystemString.IL_0001.End' redefined
1>bin\Debug\net5.0\Aura_OS.asm:988236: error: symbol `SystemUInt32PrivateImplementationDetailsComputeStringHashSystemString.IL_0003' redefined
1>bin\Debug\net5.0\Aura_OS.asm:988240: error: symbol `SystemUInt32PrivateImplementationDetailsComputeStringHashSystemString.IL_0008' redefined
1>bin\Debug\net5.0\Aura_OS.asm:988248: error: symbol `SystemUInt32PrivateImplementationDetailsComputeStringHashSystemString.IL_0009' redefined
1>bin\Debug\net5.0\Aura_OS.asm:988252: error: symbol `SystemUInt32PrivateImplementationDetailsComputeStringHashSystemString.IL_000A' redefined
1>bin\Debug\net5.0\Aura_OS.asm:988260: error: symbol `SystemUInt32PrivateImplementationDetailsComputeStringHashSystemString.IL_000B' redefined
1>bin\Debug\net5.0\Aura_OS.asm:988264: error: symbol `SystemUInt32PrivateImplementationDetailsComputeStringHashSystemString.IL_000D' redefined
1>bin\Debug\net5.0\Aura_OS.asm:988272: error: symbol `SystemUInt32PrivateImplementationDetailsComputeStringHashSystemString.IL_000E' redefined
1>bin\Debug\net5.0\Aura_OS.asm:988279: error: symbol `SystemUInt32PrivateImplementationDetailsComputeStringHashSystemString.IL_000F' redefined
1>bin\Debug\net5.0\Aura_OS.asm:988294: error: symbol `SystemUInt32PrivateImplementationDetailsComputeStringHashSystemString.IL_000F.NoExceptionAfterCall' redefined
1>bin\Debug\net5.0\Aura_OS.asm:988296: error: symbol `SystemUInt32PrivateImplementationDetailsComputeStringHashSystemString.IL_0014' redefined
1>bin\Debug\net5.0\Aura_OS.asm:988303: error: symbol `SystemUInt32PrivateImplementationDetailsComputeStringHashSystemString.IL_0015' redefined
1>bin\Debug\net5.0\Aura_OS.asm:988308: error: symbol `SystemUInt32PrivateImplementationDetailsComputeStringHashSystemString.IL_0016' redefined
1>bin\Debug\net5.0\Aura_OS.asm:988312: error: symbol `SystemUInt32PrivateImplementationDetailsComputeStringHashSystemString.IL_001B' redefined
1>bin\Debug\net5.0\Aura_OS.asm:988319: error: symbol `SystemUInt32PrivateImplementationDetailsComputeStringHashSystemString.IL_001C' redefined
1>bin\Debug\net5.0\Aura_OS.asm:988327: error: symbol `SystemUInt32PrivateImplementationDetailsComputeStringHashSystemString.IL_001D' redefined
1>bin\Debug\net5.0\Aura_OS.asm:988334: error: symbol `SystemUInt32PrivateImplementationDetailsComputeStringHashSystemString.IL_001E' redefined
1>bin\Debug\net5.0\Aura_OS.asm:988338: error: symbol `SystemUInt32PrivateImplementationDetailsComputeStringHashSystemString.IL_001F' redefined
1>bin\Debug\net5.0\Aura_OS.asm:988343: error: symbol `SystemUInt32PrivateImplementationDetailsComputeStringHashSystemString.IL_0020' redefined
1>bin\Debug\net5.0\Aura_OS.asm:988351: error: symbol `SystemUInt32PrivateImplementationDetailsComputeStringHashSystemString.IL_0021' redefined
1>bin\Debug\net5.0\Aura_OS.asm:988358: error: symbol `SystemUInt32PrivateImplementationDetailsComputeStringHashSystemString.IL_0022' redefined
1>bin\Debug\net5.0\Aura_OS.asm:988366: error: symbol `SystemUInt32PrivateImplementationDetailsComputeStringHashSystemString.IL_0023' redefined
1>bin\Debug\net5.0\Aura_OS.asm:988383: error: symbol `SystemUInt32PrivateImplementationDetailsComputeStringHashSystemString.IL_0023.NoExceptionAfterCall' redefined
1>bin\Debug\net5.0\Aura_OS.asm:988385: error: symbol `SystemUInt32PrivateImplementationDetailsComputeStringHashSystemString.IL_0028' redefined
1>bin\Debug\net5.0\Aura_OS.asm:988392: error: symbol `SystemUInt32PrivateImplementationDetailsComputeStringHashSystemString.IL_002A' redefined
1>bin\Debug\net5.0\Aura_OS.asm:988396: error: symbol `SystemUInt32PrivateImplementationDetailsComputeStringHashSystemString.IL_002C' redefined
1>bin\Debug\net5.0\Aura_OS.asm:988403: error: symbol `SystemUInt32PrivateImplementationDetailsComputeStringHashSystemString.IL_002D' redefined
1>bin\Debug\net5.0\Aura_OS.asm:988408: error: symbol `SystemUInt32PrivateImplementationDetailsComputeStringHashSystemString.END__OF__METHOD_NORMAL' redefined
1>bin\Debug\net5.0\Aura_OS.asm:988415: error: symbol `SystemUInt32PrivateImplementationDetailsComputeStringHashSystemString.END__OF__METHOD_EXCEPTION' redefined
1>bin\Debug\net5.0\Aura_OS.asm:988418: error: symbol `SystemUInt32PrivateImplementationDetailsComputeStringHashSystemString.END__OF__METHOD_EXCEPTION__2' redefined
1>C:\Users\valentinbreiz\.nuget\packages\cosmos.build\0.1.0-localbuild20211021045217\build\Cosmos.Build.targets(206,9): error MSB6006: "nasm.exe" exited with code 1.
1>Nasm task took 00:00:07.6073003
1>Done building project "Aura_OS.csproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Reproduction - How did you get this error to appear?

Clone Aura_OS, try to compile using .net 5.

Version - Were you using the User Kit or Dev Kit? And what User Kit version or Dev Kit commit (Cosmos, IL2CPU, X#)?

Devkit

Leave address should be pushed to the stack

The endfinally/endfilter op declares a data member to store the leave address and the leave op stores the current address in the data member, but the address should be stored in the stack.
For example, if a method calls itself from a finally block (which comes from a leave address X), and the finally block in the called method comes from a leave address Y, then Y is stored in the data member and, after returning, endfinally/endfilter will jump address Y, but it should jump to X.

Related to #16

[Discussion] IL2CPU compilation context

Currently IL2CPU is targeting netcoreapp2.0 and win7-x86, so it can only be run on Windows and it uses the .NET Core 2.0 assemblies that ship as part of the compiler, which are built for 32-bit systems. We should pass all references to IL2CPU, and the assemblies should be loaded in a separate context.

Pros

  • IL2CPU will be cross-platform.
  • It's almost impossible to fail to load a reference assembly.
  • IL2CPU can load 32-bit or 64-bit assemblies according to the target platform.
  • Users can target any framework they want.

Cons

  • Plugs are implemented for a specific framework (currently netcoreapp2.0), and it would be too much work to support all frameworks, so we can either document what is the recommended framework or, as plugs are part of Cosmos, we can prevent the compilation for unsupported frameworks (maybe using an MSBuild task target).

Improve label name

The problem with including the entire assembly name in the label is that its too long
so an idea could be that we create a short unique id for each assembly as we encounter it
and append that to each label
@quajak

Better approach for #122

Implement sub.ovf

Implement sub.ovf, for:

  • 4 byte values (higher priority)
  • 8 byte values (lower priority)

System.InvalidOperationException: SqliteConnection does not support nested transactions.

Sometimes during TestRunner "routine" I get this error that make kernel fails.
This is the complete exception:

08:14:10.687024 Msg: Warning: Exists
08:14:25.043802 Msg: Detecting fields for type 'Cosmos.Debug.Symbols.FIELD_INFO'
08:14:25.336979 Msg: Detecting fields for type 'Cosmos.Debug.Symbols.FIELD_MAPPING'
08:15:12.638903 Msg: Detecting fields for type 'Cosmos.Debug.Symbols.AssemblyFile'
08:15:12.706129 Msg: Error: Exception: System.InvalidOperationException: SqliteConnection does not support nested transactions.
08:15:12.706562 Msg: at Microsoft.Data.Sqlite.SqliteConnection.BeginTransaction(IsolationLevel isolationLevel)
08:15:12.714657 Msg: at Microsoft.Data.Sqlite.SqliteConnection.BeginTransaction()
08:15:12.717210 Msg: at Cosmos.Debug.Symbols.SqliteBulkCopy.WriteToServer(IDataReader reader) in C:\Users\fano\Documents\GitHub\Cosmos\IL2CPU\source\IL2CPU.Debug.Symbols\SqliteBulkCopy.cs:line 36
08:15:12.737130 Msg: at Cosmos.Debug.Symbols.DebugInfo.BulkInsertT in C:\Users\fano\Documents\GitHub\Cosmos\IL2CPU\source\IL2CPU.Debug.Symbols\DebugInfo.cs:line 520
08:15:12.753046 Msg: at Cosmos.Debug.Symbols.DebugInfo.AddAssemblies(List`1 aAssemblies, Boolean aFlush) in C:\Users\fano\Documents\GitHub\Cosmos\IL2CPU\source\IL2CPU.Debug.Symbols\DebugInfo.cs:line 395
08:15:12.759681 Msg: at Cosmos.Debug.Symbols.DebugInfo.Dispose() in C:\Users\fano\Documents\GitHub\Cosmos\IL2CPU\source\IL2CPU.Debug.Symbols\DebugInfo.cs:line 545
08:15:12.797378 Msg: at Cosmos.IL2CPU.CompilerEngine.Execute() in C:\Users\fano\Documents\GitHub\Cosmos\IL2CPU\source\Cosmos.IL2CPU\CompilerEngine.cs:line 246
08:15:12.846716 Error: Error invoking 'dotnet'.

IL2CPU randomly fails at "Detecting fields for type 'IL2CPU.Debug.Symbols.LOCAL_ARGUMENT_INFO'"

After adding some code (CommandEDIT class), I started getting this error.

1>------ Erstellen gestartet: Projekt: EtorumOS, Konfiguration: Debug Any CPU ------
1>Analysetools werden übersprungen, um den Build zu beschleunigen. Sie können den Befehl „Build“ oder „Rebuild“ ausführen, um Analyzer auszuführen.
1>C:\Users\user\source\repos\EtorumOS\EtorumOS\ETOScript\Commands\CommandCD.cs(2,7,2,18): warning CS0105: Die using-Direktive für "EtorumOS.IO" ist bereits vorher in diesem Namespace aufgetreten.
1>C:\Users\user\source\repos\EtorumOS\EtorumOS\ETOScript\Commands\CommandHELP.cs(2,7,2,18): warning CS0105: Die using-Direktive für "EtorumOS.IO" ist bereits vorher in diesem Namespace aufgetreten.
1>C:\Users\user\source\repos\EtorumOS\EtorumOS\ETOScript\Commands\Command.cs(150,17,150,34): warning CS0472: Das Ergebnis des Ausdrucks ist immer "false", da ein Wert vom Typ "int" niemals NULL vom Typ "int?" ist.
1>C:\Users\user\source\repos\EtorumOS\EtorumOS\Resources\ResourceManager.cs(20,30,20,41): warning CS0649: Dem Feld "ResourceManager.ZapLightPSF" wird nie etwas zugewiesen, und es hat immer seinen Standardwert von "null".
1>C:\Users\user\source\repos\EtorumOS\EtorumOS\ETOScript\Commands\CommandEDIT.cs(15,63,15,73): warning CS0414: Dem Feld "CommandEDIT.prevScollY" wurde ein Wert zugewiesen, der aber nie verwendet wird.
1>C:\Users\user\source\repos\EtorumOS\EtorumOS\ETOScript\Commands\CommandEDIT.cs(15,46,15,57): warning CS0414: Dem Feld "CommandEDIT.prevScrollX" wurde ein Wert zugewiesen, der aber nie verwendet wird.
1>EtorumOS -> C:\Users\user\source\repos\EtorumOS\EtorumOS\bin\Debug\net6.0\EtorumOS.dll
1>Executing IL2CPU on assembly
1>Kernel Base: Cosmos.System.Kernel
1>Checking target assembly: C:\Users\user\source\repos\EtorumOS\EtorumOS\bin\Debug\net6.0\EtorumOS.dll
1>IL2CPU : warning : Loading plugs from assembly: EtorumOS.Plugs, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
1>IL2CPU : warning : Loading plugs from assembly: Cosmos.Core_Asm, Version=10.0.0.0, Culture=neutral, PublicKeyToken=5ae71220097cb983
1>IL2CPU : warning : Loading plugs from assembly: Cosmos.Core_Plugs, Version=10.0.0.0, Culture=neutral, PublicKeyToken=5ae71220097cb983
1>IL2CPU : warning : Loading plugs from assembly: Cosmos.Debug.Kernel.Plugs.Asm, Version=10.0.0.0, Culture=neutral, PublicKeyToken=5ae71220097cb983
1>IL2CPU : warning : Loading plugs from assembly: Cosmos.System2_Plugs, Version=10.0.0.0, Culture=neutral, PublicKeyToken=5ae71220097cb983
1>Detecting fields for type 'IL2CPU.Debug.Symbols.FIELD_INFO'
1>Detecting fields for type 'IL2CPU.Debug.Symbols.FIELD_MAPPING'
1>Detecting fields for type 'IL2CPU.Debug.Symbols.MethodIlOp'
1>Detecting fields for type 'IL2CPU.Debug.Symbols.Document'
1>Detecting fields for type 'IL2CPU.Debug.Symbols.AssemblyFile'
1>Detecting fields for type 'IL2CPU.Debug.Symbols.Method'
1>Detecting fields for type 'IL2CPU.Debug.Symbols.LOCAL_ARGUMENT_INFO'
1>IL2CPU : error : Exception: System.InvalidOperationException: Value must be set.
1>   at Microsoft.Data.Sqlite.SqliteParameter.Bind(sqlite3_stmt stmt)
1>   at Microsoft.Data.Sqlite.SqliteParameterCollection.Bind(sqlite3_stmt stmt)
1>   at Microsoft.Data.Sqlite.SqliteCommand.GetStatements(Stopwatch timer)+MoveNext()
1>   at Microsoft.Data.Sqlite.SqliteDataReader.NextResult()
1>   at Microsoft.Data.Sqlite.SqliteCommand.ExecuteReader(CommandBehavior behavior)
1>   at Microsoft.Data.Sqlite.SqliteCommand.ExecuteNonQuery()
1>   at IL2CPU.Debug.Symbols.SqliteBulkCopy.WriteToServer(IDataReader reader) in C:\Users\user\source\repos\Cosmos\IL2CPU\source\IL2CPU.Debug.Symbols\SqliteBulkCopy.cs:line 63
1>   at IL2CPU.Debug.Symbols.DebugInfo.BulkInsert[T](String aTableName, IList`1 aList, Int32 aFlushSize, Boolean aFlush) in C:\Users\user\source\repos\Cosmos\IL2CPU\source\IL2CPU.Debug.Symbols\DebugInfo.cs:line 512
1>   at IL2CPU.Debug.Symbols.DebugInfo.WriteAllLocalsArgumentsInfos(IList`1 aInfos) in C:\Users\user\source\repos\Cosmos\IL2CPU\source\IL2CPU.Debug.Symbols\DebugInfo.cs:line 487
1>   at Cosmos.IL2CPU.AppAssembler.FinalizeDebugInfo() in C:\Users\user\source\repos\Cosmos\IL2CPU\source\Cosmos.IL2CPU\AppAssembler.cs:line 414
1>   at Cosmos.IL2CPU.CompilerEngine.Execute() in C:\Users\user\source\repos\Cosmos\IL2CPU\source\Cosmos.IL2CPU\CompilerEngine.cs:line 197
1>IL2CPU task took 00:00:23.6525567
1>Die Erstellung des Projekts "EtorumOS.csproj" ist abgeschlossen -- FEHLER.
========== Build: 0 erfolgreich, 1 Fehler, 2 aktuell, 0 übersprungen ==========
========== Erstellen wurde am 2:35 PM gestartet und dauerte 24,750 Sekunden ==========

Can be, most likely, reproduced with this repo:
https://github.com/GoldenretriverYT/EtorumOS/tree/4b9d38be586a8833b6e609e2514b0e5d197d5180

Null Reference Exception in Ldind_U2

During the plugging of DirectoryInfo class I've found a bug of IL2CPU, an internal method of the Path class is calling this unsafe code:

        private static unsafe bool StartsWithOrdinal(char* source, uint sourceLength, string value)
        {
            if (sourceLength < (uint)value.Length) return false;
            for (int i = 0; i < value.Length; i++)
            {
                if (value[i] != source[i]) return false;
            }
            return true;
        }

one can - for example - call it in this way (similar of what is done in CoreFx):

            String pathAsString = @"0:\DiTest";
            int pathLength = pathAsString.Length;
            bool val1;
            fixed (char* path = pathAsString)
            {
                val1 = StartsWithOrdinal(path, (uint)pathLength, "\\\\?\\");
            }

while nothing has value "null" you will get NRE on Ldind_U2.
The hypothesis is that - in reality - the null pointer is wrongly put onto the stack by previous opcodes and
Ldind_U2 is not really wrong.

Char < operator not working

Trying to do this code on a char when the value interpreted as number (the codepoint) is > SHORT_MAX this tests fails:

       private byte GetByte(char ch)
        {
            /* ch is in reality an ASCII character? */
            //if (ch >= 0 && ch < 127)
            if (ch < 127)
            {
                //mDebugger.SendInternal($"ch {(ushort)ch} is ASCII");
                return (byte)ch;
            }

	   return 42;
}

For the same cause Char.IsSurrugate(ch) returns false.

This the IL that this code generates:

GetByte:
IL_0000:  nop         
IL_0001:  ldarg.1     
IL_0002:  ldc.i4.s    7F
IL_0004:  clt         
IL_0006:  stloc.0     
IL_0007:  ldloc.0     
IL_0008:  brfalse.s   IL_0010
IL_000A:  nop         
IL_000B:  ldarg.1     
IL_000C:  conv.u1     
IL_000D:  stloc.1     
IL_000E:  br.s        IL_0015
IL_0010:  ldc.i4.s    2A 
IL_0012:  stloc.1     
IL_0013:  br.s        IL_0015
IL_0015:  ldloc.1     
IL_0016:  ret         

[Bug] Stack Corruption Detection Fails on Valid Cases

The stack corruption detection fails when there are complex conditions, because there are branches which implicitly assume that some IL instructions will only be executed on certain conditions (specific stack differences).

A sample, in C#: SharpLab

Analyzing the C# sample (IL, using 32-bit sizes)
... truncated ... -> stack difference = base
ΔSD -> Δ Stack Difference
[ΔSD]
[ +4]IL_0007: ldloc.0
[ -4]IL_0008: brfalse.s IL_000f          // stack difference = base
[ +4]IL_000a: ldloc.1
[ +4]IL_000b: ldloc.2
[ -4]IL_000c: or
[  0]IL_000d: br.s IL_0010               // stack difference = base + 4
[ +4]IL_000f: ldc.i4.0                   // came from IL_0008 -> stack difference before op = base
[ -4]IL_0010: stloc.3                    // came from IL_000d -> stack difference before op = base + 4
[ +4]IL_0011: ldloc.3
[ -4]IL_0012: brfalse.s IL_0023          // stack difference = base
                                         // calculated stack difference: base + 4
                                         // stack corruption on IL_0014
[  0]IL_0014: nop
[ +8]IL_0015: ldstr "True condition"
[ -8]IL_001a: call void [mscorlib]System.Console::WriteLine(string)
[  0]IL_001f: nop
[  0]IL_0020: nop
[  0]IL_0021: br.s IL_0030               // stack difference -> base
[  0]IL_0023: nop                        // came from IL_0012 -> stack difference before op = base
[ +8]IL_0024: ldstr "False condition"
[ -8]IL_0029: call void [mscorlib]System.Console::WriteLine(string)
[  0]IL_002e: nop
[  0]IL_002f: nop
[  0]IL_0030: ret

[Discussion] Using ldftn and calli to call X# methods from managed code

I think it would be interesting to call X# methods from IL (C#) using ldftn/calli. The assembler plug would be replaced with managed code, which means better portability.

Example

public static void SendNumber(int number)
{
	ldarg.0
    ldftn
	calli
}

[XSharpMethod("DebugStub_SendSimpleNumber")]
private static void DoSendNumber(int number);

We just need to handle the attribute in ldftn, where we just emit push label.

Possible issues

  • In the debug stub assembler plugs, we currently ifdef the calls, because the debug stub may be disabled (i.e. it's not emitted), so we need to handle that somehow.
  • Calling conventions.

Severity Code Description Project File Line Suppression State Error Exception: System.InvalidOperationException: Value must be set. IL2CPU

Area of Cosmos - What area of Cosmos are we dealing with?

IL2CPU

Expected Behaviour - What do you think that should happen?

The program should build successfully
The code for part of the Kernel
string textEditor() { bool inTextEditor = true; int x = 1; string[] textToSave = {"/",}; string savedText = "No text"; while (inTextEditor == true) { textToSave[x] = input; x++; if (input == "t-exit") { inTextEditor = false; } } savedText = string.Join("", textToSave); return savedText; }

Actual Behaviour - What unexpectedly happens?

Build error in IL2CPU line 1

Reproduction - How did you get this error to appear?

Paste this code into your kernel:
string textEditor() { bool inTextEditor = true; int x = 1; string[] textToSave = {"/",}; string savedText = "No text"; while (inTextEditor == true) { textToSave[x] = input; x++; if (input == "t-exit") { inTextEditor = false; } } savedText = string.Join("", textToSave); return savedText; }

Version - Were you using the User Kit or Dev Kit? And what User Kit version or Dev Kit commit (Cosmos, IL2CPU, X#)?

User Kit 20200708

Review stack type interpretation

Currently, we use the real types to interpret the stack types and implement the ops.
We should use the "basic CLI types" (III.1.1):

  • A subset of the full numeric types (int32, int64, native int, and F).
  • Object references (O) without distinction between the type of object referenced.
  • Pointer types (native unsigned int and &) without distinction as to the type pointed to.

The operand type tables (III.1.5) are based on these types, so we should use them to check the stack types and implement the ops.

There are 2 options to implement this:

  1. Create a new class for stack types (maybe StackType), which holds the real type and the "basic CLI type", which would be evaluated in the constructor of StackType.
  2. Use helper methods (like TypeOnStackIsInt32 and TypeOnStackIsObjectRef).

Interface maps for generic interfaces on arrays cannot be retvived.

This happened when i tried to render some text with figgle (Console.WriteLine(FiggleFonts.Alligator.Render("some text"));. logs:

1>Message: Executing IL2CPU on assembly
1>Message: Kernel Base: Cosmos.System.Kernel
1>Message: Checking target assembly: C:\Users\waver\source\repos\kocmoc\kocmoc\bin\Debug\netcoreapp2.0\cosmos\kocmoc.dll
1>IL2CPU : error : Exception: System.ArgumentException: Interface maps for generic interfaces on arrays cannot be retrieved.
1>   at System.RuntimeType.GetInterfaceMap(Type ifaceType)
1>   at Cosmos.IL2CPU.ILScanner.ScanMethod(MethodBase aMethod, Boolean aIsPlug, String sourceItem) in C:\Development\Cosmos\IL2CPU\source\Cosmos.IL2CPU\ILScanner.cs:line 559
1>   at Cosmos.IL2CPU.ILScanner.ScanQueue() in C:\Development\Cosmos\IL2CPU\source\Cosmos.IL2CPU\ILScanner.cs:line 770
1>   at Cosmos.IL2CPU.ILScanner.Execute(MethodBase aStartMethod, IEnumerable`1 plugsAssemblies) in C:\Development\Cosmos\IL2CPU\source\Cosmos.IL2CPU\ILScanner.cs:line 264
1>   at Cosmos.IL2CPU.CompilerEngine.Execute() in C:\Development\Cosmos\IL2CPU\source\Cosmos.IL2CPU\CompilerEngine.cs:line 200
1>IL2CPU task took 00:00:03.2715992

Assembly names should be included as part of the type names

There are many cases on .NET Core where there are internal types with the same full name as public types, and it can cause unexpected errors, as assembly names are currently ignored.

One example is System.Environment, which is a public type in the System.Runtime.Extensions assembly: Environment.cs, but there's also an internal version, in the System.Private.CoreLib assembly: Environment.cs.

Rework debug symbols implementation

The current debug symbols implementation has some weak points:

  1. It uses SQLite to store the debug symbols, which is native, and forces us to have .
  2. It depends on getting debug info from pdb files at compile time, which is wrong. The debug symbols should be loaded at debug time, as they can come from anywhere.

The following changes should be done on the debug symbols implementation (probably both at the same time):

  1. We can replace SQLite with LiteDB, which is fully managed, and has good performance.

  2. The debug symbols should contain debug info that allows the debug engine to retrieve debug data from the pdb. The following data is important:

    • Mapping between static fields and the corresponding labels (already present)
    • Mapping between methods and the corresponding labels, including IL opcode labels (already present)
    • Stack offsets for arguments and locals (already present)
    • Field offsets (already present)
    • Type, method and field metadata tokens, and generic arguments (new)

    So sequence points and source documents would no longer be present in the debug symbols, and would be loaded by the debug engine. It would be possible to debug any assembly, including the runtime ones.

System.Exception: Error interpreting stacktypes for IL_0006:

From @fanoI on August 14, 2016 16:53

I were trying to port BigInteger to Cosmos the .NET version is too complex and will need to plug 99% of .NET so I've found this implementation that is really more simple:
http://www.codeproject.com/Articles/2728/C-BigInteger-Class

SingleImpl.cs is now using BigInteger as the range of float overcome that of ulong but now the code does not compile anymore this is the error:

6:44:13.265590 Msg: Detecting fields for type 'Cosmos.Debug.Common.Method'
06:44:13.281600 Msg: Error: Exception: System.Exception: Error compiling method 'SystemBooleanSystemSingleEqualsSystemObject': System.Exception: Error interpreting stacktypes for IL_0006: Brtrue ---> System.Exception: Invalid type in PopTypes! (Type = 'System.Single, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
06:44:13.283602 Msg: in Cosmos.IL2CPU.ILOpCodes.OpBranch.DoInterpretStackTypes(Boolean& aSituationChanged) in C:\Users\fano\Documents\GitHub\Cosmos\source\Cosmos.IL2CPU\ILOpCodes\OpBranch.cs:riga 115
06:44:13.284603 Msg: in Cosmos.IL2CPU.ILOpCode.InterpretStackTypes(IDictionary2 aOpCodes, Stack1 aStack, Boolean& aSituationChanged, Int32 aMaxRecursionDepth) in C:\Users\fano\Documents\GitHub\Cosmos\source\Cosmos.IL2CPU\ILOpCode.cs:riga 413
06:44:13.285604 Msg: --- Fine della traccia dello stack dell'eccezione interna ---

I suppose it is something done in BigInteger.cs as removing the variable declaration it compiles again.

Copied from original issue: CosmosOS/Cosmos#436

Interface maps for generic interfaces on arrays cannot be retrieved.

When I try to use this code return new List<uint>(H); inside a List<uint> function I have this error:

1>IL2CPU : error : Exception: System.ArgumentException: Interface maps for generic interfaces on arrays cannot be retrieved.
1> at System.RuntimeType.GetInterfaceMap(Type ifaceType)
1>Message: C:\Users\valentinbreiz\Documents\GitHub\Aura-Operating-System\Aura Operating System\Aura OS\bin\Debug\netstandard2.0\Aura_OS.dll
1>Message: C:\Users\valentinbreiz\AppData\Roaming\Cosmos User Kit\Kernel\Cosmos.Core_Asm.dll
1>Message: C:\Users\valentinbreiz\AppData\Roaming\Cosmos User Kit\Kernel\Cosmos.Core_Plugs.dll
1>Message: C:\Users\valentinbreiz\AppData\Roaming\Cosmos User Kit\Kernel\Cosmos.Debug.Kernel.Plugs.Asm.dll
1>Message: C:\Users\valentinbreiz\AppData\Roaming\Cosmos User Kit\Kernel\Cosmos.System2_Plugs.dll
1> at Cosmos.IL2CPU.ILScanner.ScanMethod(MethodBase aMethod, Boolean aIsPlug, String sourceItem) in C:\Users\valentinbreiz\Documents\Cosmos\IL2CPU\source\Cosmos.IL2CPU\ILScanner.cs:line 561
1> at Cosmos.IL2CPU.ILScanner.ScanQueue() in C:\Users\valentinbreiz\Documents\Cosmos\IL2CPU\source\Cosmos.IL2CPU\ILScanner.cs:line 775
1> at Cosmos.IL2CPU.ILScanner.Execute(MethodBase aStartMethod) in C:\Users\valentinbreiz\Documents\Cosmos\IL2CPU\source\Cosmos.IL2CPU\ILScanner.cs:line 253
1> at Cosmos.IL2CPU.CompilerEngine.Execute() in C:\Users\valentinbreiz\Documents\Cosmos\IL2CPU\source\Cosmos.IL2CPU\CompilerEngine.cs:line 168

Devkit build error: "ReflectionTypeLoadException" in IL2CPU

Got this cryptic error with the most recent devkit build even on a stock, out of box C# kernel. Modified the IL2CPU solution to give the internal error in the debug log.

Modified Stack Trace:

1>------ Build started: Project: CosmosKernel1, Configuration: Debug Any CPU ------
1>C:\Program Files\dotnet\sdk\3.0.100-preview5-011568\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInference.targets(157,5): message NETSDK1057: You are using a preview version of .NET Core. See: https://aka.ms/dotnet-core-preview
1>CosmosKernel1 -> C:\Users\MYUSERNAME\Desktop\CosmosKernel1\CosmosKernel1\bin\Debug\netcoreapp2.0\cosmos\CosmosKernel1.dll
1>Message: Executing IL2CPU on assembly
1>Message: Kernel Base: Cosmos.System.Kernel
1>Message: Checking target assembly: C:\Users\MYUSERNAME\Desktop\CosmosKernel1\CosmosKernel1\bin\Debug\netcoreapp2.0\cosmos\CosmosKernel1.dll
1>IL2CPU : error : Exception: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
1>   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
1>   at System.Reflection.RuntimeModule.GetTypes()
1>   at System.Reflection.Assembly.GetTypes()
1>   at Cosmos.IL2CPU.PlugManager.FindPlugImpls(IEnumerable`1 assemblies) in D:\Users\MYUSERNAME\Source\Repos\CosmosOS\IL2CPU\source\Cosmos.IL2CPU\PlugManager.cs:line 79
1>   at Cosmos.IL2CPU.ILScanner.Execute(MethodBase aStartMethod, IEnumerable`1 plugsAssemblies) in D:\Users\MYUSERNAME\Source\Repos\CosmosOS\IL2CPU\source\Cosmos.IL2CPU\ILScanner.cs:line 218
1>   at Cosmos.IL2CPU.CompilerEngine.Execute() in D:\Users\MYUSERNAME\Source\Repos\CosmosOS\IL2CPU\source\Cosmos.IL2CPU\CompilerEngine.cs:line 200
1>IL2CPU : error : Exception: System.TypeLoadException: Could not load type 'XSharp.Assembler.AssemblerMethod' from assembly 'XSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b94a93fbb8fa3f4f'.
1>IL2CPU : error : Exception: System.TypeLoadException: Could not load type 'XSharp.Assembler.AssemblerMethod' from assembly 'XSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b94a93fbb8fa3f4f'.
1>IL2CPU : error : Exception: System.TypeLoadException: Could not load type 'XSharp.Assembler.AssemblerMethod' from assembly 'XSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b94a93fbb8fa3f4f'.
1>IL2CPU : error : Exception: System.TypeLoadException: Could not load type 'XSharp.Assembler.AssemblerMethod' from assembly 'XSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b94a93fbb8fa3f4f'.
1>IL2CPU : error : Exception: System.TypeLoadException: Could not load type 'XSharp.Assembler.AssemblerMethod' from assembly 'XSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b94a93fbb8fa3f4f'.
1>IL2CPU : error : Exception: System.TypeLoadException: Could not load type 'XSharp.Assembler.AssemblerMethod' from assembly 'XSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b94a93fbb8fa3f4f'.
1>IL2CPU : error : Exception: System.TypeLoadException: Could not load type 'XSharp.Assembler.AssemblerMethod' from assembly 'XSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b94a93fbb8fa3f4f'.
1>IL2CPU : error : Exception: System.TypeLoadException: Could not load type 'XSharp.Assembler.AssemblerMethod' from assembly 'XSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b94a93fbb8fa3f4f'.
1>IL2CPU : error : Exception: System.TypeLoadException: Could not load type 'XSharp.Assembler.AssemblerMethod' from assembly 'XSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b94a93fbb8fa3f4f'.
1>IL2CPU : error : Exception: System.TypeLoadException: Could not load type 'XSharp.Assembler.AssemblerMethod' from assembly 'XSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b94a93fbb8fa3f4f'.
1>IL2CPU : error : Exception: System.TypeLoadException: Could not load type 'XSharp.Assembler.AssemblerMethod' from assembly 'XSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b94a93fbb8fa3f4f'.
1>IL2CPU : error : Exception: System.TypeLoadException: Could not load type 'XSharp.Assembler.AssemblerMethod' from assembly 'XSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b94a93fbb8fa3f4f'.
1>IL2CPU : error : Exception: System.TypeLoadException: Could not load type 'XSharp.Assembler.AssemblerMethod' from assembly 'XSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b94a93fbb8fa3f4f'.
1>IL2CPU : error : Exception: System.TypeLoadException: Could not load type 'XSharp.Assembler.AssemblerMethod' from assembly 'XSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b94a93fbb8fa3f4f'.
1>IL2CPU task took 00:00:05.0005391
1>Done building project "CosmosKernel1.csproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Kernel panic with debug output of InterfaceMethodId not found.

I have a logging implementation that use two interfaces and implement all the methods, building is done correctly but at runtime i get a kernel panic indicating that an interface method is not found. Quite strange behavior.

Type
0x0000028D
TypeName: Zaphyros.Core.Logging.MultiTargetLogger, Zaphyros.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
InterfaceMethodId
0x0000033A
Not FOUND!

Implementation can be found on Zaphyros's logging feacture branch

My OS is not booting

hello, my OS is not booting, i asked that in the Cosmos Discord server, and Quajak told me that the error is in IL2CPU, and told me to open an issue here, ill post the logs and the code of BeforeRun() (where is the error in, according to the logs) below.

LOGS (its in portuguese, and i removed the \Users<user>\ from the path):

Compilação iniciada...
1>------ Compilação iniciada: Projeto: PlatinumOS, Configuração: Debug Any CPU ------
1>Ignorando analisadores para acelerar a construção. Você pode executar o comando 'Build' ou 'Rebuild' para executar os analisadores.
1>PlatinumOS -> C:\Users\source\repos\PlatinumOS\bin\Debug\net6.0\PlatinumOS.dll
1>Message: Executing IL2CPU on assembly
1>Message: Kernel Base: Cosmos.System.Kernel
1>Message: Checking target assembly: C:\Users\source\repos\PlatinumOS\bin\Debug\net6.0\PlatinumOS.dll
1>Message : warning : Loading plugs from assembly: Cosmos.Core_Asm, Version=10.0.0.0, Culture=neutral, PublicKeyToken=5ae71220097cb983
1>Message : warning : Loading plugs from assembly: Cosmos.Core_Plugs, Version=10.0.0.0, Culture=neutral, PublicKeyToken=5ae71220097cb983
1>Message : warning : Loading plugs from assembly: Cosmos.Debug.Kernel.Plugs.Asm, Version=10.0.0.0, Culture=neutral, PublicKeyToken=5ae71220097cb983
1>Message : warning : Loading plugs from assembly: Cosmos.System2_Plugs, Version=10.0.0.0, Culture=neutral, PublicKeyToken=5ae71220097cb983
1>Detecting fields for type 'IL2CPU.Debug.Symbols.FIELD_INFO'
1>Detecting fields for type 'IL2CPU.Debug.Symbols.FIELD_MAPPING'
1>IL2CPU : error : Exception: System.Exception: Error compiling method 'SystemVoidPlatinumOSKernelBeforeRun': System.ArgumentNullException: Value cannot be null. (Parameter 'aType')
1> at Cosmos.IL2CPU.ILOp.SizeOfType(Type aType) in C:\Development\CosmosOS\IL2CPU\source\Cosmos.IL2CPU\ILOp.cs:line 619
1> at Cosmos.IL2CPU.ILOpCode.DoStackAnalysis(Stack1 aStack, UInt32& aStackOffset) in C:\Development\CosmosOS\IL2CPU\source\Cosmos.IL2CPU\ILOpCode.cs:line 356 1> at Cosmos.IL2CPU.MethodAnalysis.ILMethod.Analyse() in C:\Development\CosmosOS\IL2CPU\source\Cosmos.IL2CPU\MethodAnalysis\ILMethod.cs:line 48 1> at Cosmos.IL2CPU.AppAssembler.AnalyseMethodOpCodes(Il2cpuMethodInfo aMethod, List1 aOpCodes) in C:\Development\CosmosOS\IL2CPU\source\Cosmos.IL2CPU\AppAssembler.cs:line 493
1> at Cosmos.IL2CPU.AppAssembler.ProcessMethod(Il2cpuMethodInfo aMethod, List1 aOpCodes) in C:\Development\CosmosOS\IL2CPU\source\Cosmos.IL2CPU\AppAssembler.cs:line 475 1> ---> System.ArgumentNullException: Value cannot be null. (Parameter 'aType') 1> at Cosmos.IL2CPU.ILOp.SizeOfType(Type aType) in C:\Development\CosmosOS\IL2CPU\source\Cosmos.IL2CPU\ILOp.cs:line 619 1> at Cosmos.IL2CPU.ILOpCode.DoStackAnalysis(Stack1 aStack, UInt32& aStackOffset) in C:\Development\CosmosOS\IL2CPU\source\Cosmos.IL2CPU\ILOpCode.cs:line 356
1> at Cosmos.IL2CPU.MethodAnalysis.ILMethod.Analyse() in C:\Development\CosmosOS\IL2CPU\source\Cosmos.IL2CPU\MethodAnalysis\ILMethod.cs:line 48
1> at Cosmos.IL2CPU.AppAssembler.AnalyseMethodOpCodes(Il2cpuMethodInfo aMethod, List1 aOpCodes) in C:\Development\CosmosOS\IL2CPU\source\Cosmos.IL2CPU\AppAssembler.cs:line 493 1> at Cosmos.IL2CPU.AppAssembler.ProcessMethod(Il2cpuMethodInfo aMethod, List1 aOpCodes) in C:\Development\CosmosOS\IL2CPU\source\Cosmos.IL2CPU\AppAssembler.cs:line 475
1> --- End of inner exception stack trace ---
1> at Cosmos.IL2CPU.AppAssembler.ProcessMethod(Il2cpuMethodInfo aMethod, List1 aOpCodes) in C:\Development\CosmosOS\IL2CPU\source\Cosmos.IL2CPU\AppAssembler.cs:line 483 1> at Cosmos.IL2CPU.ILScanner.Assemble() in C:\Development\CosmosOS\IL2CPU\source\Cosmos.IL2CPU\ILScanner.cs:line 1044 1> at Cosmos.IL2CPU.ILScanner.Execute(MethodBase aStartMethod, IEnumerable1 plugsAssemblies) in C:\Development\CosmosOS\IL2CPU\source\Cosmos.IL2CPU\ILScanner.cs:line 278
1> at Cosmos.IL2CPU.CompilerEngine.Execute() in C:\Development\CosmosOS\IL2CPU\source\Cosmos.IL2CPU\CompilerEngine.cs:line 223
1>IL2CPU task took 00:00:12.7880164
1>Projeto de compilação pronto "PlatinumOS.csproj" -- FALHA.
========== Compilação: 0 bem-sucedida, 1 com falha, 0 atualizada, 0 ignorada ==========
=========== Decorrido 00:13,445 =========

CODE BeforeRun():
protected override void BeforeRun()
{
Sys.FileSystem.VFS.VFSManager.RegisterVFS(fs);

        var fstype = fs.GetFileSystemType;
        Console.ForegroundColor = ConsoleColor.Green;
        Console.Beep(300, 100);
        Console.WriteLine($"[OK] Initialized File System: {fstype}");
        Thread.Sleep(2000);
        Console.ResetColor();

        if (!Directory.Exists("0:\\System\\"))
        {
            Console.ForegroundColor = ConsoleColor.Green;
            fs.CreateDirectory("0:\\System\\");
            File.Create("0:\\System\\SystemConfig.cfg");
            File.WriteAllText("0:\\System\\SystemConfig.cfg", "SystemFilesCreated");
            fs.CreateDirectory("0:\\Users\\");
            Console.Beep(300, 100);
            Console.WriteLine($"[OK] Created System Configs");
            Console.ResetColor();
        }
        else
        {

        }
        
        if (!Directory.Exists("0:\\Users\\"))
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("[NO] User Found");
            Console.ResetColor();
            Console.Write("New User: ");
            var userName = Console.ReadLine();
            Console.Write("New Password: ");
            var passWord = Console.ReadLine();
            Console.WriteLine($"User {userName} Created");
            File.WriteAllText($"0:\\Users\\passwords.db", passWord);
            File.WriteAllText($"0:\\Users\\users.db", userName);
        }
        else
        {
            Console.ForegroundColor = ConsoleColor.Green;
            Console.Beep(300, 100);
            Console.Write("[OK] User Found");
            Console.ResetColor();
            var username = File.ReadAllText($"0:\\Users\\users.db");
            Console.WriteLine($"Logging in {username}...");
            Thread.Sleep(1500);                
            Console.Beep(50, 200);
            Console.Beep(250, 200);
            Console.Beep(500, 200);
            Console.Beep(750, 200);
            Console.Beep(1000, 200);
            Console.WriteLine("Logged in.");
            Console.WriteLine($"Welcome to PlatinumOS, {username}.");
            Console.Clear();
        }
    }

Problem with IEnumerable

Having this simply IEnumerable function:

        static IEnumerable<Command> RegisterAllCommands()
        {
            yield return new Echo();
            yield return new Help();
        }

If I simply call it:

 RegisterAllCommands();

I get Stack Overflow exception, a normal Net Core application does little better simply blocks as the IEnumerable is not evalutated.

Doing instead a simple empty foreach (I know I cannot call .ToList() / .ToArray() as that will be a call to a Linq method):

foreach (var c in RegisterAllCommands()) { }

I get this error from IL2CPU itself that make the compilation fail:

Error Exception: System.ArgumentException: 'this' type cannot be an interface itself

Add uint support to Conv_R4

Area of Cosmos - What area of Cosmos are we dealing with?

IL2CPU

Expected Behaviour - What do you think that should happen?

Should compile fine

Actual Behaviour - What unexpectedly happens?

Compilation fails

2>Detecting fields for type 'IL2CPU.Debug.Symbols.Method'
2>IL2CPU : error : Exception: System.Exception: Error compiling method 'SystemInt32cs_ttfTTFstbtt__run_charstringcs_ttfstbtt_fontinfopointerSystemInt32cs_ttfTTFstbtt__csctxpointer': System.NotSupportedException: Specified method is not supported.
2>   at Cosmos.IL2CPU.X86.IL.Conv_R4.Execute(Il2cpuMethodInfo aMethod, ILOpCode aOpCode) in C:\Users\FrancescoDettling\source\repos\Cosmos\IL2CPU\source\Cosmos.IL2CPU\IL\Conv_R4.cs:line 37
2>   at Cosmos.IL2CPU.AppAssembler.EmitInstructions(Il2cpuMethodInfo aMethod, List`1 aCurrentGroup, Boolean& emitINT3) in C:\Users\FrancescoDettling\source\repos\Cosmos\IL2CPU\source\Cosmos.IL2CPU\AppAssembler.cs:line 632
2>   at Cosmos.IL2CPU.AppAssembler.ProcessMethod(Il2cpuMethodInfo aMethod, List`1 aOpCodes) in C:\Users\FrancescoDettling\source\repos\Cosmos\IL2CPU\source\Cosmos.IL2CPU\AppAssembler.cs:line 476
2> ---> System.NotSupportedException: Specified method is not supported.
2>   at Cosmos.IL2CPU.X86.IL.Conv_R4.Execute(Il2cpuMethodInfo aMethod, ILOpCode aOpCode) in C:\Users\FrancescoDettling\source\repos\Cosmos\IL2CPU\source\Cosmos.IL2CPU\IL\Conv_R4.cs:line 37
2>   at Cosmos.IL2CPU.AppAssembler.EmitInstructions(Il2cpuMethodInfo aMethod, List`1 aCurrentGroup, Boolean& emitINT3) in C:\Users\FrancescoDettling\source\repos\Cosmos\IL2CPU\source\Cosmos.IL2CPU\AppAssembler.cs:line 632
2>   at Cosmos.IL2CPU.AppAssembler.ProcessMethod(Il2cpuMethodInfo aMethod, List`1 aOpCodes) in C:\Users\FrancescoDettling\source\repos\Cosmos\IL2CPU\source\Cosmos.IL2CPU\AppAssembler.cs:line 476
2>   --- End of inner exception stack trace ---
2>   at Cosmos.IL2CPU.AppAssembler.ProcessMethod(Il2cpuMethodInfo aMethod, List`1 aOpCodes) in C:\Users\FrancescoDettling\source\repos\Cosmos\IL2CPU\source\Cosmos.IL2CPU\AppAssembler.cs:line 482
2>   at Cosmos.IL2CPU.ILScanner.Assemble() in C:\Users\FrancescoDettling\source\repos\Cosmos\IL2CPU\source\Cosmos.IL2CPU\ILScanner.cs:line 1044
2>   at Cosmos.IL2CPU.ILScanner.Execute(MethodBase aStartMethod, IEnumerable`1 plugsAssemblies) in C:\Users\FrancescoDettling\source\repos\Cosmos\IL2CPU\source\Cosmos.IL2CPU\ILScanner.cs:line 278
2>   at Cosmos.IL2CPU.CompilerEngine.Execute() in C:\Users\FrancescoDettling\source\repos\Cosmos\IL2CPU\source\Cosmos.IL2CPU\CompilerEngine.cs:line 222

Reproduction - How did you get this error to appear?

Clone this repository: https://github.com/GoldenretriverYT/CosmosTTF/tree/implement-new-ttf
Then try to add it to your Cosmos OS. The method causing this error is stbtt__run_charstring in NewTTFLib.cs

Version - Were you using the User Kit or Dev Kit? And what User Kit version or Dev Kit commit (Cosmos, IL2CPU, X#)?

Latest DevKit

Multidimensional arrays issue.

From @lukaandjelkovic on November 2, 2015 12:39

From Gitter

int[,] map = new int[120, 25];

When i use multidimensional arrays, it shows this error:

SystemVoidSystemInt32arraySetSystemInt32SystemInt32SystemInt32' undefined C:\Program Files (x86)\MSBuild\Cosmos\Cosmos.targets
ThontOS\TriangleOS\bin\tt\TriangleBoot.asm:370905: error: symbol `SystemVoidSystemInt32arrayctorSystemInt32SystemInt32' undefined

Copied from original issue: CosmosOS/Cosmos#231

Yasm error: undefined symbol everywhere when trying to implement some C# code

https://gist.github.com/valentinbreiz/8b099c7acd93783e90d71e644f070519

Builds fine until it goes to YASM part

Edit: After a deeper investigation this method seems to be the problem:

private static int Str_Dump( ILuaState lua )
{
	lua.L_CheckType( 1, LuaType.LUA_TFUNCTION );
	lua.SetTop( 1 );
	var bsb = new ByteStringBuilder();
	LuaWriter writeFunc = 
		delegate(byte[] bytes, int start, int length)
	{
		bsb.Append(bytes, start, length);
		return DumpStatus.OK;
	};
	if( lua.Dump( writeFunc ) != DumpStatus.OK )
		return lua.L_Error( "unable to dump given function" );
	lua.PushString( bsb.ToString() );
	return 1;
}

Specially LuaWriter writeFunc = delegate(byte[] bytes, int start, int length)

Implement generic methods on arrays

From @jp2masa on February 21, 2017 19:19

Currently we don't handle generic methods on arrays.
Example:

IEnumerable<string> xEnumerable;
string[] xArray = new string[] { "a", "b", "c" };
xEnumerable = xArray;
xEnumerable.GetEnumerator();

This code won't work, because Array doesn't have an implementation for this method. Array can be used as ICollection<T>, IEnumerable<T> and IList<T>
The implementations for these interfaces are in System.SZArrayHelper, but the compiler needs an implementation that replaces calls to the generic method on arrays with calls to the methods in SZArrayHelper.

Copied from original issue: CosmosOS/Cosmos#583

Null checks are not working in arrays

The virtual machine shuts down when reading from a null item from an array.
Example code:

using System;
using System.Collections.Generic;
using System.Text;
using Sys = Cosmos.System;

namespace CosmosWeirdError
{
    public class Kernel : Sys.Kernel
    {
        MyClass[] SomeArray = new MyClass[2];
        protected override void BeforeRun()
        {
            try
            {
                Console.WriteLine("Cosmos booted successfully. Type a line of text to get it echoed back.");

                //This should cause a null refrence expection, but instead the VM shuts down or shows a random value
                Console.WriteLine(SomeArray[1].SomeValue);
            }
            catch(Exception x)
            {
                Console.WriteLine(x.Message);
            }
        }

        protected override void Run()
        {
            Console.Write("Input: ");
            var input = Console.ReadLine();
            Console.Write("Text typed: ");
            Console.WriteLine(input);
        }
    }
    public class MyClass
    {
        public byte SomeValue;
    }
}

il2cpu type error (int32*)

Area of Cosmos - What area of Cosmos are we dealing with?

compiler/il2cpu

Expected Behaviour - What do you think that should happen?

it should compile normally

Actual Behaviour - What unexpectedly happens?

l2cpu crashes and fails to compile

Reproduction - How did you get this error to appear?

use vs2022 branch and attempt to compile prism

Version - Were you using the User Kit or Dev Kit? And what User Kit version or Dev Kit commit (Cosmos, IL2CPU, X#)?

devkit, vs2022 branch

Screenshots

image
image

Misc

this issue can be fixeed by using an olt il2cpu repo version from at least march, so something changed recently

Implement endfilter opcode and plug Microsoft.VisualBasic.CompilerServices.Utils

Same new project...
If I use the IF or SELECT CASE statement I receve a "Exception: System.NotImplementedException: OpCode 'Endfilter' not implemented! SAM D:\Sviluppo vb.Net\Sistemi Operativi\SAM\SAM\IL2CPU" error. I try to move this code to other Class with the same error.
Version - Were you using the User Kit or Dev Kit? And what User Kit version or Dev Kit commit (Cosmos, IL2CPU, X#)? I download all new three days ago on my Lattepanda alpha.
I try compiling the solution here, using the precompiled versione...
Cosmos_Issue

Use ref locals to get class fields in Plugs

When there is the need to access a field of a class you have to add a ref variable to one of its plug method and use the attribute "FieldAccess" this could be easily become ugly when you need to access a lot of fields:

public static void Ctor(StreamWriter aThis, string path, bool append, Encoding encoding, int bufferSize,
                         [FieldAccess(Name = "System.IO.Stream System.IO.StreamWriter._stream")] ref Stream _stream,
                         [FieldAccess(Name = "System.Int32 System.IO.StreamWriter._charPos")] ref int _charPos,
                         [FieldAccess(Name = "System.Char[] System.IO.StreamWriter._charBuffer")] ref int _charLen,
                         [FieldAccess(Name = "System.Char[] System.IO.StreamWriter._charBuffer")] ref char[] _charBuffer,
                         [FieldAccess(Name = "System.Byte[] System.IO.StreamWriter._byteBuffer")] ref byte[] _byteBuffer,
                         [FieldAccess(Name = "System.Char[] System.IO.TextWriter.CoreNewLine")] ref char[] CoreNewLine
                        )

I've had two constructors to plug (one that take a String representing a File Path and an other in which you pass a Stream already created) and so the ideal solution would have been to use an utility function to initialize all the field but I will have to pass all the ref variables and their value to it that well defeat the purpose of it a lot!

My idea is leaving the attribute version for the old code (or replace it if we are so brave) and to use ref locals introduced in C# 7 to resolve this problem so the Init() would become:

private static void Init(Stream stream, bool append, CosmosEncoding encoding, int bufferSize,  bool shouldLeaveOpen) 
{
    ref Stream _stream = ref GetFieldAccess("System.IO.Stream System.IO.StreamWriter._stream");
    ref int _charPos = ref GetFieldAccess("System.Int32 System.IO.StreamWriter._charPos");
    ref char[] _charBuffer = ref GetFieldAccess("System.Char[] System.IO.StreamWriter._charBuffer");
    ref byte[] _byteBuffer = ref  GetFieldAccess("System.Byte[] System.IO.StreamWriter._byteBuffer");
    ref char[] CoreNewLine = ref  GetFieldAccess("System.Char[] System.IO.TextWriter.CoreNewLine");

    _stream = stream;
    [...]
}      

GetFieldAccess should have these prototypes:

ref object GetFieldAccess(String FieldName);
ref object[] GetFieldAccess(String FieldName);
unsafe ref void *GetFieldAccess(String FieldName); // Not working in C# 7.0 should be added in future releases

Struct member to object conversion

Possible issues

The convertion between a struct member to an object in IL2CPU might be not working for some reasons.

Log

System.Exception: OpCode IL_007D: Ldflda tries to pop item at stack position 0 with type Aura_OS.Core.VBE+ModeInfo&, but actual type is System.IntPtr

Example

public struct ModeInfo
{
    public byte bpp;
}
Console.WriteLine("BPP: " + ModeInfo.bpp);

Inserting PITTimers with abstracts voids as a dOnTrigger

Have you checked Github Issues for similar errors?
I have checked for other issues, but the only one that came up was unrelated to the issue whence this has arisen.
Exception
Post the exception returned by Visual Studio
"Exception: System.Exception: Error compiling method 'SystemVoidSystemCProcessingProcMGRKStartSystemCProcessingCriProc': System.Exception: After interpreting stack types, nothing changed! (First instruction needing types = IL_0020: Ldvirtftn)"
** VS Output Logs **
Post the entire output log given by Visual Studio for the build
https://pastebin.com/KuyrsEjX
To Reproduce
Describe any changes done to a clean kernel for this error to occur.
Inserting a PITTimer with a possibly-defined abstract void will cause this error in IL2CPU
Screenshots
If applicable, add screenshots to help explain your problem.
Screenshot (60)

Context
Before posting please confirm that the following are in order
[Yes] Both Cosmos VS Extensions are installed
[Yes] The Cosmos nuget packages are installed

Add any other context about the problem which might be helpful.
I am running the latest devkit.

error when trying to build from source code

dotnet gives this error: C:\Program Files\dotnet\sdk\7.0.302\NuGet.targets(398,5): error MSB3202: The project file "C:\Users\user\Downloads\IL2CPU-master\Common\source\Cosm
os.Build.Common\Cosmos.Build.Common.csproj" was not found. [C:\Users\user\Downloads\IL2CPU-master\IL2CPU-master\IL2CPU.sln]
C:\Program Files\dotnet\sdk\7.0.302\NuGet.targets(398,5): error MSB3202: The project file "C:\Users\user\Downloads\IL2CPU-master\Cosmos\source\Cosm
os.Debug.Kernel\Cosmos.Debug.Kernel.csproj" was not found. [C:\Users\user\Downloads\IL2CPU-master\IL2CPU-master\IL2CPU.sln]

Build FAILED.

C:\Program Files\dotnet\sdk\7.0.302\NuGet.targets(398,5): error MSB3202: The project file "C:\Users\user\Downloads\IL2CPU-master\Common\source\Cosm
os.Build.Common\Cosmos.Build.Common.csproj" was not found. [C:\Users\Eetu\Downloads\IL2CPU-master\IL2CPU-master\IL2CPU.sln]
C:\Program Files\dotnet\sdk\7.0.302\NuGet.targets(398,5): error MSB3202: The project file "C:\Users\user\Downloads\IL2CPU-master\Cosmos\source\Cosm
os.Debug.Kernel\Cosmos.Debug.Kernel.csproj" was not found. [C:\Users\user\Downloads\IL2CPU-master\IL2CPU-master\IL2CPU.sln]
0 Warning(s)
2 Error(s)

Implement sub.ovf.un

Implement sub.ovf.un, for:

  • 4 byte values (higher priority)
  • 8 byte values (lower priority)

x64 instructions

From @Hetal728 on January 2, 2015 20:52

x64 instructions would be a great enhancement, I could give it a shot if I figure out where/what I have to do.

Copied from original issue: CosmosOS/Cosmos#44

Exception: Interface maps for generic interfaces on arrays cannot be retrieved

I'm trying to make a shell in cosmos.
to split command and arguments this is the code i use:

public static IDictionary<string, Action<string[]>> commands = new Dictionary<string, Action<string[]>>(StringComparer.InvariantCultureIgnoreCase)
{
   {"help", Help.Run}
};
protected override void Run()
{
   string input = string.Empty;
   Console.Write($"{Color.LtGreen}$ {Color.White}");
   input = Console.ReadLine();

   string command = Regex.Replace(input.Split()[0], @"[^0-9a-zA-Z\]+", "");
   string[] args = input.Split(" ").Skip(1).ToArray();
   args = args.Where(x => !String.IsNullOrWhiteSpace(x)).ToArray();

   if (commands.Keys.Contains(command))
   {
       commands[command](args);
   }
   else
   {
       Console.WriteLine($"{Color.Red}Command Not Found!{Color.White}");
   }
}

but when i compile error shows up.

sorry for bad grammar.

Incorrect sorting in CompilerEngine.cs

Hello,
Looks like the LoadBootEntries method performs invalid ordering.

private void LoadBootEntries()
{

  ....
  mBootEntries = mBootEntries.OrderBy(e => e.Value)
                             .OrderByDescending(e => e.Value.HasValue)
                             .ToDictionary(e => e.Key, e => e.Value);
  ....
}

Most likely, there should be the ThenByDescending invocation instead of OrderByDescending.
Here is the link.

Please publish a release

Can you please publish a binary release so that I can download an .exe file rather than having to compile.

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.