@@ -108,12 +108,13 @@ impl FileDesc {
108
108
target_os = "vita" ,
109
109
target_os = "nuttx"
110
110
) ) ) ]
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 ( ) ) ;
112
113
let ret = cvt ( unsafe {
113
114
libc:: readv (
114
115
self . as_raw_fd ( ) ,
115
116
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 ,
117
118
)
118
119
} ) ?;
119
120
Ok ( ret as usize )
@@ -198,12 +199,17 @@ impl FileDesc {
198
199
target_os = "netbsd" ,
199
200
target_os = "openbsd" , // OpenBSD 2.7
200
201
) ) ]
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 ( ) ) ;
202
208
let ret = cvt ( unsafe {
203
209
libc:: preadv (
204
210
self . as_raw_fd ( ) ,
205
211
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 ,
207
213
offset as _ ,
208
214
)
209
215
} ) ?;
@@ -235,7 +241,11 @@ impl FileDesc {
235
241
// passing 64-bits parameters to syscalls, so we fallback to the default
236
242
// implementation if `preadv` is not available.
237
243
#[ 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 > {
239
249
syscall ! (
240
250
fn preadv(
241
251
fd: libc:: c_int,
@@ -245,11 +255,12 @@ impl FileDesc {
245
255
) -> isize ;
246
256
) ;
247
257
258
+ IoSliceMut :: limit_slices ( & mut bufs, max_iov ( ) ) ;
248
259
let ret = cvt ( unsafe {
249
260
preadv (
250
261
self . as_raw_fd ( ) ,
251
262
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 ,
253
264
offset as _ ,
254
265
)
255
266
} ) ?;
@@ -260,7 +271,11 @@ impl FileDesc {
260
271
// FIXME(#115199): Rust currently omits weak function definitions
261
272
// and its metadata from LLVM IR.
262
273
#[ 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 > {
264
279
weak ! (
265
280
fn preadv64(
266
281
fd: libc:: c_int,
@@ -272,11 +287,12 @@ impl FileDesc {
272
287
273
288
match preadv64. get ( ) {
274
289
Some ( preadv) => {
290
+ IoSliceMut :: limit_slices ( & mut bufs, max_iov ( ) ) ;
275
291
let ret = cvt ( unsafe {
276
292
preadv (
277
293
self . as_raw_fd ( ) ,
278
294
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 ,
280
296
offset as _ ,
281
297
)
282
298
} ) ?;
@@ -296,7 +312,11 @@ impl FileDesc {
296
312
// These versions may be newer than the minimum supported versions of OS's we support so we must
297
313
// use "weak" linking.
298
314
#[ 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 > {
300
320
weak ! (
301
321
fn preadv(
302
322
fd: libc:: c_int,
@@ -308,11 +328,12 @@ impl FileDesc {
308
328
309
329
match preadv. get ( ) {
310
330
Some ( preadv) => {
331
+ IoSliceMut :: limit_slices ( & mut bufs, max_iov ( ) ) ;
311
332
let ret = cvt ( unsafe {
312
333
preadv (
313
334
self . as_raw_fd ( ) ,
314
335
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 ,
316
337
offset as _ ,
317
338
)
318
339
} ) ?;
@@ -339,12 +360,13 @@ impl FileDesc {
339
360
target_os = "vita" ,
340
361
target_os = "nuttx"
341
362
) ) ) ]
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 ( ) ) ;
343
365
let ret = cvt ( unsafe {
344
366
libc:: writev (
345
367
self . as_raw_fd ( ) ,
346
368
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 ,
348
370
)
349
371
} ) ?;
350
372
Ok ( ret as usize )
@@ -408,12 +430,13 @@ impl FileDesc {
408
430
target_os = "netbsd" ,
409
431
target_os = "openbsd" , // OpenBSD 2.7
410
432
) ) ]
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 ( ) ) ;
412
435
let ret = cvt ( unsafe {
413
436
libc:: pwritev (
414
437
self . as_raw_fd ( ) ,
415
438
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 ,
417
440
offset as _ ,
418
441
)
419
442
} ) ?;
@@ -445,7 +468,7 @@ impl FileDesc {
445
468
// passing 64-bits parameters to syscalls, so we fallback to the default
446
469
// implementation if `pwritev` is not available.
447
470
#[ 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 > {
449
472
syscall ! (
450
473
fn pwritev(
451
474
fd: libc:: c_int,
@@ -455,19 +478,20 @@ impl FileDesc {
455
478
) -> isize ;
456
479
) ;
457
480
481
+ IoSlice :: limit_slices ( & mut bufs, max_iov ( ) ) ;
458
482
let ret = cvt ( unsafe {
459
483
pwritev (
460
484
self . as_raw_fd ( ) ,
461
485
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 ,
463
487
offset as _ ,
464
488
)
465
489
} ) ?;
466
490
Ok ( ret as usize )
467
491
}
468
492
469
493
#[ 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 > {
471
495
weak ! (
472
496
fn pwritev64(
473
497
fd: libc:: c_int,
@@ -479,11 +503,12 @@ impl FileDesc {
479
503
480
504
match pwritev64. get ( ) {
481
505
Some ( pwritev) => {
506
+ IoSlice :: limit_slices ( & mut bufs, max_iov ( ) ) ;
482
507
let ret = cvt ( unsafe {
483
508
pwritev (
484
509
self . as_raw_fd ( ) ,
485
510
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 ,
487
512
offset as _ ,
488
513
)
489
514
} ) ?;
@@ -503,7 +528,7 @@ impl FileDesc {
503
528
// These versions may be newer than the minimum supported versions of OS's we support so we must
504
529
// use "weak" linking.
505
530
#[ 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 > {
507
532
weak ! (
508
533
fn pwritev(
509
534
fd: libc:: c_int,
@@ -515,11 +540,12 @@ impl FileDesc {
515
540
516
541
match pwritev. get ( ) {
517
542
Some ( pwritev) => {
543
+ IoSlice :: limit_slices ( & mut bufs, max_iov ( ) ) ;
518
544
let ret = cvt ( unsafe {
519
545
pwritev (
520
546
self . as_raw_fd ( ) ,
521
547
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 ,
523
549
offset as _ ,
524
550
)
525
551
} ) ?;
0 commit comments