OSDev.org
https://forum.osdev.org/

(Fixed) Array Triple Fault
https://forum.osdev.org/viewtopic.php?f=1&t=32215
Page 5 of 7

Author:  LtG [ Mon Jul 17, 2017 7:46 am ]
Post subject:  Re: Undefined Array Triple Fault

Octacone wrote:
LtG wrote:
So what happens if you single-step/breakpoint at the first instruction in Kernel_Main, what's the value of EAX, EBX, and the two multiboot variables you are passing onto the function?

Test with both versions, are they both correct? Does the MBI structure that is being pointed at by EBX look valid with both versions?

Also, which of the two side-by-side versions of disasm you showed works and which doesn't?

How do you handle global objects?


Left one works, right one doesn't.

Actually I found out what is going on.
When I comment out Call_Constructors(); GRUB doesn't report 16 KB any more.

Code:
//"Borrowed" from @max, was lazy to consider looking at it myself
typedef void (*function_pointer)();
extern "C" void* start_constructors;
extern "C" void* end_constructors;

extern "C" void Call_Constructors()
{
   function_pointer* start = (function_pointer*) & start_constructors;
   function_pointer* end = (function_pointer*) & end_constructors;
   for(function_pointer* current = start; current != end; current++)
   {
      (*current)();
   }
}


Inside linker's data block:
Code:
start_constructors = .;
*(.ctor*)
KEEP(*(.init_array));
KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*)));
end_constructors = .;



Where did you get the idea of doing it like that? Is there a reason you're doing it like that?

At least the Wiki doesn't seem to suggest anything like that..?

Author:  Octacone [ Mon Jul 17, 2017 7:57 am ]
Post subject:  Re: Undefined Array Triple Fault

LtG wrote:
Where did you get the idea of doing it like that? Is there a reason you're doing it like that?

At least the Wiki doesn't seem to suggest anything like that..?


It worked for other people, so I thought I would work for me too.
Wiki's article on that subject seems to be very clogged and bloated.

Author:  simeonz [ Mon Jul 17, 2017 10:25 am ]
Post subject:  Re: Undefined Array Triple Fault

Octacone wrote:
Wiki's article on that subject seems to be very clogged and bloated.
Here is another even more clogged and bloated article. :) There are detailed sections on initialization in it. (It is actually true that the Wiki shows the _init implementation for the init_array ABI, without handling .ctors.)

May be someone will correct me on this, but your approach should work in principle. You are not handling exceptions and per-thread storage, but that is not relevant. Still, it should be at least something like this in the linker script:
Code:
start_constructors = .;
KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
KEEP(*(.init_array .ctors))
end_constructors = .;
Particularly, the ctors must be inside KEEP. Assuming that doesn't fix the issue, as always, you need to trace your code with gdb and track which ctors are called and what memory they write to.

Author:  Octacone [ Mon Jul 17, 2017 10:38 am ]
Post subject:  Re: Undefined Array Triple Fault

simeonz wrote:
Octacone wrote:
Wiki's article on that subject seems to be very clogged and bloated.
Here is another even more clogged and bloated article. :) There are detailed sections on initialization in it. (It is actually true that the Wiki shows the _init implementation for the init_array ABI, without handling .ctors.)

May be someone will correct me on this, but your approach should work in principle. You are not handling exceptions and per-thread storage, but that is not relevant. Still, it should be at least something like this in the linker script:
Code:
start_constructors = .;
KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
KEEP(*(.init_array .ctors))
end_constructors = .;
Particularly, the ctors must be inside KEEP. Assuming that doesn't fix the issue, as always, you need to trace your code with gdb and track which ctors are called and what memory they write to.


That theme is just :-&, worse than "OMG Ponies". That article is just mind blowing, fame to anyone that can understand it.
Actually your example works too. I need it not to work in order for it to work, mind-blown yet? :P

Author:  dozniak [ Mon Jul 17, 2017 10:42 am ]
Post subject:  Re: Undefined Array Triple Fault

Looks like one of your ctors simply overwrites Multiboot_Info memory.

Author:  Octacone [ Mon Jul 17, 2017 10:48 am ]
Post subject:  Re: Undefined Array Triple Fault

dozniak wrote:
Looks like one of your ctors simply overwrites Multiboot_Info memory.


Is that my fault anyhow? :?

Author:  LtG [ Mon Jul 17, 2017 11:00 am ]
Post subject:  Re: Undefined Array Triple Fault

Octacone wrote:
dozniak wrote:
Looks like one of your ctors simply overwrites Multiboot_Info memory.


Is that my fault anyhow? :?


Are we supposed to know/guess what _all_ of your constructors do?

Btw, do you make any allocations (new/malloc) in any of your constructors?

Author:  Ch4ozz [ Mon Jul 17, 2017 11:08 am ]
Post subject:  Re: Undefined Array Triple Fault

Octacone wrote:
dozniak wrote:
Looks like one of your ctors simply overwrites Multiboot_Info memory.


Is that my fault anyhow? :?


Well obviously it is, Im pretty sure your using memory allocations in your constructor

Author:  iansjack [ Mon Jul 17, 2017 11:15 am ]
Post subject:  Re: Undefined Array Triple Fault

I'm not convinced that C++ is a good language for beginners to use for OS development.

Author:  Ch4ozz [ Mon Jul 17, 2017 11:39 am ]
Post subject:  Re: Undefined Array Triple Fault

iansjack wrote:
I'm not convinced that C++ is a good language for beginners to use for OS development.


