Skip to content

Various attributes and extern "C" must be marked "unsafe" to compile generated code #933

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/generate/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,10 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
}

out.extend(quote! {
// NOTE `no_mangle` is used here to prevent linking different minor versions of the device
// NOTE `unsafe(no_mangle)` is used here to prevent linking different minor versions of the device
// crate as that would let you `take` the device peripherals more than once (one per minor
// version)
#[no_mangle]
#[unsafe(no_mangle)]
static mut DEVICE_PERIPHERALS: bool = false;

/// All the peripherals.
Expand Down
24 changes: 12 additions & 12 deletions src/generate/interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ pub fn render(
.as_deref()
.unwrap_or(".vector_table.interrupts");
let link_section_attr = quote! {
#[link_section = #link_section_name]
#[unsafe(link_section = #link_section_name)]
};

root.extend(quote! {
#[cfg(feature = "rt")]
extern "C" {
unsafe extern "C" {
#(#names_cfg_attr fn #names();)*
}

Expand All @@ -144,7 +144,7 @@ pub fn render(
#[cfg(feature = "rt")]
#[doc(hidden)]
#link_section_attr
#[no_mangle]
#[unsafe(no_mangle)]
pub static __INTERRUPTS: [Vector; #n] = [
#elements
];
Expand All @@ -160,7 +160,7 @@ pub fn render(
.as_deref()
.unwrap_or(".vector_table.interrupts");
let link_section_attr = quote! {
#[link_section = #link_section_name]
#[unsafe(link_section = #link_section_name)]
};

root.extend(quote! {
Expand All @@ -179,7 +179,7 @@ pub fn render(
#[cfg(feature = "rt")]
#[doc(hidden)]
#link_section_attr
#[no_mangle]
#[unsafe(no_mangle)]
#[used]
pub static __INTERRUPTS:
[Vector; #n] = [
Expand All @@ -194,13 +194,13 @@ pub fn render(

let link_section_attr = config.interrupt_link_section.as_ref().map(|section| {
quote! {
#[link_section = #section]
#[unsafe(link_section = #section)]
}
});

root.extend(quote! {
#[cfg(feature = "rt")]
extern "C" {
unsafe extern "C" {
#(#names_cfg_attr fn #names();)*
}

Expand All @@ -214,7 +214,7 @@ pub fn render(
#[cfg(feature = "rt")]
#[doc(hidden)]
#link_section_attr
#[no_mangle]
#[unsafe(no_mangle)]
pub static __EXTERNAL_INTERRUPTS: [Vector; #n] = [
#elements
];
Expand All @@ -227,13 +227,13 @@ pub fn render(

let link_section_attr = config.interrupt_link_section.as_ref().map(|section| {
quote! {
#[link_section = #section]
#[unsafe(link_section = #section)]
}
});

root.extend(quote! {
#[cfg(feature = "rt")]
extern "C" {
unsafe extern "C" {
#(#names_cfg_attr fn #names();)*
}

Expand Down Expand Up @@ -414,7 +414,7 @@ pub fn render(
}

#[allow(non_snake_case)]
#[no_mangle]
#[unsafe(no_mangle)]
pub extern #abi fn $NAME() {
// check that the handler exists
let _ = $crate::interrupt::Interrupt::$NAME;
Expand All @@ -433,7 +433,7 @@ pub fn render(
};
($NAME:ident, $path:path) => {
#[allow(non_snake_case)]
#[no_mangle]
#[unsafe(no_mangle)]
pub extern #abi fn $NAME() {
// check that the handler exists
let _ = $crate::interrupt::Interrupt::$NAME;
Expand Down