From owner-svn-src-head@FreeBSD.ORG Fri Oct 24 16:18:17 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 63BFC8CC; Fri, 24 Oct 2014 16:18:17 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4F7FAA55; Fri, 24 Oct 2014 16:18:17 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s9OGIHiZ004617; Fri, 24 Oct 2014 16:18:17 GMT (envelope-from ngie@FreeBSD.org) Received: (from ngie@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s9OGIHAJ004616; Fri, 24 Oct 2014 16:18:17 GMT (envelope-from ngie@FreeBSD.org) Message-Id: <201410241618.s9OGIHAJ004616@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: ngie set sender to ngie@FreeBSD.org using -f From: Garrett Cooper Date: Fri, 24 Oct 2014 16:18:17 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r273592 - head/contrib/netbsd-tests/lib/libc/sys X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Oct 2014 16:18:17 -0000 Author: ngie Date: Fri Oct 24 16:18:16 2014 New Revision: 273592 URL: https://svnweb.freebsd.org/changeset/base/273592 Log: - 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 Modified: head/contrib/netbsd-tests/lib/libc/sys/t_mlock.c Modified: head/contrib/netbsd-tests/lib/libc/sys/t_mlock.c ============================================================================== --- head/contrib/netbsd-tests/lib/libc/sys/t_mlock.c Fri Oct 24 16:07:31 2014 (r273591) +++ head/contrib/netbsd-tests/lib/libc/sys/t_mlock.c Fri Oct 24 16:18:16 2014 (r273592) @@ -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/0 #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); }