Syscalls such as mlock() first check the pointer (capability) they are passed in PCuABI. If the capability bounds are not contained in any reservation, -ERESERVATION is returned. This is what happens after a mapping is created and then fully unmapped.
Signed-off-by: Kevin Brodsky kevin.brodsky@arm.com --- testcases/kernel/syscalls/mlock/mlock02.c | 12 +++++++++++- testcases/kernel/syscalls/mlock2/mlock202.c | 5 +++-- 2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/testcases/kernel/syscalls/mlock/mlock02.c b/testcases/kernel/syscalls/mlock/mlock02.c index 921ddeeae707..3e18cab016df 100644 --- a/testcases/kernel/syscalls/mlock/mlock02.c +++ b/testcases/kernel/syscalls/mlock/mlock02.c @@ -40,7 +40,17 @@ static void test_enomem1(void) addr = SAFE_MMAP(NULL, len, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); SAFE_MUNMAP(addr, len); - TST_EXP_FAIL(mlock(addr, len), ENOMEM, "mlock(%p, %lu)", addr, len); + + TEST(mlock(addr, len)); + if (TST_RET != -1) + tst_res(TFAIL | TTERRNO, "mlock(%p, %lu): wrong return code: %ld", + addr, len, TST_RET); + else if (TST_ERR != ENOMEM && TST_ERR != ERESERVATION) + tst_res(TFAIL | TTERRNO, "mlock(%p, %lu): expected errno: %d", + addr, len, TST_ERR); + else + tst_res(TPASS | TTERRNO, "mlock(%p, %lu) ", + addr, len); }
static void test_enomem2(void) diff --git a/testcases/kernel/syscalls/mlock2/mlock202.c b/testcases/kernel/syscalls/mlock2/mlock202.c index 3b49650657cd..5ef33ea95aed 100644 --- a/testcases/kernel/syscalls/mlock2/mlock202.c +++ b/testcases/kernel/syscalls/mlock2/mlock202.c @@ -40,11 +40,12 @@ static struct tcase { /* 1: nobody 0: root */ int user; int exp_err; + int alt_err; } tcases[] = { {&addr, -1, NULL, 0, EINVAL}, {&addr, 0, &max_sz1, 1, ENOMEM}, {&addr, 0, &max_sz2, 1, EPERM}, - {&unmapped_addr, 0, NULL, 0, ENOMEM}, + {&unmapped_addr, 0, NULL, 0, ENOMEM, ERESERVATION}, };
static void verify_mlock2(unsigned int n) @@ -67,7 +68,7 @@ static void verify_mlock2(unsigned int n) goto end; }
- if (TST_ERR != tc->exp_err) { + if (TST_ERR != tc->exp_err && TST_ERR != tc->alt_err) { tst_res(TFAIL | TTERRNO, "mlock2() failed unexpectedly, expected %s", tst_strerrno(tc->exp_err));