From 55fd0faa7e763ca6d5e8a1b17c7df4e144ed32a4 Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Fri, 24 Oct 2014 16:18:16 +0000 Subject: [PATCH] - Add sys/types.h for the APIs in sys/sysctl.h - Poke at VM_MIN_ADDRESS in machine/vmparam.h because FreeBSD doesn't have a vm.minaddress sysctl analog - Expect ENOMEM instead of EAGAIN in mlock_limits - Provide mlock an mmap'ed page twice to simulate MAP_WIRED on NetBSD In collaboration with: pho Sponsored by: EMC / Isilon Storage Division --- contrib/netbsd-tests/lib/libc/sys/t_mlock.c | 42 +++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/contrib/netbsd-tests/lib/libc/sys/t_mlock.c b/contrib/netbsd-tests/lib/libc/sys/t_mlock.c index 52576f77bc8f..0397b5cdac6a 100644 --- a/contrib/netbsd-tests/lib/libc/sys/t_mlock.c +++ b/contrib/netbsd-tests/lib/libc/sys/t_mlock.c @@ -31,6 +31,9 @@ #include __RCSID("$NetBSD: t_mlock.c,v 1.5 2014/02/26 20:49:26 martin Exp $"); +#ifdef __FreeBSD__ +#include +#endif #include #include #include @@ -43,6 +46,11 @@ __RCSID("$NetBSD: t_mlock.c,v 1.5 2014/02/26 20:49:26 martin Exp $"); #include #include +#ifdef __FreeBSD__ +#define _KMEMUSER +#include +#endif + static long page = 0; ATF_TC(mlock_clip); @@ -79,16 +87,25 @@ ATF_TC_HEAD(mlock_err, tc) ATF_TC_BODY(mlock_err, tc) { +#ifdef __NetBSD__ unsigned long vmin = 0; size_t len = sizeof(vmin); +#endif void *invalid_ptr; int null_errno = ENOMEM; /* error expected for NULL */ +#ifdef __FreeBSD__ +#ifdef VM_MIN_ADDRESS + if ((uintptr_t)VM_MIN_ADDRESS > 0) + null_errno = EINVAL; /* NULL is not inside user VM */ +#endif +#else if (sysctlbyname("vm.minaddress", &vmin, &len, NULL, 0) != 0) atf_tc_fail("failed to read vm.minaddress"); if (vmin > 0) null_errno = EINVAL; /* NULL is not inside user VM */ +#endif errno = 0; ATF_REQUIRE_ERRNO(null_errno, mlock(NULL, page) == -1); @@ -156,7 +173,17 @@ ATF_TC_BODY(mlock_limits, tc) errno = 0; +#ifdef __FreeBSD__ + /* + * NetBSD doesn't conform to POSIX with ENOMEM requirement; + * FreeBSD does. + * + * See: NetBSD PR # kern/48962 for more details. + */ + if (mlock(buf, i) != -1 || errno != ENOMEM) { +#else if (mlock(buf, i) != -1 || errno != EAGAIN) { +#endif (void)munlock(buf, i); _exit(EXIT_FAILURE); } @@ -181,7 +208,11 @@ ATF_TC_HEAD(mlock_mmap, tc) ATF_TC_BODY(mlock_mmap, tc) { +#ifdef __NetBSD__ static const int flags = MAP_ANON | MAP_PRIVATE | MAP_WIRED; +#else + static const int flags = MAP_ANON | MAP_PRIVATE; +#endif void *buf; /* @@ -191,6 +222,13 @@ ATF_TC_BODY(mlock_mmap, tc) buf = mmap(NULL, page, PROT_READ | PROT_WRITE, flags, -1, 0); ATF_REQUIRE(buf != MAP_FAILED); +#ifdef __FreeBSD__ + /* + * The duplicate mlock call is added to ensure that the call works + * as described above without MAP_WIRED support. + */ + ATF_REQUIRE(mlock(buf, page) == 0); +#endif ATF_REQUIRE(mlock(buf, page) == 0); ATF_REQUIRE(munlock(buf, page) == 0); ATF_REQUIRE(munmap(buf, page) == 0); @@ -202,7 +240,11 @@ ATF_TC_BODY(mlock_mmap, tc) buf = mmap(NULL, page, PROT_NONE, flags, -1, 0); ATF_REQUIRE(buf != MAP_FAILED); +#ifdef __FreeBSD__ + ATF_REQUIRE_ERRNO(ENOMEM, mlock(buf, page) != 0); +#else ATF_REQUIRE(mlock(buf, page) != 0); +#endif ATF_REQUIRE(munmap(buf, page) == 0); }