From 3ad39e9878310e5317ee73c9b353c1e2c1c5c4ee Mon Sep 17 00:00:00 2001 From: Richard Qin Date: Sat, 11 Jul 2026 22:48:30 +0800 Subject: lib: establish Zircon libc++ and KTL foundation --- lib/ktl/README.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 lib/ktl/README.md (limited to 'lib/ktl/README.md') diff --git a/lib/ktl/README.md b/lib/ktl/README.md new file mode 100644 index 0000000..667c678 --- /dev/null +++ b/lib/ktl/README.md @@ -0,0 +1,36 @@ +# Kernel Template Library + +The Kernel Template Library is a curated subset of the C++ standard library API +using the `ktl` namespace rather than the `std` namespace. When a specific +interface is deemed useful, safe, and appropriate for use in the kernel, it can +be added here. No `std` APIs are ever used directly in the kernel, only `ktl`. + +The API is a strict subset of the standard C++ library API aside from the +namespace. The header file names are mostly directly mapped as well: + + -> + +There can be exceptions. For example, is a very broad collection of +APIs and the ktl subset is more focused. So instead of there +are specific headers for the standard APIs from that are included, such +as for `ktl::unique_ptr` (`std::unique_ptr` in ). + +The implementation here simply leverages the libc++ implementation and defines +`using` aliases in the `ktl` namespace. It's expected that ktl will only ever +provide "header only" APIs. + +## ktl enforcement + +The [``](include/ktl/enforce.h) header file should be used in +most `.cc` files (but not `.h`) files meant only for the kernel environment. +That is, in `.cc` files that use the `` headers or use kernel-only +headers that use them. + +This file must appear last in the `#include` list and `clang-format` will +arrange that automatically. + +After this `#include` any use of the `std` identifier in C++ code will cause a +compile-time error. When such errors are encountered, the kernel code should +be checked for use of C++ standard library headers (with no `.h` in the name, +like `, etc.) that should be replaced with `` headers and for +`std::` names that should be replaced with `ktl::` names. -- cgit v1.2.3