CosmosOS / Cosmos

Cosmos is an operating system "construction kit". Build your own OS using managed languages such as C#, VB.NET, and more!
https://www.goCosmos.org
BSD 3-Clause "New" or "Revised" License
2.94k stars 552 forks source link

File.Exists() causes CPU Exception #3028

Open JeffTheK opened 6 months ago

JeffTheK commented 6 months ago

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

FileSystem

Expected Behaviour - What do you think that should happen?

File.Exists should return a bool

Actual Behaviour - What unexpectedly happens?

I get Cosmos CPU Exception, invalid opcode

Reproduction - How did you get this error to appear?

Use System.IO.File.Exists()

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

Latest dev kit, running using vmware on linux

Here's my code:

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

namespace TestKernel
{
    public class Kernel: Sys.Kernel
    {
        Sys.FileSystem.CosmosVFS fs = new Cosmos.System.FileSystem.CosmosVFS();

        protected override void BeforeRun()
        {
            Sys.FileSystem.VFS.VFSManager.RegisterVFS(fs);
            Console.WriteLine("Cosmos booted successfully. Type a line of text to get it echoed back.");
            Console.WriteLine("Testing FileExists");
            try
            {
                Console.WriteLine(System.IO.File.Exists(@"0:\test.txt"));
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e);
            }
        }

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

here's a screenshot of the error image

blackneeed commented 6 months ago

Try instead of initializing the fs immediately set it to null first and then in beforerun set it to a new instance

blackneeed commented 6 months ago

Since it probaly needs to do some more initialization in OnBoot which is called before BeforeRun but if you just init it immediately then its probaly not gonna work. @JeffTheK

JeffTheK commented 6 months ago

Just tried doing it the way you told me, I still get the same error

JeffTheK commented 6 months ago

In the first code i copied the initialization code from the docs, so i thought it would work

JeffTheK commented 6 months ago

Also Directory.Exists works fine, but File.Exists does not

zarlo commented 5 months ago

from memory there is a bug in the exception handler where it will some times kill the system i think it was something to do with stack corruption

ADev531 commented 5 months ago

Weird, I'm using old devkit and it's works...

zarlo commented 5 months ago

it works most of the time