[PATCH 1/4] tests/mlock2.c: fix test failure on mips64

James Cowgill james410 at cowgill.org.uk
Thu Aug 11 09:49:35 UTC 2016


On 11/08/16 03:14, Dmitry V. Levin wrote:
> On Wed, Aug 10, 2016 at 11:38:42AM +0100, James Cowgill wrote:
>> In tests/mlock2.c, the address argument for the mlock2 syscall is passed
>> through a vararg using the "syscall" function. On 64-bit systems, while the
>> input argument is treated as an unsigned int, the argument is read as a
>> void* (64-bits wide). On mips64, writes to the lower 32-bits of a register
>> are by default sign extended to the upper 32-bits, so the pointer is read by
>> the syscall function as 0xffffffffdeadbeef causing the test to fail.
>> Fix by casting the integer to a void* before passing it.
>>
>> * tests/mlock2.c: add void* cast to address argument of mlock2
>> ---
>>  tests/mlock2.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/tests/mlock2.c b/tests/mlock2.c
>> index af63917..59f1bf9 100644
>> --- a/tests/mlock2.c
>> +++ b/tests/mlock2.c
>> @@ -36,7 +36,7 @@
>>  int
>>  main(void)
>>  {
>> -	long rc = syscall(__NR_mlock2, 0xdeadbeef, 0xdefaced, 0xffff);
>> +	long rc = syscall(__NR_mlock2, (void*) 0xdeadbeef, 0xdefaced, 0xffff);
>>  	printf("mlock2(0xdeadbeef, 233811181, MLOCK_ONFAULT|0xfffe)"
>>  	       " = %ld %s (%m)\n", rc, errno2name());
> 
> I think 0xdeadbeefUL would also fix this test failure.
> 
> I'd even extended this test to
> 
> 	const unsigned long addr = (unsigned long) 0xfacefeeddeadbeefULL;
> 	const unsigned long len = (unsigned long) 0xcafef00dbadc0dedULL;
> 	long rc = syscall(__NR_mlock2, addr, len, -1UL);
> 	printf("mlock2(%#lx, %lu, MLOCK_ONFAULT|0xfffffffe)"
> 	       " = %ld %s (%m)\n", addr, len, rc, errno2name());

Yes that makes the test pass on mips64 as well.

Thanks,
James

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20160811/c520a6a8/attachment.bin>


More information about the Strace-devel mailing list