Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .config/target-matrix.json
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
"runner": "ubuntu-24.04-riscv",
"contract": "nightly",
"components": "",
"timeout_minutes": 60,
"timeout_minutes": 120,
"verify_plan": false,
"cache": false,
"compile": "native",
Expand Down
3 changes: 2 additions & 1 deletion scripts/ci/native-platform.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ require_host() {

run_amx() {
local flags test_name
flags=$(sed -n 's/^flags[[:space:]]*: //p' /proc/cpuinfo | head -n 1)
flags=$(awk '/^flags[[:space:]]*:/ { sub(/^[^:]*:[[:space:]]*/, ""); print; exit }' /proc/cpuinfo)
[[ " $flags " == *" amx_tile "* ]] || fail "intel-spr runner does not expose AMX-TILE"
export CARGO_PROFILE_TEST_DEBUG=0

Expand All @@ -74,6 +74,7 @@ run_native_runtime() {
export RSCRYPTO_TEST_MODE=commit
if [[ "$platform" == rise-riscv ]]; then
export RSCRYPTO_CI_RESOURCE_PROFILE=constrained
export CARGO_PROFILE_TEST_DEBUG=0
apply_ci_resource_profile
elif [[ "$platform" == ibm-s390x ]]; then
export CARGO_TARGET_S390X_UNKNOWN_LINUX_GNU_RUSTFLAGS="-C target-feature=+vector"
Expand Down
2 changes: 1 addition & 1 deletion scripts/test/test-rsa-linux-asm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fail() {

[[ "$(uname -s)" == Linux && "$(uname -m)" == x86_64 ]] \
|| fail "requires a Linux x86-64 host"
flags=$(sed -n 's/^flags[[:space:]]*: //p' /proc/cpuinfo | head -n 1)
flags=$(awk '/^flags[[:space:]]*:/ { sub(/^[^:]*:[[:space:]]*/, ""); print; exit }' /proc/cpuinfo)
[[ " $flags " == *" bmi2 "* && " $flags " == *" adx "* ]] \
|| fail "requires BMI2 and ADX"

Expand Down
28 changes: 21 additions & 7 deletions tests/rsa_allocations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use core::{
alloc::{GlobalAlloc, Layout},
sync::atomic::{AtomicUsize, Ordering},
cell::Cell,
};
use std::alloc::System;

Expand All @@ -12,18 +12,30 @@ use rscrypto::{
RsaPssProfile, RsaPublicKey, RsaPublicKeyPolicy, RsaSignatureProfile, RsaX509PublicKey,
};

static ALLOCATIONS: AtomicUsize = AtomicUsize::new(0);
std::thread_local! {
static ALLOCATIONS: Cell<Option<usize>> = const { Cell::new(None) };
}
const ID_RSASSA_PSS_OID: &[u8] = &[0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0a];

struct CountingAlloc;

fn record_allocation() {
match ALLOCATIONS.try_with(|allocations| {
if let Some(count) = allocations.get() {
allocations.set(Some(count.strict_add(1)));
}
}) {
Ok(()) | Err(_) => {}
}
}

// SAFETY: CountingAlloc preserves the global allocator contract because:
// 1. Every allocation operation delegates to `System` with the original `Layout`.
// 2. Returned pointers and deallocations are exactly those produced/accepted by `System`.
// 3. The only added behavior is an atomic counter update independent of allocation memory.
// 3. The only added behavior is a thread-local counter update independent of allocation memory.
unsafe impl GlobalAlloc for CountingAlloc {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
ALLOCATIONS.fetch_add(1, Ordering::Relaxed);
record_allocation();
// SAFETY: Delegating allocation to `System` because:
// 1. `layout` is forwarded unchanged from the caller.
// 2. `System` is the platform allocator and defines the allocation contract.
Expand All @@ -38,7 +50,7 @@ unsafe impl GlobalAlloc for CountingAlloc {
}

unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
ALLOCATIONS.fetch_add(1, Ordering::Relaxed);
record_allocation();
// SAFETY: Delegating reallocation to `System` because:
// 1. `ptr` and `layout` identify an allocation owned by this allocator.
// 2. `new_size` is forwarded unchanged from the caller.
Expand Down Expand Up @@ -378,11 +390,13 @@ fn public_operation_input() -> Vec<u8> {
}

fn reset_allocations() {
ALLOCATIONS.store(0, Ordering::SeqCst);
ALLOCATIONS.set(Some(0));
}

fn allocation_count() -> usize {
ALLOCATIONS.load(Ordering::SeqCst)
ALLOCATIONS
.replace(None)
.expect("allocation counting must be enabled before reading it")
}

#[test]
Expand Down