Skip to content

Commit 2428dd6

Browse files
committed
fix: use repr packed to avoid padding in the syscall interface
I was hoping to _not_ do this as it might have a perf implication, but: - Padding is "undefined" so we could end up leaking rust memory (and causing non-determinism at runtime). - Requiring that everything be "packed" simplifies the spec. - In practice, there should be no performance issues (with existing syscalls). Specifically, we can re-order fields to avoid unaligned loads. part of https://github.com/filecoin-project/fvm-specs/issues/63
1 parent 02bf297 commit 2428dd6

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

shared/src/sys/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ pub type Codec = u64;
1111
///
1212
/// Internally, this type is a tuple of `u64`s storing the "low" and "high" bits of a little-endian
1313
/// u128.
14-
#[repr(C)]
1514
#[derive(Debug, Copy, Clone)]
15+
#[repr(packed, C)]
1616
pub struct TokenAmount {
1717
pub lo: u64,
1818
pub hi: u64,

shared/src/sys/out.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,25 @@
88
//! Read more at https://github.com/rust-lang/rust/issues/73755.
99
1010
pub mod actor {
11-
#[repr(C)]
1211
#[derive(Debug, Copy, Clone)]
12+
#[repr(packed, C)]
1313
pub struct ResolveAddress {
1414
pub resolved: i32,
1515
pub value: u64,
1616
}
1717
}
1818

1919
pub mod ipld {
20-
#[repr(C)]
2120
#[derive(Debug, Copy, Clone)]
21+
#[repr(packed, C)]
2222
pub struct IpldOpen {
23-
/// TODO could be more efficient to align id, size, codec, depending on padding.
24-
pub id: u32,
2523
pub codec: u64,
24+
pub id: u32,
2625
pub size: u32,
2726
}
2827

29-
#[repr(C)]
3028
#[derive(Debug, Copy, Clone)]
29+
#[repr(packed, C)]
3130
pub struct IpldStat {
3231
pub codec: u64,
3332
pub size: u32,
@@ -37,8 +36,8 @@ pub mod ipld {
3736
pub mod send {
3837
use crate::sys::BlockId;
3938

40-
#[repr(C)]
4139
#[derive(Debug, Copy, Clone)]
40+
#[repr(packed, C)]
4241
pub struct Send {
4342
pub exit_code: u32,
4443
pub return_id: BlockId,
@@ -48,11 +47,11 @@ pub mod send {
4847
pub mod crypto {
4948
use crate::{ActorID, ChainEpoch};
5049

51-
#[repr(C)]
5250
#[derive(Debug, Copy, Clone)]
51+
#[repr(packed, C)]
5352
pub struct VerifyConsensusFault {
54-
pub fault: u32,
5553
pub epoch: ChainEpoch,
5654
pub target: ActorID,
55+
pub fault: u32,
5756
}
5857
}

0 commit comments

Comments
 (0)