The no_mangle attribute is unsafe since Rust 2024

This commit is contained in:
Philipp Oppermann
2025-03-27 15:39:15 +01:00
parent 9345886d44
commit 9753695744
47 changed files with 149 additions and 149 deletions

View File

@@ -105,7 +105,7 @@ pub fn test_runner(tests: &[&dyn Fn()]) {
#![reexport_test_harness_main = "test_main"]
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn _start() -> ! {
println!("Hello World{}", "!");
@@ -655,7 +655,7 @@ fn test_println_output() {
use core::panic::PanicInfo;
#[no_mangle] // don't mangle the name of this function
#[unsafe(no_mangle)] // don't mangle the name of this function
pub extern "C" fn _start() -> ! {
test_main();
@@ -738,7 +738,7 @@ pub fn test_panic_handler(info: &PanicInfo) -> ! {
/// Entry point for `cargo test`
#[cfg(test)]
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn _start() -> ! {
test_main();
loop {}
@@ -805,7 +805,7 @@ pub mod vga_buffer;
use core::panic::PanicInfo;
use blog_os::println;
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn _start() -> ! {
println!("Hello World{}", "!");
@@ -918,7 +918,7 @@ fn panic(_info: &PanicInfo) -> ! {
#![test_runner(test_runner)]
#![reexport_test_harness_main = "test_main"]
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn _start() -> ! {
test_main();
@@ -985,7 +985,7 @@ harness = false
use core::panic::PanicInfo;
use blog_os::{exit_qemu, serial_print, serial_println, QemuExitCode};
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn _start() -> ! {
should_fail();
serial_println!("[test did not panic]");

View File

@@ -109,7 +109,7 @@ pub fn test_runner(tests: &[&dyn Fn()]) {
#![reexport_test_harness_main = "test_main"]
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn _start() -> ! {
println!("Hello World{}", "!");
@@ -658,7 +658,7 @@ Rustにおける[結合テスト][integration tests]では、慣習としてプ
use core::panic::PanicInfo;
#[no_mangle] // この関数の名前を変えない
#[unsafe(no_mangle)] // この関数の名前を変えない
pub extern "C" fn _start() -> ! {
test_main();
@@ -740,7 +740,7 @@ pub fn test_panic_handler(info: &PanicInfo) -> ! {
/// `cargo test`のときのエントリポイント
#[cfg(test)]
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn _start() -> ! {
test_main();
loop {}
@@ -806,7 +806,7 @@ pub mod vga_buffer;
use core::panic::PanicInfo;
use blog_os::println;
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn _start() -> ! {
println!("Hello World{}", "!");
@@ -919,7 +919,7 @@ fn panic(_info: &PanicInfo) -> ! {
#![test_runner(test_runner)]
#![reexport_test_harness_main = "test_main"]
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn _start() -> ! {
test_main();
@@ -992,7 +992,7 @@ harness = false
use core::panic::PanicInfo;
use blog_os::{exit_qemu, serial_print, serial_println, QemuExitCode};
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn _start() -> ! {
should_fail();
serial_println!("[test did not panic]");

View File

@@ -108,7 +108,7 @@ fn test_runner(tests: &[&dyn Fn()]) {
#![reexport_test_harness_main = "test_main"]
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn _start() -> ! {
println!("Hello World{}", "!");
@@ -671,7 +671,7 @@ Rust에서는 [통합 테스트][integration tests]들을 프로젝트 루트에
use core::panic::PanicInfo;
#[no_mangle] // don't mangle the name of this function
#[unsafe(no_mangle)] // don't mangle the name of this function
pub extern "C" fn _start() -> ! {
test_main();
@@ -754,7 +754,7 @@ pub fn test_panic_handler(info: &PanicInfo) -> ! {
/// Entry point for `cargo test`
#[cfg(test)]
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn _start() -> ! {
test_main();
loop {}
@@ -820,7 +820,7 @@ pub mod vga_buffer;
use core::panic::PanicInfo;
use blog_os::println;
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn _start() -> ! {
println!("Hello World{}", "!");
@@ -936,7 +936,7 @@ fn panic(_info: &PanicInfo) -> ! {
#![test_runner(test_runner)]
#![reexport_test_harness_main = "test_main"]
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn _start() -> ! {
test_main();
@@ -1005,7 +1005,7 @@ harness = false
use core::panic::PanicInfo;
use blog_os::{exit_qemu, serial_print, serial_println, QemuExitCode};
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn _start() -> ! {
should_fail();
serial_println!("[test did not panic]");
@@ -1042,4 +1042,4 @@ fn panic(_info: &PanicInfo) -> ! {
## 다음 단계는 무엇일까요?
다음 글에서는 _CPU exception (예외)_ 에 대해 알아볼 것입니다. 분모가 0인 나누기 연산 혹은 매핑되지 않은 메모리 페이지에 대한 접근 (페이지 폴트) 등 허가되지 않은 작업이 일어났을 때 CPU가 예외를 발생시킵니다. 이러한 예외 발생을 포착하고 분석할 수 있어야 앞으로 커널에 발생할 수많은 오류를 디버깅할 수 있을 것입니다. 예외를 처리하는 과정은 하드웨어 인터럽트를 처리하는 과정(예: 컴퓨터의 키보드 입력을 지원할 때)과 매우 유사합니다.
다음 글에서는 _CPU exception (예외)_ 에 대해 알아볼 것입니다. 분모가 0인 나누기 연산 혹은 매핑되지 않은 메모리 페이지에 대한 접근 (페이지 폴트) 등 허가되지 않은 작업이 일어났을 때 CPU가 예외를 발생시킵니다. 이러한 예외 발생을 포착하고 분석할 수 있어야 앞으로 커널에 발생할 수많은 오류를 디버깅할 수 있을 것입니다. 예외를 처리하는 과정은 하드웨어 인터럽트를 처리하는 과정(예: 컴퓨터의 키보드 입력을 지원할 때)과 매우 유사합니다.

View File

@@ -102,7 +102,7 @@ To fix this, we first need to change the name of the generated function to somet
#![reexport_test_harness_main = "test_main"]
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn _start() -> ! {
println!("Hello World{}", "!");
@@ -659,7 +659,7 @@ All integration tests are their own executables and completely separate from our
use core::panic::PanicInfo;
#[no_mangle] // don't mangle the name of this function
#[unsafe(no_mangle)] // don't mangle the name of this function
pub extern "C" fn _start() -> ! {
test_main();
@@ -741,7 +741,7 @@ pub fn test_panic_handler(info: &PanicInfo) -> ! {
/// Entry point for `cargo test`
#[cfg(test)]
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn _start() -> ! {
test_main();
loop {}
@@ -807,7 +807,7 @@ Now we can update our `main.rs` to use the library:
use core::panic::PanicInfo;
use blog_os::println;
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn _start() -> ! {
println!("Hello World{}", "!");
@@ -920,7 +920,7 @@ This test is still incomplete as it doesn't define a `_start` function or any of
#![test_runner(test_runner)]
#![reexport_test_harness_main = "test_main"]
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn _start() -> ! {
test_main();
@@ -987,7 +987,7 @@ Now we vastly simplify our `should_panic` test by removing the `test_runner`-rel
use core::panic::PanicInfo;
use blog_os::{exit_qemu, serial_print, serial_println, QemuExitCode};
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn _start() -> ! {
should_fail();
serial_println!("[test did not panic]");

View File

@@ -106,7 +106,7 @@ pub fn test_runner(tests: &[&dyn Fn()]) {
#![reexport_test_harness_main = "test_main"]
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn _start() -> ! {
println!("Hello World{}", "!");
@@ -663,7 +663,7 @@ fn test_println_output() {
use core::panic::PanicInfo;
#[no_mangle] // don't mangle the name of this function
#[unsafe(no_mangle)] // don't mangle the name of this function
pub extern "C" fn _start() -> ! {
test_main();
@@ -745,7 +745,7 @@ pub fn test_panic_handler(info: &PanicInfo) -> ! {
/// Entry point for `cargo test`
#[cfg(test)]
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn _start() -> ! {
test_main();
loop {}
@@ -811,7 +811,7 @@ pub mod vga_buffer;
use core::panic::PanicInfo;
use blog_os::println;
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn _start() -> ! {
println!("Hello World{}", "!");
@@ -924,7 +924,7 @@ fn panic(_info: &PanicInfo) -> ! {
#![test_runner(test_runner)]
#![reexport_test_harness_main = "test_main"]
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn _start() -> ! {
test_main();
@@ -991,7 +991,7 @@ harness = false
use core::panic::PanicInfo;
use blog_os::{QemuExitCode, exit_qemu, serial_println, serial_print};
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn _start() -> ! {
should_fail();
serial_println!("[test did not panic]");