Rust Gets Into The Kernel |
Written by Harry Fairhead | |||
Wednesday, 29 June 2022 | |||
To the innocent it sounds like this might be a serious problem, but to the initiated it sounds like a serious opportunity. The Rust of which we speak is, of course, the language, not the result of corrosion, and it could be the biggest change in programming for some time. Speaking at the Linux Foundation's Open Source Summit, Linus Torvalds revealed that he thinks that Rust might be ready for introduction into the next release, 5.20. In fact, the inclusion of Rust support could increase the version number to 6.0. This really is that big a change. Since Linux was no more than a few lines of code, that code has been written in C or assembler. Linus doesn't even allow C++ code, which is nominally compatible with C code, into the kernel. Indeed Linux is a testament to what you can do with C and nothing but C and one of the reasons to keep your C skills polished. Compare this to Windows where the OS team took to C++ with an enthusiasm that never faltered. Not only is Windows extensively written in C++, many of its APIs - COM in particular - only make sense when viewed through the eyes of a C++ programmer. This enthusiasm spread beyond the operating system to the languages that Windows favors and was certainly a big factor in .NET being sidelined in favor of COM-based components. Yes, Windows is an example of how choice of implementation language influences the flavor of an operating system. By comparison Linux has, until now, been a C operating system and C is its preferred language. Its system APIs are C first and other languages only with help. The need to use C facilities is often a downside to trying to use C++ for application programming. If language support in Linux needs extending, then the obvious one to choose is C++ and probably not Rust. So why not? The answer is mostly that Linus hates C++ and rightly so. If you regard C as being a language that it is easy to make mistakes in, C++ is almost designed to make subtle errors easier to write. While there are advantages in allowing modest extensions of C to include basic C++ objects, say, allowing the whole language in would result in a lower quality kernel. So what about Rust? Rust is supposedly a better and safer language with advanced features, notably the concepts of ownership and borrowing ownership. It is arguably more difficult to accidentally fall into the traps of buffer overrun, use after free and null pointer problems in Rust - but all this depends on not resorting to using the unsafe keyword which exposes Rust to the same dangers of C, but makes writing code easier. So will Rust make a huge difference? Not at first. At first you can expect it to be used for new drivers, although some driver writers are considering updating old drivers just to find out about Rust. There is also the difficulty that Rust isn't supported on the standard tooling - GCC in particular - and you have to use LLVM which currently doesn't support all of the architectures that Linux runs on. There is work on adding a Rust backend to GCC, but it isn't yet complete. However, the effect of Linux adoption of Rust cannot be underestimated. Rust is a language that we all like to talk about, but many hold off from actually committing to because it is still young and lacks many facilities. The fact that Linus thinks it's good enough to be used alongside his beloved C speaks in its favor like no other advocate could. If Rust does make it into Linux then it will have to grow up fast and as this happens its influence on the wider world should grow.
More InformationRelated ArticlesRust Bringing Greater Safety To Linux Rust Adds Source-based Code Coverage Rust Lang Releases 2024 Roadmap Rust 1.50 Improves Array Indexing To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.
Comments
or email your comment to: comments@i-programmer.info <ASIN:1871962617> <ASIN:1871962633> <ASIN:1871962609> <ASIN:1871962668> <ASIN:1871962641> <ASIN:187196265X> |
|||
Last Updated ( Wednesday, 29 June 2022 ) |