Skip to contentSkip to conversation

linux-user: add preadv2/preadv2

PATCH In review Dominique Martinet 2 participants 2 messages Jun 10 – Jun 11

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user: add preadv2/preadv2

Some programs apparently use these, like the python test suite.

The flags argument (rwf_t) is an int, with values shared on all arches and does not need translating.

This was tested manually with the following python script:

```
import os
fd = os.open('test', os.O_RDWR|os.O_CREAT)
os.pwritev(fd, [b'test', b'ok'], 0, os.RWF_HIPRI)
buf = [bytearray(3), bytearray(10)]
os.preadv(fd, buf, 0, os.RWF_HIPRI)
print(buf[0])
print(buf[1])
```

---
(the 80-column checkpatch warning made me wrap a couple of long lines I'd find easier to read with 81 columns, so if you prefer I'd be happy to resend without wrapping for pwrite2 safe_syscall6() declaration and call, but it doesn't matter much either way)

Thanks!

---
 linux-user/syscall.c | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
linux-user/syscall.c +38 -0
index 7d7a7b489cf93663c24b4e872f509793b7a06683..f1d98857d42dbad54f79f0b1ba5887334bae8fa4 100644
@@ -741,6 +741,11 @@ safe_syscall5(ssize_t, preadv, int, fd, const struct iovec *, iov, int, iovcnt,
               unsigned long, pos_l, unsigned long, pos_h)
 safe_syscall5(ssize_t, pwritev, int, fd, const struct iovec *, iov, int, iovcnt,
               unsigned long, pos_l, unsigned long, pos_h)
+safe_syscall6(ssize_t, preadv2, int, fd, const struct iovec *, iov, int, iovcnt,
+              unsigned long, pos_l, unsigned long, pos_h, __kernel_rwf_t, flags)
+safe_syscall6(ssize_t, pwritev2, int, fd, const struct iovec *, iov,
+              int, iovcnt, unsigned long, pos_l, unsigned long, pos_h,
+              __kernel_rwf_t, flags)
 safe_syscall3(int, connect, int, fd, const struct sockaddr *, addr,
               socklen_t, addrlen)
 safe_syscall6(ssize_t, sendto, int, fd, const void *, buf, size_t, len,
@@ -11894,6 +11899,39 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
            }
         }
         return ret;
+#endif
+#if defined(TARGET_NR_preadv2)
+    case TARGET_NR_preadv2:
+        {
+            struct iovec *vec = lock_iovec(VERIFY_WRITE, arg2, arg3, 0);
+            if (vec != NULL) {
+                unsigned long low, high;
+
+                target_to_host_low_high(arg4, arg5, &low, &high);
+                ret = get_errno(safe_preadv2(arg1, vec, arg3, low, high, arg6));
+                unlock_iovec(vec, arg2, arg3, 1);
+            } else {
+                ret = -host_to_target_errno(errno);
+           }
+        }
+        return ret;
+#endif
+#if defined(TARGET_NR_pwritev2)
+    case TARGET_NR_pwritev2:
+        {
+            struct iovec *vec = lock_iovec(VERIFY_READ, arg2, arg3, 1);
+            if (vec != NULL) {
+                unsigned long low, high;
+
+                target_to_host_low_high(arg4, arg5, &low, &high);
+                ret = get_errno(safe_pwritev2(arg1, vec, arg3, low, high,
+                                              arg6));
+                unlock_iovec(vec, arg2, arg3, 0);
+            } else {
+                ret = -host_to_target_errno(errno);
+           }
+        }
+        return ret;
 #endif
     case TARGET_NR_getsid:
         return get_errno(getsid(arg1));

---
base-commit: de5d8bfd6105d3dd3ae668df9762df244a6d1506
change-id: 20260610-preadv2-66161427d627

Best regards,

Signature · 1 line
Dominique Martinet <[email protected]>
Reviewed-by on v1 1/1
#1 lore raw
Quoted 23 lines · Dominique Martinet

Some programs apparently use these, like the python test suite.

The flags argument (rwf_t) is an int, with values shared on all arches and does not need translating.

This was tested manually with the following python script:

```
import os
fd = os.open('test', os.O_RDWR|os.O_CREAT)
os.pwritev(fd, [b'test', b'ok'], 0, os.RWF_HIPRI)
buf = [bytearray(3), bytearray(10)]
os.preadv(fd, buf, 0, os.RWF_HIPRI)
print(buf[0])
print(buf[1])
```

---
(the 80-column checkpatch warning made me wrap a couple of long lines I'd find easier to read with 81 columns, so if you prefer I'd be happy to resend without wrapping for pwrite2 safe_syscall6() declaration and call, but it doesn't matter much either way)

Quoted 4 lines

Thanks!

---
  linux-user/syscall.c | 38 ++++++++++++++++++++++++++++++++++++++
  1 file changed, 38 insertions(+)

I've picked it up into the linux-user git tree as-is. Thanks!
Helge