OSDN Git Service

linux-user: Handle negative values in timespec conversion
authorPeter Maydell <peter.maydell@linaro.org>
Thu, 19 May 2016 11:01:40 +0000 (12:01 +0100)
committerRiku Voipio <riku.voipio@linaro.org>
Fri, 27 May 2016 11:50:39 +0000 (14:50 +0300)
commitc7e35da348e2e4df072e6979c48fa5283e07d1db
treebd505d5a61f849629c32ffa1a770d5a9f456f9fc
parentd509eeb13c9c6fef4a29ca43c64f591d8c61d201
linux-user: Handle negative values in timespec conversion

In a struct timespec, both fields are signed longs. Converting
them from guest to host with code like
    host_ts->tv_sec = tswapal(target_ts->tv_sec);
mishandles negative values if the guest has 32-bit longs and
the host has 64-bit longs because tswapal()'s return type is
abi_ulong: the assignment will zero-extend into the host long
type rather than sign-extending it.

Make the conversion routines use __get_user() and __set_user()
instead: this automatically picks up the signedness of the
field type and does the correct kind of sign or zero extension.
It also handles the possibility that the target struct is not
sufficiently aligned for the host's requirements.

In particular, this fixes a hang when running the Linux Test Project
mq_timedsend01 and mq_timedreceive01 tests: one of the test cases
sets the timeout to -1 and expects an EINVAL failure, but we were
setting a very long timeout instead.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
linux-user/syscall.c