syscall: read() should not write anything if reading EOF.

Read() should not write anything when returning 0 (EOF).
This patch does not correct the same bug occuring for :

nbr_read=read(file, buf, nbytes)

When nbr_read<nbytes, nbytes bytes are copied into the virtual
RAM instead of nbr_read. If buf is smaller than nbytes, a
page fault occurs, even if buf is in fact bigger than nbr_read.

Signed-off-by: Jason Lowe-Power <jason@lowepower.com>
This commit is contained in:
Nicolas Derumigny 2016-10-15 15:06:24 -05:00
parent 6c72c35519
commit 976ef444b8

View file

@ -245,7 +245,7 @@ readFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
int bytes_read = read(sim_fd, bufArg.bufferPtr(), nbytes); int bytes_read = read(sim_fd, bufArg.bufferPtr(), nbytes);
if (bytes_read != -1) if (bytes_read > 0)
bufArg.copyOut(tc->getMemProxy()); bufArg.copyOut(tc->getMemProxy());
return bytes_read; return bytes_read;