From 1bf9be5f05937025c2b8169b4d4016c50e4ed09d Mon Sep 17 00:00:00 2001 From: d2weber <29163905+d2weber@users.noreply.github.com> Date: Tue, 10 Sep 2024 18:06:09 +0200 Subject: [PATCH 1/5] Fixes #982 --- src/socket/tcp.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/socket/tcp.rs b/src/socket/tcp.rs index f944875ad..2bead6a65 100644 --- a/src/socket/tcp.rs +++ b/src/socket/tcp.rs @@ -510,6 +510,7 @@ impl<'a> Socket<'a> { // [...] 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 // windows of 2**30 = 1 Gbyte). + #[cfg(not(target_pointer_width = "16"))] // Prevent overflow if rx_capacity > (1 << 30) { 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. #[inline] fn scaled_window(&self) -> u16 { - cmp::min( - self.rx_buffer.window() >> self.remote_win_shift as usize, - (1 << 16) - 1, - ) as u16 + u16::try_from(self.rx_buffer.window() >> self.remote_win_shift as usize).unwrap_or(u16::MAX) } /// Return the last window field value, including scaling according to RFC 1323. @@ -2334,7 +2332,7 @@ impl<'a> Socket<'a> { State::SynSent | State::SynReceived => { repr.control = TcpControl::Syn; // 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 { repr.ack_number = None; repr.window_scale = Some(self.remote_win_shift); From 021d35a274be81c8d862c041a2973feba9ffaee3 Mon Sep 17 00:00:00 2001 From: d2weber <29163905+d2weber@users.noreply.github.com> Date: Tue, 17 Sep 2024 18:52:01 +0200 Subject: [PATCH 2/5] Add build_16 bit to ci --- .github/workflows/test.yml | 8 ++++++++ ci.sh | 17 +++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4a13ca959..a3e79ec6e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -47,3 +47,11 @@ jobs: - uses: actions/checkout@v4 - name: Run Tests 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 diff --git a/ci.sh b/ci.sh index 109047719..5aa5583a7 100755 --- a/ci.sh +++ b/ci.sh @@ -44,6 +44,10 @@ FEATURES_CHECK=( "defmt,alloc,medium-ip,medium-ethernet,proto-ipv6,proto-ipv6,multicast,proto-dhcpv4,socket-raw,socket-udp,socket-tcp,socket-icmp,socket-dns,async" ) +FEATURES_NO_STD=( + "alloc,defmt,medium-ethernet,medium-ip,medium-ieee802154,proto-ipv4,proto-ipv4-fragmentation,proto-igmp,proto-dhcpv4,proto-ipv6,proto-rpl,proto-sixlowpan,proto-sixlowpan-fragmentation,proto-dns,socket,socket-raw,socket-udp,socket-tcp,socket-icmp,socket-dhcpv4,socket-dns,socket-mdns,packetmeta-id,async" +) + test() { local version=$1 rustup toolchain install $version @@ -82,6 +86,15 @@ clippy() { cargo +$MSRV clippy --tests --examples -- -D warnings } +build_16bit() { + rustup toolchain install nightly + + 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() { for features in ${FEATURES_TEST[@]}; do cargo llvm-cov --no-report --no-default-features --features "$features" @@ -121,6 +134,10 @@ if [[ $1 == "clippy" || $1 == "all" ]]; then clippy fi +if [[ $1 == "build_16bit" || $1 == "all" ]]; then + build_16bit +fi + if [[ $1 == "coverage" || $1 == "all" ]]; then coverage fi From d6eaf8e1c45aceeced00e8352b6008a47c372255 Mon Sep 17 00:00:00 2001 From: d2weber <29163905+d2weber@users.noreply.github.com> Date: Tue, 17 Sep 2024 18:58:50 +0200 Subject: [PATCH 3/5] Add rust-src component --- ci.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/ci.sh b/ci.sh index 5aa5583a7..6715bd8a2 100755 --- a/ci.sh +++ b/ci.sh @@ -88,6 +88,7 @@ clippy() { 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 From 16345da2834700e2c042dfe0285c8e0e36b9c5f4 Mon Sep 17 00:00:00 2001 From: d2weber <29163905+d2weber@users.noreply.github.com> Date: Tue, 17 Sep 2024 19:12:48 +0200 Subject: [PATCH 4/5] Change the line that has already been fixed --- src/socket/tcp.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/socket/tcp.rs b/src/socket/tcp.rs index 2bead6a65..b02d15653 100644 --- a/src/socket/tcp.rs +++ b/src/socket/tcp.rs @@ -677,7 +677,7 @@ impl<'a> Socket<'a> { /// Used in internal calculations as well as packet generation. #[inline] fn scaled_window(&self) -> u16 { - u16::try_from(self.rx_buffer.window() >> self.remote_win_shift as usize).unwrap_or(u16::MAX) + u16::try_from(self.rx_buffer.window() >> self.remote_win_shift).unwrap_or(u16::MAX) } /// Return the last window field value, including scaling according to RFC 1323. From 9ce51892dfd7f8e453a468d80bd5a04d6caa1b24 Mon Sep 17 00:00:00 2001 From: d2weber <29163905+d2weber@users.noreply.github.com> Date: Wed, 18 Sep 2024 18:58:09 +0200 Subject: [PATCH 5/5] Remove FEATURES_NO_STD --- ci.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ci.sh b/ci.sh index 6715bd8a2..eb9235f7e 100755 --- a/ci.sh +++ b/ci.sh @@ -44,10 +44,6 @@ FEATURES_CHECK=( "defmt,alloc,medium-ip,medium-ethernet,proto-ipv6,proto-ipv6,multicast,proto-dhcpv4,socket-raw,socket-udp,socket-tcp,socket-icmp,socket-dns,async" ) -FEATURES_NO_STD=( - "alloc,defmt,medium-ethernet,medium-ip,medium-ieee802154,proto-ipv4,proto-ipv4-fragmentation,proto-igmp,proto-dhcpv4,proto-ipv6,proto-rpl,proto-sixlowpan,proto-sixlowpan-fragmentation,proto-dns,socket,socket-raw,socket-udp,socket-tcp,socket-icmp,socket-dhcpv4,socket-dns,socket-mdns,packetmeta-id,async" -) - test() { local version=$1 rustup toolchain install $version