.Net OS

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Post by Colonel Kernel »

MessiahAndrw wrote:Wouldn't this then make C# the perfect language for OSdeving?
In any language debate, "perfect" is too strong a word. ;)

I'd say it depends on what your goals are. For us hobbyists, I think we'd have a hard time getting the most out of a language like C#. If you only use the "unsafe" features of C#, you might as well use C or C++ IMO. To really take advantage of its safety, you'd need to implement a fairly robust in-kernel garbage collector and run-time library. Sounds like a lot of fun, but just implementing a kernel in C or C++ is already challenging enough IMO, at least for a first project. :)

Large-scale projects (commercial or open source) are a different story of course, since they have more resources and expertise available. I for one am keeping my goals limited because I actually want to get my OS into a reasonable state some time before I die. ;)
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
User avatar
AndrewAPrice
Member
Member
Posts: 2300
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Post by AndrewAPrice »

Colonel Kernel wrote:
MessiahAndrw wrote:Wouldn't this then make C# the perfect language for OSdeving?
In any language debate, "perfect" is too strong a word. ;)

I'd say it depends on what your goals are. For us hobbyists, I think we'd have a hard time getting the most out of a language like C#. If you only use the "unsafe" features of C#, you might as well use C or C++ IMO. To really take advantage of its safety, you'd need to implement a fairly robust in-kernel garbage collector and run-time library. Sounds like a lot of fun, but just implementing a kernel in C or C++ is already challenging enough IMO, at least for a first project. :)

Large-scale projects (commercial or open source) are a different story of course, since they have more resources and expertise available. I for one am keeping my goals limited because I actually want to get my OS into a reasonable state some time before I die. ;)
Do you mean like Singularity? Look at all the resources Microsoft have and so far all it does is load applications, multi-task, have a cool debugger and comes with 1000 page documents on memory management and security. Were it C++ instead of C# then they wouldn't spend so much time implementing global garbage collection theories and writing research documents than actually moving ahead and working on other things. But I guess they don't call it Microsoft 'Research' for nothing.

What I don't get about this whole Singularity "you can block programs with unsafe code from running" is wouldn't that mean a lot of programs could not use pointers? (The thing I don't like in C# is if I pass an object to a function, I don't know if I'm making a copy of it or a reference?) I guess it could be useful for systems without any sort of memory protection. But then, couldn't someone use a modified compiler so that it claims a program isn't using unsafe code when it actually is?
Last edited by AndrewAPrice on Wed Sep 12, 2007 1:24 am, edited 1 time in total.
My OS is Perception.
Zekrazey1
Member
Member
Posts: 37
Joined: Sat Mar 10, 2007 8:28 am

Post by Zekrazey1 »

Ideally, that unsafe compiler wouldn't compile/run :p. You may be able to make your own system unsafe, but the idea is that programs are checked/compiled by the system that's going to run them.
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Post by Colonel Kernel »

MessiahAndrw wrote:Look at all the resources Microsoft have and so far all it does is load applications, multi-task, have a cool debugger and comes with 1000 page documents on memory management and security.
That's a lot farther than most hobbyists get.
Were it C++ instead of C# then they wouldn't spend so much time implementing global garbage collection theories and writing research documents than actually moving ahead and working on other things. But I guess they don't call it Microsoft 'Research' for nothing.
Exactly, that would defeat the entire purpose of the project. They're looking at what advantages can be had by using a safe language like C# in all parts of the system.
What I don't get about this whole Singularity "you can block programs with unsafe code from running" is wouldn't that mean a lot of programs could not use pointers? (The thing I don't like in C# is if I pass an object to a function, I don't know if I'm making a copy of it or a reference?)
In C#, if you're passing an instance of a class, you're passing a reference. If you're passing an instance of a struct, you're passing a copy. Pointers have more power than is necessary for just passing by reference (e.g. -- the ability to do arithmetic on them, cast them arbitrarily to different types, etc.).
I guess it could be useful for systems without any sort of memory protection.
Exactly. Singularity by default runs everything in ring 0 in a single address space. Even though the primary goal of Singularity is dependability, better performance has been a nice side benefit (especially for IPC, which is zero-copy in Singularity).
But then, couldn't someone use a modified compiler so that it claims a program isn't using unsafe code when it actually is?
Yes, but that someone would have to install the modified compiler on the system somehow. Remember, the compiler we're talking about is an MSIL-to-x86 translator and optimizer. Singularity programs are deployed as MSIL binaries, not as source code.

In a future version of Singularity, they'll have the MSIL-to-x86 compiler ("Bartok") emit proofs along with the generated x86 code so that the code can be checked by a small verifier before being run. Currently Bartok is a "trusted" part of the system because they rely on it to reject any unsafe code.
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
User avatar
AndrewAPrice
Member
Member
Posts: 2300
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Post by AndrewAPrice »

Colonel Kernel wrote:
What I don't get about this whole Singularity "you can block programs with unsafe code from running" is wouldn't that mean a lot of programs could not use pointers? (The thing I don't like in C# is if I pass an object to a function, I don't know if I'm making a copy of it or a reference?)
In C#, if you're passing an instance of a class, you're passing a reference. If you're passing an instance of a struct, you're passing a copy. Pointers have more power than is necessary for just passing by reference (e.g. -- the ability to do arithmetic on them, cast them arbitrarily to different types, etc.).
Thanks. Now I know. But, say I have the following C# code (assuming MyClass is a class):

Code: Select all

public MyClass myClass1;

void MyFunction(MyClass myClass2)
{
   myClass1 = myClass2;
}
Am I making a copy of myClass2 and placing it in myClass1? If not, how do I make a copy so I can modify myClass1 without affecting myClass2?
My OS is Perception.
shiz98
Posts: 10
Joined: Sun Jul 29, 2007 8:59 pm

Post by shiz98 »

Here's a handy way of thinking about classes in C# (not exactly correct, but it helps get the concept).

When you declare an object in C#, you're really just creating a pointer. So in your example, myClass1 is really just a null pointer to a MyClass object. myClass2 also points to a MyClass object. So when you set myClass1 = myClass2, you're simply setting where myClass1 points to, which is now wherever myClass2 points to.

If you want to create a copy of an object, use the .Clone() method. It may not always be present. I believe the object has to implement the ICloneable interface. It's really kind of dangerous using the Clone method, because you have to worry about how deeply the object is cloned. For example, if the object you want to clone (we'll call it obj1) contains another object (obj2) inside it, you need to find out if obj2 is cloned as well when you clone obj1. Sometimes you'll find that obj2 isn't cloned, and that the pointer is simply passed along to the new object. If this happens and you modify obj2 in the cloned object, you're also modifying obj2 in the original object (obj1). Check it the MSDN documentation for the best explanation.
com1
Member
Member
Posts: 105
Joined: Sat Apr 28, 2007 11:57 am
Location: TN

first of all

Post by com1 »

first of all 'Crazed123' this is a forum for OS DEVELOPEMENT, not for calling people weenies and explaining why they are.
oh microsoft, microsoft, what souls you have dismayed
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Re: first of all

Post by pcmattman »

com1 wrote:first of all 'Crazed123' this is a forum for OS DEVELOPEMENT, not for calling people weenies and explaining why they are.
He called someone a weenie more than 6 months ago...
Sometimes you'll find that obj2 isn't cloned, and that the pointer is simply passed along to the new object. If this happens and you modify obj2 in the cloned object, you're also modifying obj2 in the original object (obj1).
I haven't done a lot of C# lately (the 2005 beta expired and I haven't really bothered to download the release version), but there's got to be some way of detecting this...
I believe the object has to implement the ICloneable interface.
Is it possible that in the implementation it checks its internal state and also clones any internal objects?
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Re: first of all

Post by Colonel Kernel »

pcmattman wrote:I haven't done a lot of C# lately (the 2005 beta expired and I haven't really bothered to download the release version), but there's got to be some way of detecting this...
What do you mean by "detecting" exactly? Cloning behaviour is one of those things that has to be designed into a class properly and documented well, just like when you implement a copy constructor and assignment operator in C++.
Is it possible that in the implementation it checks its internal state and also clones any internal objects?
At what time? When Clone() is called, yes -- that's how deep copies are implemented. I suppose you can also implement "copy-on-write" semantics and clone the inner object whenever a method is called that tries to modify it. This is usually not worth the hassle though.

