Source: https://en.wikipedia.org/wiki/Rust_%28programming_language%29

The core of the modern system is based on operating system kernels, browsers, databases, and other software with complex data structures and extensive low-level operations. The languages that are traditionally used to write such programs are C, C ++, and others, which provide the programmer with direct access to memory and hardware. At the same time, the ability to directly manipulate low-level data structures is fraught with the risk of run-time errors due to the impossibility of guaranteed memory safety. A significant number of software vulnerabilities in the industry are caused by memory safety errors. The need to increase the level of security and protection has prompted the system software industry to turn to alternatives that provide memory safety. Such a transition will have many beneficial effects on the software industry, although it will be associated with performance overhead due to special precautions when working with memory. The study of memory safety and its impact on software is relevant for the entire industry. The main problem in migrating from C and C ++ to Rust is the difference in paradigms and syntax, as well as the necessity of overcoming the natural reluctance of developers to adopt a new programming language. Programmers who have written tens or hundreds of thousands of lines of code in C or C ++ confidently release code that implements various low-level operations, working directly with memory. The reason for this is the capabilities of these languages, which allow the programmer to take responsibility for the correctness of memory operations and the correctness of the program’s functioning as a whole. In Rust, memory management is controlled by the compiler, which tracks all operations with memory and protects against various errors at compile-time. Naturally, writing code in Rust requires a semantic analysis of the code and a close study of the data flow and memory flow. Thus, when porting code from C and C ++ to Rust, it becomes necessary to analyze the data structures and their layout in memory, which requires fundamentally new approaches in programming. When considering the migration of code from C and C ++ to Rust, the main question that arises is the performance of the code after migration. One of the main objections to the creation of such languages is the assumption that code written in them cannot achieve the necessary performance, which is due to the mandatory checking of all operations at the compilation stage. From the practical side, there is a decrease in performance due to additional checks when working with memory. However, in reality, the performance hit is minimal, since the compiler translates the high-level constructs used in Rust into highly optimized machine instructions. Unlike Rust, C and C ++ compilers have had decades of development and optimization experience. Thus, it is wrong to compare the performance of programs written in different languages without considering their implementation details and optimization. One of the main advantages of Rust is that it does not sacrifice performance for the sake of security, which is a fundamental advantage over unsafe languages like C and C ++. Since rewriting large software systems in a new programming language is a resource-intensive and time-consuming process, software companies are looking for alternatives to gradually port their codebase to the new language. To do this, they use Foreign Function Interfaces, which allow interacting with functions written in other languages by expanding the compiler’s capabilities. In practice, this means that code written in Rust is inserted into the code written in C or C ++. This approach is the fastest way to adopt the new programming language and protect the code from security issues associated with pointer overflow, use-after-free, double-free, and other vulnerabilities. At the same time, the interaction between safe Rust code and unsafe C and C ++ code requires additional security measures, which require analyzing memory accesses and wrapping them in unsafe blocks. To create software using such an approach, developers must have knowledge of both languages and the intricacies of working with pointers. Rewriting system software code from C and C ++ to safer and more reliable programming languages is a complicated and time-consuming process that requires additional security measures when interacting with code written in different languages using Foreign Function Interfaces. However, the benefits of adopting such methods and tools far outweigh the costs and complexities of the implementation. On the one hand, the compiler itself carries out many security checks, thereby eliminating the need for developers to study the memory structure and interact with it directly. On the other hand, Rust provides the opportunity to achieve the necessary performance without sacrificing system security, which makes it a promising programming language.

Sources

https://bidenwhitehouse.archives.gov/wp-content/uploads/2024/02/Final-ONCD-Technical-Repor t.pdf

Reference links