All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] Force pread64/pwrite64 to return 0 for zero-length buffer
@ 2014-12-17 12:02 Ilya Palachev
  2014-12-17 12:28 ` Peter Maydell
  0 siblings, 1 reply; 4+ messages in thread
From: Ilya Palachev @ 2014-12-17 12:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: Vyachelav Barinov, Ilya Palachev

According to official standard POSIX.1-2001. pread64 and pwrite64
should return 0 for zero-length buffers as mentioned at

http://pubs.opengroup.org/onlinepubs/009695399/functions/read.html
http://pubs.opengroup.org/onlinepubs/009695399/functions/write.html

Change-Id: Icd66ea29658329fbd5e6461d1def0c78c81d2671
Signed-off-by: Ilya Palachev <i.palachev@samsung.com>
---
 linux-user/syscall.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index a41dd43..a08f5ef 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -8127,6 +8127,10 @@ abi_long do_syscall(void *cpu_env, int num, abi_ulong arg1,
             arg4 = arg5;
             arg5 = arg6;
         }
+        if (!arg3) {
+            ret = 0;
+            break;
+        }
         if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0)))
             goto efault;
         ret = get_errno(pread64(arg1, p, arg3, target_offset64(arg4, arg5)));
@@ -8137,6 +8141,10 @@ abi_long do_syscall(void *cpu_env, int num, abi_ulong arg1,
             arg4 = arg5;
             arg5 = arg6;
         }
+        if (!arg3) {
+            ret = 0;
+            break;
+        }
         if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1)))
             goto efault;
         ret = get_errno(pwrite64(arg1, p, arg3, target_offset64(arg4, arg5)));
-- 
2.1.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] Force pread64/pwrite64 to return 0 for zero-length buffer
  2014-12-17 12:02 [Qemu-devel] [PATCH] Force pread64/pwrite64 to return 0 for zero-length buffer Ilya Palachev
@ 2014-12-17 12:28 ` Peter Maydell
  2014-12-17 12:56   ` Ilya Palachev
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Maydell @ 2014-12-17 12:28 UTC (permalink / raw)
  To: Ilya Palachev; +Cc: Vyachelav Barinov, QEMU Developers

On 17 December 2014 at 12:02, Ilya Palachev <i.palachev@samsung.com> wrote:
> According to official standard POSIX.1-2001. pread64 and pwrite64
> should return 0 for zero-length buffers as mentioned at
>
> http://pubs.opengroup.org/onlinepubs/009695399/functions/read.html
> http://pubs.opengroup.org/onlinepubs/009695399/functions/write.html
>
> Change-Id: Icd66ea29658329fbd5e6461d1def0c78c81d2671
> Signed-off-by: Ilya Palachev <i.palachev@samsung.com>

If this is a problem, doesn't it apply to more syscalls than
just pread64 and pwrite64 ?

-- PMM

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] Force pread64/pwrite64 to return 0 for zero-length buffer
  2014-12-17 12:28 ` Peter Maydell
@ 2014-12-17 12:56   ` Ilya Palachev
  2014-12-17 13:15     ` Peter Maydell
  0 siblings, 1 reply; 4+ messages in thread
From: Ilya Palachev @ 2014-12-17 12:56 UTC (permalink / raw)
  To: Peter Maydell; +Cc: Vyachelav Barinov, QEMU Developers

On 17.12.2014 15:28, Peter Maydell wrote:
> If this is a problem, doesn't it apply to more syscalls than
> just pread64 and pwrite64 ?

Hi,

We were interested in pwrite64/pread64 only since it caused a failure in 
elfutils (see https://bugzilla.redhat.com/show_bug.cgi?id=1174267).
Of course, it applies also to other syscalls. There are the following 
problems:

- Find what syscalls should be changed (check POSIX specification and 
qemu implementation)

- Whether to change them all with "if" statements as for 
pread64/pwrite64. Or there is some more convenient way?

- Find they how to test them all after the change is made (make check?)

What do you think about that?

Best regards,
Ilya Palachev

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] Force pread64/pwrite64 to return 0 for zero-length buffer
  2014-12-17 12:56   ` Ilya Palachev
@ 2014-12-17 13:15     ` Peter Maydell
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Maydell @ 2014-12-17 13:15 UTC (permalink / raw)
  To: Ilya Palachev; +Cc: Vyachelav Barinov, QEMU Developers

On 17 December 2014 at 12:56, Ilya Palachev <i.palachev@samsung.com> wrote:
> We were interested in pwrite64/pread64 only since it caused a failure in
> elfutils (see https://bugzilla.redhat.com/show_bug.cgi?id=1174267).
> Of course, it applies also to other syscalls. There are the following
> problems:
>
> - Find what syscalls should be changed (check POSIX specification and qemu
> implementation)

Well, we should at least fix all the read/write syscalls, so we're
consistent.

> - Whether to change them all with "if" statements as for pread64/pwrite64.
> Or there is some more convenient way?

The other possibility would be to make sure that lock_user/unlock_user
succeeded for zero length. But that would be a pain to validate because
we'd need to check that no other syscall was relying on the "zero length
fails" behaviour. So a specific check and early exit is probably easier
and better.

> - Find they how to test them all after the change is made (make check?)

"make check" doesn't really exercise linux-user. Running the ltp tests
is usually a more comprehensive test:
http://wiki.qemu.org/Testing/LTP

-- PMM

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-12-17 13:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-17 12:02 [Qemu-devel] [PATCH] Force pread64/pwrite64 to return 0 for zero-length buffer Ilya Palachev
2014-12-17 12:28 ` Peter Maydell
2014-12-17 12:56   ` Ilya Palachev
2014-12-17 13:15     ` Peter Maydell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.