In PCuABI, library functions such as malloc() are not expected to return a pointer that allows manipulating the underlying mapping. For that purpose, mmap() should be used.
Signed-off-by: Kevin Brodsky kevin.brodsky@arm.com --- testcases/kernel/syscalls/mlock/mlock01.c | 13 +++---------- testcases/kernel/syscalls/munlock/munlock01.c | 13 +++---------- 2 files changed, 6 insertions(+), 20 deletions(-)
diff --git a/testcases/kernel/syscalls/mlock/mlock01.c b/testcases/kernel/syscalls/mlock/mlock01.c index 0b079f8be83a..8cefc96b87dc 100644 --- a/testcases/kernel/syscalls/mlock/mlock01.c +++ b/testcases/kernel/syscalls/mlock/mlock01.c @@ -32,21 +32,14 @@ static void do_mlock(unsigned int i) struct tcase *tc = &tcases[i];
tst_res(TINFO, "%s", tc->msg); - addr = SAFE_MALLOC(tc->len); + addr = SAFE_MMAP(NULL, tc->len, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); TST_EXP_PASS(mlock(addr, tc->len), "mlock(%p, %d)", addr, tc->len); - free(addr); - addr = NULL; -} - -static void cleanup(void) -{ - if (addr) - free(addr); + SAFE_MUNMAP(addr, tc->len); }
static struct tst_test test = { .needs_root = 1, .test = do_mlock, .tcnt = ARRAY_SIZE(tcases), - .cleanup = cleanup, }; diff --git a/testcases/kernel/syscalls/munlock/munlock01.c b/testcases/kernel/syscalls/munlock/munlock01.c index 31d749e66697..ff55056ae908 100644 --- a/testcases/kernel/syscalls/munlock/munlock01.c +++ b/testcases/kernel/syscalls/munlock/munlock01.c @@ -30,22 +30,15 @@ static void verify_munlock(unsigned int i) struct tcase *tc = &tcases[i];
tst_res(TINFO, "%s", tc->msg); - addr = SAFE_MALLOC(tc->len); + addr = SAFE_MMAP(NULL, tc->len, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); SAFE_MLOCK(addr, tc->len); TST_EXP_PASS(munlock(addr, tc->len), "munlock(%p, %d)", addr, tc->len); - free(addr); - addr = NULL; -} - -static void cleanup(void) -{ - if (addr) - free(addr); + SAFE_MUNMAP(addr, tc->len); }
static struct tst_test test = { .needs_root = 1, .test = verify_munlock, .tcnt = ARRAY_SIZE(tcases), - .cleanup = cleanup, };