MCPcopy
hub / github.com/google/gvisor / Pwritev2

Function Pwritev2

pkg/sentry/syscalls/linux/sys_read_write.go:439–480  ·  view source on GitHub ↗

Pwritev2 implements Linux syscall pwritev2(2).

(t *kernel.Task, sysno uintptr, args arch.SyscallArguments)

Source from the content-addressed store, hash-verified

437
438// Pwritev2 implements Linux syscall pwritev2(2).
439func Pwritev2(t *kernel.Task, sysno uintptr, args arch.SyscallArguments) (uintptr, *kernel.SyscallControl, error) {
440 // While the glibc signature is
441 // pwritev2(int fd, struct iovec* iov, int iov_cnt, off_t offset, int flags)
442 // the actual syscall
443 // (https://elixir.bootlin.com/linux/v5.5/source/fs/read_write.c#L1162)
444 // splits the offset argument into a high/low value for compatibility with
445 // 32-bit architectures. The flags argument is the 6th argument (index 5).
446 fd := args[0].Int()
447 addr := args[1].Pointer()
448 iovcnt := int(args[2].Int())
449 offset := args[3].Int64()
450 flags := args[5].Int()
451
452 file := t.GetFile(fd)
453 if file == nil {
454 return 0, nil, linuxerr.EBADF
455 }
456 defer file.DecRef(t)
457
458 // Check that the offset is legitimate.
459 if offset < -1 {
460 return 0, nil, linuxerr.EINVAL
461 }
462
463 // Get the source of the write.
464 src, err := t.IovecsIOSequence(addr, iovcnt, usermem.IOOpts{})
465 if err != nil {
466 return 0, nil, err
467 }
468
469 opts := vfs.WriteOptions{
470 Flags: uint32(flags),
471 }
472 var n int64
473 if offset == -1 {
474 n, err = write(t, file, src, opts)
475 } else {
476 n, err = pwrite(t, file, src, offset, opts)
477 }
478 t.IOUsage().AccountWriteSyscall(n)
479 return uintptr(n), nil, HandleIOError(t, n != 0, err, linuxerr.ERESTARTSYS, "pwritev2", file)
480}
481
482func pwrite(t *kernel.Task, file *vfs.FileDescription, src usermem.IOSequence, offset int64, opts vfs.WriteOptions) (int64, error) {
483 n, err := file.PWrite(t, src, offset, opts)

Callers

nothing calls this directly

Calls 11

pwriteFunction · 0.85
HandleIOErrorFunction · 0.85
GetFileMethod · 0.80
IovecsIOSequenceMethod · 0.80
AccountWriteSyscallMethod · 0.80
writeFunction · 0.70
DecRefMethod · 0.65
IOUsageMethod · 0.65
IntMethod · 0.45
PointerMethod · 0.45
Int64Method · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…