I just want to mention this even though it's obvious, just in case anyone isn't already thinking it: If the inner object is immutable, there is no need to Clone() it.
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Re: first of all

Post by pcmattman »

Colonel Kernel wrote:
pcmattman wrote:I haven't done a lot of C# lately (the 2005 beta expired and I haven't really bothered to download the release version), but there's got to be some way of detecting this...
What do you mean by "detecting" exactly? Cloning behaviour is one of those things that has to be designed into a class properly and documented well, just like when you implement a copy constructor and assignment operator in C++.
I mean, in the Clone implementation, detect any objects that may need cloning.
Colonel Kernel wrote:
Is it possible that in the implementation it checks its internal state and also clones any internal objects?
At what time? When Clone() is called, yes -- that's how deep copies are implemented. I suppose you can also implement "copy-on-write" semantics and clone the inner object whenever a method is called that tries to modify it. This is usually not worth the hassle though.

I just want to mention this even though it's obvious, just in case anyone isn't already thinking it: If the inner object is immutable, there is no need to Clone() it.
I wasn't thinking it :cry: .
User avatar
AndrewAPrice
Member
Member
Posts: 2300
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Post by AndrewAPrice »

But, the same applies in C++. If you copy a class, but the class contains pointers, then the pointers in the new and old classes both point to the same objects. Hence, the copy constructor. I think the same principle applies in C# by overriding the Clone method by inheriting IClonable.
My OS is Perception.
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Re: first of all

Post by Colonel Kernel »

Colonel Kernel wrote:Cloning behaviour is one of those things that has to be designed into a class properly and documented well, just like when you implement a copy constructor and assignment operator in C++.
Beat you to it. ;)
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
User avatar
crazygray
Member
Member
Posts: 73
Joined: Sat Nov 03, 2007 10:17 am
Location: Toky,Japan

Post by crazygray »

Thank goodness there aren't any weenie/troll arguments going on any more.(Just wanted to say guys that was really getting on my nerves when I read this forum post)
Imagine if a creature came from a 4 dimensional world, would he think you to be flat?
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Post by Colonel Kernel »

crazygray wrote:Thank goodness there aren't any weenie/troll arguments going on any more.(Just wanted to say guys that was really getting on my nerves when I read this forum post)
Anything remotely related to Microsoft tends to bring the trolls out pretty fast. I guess we're like Slashdot in that respect. ;)
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
User avatar
AndrewAPrice
Member
Member
Posts: 2300
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Post by AndrewAPrice »

Colonel Kernel wrote:
crazygray wrote:Thank goodness there aren't any weenie/troll arguments going on any more.(Just wanted to say guys that was really getting on my nerves when I read this forum post)
Anything remotely related to Microsoft tends to bring the trolls out pretty fast. I guess we're like Slashdot in that respect. ;)
That usually seems to happen when people are like
"Let's make an OS in C#/VB.Net/JavaScript!!!! :D:D:D:D" and we're all saying "impossible!" "it can't be done!" "the language/technology doesn't allow for it!" and they release a few proof of concept alphas and it shuts us all up. :shock:
My OS is Perception.
Post Reply