Home  >  Article  >  Technology peripherals  >  Replace C++! 36,000 lines of Rust code rewrite the Windows kernel. This language was first used to repair elevators

Replace C++! 36,000 lines of Rust code rewrite the Windows kernel. This language was first used to repair elevators

王林
王林forward
2023-05-30 21:31:041558browse

Replacing C, Rust is really going to rewrite everything!

After gaining the favor of Linux, Google, Amazon Cloud and other major manufacturers, the latest explosive news-

Microsoft has rewritten the Windows kernel with 36,000 lines of Rust code .

And the progress is quite fast. Spoiler news for April, after two weeks, the internal preview version of Windows 11 has been used.

Microsoft Cloud Azure CTO excitedly shouted on Twitter:

If you join the Windows 11 Insider Preview internal test, you will experience the Windows kernel supported by Rust for the first time!

Replace C++! 36,000 lines of Rust code rewrite the Windows kernel. This language was first used to repair elevators

The rewritten kernel mainly includes two projects: DWriteCore and Win32 GDI, and has passed all Windows boot tests.

Among them, Win32 GDI was written in the late 1980s and early 1990s, and is an old code with more than 30 years of working experience.

The reason why it is now replaced by Rust is simple and crude:

The Rust language has extremely high memory security, and there are a large number of unsafe subroutines in the original kernel. It also disappeared after being rewritten. At the same time, the Rust language is more concise and efficient.

Public information also indicates that over time, the Windows kernel's adoption of Rust will be significantly expanded.

Not only is it favored by major manufacturers, Rust has also been the “most popular programming language” in the Stack Overflow developer survey for many years in a row. Recently, sudo and su, the basic tools of Unix systems, have also been rewritten in Rust.

But what’s a bit surprising is that when Rust was first invented, was actually for repairing elevators? ? ?

Decided to develop a new language after climbing 21 floors in anger

The origin of everything lies in one day in 2006, a man named Graydon Hoare(Graydon Hoare) The elevator in the apartment building where I lived was broken again.

For the nth time, he struggled to crawl to his home on the 21st floor while cursing. He couldn't figure out why the elevator system collapsed so easily? It shouldn’t be!

As a coder in a large factory, Brother Graydon feels that this matter is not impossible to solve.

He was 29 years old at the time and working part-time at the open source web browser Mozilla Company (the company behind Firefox) . As an industry insider, he knows that most elevator failures are caused by the programming language that easily introduces memory errors accidentally, causing software crashes.

At that time, elevator software was often written in C or C language.

Their advantages are compactness and speed, but the problem is that it is very easy to cause memory errors, lead to system crashes, and even security issues.

So he kept doing nothing. In order to stop climbing stairs, Brother Graydon simply decided to come up with a new programming language.

The goal is a language that is less prone to memory errors, preferably shorter and faster.

So, the Rust language was born.

And the name of Rust is also very interesting.

Rust has the same name as a fungus, the Chinese name of which is plant rust. Graydon commented that it is "over-designed for survival."

This kind of fungal biological structure is completely distributed, with no single point of failure in space. That is to say, removing any part alone will not affect its survival, and it is extremely robust.

Throughout the life cycle, Rust fungi have a total of 5 life forms, 3 of which can regress back to the previous form, which is almost equivalent to the fact that a butterfly can turn back into a caterpillar and grow again.

Moreover, Rust fungi can be parasitic on multiple hosts, which reflects the Rust language's emphasis on interoperability between languages.

Replace C++! 36,000 lines of Rust code rewrite the Windows kernel. This language was first used to repair elevators

△A plant with Rust (Sorry for those who are cryptophobic!)

After several years of solo development, Rust was acquired by Mozilla in 2009 Supported by the company's research institute; the project was announced in 2010.

During the development process, Rust has established a highly active community. Any developer can directly report bugs to this project or directly contribute source code.

In May 2015, Rust version 1.0 was officially released.

In just one year, Rust has attracted countless fans. Since 2016, it has been rated "the most popular programming language" by the Stack Overflow developer survey for 7 consecutive years.

The advantages that it relies on to continuously top the list are: first, fast running speed, second, high memory utilization, and third, prevention of segfaults.

In short, it is a powerful tool that can replace C/C in some parts.

So there is a saying in the code world that compares Rust to parkour. You can do high-risk moves, but it is not easy to hurt yourself.

In contrast, C can be seen as playing with a flaming chainsaw.

And by virtue of developing Rust, Brother Graydon also became famous in one battle.

In the following years, he also participated in the development of Swift.

This is also an interesting story. Compared to being a team leader, I seem to prefer doing front-line development.

He once said in response to "Why left the Rust team" that his personal emotional life suffered a heavy blow (divorce) around 2013, which resulted in him not having much energy to be responsible for the Rust team. Later, he was still the president of Mozilla. I worked on some projects that were low-key and not in a hurry to be launched, and then I left my job.

