From dd021d44ba1db313b90da76c1dc2088bd6ab398c Mon Sep 17 00:00:00 2001 From: joannejchen Date: Sat, 15 Apr 2023 14:50:46 -0500 Subject: [PATCH] Change alignment of virtiofs structs to be based on the first field. Alignment of the virtiofs struct was previously based on the alignment of the largest field in fuse_in_header/fuse_out_header. Switched to explicitly align on u32, the type of the first field in the header. Fixes #691 Signed-off-by: joannejchen --- src/fs/fuse.rs | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/fs/fuse.rs b/src/fs/fuse.rs index 6c6df6c72f..6452a2457a 100644 --- a/src/fs/fuse.rs +++ b/src/fs/fuse.rs @@ -331,7 +331,7 @@ where fn create_init() -> (Box>, Box>) { let len = core::mem::size_of::() + core::mem::size_of::(); - let layout = Layout::from_size_align(len, core::mem::align_of::()); + let layout = Layout::from_size_align(len, core::mem::align_of::()); let cmd = unsafe { let data = alloc(layout.unwrap()); let raw = core::ptr::slice_from_raw_parts_mut(data, 0) as *mut Cmd; @@ -348,7 +348,7 @@ fn create_init() -> (Box>, Box>) { }; let len = core::mem::size_of::() + core::mem::size_of::(); - let layout = Layout::from_size_align(len, core::mem::align_of::()); + let layout = Layout::from_size_align(len, core::mem::align_of::()); let rsp = unsafe { let data = alloc(layout.unwrap()); let raw = core::ptr::slice_from_raw_parts_mut(data, 0) as *mut Rsp; @@ -369,7 +369,7 @@ fn create_lookup(name: &str) -> (Box>, Box() + slice.len() + 1; - let layout = Layout::from_size_align(len, core::mem::align_of::()); + let layout = Layout::from_size_align(len, core::mem::align_of::()); let cmd = unsafe { let data = alloc(layout.unwrap()); let raw = @@ -383,7 +383,7 @@ fn create_lookup(name: &str) -> (Box>, Box() + core::mem::size_of::(); - let layout = Layout::from_size_align(len, core::mem::align_of::()); + let layout = Layout::from_size_align(len, core::mem::align_of::()); let rsp = unsafe { let data = alloc(layout.unwrap()); let raw = core::ptr::slice_from_raw_parts_mut(data, 0) as *mut Rsp; @@ -471,7 +471,7 @@ fn create_read( offset: u64, ) -> (Box>, Box>) { let len = core::mem::size_of::() + core::mem::size_of::(); - let layout = Layout::from_size_align(len, core::mem::align_of::()); + let layout = Layout::from_size_align(len, core::mem::align_of::()); let cmd = unsafe { let data = alloc(layout.unwrap()); let raw = core::ptr::slice_from_raw_parts_mut(data, 0) as *mut Cmd; @@ -489,7 +489,7 @@ fn create_read( let len = core::mem::size_of::() + core::mem::size_of::() + usize::try_from(size).unwrap(); - let layout = Layout::from_size_align(len, core::mem::align_of::()); + let layout = Layout::from_size_align(len, core::mem::align_of::()); let rsp = unsafe { let data = alloc(layout.unwrap()); let raw = core::ptr::slice_from_raw_parts_mut(data, size.try_into().unwrap()) @@ -529,7 +529,7 @@ fn create_lseek( whence: SeekWhence, ) -> (Box>, Box>) { let len = core::mem::size_of::() + core::mem::size_of::(); - let layout = Layout::from_size_align(len, core::mem::align_of::()); + let layout = Layout::from_size_align(len, core::mem::align_of::()); let cmd = unsafe { let data = alloc(layout.unwrap()); let raw = core::ptr::slice_from_raw_parts_mut(data, 0) as *mut Cmd; @@ -551,7 +551,7 @@ fn create_lseek( }; let len = core::mem::size_of::() + core::mem::size_of::(); - let layout = Layout::from_size_align(len, core::mem::align_of::()); + let layout = Layout::from_size_align(len, core::mem::align_of::()); let rsp = unsafe { let data = alloc(layout.unwrap()); let raw = core::ptr::slice_from_raw_parts_mut(data, 0) as *mut Rsp; @@ -596,7 +596,7 @@ fn create_write( ) -> (Box>, Box>) { let len = core::mem::size_of::() + core::mem::size_of::() + buf.len(); - let layout = Layout::from_size_align(len, core::mem::align_of::()); + let layout = Layout::from_size_align(len, core::mem::align_of::()); let cmd = unsafe { let data = alloc(layout.unwrap()); let raw = core::ptr::slice_from_raw_parts_mut(data, buf.len()) as *mut Cmd; @@ -619,7 +619,7 @@ fn create_write( }; let len = core::mem::size_of::() + core::mem::size_of::(); - let layout = Layout::from_size_align(len, core::mem::align_of::()); + let layout = Layout::from_size_align(len, core::mem::align_of::()); let rsp = unsafe { let data = alloc(layout.unwrap()); let raw = core::ptr::slice_from_raw_parts_mut(data, 0) as *mut Rsp; @@ -655,7 +655,7 @@ unsafe impl FuseOut for fuse_open_out {} fn create_open(nid: u64, flags: u32) -> (Box>, Box>) { let len = core::mem::size_of::() + core::mem::size_of::(); - let layout = Layout::from_size_align(len, core::mem::align_of::()); + let layout = Layout::from_size_align(len, core::mem::align_of::()); let cmd = unsafe { let data = alloc(layout.unwrap()); let raw = core::ptr::slice_from_raw_parts_mut(data, 0) as *mut Cmd; @@ -669,7 +669,7 @@ fn create_open(nid: u64, flags: u32) -> (Box>, Box() + core::mem::size_of::(); - let layout = Layout::from_size_align(len, core::mem::align_of::()); + let layout = Layout::from_size_align(len, core::mem::align_of::()); let rsp = unsafe { let data = alloc(layout.unwrap()); let raw = core::ptr::slice_from_raw_parts_mut(data, 0) as *mut Rsp; @@ -702,7 +702,7 @@ unsafe impl FuseOut for fuse_release_out {} fn create_release(nid: u64, fh: u64) -> (Box>, Box>) { let len = core::mem::size_of::() + core::mem::size_of::(); - let layout = Layout::from_size_align(len, core::mem::align_of::()); + let layout = Layout::from_size_align(len, core::mem::align_of::()); let cmd = unsafe { let data = alloc(layout.unwrap()); let raw = core::ptr::slice_from_raw_parts_mut(data, 0) as *mut Cmd; @@ -716,7 +716,7 @@ fn create_release(nid: u64, fh: u64) -> (Box>, Box() + core::mem::size_of::(); - let layout = Layout::from_size_align(len, core::mem::align_of::()); + let layout = Layout::from_size_align(len, core::mem::align_of::()); let rsp = unsafe { let data = alloc(layout.unwrap()); let raw = core::ptr::slice_from_raw_parts_mut(data, 0) as *mut Rsp; @@ -787,7 +787,7 @@ fn create_unlink(name: &str) -> (Box>, Box() + slice.len() + 1; - let layout = Layout::from_size_align(len, core::mem::align_of::()); + let layout = Layout::from_size_align(len, core::mem::align_of::()); let cmd = unsafe { let data = alloc(layout.unwrap()); let raw = @@ -801,7 +801,7 @@ fn create_unlink(name: &str) -> (Box>, Box() + core::mem::size_of::(); - let layout = Layout::from_size_align(len, core::mem::align_of::()); + let layout = Layout::from_size_align(len, core::mem::align_of::()); let rsp = unsafe { let data = alloc(layout.unwrap()); let raw = core::ptr::slice_from_raw_parts_mut(data, 0) as *mut Rsp; @@ -845,7 +845,7 @@ fn create_create( + core::mem::size_of::() + slice.len() + 1; - let layout = Layout::from_size_align(len, core::mem::align_of::()); + let layout = Layout::from_size_align(len, core::mem::align_of::()); let cmd = unsafe { let data = alloc(layout.unwrap()); let raw = @@ -864,7 +864,7 @@ fn create_create( }; let len = core::mem::size_of::() + core::mem::size_of::(); - let layout = Layout::from_size_align(len, core::mem::align_of::()); + let layout = Layout::from_size_align(len, core::mem::align_of::()); let rsp = unsafe { let data = alloc(layout.unwrap()); let raw = core::ptr::slice_from_raw_parts_mut(data, 0) as *mut Rsp;