chore: checkpoint before Python removal

This commit is contained in:
2026-03-26 22:33:59 +00:00
parent 683cec9307
commit e568ddf82a
29972 changed files with 11269302 additions and 2 deletions

20
vendor/psm/examples/info.rs vendored Normal file
View File

@@ -0,0 +1,20 @@
extern crate psm;
psm::psm_stack_information! {
yes {
fn main() {
println!("Stack is {:?} and is at {:p} currently",
psm::StackDirection::new(), psm::stack_pointer());
}
}
no {
fn main() {
eprintln!("Stack information not supported by this target");
}
}
}
#[test]
fn run_example() {
main();
}

77
vendor/psm/examples/on_stack_fibo.rs vendored Normal file
View File

@@ -0,0 +1,77 @@
extern crate psm;
psm::psm_stack_manipulation! {
yes {
use std::alloc;
#[inline(never)]
fn fib(n: usize, stack_limit: *mut u8) -> Option<u64> {
// match psm::StackDirection::new() {
// psm::StackDirection::Ascending => if psm::stack_pointer() > stack_limit {
// return None;
// }
// psm::StackDirection::Descending => if psm::stack_pointer() < stack_limit {
// return None;
// }
// }
match n {
0 => Some(0),
1 => Some(1),
_ => fib(n - 1, stack_limit).and_then(|x| fib(n - 2, stack_limit).map(|y| x + y)),
}
}
const STACK_ALIGN: usize = 4096;
const STACK_REDLINE: usize = 512;
const FIB_COUNTS: [(usize, u64); 3] = [
(8, 21),
(16, 987),
(32, 2178309),
];
fn main() {
let mut stack_size = 1024 * 128;
unsafe {
for &(n, expected) in FIB_COUNTS.iter() {
loop {
println!("fib({}) with {} bytes of stack", n, stack_size - STACK_REDLINE);
let layout = alloc::Layout::from_size_align(stack_size, STACK_ALIGN).unwrap();
let new_stack = alloc::alloc(layout);
assert!(!new_stack.is_null(), "allocations must succeed!");
let max_stack = match psm::StackDirection::new() {
psm::StackDirection::Ascending =>
new_stack.offset((stack_size - STACK_REDLINE) as isize),
psm::StackDirection::Descending =>
new_stack.offset(STACK_REDLINE as isize),
};
let result = psm::on_stack(new_stack, stack_size, || {
fib(n, max_stack)
});
alloc::dealloc(new_stack, layout);
if let Some(res) = result {
assert_eq!(res, expected);
println!("fib({}) = {}", n, res);
break;
} else {
println!("Stack not large enough!");
stack_size *= 2;
}
}
}
}
}
}
no {
fn main() {
eprintln!("Stack manipulation not supported by this target");
}
}
}
#[test]
fn run_example() {
main()
}

View File

@@ -0,0 +1,53 @@
extern crate psm;
psm::psm_stack_manipulation! {
yes {
use std::alloc;
const STACK_ALIGN: usize = 4096;
const FRAME_SIZE: usize = 4096;
const FIB_COUNTS: [(usize, u64); 3] = [
(8, 21),
(16, 987),
(24, 46368),
];
#[inline(never)]
fn fib(n: usize) -> u64 {
unsafe {
let layout = alloc::Layout::from_size_align(FRAME_SIZE, STACK_ALIGN).unwrap();
let new_stack = alloc::alloc(layout);
assert!(!new_stack.is_null(), "allocations must succeed!");
let r = match n {
0 => 0,
1 => 1,
_ => {
psm::on_stack(new_stack, FRAME_SIZE, || {
fib(n - 1) + fib(n - 2)
})
}
};
alloc::dealloc(new_stack, layout);
r
}
}
fn main() {
for &(n, expected) in FIB_COUNTS.iter() {
let res = fib(n);
assert_eq!(res, expected);
println!("fib({}) = {}", n, res);
}
}
}
no {
fn main() {
eprintln!("Stack manipulation not supported by this target");
}
}
}
#[test]
fn run_example() {
main()
}