Until early 2016, he received a call from the Apple team, saying that they were looking for programmers to help develop Swift. "It was a non-leadership position that I preferred."

Relying on safety to become the darling of major manufacturers

But here, Rust’s legendary story is only half told.

With the original intention of "high safety", it has become increasingly popular among large manufacturers in recent years.

Not only Windows, but also mainstream systems such as Linux and Android have embraced Rust. The relationship between Amazon Cloud, Microsoft, Google and Rust has always been good.

The main reason for this may be that C/C is really not good at memory safety.

For exampleMicrosoft was very interested in Rust a few years ago. They identified it as a way to eliminate memory security vulnerabilities before product delivery. good idea.

In 2019, Microsoft admitted that 70% of the vulnerabilities disclosed by CVE in its products were memory security vulnerabilities caused by the use of C/C.

The Rust tool chain focuses on uncovering potential vulnerabilities in the code, which ideally reduces the possibility of the code being attacked.

On the other side, Rust has also been introduced into the Linux kernel.

Last year, at the 2022 Open Source Summit hosted by the Linux Foundation, Mr. Linus suddenly announced that Rust might be added to the next version!

This means that the official PR for Rust for Linux will be merged into the mainline of the Linux kernel.

(Rust for Linux is an organization that calls for the combination of Linux and Rust)

You must know that the Rust support patch alone has been released to the seventh version .

When the audience heard the news, they immediately burst into applause, so that it took Linus a while to calm everyone down.

A few months later, Linux version 6.1 was released, and the kernel added support for Rust, becoming the second official language besides C.

Google’s actions were actually earlier.

When Android 12 is released in 2021, it will be announced that it supports Rust. Since then, they have been expanding the use of Rust in the Android open source project.

However, Google’s approach is not to immediately replace C/C with Rust, but to write new code in Rust.

It can be seen from the official data that C and C still dominate, and the proportion of Rust is gradually increasing.

Replace C++! 36,000 lines of Rust code rewrite the Windows kernel. This language was first used to repair elevators

As of the end of last year, Google stated that no security vulnerabilities had been found in the parts of Android written in Rust.

This result is very important because it means that Rust can effectively prevent the most common vulnerability in Android-that is, memory safety vulnerability. Google's 22-year data shows that memory security vulnerabilities account for a very high proportion of all types of vulnerabilities.

Replace C++! 36,000 lines of Rust code rewrite the Windows kernel. This language was first used to repair elevators

In many components written in C/C (such as Bluetooth, NFC, etc.), there will be a vulnerability in every thousand lines of code . Based on this ratio,

Rust has probably blocked hundreds of vulnerabilities.

And based on its high concurrency advantages, using Rust in Android can further balance system security and latency. Generally speaking, some security measures will cause the programming language to slow down.

For example, using the new UWB stack, you can save several megabytes of memory and avoid some IPC delays by running through existing processes.

Amazon Cloud also likes Rust very much,

because it is also very nice in saving energy.

A study tested 27 programming languages ​​and found that C and Rust were 50% more efficient than Java and 98% more efficient than Python in terms of energy use.

But the problem of C has been mentioned many times, and there are many memory security vulnerabilities, so based on this, Rust wins again.

Replace C++! 36,000 lines of Rust code rewrite the Windows kernel. This language was first used to repair elevators

In fact, major manufacturers not only favor Rust, but even dote on it.

In 2020, Mozilla, the company behind Rust, announced large-scale layoffs, the Rust team was laid off, and the fate of Rust fell into huge uncertainty.

In order to avoid this hidden worry, major manufacturers such as Amazon, Microsoft, Google, and Huawei directly jointly launched a Rust non-profit foundation. Commitment to invest approximately US$1 million in budget within two years to support Rust project maintenance.

In the industry, Rust’s deeds are countless.

Recently, two core Unix-like utilities sudo and su are being rewritten in Rust; previously, GitHub changed its search engine to be based on Rust; Discord, a Go service, was also rewritten in Rust...

However, Rust also has shortcomings. For example, it is more difficult to learn later, and the development speed is much slower than Go and Java when you first get started.

So Rust has high praise, but its "sales rate" is still relatively average, and it may even be labeled as an "unpopular language".

Especially in China, the recruitment of Rust can be described as "pitifully few".

Some netizens are pessimistic:

Replace C++! 36,000 lines of Rust code rewrite the Windows kernel. This language was first used to repair elevators

For this reason, Rust is also further optimizing itself.

According to the Rust 2024 roadmap released by it, the official team will increase its efforts in lowering the learning threshold and strengthening ecological connections.

So, it’s still worth looking forward to how Rust will develop in the future~

The above is the detailed content of Replace C++! 36,000 lines of Rust code rewrite the Windows kernel. This language was first used to repair elevators. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:51cto.com. If there is any infringement, please contact admin@php.cn delete