Minimal C++-Runtime on L4-Microkernel
Idea and Concept
In the DROPS L4Env integration, the C++ - runtime needs many L4env services.
What support do we need for exception handling ?
We want a very low level support for the exception handling for:
- We want to write Boot-Servers in C++.
We want for RAMS (or ACE,Boost)a Low level-Integration, for example for the Shadow-Segments and other memory-qualities.
- A low level exception-handling will be good for an L4-C++-API with exceptions for systemcalls. We wish to have exceptions from L4-systemcalls from an L4 C++-API without big wrappers.
- It will be good for L4 to use standard interfaces like COSNaming or COSEvent/COSNotification.
To be compatible and to be more comfortable, it would be great to raise exceptions.
Other Ideas
- Namespaces
- There could be Namespaces for
- L4-Systemcalls
- the cstdlib
Exception Handling in gcc/g++
After Linux from Scratch provides libsupc++ support for the c++ programming language.
We find here:
- new and delete-Operators
- C++-RTTI Runtime-Type-Information
- routines for exception handling.
An overview is found here and some remarks.
The main work is done in the language independent unwind mechanism (Files unwind*).
Critique
At the first throw the compile time information is interpreted and dynamical structures (malloc) are build. The code is brilliant, but hard to understand.
Some people don't want such a code in boot servers for performance and security reasons.
It seems, that nearly the whole classifications could be made at compiletime, and kept in the binary. For an alternative implementation, the idea of the Relative Pointers could be useful.
What we need
- dynamic memory management malloc and free
- the oskit implements it for us. Perhaps the above idea with the (more) static compiled exception-Tables could reduce the use.
- Thread Specific Storage
- Each thread in a C++ program has access to a __cxa_eh_globals object.
Discussion:
- In the pattern-Book II a important usage of thread specific storage is the errno-variable. I think, the try/catch-mechanism is a more elegant solution. In the implementation of a systemcall the errno is set in the stub. Thus we need other stubs ...
- If we have an object oriented thread wrapper, this thread-Wrapper may serve ans a TSS.
- The only TSS we need are the __cxa_eh_globals of the libsub++.
We implement this in a static array, were the Thread-Id is the key.
- Thread-Abstraction
- There exists a C-Interface for Threads : ./c++/3.2/i386-redhat-linux/bits/gthr.h.
I have ported a gthr-l4min.h which seems to be sufficcient for the need of C++. Objective C needs more. In this I used the primitivest locks from l4/util/lock.h)
- registering in the start-code
-
Fazit
- The exception-Handling mechanism is nearly elementary and the realisation
of the idea is possible. We have stripped down the linux-Implementation.
- Code compiles and links
- The Machanism is algorithmicaly complicated and the implementation difficult to understand.
- I learned printf-Debugging and the playing with objdump, and the linker, and a lot of the implementation of exceptions, but I don't understand all the details.
- In the summer-Version the orginal crtbegin.c was reused for calling the Constructors.
- The code
Bugs Summer 2003
- The calling from the startcode must be wrong. In our litte Example the Frame isn't found.
- We can call the constructors, but not the destructores
- Integration in the BID-Build-Environment.
Chances 10.1.2004
- Throw away the crtbegin-Things, the l4-things are good
- Steal l4/pkg/cxx/lib/start/src/cxx_* from Alexander Warg
The Threadabstraction is beautifull, but there may
be other Thread-Wrapper and we let the user the choise
- Open Question: how to programm frame_dummy ?
- code v2
Bugs remains:
- crt0_destruction don't exist, static destructores are not called
Lessons learned
The Startcode and the linkerscript
(Caution: I used a Version from Juli :-)
The l4/pkg/crtx/lib/src/crt0_getopt.S don't call the constructors.
Later I have read, that there is a Problem with location the .init-Section.
But I don't knew and tried it and this worked.
But in the mean time, there is only one crt0 for all since 10.1.2004
we use this.
Computer science and network assocation Ravensburg Rudolf Weber