@@ -20,9 +20,11 @@ use cras_sys::gen::{
20
20
use cras_sys:: {
21
21
AudioDebugInfo , AudioDevDebugInfo , AudioStreamDebugInfo , CrasIodevInfo , CrasIonodeInfo ,
22
22
} ;
23
- use data_model:: { VolatileRef , VolatileSlice } ;
23
+ use data_model:: VolatileSlice ;
24
24
use libchromeos:: sys:: warn;
25
25
26
+ use crate :: unaligned_memory:: UnalignedRef ;
27
+
26
28
/// A structure wrapping a fd which contains a shared `cras_audio_shm_header`.
27
29
/// * `shm_fd` - A shared memory fd contains a `cras_audio_shm_header`
28
30
pub struct CrasAudioShmHeaderFd {
@@ -52,46 +54,46 @@ impl CrasAudioShmHeaderFd {
52
54
53
55
/// A wrapper for the raw structure `cras_audio_shm_header` with
54
56
/// size information for the separate audio samples shm area and several
55
- /// `VolatileRef ` to sub fields for safe access to the header.
57
+ /// `UnalignedRef ` to sub fields for safe access to the header.
56
58
pub struct CrasAudioHeader < ' a > {
57
59
addr : * mut libc:: c_void ,
58
60
/// Size of the buffer for samples in CrasAudioBuffer
59
61
samples_len : usize ,
60
- used_size : VolatileRef < ' a , u32 > ,
61
- frame_size : VolatileRef < ' a , u32 > ,
62
- read_buf_idx : VolatileRef < ' a , u32 > ,
63
- write_buf_idx : VolatileRef < ' a , u32 > ,
64
- read_offset : [ VolatileRef < ' a , u32 > ; CRAS_NUM_SHM_BUFFERS as usize ] ,
65
- write_offset : [ VolatileRef < ' a , u32 > ; CRAS_NUM_SHM_BUFFERS as usize ] ,
66
- buffer_offset : [ VolatileRef < ' a , u64 > ; CRAS_NUM_SHM_BUFFERS as usize ] ,
67
- ts_sec : VolatileRef < ' a , i64 > ,
68
- ts_nsec : VolatileRef < ' a , i64 > ,
62
+ used_size : UnalignedRef < ' a , u32 > ,
63
+ frame_size : UnalignedRef < ' a , u32 > ,
64
+ read_buf_idx : UnalignedRef < ' a , u32 > ,
65
+ write_buf_idx : UnalignedRef < ' a , u32 > ,
66
+ read_offset : [ UnalignedRef < ' a , u32 > ; CRAS_NUM_SHM_BUFFERS as usize ] ,
67
+ write_offset : [ UnalignedRef < ' a , u32 > ; CRAS_NUM_SHM_BUFFERS as usize ] ,
68
+ buffer_offset : [ UnalignedRef < ' a , u64 > ; CRAS_NUM_SHM_BUFFERS as usize ] ,
69
+ ts_sec : UnalignedRef < ' a , i64 > ,
70
+ ts_nsec : UnalignedRef < ' a , i64 > ,
69
71
}
70
72
71
73
// It is safe to send audio buffers between threads as this struct has exclusive ownership of the
72
74
// pointers contained in it.
73
75
unsafe impl < ' a > Send for CrasAudioHeader < ' a > { }
74
76
75
- /// An unsafe macro for getting `VolatileRef ` for a field from a given NonNull pointer.
77
+ /// An unsafe macro for getting `UnalignedRef ` for a field from a given NonNull pointer.
76
78
/// It Supports
77
79
/// - Nested sub-field
78
80
/// - Element of an array field
79
81
///
80
82
/// To use this macro safely, we need to
81
83
/// - Make sure the pointer address is readable and writable for its structure.
82
- /// - Make sure all `VolatileRef `s generated from this macro have exclusive ownership for the same
84
+ /// - Make sure all `UnalignedRef `s generated from this macro have exclusive ownership for the same
83
85
/// pointer.
84
86
///
85
- /// TODO(b/239850356): Use self-implemented `VolatileRef ` implemetation
87
+ /// TODO(b/239850356): Use self-implemented `UnalignedRef ` implemetation
86
88
/// with [`ptr::read_unaligned`] and [`ptr::write_unaligned`].
87
89
#[ macro_export]
88
90
macro_rules! vref_from_addr {
89
91
( $addr: ident, $( $field: ident) .* ) => {
90
- VolatileRef :: new( ptr:: addr_of_mut!( $addr. as_mut( ) . $( $field) .* ) )
92
+ UnalignedRef :: new( ptr:: addr_of_mut!( $addr. as_mut( ) . $( $field) .* ) )
91
93
} ;
92
94
93
95
( $addr: ident, $field: ident[ $idx: tt] ) => {
94
- VolatileRef :: new( ptr:: addr_of_mut!( $addr. as_mut( ) . $field[ $idx] ) )
96
+ UnalignedRef :: new( ptr:: addr_of_mut!( $addr. as_mut( ) . $field[ $idx] ) )
95
97
} ;
96
98
}
97
99
@@ -553,20 +555,20 @@ macro_rules! vslice_from_addr {
553
555
#[ derive( Debug ) ]
554
556
pub struct CrasServerState < ' a > {
555
557
addr : * mut libc:: c_void ,
556
- volume : VolatileRef < ' a , u32 > ,
557
- mute : VolatileRef < ' a , i32 > ,
558
- num_output_devs : VolatileRef < ' a , u32 > ,
558
+ volume : UnalignedRef < ' a , u32 > ,
559
+ mute : UnalignedRef < ' a , i32 > ,
560
+ num_output_devs : UnalignedRef < ' a , u32 > ,
559
561
output_devs : VolatileSlice < ' a > ,
560
- num_input_devs : VolatileRef < ' a , u32 > ,
562
+ num_input_devs : UnalignedRef < ' a , u32 > ,
561
563
input_devs : VolatileSlice < ' a > ,
562
- num_output_nodes : VolatileRef < ' a , u32 > ,
563
- num_input_nodes : VolatileRef < ' a , u32 > ,
564
+ num_output_nodes : UnalignedRef < ' a , u32 > ,
565
+ num_input_nodes : UnalignedRef < ' a , u32 > ,
564
566
output_nodes : VolatileSlice < ' a > ,
565
567
input_nodes : VolatileSlice < ' a > ,
566
- update_count : VolatileRef < ' a , u32 > ,
567
- debug_info_num_devs : VolatileRef < ' a , u32 > ,
568
+ update_count : UnalignedRef < ' a , u32 > ,
569
+ debug_info_num_devs : UnalignedRef < ' a , u32 > ,
568
570
debug_info_devs : VolatileSlice < ' a > ,
569
- debug_info_num_streams : VolatileRef < ' a , u32 > ,
571
+ debug_info_num_streams : UnalignedRef < ' a , u32 > ,
570
572
debug_info_streams : VolatileSlice < ' a > ,
571
573
}
572
574
0 commit comments