@@ -11,7 +11,6 @@ use crate::{
11
11
prelude:: * ,
12
12
types:: { AsBytes , FromBytes } ,
13
13
} ;
14
- use alloc:: vec:: Vec ;
15
14
use core:: ffi:: { c_ulong, c_void} ;
16
15
use core:: mem:: { size_of, MaybeUninit } ;
17
16
@@ -46,15 +45,14 @@ pub type UserPtr = usize;
46
45
/// every byte in the region.
47
46
///
48
47
/// ```no_run
49
- /// use alloc::vec::Vec;
50
48
/// use core::ffi::c_void;
51
49
/// use kernel::error::Result;
52
50
/// use kernel::uaccess::{UserPtr, UserSlice};
53
51
///
54
52
/// fn bytes_add_one(uptr: UserPtr, len: usize) -> Result<()> {
55
53
/// let (read, mut write) = UserSlice::new(uptr, len).reader_writer();
56
54
///
57
- /// let mut buf = Vec ::new();
55
+ /// let mut buf = KVec ::new();
58
56
/// read.read_all(&mut buf, GFP_KERNEL)?;
59
57
///
60
58
/// for b in &mut buf {
@@ -69,7 +67,6 @@ pub type UserPtr = usize;
69
67
/// Example illustrating a TOCTOU (time-of-check to time-of-use) bug.
70
68
///
71
69
/// ```no_run
72
- /// use alloc::vec::Vec;
73
70
/// use core::ffi::c_void;
74
71
/// use kernel::error::{code::EINVAL, Result};
75
72
/// use kernel::uaccess::{UserPtr, UserSlice};
@@ -78,21 +75,21 @@ pub type UserPtr = usize;
78
75
/// fn is_valid(uptr: UserPtr, len: usize) -> Result<bool> {
79
76
/// let read = UserSlice::new(uptr, len).reader();
80
77
///
81
- /// let mut buf = Vec ::new();
78
+ /// let mut buf = KVec ::new();
82
79
/// read.read_all(&mut buf, GFP_KERNEL)?;
83
80
///
84
81
/// todo!()
85
82
/// }
86
83
///
87
84
/// /// Returns the bytes behind this user pointer if they are valid.
88
- /// fn get_bytes_if_valid(uptr: UserPtr, len: usize) -> Result<Vec <u8>> {
85
+ /// fn get_bytes_if_valid(uptr: UserPtr, len: usize) -> Result<KVec <u8>> {
89
86
/// if !is_valid(uptr, len)? {
90
87
/// return Err(EINVAL);
91
88
/// }
92
89
///
93
90
/// let read = UserSlice::new(uptr, len).reader();
94
91
///
95
- /// let mut buf = Vec ::new();
92
+ /// let mut buf = KVec ::new();
96
93
/// read.read_all(&mut buf, GFP_KERNEL)?;
97
94
///
98
95
/// // THIS IS A BUG! The bytes could have changed since we checked them.
@@ -130,7 +127,7 @@ impl UserSlice {
130
127
/// Reads the entirety of the user slice, appending it to the end of the provided buffer.
131
128
///
132
129
/// Fails with [`EFAULT`] if the read happens on a bad address.
133
- pub fn read_all ( self , buf : & mut Vec < u8 > , flags : Flags ) -> Result {
130
+ pub fn read_all ( self , buf : & mut KVec < u8 > , flags : Flags ) -> Result {
134
131
self . reader ( ) . read_all ( buf, flags)
135
132
}
136
133
@@ -291,9 +288,9 @@ impl UserSliceReader {
291
288
/// Reads the entirety of the user slice, appending it to the end of the provided buffer.
292
289
///
293
290
/// Fails with [`EFAULT`] if the read happens on a bad address.
294
- pub fn read_all ( mut self , buf : & mut Vec < u8 > , flags : Flags ) -> Result {
291
+ pub fn read_all ( mut self , buf : & mut KVec < u8 > , flags : Flags ) -> Result {
295
292
let len = self . length ;
296
- VecExt :: < u8 > :: reserve ( buf , len, flags) ?;
293
+ buf . reserve ( len, flags) ?;
297
294
298
295
// The call to `try_reserve` was successful, so the spare capacity is at least `len` bytes
299
296
// long.
0 commit comments