Le 30/09/2017 à 17:23, [email protected] a écrit : > From: Zhuowei Zhang <[email protected]> > > Linux returns success for the special case of calling write with a zero-length > NULL buffer: compiling and running > > ``` > #include <stdio.h> > #include <unistd.h> > #include <fcntl.h> > > int main() { > ssize_t ret = write(STDOUT_FILENO, NULL, 0); > fprintf(stderr, "write returned %ld\n", ret); > return 0; > } > ``` > gives "write returned 0" when run directly, but "write returned -1" in QEMU. > > This commit checks for this situation and calls the real syscall with a NULL > buffer and zero length, which gives the correct return value. > > Signed-off-by: Zhuowei Zhang <[email protected]> > --- > linux-user/syscall.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/linux-user/syscall.c b/linux-user/syscall.c > index 9b6364a..60769c0 100644 > --- a/linux-user/syscall.c > +++ b/linux-user/syscall.c > @@ -7783,6 +7783,11 @@ abi_long do_syscall(void *cpu_env, int num, abi_long > arg1, > } > break; > case TARGET_NR_write: > + if (arg2 == 0 && arg3 == 0) { > + /* special case: write(fd, NULL, 0) returns success. */ > + ret = get_errno(safe_write(arg1, NULL, 0)); > + break; > + } > if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1))) > goto efault; > if (fd_trans_target_to_host_data(arg1)) { >
Reviewed-by: Laurent Vivier <[email protected]> Could you change the NR_read too, for consistency? Thanks, Laurent
