This commit is contained in:
d2weber 2024-09-10 18:06:09 +02:00
parent 54905ee17a
commit b59e494ae7
No known key found for this signature in database
GPG Key ID: 400413E7AC36EEA4
3 changed files with 29 additions and 9 deletions

View File

@ -47,3 +47,11 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Run Tests nightly - name: Run Tests nightly
run: ./ci.sh test nightly run: ./ci.sh test nightly
test-build-16bit:
runs-on: ubuntu-22.04
continue-on-error: true
steps:
- uses: actions/checkout@v4
- name: Build for target with 16 bit pointer
run: ./ci.sh build_16bit

14
ci.sh
View File

@ -82,6 +82,16 @@ clippy() {
cargo +$MSRV clippy --tests --examples -- -D warnings cargo +$MSRV clippy --tests --examples -- -D warnings
} }
build_16bit() {
rustup toolchain install nightly
rustup +nightly component add rust-src
TARGET_WITH_16BIT_POINTER=msp430-none-elf
for features in ${FEATURES_CHECK[@]}; do
cargo +nightly build -Z build-std=core,alloc --target $TARGET_WITH_16BIT_POINTER --no-default-features --features=$features
done
}
coverage() { coverage() {
for features in ${FEATURES_TEST[@]}; do for features in ${FEATURES_TEST[@]}; do
cargo llvm-cov --no-report --no-default-features --features "$features" cargo llvm-cov --no-report --no-default-features --features "$features"
@ -121,6 +131,10 @@ if [[ $1 == "clippy" || $1 == "all" ]]; then
clippy clippy
fi fi
if [[ $1 == "build_16bit" || $1 == "all" ]]; then
build_16bit
fi
if [[ $1 == "coverage" || $1 == "all" ]]; then if [[ $1 == "coverage" || $1 == "all" ]]; then
coverage coverage
fi fi

View File

@ -5,7 +5,7 @@
use core::fmt::Display; use core::fmt::Display;
#[cfg(feature = "async")] #[cfg(feature = "async")]
use core::task::Waker; use core::task::Waker;
use core::{cmp, fmt, mem}; use core::{fmt, mem};
#[cfg(feature = "async")] #[cfg(feature = "async")]
use crate::socket::WakerRegistration; use crate::socket::WakerRegistration;
@ -510,6 +510,7 @@ impl<'a> Socket<'a> {
// [...] the above constraints imply that 2 * the max window size must be less // [...] the above constraints imply that 2 * the max window size must be less
// than 2**31 [...] Thus, the shift count must be limited to 14 (which allows // than 2**31 [...] Thus, the shift count must be limited to 14 (which allows
// windows of 2**30 = 1 Gbyte). // windows of 2**30 = 1 Gbyte).
#[cfg(not(target_pointer_width = "16"))] // Prevent overflow
if rx_capacity > (1 << 30) { if rx_capacity > (1 << 30) {
panic!("receiving buffer too large, cannot exceed 1 GiB") panic!("receiving buffer too large, cannot exceed 1 GiB")
} }
@ -676,10 +677,7 @@ impl<'a> Socket<'a> {
/// Used in internal calculations as well as packet generation. /// Used in internal calculations as well as packet generation.
#[inline] #[inline]
fn scaled_window(&self) -> u16 { fn scaled_window(&self) -> u16 {
cmp::min( u16::try_from(self.rx_buffer.window() >> self.remote_win_shift).unwrap_or(u16::MAX)
self.rx_buffer.window() >> self.remote_win_shift as usize,
(1 << 16) - 1,
) as u16
} }
/// Return the last window field value, including scaling according to RFC 1323. /// Return the last window field value, including scaling according to RFC 1323.
@ -698,7 +696,7 @@ impl<'a> Socket<'a> {
let last_win = (self.remote_last_win as usize) << self.remote_win_shift; let last_win = (self.remote_last_win as usize) << self.remote_win_shift;
let last_win_adjusted = last_ack + last_win - next_ack; let last_win_adjusted = last_ack + last_win - next_ack;
Some(cmp::min(last_win_adjusted >> self.remote_win_shift, (1 << 16) - 1) as u16) Some(u16::try_from(last_win_adjusted >> self.remote_win_shift).unwrap_or(u16::MAX))
} }
/// Set the timeout duration. /// Set the timeout duration.
@ -2335,7 +2333,7 @@ impl<'a> Socket<'a> {
State::SynSent | State::SynReceived => { State::SynSent | State::SynReceived => {
repr.control = TcpControl::Syn; repr.control = TcpControl::Syn;
// window len must NOT be scaled in SYNs. // window len must NOT be scaled in SYNs.
repr.window_len = self.rx_buffer.window().min((1 << 16) - 1) as u16; repr.window_len = u16::try_from(self.rx_buffer.window()).unwrap_or(u16::MAX);
if self.state == State::SynSent { if self.state == State::SynSent {
repr.ack_number = None; repr.ack_number = None;
repr.window_scale = Some(self.remote_win_shift); repr.window_scale = Some(self.remote_win_shift);
@ -3075,7 +3073,7 @@ mod test {
ack_number: Some(REMOTE_SEQ + 1), ack_number: Some(REMOTE_SEQ + 1),
max_seg_size: Some(BASE_MSS), max_seg_size: Some(BASE_MSS),
window_scale: Some(*shift_amt), window_scale: Some(*shift_amt),
window_len: cmp::min(*buffer_size, 65535) as u16, window_len: u16::try_from(*buffer_size).unwrap_or(u16::MAX),
..RECV_TEMPL ..RECV_TEMPL
}] }]
); );
@ -3810,7 +3808,7 @@ mod test {
ack_number: None, ack_number: None,
max_seg_size: Some(BASE_MSS), max_seg_size: Some(BASE_MSS),
window_scale: Some(*shift_amt), window_scale: Some(*shift_amt),
window_len: cmp::min(*buffer_size, 65535) as u16, window_len: u16::try_from(*buffer_size).unwrap_or(u16::MAX),
sack_permitted: true, sack_permitted: true,
..RECV_TEMPL ..RECV_TEMPL
}] }]