Im somehow convinced that C++ and OOP itself is not truly meant for any critical hardware close running code.
I mean, you can use it in userspace as much as you love, but imo the kernel should be written in a language where you can manage memory perfectly even though it can be annoying.
OOP is a waste of memory and speed even on fast processors, ofcourse it obviously depends on functions and abstraction layers used such as virtual tables / jump tables whatsoever.

Author:  LtG [ Mon Jul 17, 2017 11:45 am ]
Post subject:  Re: Undefined Array Triple Fault

Ch4ozz wrote:
iansjack wrote:
I'm not convinced that C++ is a good language for beginners to use for OS development.


Im somehow convinced that C++ and OOP itself is not truly meant for any critical hardware close running code.
I mean, you can use it in userspace as much as you love, but imo the kernel should be written in a language where you can manage memory perfectly even though it can be annoying.
OOP is a waste of memory and speed even on fast processors.


I agree with most of what you two are saying, but OOP being a waste of memory and speed? You do realize that speed/RAM is orthogonal to OOP or lack thereof.

Of course it really depends on what type of kernel you are doing whether or not C++, or even plain old C, is a good idea. For a monolithic kernel I would think OOP is quite useful. While I'm not a huge fan of Linux, AFAIK they use OOP, though not C++.

Author:  iansjack [ Mon Jul 17, 2017 12:49 pm ]
Post subject:  Re: Undefined Array Triple Fault

I've nothing against OOP. My favourite OS was object oriented.

But I think C++ has too many pitfalls for beginners when it comes to low-level programming, linking with assembler routines, and the like. It's hard enough for some to realize that they can't use the C standard library when using C, let alone appreciating what they can and can't do with C++. I'm sure it's a fine language to use for someone who understands it fully.

Author:  simeonz [ Mon Jul 17, 2017 12:54 pm ]
Post subject:  Re: Undefined Array Triple Fault

When you manipulate different object types uniformly, you have polymorhism, C++ or not. Behavior variation requires data that specifies it, and the single pointer in C++ is pretty minimal cost. Error handling with branches, even if properly predicted by the CPU, should still be marginally slower in the normal path. It makes for a horribly looking coding style as well. Exceptions are slower in the failure path only, and it is rarely taken. Together with RAII, they make error handling much more capsulated affair. Templates offers type safe alternative to macros, and although it is true that sometimes compilers fail to chew them info efficient code, that depends on how extensively they are used and how deeply they are nested, as well as the compiler. Genericity is a very convenient library feature.

On the other hand, it is true that templates come at the cost of making the project header centric, and dependent on inclusion order. Also, polymorphism with some syntax features make the semantics so flexible, that the code looses its self-contained meaning and can become unpredictable. Exceptions introduce hidden control flow, which must be tracked at all times, and good knowledge of RAII becomes necessity. The biggest caveat in my opinion however is that people tend to produce high-level abstractions that eventually become costly. But this is not due to C++ in itself, but due to the comfort with which such abstractions are produced in OOP style. It is abstraction that is expensive, not C++.

Author:  LtG [ Mon Jul 17, 2017 1:12 pm ]
Post subject:  Re: Undefined Array Triple Fault

iansjack wrote:
I've nothing against OOP. My favourite OS was object oriented.

But I think C++ has too many pitfalls for beginners when it comes to low-level programming, linking with assembler routines, and the like. It's hard enough for some to realize that they can't use the C standard library when using C, let alone appreciating what they can and can't do with C++. I'm sure it's a fine language to use for someone who understands it fully.


I agree, especially as it appears to be the case in this thread. While the relevant Wiki articles might not be the most straightforward and easiest to read, choosing to "ignore" them seems to have caused almost endless problems..

What is this favorite OS? Btw, I'm sure you've made the distinction of having an OO OS as opposed to creating an OS in an OOP language.

Author:  Ch4ozz [ Mon Jul 17, 2017 1:26 pm ]
Post subject:  Re: Undefined Array Triple Fault

simeonz wrote:
When you manipulate different object types uniformly, you have polymorhism, C++ or not. Behavior variation requires data that specifies it, and the single pointer in C++ is pretty minimal cost. Error handling with branches, even if properly predicted by the CPU, should still be marginally slower in the normal path. It makes for a horribly looking coding style as well. Exceptions are slower in the failure path only, and it is rarely taken. Together with RAII, they make error handling much more capsulated affair. Templates offers type safe alternative to macros, and although it is true that sometimes compilers fail to chew them info efficient code, that depends on how extensively they are used and how deeply they are nested, as well as the compiler. Genericity is a very convenient library feature.

On the other hand, it is true that templates come at the cost of making the project header centric, and dependent on inclusion order. Also, polymorphism with some syntax features make the semantics so flexible, that the code looses its self-contained meaning and can become unpredictable. Exceptions introduce hidden control flow, which must be tracked at all times, and good knowledge of RAII becomes necessity. The biggest caveat in my opinion however is that people tend to produce high-level abstractions that eventually become costly. But this is not due to C++ in itself, but due to the comfort with which such abstractions are produced in OOP style. It is abstraction that is expensive, not C++.


Branch prediction works in 95% of the cases very well, I really dislike the way exceptions look like and work though.
Anyways you are are completely right, its not the fault of OOP languages but the people using them, I think I should have made that a bit more clear in my previous post.
The problem is the easier languages get for people, the more such people exist which leads to alot of bad written and slow software these days.

Page 5 of 7 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/