Pwritev2 implements Linux syscall pwritev2(2).
(t *kernel.Task, sysno uintptr, args arch.SyscallArguments)
| 437 | |
| 438 | // Pwritev2 implements Linux syscall pwritev2(2). |
| 439 | func 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 | |
| 482 | func 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) |
nothing calls this directly
no test coverage detected
searching dependent graphs…