[PATCH 1/2] linux: prevent kernel choose addr by itself in mremap test
Celeste Liu
uwu@coelacanthus.name
Fri Feb 7 20:17:50 GMT 2025
It's only guaranteed when MREMAP_FIXED was specified.
---
sysdeps/unix/sysv/linux/tst-linux-mremap1.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/sysdeps/unix/sysv/linux/tst-linux-mremap1.c b/sysdeps/unix/sysv/linux/tst-linux-mremap1.c
index a5dce5aee4104b5c4a594daab4e5fda1c4080ab4..334ce2a30be1362233f6c20139f7a80213585d10 100644
--- a/sysdeps/unix/sysv/linux/tst-linux-mremap1.c
+++ b/sysdeps/unix/sysv/linux/tst-linux-mremap1.c
@@ -40,20 +40,21 @@ do_test (void)
MAP_PRIVATE | MAP_ANONYMOUS, -1);
xmunmap (fixed_addr, fixed_size);
- /* Add 3 * pagesize. */
- fixed_size += 3 * old_size;
-
- /* Test MREMAP_DONTUNMAP. It should return FIXED_ADDR created above. */
+ /* Test MREMAP_DONTUNMAP and MREMAP_FIXED. It should return address we
+ specified and the old address is still available */
char *new_addr = mremap (old_addr, old_size, new_size,
- MREMAP_DONTUNMAP | MREMAP_MAYMOVE,
+ MREMAP_DONTUNMAP | MREMAP_MAYMOVE | MREMAP_FIXED,
fixed_addr);
if (new_addr == MAP_FAILED)
return mremap_failure_exit (errno);
+ /* mremap should use the hint address. */
TEST_VERIFY_EXIT (fixed_addr == new_addr);
- old_addr[0] = 3;
- old_addr[old_size - 1] = 4;
- new_addr[0] = 1;
- new_addr[new_size - 1] = 2;
+ /* Old range should be zero-filled. */
+ TEST_VERIFY_EXIT (old_addr[0] == 0);
+ TEST_VERIFY_EXIT (old_addr[old_size - 1] == 0);
+ /* New range should have the same bytes as the old one. */
+ TEST_VERIFY_EXIT (new_addr[0] == 1);
+ TEST_VERIFY_EXIT (new_addr[new_size - 1] == 2);
xmunmap (new_addr, new_size);
xmunmap (old_addr, old_size);
--
2.48.1
More information about the Libc-alpha
mailing list