@@ -108,12 +108,13 @@ impl FileDesc {
108108 target_os = "vita" ,
109109 target_os = "nuttx"
110110 ) ) ) ]
111- pub fn read_vectored ( & self , bufs : & mut [ IoSliceMut < ' _ > ] ) -> io:: Result < usize > {
111+ pub fn read_vectored ( & self , mut bufs : & mut [ IoSliceMut < ' _ > ] ) -> io:: Result < usize > {
112+ IoSliceMut :: limit_slices ( & mut bufs, max_iov ( ) ) ;
112113 let ret = cvt ( unsafe {
113114 libc:: readv (
114115 self . as_raw_fd ( ) ,
115116 bufs. as_mut_ptr ( ) as * mut libc:: iovec as * const libc:: iovec ,
116- cmp :: min ( bufs. len ( ) , max_iov ( ) ) as libc:: c_int ,
117+ bufs. len ( ) as libc:: c_int ,
117118 )
118119 } ) ?;
119120 Ok ( ret as usize )
@@ -198,12 +199,17 @@ impl FileDesc {
198199 target_os = "netbsd" ,
199200 target_os = "openbsd" , // OpenBSD 2.7
200201 ) ) ]
201- pub fn read_vectored_at ( & self , bufs : & mut [ IoSliceMut < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
202+ pub fn read_vectored_at (
203+ & self ,
204+ mut bufs : & mut [ IoSliceMut < ' _ > ] ,
205+ offset : u64 ,
206+ ) -> io:: Result < usize > {
207+ IoSliceMut :: limit_slices ( & mut bufs, max_iov ( ) ) ;
202208 let ret = cvt ( unsafe {
203209 libc:: preadv (
204210 self . as_raw_fd ( ) ,
205211 bufs. as_mut_ptr ( ) as * mut libc:: iovec as * const libc:: iovec ,
206- cmp :: min ( bufs. len ( ) , max_iov ( ) ) as libc:: c_int ,
212+ bufs. len ( ) as libc:: c_int ,
207213 offset as _ ,
208214 )
209215 } ) ?;
@@ -235,7 +241,11 @@ impl FileDesc {
235241 // passing 64-bits parameters to syscalls, so we fallback to the default
236242 // implementation if `preadv` is not available.
237243 #[ cfg( all( target_os = "android" , target_pointer_width = "64" ) ) ]
238- pub fn read_vectored_at ( & self , bufs : & mut [ IoSliceMut < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
244+ pub fn read_vectored_at (
245+ & self ,
246+ mut bufs : & mut [ IoSliceMut < ' _ > ] ,
247+ offset : u64 ,
248+ ) -> io:: Result < usize > {
239249 syscall ! (
240250 fn preadv(
241251 fd: libc:: c_int,
@@ -245,11 +255,12 @@ impl FileDesc {
245255 ) -> isize ;
246256 ) ;
247257
258+ IoSliceMut :: limit_slices ( & mut bufs, max_iov ( ) ) ;
248259 let ret = cvt ( unsafe {
249260 preadv (
250261 self . as_raw_fd ( ) ,
251262 bufs. as_mut_ptr ( ) as * mut libc:: iovec as * const libc:: iovec ,
252- cmp :: min ( bufs. len ( ) , max_iov ( ) ) as libc:: c_int ,
263+ bufs. len ( ) as libc:: c_int ,
253264 offset as _ ,
254265 )
255266 } ) ?;
@@ -260,7 +271,11 @@ impl FileDesc {
260271 // FIXME(#115199): Rust currently omits weak function definitions
261272 // and its metadata from LLVM IR.
262273 #[ no_sanitize( cfi) ]
263- pub fn read_vectored_at ( & self , bufs : & mut [ IoSliceMut < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
274+ pub fn read_vectored_at (
275+ & self ,
276+ mut bufs : & mut [ IoSliceMut < ' _ > ] ,
277+ offset : u64 ,
278+ ) -> io:: Result < usize > {
264279 weak ! (
265280 fn preadv64(
266281 fd: libc:: c_int,
@@ -272,11 +287,12 @@ impl FileDesc {
272287
273288 match preadv64. get ( ) {
274289 Some ( preadv) => {
290+ IoSliceMut :: limit_slices ( & mut bufs, max_iov ( ) ) ;
275291 let ret = cvt ( unsafe {
276292 preadv (
277293 self . as_raw_fd ( ) ,
278294 bufs. as_mut_ptr ( ) as * mut libc:: iovec as * const libc:: iovec ,
279- cmp :: min ( bufs. len ( ) , max_iov ( ) ) as libc:: c_int ,
295+ bufs. len ( ) as libc:: c_int ,
280296 offset as _ ,
281297 )
282298 } ) ?;
@@ -296,7 +312,11 @@ impl FileDesc {
296312 // These versions may be newer than the minimum supported versions of OS's we support so we must
297313 // use "weak" linking.
298314 #[ cfg( target_vendor = "apple" ) ]
299- pub fn read_vectored_at ( & self , bufs : & mut [ IoSliceMut < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
315+ pub fn read_vectored_at (
316+ & self ,
317+ mut bufs : & mut [ IoSliceMut < ' _ > ] ,
318+ offset : u64 ,
319+ ) -> io:: Result < usize > {
300320 weak ! (
301321 fn preadv(
302322 fd: libc:: c_int,
@@ -308,11 +328,12 @@ impl FileDesc {
308328
309329 match preadv. get ( ) {
310330 Some ( preadv) => {
331+ IoSliceMut :: limit_slices ( & mut bufs, max_iov ( ) ) ;
311332 let ret = cvt ( unsafe {
312333 preadv (
313334 self . as_raw_fd ( ) ,
314335 bufs. as_mut_ptr ( ) as * mut libc:: iovec as * const libc:: iovec ,
315- cmp :: min ( bufs. len ( ) , max_iov ( ) ) as libc:: c_int ,
336+ bufs. len ( ) as libc:: c_int ,
316337 offset as _ ,
317338 )
318339 } ) ?;
@@ -339,12 +360,13 @@ impl FileDesc {
339360 target_os = "vita" ,
340361 target_os = "nuttx"
341362 ) ) ) ]
342- pub fn write_vectored ( & self , bufs : & [ IoSlice < ' _ > ] ) -> io:: Result < usize > {
363+ pub fn write_vectored ( & self , mut bufs : & [ IoSlice < ' _ > ] ) -> io:: Result < usize > {
364+ IoSlice :: limit_slices ( & mut bufs, max_iov ( ) ) ;
343365 let ret = cvt ( unsafe {
344366 libc:: writev (
345367 self . as_raw_fd ( ) ,
346368 bufs. as_ptr ( ) as * const libc:: iovec ,
347- cmp :: min ( bufs. len ( ) , max_iov ( ) ) as libc:: c_int ,
369+ bufs. len ( ) as libc:: c_int ,
348370 )
349371 } ) ?;
350372 Ok ( ret as usize )
@@ -408,12 +430,13 @@ impl FileDesc {
408430 target_os = "netbsd" ,
409431 target_os = "openbsd" , // OpenBSD 2.7
410432 ) ) ]
411- pub fn write_vectored_at ( & self , bufs : & [ IoSlice < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
433+ pub fn write_vectored_at ( & self , mut bufs : & [ IoSlice < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
434+ IoSlice :: limit_slices ( & mut bufs, max_iov ( ) ) ;
412435 let ret = cvt ( unsafe {
413436 libc:: pwritev (
414437 self . as_raw_fd ( ) ,
415438 bufs. as_ptr ( ) as * const libc:: iovec ,
416- cmp :: min ( bufs. len ( ) , max_iov ( ) ) as libc:: c_int ,
439+ bufs. len ( ) as libc:: c_int ,
417440 offset as _ ,
418441 )
419442 } ) ?;
@@ -445,7 +468,7 @@ impl FileDesc {
445468 // passing 64-bits parameters to syscalls, so we fallback to the default
446469 // implementation if `pwritev` is not available.
447470 #[ cfg( all( target_os = "android" , target_pointer_width = "64" ) ) ]
448- pub fn write_vectored_at ( & self , bufs : & [ IoSlice < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
471+ pub fn write_vectored_at ( & self , mut bufs : & [ IoSlice < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
449472 syscall ! (
450473 fn pwritev(
451474 fd: libc:: c_int,
@@ -455,19 +478,20 @@ impl FileDesc {
455478 ) -> isize ;
456479 ) ;
457480
481+ IoSlice :: limit_slices ( & mut bufs, max_iov ( ) ) ;
458482 let ret = cvt ( unsafe {
459483 pwritev (
460484 self . as_raw_fd ( ) ,
461485 bufs. as_ptr ( ) as * const libc:: iovec ,
462- cmp :: min ( bufs. len ( ) , max_iov ( ) ) as libc:: c_int ,
486+ bufs. len ( ) as libc:: c_int ,
463487 offset as _ ,
464488 )
465489 } ) ?;
466490 Ok ( ret as usize )
467491 }
468492
469493 #[ cfg( all( target_os = "android" , target_pointer_width = "32" ) ) ]
470- pub fn write_vectored_at ( & self , bufs : & [ IoSlice < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
494+ pub fn write_vectored_at ( & self , mut bufs : & [ IoSlice < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
471495 weak ! (
472496 fn pwritev64(
473497 fd: libc:: c_int,
@@ -479,11 +503,12 @@ impl FileDesc {
479503
480504 match pwritev64. get ( ) {
481505 Some ( pwritev) => {
506+ IoSlice :: limit_slices ( & mut bufs, max_iov ( ) ) ;
482507 let ret = cvt ( unsafe {
483508 pwritev (
484509 self . as_raw_fd ( ) ,
485510 bufs. as_ptr ( ) as * const libc:: iovec ,
486- cmp :: min ( bufs. len ( ) , max_iov ( ) ) as libc:: c_int ,
511+ bufs. len ( ) as libc:: c_int ,
487512 offset as _ ,
488513 )
489514 } ) ?;
@@ -503,7 +528,7 @@ impl FileDesc {
503528 // These versions may be newer than the minimum supported versions of OS's we support so we must
504529 // use "weak" linking.
505530 #[ cfg( target_vendor = "apple" ) ]
506- pub fn write_vectored_at ( & self , bufs : & [ IoSlice < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
531+ pub fn write_vectored_at ( & self , mut bufs : & [ IoSlice < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
507532 weak ! (
508533 fn pwritev(
509534 fd: libc:: c_int,
@@ -515,11 +540,12 @@ impl FileDesc {
515540
516541 match pwritev. get ( ) {
517542 Some ( pwritev) => {
543+ IoSlice :: limit_slices ( & mut bufs, max_iov ( ) ) ;
518544 let ret = cvt ( unsafe {
519545 pwritev (
520546 self . as_raw_fd ( ) ,
521547 bufs. as_ptr ( ) as * const libc:: iovec ,
522- cmp :: min ( bufs. len ( ) , max_iov ( ) ) as libc:: c_int ,
548+ bufs. len ( ) as libc:: c_int ,
523549 offset as _ ,
524550 )
525551 } ) ?;
0 commit comments