mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
macros: remove unused proc-macros crate
This crate held the `xous_main` proc_macro that was previously used when we were in `no_std` land. Since we now have a libstd, we can remove this crate and improve build times while having a standard `main()` function. Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
aa12a6e37f
commit
d2a6097e9f
5 changed files with 0 additions and 327 deletions
22
Cargo.lock
generated
22
Cargo.lock
generated
|
|
@ -2402,7 +2402,6 @@ dependencies = [
|
|||
"rand_chacha 0.2.2",
|
||||
"rand_core 0.5.1",
|
||||
"rand_hc",
|
||||
"rand_pcg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -2463,15 +2462,6 @@ dependencies = [
|
|||
"rand_core 0.5.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_pcg"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "16abd0c1b639e9eb4d7c50c0b8100b0d0f849be2349829c740fe8e6eb4816429"
|
||||
dependencies = [
|
||||
"rand_core 0.5.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "raw-window-handle"
|
||||
version = "0.3.4"
|
||||
|
|
@ -3998,11 +3988,9 @@ checksum = "d2d7d3948613f75c98fd9328cfdcc45acc4d360655289d0a7d4ec931392200a3"
|
|||
name = "xous"
|
||||
version = "0.9.7"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"compiler_builtins",
|
||||
"lazy_static",
|
||||
"rustc-std-workspace-core",
|
||||
"xous-macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -4025,16 +4013,6 @@ dependencies = [
|
|||
"xous",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "xous-macros"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"rand 0.7.3",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "xous-names"
|
||||
version = "0.9.7"
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ members = [
|
|||
"xous-ipc",
|
||||
"xous-rs",
|
||||
"tools",
|
||||
"macros",
|
||||
"services/aes-test",
|
||||
"services/graphics-server",
|
||||
"services/log-server",
|
||||
|
|
@ -102,7 +101,6 @@ incremental = true
|
|||
|
||||
[patch.crates-io]
|
||||
xous = {path = "xous-rs"}
|
||||
xous-macros = {path = "macros"}
|
||||
|
||||
# prefer hardware-accelerated versions of services
|
||||
[patch.crates-io.sha2]
|
||||
|
|
|
|||
98
macros/Cargo.lock
generated
98
macros/Cargo.lock
generated
|
|
@ -1,98 +0,0 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "237a5ed80e274dbc66f86bd59c1e25edc039660be53194b5fe0a482e0f2612ea"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "04f5f085b5d71e2188cb8271e5da0161ad52c3f227a661a3c135fdf28e258b12"
|
||||
dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.7.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
|
||||
dependencies = [
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
"rand_hc",
|
||||
"rand_pcg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
|
||||
|
||||
[[package]]
|
||||
name = "rand_hc"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
|
||||
dependencies = [
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_pcg"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "16abd0c1b639e9eb4d7c50c0b8100b0d0f849be2349829c740fe8e6eb4816429"
|
||||
dependencies = [
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.38"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e69abc24912995b3038597a7a593be5053eb0fb44f3cc5beec0deb421790c1f4"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
|
||||
|
||||
[[package]]
|
||||
name = "xous-macros"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"rand",
|
||||
"syn",
|
||||
]
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
[package]
|
||||
authors = [
|
||||
"Sean Cross <sean@xobs.io>"
|
||||
]
|
||||
categories = ["embedded", "no-std"]
|
||||
description = "Attributes re-exported in `xous`"
|
||||
documentation = "https://docs.rs/xous"
|
||||
keywords = ["xous", "runtime", "startup"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
name = "xous-macros"
|
||||
repository = "https://github.com/betrusted/xous-core"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
[lib]
|
||||
proc-macro = true
|
||||
|
||||
# Dependency policy: fully specify dependencies to the minor version number
|
||||
[dependencies]
|
||||
quote = "1.0"
|
||||
proc-macro2 = "1.0"
|
||||
|
||||
[dependencies.syn]
|
||||
version = "1.0"
|
||||
features = ["extra-traits", "full"]
|
||||
|
||||
[dependencies.rand]
|
||||
version = "0.7.3"
|
||||
default-features = false
|
||||
features = ["small_rng"]
|
||||
|
|
@ -1,175 +0,0 @@
|
|||
// #![deny(warnings)]
|
||||
|
||||
extern crate proc_macro;
|
||||
extern crate rand;
|
||||
#[macro_use]
|
||||
extern crate quote;
|
||||
extern crate core;
|
||||
extern crate proc_macro2;
|
||||
#[macro_use]
|
||||
extern crate syn;
|
||||
|
||||
use proc_macro2::Span;
|
||||
use rand::Rng;
|
||||
use rand::SeedableRng;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
use syn::{parse, spanned::Spanned, Ident, ItemFn, ReturnType, Type, Visibility};
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
|
||||
/// Attribute to declare the entry point of the program
|
||||
///
|
||||
/// **IMPORTANT**: This attribute must appear exactly *once* in the dependency graph. Also, if you
|
||||
/// are using Rust 1.30 the attribute must be used on a reachable item (i.e. there must be no
|
||||
/// private modules between the item and the root of the crate); if the item is in the root of the
|
||||
/// crate you'll be fine. This reachability restriction doesn't apply to Rust 1.31 and newer releases.
|
||||
///
|
||||
/// The specified function will be called by the reset handler *after* RAM has been initialized.
|
||||
/// If present, the FPU will also be enabled before the function is called.
|
||||
///
|
||||
/// The type of the specified function must be `[unsafe] fn() -> !` (never ending function)
|
||||
///
|
||||
/// # Properties
|
||||
///
|
||||
/// The entry point will be called by the reset handler. The program can't reference to the entry
|
||||
/// point, much less invoke it.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// - Simple entry point
|
||||
///
|
||||
/// ``` no_run
|
||||
/// # #![no_main]
|
||||
/// # use riscv_rt_macros::entry;
|
||||
/// #[entry]
|
||||
/// fn main() -> ! {
|
||||
/// loop {
|
||||
/// /* .. */
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
#[proc_macro_attribute]
|
||||
pub fn xous_main(args: TokenStream, input: TokenStream) -> TokenStream {
|
||||
let f = parse_macro_input!(input as ItemFn);
|
||||
|
||||
// check the function signature
|
||||
let valid_signature = f.sig.constness.is_none()
|
||||
&& f.sig.asyncness.is_none()
|
||||
&& f.vis == Visibility::Inherited
|
||||
&& f.sig.abi.is_none()
|
||||
&& f.sig.inputs.is_empty()
|
||||
&& f.sig.generics.params.is_empty()
|
||||
&& f.sig.generics.where_clause.is_none()
|
||||
&& f.sig.variadic.is_none()
|
||||
&& match f.sig.output {
|
||||
ReturnType::Default => false,
|
||||
ReturnType::Type(_, ref ty) => matches!(**ty, Type::Never(_)),
|
||||
};
|
||||
|
||||
if !valid_signature {
|
||||
return parse::Error::new(
|
||||
f.span(),
|
||||
"`#[xous_main]` function must have signature `[unsafe] fn() -> !`",
|
||||
)
|
||||
.to_compile_error()
|
||||
.into();
|
||||
}
|
||||
|
||||
if !args.is_empty() {
|
||||
return parse::Error::new(Span::call_site(), "This attribute accepts no arguments")
|
||||
.to_compile_error()
|
||||
.into();
|
||||
}
|
||||
|
||||
// XXX should we blacklist other attributes?
|
||||
let attrs = f.attrs;
|
||||
let unsafety = f.sig.unsafety;
|
||||
let hash = random_ident();
|
||||
let stmts = f.block.stmts;
|
||||
|
||||
let r = quote!(
|
||||
#[export_name = "xous_entry"]
|
||||
#(#attrs)*
|
||||
pub #unsafety fn #hash() -> ! {
|
||||
xous::init();
|
||||
#(#stmts)*
|
||||
}
|
||||
|
||||
xous::maybe_main!();
|
||||
);
|
||||
r.into()
|
||||
}
|
||||
|
||||
// Creates a random identifier
|
||||
/*
|
||||
Historical note -- this identifier was inherited from the Cortex libraries.
|
||||
Apparently, it serves just to prove that the initializing function was run at
|
||||
all, and does not create any sort of security property. It could be replaced
|
||||
with a "magic number" instead and achieve the same goal. From reading the rationale
|
||||
behind why the Cortex ecosystem does this, it's that a name like "__main" could accidentally
|
||||
be used by a developer and cause the system to be unsafe, and so by going with
|
||||
a pseudorandom identifier, it discourages programmers from accidental
|
||||
copy/pasta of well-known symbols and skipping certain initializations that are
|
||||
critical in the runtime to guarantee the safety properties that Rust depends
|
||||
upon.
|
||||
|
||||
Safety properties meaning, the Rust memory system has to reason about the type
|
||||
safety and initialization state of a program, and this starts with a base set
|
||||
of assumptions. The runtime is responsible for setting up these assumptions,
|
||||
and if they are wrong then the whole Rust memory system analysis is for naught.
|
||||
Because the Rust compiler can't "reason beyond the runtime", it becomes a hazard
|
||||
that a programmer unwittingly names their "main" function with a well-known
|
||||
symbol that doesn't have the proper initializations, and become confused as to
|
||||
why their programs don't work. Thus it seems that this random identifier is
|
||||
a way to "prove" that the run-time did its thing, without relying upon a symbol
|
||||
or name that could just be copy/pasted by the programmer without also copy/pasting
|
||||
its semantic significance.
|
||||
|
||||
This is not a "security-critical" random number because it's more of a check on
|
||||
programmer behavior; any attacker with the ability to write or modify this number
|
||||
also has the ability to modify the initialization routines anyways, and therefore
|
||||
promoting this to a true cryptographic random number doesn't solve any problem
|
||||
or necessarily protect the Rust type safety system from attacks against the
|
||||
initialization frameworks. To protect against that, the code base needs to be
|
||||
hashed and signed and checked against a signature, and not rely upon random
|
||||
identifiers which have no cryptographically essential correlation with the code around it.
|
||||
*/
|
||||
fn random_ident() -> Ident {
|
||||
let secs = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_secs();
|
||||
|
||||
let count = 1;
|
||||
let mut seed: [u8; 16] = [0; 16];
|
||||
|
||||
for (i, v) in seed.iter_mut().take(8).enumerate() {
|
||||
if (i * 8) >= 64 {
|
||||
*v = 0;
|
||||
} else {
|
||||
*v = ((secs >> (i * 8)) & 0xFF) as u8
|
||||
}
|
||||
}
|
||||
|
||||
for (i, v) in seed.iter_mut().skip(8).enumerate() {
|
||||
if (i * 8) >= 32 {
|
||||
*v = 0
|
||||
} else {
|
||||
*v = ((count >> (i * 8)) & 0xFF) as u8
|
||||
}
|
||||
}
|
||||
|
||||
let mut rng = rand::rngs::SmallRng::from_seed(seed);
|
||||
Ident::new(
|
||||
&(0..16)
|
||||
.map(|i| {
|
||||
if i == 0 || rng.gen() {
|
||||
(b'a' + rng.gen::<u8>() % 25) as char
|
||||
} else {
|
||||
(b'0' + rng.gen::<u8>() % 10) as char
|
||||
}
|
||||
})
|
||||
.collect::<String>(),
|
||||
Span::call_site(),
|
||||
)
|
||||
}
|
||||
Loading…
Reference in a new issue