Remove hardcoded VM_MIN_ADDRESS and instead query current value via

sysctl vm.minaddress.
This commit is contained in:
martin 2014-02-26 20:49:26 +00:00
parent 87d65da062
commit 1f6c8fa478
1 changed files with 9 additions and 7 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: t_mlock.c,v 1.4 2012/09/08 12:25:05 martin Exp $ */
/* $NetBSD: t_mlock.c,v 1.5 2014/02/26 20:49:26 martin Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@ -29,13 +29,12 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_mlock.c,v 1.4 2012/09/08 12:25:05 martin Exp $");
__RCSID("$NetBSD: t_mlock.c,v 1.5 2014/02/26 20:49:26 martin Exp $");
#include <sys/mman.h>
#include <sys/resource.h>
#include <sys/sysctl.h>
#include <sys/wait.h>
#define _KMEMUSER
#include <machine/vmparam.h>
#include <errno.h>
#include <atf-c.h>
@ -80,13 +79,16 @@ ATF_TC_HEAD(mlock_err, tc)
ATF_TC_BODY(mlock_err, tc)
{
unsigned long vmin = 0;
size_t len = sizeof(vmin);
void *invalid_ptr;
int null_errno = ENOMEM; /* error expected for NULL */
#ifdef VM_MIN_ADDRESS
if ((uintptr_t)VM_MIN_ADDRESS > 0)
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);