52
vendor/psm/examples/panics.rs vendored Normal file
View File

@@ -0,0 +1,52 @@
extern crate psm;
use std::panic;
const CHAIN_DEPTH: usize = 16;
psm::psm_stack_manipulation! {
yes {
use std::alloc;
const STACK_ALIGN: usize = 4096;
// Generating backraces (because of RUST_BACKTRACE) create a few quite large frames, so it is
// important, that all frames have sufficient amount of available memory to not run over the
// stack...
const FRAME_SIZE: usize = 4096 * 10;
fn panic_chain(depth: usize) {
if depth == 0 {
panic!("full chain!");
} else {
unsafe {
let layout = alloc::Layout::from_size_align(FRAME_SIZE, STACK_ALIGN).unwrap();
let new_stack = alloc::alloc(layout);
assert!(!new_stack.is_null(), "allocations must succeed!");
let p = psm::on_stack(new_stack, FRAME_SIZE, || {
panic::catch_unwind(|| {
panic_chain(depth - 1);
})
});
alloc::dealloc(new_stack, layout);
p.map_err(panic::resume_unwind).unwrap()
}
}
}
fn main() {
panic_chain(CHAIN_DEPTH);
}
#[test]
fn run_example() {
assert!(panic::catch_unwind(|| {
panic_chain(CHAIN_DEPTH);
}).is_err(), "Panic did not propagate!");
}
}
no {
fn main() {
eprintln!("Stack manipulation not supported by this target");
}
}
}

33
vendor/psm/examples/replace_stack_1.rs vendored Normal file
View File

@@ -0,0 +1,33 @@
extern crate psm;
psm::psm_stack_manipulation! {
yes {
use std::alloc;
const STACK_SIZE: usize = 4096 * 64;
const STACK_ALIGN: usize = 4096;
fn main() {
println!("current stack pointer is {:p}", psm::stack_pointer());
unsafe {
let new_stack = alloc::alloc(alloc::Layout::from_size_align(STACK_SIZE, STACK_ALIGN).unwrap());
println!("new stack is between {:p} and {:p}", new_stack, new_stack.offset(STACK_SIZE as isize));
psm::replace_stack(new_stack, STACK_SIZE, || {
println!("after replacement stack pointer is {:p}", psm::stack_pointer());
::std::process::exit(0);
});
}
}
}
no {
fn main() {
eprintln!("Stack manipulation not supported by this target");
}
}
}
#[test]
fn run_example() {
// NOTE: intentionally out-of-processes, as the example exits with `process::exit(0)`.
main()
}

60
vendor/psm/examples/thread.rs vendored Normal file
View File

@@ -0,0 +1,60 @@
extern crate psm;
psm::psm_stack_manipulation! {
yes {
use std::alloc;
const STACK_ALIGN: usize = 4096;
const FRAME_SIZE: usize = 4096;
const FIB_COUNTS: [(usize, u64); 3] = [
(8, 21),
(16, 987),
(24, 46368),
];
#[inline(never)]
fn fib(n: usize) -> u64 {
unsafe {
let layout = alloc::Layout::from_size_align(FRAME_SIZE, STACK_ALIGN).unwrap();
let new_stack = alloc::alloc(layout);
assert!(!new_stack.is_null(), "allocations must succeed!");
let r = match n {
0 => 0,
1 => 1,
_ => {
psm::on_stack(new_stack, FRAME_SIZE, || {
fib(n - 1) + fib(n - 2)
})
}
};
alloc::dealloc(new_stack, layout);
r
}
}
fn main() {
for (n, expected, handle) in FIB_COUNTS.iter().map(|&(n, expected)|
(n, expected, std::thread::spawn(move || {
fib(n)
}))
) {
if let Ok(res) = handle.join() {
assert_eq!(res, expected);
println!("fib({}) = {}", n, res);
} else {
panic!("joining a thread returned an Err");
}
}
}
}
no {
fn main() {
eprintln!("Stack manipulation not supported by this target");
}
}
}
#[test]
fn run_example() {
main()
}