On 18/07/2023 17:43, Tudor Cretu wrote:
+ addr = mmap(NULL, MMAP_SIZE, prot, flags, -1, 0); + ASSERT_GT((unsigned long)addr, 0);
mmap returns MAP_FAILED on error, not 0. If you want to check that mmap return value is valid, use: ASSERT_FALSE(IS_ERR_VALUE(addr))
To be clear: the libc mmap() wrapper returns MAP_FAILED (-1), but our wrappers just make a raw syscall, so the return value is directly the error (if one occurs).
Tudor is right that there is a problem with this approach: the return value interpreted as *unsigned* long is always going to be greater than 0. Using IS_ERR_VALUE() like in mmap_verified() is a good option.
In fact, I wonder if we shouldn't simply use mmap_verified() whenever we expect mmap() to succeed, as that function already takes care of the standard checks (return value, tag, permissions). Maybe we could add another helper (in this file) for the cases where we expect mmap() to fail, adding an argument specifying the expected error. I'm suggesting this as the casts in ASSERT_EQ() in that case are rather cumbersome.
Kevin