简体   繁体   English

如何在我的内核中使用 STLPort?

[英]How to use STLPort in my kernel?

I am developing a kernel in C++.我正在用 C++ 开发内核。 But I do not want to write a stdlib ;但我不想写一个stdlib for that purpose I have downloaded STLport http://www.stlport.org/ , but I don't know how to install and use it.为此,我下载了STLport http://www.stlport.org/ ,但我不知道如何安装和使用它。

I am using Linux for building my kernel.我正在使用 Linux 来构建我的内核。

How can I use c++ standard libs in my kernel?如何在我的内核中使用 C++ 标准库?

And I do not want to port all libs from STLport.而且我不想从 STLport 移植所有库。 How can I exclude a selection of libs?如何排除选择的库? Like std::string , std::vector etc.std::stringstd::vector等。

I would probably advise against using the STL in Kernel development.我可能会建议不要在内核开发中使用 STL。 STL will assume some form of standard library support of which there is none in your kernel. STL 将采用某种形式的标准库支持,而您的内核中没有这些支持。 Also most memory allocation operations have no bounds for the time that they can take and are therefore unsuitable for use in interrupt handlers.此外,大多数内存分配操作对它们可以花费的时间没有限制,因此不适合在中断处理程序中使用。 Exceptions are another thing that can cause major headaches in the kernel异常是另一件可能导致内核严重头痛的事情

In order for STL to work you have to port several things like static initialization (for ie std::cin and std::cout) and stack unwinding...为了让 STL 工作,你必须移植一些东西,比如静态初始化(例如 std::cin 和 std::cout)和堆栈展开......

you'd have to port ie: libsupc++ and have that in your kernel.你必须移植 ie: libsupc++ 并在你的内核中安装它。 Basically all this stuff shouldn't be in the Kernel in the first place.基本上所有这些东西一开始就不应该在内核中。 DON'T use Vectors use static arrays because vectors might reallocate your data!不要使用向量使用静态数组,因为向量可能会重新分配您的数据!

also all that stuff will bloat your kernel for nothing!所有这些东西都会使你的内核膨胀!

you can have a look what L4 allows itself to be used in kernel.你可以看看 L4 允许自己在内核中使用什么。 they don't do memory allocation and they don't do exceptions (unpredictable) and they especially don't do STL.他们不做内存分配,也不做异常(不可预测),尤其不做 STL。

The latter links shall give you an idea what you need to port to get c++ operating system support.后面的链接将使您了解需要移植什么才能获得 C++ 操作系统支持。 Libsupc++ is part of gcc. Libsupc++ 是 gcc 的一部分。 it's purpose is to encapsulate all the parts where runtime code is needed.它的目的是封装所有需要运行时代码的部分。

Useful information about libsupc++关于 libsupc++ 的有用信息

Useful information about c++ operating system support有关 C++ 操作系统支持的有用信息

I am not sure whether STL in kernel is actually good to have, but if you really want to try, it's very fun.我不确定内核中的 STL 是否真的很好,但如果你真的想尝试,它会很有趣。 I have written my own OS and when I had memory allocation in the kernel, the first thing I did was porting STLport (5.2.1).我已经编写了自己的操作系统,当我在内核中分配内存时,我做的第一件事就是移植 STLport (5.2.1)。 It was working well so far, although the kernel itself is still too preliminary.到目前为止,它运行良好,尽管内核本身仍然过于初级。

Anyway, I can share some experience on porting it.无论如何,我可以分享一些移植的经验。

  1. Porting STLport requires no building and very few prerequisites, just include the headers and let the compiler know it's path (-I option for gcc).移植 STLport 不需要构建和很少的先决条件,只需包含头文件并让编译器知道它的路径(gcc 的 -I 选项)。 The template classes will be compiled with your cpp source files.模板类将与您的 cpp 源文件一起编译。

  2. STLport is configurable, you can disable what you can't afford and select what you want, such as iostream, debug, exception, RTTI and threading. STLport 是可配置的,您可以禁用您负担不起的内容并选择您想要的内容,例如 iostream、调试、异常、RTTI 和线程。 Just checkout the documentation and then get to the configuration headers, it's very nicely commented (eg stlport/stl/config/user_config.h)只需查看文档然后进入配置标题,它的注释非常好(例如 stlport/stl/config/user_config.h)

  3. As the most basic you'll need malloc and free , or maybe new , delete and variants.作为最基本的,您将需要mallocfree ,或者可能是newdelete和变体。 That's enough for porting std string, containers and algorithms, IIRC.这足以移植标准字符串、容器和算法,IIRC。 But it's neither thread safe nor memory allocation optimized, you need to be very careful when you rely on it.但它既不是线程安全的,也不是内存分配优化的,你在依赖它时需要非常小心。

  4. You can do you own iostream, it's just template classes and global objects (BTW, I hacked ELF sections and manually initialized my global objects by calling the functions), but this needs more work.你可以自己做 iostream,它只是模板类和全局对象(顺便说一句,我破解了 ELF 部分并通过调用函数手动初始化了我的全局对象),但这需要更多的工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM